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"
47 #include "OSGSysFieldTraits.h"
49 #include "OSGStatTimeStampElem.h"
51 #include <boost/format.hpp>
56 /***************************************************************************\
58 \***************************************************************************/
60 /*! \class OSG::StatTimeStampElem
62 The StatIntElem keeps a OSG::Time value for time measurements,
63 see \ref PageSystemStatistics for details.
66 /***************************************************************************\
68 \***************************************************************************/
70 /*------------- constructors & destructors --------------------------------*/
72 StatTimeStampElem::StatTimeStampElem(StatElemDescBase
*desc
) :
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.;
97 // Confusing if %e is used.
101 sprintf(temp
, "%f", Real32(_time
));
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");
117 else if((pos
= formatCopy
.find("%r")) != std::string::npos
)
119 formatCopy
.replace(pos
, 2, "%.2f");
124 boost::format
fmt(formatCopy
);
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
)
155 _time
= source
._time
;
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());
178 /*--------------------------- operators ------------------------------------*/
180 StatElem
&StatTimeStampElem::operator += (const StatElem
&other
)
182 const StatTimeStampElem
*o
=
183 dynamic_cast<const StatTimeStampElem
*>(&other
);