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) :
82 StatCollector::StatCollector(const StatCollector
&source
) :
86 _elemVec
.resize(source
._elemVec
.size());
88 for(UInt32 i
= 0; i
< source
._elemVec
.size(); ++i
)
90 if(source
._elemVec
[i
])
92 _elemVec
[i
] = source
._elemVec
[i
]->clone();
101 StatCollector
*StatCollector::create(void)
103 return new StatCollector();
106 StatCollector::~StatCollector(void)
108 for(UInt32 i
= 0; i
< _elemVec
.size(); ++i
)
112 /*-------------------------- your_category---------------------------------*/
114 /*! Increase the size of the StatCollector's data array. This is called during
115 construction and will only be needed later, when a new StatElem has been
116 added after the StatCollector was instanced. This will very rarely be the
119 void StatCollector::refitElemNum(void)
121 SizeT eN
= _elemVec
.size();
122 SizeT dN
= StatElemDescBase::getNumOfDescs();
126 _elemVec
.resize(dN
, 0);
130 /*! Convert the current contents into a string. This
131 string can be used as a compact representation of the data, and as input
132 for StatCollector::getFromString.
134 void StatCollector::putToString(std::string
&str
) const
140 StatElemStoreConstIt it
= _elemVec
.begin();
141 StatElemStoreConstIt endIt
= _elemVec
.end();
143 for(; it
!= endIt
; ++it
)
152 str
.append((*it
)->getDesc()->getName().c_str());
154 (*it
)->putToString(elem
);
163 /*! Set the contents from a string. The string has to have the format that is
164 used by StatCollector::putToString.
166 bool StatCollector::getFromCString(const Char8
*&inVal
)
168 const Char8
*c
= inVal
;
173 StatElemDescBase
*desc
;
178 while(*c
&& *c
!= '}')
180 const Char8
*end
= c
;
182 while(*end
!= 0 && *end
!= '=' && *end
!= '}' && *end
!= '|')
185 if(*end
== 0 || *end
== '}' || *end
== '|')
188 std::string
name(c
, end
- c
);
189 desc
= StatElemDescBase::findDescByName(name
.c_str());
194 elem
= getElem(*desc
);
197 while(*end
!= 0 && *end
!= '}' && *end
!= '|')
203 std::string
val(c
, end
- c
);
204 const Char8
*valp
= val
.c_str();
205 if(!elem
->getFromCString(valp
))
213 /*! Get the value of the named element, if it exists, return false if not.
216 bool StatCollector::getValue(std::string
&name
, Real64
&val
)
218 StatElemDescBase
*desc
= StatElemDescBase::findDescByName(name
.c_str());
223 StatElem
*el
= getElem(*desc
, false);
228 val
= el
->getValue();
233 /*! Remove all elements from the collector.
235 void StatCollector::clearElems(void)
237 StatElemStoreIt it
= _elemVec
.begin();
238 StatElemStoreConstIt endIt
= _elemVec
.end();
240 for(; it
!= endIt
; ++it
)
252 /*! Reset all elements to the start value.
254 void StatCollector::reset(StatElemDescBase::ResetMode mode
)
256 StatElemStoreIt it
= _elemVec
.begin();
257 StatElemStoreConstIt endIt
= _elemVec
.end();
259 for(; it
!= endIt
; ++it
)
261 if(*it
!= NULL
&& (*it
)->getDesc()->getResetMode() >= mode
)
268 /*-------------------------- assignment -----------------------------------*/
270 const StatCollector
&StatCollector::operator = (const StatCollector
&source
)
275 _elemVec
= source
._elemVec
;
280 /*-------------------------- comparison -----------------------------------*/
282 /*! The comparison is only done on the addresses, as a real comparison is not
283 well defined on a StatCollector.
285 bool StatCollector::operator < (const StatCollector
&other
) const
287 return this < &other
;
290 bool StatCollector::operator == (const StatCollector
&rhs
) const
295 StatCollector
StatCollector::operator + (const StatCollector
&other
)
297 StatCollector
res(*this);
304 StatCollector
&StatCollector::operator += (const StatCollector
&other
)
306 if(other
._elemVec
.size() > _elemVec
.size())
308 _elemVec
.resize(other
._elemVec
.size());
311 for(UInt32 i
= 0; i
< _elemVec
.size(); ++i
)
315 *_elemVec
[i
] += *other
._elemVec
[i
];
324 #include "OSGSField.h"
325 #include "OSGSField.ins"
327 #include "OSGMField.h"
328 #include "OSGMField.ins"
330 #include "OSGFieldContainer.h"
336 /*-------------------------- field instantiations -------------------------*/
338 DataType FieldTraits
<StatCollectorP
>::_type("StatCollectorP",
342 DataType
&FieldTraits
<StatCollectorP
>::getType(void)
348 OSG_FIELD_DLLEXPORT_DEF1(SField
, StatCollectorP
);