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
5 #include "CAttributes.h"
\r
6 #include "CAttributeImpl.h"
\r
7 #include "ITexture.h"
\r
8 #include "IVideoDriver.h"
\r
15 CAttributes::CAttributes(video::IVideoDriver* driver)
\r
19 setDebugName("CAttributes");
\r
26 CAttributes::~CAttributes()
\r
35 //! Removes all attributes
\r
36 void CAttributes::clear()
\r
38 for (u32 i=0; i<Attributes.size(); ++i)
\r
39 Attributes[i]->drop();
\r
44 //! Returns attribute index from name, -1 if not found
\r
45 s32 CAttributes::findAttribute(const c8* attributeName) const
\r
47 for (u32 i=0; i<Attributes.size(); ++i)
\r
48 if (Attributes[i]->Name == attributeName)
\r
55 IAttribute* CAttributes::getAttributeP(const c8* attributeName) const
\r
57 for (u32 i=0; i<Attributes.size(); ++i)
\r
58 if (Attributes[i]->Name == attributeName)
\r
59 return Attributes[i];
\r
64 //! Sets a attribute as boolean value
\r
65 void CAttributes::setAttribute(const c8* attributeName, bool value)
\r
67 IAttribute* att = getAttributeP(attributeName);
\r
69 att->setBool(value);
\r
72 Attributes.push_back(new CBoolAttribute(attributeName, value));
\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
82 const IAttribute* att = getAttributeP(attributeName);
\r
84 return att->getBool();
\r
86 return defaultNotFound;
\r
89 //! Sets a attribute as integer value
\r
90 void CAttributes::setAttribute(const c8* attributeName, s32 value)
\r
92 IAttribute* att = getAttributeP(attributeName);
\r
97 Attributes.push_back(new CIntAttribute(attributeName, value));
\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
107 const IAttribute* att = getAttributeP(attributeName);
\r
109 return att->getInt();
\r
111 return defaultNotFound;
\r
114 //! Sets a attribute as float value
\r
115 void CAttributes::setAttribute(const c8* attributeName, f32 value)
\r
117 IAttribute* att = getAttributeP(attributeName);
\r
119 att->setFloat(value);
\r
121 Attributes.push_back(new CFloatAttribute(attributeName, value));
\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
130 const IAttribute* att = getAttributeP(attributeName);
\r
132 return att->getFloat();
\r
134 return defaultNotFound;
\r
137 //! Returns amount of string attributes set in this scene manager.
\r
138 u32 CAttributes::getAttributeCount() const
\r
140 return Attributes.size();
\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
147 if ((u32)index >= Attributes.size())
\r
150 return Attributes[index]->Name.c_str();
\r
153 //! Returns the type of an attribute
\r
154 E_ATTRIBUTE_TYPE CAttributes::getAttributeType(const c8* attributeName) const
\r
156 E_ATTRIBUTE_TYPE ret = EAT_UNKNOWN;
\r
158 const IAttribute* att = getAttributeP(attributeName);
\r
160 ret = att->getType();
\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
169 if ((u32)index >= Attributes.size())
\r
170 return EAT_UNKNOWN;
\r
172 return Attributes[index]->getType();
\r
175 //! Returns the type of an attribute
\r
176 const wchar_t* CAttributes::getAttributeTypeString(const c8* attributeName, const wchar_t* defaultNotFound) const
\r
178 const IAttribute* att = getAttributeP(attributeName);
\r
180 return att->getTypeString();
\r
182 return defaultNotFound;
\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
189 if ((u32)index >= Attributes.size())
\r
190 return defaultNotFound;
\r
192 return Attributes[index]->getTypeString();
\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
199 if ((u32)index < Attributes.size())
\r
200 return Attributes[index]->getInt();
\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
209 if ((u32)index < Attributes.size())
\r
210 return Attributes[index]->getFloat();
\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
221 if ((u32)index < Attributes.size())
\r
222 ret = Attributes[index]->getBool();
\r
227 //! Adds an attribute as integer
\r
228 void CAttributes::addInt(const c8* attributeName, s32 value)
\r
230 Attributes.push_back(new CIntAttribute(attributeName, value));
\r
233 //! Adds an attribute as float
\r
234 void CAttributes::addFloat(const c8* attributeName, f32 value)
\r
236 Attributes.push_back(new CFloatAttribute(attributeName, value));
\r
239 //! Adds an attribute as bool
\r
240 void CAttributes::addBool(const c8* attributeName, bool value)
\r
242 Attributes.push_back(new CBoolAttribute(attributeName, value));
\r
245 //! Returns if an attribute with a name exists
\r
246 bool CAttributes::existsAttribute(const c8* attributeName) const
\r
248 return getAttributeP(attributeName) != 0;
\r
251 //! Sets an attribute as boolean value
\r
252 void CAttributes::setAttribute(s32 index, bool value)
\r
254 if ((u32)index < Attributes.size())
\r
255 Attributes[index]->setBool(value);
\r
258 //! Sets an attribute as integer value
\r
259 void CAttributes::setAttribute(s32 index, s32 value)
\r
261 if ((u32)index < Attributes.size())
\r
262 Attributes[index]->setInt(value);
\r
265 //! Sets a attribute as float value
\r
266 void CAttributes::setAttribute(s32 index, f32 value)
\r
268 if ((u32)index < Attributes.size())
\r
269 Attributes[index]->setFloat(value);
\r
272 } // end namespace io
\r
273 } // end namespace irr
\r