CFugue
MayaStrUtils.h
1 #ifndef __MSTRUTILS_H_AB781278_E118_4246_A3BA_16102A7F2DFD__
2 
3 #include <atlstr.h>
4 #define STRUTILS_RETURN_TYPE ATL::CString
5 
6 #include "StrUtils.h"
7 
8 #ifdef _MString // if included Maya/MString.h
9 
10 // Helper for Maya String convertion to LPCTSTR
11 inline LPCTSTR MStringToLPCTSTR(const MString& MStr)
12 {
13 #if defined(UNICODE) || defined(_UNICODE)
14  return MStr.asWChar();
15 #else
16  return MStr.asChar();
17 #endif
18 }
19 
20 // Helper for Maya String convertion to LPCSTR
21 inline LPCSTR MStringToLPCSTR(const MString& MStr)
22 {
23  return MStr.asChar();
24 }
25 
26 // Helper for Maya String convertion to LPCWSTR
27 inline LPCWSTR MStringToLPCWSTR(const MString& MStr)
28 {
29  return MStr.asWChar();
30 }
31 
32 template<>
33 inline OIL::StrUtils_Return_Type OIL::ToString(const MString& MStr)
34 {
35 #if defined(UNICODE) || defined(_UNICODE)
36  return _T("\"") + OIL::StrUtils_Return_Type(MStr.asWChar()) + _T("\"");
37 #else
38  return _T("\"") + OIL::StrUtils_Return_Type(MStr.asChar()) + _T("\"");
39 #endif
40 }
41 #endif // _MString
42 
43 #ifdef _MStringArray // if included Maya/MStringArray.h
44 template<>
45 inline OIL::StrUtils_Return_Type OIL::ToString(const MStringArray& strArr)
46 {
47  OIL::StrUtils_Return_Type strRet(_T("{"));
48 
49  const unsigned int len = strArr.length();
50 
51  for(unsigned int i=0; len !=0 && i < len-1; ++i)
52  {
53  strRet += OIL::ToString(strArr[i]);
54  strRet += _T(", ");
55  }
56 
57  if(len != 0) strRet += OIL::ToString(strArr[len-1]);
58 
59  return strRet + _T("}");
60 }
61 #endif // _MStringArray
62 
63 #ifdef _MPoint // if included maya/MPoint.h
64 template<>
65 inline OIL::StrUtils_Return_Type OIL::ToString(const MPoint& pt)
66 {
67  return OIL::StrUtils_Return_Type(_T("{")) +
68  OIL::ToString(pt.x) + _T(",") +
69  OIL::ToString(pt.y) + _T(",") +
70  OIL::ToString(pt.z) + _T(",") +
71  OIL::ToString(pt.w) + _T(" ") +
72  _T("}");
73 }
74 #endif //_MPoint
75 
76 #ifdef _MBoundingBox // if included Maya/MBoundingBox.h
77 template<>
78 inline OIL::StrUtils_Return_Type OIL::ToString(const MBoundingBox& bb)
79 {
80  return OIL::StrUtils_Return_Type(_T("{")) +
81  _T("w=") + OIL::ToString(bb.width()) + _T(",") +
82  _T("h=") + OIL::ToString(bb.height()) + _T(",") +
83  _T("d=") + OIL::ToString(bb.depth()) + _T(",") +
84  _T("Center=") + OIL::ToString(bb.center()) + _T("") +
85  //_T("Min=") + OIL::ToString(bb.center()) + _T(",") +
86  //_T("Max=") + OIL::ToString(bb.center()) + _T("") +
87  _T("}");
88 }
89 #endif // _MBoundingBox
90 
91 #ifdef _MDagPathArray // if included Maya/MDagPathArray.h
92 template<>
93 inline OIL::StrUtils_Return_Type OIL::ToString(const MDagPathArray& pathArray)
94 {
95  OIL::StrUtils_Return_Type strRet(_T("{"));
96 
97  const unsigned int len = pathArray.length();
98 
99  for(unsigned int i=0; len !=0 && i < len-1; ++i)
100  {
101  strRet += OIL::ToString(pathArray[i].fullPathName());
102  strRet += _T(", ");
103  }
104 
105  if(len != 0) strRet += OIL::ToString(pathArray[len-1].fullPathName());
106 
107  return strRet + _T("}");
108 }
109 #endif // _MDagPathArray
110 
111 #ifdef _MVector // if included Maya/MVector.h
112 template<>
113 inline OIL::StrUtils_Return_Type OIL::ToString(const MVector& vec)
114 {
115  return OIL::StrUtils_Return_Type(_T("{")) +
116  OIL::ToString(vec.x) + _T(",") +
117  OIL::ToString(vec.y) + _T(",") +
118  OIL::ToString(vec.z) + _T(" ") +
119  _T("}");
120 }
121 #endif //_MVector
122 
123 #ifdef _MFloatVector // if included Maya/MFloatVector.h
124 template<>
125 inline OIL::StrUtils_Return_Type OIL::ToString(const MFloatVector& vec)
126 {
127  return OIL::StrUtils_Return_Type(_T("{")) +
128  OIL::ToString(vec.x) + _T(",") +
129  OIL::ToString(vec.y) + _T(",") +
130  OIL::ToString(vec.z) + _T(" ") +
131  _T("}");
132 }
133 #endif //_MVector
134 
135 #ifdef _MFloatMatrix // if included Maya/MFloatMatrix.h
136 template<>
137 inline OIL::StrUtils_Return_Type OIL::ToString(const MFloatMatrix& fm)
138 {
139  return OIL::StrUtils_Return_Type(_T("{")) +
140  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(fm.matrix[0][0]) + _T(",") + OIL::ToString(fm.matrix[0][1]) + _T(",") + OIL::ToString(fm.matrix[0][2]) + _T(",") + OIL::ToString(fm.matrix[0][3]) + _T(" }") +
141  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(fm.matrix[1][0]) + _T(",") + OIL::ToString(fm.matrix[1][1]) + _T(",") + OIL::ToString(fm.matrix[1][2]) + _T(",") + OIL::ToString(fm.matrix[1][3]) + _T(" }") +
142  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(fm.matrix[2][0]) + _T(",") + OIL::ToString(fm.matrix[2][1]) + _T(",") + OIL::ToString(fm.matrix[2][2]) + _T(",") + OIL::ToString(fm.matrix[2][3]) + _T(" }") +
143  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(fm.matrix[3][0]) + _T(",") + OIL::ToString(fm.matrix[3][1]) + _T(",") + OIL::ToString(fm.matrix[3][2]) + _T(",") + OIL::ToString(fm.matrix[3][3]) + _T(" }") +
144  _T("}");
145 }
146 #endif // _MFloatMatrix
147 
148 #ifdef _MMatrix // if included Maya/MMatrix.h
149 template<>
150 inline OIL::StrUtils_Return_Type OIL::ToString(const MMatrix& mat)
151 {
152  return OIL::StrUtils_Return_Type(_T("{")) +
153  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(mat.matrix[0][0]) + _T(",") + OIL::ToString(mat.matrix[0][1]) + _T(",") + OIL::ToString(mat.matrix[0][2]) + _T(",") + OIL::ToString(mat.matrix[0][3]) + _T(" }") +
154  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(mat.matrix[1][0]) + _T(",") + OIL::ToString(mat.matrix[1][1]) + _T(",") + OIL::ToString(mat.matrix[1][2]) + _T(",") + OIL::ToString(mat.matrix[1][3]) + _T(" }") +
155  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(mat.matrix[2][0]) + _T(",") + OIL::ToString(mat.matrix[2][1]) + _T(",") + OIL::ToString(mat.matrix[2][2]) + _T(",") + OIL::ToString(mat.matrix[2][3]) + _T(" }") +
156  OIL::StrUtils_Return_Type(_T("{")) + OIL::ToString(mat.matrix[3][0]) + _T(",") + OIL::ToString(mat.matrix[3][1]) + _T(",") + OIL::ToString(mat.matrix[3][2]) + _T(",") + OIL::ToString(mat.matrix[3][3]) + _T(" }") +
157  _T("}");
158 }
159 #endif // _MMatrix
160 
161 #ifdef _MFnCamera // if included Maya/MFnCamera.h
162 template<>
163 inline OIL::StrUtils_Return_Type OIL::ToString(const MFnCamera::FilmFit& ff)
164 {
165  const TCHAR* FilmFitStr[] = { _T("kFillFilmFit"), _T("kHorizontalFilmFit"), _T("kVerticalFilmFit"), _T("kOverscanFilmFit"), _T("kInvalid") };
166  return OIL::StrUtils_Return_Type(FilmFitStr[ff]);
167 }
168 
169 template<>
170 inline OIL::StrUtils_Return_Type OIL::ToString(const MFnCamera::RollOrder& ro)
171 {
172  const TCHAR* RollOrderStr[] = { _T("kRotateTranslate"), _T("kTranslateRotate") };
173  return OIL::StrUtils_Return_Type(RollOrderStr[ro]);
174 }
175 #endif // _MFnCamera
176 
177 #ifdef _MColor // if included Maya/MColor.h
178 template<>
179 inline OIL::StrUtils_Return_Type OIL::ToString(const MColor& Color)
180 {
181  return OIL::StrUtils_Return_Type(_T("{")) +
182  OIL::ToString(Color.r) + _T(",") +
183  OIL::ToString(Color.g) + _T(",") +
184  OIL::ToString(Color.b) + _T(",") +
185  OIL::ToString(Color.a) + _T(" ") +
186  _T("}");
187 }
188 #endif //_MColor
189 
190 #ifdef _MFnNurbsCurve // if included <Maya/MFnNurbsCurve.h>
191 template<>
192 inline OIL::StrUtils_Return_Type OIL::ToString(const MFnNurbsCurve::Form& form)
193 {
194  const TCHAR* FormStr[] = { _T("kInvalid"), _T("kOpen"), _T("kClosed"), _T("kPeriodic"), _T("kLast")};
195  return OIL::StrUtils_Return_Type(FormStr[form]);
196 }
197 #endif //_MFnNurbsCurve
198 
199 #ifdef _MFnNurbsSurface // if included <Maya/MFnNurbsSurface.h>
200 template<>
201 inline OIL::StrUtils_Return_Type OIL::ToString(const MFnNurbsSurface::Form& form)
202 {
203  const TCHAR* FormStr[] = { _T("kInvalid"), _T("kOpen"), _T("kClosed"), _T("kPeriodic"), _T("kLast")};
204  return OIL::StrUtils_Return_Type(FormStr[form]);
205 }
206 #endif //_MFnNurbsSurface
207 
208 #endif //__MSTRUTILS_H_AB781278_E118_4246_A3BA_16102A7F2DFD__

CFugue, the C++ Music Programming Library © Copyright 2009 Cenacle Research India Private Limited Gopalakrishna Palem