BARE2D
BARE2D::XMLDataManager Class Reference

A singleton class that statically manages all XML data, including read and write operations. More...

#include <XMLDataManager.hpp>

+ Collaboration diagram for BARE2D::XMLDataManager:

Public Member Functions

template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, std::string &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, unsigned int &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, std::vector< unsigned int > &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, int &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, float &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, std::vector< float > &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, bool &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, std::vector< bool > &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, glm::vec2 &variable)
 
template<>
bool readValue (rapidxml::xml_node<> *parent, std::string valueName, std::vector< glm::vec2 > &variable)
 

Static Public Member Functions

static void loadXML (std::string filepath)
 Loads all of the files from the filepath that end in .xml to the caches. Does not clear caches. More...
 
static void saveXML (std::string filepath)
 Writes all of the currently cached data to the data's respective files in a folder at filepath. Does not clear caches. More...
 
template<typename T >
static void addDataType ()
 Adds a type of data that can be read. Make sure that the custom data type's nodeName is set. More...
 
static void addData (XMLData *data)
 Adds a piece of data to the cache, in the appropriate sub-cache. More...
 
static void setData (XMLData *data)
 Adds or overwrites data in the cache/sub-cache. More...
 
template<typename T >
static T getData (std::string dataType, unsigned int key)
 Finds some data in the subcache. More...
 
static unsigned int getDataCount (std::string dataType)
 
static void clearCache ()
 Clears the various caches and subcaches that the class uses. Useful for refreshes. More...
 
static XMLData getDataType (std::string dataType)
 Provides a copy of some data type added by the addDataType function. More...
 

Static Private Member Functions

static void writeXMLData (std::ofstream &file, Cache< unsigned int, XMLData > *data)
 Writes a single subcache of data to a single file. More...
 
static void readXMLData (std::ifstream &file, std::string dataType)
 Reads a single subcache from a single file. More...
 
template<typename T >
static bool readValue (rapidxml::xml_node<> *parent, std::string valueName, T &variable)
 Reads a value from a node. Templated for almost any primitive. More...
 
static Cache< unsigned int, XMLData > * getDataCache (std::string dataType)
 Returns a cache for a certain type of data. More...
 

Static Private Attributes

static Cache< std::string, Cache< unsigned int, XMLData > > m_storedData
 
static std::unordered_map< std::string, std::function< XMLData *()> > m_dataTypingFunctions
 

Friends

class XMLData
 

Detailed Description

A singleton class that statically manages all XML data, including read and write operations.

Definition at line 16 of file XMLDataManager.hpp.

Member Function Documentation

◆ addData()

void BARE2D::XMLDataManager::addData ( XMLData data)
static

Adds a piece of data to the cache, in the appropriate sub-cache.

Parameters
dataA pointer to the data to be added. data->nodeName must be set for appropriate sub-caching.

Definition at line 158 of file XMLDataManager.cpp.

References BARE2D::Cache< S, T >::addItem(), BARE2D::Cache< S, T >::findItem(), getDataCache(), BARE2D::XMLData::id, BARE2D::XMLData::name, BARE2D::XMLData::nodeName, BARE2D::throwError(), and BARE2D::XML_FAILURE.

Referenced by readXMLData().

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

◆ addDataType()

template<typename T >
static void BARE2D::XMLDataManager::addDataType ( )
static

Adds a type of data that can be read. Make sure that the custom data type's nodeName is set.

◆ clearCache()

void BARE2D::XMLDataManager::clearCache ( )
static

Clears the various caches and subcaches that the class uses. Useful for refreshes.

Definition at line 494 of file XMLDataManager.cpp.

References m_dataTypingFunctions, and m_storedData.

◆ getData()

template<typename T >
static T BARE2D::XMLDataManager::getData ( std::string  dataType,
unsigned int  key 
)
static

Finds some data in the subcache.

Parameters
dataTypeThe string type of the data to get.
keyThe ID of the data.
Returns
A copy of the data, as nobody should be modifying the cached data.

◆ getDataCache()

Cache< unsigned int, XMLData > * BARE2D::XMLDataManager::getDataCache ( std::string  dataType)
staticprivate

Returns a cache for a certain type of data.

Parameters
dataTypeThe string type of the data
Returns
A pointer to the subcache.

Definition at line 482 of file XMLDataManager.cpp.

References BARE2D::Logger::getInstance(), BARE2D::Logger::log(), and m_storedData.

Referenced by addData(), getDataCount(), and setData().

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

◆ getDataCount()

unsigned int BARE2D::XMLDataManager::getDataCount ( std::string  dataType)
static
Parameters
dataTypeThe string type of the data to get info on.
Returns
The number of elements of the type of data.

Definition at line 153 of file XMLDataManager.cpp.

References getDataCache().

+ Here is the call graph for this function:

◆ getDataType()

static XMLData BARE2D::XMLDataManager::getDataType ( std::string  dataType)
static

Provides a copy of some data type added by the addDataType function.

Parameters
dataTypeThe string identifier for the type of data. In other words, nodeName
Returns
A copy of some type of data, complete with nodeName and attributes set.

◆ loadXML()

void BARE2D::XMLDataManager::loadXML ( std::string  filepath)
static

Loads all of the files from the filepath that end in .xml to the caches. Does not clear caches.

Parameters
filepathThe path of the folder of files to load, or the path of an actual singular file to load.

Definition at line 18 of file XMLDataManager.cpp.

References BARE2D::Filesystem::getFilesIn(), BARE2D::Logger::getInstance(), BARE2D::Logger::log(), readXMLData(), BARE2D::throwFatalError(), and BARE2D::XML_FAILURE.

+ Here is the call graph for this function:

◆ readValue() [1/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
bool &  variable 
)

Definition at line 346 of file XMLDataManager.cpp.

◆ readValue() [2/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
float &  variable 
)

Definition at line 283 of file XMLDataManager.cpp.

◆ readValue() [3/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
glm::vec2 &  variable 
)

Definition at line 409 of file XMLDataManager.cpp.

◆ readValue() [4/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
int &  variable 
)

Definition at line 263 of file XMLDataManager.cpp.

◆ readValue() [5/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
std::string &  variable 
)

Definition at line 180 of file XMLDataManager.cpp.

◆ readValue() [6/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
std::vector< bool > &  variable 
)

Definition at line 367 of file XMLDataManager.cpp.

◆ readValue() [7/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
std::vector< float > &  variable 
)

Definition at line 304 of file XMLDataManager.cpp.

◆ readValue() [8/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
std::vector< glm::vec2 > &  variable 
)

Definition at line 437 of file XMLDataManager.cpp.

◆ readValue() [9/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
std::vector< unsigned int > &  variable 
)

Definition at line 221 of file XMLDataManager.cpp.

◆ readValue() [10/11]

template<typename T >
static bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
T &  variable 
)
staticprivate

Reads a value from a node. Templated for almost any primitive.

Parameters
parentA pointer to the node of the parent data.
valueNameThe "nodeName" of the value to be read.
variableThe return variable.
Returns
True on success, false on failure.

Referenced by BARE2D::XMLData::read().

+ Here is the caller graph for this function:

◆ readValue() [11/11]

template<>
bool BARE2D::XMLDataManager::readValue ( rapidxml::xml_node<> *  parent,
std::string  valueName,
unsigned int &  variable 
)

Definition at line 200 of file XMLDataManager.cpp.

◆ readXMLData()

void BARE2D::XMLDataManager::readXMLData ( std::ifstream &  file,
std::string  dataType 
)
staticprivate

Reads a single subcache from a single file.

Parameters
fileThe file to read from.
dataTypeThe nodeName of the data to read. This will be the key for the cache.

Definition at line 57 of file XMLDataManager.cpp.

References addData(), BARE2D::Logger::getInstance(), BARE2D::XMLData::id, BARE2D::Logger::log(), m_dataTypingFunctions, BARE2D::XMLData::name, BARE2D::XMLData::nodeName, BARE2D::XMLData::read(), BARE2D::throwFatalError(), and BARE2D::XML_FAILURE.

Referenced by loadXML().

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

◆ saveXML()

void BARE2D::XMLDataManager::saveXML ( std::string  filepath)
static

Writes all of the currently cached data to the data's respective files in a folder at filepath. Does not clear caches.

Parameters
filepathThe path of the folder of files to save.

Definition at line 103 of file XMLDataManager.cpp.

References BARE2D::Logger::getInstance(), BARE2D::Logger::log(), m_storedData, BARE2D::throwFatalError(), writeXMLData(), and BARE2D::XML_FAILURE.

+ Here is the call graph for this function:

◆ setData()

void BARE2D::XMLDataManager::setData ( XMLData data)
static

Adds or overwrites data in the cache/sub-cache.

Parameters
dataA pointer to the data to be added. data->nodeName must be set for appropriate sub-caching

Definition at line 173 of file XMLDataManager.cpp.

References getDataCache(), BARE2D::XMLData::id, BARE2D::XMLData::nodeName, and BARE2D::Cache< S, T >::setItem().

+ Here is the call graph for this function:

◆ writeXMLData()

void BARE2D::XMLDataManager::writeXMLData ( std::ofstream &  file,
Cache< unsigned int, XMLData > *  data 
)
staticprivate

Writes a single subcache of data to a single file.

Parameters
fileThe file to write the data to
dataA pointer to the subcache to write

Definition at line 130 of file XMLDataManager.cpp.

References BARE2D::Logger::getInstance(), and BARE2D::Logger::log().

Referenced by saveXML().

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

Friends And Related Function Documentation

◆ XMLData

friend class XMLData
friend

Definition at line 18 of file XMLDataManager.hpp.

Field Documentation

◆ m_dataTypingFunctions

std::unordered_map< std::string, std::function< XMLData *()> > BARE2D::XMLDataManager::m_dataTypingFunctions
staticprivate

Definition at line 108 of file XMLDataManager.hpp.

Referenced by clearCache(), and readXMLData().

◆ m_storedData

Cache< std::string, Cache< unsigned int, XMLData > > BARE2D::XMLDataManager::m_storedData
staticprivate

Definition at line 107 of file XMLDataManager.hpp.

Referenced by clearCache(), getDataCache(), and saveXML().


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