osg::StatCollector Class Reference
[Statistics]

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

#include <OSGStatCollector.h>

List of all members.

Constructor



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

Public Member Functions

Instance


UInt32 getNumOfElems (void) const
void refitElemNum (void)
void clearElems (void)
bool isValidID (Int32 elemId) const
void reset (void)
StatElemgetElem (Int32 elemId) const
StatElemgetElem (Int32 elemId, 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
Operators


StatCollector operator+ (const StatCollector &other)
StatCollectoroperator+= (const StatCollector &other)

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   )  const [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 osg::SimpleStatisticsForeground::clearElems(), and 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     
00241     _elemVec.clear();
00242 }

bool osg::StatCollector::isValidID ( Int32  elemId  )  const [inline]

Definition at line 49 of file OSGStatCollector.inl.

References _elemVec.

Referenced by getElem().

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

void StatCollector::reset ( void   ) 

Reset all elements to the start value.

Definition at line 247 of file OSGStatCollector.cpp.

References _elemVec.

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

00248 {
00249     for(std::vector<StatElem*>::iterator i = _elemVec.begin(); 
00250         i != _elemVec.end();
00251         ++i)
00252     {
00253         if(*i != NULL)
00254         {
00255             (*i)->reset();
00256         }
00257     }
00258 }

StatElem * osg::StatCollector::getElem ( Int32  elemId  )  const [inline]

Return a pointer to the StatElem for the id. It will returnn NULL if the element doesn't exist yet.

Definition at line 90 of file OSGStatCollector.inl.

References _elemVec, and isValidID().

Referenced by osg::TextureChunk::activate(), osg::CubeTextureChunk::activate(), osg::PriorityAction::beginEditStateEvent(), osg::DepthFirstStateAction::beginEditStateEvent(), osg::TextureChunk::changeFrom(), osg::CubeTextureChunk::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::isOccluded(), 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().

00091 {
00092     return isValidID(elemId) ? _elemVec[elemId] : NULL;
00093 }

StatElem * osg::StatCollector::getElem ( Int32  elemId,
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(), isValidID(), and refitElemNum().

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

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

Definition at line 96 of file OSGStatCollector.inl.

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

00097 {
00098     return getElem(desc.getID(), create);
00099 }

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

Definition at line 103 of file OSGStatCollector.inl.

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

00104 {
00105     return reinterpret_cast < T * > (getElem(desc.getID(), create));
00106 }

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::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::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 }

const StatCollector & StatCollector::operator= ( const StatCollector source  ) 

Definition at line 262 of file OSGStatCollector.cpp.

References _elemVec.

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

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 277 of file OSGStatCollector.cpp.

00278 {
00279     return this < &other;
00280 }

StatCollector StatCollector::operator+ ( const StatCollector other  ) 

Definition at line 283 of file OSGStatCollector.cpp.

00284 {
00285     StatCollector res(*this);
00286     
00287     res += other;
00288     
00289     return res;
00290 }

StatCollector & StatCollector::operator+= ( const StatCollector other  ) 

Definition at line 292 of file OSGStatCollector.cpp.

References _elemVec.

00293 {
00294     if(other._elemVec.size() > _elemVec.size())
00295     {
00296         _elemVec.resize(other._elemVec.size());
00297     }
00298     
00299     for(UInt32 i = 0; i < _elemVec.size(); ++i)
00300     {
00301         if(_elemVec[i])
00302         {
00303             *_elemVec[i] += *other._elemVec[i];
00304         }
00305     }
00306     
00307     return *this;
00308 }


Member Data Documentation

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


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:15:07 2008 for OpenSG by  doxygen 1.5.5