Resources Class Reference

A Resources object represents a set of named values. Both the names and the values are strings. Thus, a Resources object is roughly equivalent to the operating system's environment structure but Resource are not identical with environment variables because they cannot be obtained using getenv(), and cannot be set using putenv. More...

#include <resources.h>

Collaboration diagram for Resources:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::pair< string, bool > ReturnString
 The return value from queries often includes both a string < and a value indicating that the string value is actually < valid. If the value is empty, is it because there was no < value found, or is it because the string was indeed empty? < The second value tells you. True means that it was found.
typedef std::map< string, stringSettings
 Resource settings are stored in a map.
typedef std::string string
 Use standard strings to represent text.
typedef std::list< stringStringList
 A list of strings.

Public Member Functions

ReturnString find (string const &name) const
 Search for a given resource and return both its value and a < flag indicating that it was found.
void print () const
 Write the resources to std::cout for debugging purposes.
void read (StringList const &files)
 read the named resources files and accumulate them into this < Resources object (just like the constructor, above)
 Resources ()
 An empty resources set can be created and then populated using the < set method.
 Resources (StringList const &files)
 Construct resources by specifying a list of file names to read. < If one of the names does not exist, the error will be silently < ignored.
void set (string const &name, string const &value)
 Override a resource's value.
 ~Resources ()
 Upon destruction, free all memory etc.

Private Attributes

Settings map_
 The resource settings.

Friends

std::ostream & operator<< (std::ostream &s, Resources const &)
 Resources can be written to a stream -- mainly so that they < can be debugged, however.

Detailed Description

A Resources object represents a set of named values. Both the names and the values are strings. Thus, a Resources object is roughly equivalent to the operating system's environment structure but Resource are not identical with environment variables because they cannot be obtained using getenv(), and cannot be set using putenv.

Resources are meant to be stored in a file used by an application to permit the user to configure its behaviour. Resource files can be merged automatically so that configurations can be specified in multiple places -- with the last place winning.

Resources are specified in files using the following syntax:

        #
        # this is a comment
        #
        name = value  # this is a comment, also
        
        long = value \        # begins a continuation
               more values \  # continues the continuation
               more values \  # more continuation
               last value     # ends the continuation

Comments begin with # unless escaped: "\#" is not a comment, and is left in the value or name without the leading \ character

The name must not have spaces and the equal can have spaces around it.

Leading and trailing spaces are removed from continuation lines and trailing spaces before the \ character are removed from first line of a continuation sequence. A single space is placed before continuation lines before joining them. Thus, the continuation lines above result in the following setting:

        long=value more values more values last value

Definition at line 44 of file resources.h.


Member Typedef Documentation

typedef std::pair<string, bool> ReturnString

The return value from queries often includes both a string < and a value indicating that the string value is actually < valid. If the value is empty, is it because there was no < value found, or is it because the string was indeed empty? < The second value tells you. True means that it was found.

Definition at line 93 of file resources.h.

typedef std::map<string,string> Settings

Resource settings are stored in a map.

Definition at line 100 of file resources.h.

typedef std::string string

Use standard strings to represent text.

Definition at line 87 of file resources.h.

typedef std::list<string> StringList

A list of strings.

Definition at line 90 of file resources.h.


Constructor & Destructor Documentation

Resources ( StringList const &  files  ) 

Construct resources by specifying a list of file names to read. < If one of the names does not exist, the error will be silently < ignored.

Definition at line 27 of file resources.cxx.

Here is the call graph for this function:

Resources (  ) 

An empty resources set can be created and then populated using the < set method.

Definition at line 16 of file resources.cxx.

~Resources (  ) 

Upon destruction, free all memory etc.

Definition at line 22 of file resources.cxx.


Member Function Documentation

Resources::ReturnString find ( string const &  name  )  const

Search for a given resource and return both its value and a < flag indicating that it was found.

Definition at line 199 of file resources.cxx.

void print (  )  const

Write the resources to std::cout for debugging purposes.

Definition at line 242 of file resources.cxx.

void read ( StringList const &  files  ) 

read the named resources files and accumulate them into this < Resources object (just like the constructor, above)

Definition at line 67 of file resources.cxx.

Here is the call graph for this function:

Here is the caller graph for this function:

void set ( string const &  name,
string const &  value 
)

Override a resource's value.

Definition at line 214 of file resources.cxx.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
Resources const &  r 
) [friend]

Resources can be written to a stream -- mainly so that they < can be debugged, however.

Definition at line 225 of file resources.cxx.


Member Data Documentation

Settings map_ [private]

The resource settings.

Definition at line 136 of file resources.h.


The documentation for this class was generated from the following files:
Generated on Wed Feb 29 22:56:12 2012 for CXXUtilities by  doxygen 1.6.3