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 "OSGStatIntElem.h"
51 #include <boost/format.hpp>
56 /***************************************************************************\
58 \***************************************************************************/
60 /*! \class OSG::StatIntElem
62 The StatIntElem keeps an Int32 counter, see \ref PageSystemStatistics for
66 /***************************************************************************\
68 \***************************************************************************/
70 /*------------- constructors & destructors --------------------------------*/
72 StatIntElem::StatIntElem(StatElemDescBase
*desc
) :
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
94 FieldTraits
<Int32
>::putToString(_value
, str
);
98 std::string formatCopy
= format
;
99 std::string::size_type pos
= formatCopy
.find("%");
102 if(pos
!= std::string::npos
)
104 if((pos
= formatCopy
.find("%KB")) != std::string::npos
)
106 formatCopy
.replace(pos
, 3, "%.2f");
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
);
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)
144 /*-------------------------- assignment -----------------------------------*/
146 StatIntElem
& StatIntElem::operator = (const StatIntElem
&source
)
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());
174 /*--------------------------- operators ------------------------------------*/
176 StatElem
&StatIntElem::operator += (const StatElem
&other
)
178 const StatIntElem
*o
= dynamic_cast<const StatIntElem
*>(&other
);