Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGStandardStringConversionState.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifdef OSG_DOC_FILES_IN_MODULE
00040 
00043 #endif
00044 
00045 //---------------------------------------------------------------------------
00046 //  Includes
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 /*                            Constructors                                 */
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 /*                             Destructor                                  */
00080 
00081 StandardStringConversionState::~StandardStringConversionState(void)
00082 {
00083 }
00084 
00085 
00086 /*-------------------------------------------------------------------------*/
00087 /*                             Handle Fields                               */
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 /*                              cvs id's                                   */
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 }

Generated on Thu Aug 25 04:10:38 2005 for OpenSG by  doxygen 1.4.3