HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_StdUtil.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_StdUtil.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 /// @file UT_StdUtil.h
12 /// @brief Adaptors between UT and std classes
13 
14 #ifndef __UT_STDUTIL_H_INCLUDED__
15 #define __UT_STDUTIL_H_INCLUDED__
16 
17 #include "UT_API.h"
18 #include "UT_Array.h"
19 #include "UT_FixedVector.h"
20 #include "UT_StringHolder.h"
21 #include "UT_StringView.h"
22 #include "UT_WorkArgs.h"
23 #include <SYS/SYS_Types.h>
24 
25 #include <string>
26 #include <vector>
27 
28 // Forward declare
29 template <typename T> class UT_Vector3T;
30 
31 template <typename T>
32 static inline void
33 UTarrayFromStdVector(UT_Array<T> &dst, const std::vector<T> &src)
34 {
35  dst.clear();
36  dst.setCapacityIfNeeded(src.size());
37  for (exint i = 0, n = src.size(); i < n; ++i)
38  dst.append(src[i]);
39 }
40 
41 template <typename T>
42 static inline void
43 UTarrayToStdVector(const UT_Array<T> &src, std::vector<T> &dst)
44 {
45  dst.clear();
46  dst.reserve(src.size());
47  for (exint i = 0, n = src.size(); i < n; ++i)
48  dst.push_back(src[i]);
49 }
50 
51 inline void
53  UT_Array<UT_StringHolder> &dst, const std::vector<std::string> &src)
54 {
55  dst.clear();
56  dst.setCapacityIfNeeded(src.size());
57  for (exint i = 0, n = src.size(); i < n; ++i)
58  dst.append(src[i]);
59 }
60 
61 static inline void
62 UTarrayToStdVectorOfStrings(
63  const UT_Array<UT_StringHolder> &src, std::vector<std::string> &dst)
64 {
65  dst.clear();
66  dst.reserve(src.size());
67  for (exint i = 0, n = src.size(); i < n; ++i)
68  dst.push_back(src[i].toStdString());
69 }
70 
71 static inline void
72 UTargsToStringVector(const UT_WorkArgs &src, std::vector<std::string> &dst)
73 {
74  dst.clear();
75  dst.reserve(src.getArgc());
76  for (exint i = 0, n = src.getArgc(); i < n; ++i)
77  dst.push_back(src.getArg(i));
78 }
79 
80 template <typename T, exint SIZE>
81 static inline std::vector<T>
82 UTasStdVector(const UT_FixedVector<T,SIZE> &src)
83 {
84  std::vector<T> dst(SIZE);
85  for (exint i = 0; i < SIZE; ++i)
86  dst[i] = src[i];
87  return dst;
88 }
89 
90 template <typename T>
91 static inline std::vector<T>
92 UTasStdVector(const UT_Vector3T<T> &src)
93 {
94  std::vector<T> dst(3);
95  for (exint i = 0; i < 3; ++i)
96  dst[i] = src[i];
97  return dst;
98 }
99 
100 template <typename T>
101 static inline std::vector<T>
102 UTasStdVector(const UT_Vector2T<T> &src)
103 {
104  std::vector<T> dst(2);
105  for (exint i = 0; i < 2; ++i)
106  dst[i] = src[i];
107  return dst;
108 }
109 
110 template <typename T>
111 static inline std::vector<T>
112 UTasStdVector(const UT_Vector4T<T> &src)
113 {
114  std::vector<T> dst(4);
115  for (exint i = 0; i < 4; ++i)
116  dst[i] = src[i];
117  return dst;
118 }
119 
120 static inline UT_StringView
121 UTasStringView(const std::string &str)
122 {
123  return UT_StringView(str.c_str(), str.c_str() + str.length());
124 }
125 
126 #endif // __UT_STDUTIL_H_INCLUDED__
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
int64 exint
Definition: SYS_Types.h:125
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:174
2D Vector class.
Definition: UT_Vector2.h:159
exint size() const
Definition: UT_Array.h:646
A utility class to do read-only operations on a subset of an existing string.
Definition: UT_StringView.h:39
GLdouble n
Definition: glcorearb.h:2008
const char * getArg(int idx) const
Definition: UT_WorkArgs.h:35
void setCapacityIfNeeded(exint min_capacity)
Definition: UT_Array.h:603
int getArgc() const
Definition: UT_WorkArgs.h:34
exint append()
Definition: UT_Array.h:142
GLenum GLenum dst
Definition: glcorearb.h:1793
void UTarrayFromStdVectorOfStrings(UT_Array< UT_StringHolder > &dst, const std::vector< std::string > &src)
Definition: UT_StdUtil.h:52
#define SIZE
Definition: simple.C:41
void clear()
Resets list to an empty list.
Definition: UT_Array.h:729
GLenum src
Definition: glcorearb.h:1793