source: GTP/trunk/App/Demos/Geom/OgreStuff/include/CEGUI/CEGUIXMLAttributes.h @ 1092

Revision 1092, 9.1 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

Line 
1/************************************************************************
2    filename:   CEGUIXMLAttributes.h
3    created:    Sat Mar 12 2005
4    author:     Paul D Turner
5*************************************************************************/
6/*************************************************************************
7    Crazy Eddie's GUI System (http://www.cegui.org.uk)
8    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
9 
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2.1 of the License, or (at your option) any later version.
14 
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19 
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*************************************************************************/
24#ifndef _CEGUIXMLAttributes_h_
25#define _CEGUIXMLAttributes_h_
26
27#include "CEGUIBase.h"
28#include "CEGUIString.h"
29#include <map>
30
31// Start of CEGUI namespace section
32namespace CEGUI
33{
34    /*!
35    \brief
36        Class representing a block of attributes associated with an XML element.
37     */
38    class CEGUIEXPORT XMLAttributes
39    {
40    public:
41        /*!
42        \brief
43            XMLAttributes constructor.
44         */
45        XMLAttributes(void);
46
47        /*!
48        \brief
49            XMLAttributes Destructor
50         */
51        virtual ~XMLAttributes(void);
52
53        /*!
54        \brief
55            Adds an attribute to the attribute block.  If the attribute value already exists, it is replaced with
56            the new value.
57
58        \param attrName
59            String object holding the name of the attribute to be added.
60
61        \param attrValue
62            String object holding a string representation of the attribute value.
63
64        \return
65            Nothing.
66         */
67        void add(const String& attrName, const String& attrValue);
68       
69        /*!
70        \brief
71            Removes an attribute from the attribute block.
72
73        \param attrName
74            String object holding the name of the attribute to be removed.
75
76        \return
77            Nothing.
78         */
79        void remove(const String& attrName);
80
81        /*!
82        \brief
83            Return whether the named attribute exists within the attribute block.
84
85        \param attrName
86            String object holding the name of the attribute to be checked.
87
88        \return
89            - true if an attribute with the name \a attrName is present in the attribute block.
90            - false if no attribute named \a attrName is present in the attribute block.
91        */
92        bool exists(const String& attrName) const;
93
94        /*!
95        \brief
96            Return the number of attributes in the attribute block.
97
98        \return
99            value specifying the number of attributes in this attribute block.
100         */
101        size_t getCount(void) const;
102
103        /*!
104        \brief
105            Return the name of an attribute based upon its index within the attribute block.
106
107        \note
108            Nothing is specified about the order of elements within the attribute block.  Elements
109            may not, for example, appear in the order they were specified in the XML file.
110
111        \param index
112            zero based index of the attribute whos name is to be returned.
113
114        \return
115            String object holding the name of the attribute at the requested index.
116
117        \exception IllegalRequestException  thrown if \a index is out of range for this attribute block.
118        */
119        const String& getName(size_t index) const;
120       
121        /*!
122        \brief
123            Return the value string of an attribute based upon its index within the attribute block.
124
125        \note
126            Nothing is specified about the order of elements within the attribute block.  Elements
127            may not, for example, appear in the order they were specified in the XML file.
128       
129        \param index
130            zero based index of the attribute whos value string is to be returned.
131
132        \return
133            String object holding the string value of the attribute at the requested index.
134
135        \exception IllegalRequestException  thrown if \a index is out of range for this attribute block.
136        */
137        const String& getValue(size_t index) const;
138
139        /*!
140        \brief
141            Return the value string for attribute \a attrName.
142
143        \param attrName
144            String object holding the name of the attribute whos value string is to be returned
145
146        \return
147            String object hilding the value string for attribute \a attrName.
148
149        \exception UnknownObjectException   thrown if no attribute named \a attrName is present in the attribute block.
150         */
151        const String& getValue(const String& attrName) const;
152
153        /*!
154        \brief
155            Return the value of attribute \a attrName as a string.
156
157        \param attrName
158            String object holding the name of the attribute whos value is to be returned.
159
160        \param def
161            String object holding the default value to be returned if \a attrName does not exist in the attribute block.
162            For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
163            or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
164
165        \return
166            String object containing the value of attribute \a attrName if present, or \a def if not.
167         */
168        const String& getValueAsString(const String& attrName, const String& def = "") const;
169
170        /*!
171        \brief
172            Return the value of attribute \a attrName as a boolean value.
173
174        \param attrName
175            String object holding the name of the attribute whos value is to be returned.
176
177        \param def
178            bool value specifying the default value to be returned if \a attrName does not exist in the attribute block.
179            For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
180            or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
181
182        \return
183            bool value equal to the value of attribute \a attrName if present, or \a def if not.
184
185        \exception IllegalRequestException  thrown if the attribute value string coul dnot be converted to the requested type.
186        */
187        bool getValueAsBool(const String& attrName, bool def = false) const;
188       
189        /*!
190        \brief
191            Return the value of attribute \a attrName as a integer value.
192
193        \param attrName
194            String object holding the name of the attribute whos value is to be returned.
195
196        \param def
197            integer value specifying the default value to be returned if \a attrName does not exist in the attribute block.
198            For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
199            or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
200
201        \return
202            integer value equal to the value of attribute \a attrName if present, or \a def if not.
203       
204        \exception IllegalRequestException  thrown if the attribute value string coul dnot be converted to the requested type.
205        */
206        int getValueAsInteger(const String& attrName, int def = 0) const;
207       
208        /*!
209        \brief
210            Return the value of attribute \a attrName as a floating point value.
211
212        \param attrName
213            String object holding the name of the attribute whos value is to be returned.
214
215        \param def
216            float value specifying the default value to be returned if \a attrName does not exist in the attribute block.
217            For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
218            or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
219
220        \return
221            float value equal to the value of attribute \a attrName if present, or \a def if not.
222
223        \exception IllegalRequestException  thrown if the attribute value string coul dnot be converted to the requested type.
224        */
225        float getValueAsFloat(const String& attrName, float def = 0.0f) const;
226
227    protected:
228        typedef std::map<String, String> AttributeMap;
229        AttributeMap    d_attrs;
230    };
231
232} // End of  CEGUI namespace section
233
234
235#endif  // end of guard _CEGUIXMLAttributes_h_
Note: See TracBrowser for help on using the repository browser.