changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / Statistics / OSGStatTimeStampElem.cpp
blob99a2c6d3d4dfe2d6c81c13511a0588db53b4592f
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 "OSGStatTimeStampElem.h"
51 #include <boost/format.hpp>
53 OSG_USING_NAMESPACE
56 /***************************************************************************\
57 * Description *
58 \***************************************************************************/
60 /*! \class OSG::StatTimeStampElem
62 The StatIntElem keeps a OSG::Time value for time measurements,
63 see \ref PageSystemStatistics for details.
66 /***************************************************************************\
67 * Instance methods *
68 \***************************************************************************/
70 /*------------- constructors & destructors --------------------------------*/
72 StatTimeStampElem::StatTimeStampElem(StatElemDescBase *desc) :
73 Inherited(desc),
74 _time ( 0)
78 StatElem *StatTimeStampElem::create(StatElemDescBase *desc)
80 return new StatTimeStampElem(desc);
84 StatTimeStampElem::~StatTimeStampElem(void)
88 /*------------------------------ access -----------------------------------*/
90 void StatTimeStampElem::putToString(
91 std::string &str, const std::string &format) const
93 Real64 time = getTimeStampMsecs(_time) / 1000.;
95 if(format.empty())
97 // Confusing if %e is used.
99 Char8 temp[64];
101 sprintf(temp, "%f", Real32(_time));
103 str.assign(temp);
105 else
107 std::string formatCopy = format;
108 std::string::size_type pos = formatCopy.find("%");
110 if(pos != std::string::npos)
112 if((pos = formatCopy.find("%ms")) != std::string::npos)
114 formatCopy.replace(pos, 3, "%.2f");
115 time *= 1000.f;
117 else if((pos = formatCopy.find("%r")) != std::string::npos)
119 formatCopy.replace(pos, 2, "%.2f");
120 time = 1.f / time;
124 boost::format fmt(formatCopy);
126 fmt % time;
128 str = fmt.str();
132 bool StatTimeStampElem::getFromCString(const Char8 *&inVal)
134 return FieldTraits<TimeStamp>::getFromCString(_time, inVal);
137 Real64 StatTimeStampElem::getValue(void) const
139 return static_cast<Real64>(getTime());
142 void StatTimeStampElem::reset(void)
144 // Time elements need to be started and stopped and can't be reset
147 /*-------------------------- assignment -----------------------------------*/
149 StatTimeStampElem& StatTimeStampElem::operator = (
150 const StatTimeStampElem &source)
152 if (this == &source)
153 return *this;
155 _time = source._time;
157 return *this;
160 /*-------------------------- comparison -----------------------------------*/
162 bool StatTimeStampElem::operator < (const StatTimeStampElem &other) const
164 return _time < other._time;
167 /*--------------------------- creation ------------------------------------*/
169 StatElem *StatTimeStampElem::clone(void) const
171 StatTimeStampElem *e = new StatTimeStampElem(getDesc());
173 *e = *this;
175 return e;
178 /*--------------------------- operators ------------------------------------*/
180 StatElem &StatTimeStampElem::operator += (const StatElem &other)
182 const StatTimeStampElem *o =
183 dynamic_cast<const StatTimeStampElem *>(&other);
185 _time += o->_time;
187 return *this;