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 "OSGStatIntOnceElem.h"
51 #include <boost/format.hpp>
56 /***************************************************************************\
58 \***************************************************************************/
60 /*! \class OSG::StatIntOnceElem
62 The StatIntOnceElem is similar to the OSG::StatIntElem, but it keeps
63 track of who has contributed already and only allows each ID to
64 contribute once. \ref PageSystemStatistics for details.
67 /***************************************************************************\
69 \***************************************************************************/
71 /*------------- constructors & destructors --------------------------------*/
73 StatIntOnceElem::StatIntOnceElem(StatElemDescBase
*desc
) :
80 StatElem
*StatIntOnceElem::create(StatElemDescBase
*desc
)
82 return new StatIntOnceElem(desc
);
86 StatIntOnceElem::~StatIntOnceElem(void)
90 /*------------------------------ access -----------------------------------*/
92 void StatIntOnceElem::putToString(
93 std::string
&str
, const std::string
&format
) const
97 FieldTraits
<Int64
>::putToString(_value
, str
);
101 std::string formatCopy
= format
;
102 std::string::size_type pos
= formatCopy
.find("%");
105 if(pos
!= std::string::npos
)
107 if((pos
= formatCopy
.find("%KB")) != std::string::npos
)
109 formatCopy
.replace(pos
, 3, "%.2f");
112 else if((pos
= formatCopy
.find("%MB")) != std::string::npos
)
114 formatCopy
.replace(pos
, 3, "%.2f");
115 val
/= 1024.f
* 1024.f
;
117 else if((pos
= formatCopy
.find("%GB")) != std::string::npos
)
119 formatCopy
.replace(pos
, 3, "%.2f");
120 val
/= 1024.f
* 1024.f
* 1024.f
;
124 boost::format
fmt(formatCopy
);
132 bool StatIntOnceElem::getFromCString(const Char8
*&inVal
)
134 return FieldTraits
<Int64
>::getFromCString(_value
, inVal
);
137 Real64
StatIntOnceElem::getValue(void) const
139 return static_cast<Real64
>(get());
142 void StatIntOnceElem::reset(void)
149 /*-------------------------- assignment -----------------------------------*/
151 StatIntOnceElem
& StatIntOnceElem::operator = (const StatIntOnceElem
&source
)
156 _value
= source
._value
;
162 /*-------------------------- comparison -----------------------------------*/
164 bool StatIntOnceElem::operator < (const StatIntOnceElem
&other
) const
166 return this->get() < other
.get();
169 /*--------------------------- creation ------------------------------------*/
171 StatElem
*StatIntOnceElem::clone(void) const
173 StatIntOnceElem
*e
= new StatIntOnceElem(getDesc());
180 /*--------------------------- operators ------------------------------------*/
182 StatElem
&StatIntOnceElem::operator += (const StatElem
&other
)
184 const StatIntOnceElem
*o
= dynamic_cast<const StatIntOnceElem
*>(&other
);
188 IdHash::const_iterator it
= o
->_ids
.begin();
190 while(it
!= o
->_ids
.end())