BARE2D
BARE2D::XMLData Class Reference

Holds all the very basic information for XML data. Designed to be a base class from which a user can derive custom data formats. To derive, please overload the default constructor and XMLData(std::string dataType, unsigned int ID) More...

#include <XMLDataTypes.hpp>

+ Collaboration diagram for BARE2D::XMLData:

Public Member Functions

 XMLData ()
 Just adds attributes, using the protected function addAttribute(AttributeBase* attr) or its vector counterpart, as well as the nodeName variable. More...
 
 XMLData (std::string dataType, unsigned int ID)
 Sets all data to a known XMLData's (Uses master map to retrieve this) More...
 
 XMLData (std::vector< AttributeBase * > attributes)
 
 XMLData (std::unordered_map< std::string, AttributeBase * > attributes)
 
 ~XMLData ()
 
void read (rapidxml::xml_node<> *node)
 Reads the entire piece of data from a given XML node. More...
 
void write (rapidxml::xml_document<> *doc)
 Writes the entire piece of data to a new node in the XML document. More...
 
template<typename T >
getAttributeByName (std::string name)
 Finds an attribute by its name (eg. "name", "id") More...
 
std::unordered_map< std::string, AttributeBase * > getAttributes ()
 

Data Fields

std::string name
 
unsigned int id
 
std::string nodeName
 

Protected Member Functions

template<typename T >
void addAttribute (std::string name, AttributeType type, T *data)
 Constructs and adds an attribute to the data. More...
 
void addAttribute (AttributeBase *attr)
 Adds an attribute to the data. More...
 
void addAttributes (std::vector< AttributeBase * > attrs)
 Bulk adds attributes to the data. More...
 

Protected Attributes

std::unordered_map< std::string, AttributeBase * > m_attributes
 

Detailed Description

Holds all the very basic information for XML data. Designed to be a base class from which a user can derive custom data formats. To derive, please overload the default constructor and XMLData(std::string dataType, unsigned int ID)

Definition at line 108 of file XMLDataTypes.hpp.

Constructor & Destructor Documentation

◆ XMLData() [1/4]

BARE2D::XMLData::XMLData ( )

Just adds attributes, using the protected function addAttribute(AttributeBase* attr) or its vector counterpart, as well as the nodeName variable.

Definition at line 186 of file XMLDataTypes.cpp.

References addAttribute(), name, BARE2D::STRING, and BARE2D::UNSIGNED_INT.

+ Here is the call graph for this function:

◆ XMLData() [2/4]

BARE2D::XMLData::XMLData ( std::string  dataType,
unsigned int  ID 
)

Sets all data to a known XMLData's (Uses master map to retrieve this)

Parameters
dataTypeThe name of the type to make this
IDThe ID of the data.

Definition at line 195 of file XMLDataTypes.cpp.

References m_attributes, and name.

◆ XMLData() [3/4]

BARE2D::XMLData::XMLData ( std::vector< AttributeBase * >  attributes)

Definition at line 204 of file XMLDataTypes.cpp.

References addAttribute(), addAttributes(), name, BARE2D::STRING, and BARE2D::UNSIGNED_INT.

+ Here is the call graph for this function:

◆ XMLData() [4/4]

BARE2D::XMLData::XMLData ( std::unordered_map< std::string, AttributeBase * >  attributes)

Definition at line 215 of file XMLDataTypes.cpp.

References m_attributes.

◆ ~XMLData()

BARE2D::XMLData::~XMLData ( )
inline

Definition at line 124 of file XMLDataTypes.hpp.

Member Function Documentation

◆ addAttribute() [1/2]

void BARE2D::XMLData::addAttribute ( AttributeBase attr)
protected

Adds an attribute to the data.

Parameters
attrA pointer to the attribute to be added.

Definition at line 447 of file XMLDataTypes.cpp.

References m_attributes, and BARE2D::AttributeBase::name.

◆ addAttribute() [2/2]

template<typename T >
void BARE2D::XMLData::addAttribute ( std::string  name,
AttributeType  type,
T *  data 
)
protected

Constructs and adds an attribute to the data.

Parameters
nameThe name of the attribute. "name" and "id" are already in use, please don't break things like that.
typeThe type of data. Eg. AttributeType::FLOAT is a float, AttributeType::VECTOR_FLOAT is a vector of floats, etc.
dataA pointer to the data that the attribute is linked to.

Referenced by addAttributes(), and XMLData().

+ Here is the caller graph for this function:

◆ addAttributes()

void BARE2D::XMLData::addAttributes ( std::vector< AttributeBase * >  attrs)
protected

Bulk adds attributes to the data.

Parameters
attrsA vector of pointers to attributes to add.

Definition at line 452 of file XMLDataTypes.cpp.

References addAttribute().

Referenced by XMLData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAttributeByName()

template<typename T >
T BARE2D::XMLData::getAttributeByName ( std::string  name)

Finds an attribute by its name (eg. "name", "id")

Parameters
nameThe name of the attribute
Returns
A copy of the data held by the attribute.

◆ getAttributes()

std::unordered_map< std::string, AttributeBase * > BARE2D::XMLData::getAttributes ( )
Returns
Returns a copy of the entire attributes map. Useful for pseudo-copy operations.

Definition at line 442 of file XMLDataTypes.cpp.

References m_attributes.

◆ read()

void BARE2D::XMLData::read ( rapidxml::xml_node<> *  node)

◆ write()

void BARE2D::XMLData::write ( rapidxml::xml_document<> *  doc)

Writes the entire piece of data to a new node in the XML document.

Parameters
docThe document to write to.

Definition at line 383 of file XMLDataTypes.cpp.

References BARE2D::AttributeBase::getDataString(), m_attributes, name, and nodeName.

+ Here is the call graph for this function:

Field Documentation

◆ id

unsigned int BARE2D::XMLData::id

◆ m_attributes

std::unordered_map<std::string, AttributeBase*> BARE2D::XMLData::m_attributes
protected

Definition at line 175 of file XMLDataTypes.hpp.

Referenced by addAttribute(), getAttributes(), read(), write(), and XMLData().

◆ name

std::string BARE2D::XMLData::name

◆ nodeName

std::string BARE2D::XMLData::nodeName

The documentation for this class was generated from the following files: