Public Types | Public Member Functions | Static Public Member Functions | List of all members
ibis::resource Class Reference

A container for name-value pairs. More...

#include <resource.h>

Public Types

typedef std::map< const char *, resource *, ibis::lessi > gList
 The name-value pairs are categorized into two types, names that map to simple values (vList) and names that map to groups of name-value pairs (gList). More...
 
typedef std::map< const char *, char *, ibis::lessi > vList
 

Public Member Functions

void add (const char *name, const char *value)
 Add a name-value pair to the resource list. More...
 
bool empty () const
 Returns true if there is no name-value pair on record.
 
gList::const_iterator gBegin () const
 
gList::const_iterator gEnd () const
 
const resourcegetGroup (const char *name) const
 Find a group with the given name. More...
 
double getNumber (const char *name) const
 Locate the named parameter and return its value as a number. More...
 
std::string getPrefix () const
 Return the name of the full prefix of the resource.
 
const char * getValue (const char *name) const
 Find a named parameter. More...
 
bool isTrue (const char *name) const
 Locate the named parameter and return its value as true or false. More...
 
resourceoperator= (const resource &rhs)
 The assignment operator.
 
const char * operator[] (const char *name) const
 Locate the named parameter and return its value in raw string form. More...
 
int read (const char *fn=0)
 Read a configuration file. More...
 
 resource ()
 Default constructor. Creates an empty object.
 
 resource (const char *fn)
 Read the content of a parameter file.
 
 resource (const resource *ctx, const char *pfx)
 Create an empty object with the specified prefix and context.
 
 resource (const resource &rhs)
 Copy constructor. Deep copy.
 
vList::const_iterator vBegin () const
 
vList::const_iterator vEnd () const
 
void write (const char *fn=0) const
 Write the content to a file. More...
 

Static Public Member Functions

static void clear (vList &vl)
 Clear a vList. More...
 
static bool isStringTrue (const char *val)
 Returns true is the string value should be interpreted as logical truth. More...
 
static void parseNameValuePairs (const char *in, vList &lst)
 Parse a string into a name-value list. More...
 

Detailed Description

A container for name-value pairs.

It is mostly used for storing the configuration parameters. The parameters are in a format as follows:

group:group:...:name=value

where the delimiter can be either '*', ':' or '.' and anything following the first '=' sign is assumed to be part of the value string until the end of line. The leading and trailing spaces are removed from both the name and the value. The specification that appears later in the same configuration file or read later (through a call to read()) will overwrite the parameter with the same name. This include the groups and individual parameters. For example if a parameter named 'abcd' is specified first, but later, the same name is used as a group name, then the previously specified parameter will be removed from the list and the new group will be inserted. If the parameter with name 'abcd' appeared again, then the group 'abcd' will be removed and the named parameter will be inserted.

The line length must of no more than MAX_LINE defined in const.h.

The top level group name can be any one of the following: all, common, and '*'. When writing out the parameters, the top level name is not written.

Member Typedef Documentation

typedef std::map< const char*, resource*, ibis::lessi > ibis::resource::gList

The name-value pairs are categorized into two types, names that map to simple values (vList) and names that map to groups of name-value pairs (gList).

Member Function Documentation

void ibis::resource::add ( const char *  name,
const char *  value 
)

Add a name-value pair to the resource list.

It replaces the existing value.

References add(), ibis::util::delimiters, ibis::util::strnewdup(), and ibis::util::trim().

Referenced by add(), ibis::query::keepQueryRecords(), read(), and ibis::query::removeQueryRecords().

void ibis::resource::clear ( vList &  vl)
static

Clear a vList.

Delete a simple list of name-value pairs.

References clear().

Referenced by clear().

const ibis::resource * ibis::resource::getGroup ( const char *  name) const
inline

Find a group with the given name.

The name is expected to be a simple name without any separators. Any separator in the name will cause it to return a nil pointer.

double ibis::resource::getNumber ( const char *  name) const

Locate the named parameter and return its value as a number.

Parse the string value as a number.

If the first non-numeric character is a 'k' or 'm' or 'g', the proceeding number is mutiplied by 1024, 1048576, or 1073742824. If the first non-numeric character is 'h', the value before it is multiplied by 3600 (h for hour), converting it from hours to seconds.

References ibis::util::readDouble().

Referenced by ibis::fileManager::fileManager().

const char * ibis::resource::getValue ( const char *  name) const
inline

Find a named parameter.

The name is expected to be a simple name without any separators. Any separator in it will cause a nil pointer to be returned.

Referenced by ibis::util::gatherParts().

bool ibis::resource::isStringTrue ( const char *  val)
inlinestatic

Returns true is the string value should be interpreted as logical truth.

The string values string with 'y', 't', and '1' (the number one), and the string "on" are interpreted as true. All other strings are interpreted as false.

Referenced by ibis::column::column(), and ibis::part::part().

bool ibis::resource::isTrue ( const char *  name) const

Locate the named parameter and return its value as true or false.

If the named parameter exists and its value is one of "true", "yes", "on" or "1", this function will return true, otherwise false.

Referenced by ibis::index::create(), ibis::part::selfTest(), ibis::relic::speedTest(), and ibis::bin::speedTest().

const char * ibis::resource::operator[] ( const char *  name) const

Locate the named parameter and return its value in raw string form.

The incoming name can contain multiple separators.

Each component of the name is separated by one separator. From the left to right, the left-most component defines the highest level of the hierarchy. A high-level name forms the context for the next level of the name hierarchy. The final component of the name is directly associated with a string value. The search algorithm first descend to the lowest level with the matching names and starts to look for a name that matches the last component of the specified name. If a match is not found, it will go back one level and perform the same search. This continues until a match is found or it has searched all the levels.

References ibis::util::delimiters, ibis::util::strnewdup(), and ibis::util::trim().

void ibis::resource::parseNameValuePairs ( const char *  in,
vList &  lst 
)
static

Parse a string into a name-value list.

Parse a string of the form "name=vale, name=value, ..." into a simple list of name-value pairs.

Add the new ones to the incoming list, lst.

The list is sparated by comas or blank spaces. Every character before the equal sign is treated as part of the name except the blank space surrounding the string. Therefore, embedded blanks are allowed here, but this usage is not consistent of the SQL naming convention and is therefore discoveraged. Each value can be a single non-empty string or collection of string values surrended by parentheses or quotes. The parentheses and quotes may be nested, but has to match properly. For example, the following strings are valid input strings: "pressure = 1.025E10, template = (10, 10, 5)" and "meshShape = (ny=100, nx=100), creator = 'octave version 1.2'". Here is the list of special characters can contain compound values:

  • ()
  • []
  • {}
  • ""
  • ''
  • `'

When the openning character of a pair is encountered, this function will not recognize the normal terminators untill the corresponding matching closing character is found or the end of the string is found.

References ibis::util::strnewdup().

Referenced by ibis::math::variable::printFull(), ibis::part::readMetaData(), and ibis::column::setTimeFormat().

int ibis::resource::read ( const char *  fn = 0)

Read a configuration file.

It will open the first file in the following list and add the content to the existing list of parameter,

  • (1) argument to this function (fn),
  • (2) environment variable IBISRC,
  • (3) file named ibis.rc in the current directory,
  • (4) file named .ibisrc in the current directory,
  • (5) file named .ibisrc in the user's home directory (if the environment variable HOME is defined).

It attempts to parse the content of the first file it finds. The content of the file is added to the current content of the resouce object. The parameters with the same names will overwrite the existing values.

If it can not find any one of these files, it will return without modifying the current content of the resource object.

Return values: 0 – normal return, -1 – the incoming argument appears to point to a valid file, but the file can not be opened, +1 – can not open any of the default files specified in the above list.

References add(), ibis::util::getFileSize(), ibis::util::trim(), and write().

Referenced by fastbit_init(), ibis::init(), and resource().

void ibis::resource::write ( const char *  fn = 0) const

Write the content to a file.

If the file name is a nil pointer, the pairs are written to the standard output. If it can not open the named file, it will also write to the standard output.

References ibis::util::write().

Referenced by read().


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

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive