changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / Statistics / OSGStatElemDesc.cpp
blob133af0afb60322a189155da86839130ecb3a4f64
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 * This library is distributed in the hope that it will be useful, but *
19 * WITHOUT ANY WARRANTY; without even the implied warranty of *
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
21 * Library General Public License for more details. *
22 * *
23 * You should have received a copy of the GNU Library General Public *
24 * License along with this library; if not, write to the Free Software *
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
26 * *
27 \*---------------------------------------------------------------------------*/
28 /*---------------------------------------------------------------------------*\
29 * Changes *
30 * *
31 * *
32 * *
33 * *
34 * *
35 * *
36 \*---------------------------------------------------------------------------*/
38 //---------------------------------------------------------------------------
39 // Includes
40 //---------------------------------------------------------------------------
42 #include <cstdlib>
43 #include <cstdio>
45 #include "OSGConfig.h"
47 #include "OSGStatElemDesc.h"
49 #include "OSGLog.h"
50 #include "OSGBaseInitFunctions.h"
51 #include "OSGStringUtils.h"
53 OSG_USING_NAMESPACE
55 /***************************************************************************\
56 * Types *
57 \***************************************************************************/
59 /***************************************************************************\
60 * Class variables *
61 \***************************************************************************/
63 StatElemDescBase::DescStorage *StatElemDescBase::_descVec = NULL;
65 /***************************************************************************\
66 * Class methods *
67 \***************************************************************************/
71 /*-------------------------------------------------------------------------*\
72 - public -
73 \*-------------------------------------------------------------------------*/
75 /*! Returns the descriptor with the given \a name, or NULL if no such
76 descriptor is found.
78 \param[in] name Name of the descriptor to return.
79 \return Descriptor with the given name, or NULL if it is not found.
81 StatElemDescBase *StatElemDescBase::findDescByName(const Char8 *name)
83 SizeT n = _descVec ? _descVec->size() : 0;
84 StatElemDescBase *desc = 0;
86 if(name && *name && n)
88 for(SizeT i = 0; i < n; ++i)
90 if (!osgStringCmp(name, (*_descVec)[i]->_name.c_str()))
92 desc = (*_descVec)[i];
93 break;
98 return desc;
101 /*-------------------------------------------------------------------------*\
102 - protected -
103 \*-------------------------------------------------------------------------*/
105 /*-------------------------------------------------------------------------*\
106 - private -
107 \*-------------------------------------------------------------------------*/
110 /***************************************************************************\
111 * Instance methods *
112 \***************************************************************************/
114 /*-------------------------------------------------------------------------*\
115 - public -
116 \*-------------------------------------------------------------------------*/
118 /*------------- constructors & destructors --------------------------------*/
120 /*! \brief Constructor.
121 Creates a descriptor with the given name and description. The descriptor
122 is assigned a unique id, that can be obtained with getId().
123 It is an error to create two descriptors with the same name.
125 \param[in] name Name for the descriptor; must be unique.
126 \param[in] description Description of the purpose of the StatElem, this
127 descriptor belongs to.
128 \param[in] reset
130 StatElemDescBase::StatElemDescBase(const Char8 *name,
131 const Char8 *description,
132 ResetMode reset) :
133 _id ( -1),
134 _name ( name),
135 _description(description),
136 _resetMode (reset)
138 StatElemDescBase *desc = 0;
140 if(_descVec)
142 desc = findDescByName(name);
144 else
146 _descVec = new DescStorage;
148 addPostFactoryExitFunction(&StatElemDescBase::terminate);
151 if(desc)
153 FFATAL(("Attempt to register the StatElemDescBase name %s a second "
154 "time\n", name));
156 else
158 _id = Int32(_descVec->size());
159 _descVec->push_back(this);
163 /*! \brief Destructor.
164 It destroys the descriptor object, but the name and id are still reserved,
165 so you still can not create a new descriptor with the same name.
167 StatElemDescBase::~StatElemDescBase(void)
171 /*! Prints information about all registered descriptors, by calling their
172 print() method.
174 void StatElemDescBase::printAll(void)
176 SizeT n = _descVec ? _descVec->size() : 0;
178 for(SizeT i = 0; i < n; i++)
179 (*_descVec)[i]->print();
182 /*! Print information about this descriptor, i.e. its id, name and description.
184 void StatElemDescBase::print(void)
186 FLOG(( "StatElemDescBase: ID/Name/Description: %d/%s/%s\n",
187 _id,
188 _name.c_str(),
189 _description.c_str()));
192 /*------------------------------ access -----------------------------------*/
194 /*---------------------------- properties ---------------------------------*/
196 /*-------------------------- your_category---------------------------------*/
198 /*! Destroys the storage for the registered descriptors.
199 \warning This is and should only be called during system shutdown.
201 bool StatElemDescBase::terminate(void)
203 delete _descVec;
205 return true;
208 /*-------------------------- assignment -----------------------------------*/
210 /*! \brief Assignment.
211 This is a no-op.
213 StatElemDescBase& StatElemDescBase::operator = (const StatElemDescBase &source)
215 if (this == &source)
216 return *this;
218 return *this;
221 /*-------------------------- comparison -----------------------------------*/
223 /*! \brief Less comparison.
224 Compares the address of this agains \a other.
226 bool StatElemDescBase::operator < (const StatElemDescBase &other) const
228 return this < &other;