00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifdef OSG_DOC_FILES_IN_MODULE
00040
00043 #endif
00044
00045
00046
00047
00048
00049 #include <stdlib.h>
00050 #include <stdio.h>
00051
00052 #include "OSGConfig.h"
00053
00054 #include "OSGStandardStringConversionState.h"
00055
00056 OSG_USING_NAMESPACE
00057
00058
00059
00060
00061
00062 StandardStringConversionState::StandardStringConversionState(UInt32 indent,
00063 UInt32 width ) :
00064 Inherited ( ),
00065
00066 _indent (indent),
00067 _width (width ),
00068
00069 _lineLength ( 0),
00070 _noLineBreakHint(false ),
00071 _multiFieldHint (false ),
00072 _mfSeparator (", " ),
00073 _mfSepLength ( 2),
00074 _lastMFSepStart ( 0)
00075 {
00076 }
00077
00078
00079
00080
00081 StandardStringConversionState::~StandardStringConversionState(void)
00082 {
00083 }
00084
00085
00086
00087
00088
00093 std::string &StandardStringConversionState::beginField(
00094 const Field *pF,
00095 std::string &outStr)
00096 {
00097 _lineLength = 0;
00098 _lastMFSepStart = 0;
00099
00100 if(pF->getCardinality() == FieldType::MULTI_FIELD)
00101 {
00102 _multiFieldHint = true;
00103 }
00104 else
00105 {
00106 _multiFieldHint = false;
00107 }
00108
00109 if(strstr(pF->getContentType().getCName(), "String") != NULL)
00110 {
00111 _noLineBreakHint = true;
00112 }
00113 else
00114 {
00115 _noLineBreakHint = false;
00116 }
00117
00118 outStr.append(_indent.str());
00119 return outStr;
00120 }
00121
00126 std::string &StandardStringConversionState::addValueStr(std::string &value,
00127 std::string &outStr)
00128 {
00129 UInt32 valLength = value.length();
00130
00131 if(_noLineBreakHint)
00132 {
00133 if(_lineLength+valLength > _width)
00134 {
00135 outStr.append("\n");
00136 _lineLength = 0;
00137 outStr.append(_indent.str());
00138 }
00139
00140 outStr.append(value);
00141 _lineLength += valLength;
00142 }
00143 else
00144 {
00145 StringTokenizer tokens(value);
00146 std::string token;
00147
00148 bool first = true;
00149
00150 while(tokens.hasNext() == true)
00151 {
00152 token = tokens.getNext();
00153 UInt32 tokenLength = token.length();
00154
00155 if(_lineLength + tokenLength > _width)
00156 {
00157 outStr.append("\n");
00158 _lineLength = 0;
00159 outStr.append(_indent.str());
00160 first = true;
00161 }
00162
00163 if(first == true)
00164 {
00165 first = false;
00166 }
00167 else
00168 {
00169 outStr.append(" ");
00170 }
00171
00172 outStr.append(token);
00173
00174 _lineLength += tokenLength+1;
00175 }
00176 }
00177
00178 if(_multiFieldHint == true)
00179 {
00180 _lastMFSepStart = outStr.length();
00181 outStr.append(_mfSeparator);
00182 _lineLength += _mfSepLength;
00183 }
00184
00185 return outStr;
00186 }
00187
00188
00193 std::string &StandardStringConversionState::endField(
00194 const Field *OSG_CHECK_ARG(pF),
00195 std::string &outStr)
00196 {
00197 if(_multiFieldHint == true)
00198 {
00199 outStr = outStr.erase(_lastMFSepStart, _mfSepLength);
00200 }
00201
00202 return outStr;
00203 }
00204
00205
00206
00207
00208
00209 #ifdef __sgi
00210 #pragma set woff 1174
00211 #endif
00212
00213 #ifdef OSG_LINUX_ICC
00214 #pragma warning( disable : 177 )
00215 #endif
00216
00217 namespace
00218 {
00219 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00220 static Char8 cvsid_hpp[] = OSGSTANDARDSTRINGCONVERSIONSTATE_HEADER_CVSID;
00221 static Char8 cvsid_inl[] = OSGSTANDARDSTRINGCONVERSIONSTATE_INLINE_CVSID;
00222 }