changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / Statistics / OSGStatRealElem.cpp
blob3eddc93aa1b3b09f9b453fede976e93371238805
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"
48 #include "OSGStatRealElem.h"
49 #include "OSGSysFieldTraits.h"
51 #include <boost/format.hpp>
53 OSG_USING_NAMESPACE
56 /***************************************************************************\
57 * Description *
58 \***************************************************************************/
60 /*! \class OSG::StatRealElem
62 The StatIntElem keeps an Real32 value, see \ref PageSystemStatistics for
63 details.
66 /***************************************************************************\
67 * Instance methods *
68 \***************************************************************************/
70 /*------------- constructors & destructors --------------------------------*/
72 StatRealElem::StatRealElem(StatElemDescBase *desc) :
73 StatElem(desc),
74 _value (0.f )
78 StatElem *StatRealElem::create(StatElemDescBase *desc)
80 return new StatRealElem(desc);
83 StatRealElem::~StatRealElem(void)
87 /*------------------------------ access -----------------------------------*/
89 void StatRealElem::putToString(
90 std::string &str, const std::string &format) const
92 if(format.empty())
94 FieldTraits<Real32>::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("%per")) != std::string::npos)
106 formatCopy.replace(pos, 4, "%.2f");
107 val *= 100.f;
111 boost::format fmt(formatCopy);
113 fmt % val;
115 str = fmt.str();
119 bool StatRealElem::getFromCString(const Char8 *&inVal)
121 return FieldTraits<Real32>::getFromCString(_value, inVal);
124 Real64 StatRealElem::getValue(void) const
126 return static_cast<Real64>(get());
130 void StatRealElem::reset(void)
132 _value = 0.f;
135 /*-------------------------- assignment -----------------------------------*/
137 StatRealElem& StatRealElem::operator = (const StatRealElem &source)
139 if (this == &source)
140 return *this;
142 set(source.get());
144 return *this;
147 /*-------------------------- comparison -----------------------------------*/
149 bool StatRealElem::operator < (const StatRealElem &other) const
151 return this->get() < other.get();
154 /*--------------------------- creation ------------------------------------*/
156 StatElem *StatRealElem::clone(void) const
158 StatRealElem *e = new StatRealElem(getDesc());
160 *e = *this;
162 return e;
165 /*--------------------------- operators ------------------------------------*/
167 StatElem &StatRealElem::operator += (const StatElem &other)
169 const StatRealElem *o = dynamic_cast<const StatRealElem *>(&other);
171 _value += o->_value;
173 return *this;