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 "OSGStatTimeElem.h"
49 #include "OSGBaseFieldTraits.h"
51 #include <boost/format.hpp>
56 /***************************************************************************\
58 \***************************************************************************/
60 /*! \class OSG::StatTimeElem
62 The StatIntElem keeps a OSG::Time value for time measurements,
63 see \ref PageSystemStatistics for details.
66 /***************************************************************************\
68 \***************************************************************************/
70 /*------------- constructors & destructors --------------------------------*/
72 StatTimeElem::StatTimeElem(StatElemDescBase
*desc
) :
79 StatElem
*StatTimeElem::create(StatElemDescBase
*desc
)
81 return new StatTimeElem(desc
);
85 StatTimeElem::~StatTimeElem(void)
89 /*------------------------------ access -----------------------------------*/
91 void StatTimeElem::putToString(
92 std::string
&str
, const std::string
&format
) const
96 // Confusing if %e is used.
100 sprintf(temp
, "%f", _time
);
106 std::string formatCopy
= format
;
107 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, "%");
120 if(val
<= TypeTraits
<Time
>::ZeroEps())
131 boost::format
fmt(formatCopy
);
139 bool StatTimeElem::getFromCString(const Char8
*&inVal
)
141 return FieldTraits
<Time
, 1>::getFromCString(_time
, inVal
);
144 Real64
StatTimeElem::getValue(void) const
146 return static_cast<Real64
>(getTime());
149 void StatTimeElem::reset(void)
154 /*-------------------------- assignment -----------------------------------*/
156 StatTimeElem
& StatTimeElem::operator = (const StatTimeElem
&source
)
161 _startTime
= source
._startTime
;
162 _time
= source
._time
;
167 /*-------------------------- comparison -----------------------------------*/
169 bool StatTimeElem::operator < (const StatTimeElem
&other
) const
171 return _time
< other
._time
;
174 /*--------------------------- creation ------------------------------------*/
176 StatElem
*StatTimeElem::clone(void) const
178 StatTimeElem
*e
= new StatTimeElem(getDesc());
185 /*--------------------------- operators ------------------------------------*/
187 StatElem
&StatTimeElem::operator += (const StatElem
&other
)
189 const StatTimeElem
*o
= dynamic_cast<const StatTimeElem
*>(&other
);