changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / Statistics / OSGStatIntElem.cpp
blob489bad0d01dd2efdae5902f1890ee4dcb6fbc1b4
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
47 #include "OSGSysFieldTraits.h"
49 #include "OSGStatIntElem.h"
51 #include <boost/format.hpp>
53 OSG_USING_NAMESPACE
56 /***************************************************************************\
57 * Description *
58 \***************************************************************************/
60 /*! \class OSG::StatIntElem
62 The StatIntElem keeps an Int32 counter, see \ref PageSystemStatistics for
63 details.
66 /***************************************************************************\
67 * Instance methods *
68 \***************************************************************************/
70 /*------------- constructors & destructors --------------------------------*/
72 StatIntElem::StatIntElem(StatElemDescBase *desc) :
73 StatElem(desc),
74 _value ( 0)
78 StatElem *StatIntElem::create(StatElemDescBase *desc)
80 return new StatIntElem(desc);
83 StatIntElem::~StatIntElem(void)
87 /*------------------------------ access -----------------------------------*/
89 void StatIntElem::putToString(
90 std::string &str, const std::string &format) const
92 if(format.empty())
94 FieldTraits<Int32>::putToString(_value, str);
96 else
98 std::string formatCopy = format;
99 std::string::size_type pos = formatCopy.find("%");
100 Real32 val = _value;
102 if(pos != std::string::npos)
104 if((pos = formatCopy.find("%KB")) != std::string::npos)
106 formatCopy.replace(pos, 3, "%.2f");
107 val /= 1024.f;
109 else if((pos = formatCopy.find("%MB")) != std::string::npos)
111 formatCopy.replace(pos, 3, "%.2f");
112 val /= 1024.f * 1024.f;
114 else if((pos = formatCopy.find("%GB")) != std::string::npos)
116 formatCopy.replace(pos, 3, "%.2f");
117 val /= 1024.f * 1024.f * 1024.f;
121 boost::format fmt(formatCopy);
123 fmt % val;
125 str = fmt.str();
129 bool StatIntElem::getFromCString(const Char8 *&inVal)
131 return FieldTraits<Int32>::getFromCString(_value, inVal);
134 Real64 StatIntElem::getValue(void) const
136 return static_cast<Real64>(get());
139 void StatIntElem::reset(void)
141 _value = 0;
144 /*-------------------------- assignment -----------------------------------*/
146 StatIntElem& StatIntElem::operator = (const StatIntElem &source)
148 if (this == &source)
149 return *this;
151 set(source.get());
153 return *this;
156 /*-------------------------- comparison -----------------------------------*/
158 bool StatIntElem::operator < (const StatIntElem &other) const
160 return this->get() < other.get();
163 /*--------------------------- creation ------------------------------------*/
165 StatElem *StatIntElem::clone(void) const
167 StatIntElem *e = new StatIntElem(getDesc());
169 *e = *this;
171 return e;
174 /*--------------------------- operators ------------------------------------*/
176 StatElem &StatIntElem::operator += (const StatElem &other)
178 const StatIntElem *o = dynamic_cast<const StatIntElem *>(&other);
180 _value += o->_value;
182 return *this;