ARC SDK
Public Member Functions | Static Public Member Functions
Arc::Config Class Reference

Configuration element - represents (sub)tree of ARC XML configuration. More...

#include <arc/ArcConfig.h>

Inheritance diagram for Arc::Config:
Arc::XMLNode

Public Member Functions

 Config ()
 Creates empty XML tree. More...
 
 Config (const NS &ns)
 Creates an empty configuration object with the given namespace. More...
 
 Config (const char *filename)
 Loads configuration document from file at filename. More...
 
 Config (const std::string &xml_str)
 Parse configuration document from string. More...
 
 Config (XMLNode xml)
 Acquire existing XML (sub)tree. More...
 
 Config (XMLNode xml, const std::string &filename)
 Acquire existing XML (sub)tree and set config file. More...
 
 Config (long cfg_ptr_addr)
 Copy constructor used by language bindings. More...
 
 Config (const Config &cfg)
 Copy constructor used by language bindings. More...
 
void print (void)
 Print structure of document for debugging purposes. More...
 
bool parse (const char *filename)
 Parse configuration document from file at filename. More...
 
const std::string & getFileName (void) const
 Returns file name of config file or empty string if it was generated from the XMLNode subtree. More...
 
void setFileName (const std::string &filename)
 Set the file name of config file. More...
 
void save (const char *filename)
 Save config to file. More...
 
- Public Member Functions inherited from Arc::XMLNode
 XMLNode (void)
 Constructor of invalid node. More...
 
 XMLNode (const XMLNode &node)
 Copies existing instance. More...
 
 XMLNode (const std::string &xml)
 Creates XML document structure from textual representation of XML document. More...
 
 XMLNode (const char *xml, int len=-1)
 Creates XML document structure from textual representation of XML document. More...
 
 XMLNode (long ptr_addr)
 Copy constructor. Used by language bindings. More...
 
 XMLNode (const NS &ns, const char *name)
 Creates empty XML document structure with specified namespaces. More...
 
 ~XMLNode (void)
 Destructor. More...
 
void New (XMLNode &node) const
 Creates a copy of XML (sub)tree. More...
 
void Exchange (XMLNode &node)
 Exchanges XML (sub)trees. More...
 
void Move (XMLNode &node)
 Moves content of this XML (sub)tree to node. More...
 
void Swap (XMLNode &node)
 Swaps XML (sub)trees to which this and node refer. More...
 
 operator bool (void) const
 Returns true if instance points to XML element - valid instance. More...
 
bool operator! (void) const
 Returns true if instance does not point to XML element - invalid instance. More...
 
bool operator== (const XMLNode &node)
 Returns true if 'node' represents same XML element. More...
 
bool operator!= (const XMLNode &node)
 Returns false if 'node' represents same XML element. More...
 
bool Same (const XMLNode &node)
 Returns true if 'node' represents same XML element - for bindings. More...
 
bool operator== (bool val)
 This operator is needed to avoid ambiguity. More...
 
bool operator!= (bool val)
 This operator is needed to avoid ambiguity. More...
 
bool operator== (const std::string &str)
 This operator is needed to avoid ambiguity. More...
 
bool operator!= (const std::string &str)
 This operator is needed to avoid ambiguity. More...
 
bool operator== (const char *str)
 This operator is needed to avoid ambiguity. More...
 
bool operator!= (const char *str)
 This operator is needed to avoid ambiguity. More...
 
XMLNode Child (int n=0)
 Returns XMLNode instance representing n-th child of XML element. More...
 
XMLNode operator[] (const char *name) const
 Returns XMLNode instance representing first child element with specified name. More...
 
XMLNode operator[] (const std::string &name) const
 Returns XMLNode instance representing first child element with specified name. More...
 
XMLNode operator[] (int n) const
 Returns XMLNode instance representing n-th node in sequence of siblings of same name. More...
 
void operator++ (void)
 Convenience operator to switch to next element of same name. More...
 
void operator-- (void)
 Convenience operator to switch to previous element of same name. More...
 
int Size (void) const
 Returns number of children nodes. More...
 
XMLNode Get (const std::string &name) const
 Same as operator[](). More...
 
std::string Name (void) const
 Returns name of XML node. More...
 
std::string Prefix (void) const
 Returns namespace prefix of XML node. More...
 
std::string FullName (void) const
 Returns prefix:name of XML node. More...
 
std::string Namespace (void) const
 Returns namespace URI of XML node. More...
 
void Prefix (const std::string &prefix, int recursion=0)
 Assigns namespace prefix to XML node(s). More...
 
void StripNamespace (int recursion=0)
 Removes namespace prefix from XML node(s). More...
 
void Name (const char *name)
 Assigns new name to XML node. More...
 
void Name (const std::string &name)
 Assigns new name to XML node. More...
 
void GetXML (std::string &out_xml_str, bool user_friendly=false) const
 Fills argument with this instance XML subtree textual representation. More...
 
void GetXML (std::string &out_xml_str, const std::string &encoding, bool user_friendly=false) const
 Get string representation of XML subtree. More...
 
void GetDoc (std::string &out_xml_str, bool user_friendly=false) const
 Fills out_xml_str with whole XML document textual representation. More...
 
 operator std::string (void) const
 Returns textual content of node excluding content of children nodes. More...
 
XMLNodeoperator= (const char *content)
 Sets textual content of node. All existing children nodes are discarded. More...
 
XMLNodeoperator= (const std::string &content)
 Sets textual content of node. All existing children nodes are discarded. More...
 
void Set (const std::string &content)
 Same as operator=. Used for bindings. More...
 
XMLNodeoperator= (const XMLNode &node)
 Make instance refer to another XML node. Ownership is not inherited. More...
 
XMLNode Attribute (int n=0)
 Returns XMLNode instance reresenting n-th attribute of node. More...
 
XMLNode Attribute (const char *name)
 Returns XMLNode instance representing first attribute of node with specified by name. More...
 
XMLNode Attribute (const std::string &name)
 Returns XMLNode instance representing first attribute of node with specified by name. More...
 
XMLNode NewAttribute (const char *name)
 Creates new attribute with specified name. More...
 
XMLNode NewAttribute (const std::string &name)
 Creates new attribute with specified name. More...
 
int AttributesSize (void) const
 Returns number of attributes of node. More...
 
void Namespaces (const NS &namespaces, bool keep=false, int recursion=-1)
 Assigns namespaces of XML document at point specified by this instance. More...
 
NS Namespaces (void)
 Returns namespaces known at this node. More...
 
std::string NamespacePrefix (const char *urn)
 Returns prefix of specified namespace or empty string if no such namespace. More...
 
XMLNode NewChild (const char *name, int n=-1, bool global_order=false)
 Creates new child XML element at specified position with specified name. More...
 
XMLNode NewChild (const std::string &name, int n=-1, bool global_order=false)
 Same as NewChild(const char*,int,bool). More...
 
XMLNode NewChild (const char *name, const NS &namespaces, int n=-1, bool global_order=false)
 Creates new child XML element at specified position with specified name and namespaces. More...
 
XMLNode NewChild (const std::string &name, const NS &namespaces, int n=-1, bool global_order=false)
 Same as NewChild(const char*,const NS&,int,bool). More...
 
XMLNode NewChild (const XMLNode &node, int n=-1, bool global_order=false)
 Link a copy of supplied XML node as child. More...
 
void Replace (const XMLNode &node)
 Makes a copy of supplied XML node and makes this instance refer to it. More...
 
void Destroy (void)
 Destroys underlying XML element. More...
 
XMLNodeList Path (const std::string &path)
 Collects nodes corresponding to specified path. More...
 
XMLNodeList XPathLookup (const std::string &xpathExpr, const NS &nsList)
 Uses XPath to look up XML tree. More...
 
XMLNode GetRoot (void)
 Get the root node from any child node of the tree. More...
 
XMLNode Parent (void)
 Get the parent node from any child node of the tree. More...
 
bool SaveToFile (const std::string &file_name) const
 Save string representation of node to file. More...
 
bool SaveToStream (std::ostream &out) const
 Save string representation of node to stream. More...
 
bool ReadFromFile (const std::string &file_name)
 Read XML document from file and associate it with this node. More...
 
bool ReadFromStream (std::istream &in)
 Read XML document from stream and associate it with this node. More...
 
bool Validate (const std::string &schema_file, std::string &err_msg)
 XML schema validation against the schema file defined as argument. More...
 
bool Validate (XMLNode schema_doc, std::string &err_msg)
 

Static Public Member Functions

static bool elementtobool (Arc::XMLNode pnode, const char *ename, bool &val)
 Helper method for processing element value. More...
 
static bool elementtoenum (Arc::XMLNode pnode, const char *ename, int &val, const char *const opts[])
 Helper method for processing element value. More...
 
template<typename T >
static bool elementtoint (Arc::XMLNode pnode, const char *ename, T &val)
 Helper method for processing element value. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Arc::XMLNode
 XMLNode (xmlNodePtr node)
 Protected constructor for inherited classes. More...
 
bool Validate (xmlSchemaPtr schema, std::string &err_msg)
 
- Static Protected Member Functions inherited from Arc::XMLNode
static void LogError (void *ctx, const char *msg,...)
 
- Protected Attributes inherited from Arc::XMLNode
xmlNodePtr node_
 
bool is_owner_
 If true node is owned by this instance - hence released in destructor. More...
 
bool is_temporary_
 This variable is reserved for future use. More...
 

Detailed Description

Configuration element - represents (sub)tree of ARC XML configuration.

This class is intended to be used to pass configuration details to various parts of HED and external modules. Currently it's just a wrapper over XML tree. But that may change in the future, although the interface should be preserved. Currently it is capable of loading an XML configuration document from a file. In future it will be capable of loading a more user-readable format and processing it into a tree-like structure convenient for machine processing (XML-like). So far there are no schema and/or namespaces assigned.

Constructor & Destructor Documentation

◆ Config() [1/8]

Arc::Config::Config ( )
inline

Creates empty XML tree.

◆ Config() [2/8]

Arc::Config::Config ( const NS ns)
inline

Creates an empty configuration object with the given namespace.

◆ Config() [3/8]

Arc::Config::Config ( const char *  filename)

Loads configuration document from file at filename.

◆ Config() [4/8]

Arc::Config::Config ( const std::string &  xml_str)
inline

Parse configuration document from string.

◆ Config() [5/8]

Arc::Config::Config ( XMLNode  xml)
inline

Acquire existing XML (sub)tree.

Content is not copied. Make sure XML tree is not destroyed while in use by this object.

◆ Config() [6/8]

Arc::Config::Config ( XMLNode  xml,
const std::string &  filename 
)
inline

Acquire existing XML (sub)tree and set config file.

Content is not copied. Make sure XML tree is not destroyed while in use by this object.

◆ Config() [7/8]

Arc::Config::Config ( long  cfg_ptr_addr)

Copy constructor used by language bindings.

◆ Config() [8/8]

Arc::Config::Config ( const Config cfg)

Copy constructor used by language bindings.

Member Function Documentation

◆ elementtobool()

static bool Arc::Config::elementtobool ( Arc::XMLNode  pnode,
const char *  ename,
bool &  val 
)
static

Helper method for processing element value.

Extracts sub-element ename from pnode and tries to convert it into boolean. In case of success returns true and fills result into val reference.

◆ elementtoenum()

static bool Arc::Config::elementtoenum ( Arc::XMLNode  pnode,
const char *  ename,
int &  val,
const char *const  opts[] 
)
static

Helper method for processing element value.

Extracts sub-element ename from pnode and tries to convert it into enumeration defined by opts. In case of success returns true and fills result into val reference.

◆ elementtoint()

template<typename T >
static bool Arc::Config::elementtoint ( Arc::XMLNode  pnode,
const char *  ename,
T &  val 
)
inlinestatic

Helper method for processing element value.

Extracts sub-element ename from pnode and tries to convert it into integer number. In case of success returns true and fills result into val reference.

◆ getFileName()

const std::string& Arc::Config::getFileName ( void  ) const
inline

Returns file name of config file or empty string if it was generated from the XMLNode subtree.

◆ parse()

bool Arc::Config::parse ( const char *  filename)

Parse configuration document from file at filename.

◆ print()

void Arc::Config::print ( void  )

Print structure of document for debugging purposes.

Printed content is not an XML document.

Python interface deviation
Renamed to _print in Python interface

◆ save()

void Arc::Config::save ( const char *  filename)

Save config to file.

◆ setFileName()

void Arc::Config::setFileName ( const std::string &  filename)
inline

Set the file name of config file.


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