MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00004 00009 //---------------------------------------------------------------------------------- 00010 #ifndef __mlVTKCommonToolFunctions_H 00011 #define __mlVTKCommonToolFunctions_H 00012 00014 // Include dll-specific settings. 00015 #include "mlInitSystemVTKSupport.h" 00016 00018 #ifndef __mlModuleIncludes_H 00019 #include "mlModuleIncludes.h" 00020 #endif 00021 #ifndef __mlUnicode_H 00022 #include <mlUnicode.h> 00023 #endif 00024 00025 ML_START_NAMESPACE 00026 00027 //--------------------------------------------------------------------------- 00029 //--------------------------------------------------------------------------- 00030 inline std::string mlVTKMakeStdString(const char* str){ return str ? str : ""; } 00031 00032 //--------------------------------------------------------------------------- 00034 //--------------------------------------------------------------------------- 00035 inline std::string mlVTKMakeStdString(const std::string &str){ return str; } 00036 00037 00038 00039 //--------------------------------------------------------------------------- 00044 //--------------------------------------------------------------------------- 00045 inline std::string mlVTKGetLatin1FromUTF8(const std::string &utf8StdString) 00046 { 00047 std::string retStr = ""; 00048 if (!utf8StdString.empty()){ 00049 char *latin1CStr = MLConvertUTF8ToLatin1(utf8StdString.c_str()); 00050 retStr = (latin1CStr ? latin1CStr : ""); 00051 MLFree(latin1CStr); 00052 latin1CStr = NULL; 00053 } 00054 00055 // On return assure that a non empty input string remains non empty to 00056 // avoid that previous checks on non empty input parameters on caller site 00057 // become invalid. Return "?" in that case. 00058 return (!utf8StdString.empty() && retStr.empty()) ? "?" : retStr; 00059 } 00060 00061 //--------------------------------------------------------------------------- 00068 //--------------------------------------------------------------------------- 00069 inline std::string & mlVTKGetLatin1FromUTF8Static(const std::string &utf8StdString) 00070 { 00071 static std::string retStr = ""; 00072 retStr = mlVTKGetLatin1FromUTF8(utf8StdString); 00073 return retStr; 00074 } 00075 00076 00077 00078 //--------------------------------------------------------------------------- 00083 //--------------------------------------------------------------------------- 00084 inline std::string mlVTKGetUTF8FromLatin1(const std::string &latin1StdString) 00085 { 00086 std::string retStr = ""; 00087 if (!latin1StdString.empty()){ 00088 char *utf8CStr = MLConvertLatin1ToUTF8(latin1StdString.c_str()); 00089 retStr = (utf8CStr ? utf8CStr : ""); 00090 MLFree(utf8CStr); 00091 utf8CStr = NULL; 00092 } 00093 00094 // On return assure that a non empty input string remains non empty to 00095 // avoid that previous checks on non empty input parameters on caller site 00096 // become invalid. Return "?" in that case. 00097 return (!latin1StdString.empty() && retStr.empty()) ? "?" : retStr; 00098 } 00099 00100 //--------------------------------------------------------------------------- 00107 //--------------------------------------------------------------------------- 00108 inline std::string & mlVTKGetUTF8FromLatin1Static(const std::string &latin1StdString) 00109 { 00110 static std::string retStr = ""; 00111 retStr = mlVTKGetUTF8FromLatin1(latin1StdString); 00112 return retStr; 00113 } 00114 00115 00116 00117 //--------------------------------------------------------------------------- 00120 //--------------------------------------------------------------------------- 00121 template<typename TemplArrElemType> 00122 void VTKArrayFromFixedSizeSTLVector(const VTKML_TYPENAME std::vector<TemplArrElemType> &stlVec, TemplArrElemType *arr, size_t TemplArrSize) 00123 { 00124 ML_TRACE_IN("template VTKArrayFromFixedSizeSTLVector()") 00125 00126 // Copy elements to return array. 00127 const size_t siz = stlVec.size(); 00128 for (size_t c=0; c < TemplArrSize; ++c){ arr[c] = (c < siz) ? stlVec[c] : 0; } 00129 } 00130 00131 //--------------------------------------------------------------------------- 00135 //--------------------------------------------------------------------------- 00136 template<typename TemplArrElemType, unsigned int TemplArrSize> 00137 const VTKML_TYPENAME std::vector<TemplArrElemType> STLVectorFromFixedSizeVTKArray(const TemplArrElemType *theArray) 00138 { 00139 ML_TRACE_IN("template STLVectorFromFixedSizeVTKArray()") 00140 00141 typename std::vector<TemplArrElemType> stlVector; 00142 for (size_t i=0; i<TemplArrSize; ++i){ stlVector.push_back(theArray[i]); } 00143 return stlVector; 00144 } 00145 00146 ML_END_NAMESPACE 00147 00148 #endif // __mlVTKCommonToolFunctions_H 00149