]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CAttributes.cpp
Use swap_control from MESA and EXT before SGI
[irrlicht.git] / source / Irrlicht / CAttributes.cpp
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #include "CAttributes.h"\r
6 #include "CAttributeImpl.h"\r
7 #include "ITexture.h"\r
8 #include "IVideoDriver.h"\r
9 \r
10 namespace irr\r
11 {\r
12 namespace io\r
13 {\r
14 \r
15 CAttributes::CAttributes(video::IVideoDriver* driver)\r
16 : Driver(driver)\r
17 {\r
18         #ifdef _DEBUG\r
19         setDebugName("CAttributes");\r
20         #endif\r
21 \r
22         if (Driver)\r
23                 Driver->grab();\r
24 }\r
25 \r
26 CAttributes::~CAttributes()\r
27 {\r
28         clear();\r
29 \r
30         if (Driver)\r
31                 Driver->drop();\r
32 }\r
33 \r
34 \r
35 //! Removes all attributes\r
36 void CAttributes::clear()\r
37 {\r
38         for (u32 i=0; i<Attributes.size(); ++i)\r
39                 Attributes[i]->drop();\r
40 \r
41         Attributes.clear();\r
42 }\r
43 \r
44 //! Returns attribute index from name, -1 if not found\r
45 s32 CAttributes::findAttribute(const c8* attributeName) const\r
46 {\r
47         for (u32 i=0; i<Attributes.size(); ++i)\r
48                 if (Attributes[i]->Name == attributeName)\r
49                         return i;\r
50 \r
51         return -1;\r
52 }\r
53 \r
54 \r
55 IAttribute* CAttributes::getAttributeP(const c8* attributeName) const\r
56 {\r
57         for (u32 i=0; i<Attributes.size(); ++i)\r
58                 if (Attributes[i]->Name == attributeName)\r
59                         return Attributes[i];\r
60 \r
61         return 0;\r
62 }\r
63 \r
64 //! Sets a attribute as boolean value\r
65 void CAttributes::setAttribute(const c8* attributeName, bool value)\r
66 {\r
67         IAttribute* att = getAttributeP(attributeName);\r
68         if (att)\r
69                 att->setBool(value);\r
70         else\r
71         {\r
72                 Attributes.push_back(new CBoolAttribute(attributeName, value));\r
73         }\r
74 }\r
75 \r
76 //! Gets a attribute as boolean value\r
77 //! \param attributeName: Name of the attribute to get.\r
78 //! \return Returns value of the attribute previously set by setAttribute() as bool\r
79 //! or 0 if attribute is not set.\r
80 bool CAttributes::getAttributeAsBool(const c8* attributeName, bool defaultNotFound) const\r
81 {\r
82         const IAttribute* att = getAttributeP(attributeName);\r
83         if (att)\r
84                 return att->getBool();\r
85         else\r
86                 return defaultNotFound;\r
87 }\r
88 \r
89 //! Sets a attribute as integer value\r
90 void CAttributes::setAttribute(const c8* attributeName, s32 value)\r
91 {\r
92         IAttribute* att = getAttributeP(attributeName);\r
93         if (att)\r
94                 att->setInt(value);\r
95         else\r
96         {\r
97                 Attributes.push_back(new CIntAttribute(attributeName, value));\r
98         }\r
99 }\r
100 \r
101 //! Gets a attribute as integer value\r
102 //! \param attributeName: Name of the attribute to get.\r
103 //! \return Returns value of the attribute previously set by setAttribute() as integer\r
104 //! or 0 if attribute is not set.\r
105 s32 CAttributes::getAttributeAsInt(const c8* attributeName, irr::s32 defaultNotFound) const\r
106 {\r
107         const IAttribute* att = getAttributeP(attributeName);\r
108         if (att)\r
109                 return att->getInt();\r
110         else\r
111                 return defaultNotFound;\r
112 }\r
113 \r
114 //! Sets a attribute as float value\r
115 void CAttributes::setAttribute(const c8* attributeName, f32 value)\r
116 {\r
117         IAttribute* att = getAttributeP(attributeName);\r
118         if (att)\r
119                 att->setFloat(value);\r
120         else\r
121                 Attributes.push_back(new CFloatAttribute(attributeName, value));\r
122 }\r
123 \r
124 //! Gets a attribute as integer value\r
125 //! \param attributeName: Name of the attribute to get.\r
126 //! \return Returns value of the attribute previously set by setAttribute() as float value\r
127 //! or 0 if attribute is not set.\r
128 f32 CAttributes::getAttributeAsFloat(const c8* attributeName, irr::f32 defaultNotFound) const\r
129 {\r
130         const IAttribute* att = getAttributeP(attributeName);\r
131         if (att)\r
132                 return att->getFloat();\r
133 \r
134         return defaultNotFound;\r
135 }\r
136 \r
137 //! Returns amount of string attributes set in this scene manager.\r
138 u32 CAttributes::getAttributeCount() const\r
139 {\r
140         return Attributes.size();\r
141 }\r
142 \r
143 //! Returns string attribute name by index.\r
144 //! \param index: Index value, must be between 0 and getStringAttributeCount()-1.\r
145 const c8* CAttributes::getAttributeName(s32 index) const\r
146 {\r
147         if ((u32)index >= Attributes.size())\r
148                 return 0;\r
149 \r
150         return Attributes[index]->Name.c_str();\r
151 }\r
152 \r
153 //! Returns the type of an attribute\r
154 E_ATTRIBUTE_TYPE CAttributes::getAttributeType(const c8* attributeName) const\r
155 {\r
156         E_ATTRIBUTE_TYPE ret = EAT_UNKNOWN;\r
157 \r
158         const IAttribute* att = getAttributeP(attributeName);\r
159         if (att)\r
160                 ret = att->getType();\r
161 \r
162         return ret;\r
163 }\r
164 \r
165 //! Returns attribute type by index.\r
166 //! \param index: Index value, must be between 0 and getAttributeCount()-1.\r
167 E_ATTRIBUTE_TYPE CAttributes::getAttributeType(s32 index) const\r
168 {\r
169         if ((u32)index >= Attributes.size())\r
170                 return EAT_UNKNOWN;\r
171 \r
172         return Attributes[index]->getType();\r
173 }\r
174 \r
175 //! Returns the type of an attribute\r
176 const wchar_t* CAttributes::getAttributeTypeString(const c8* attributeName, const wchar_t* defaultNotFound) const\r
177 {\r
178         const IAttribute* att = getAttributeP(attributeName);\r
179         if (att)\r
180                 return att->getTypeString();\r
181         else\r
182                 return defaultNotFound;\r
183 }\r
184 \r
185 //! Returns attribute type string by index.\r
186 //! \param index: Index value, must be between 0 and getAttributeCount()-1.\r
187 const wchar_t* CAttributes::getAttributeTypeString(s32 index, const wchar_t* defaultNotFound) const\r
188 {\r
189         if ((u32)index >= Attributes.size())\r
190                 return defaultNotFound;\r
191 \r
192         return Attributes[index]->getTypeString();\r
193 }\r
194 \r
195 //! Gets an attribute as integer value\r
196 //! \param index: Index value, must be between 0 and getAttributeCount()-1.\r
197 s32 CAttributes::getAttributeAsInt(s32 index) const\r
198 {\r
199         if ((u32)index < Attributes.size())\r
200                 return Attributes[index]->getInt();\r
201         else\r
202                 return 0;\r
203 }\r
204 \r
205 //! Gets an attribute as float value\r
206 //! \param index: Index value, must be between 0 and getAttributeCount()-1.\r
207 f32 CAttributes::getAttributeAsFloat(s32 index) const\r
208 {\r
209         if ((u32)index < Attributes.size())\r
210                 return Attributes[index]->getFloat();\r
211         else\r
212                 return 0.f;\r
213 }\r
214 \r
215 //! Gets an attribute as boolean value\r
216 //! \param index: Index value, must be between 0 and getAttributeCount()-1.\r
217 bool CAttributes::getAttributeAsBool(s32 index) const\r
218 {\r
219         bool ret = false;\r
220 \r
221         if ((u32)index < Attributes.size())\r
222                 ret = Attributes[index]->getBool();\r
223 \r
224         return ret;\r
225 }\r
226 \r
227 //! Adds an attribute as integer\r
228 void CAttributes::addInt(const c8* attributeName, s32 value)\r
229 {\r
230         Attributes.push_back(new CIntAttribute(attributeName, value));\r
231 }\r
232 \r
233 //! Adds an attribute as float\r
234 void CAttributes::addFloat(const c8* attributeName, f32 value)\r
235 {\r
236         Attributes.push_back(new CFloatAttribute(attributeName, value));\r
237 }\r
238 \r
239 //! Adds an attribute as bool\r
240 void CAttributes::addBool(const c8* attributeName, bool value)\r
241 {\r
242         Attributes.push_back(new CBoolAttribute(attributeName, value));\r
243 }\r
244 \r
245 //! Returns if an attribute with a name exists\r
246 bool CAttributes::existsAttribute(const c8* attributeName) const\r
247 {\r
248         return getAttributeP(attributeName) != 0;\r
249 }\r
250 \r
251 //! Sets an attribute as boolean value\r
252 void CAttributes::setAttribute(s32 index, bool value)\r
253 {\r
254         if ((u32)index < Attributes.size())\r
255                 Attributes[index]->setBool(value);\r
256 }\r
257 \r
258 //! Sets an attribute as integer value\r
259 void CAttributes::setAttribute(s32 index, s32 value)\r
260 {\r
261         if ((u32)index < Attributes.size())\r
262                 Attributes[index]->setInt(value);\r
263 }\r
264 \r
265 //! Sets a attribute as float value\r
266 void CAttributes::setAttribute(s32 index, f32 value)\r
267 {\r
268         if ((u32)index < Attributes.size())\r
269                 Attributes[index]->setFloat(value);\r
270 }\r
271 \r
272 } // end namespace io\r
273 } // end namespace irr\r
274 \r