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