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

OSGStatCollector.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 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #define OSG_COMPILESTATCOLLECTORINST
00044 
00045 #include <stdlib.h>
00046 #include <stdio.h>
00047 
00048 #include "OSGConfig.h"
00049 
00050 #include "OSGStatElemDesc.h"
00051 #include "OSGStatElem.h"
00052 
00053 #include "OSGStatCollector.h"
00054 
00055 OSG_USING_NAMESPACE
00056 
00057 
00058 
00059 /***************************************************************************\
00060  *                            Description                                  *
00061 \***************************************************************************/
00062 
00070 /***************************************************************************\
00071  *                         Instance methods                                *
00072 \***************************************************************************/
00073 
00074 /*-------------------------------------------------------------------------*\
00075  -  public                                                                -
00076 \*-------------------------------------------------------------------------*/
00077 
00078 StatCollector::StatCollector(void)
00079 {
00080     refitElemNum();
00081 }
00082 
00083 StatCollector::StatCollector(const StatCollector &source)
00084 {
00085     _elemVec.resize(source._elemVec.size());
00086     
00087     for(UInt32 i = 0; i < source._elemVec.size(); ++i)
00088     {
00089         if(source._elemVec[i])
00090         {
00091             _elemVec[i] = source._elemVec[i]->clone();
00092         }
00093         else
00094         {
00095             _elemVec[i] = NULL;
00096         }
00097     }
00098 }
00099 
00100 StatCollector *StatCollector::create(void)
00101 {
00102     return new StatCollector();
00103 }
00104 
00105 StatCollector::~StatCollector(void)
00106 {
00107     for(UInt32 i = 0; i < _elemVec.size(); ++i)
00108         delete _elemVec[i];
00109 }
00110 
00111 /*-------------------------- your_category---------------------------------*/
00112 
00117 void StatCollector::refitElemNum(void)
00118 {
00119   unsigned eN = _elemVec.size(), dN = StatElemDescBase::getNumOfDescs();
00120 
00121   if(eN != dN)
00122   {
00123     _elemVec.resize(dN,0);
00124   }
00125 }
00126 
00131 void StatCollector::putToString(std::string &str) const
00132 {
00133     std::vector<StatElem*>::const_iterator it;
00134     bool first = true;
00135      
00136     str = "{";
00137     
00138     for(it = _elemVec.begin(); it != _elemVec.end(); ++it)
00139     {
00140         if(*it != NULL)
00141         {
00142             std::string elem;
00143             
00144             if(!first)
00145                 str.append("|");
00146             str.append((*it)->getDesc()->getName().str());
00147             str.append("=");
00148             (*it)->putToString(elem);
00149             str.append(elem);
00150             first = false;
00151         }
00152     }
00153     str.append("}");
00154 }
00155      
00156 
00160 bool StatCollector::getFromString(const Char8 *&inVal)
00161 {
00162     const Char8 *c = inVal;
00163     
00164     if(*c++ != '{')
00165         return false;
00166 
00167     StatElemDescBase *desc;
00168     StatElem *elem;
00169     
00170     clearElems();
00171     
00172     while(*c && *c != '}')
00173     {
00174         const Char8 *end = c;
00175         
00176         while(*end != 0 && *end != '=' && *end != '}' && *end != '|')
00177             end++;
00178             
00179         if(*end == 0 || *end == '}' || *end == '|')
00180             return false;
00181         
00182         std::string name(c, end - c);
00183         desc = StatElemDescBase::findDescByName(name.c_str());
00184         
00185         if(!desc)
00186             return false;
00187         
00188         elem = getElem(*desc);
00189 
00190         c = end = end + 1;       
00191         while(*end != 0 && *end != '}' && *end != '|')
00192             end++;
00193             
00194         if(*end == 0)
00195             return false;
00196 
00197         std::string val(c, end - c);
00198         const Char8 *valp = val.c_str();
00199         if(!elem->getFromString(valp))
00200             return false;
00201  
00202         c = end + 1;
00203     }
00204     return true;
00205 }
00206 
00209 bool StatCollector::getValue(std::string &name, Real64 &val)
00210 {
00211     StatElemDescBase *desc = StatElemDescBase::findDescByName(name.c_str());
00212     
00213     if(!desc)
00214         return false;
00215     
00216     StatElem *el = getElem(*desc, false);
00217     
00218     if(!el)
00219         return false;
00220     
00221     val = el->getValue();
00222     
00223     return true;
00224 }
00225 
00228 void StatCollector::clearElems(void)
00229 {
00230     for(std::vector<StatElem*>::iterator i = _elemVec.begin(); 
00231         i != _elemVec.end();
00232         ++i)
00233     {
00234         if(*i != NULL)
00235         {
00236             delete *i;
00237             *i = NULL;
00238         }
00239     }
00240 }
00241 
00242 
00245 void StatCollector::reset(void)
00246 {
00247     for(std::vector<StatElem*>::iterator i = _elemVec.begin(); 
00248         i != _elemVec.end();
00249         ++i)
00250     {
00251         if(*i != NULL)
00252         {
00253             (*i)->reset();
00254         }
00255     }
00256 }
00257 
00258 /*-------------------------- assignment -----------------------------------*/
00259 
00260 StatCollector& StatCollector::operator = (const StatCollector &source)
00261 {
00262     if (this == &source)
00263         return *this;
00264 
00265     _elemVec = source._elemVec;
00266  
00267     return *this;
00268 }
00269 
00270 /*-------------------------- comparison -----------------------------------*/
00271 
00275 bool StatCollector::operator < (const StatCollector &other) const
00276 {
00277     return this < &other;
00278 }
00279 
00280 
00281 #include <OSGMFieldTypeDef.inl>
00282 #include <OSGSFieldTypeDef.inl>
00283 
00284 OSG_BEGIN_NAMESPACE
00285 
00286 #ifndef OSG_DO_DOC
00287 
00288 /*-------------------------- field instantiations -------------------------*/
00289 
00290 DataType FieldDataTraits<StatCollector>::_type("StatCollector", 
00291                                                "None");
00292 
00293 #endif
00294 
00295 OSG_DLLEXPORT_SFIELD_DEF1(StatCollector, OSG_SYSTEMLIB_DLLTMPLMAPPING);
00296 
00297 OSG_END_NAMESPACE
00298 
00299 /*-------------------------------------------------------------------------*/
00300 /*                              cvs id's                                   */
00301 
00302 #ifdef __sgi
00303 #pragma set woff 1174
00304 #endif
00305 
00306 #ifdef OSG_LINUX_ICC
00307 #pragma warning( disable : 177 )
00308 #endif
00309 
00310 namespace
00311 {
00312     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00313     static Char8 cvsid_hpp[] = OSGSTATCOLLECTOR_HEADER_CVSID;
00314     static Char8 cvsid_inl[] = OSGSTATCOLLECTOR_INLINE_CVSID;
00315 }
00316 

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