1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGStatElemDesc.h"
49 #include "OSGStatElem.h"
51 #include "OSGStatCollector.h"
55 /***************************************************************************\
57 \***************************************************************************/
59 /*! \class OSG::StatCollector
61 The StatCollector is responsible for managing a set of OSG::StatElem
62 elements, see \ref PageSystemStatistics for details.
65 /***************************************************************************\
67 \***************************************************************************/
69 /*-------------------------------------------------------------------------*\
71 \*-------------------------------------------------------------------------*/
73 StatCollector::StatCollector(void) :
83 StatCollector::StatCollector(const StatCollector
&source
) :
87 _elemVec
.resize(source
._elemVec
.size());
89 for(UInt32 i
= 0; i
< source
._elemVec
.size(); ++i
)
91 if(source
._elemVec
[i
])
93 _elemVec
[i
] = source
._elemVec
[i
]->clone();
102 StatCollector
*StatCollector::create(void)
104 return new StatCollector();
107 StatCollector::~StatCollector(void)
109 for(UInt32 i
= 0; i
< _elemVec
.size(); ++i
)
113 /*-------------------------- your_category---------------------------------*/
115 /*! Increase the size of the StatCollector's data array. This is called during
116 construction and will only be needed later, when a new StatElem has been
117 added after the StatCollector was instanced. This will very rarely be the
120 void StatCollector::refitElemNum(void)
122 SizeT eN
= _elemVec
.size();
123 SizeT dN
= StatElemDescBase::getNumOfDescs();
127 _elemVec
.resize(dN
, 0);
131 /*! Convert the current contents into a string. This
132 string can be used as a compact representation of the data, and as input
133 for StatCollector::getFromString.
135 void StatCollector::putToString(std::string
&str
) const
141 StatElemStoreConstIt it
= _elemVec
.begin();
142 StatElemStoreConstIt endIt
= _elemVec
.end();
144 for(; it
!= endIt
; ++it
)
153 str
.append((*it
)->getDesc()->getName().c_str());
155 (*it
)->putToString(elem
);
164 /*! Set the contents from a string. The string has to have the format that is
165 used by StatCollector::putToString.
167 bool StatCollector::getFromCString(const Char8
*&inVal
)
169 const Char8
*c
= inVal
;
174 StatElemDescBase
*desc
;
179 while(*c
&& *c
!= '}')
181 const Char8
*end
= c
;
183 while(*end
!= 0 && *end
!= '=' && *end
!= '}' && *end
!= '|')
186 if(*end
== 0 || *end
== '}' || *end
== '|')
189 std::string
name(c
, end
- c
);
190 desc
= StatElemDescBase::findDescByName(name
.c_str());
195 elem
= getElem(*desc
);
198 while(*end
!= 0 && *end
!= '}' && *end
!= '|')
204 std::string
val(c
, end
- c
);
205 const Char8
*valp
= val
.c_str();
206 if(!elem
->getFromCString(valp
))
214 /*! Get the value of the named element, if it exists, return false if not.
217 bool StatCollector::getValue(std::string
&name
, Real64
&val
)
219 StatElemDescBase
*desc
= StatElemDescBase::findDescByName(name
.c_str());
224 StatElem
*el
= getElem(*desc
, false);
229 val
= el
->getValue();
234 /*! Remove all elements from the collector.
236 void StatCollector::clearElems(void)
238 StatElemStoreIt it
= _elemVec
.begin();
239 StatElemStoreConstIt endIt
= _elemVec
.end();
241 for(; it
!= endIt
; ++it
)
253 /*! Reset all elements to the start value.
255 void StatCollector::reset(StatElemDescBase::ResetMode mode
)
257 StatElemStoreIt it
= _elemVec
.begin();
258 StatElemStoreConstIt endIt
= _elemVec
.end();
260 for(; it
!= endIt
; ++it
)
262 if(*it
!= NULL
&& (*it
)->getDesc()->getResetMode() >= mode
)
269 /*-------------------------- assignment -----------------------------------*/
271 const StatCollector
&StatCollector::operator = (const StatCollector
&source
)
276 _elemVec
= source
._elemVec
;
281 /*-------------------------- comparison -----------------------------------*/
283 /*! The comparison is only done on the addresses, as a real comparison is not
284 well defined on a StatCollector.
286 bool StatCollector::operator < (const StatCollector
&other
) const
288 return this < &other
;
291 bool StatCollector::operator == (const StatCollector
&rhs
) const
296 StatCollector
StatCollector::operator + (const StatCollector
&other
)
298 StatCollector
res(*this);
305 StatCollector
&StatCollector::operator += (const StatCollector
&other
)
307 if(other
._elemVec
.size() > _elemVec
.size())
309 _elemVec
.resize(other
._elemVec
.size());
312 for(UInt32 i
= 0; i
< _elemVec
.size(); ++i
)
316 *_elemVec
[i
] += *other
._elemVec
[i
];
325 #include "OSGSField.h"
326 #include "OSGSField.ins"
328 #include "OSGMField.h"
329 #include "OSGMField.ins"
331 #include "OSGFieldContainer.h"
337 /*-------------------------- field instantiations -------------------------*/
339 DataType FieldTraits
<StatCollectorP
>::_type("StatCollectorP",
343 DataType
&FieldTraits
<StatCollectorP
>::getType(void)
349 OSG_FIELD_DLLEXPORT_DEF1(SField
, StatCollectorP
)