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

osg::StatCollector Class Reference
[Statistics]

Manager for Stat elements, see Statistics for details. More...

#include <OSGStatCollector.h>

List of all members.

Constructor

StatCollector (void)
 StatCollector (const StatCollector &source)
StatCollectoroperator= (const StatCollector &source)
static StatCollectorcreate (void)

Public Member Functions

Instance
*UInt32 getNumOfElems (void)
void refitElemNum (void)
void clearElems (void)
bool isValidID (Int32 id)
void reset (void)
StatElemgetElem (Int32 id, bool create=true)
StatElemgetElem (StatElemDescBase &desc, bool create=true)
template<class T>
T * getElem (StatElemDesc< T > &desc, bool create=true)
void putToString (std::string &outVal) const
bool getFromString (const Char8 *&inVal)
bool getValue (std::string &name, Real64 &val)
Destructor
*virtual ~StatCollector (void)
Comparison
*bool operator< (const StatCollector &other) const

Static Public Member Functions

Class Get
*static const char * getClassname (void)

Private Attributes

std::vector< StatElem * > _elemVec


Detailed Description

The StatCollector is responsible for managing a set of osg::StatElem elements, see Statistics for details.

Definition at line 63 of file OSGStatCollector.h.


Constructor & Destructor Documentation

StatCollector::StatCollector void   ) 
 

Definition at line 78 of file OSGStatCollector.cpp.

References refitElemNum().

Referenced by create().

00079 {
00080     refitElemNum();
00081 }

StatCollector::StatCollector const StatCollector source  ) 
 

Definition at line 83 of file OSGStatCollector.cpp.

References _elemVec.

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 }

StatCollector::~StatCollector void   )  [virtual]
 

Definition at line 105 of file OSGStatCollector.cpp.

References _elemVec.

00106 {
00107     for(UInt32 i = 0; i < _elemVec.size(); ++i)
00108         delete _elemVec[i];
00109 }


Member Function Documentation

* static const char* osg::StatCollector::getClassname void   )  [inline, static]
 

Definition at line 73 of file OSGStatCollector.h.

00073 { return "StatCollector"; }

UInt32 osg::StatCollector::getNumOfElems void   )  [inline]
 

Definition at line 43 of file OSGStatCollector.inl.

References _elemVec.

Referenced by osg::SimpleStatisticsForeground::draw().

00044 {
00045     return _elemVec.size();
00046 }

void StatCollector::refitElemNum void   ) 
 

Increase the size of the StatCollector's data array. This is called during construction and will only be needed later, when a new StatElem has been added after the StatCollector was instanced. This will very rarely be the case.

Definition at line 117 of file OSGStatCollector.cpp.

References _elemVec, and osg::StatElemDescBase::getNumOfDescs().

Referenced by getElem(), and StatCollector().

00118 {
00119   unsigned eN = _elemVec.size(), dN = StatElemDescBase::getNumOfDescs();
00120 
00121   if(eN != dN)
00122   {
00123     _elemVec.resize(dN,0);
00124   }
00125 }

void StatCollector::clearElems void   ) 
 

Remove all elements from the collector.

Definition at line 228 of file OSGStatCollector.cpp.

References _elemVec.

Referenced by getFromString().

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 }

bool osg::StatCollector::isValidID Int32  id  )  [inline]
 

Definition at line 49 of file OSGStatCollector.inl.

References _elemVec.

00050 {
00051     return (id >= 0) && (id < Int32(_elemVec.size()));
00052 }

void StatCollector::reset void   ) 
 

Reset all elements to the start value.

Definition at line 245 of file OSGStatCollector.cpp.

References _elemVec.

Referenced by osg::RenderAction::start().

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 }

StatElem * osg::StatCollector::getElem Int32  id,
bool  create = true
[inline]
 

Return a pointer to the StatElem for the id. This function has two modes. By default it's careful and sets the create argument to true. In this case it checks whether the Collector already contains a StatElem for the given id and creates it if necessary. If you know that your Collector already contains that element (because you explicitly created it outside the testing loop) you can set it to false and speed up the whole function a bit.

Definition at line 65 of file OSGStatCollector.inl.

References _elemVec, osg::StatElemDescBase::createElem(), osg::StatElemDescBase::getDesc(), and refitElemNum().

Referenced by osg::TextureChunk::activate(), osg::PriorityAction::beginEditStateEvent(), osg::DepthFirstStateAction::beginEditStateEvent(), osg::TextureChunk::changeFrom(), osg::SimpleStatisticsForeground::draw(), osg::GraphicStatisticsForeground::draw(), osg::SpotLight::drawEnter(), osg::PointLight::drawEnter(), osg::DirectionalLight::drawEnter(), osg::Slices::drawPrimitives(), osg::Geometry::drawPrimitives(), getElem(), getFromString(), getValue(), osg::SimpleSceneManager::initialize(), osg::RenderAction::isVisible(), osg::DrawAction::isVisible(), osg::RenderAction::pushVisibility(), osg::RemoteAspect::receiveSync(), osg::SpotLight::renderEnter(), osg::PointLight::renderEnter(), osg::DirectionalLight::renderEnter(), osg::RemoteAspect::sendSync(), osg::DrawActionBase::start(), osg::PriorityAction::startEvent(), osg::NewActionBase::startEvent(), osg::DepthFirstStateAction::startEvent(), osg::RenderAction::stop(), osg::DrawActionBase::stop(), osg::PriorityAction::traverseEnter(), osg::DepthFirstStateAction::traverseEnter(), osg::DepthFirstAction::traverseEnter(), osg::DepthFirstStateAction::traverseEnterLeave(), and osg::DepthFirstAction::traverseEnterLeave().

00066 {
00067     if(create)
00068     {
00069         // This only happens when dynamically adding StatElems
00070         // but it's really nasty if it happens.
00071         if(id >= int(_elemVec.size())) 
00072             refitElemNum();
00073         
00074         StatElem *elem = _elemVec[id];
00075         if(elem == NULL)
00076         {
00077             StatElemDescBase    *desc = StatElemDescBase::getDesc(id);
00078             elem = _elemVec[id] = desc->createElem();
00079         }
00080         return elem;
00081     }
00082 
00083     return _elemVec[id];
00084 }

StatElem * osg::StatCollector::getElem StatElemDescBase desc,
bool  create = true
[inline]
 

Definition at line 87 of file OSGStatCollector.inl.

References getElem(), and osg::StatElemDescBase::getID().

00088 {
00089     return getElem(desc.getID(), create);
00090 }

template<class T>
T * osg::StatCollector::getElem StatElemDesc< T > &  desc,
bool  create = true
[inline]
 

Definition at line 94 of file OSGStatCollector.inl.

References getElem(), and osg::StatElemDescBase::getID().

00095 {
00096     return reinterpret_cast < T * > (getElem(desc.getID(), create));
00097 }

void StatCollector::putToString std::string &  str  )  const
 

Convert the current contents into a string. This string can be used as a compact representation of the data, and as input for StatCollector::getFromString.

Definition at line 131 of file OSGStatCollector.cpp.

References _elemVec.

Referenced by osg::FieldDataTraits< StatCollector >::putToString().

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 }

bool StatCollector::getFromString const Char8 *&  inVal  ) 
 

Set the contents from a string. The string has to have the format that is used by StatCollector::putToString.

Definition at line 160 of file OSGStatCollector.cpp.

References clearElems(), osg::StatElemDescBase::findDescByName(), getElem(), and osg::StatElem::getFromString().

Referenced by osg::FieldDataTraits< StatCollector >::getFromString().

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 }

bool StatCollector::getValue std::string &  name,
Real64 val
 

Get the value of the named element, if it exists, return false if not.

Definition at line 209 of file OSGStatCollector.cpp.

References osg::StatElemDescBase::findDescByName(), getElem(), and osg::StatElem::getValue().

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 }

StatCollector * StatCollector::create void   )  [static]
 

Definition at line 100 of file OSGStatCollector.cpp.

References StatCollector().

Referenced by osg::DrawActionBase::getStatistics(), osg::DrawActionBase::start(), and osg::NewActionBase::startEvent().

00101 {
00102     return new StatCollector();
00103 }

StatCollector & StatCollector::operator= const StatCollector source  ) 
 

Definition at line 260 of file OSGStatCollector.cpp.

References _elemVec.

00261 {
00262     if (this == &source)
00263         return *this;
00264 
00265     _elemVec = source._elemVec;
00266  
00267     return *this;
00268 }

bool StatCollector::operator< const StatCollector other  )  const
 

The comparison is only done on the addresses, as a real comparison is not well defined on a StatCollector.

Definition at line 275 of file OSGStatCollector.cpp.

00276 {
00277     return this < &other;
00278 }


Member Data Documentation

std::vector<StatElem*> osg::StatCollector::_elemVec [private]
 

Definition at line 141 of file OSGStatCollector.h.

Referenced by clearElems(), getElem(), getNumOfElems(), isValidID(), operator=(), putToString(), refitElemNum(), reset(), StatCollector(), and ~StatCollector().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:22:48 2005 for OpenSG by  doxygen 1.4.3