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 Adaptors between UT and std classes
12 
13 #ifndef __UT_STDUTIL_H_INCLUDED__
14 #define __UT_STDUTIL_H_INCLUDED__
15 
16 #include "UT_API.h"
17 #include "UT_Array.h"
18 #include "UT_FixedVector.h"
19 #include "UT_StringHolder.h"
20 #include "UT_WorkArgs.h"
21 #include <SYS/SYS_Types.h>
22 
23 #include <string>
24 #include <vector>
25 
26 // Forward declare
27 template <typename T> class UT_Vector3T;
28 
29 template <typename T>
30 static inline void
31 UTarrayFromStdVector(UT_Array<T> &dst, const std::vector<T> &src)
32 {
33  dst.clear();
34  dst.setCapacityIfNeeded(src.size());
35  for (exint i = 0, n = src.size(); i < n; ++i)
36  dst.append(src[i]);
37 }
38 
39 template <typename T>
40 static inline void
41 UTarrayToStdVector(const UT_Array<T> &src, std::vector<T> &dst)
42 {
43  dst.clear();
44  dst.reserve(src.size());
45  for (exint i = 0, n = src.size(); i < n; ++i)
46  dst.push_back(src[i]);
47 }
48 
49 inline void
51  UT_Array<UT_StringHolder> &dst, const std::vector<std::string> &src)
52 {
53  dst.clear();
54  dst.setCapacityIfNeeded(src.size());
55  for (exint i = 0, n = src.size(); i < n; ++i)
56  dst.append(src[i]);
57 }
58 
59 static inline void
60 UTarrayToStdVectorOfStrings(
61  const UT_Array<UT_StringHolder> &src, std::vector<std::string> &dst)
62 {
63  dst.clear();
64  dst.reserve(src.size());
65  for (exint i = 0, n = src.size(); i < n; ++i)
66  dst.push_back(src[i].toStdString());
67 }
68 
69 static inline void
70 UTargsToStringVector(const UT_WorkArgs &src, std::vector<std::string> &dst)
71 {
72  dst.clear();
73  dst.reserve(src.getArgc());
74  for (exint i = 0, n = src.getArgc(); i < n; ++i)
75  dst.push_back(src.getArg(i));
76 }
77 
78 template <typename T, exint SIZE>
79 static inline std::vector<T>
80 UTasStdVector(const UT_FixedVector<T,SIZE> &src)
81 {
82  std::vector<T> dst(SIZE);
83  for (exint i = 0; i < SIZE; ++i)
84  dst[i] = src[i];
85  return dst;
86 }
87 
88 template <typename T>
89 static inline std::vector<T>
90 UTasStdVector(const UT_Vector3T<T> &src)
91 {
92  std::vector<T> dst(3);
93  for (exint i = 0; i < 3; ++i)
94  dst[i] = src[i];
95  return dst;
96 }
97 
98 #endif // __UT_STDUTIL_H_INCLUDED__
int64 exint
Definition: SYS_Types.h:125
GLenum src
Definition: glcorearb.h:1793
3D Vector class.
exint size() const
Definition: UT_Array.h:609
const char * getArg(int idx) const
Definition: UT_WorkArgs.h:35
int getArgc() const
Definition: UT_WorkArgs.h:34
exint append()
Definition: UT_Array.h:137
GLdouble n
Definition: glcorearb.h:2008
void UTarrayFromStdVectorOfStrings(UT_Array< UT_StringHolder > &dst, const std::vector< std::string > &src)
Definition: UT_StdUtil.h:50
void setCapacityIfNeeded(exint mincapacity)
Definition: UT_Array.h:566
#define SIZE
Definition: simple.C:40
void clear()
Resets list to an empty list.
Definition: UT_Array.h:679
GLenum GLenum dst
Definition: glcorearb.h:1793