xyginext  0.2.0
Second generation of xygine game creation framework
Public Types | Public Member Functions | List of all members
xy::ConfigObject Class Referencefinal

A configuration object can hold one or more nested objects or configuration properties. All objects require a name, and may have an optional id as a string value. More...

#include <ConfigFile.hpp>

Inheritance diagram for xy::ConfigObject:
xy::ConfigItem

Public Types

using NameValue = std::pair< std::string, std::string >
 

Public Member Functions

 ConfigObject (const std::string &name="", const std::string &id="")
 
const std::string & getId () const
 Get the id of the object.
 
ConfigPropertyfindProperty (const std::string &name) const
 Returns a pointer to the property if found, else nullptr Pointers returned from this function should only be used within a small scope as adding or removing any properties from the parent object is likely to invalidate them.
 
ConfigObjectfindObjectWithId (const std::string &id) const
 Searches for a child object with given id and returns a pointer to it if found, else returns nullptr. Pointers returned from this function should only be used within a small scope as adding or removing any objects from the is likely to invalidate them.
 
ConfigObjectfindObjectWithName (const std::string &name) const
 Searches for a child object with the given name and returns a pointer to it if found, else returns nullptr. Pointers returned from this function should only be used within a small scope as adding or removing any objects from the is likely to invalidate them.
 
const std::vector< ConfigProperty > & getProperties () const
 Returns a reference to the vector of properties owned by this object.
 
std::vector< ConfigProperty > & getProperties ()
 
const std::vector< ConfigObject > & getObjects () const
 Returns a reference to the vector objects owned by this object.
 
std::vector< ConfigObject > & getObjects ()
 
ConfigPropertyaddProperty (const std::string &name, const std::string &value="")
 Adds a name / value property pair to this object WARNING this will most likely invalidate any pointers retreived with findProperty()
 
void addProperty (const ConfigProperty &prop)
 Adds a copy of the given ConfigProperty to this objects list of properties. WARNING this will most likely invalidate any pointers retreived with findProperty()
 
ConfigObjectaddObject (const std::string &name, const std::string &id="")
 Adds an object with the given name and optional id to this object and returns a pointer to it. WARNING this will likely invalidate any existing pointers to objects retreived with findObject()
 
void addObject (const ConfigObject &obj)
 Adds a copy of an existing object to this object. WARNING this will likely invalidate any existing pointers to objects retreived with findObject()
 
void removeProperty (const std::string &name)
 Removes a property with the given name from this object if it exists.
 
ConfigObject removeObject (const std::string &name, const std::string &="")
 Removes an object (and all of its children) with the given name from this object if it exists.
 
bool save (const std::string &path) const
 Writes this object and all its children to given path.
 
bool loadFromFile (const std::string &path)
 Attempts to load a config file into the object. More...
 
- Public Member Functions inherited from xy::ConfigItem
 ConfigItem (const std::string &name)
 
 ConfigItem (const ConfigItem &)=default
 
ConfigItemoperator= (const ConfigItem &)=default
 
 ConfigItem (ConfigItem &&)=default
 
ConfigItemoperator= (ConfigItem &&)=default
 
const std::string & getName () const
 Returns the name of this item.
 

Additional Inherited Members

- Protected Member Functions inherited from xy::ConfigItem
void setParent (ConfigItem *parent)
 
ConfigItemgetParent () const
 
void setName (const std::string &name)
 

Detailed Description

A configuration object can hold one or more nested objects or configuration properties. All objects require a name, and may have an optional id as a string value.

Member Function Documentation

◆ loadFromFile()

bool xy::ConfigObject::loadFromFile ( const std::string &  path)

Attempts to load a config file into the object.

Returns
true on success, else false if something went wrong