2024-03-21 20:13:15 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "CAttributes.h"
|
|
|
|
#include "CAttributeImpl.h"
|
|
|
|
#include "ITexture.h"
|
|
|
|
#include "IVideoDriver.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
|
|
|
|
2024-08-17 19:49:11 +02:00
|
|
|
CAttributes::CAttributes()
|
2024-03-21 20:13:15 +01:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("CAttributes");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
CAttributes::~CAttributes()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Removes all attributes
|
|
|
|
void CAttributes::clear()
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
for (auto it : Attributes)
|
|
|
|
delete it.second;
|
2024-03-21 20:13:15 +01:00
|
|
|
Attributes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a attribute as boolean value
|
|
|
|
void CAttributes::setAttribute(const c8 *attributeName, bool value)
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
auto it = Attributes.find(attributeName);
|
|
|
|
if (it != Attributes.end()) {
|
|
|
|
it->second->setBool(value);
|
|
|
|
} else {
|
|
|
|
Attributes[attributeName] = new CBoolAttribute(attributeName, value);
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets a attribute as boolean value
|
|
|
|
//! \param attributeName: Name of the attribute to get.
|
|
|
|
//! \return Returns value of the attribute previously set by setAttribute() as bool
|
|
|
|
//! or 0 if attribute is not set.
|
|
|
|
bool CAttributes::getAttributeAsBool(const c8 *attributeName, bool defaultNotFound) const
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
auto it = Attributes.find(attributeName);
|
|
|
|
if (it != Attributes.end())
|
|
|
|
return it->second->getBool();
|
2024-03-21 20:13:15 +01:00
|
|
|
else
|
|
|
|
return defaultNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a attribute as integer value
|
|
|
|
void CAttributes::setAttribute(const c8 *attributeName, s32 value)
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
auto it = Attributes.find(attributeName);
|
|
|
|
if (it != Attributes.end()) {
|
|
|
|
it->second->setInt(value);
|
|
|
|
} else {
|
|
|
|
Attributes[attributeName] = new CIntAttribute(attributeName, value);
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets a attribute as integer value
|
|
|
|
//! \param attributeName: Name of the attribute to get.
|
|
|
|
//! \return Returns value of the attribute previously set by setAttribute() as integer
|
|
|
|
//! or 0 if attribute is not set.
|
|
|
|
s32 CAttributes::getAttributeAsInt(const c8 *attributeName, irr::s32 defaultNotFound) const
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
auto it = Attributes.find(attributeName);
|
|
|
|
if (it != Attributes.end())
|
|
|
|
return it->second->getInt();
|
2024-03-21 20:13:15 +01:00
|
|
|
else
|
|
|
|
return defaultNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets a attribute as float value
|
|
|
|
void CAttributes::setAttribute(const c8 *attributeName, f32 value)
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
auto it = Attributes.find(attributeName);
|
|
|
|
if (it != Attributes.end()) {
|
|
|
|
it->second->setFloat(value);
|
|
|
|
} else {
|
|
|
|
Attributes[attributeName] = new CFloatAttribute(attributeName, value);
|
|
|
|
}
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets a attribute as integer value
|
|
|
|
//! \param attributeName: Name of the attribute to get.
|
|
|
|
//! \return Returns value of the attribute previously set by setAttribute() as float value
|
|
|
|
//! or 0 if attribute is not set.
|
|
|
|
f32 CAttributes::getAttributeAsFloat(const c8 *attributeName, irr::f32 defaultNotFound) const
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
auto it = Attributes.find(attributeName);
|
|
|
|
if (it != Attributes.end())
|
|
|
|
return it->second->getFloat();
|
|
|
|
else
|
|
|
|
return defaultNotFound;
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns the type of an attribute
|
|
|
|
E_ATTRIBUTE_TYPE CAttributes::getAttributeType(const c8 *attributeName) const
|
|
|
|
{
|
|
|
|
E_ATTRIBUTE_TYPE ret = EAT_UNKNOWN;
|
|
|
|
|
2024-08-17 19:49:11 +02:00
|
|
|
auto it = Attributes.find(attributeName);
|
|
|
|
if (it != Attributes.end())
|
|
|
|
ret = it->second->getType();
|
2024-03-21 20:13:15 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns if an attribute with a name exists
|
|
|
|
bool CAttributes::existsAttribute(const c8 *attributeName) const
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
return Attributes.find(attributeName) != Attributes.end();
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace io
|
|
|
|
} // end namespace irr
|