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.
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. *
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. *
27 \*---------------------------------------------------------------------------*/
28 /*---------------------------------------------------------------------------*\
36 \*---------------------------------------------------------------------------*/
38 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
45 #include "OSGConfig.h"
47 #include "OSGStatElemDesc.h"
50 #include "OSGBaseInitFunctions.h"
51 #include "OSGStringUtils.h"
55 /***************************************************************************\
57 \***************************************************************************/
59 /***************************************************************************\
61 \***************************************************************************/
63 StatElemDescBase::DescStorage
*StatElemDescBase::_descVec
= NULL
;
65 /***************************************************************************\
67 \***************************************************************************/
71 /*-------------------------------------------------------------------------*\
73 \*-------------------------------------------------------------------------*/
75 /*! Returns the descriptor with the given \a name, or NULL if no such
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
];
101 /*-------------------------------------------------------------------------*\
103 \*-------------------------------------------------------------------------*/
105 /*-------------------------------------------------------------------------*\
107 \*-------------------------------------------------------------------------*/
110 /***************************************************************************\
112 \***************************************************************************/
114 /*-------------------------------------------------------------------------*\
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.
130 StatElemDescBase::StatElemDescBase(const Char8
*name
,
131 const Char8
*description
,
135 _description(description
),
138 StatElemDescBase
*desc
= 0;
142 desc
= findDescByName(name
);
146 _descVec
= new DescStorage
;
148 addPostFactoryExitFunction(&StatElemDescBase::terminate
);
153 FFATAL(("Attempt to register the StatElemDescBase name %s a second "
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
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",
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)
208 /*-------------------------- assignment -----------------------------------*/
210 /*! \brief Assignment.
213 StatElemDescBase
& StatElemDescBase::operator = (const StatElemDescBase
&source
)
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
;