0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
Hypertable::Properties Class Reference

Manages a collection of program options. More...

#include <Properties.h>

Collaboration diagram for Hypertable::Properties:
Collaboration graph
[legend]

Public Member Functions

 Properties ()
 Default constructor; creates an empty set. More...
 
 Properties (const String &filename, const PropertiesDesc &desc, bool allow_unregistered=false)
 Constructor; load properties from a filename. More...
 
void load (const String &filename, const PropertiesDesc &desc, bool allow_unregistered=false)
 Loads a configuration file with properties. More...
 
void parse_args (int argc, char *argv[], const PropertiesDesc &desc, const PropertiesDesc *hidden=0, const PositionalDesc *p=0, bool allow_unregistered=false)
 Parses command line arguments. More...
 
void parse_args (const std::vector< String > &args, const PropertiesDesc &desc, const PropertiesDesc *hidden=0, const PositionalDesc *p=0, bool allow_unregistered=false)
 Parses command line arguments. More...
 
void notify ()
 Calls user-defined notifier functions (if any) with final values. More...
 
template<typename T >
get (const String &name) const
 Get the value of option of type T. More...
 
template<typename T >
get (const String &name, const T &default_value) const
 Get the value of option of type T. More...
 
const boost::any & operator[] (const String &name) const
 Get the underlying boost::any value of 'name'. More...
 
bool defaulted (const String &name) const
 Check whether a property has a default value. More...
 
bool has (const String &name) const
 Check whether a property exists. More...
 
InsRet add (const String &name, const boost::any &v, bool defaulted=false)
 Add property to the map. More...
 
void set (const String &name, const boost::any &v, bool defaulted=false)
 Set a property in the map, create if not found. More...
 
void remove (const String &name)
 Remove a property from the map. More...
 
void alias (const String &primary, const String &secondary, bool overwrite=false)
 Setup an alias for a property. More...
 
void sync_aliases ()
 Sync alias values. More...
 
void get_names (std::vector< String > &names)
 Returns all property names. More...
 
void print (std::ostream &out, bool include_default=false)
 Prints keys and values of the configuration map. More...
 

Static Public Member Functions

static String to_str (const boost::any &a)
 Helper to print boost::any used by property values. More...
 

Private Types

typedef Po::variable_value Value
 
typedef Po::variables_map Map
 
typedef std::pair
< Map::iterator, bool > 
InsRet
 
typedef std::map< String, StringAliasMap
 

Private Attributes

bool m_need_alias_sync
 Whether the aliases need to be synced. More...
 
Map m_map
 The map containing all properties. More...
 
AliasMap m_alias_map
 A map with all aliases. More...
 

Detailed Description

Manages a collection of program options.

Implements getters and setters, aliases and default values.

Definition at line 208 of file Properties.h.

Member Typedef Documentation

typedef std::map<String, String> Hypertable::Properties::AliasMap
private

Definition at line 212 of file Properties.h.

typedef std::pair<Map::iterator, bool> Hypertable::Properties::InsRet
private

Definition at line 211 of file Properties.h.

typedef Po::variables_map Hypertable::Properties::Map
private

Definition at line 210 of file Properties.h.

typedef Po::variable_value Hypertable::Properties::Value
private

Definition at line 209 of file Properties.h.

Constructor & Destructor Documentation

Hypertable::Properties::Properties ( )
inline

Default constructor; creates an empty set.

Definition at line 216 of file Properties.h.

Hypertable::Properties::Properties ( const String filename,
const PropertiesDesc desc,
bool  allow_unregistered = false 
)
inline

Constructor; load properties from a filename.

Parameters
filenameThe name of the file with the properties
descA Property description with valid properties, default values
allow_unregisteredIf true, unknown/unregistered properties are accepted

Definition at line 227 of file Properties.h.

Member Function Documentation

InsRet Hypertable::Properties::add ( const String name,
const boost::any &  v,
bool  defaulted = false 
)
inline

Add property to the map.

Parameters
nameThe name of the property
vThe value of the property
defaultedTrue if the value is default
Returns
An iterator to the new item

Definition at line 360 of file Properties.h.

void Properties::alias ( const String primary,
const String secondary,
bool  overwrite = false 
)

Setup an alias for a property.

The primary property has higher priority, meaning when aliases are sync'ed the primary value can override secondary value

Parameters
primaryThe primary property name
secondaryThe secondary property name
overwriteTrue if an existing alias should be overwritten

Definition at line 203 of file Properties.cc.

bool Hypertable::Properties::defaulted ( const String name) const
inline

Check whether a property has a default value.

Parameters
nameThe name of the property
Returns
true if the value is default

Definition at line 337 of file Properties.h.

template<typename T >
T Hypertable::Properties::get ( const String name) const
inline

Get the value of option of type T.

Throws if option is not defined.

Parameters
nameThe name of the property
Exceptions
Error::CONFIG_GET_ERRORif the requested property is not defined

Definition at line 287 of file Properties.h.

template<typename T >
T Hypertable::Properties::get ( const String name,
const T &  default_value 
) const
inline

Get the value of option of type T.

Returns supplied default value if not found. Try use the first form in usual cases and supply default values in the config descriptions, as it validates the name and is less error prone.

Parameters
nameThe name of the property
default_valueThe default value to return if not found

Definition at line 307 of file Properties.h.

void Hypertable::Properties::get_names ( std::vector< String > &  names)
inline

Returns all property names.

Parameters
namesreference to vector to hold names of all properties

Definition at line 415 of file Properties.h.

bool Hypertable::Properties::has ( const String name) const
inline

Check whether a property exists.

Parameters
nameThe name of the property
Returns
true if the property exists

Definition at line 346 of file Properties.h.

void Properties::load ( const String filename,
const PropertiesDesc desc,
bool  allow_unregistered = false 
)

Loads a configuration file with properties.

Parameters
filenameThe name of the configuration file
descA property description
allow_unregisteredIf true, unknown/unregistered properties are accepted

Definition at line 144 of file Properties.cc.

void Properties::notify ( )

Calls user-defined notifier functions (if any) with final values.

Definition at line 199 of file Properties.cc.

const boost::any& Hypertable::Properties::operator[] ( const String name) const
inline

Get the underlying boost::any value of 'name'.

Parameters
nameThe name of the property

Definition at line 327 of file Properties.h.

void Properties::parse_args ( int  argc,
char *  argv[],
const PropertiesDesc desc,
const PropertiesDesc hidden = 0,
const PositionalDesc p = 0,
bool  allow_unregistered = false 
)

Parses command line arguments.

Parameters
argcThe argument count (from main)
argvThe argument array (from main)
descThe options description
hiddenThe hidden options description
pThe positional options description
allow_unregisteredIf true, unknown/unregistered properties are accepted
Exceptions
Error::CONFIG_INVALID_ARGUMENTon error

Definition at line 172 of file Properties.cc.

void Properties::parse_args ( const std::vector< String > &  args,
const PropertiesDesc desc,
const PropertiesDesc hidden = 0,
const PositionalDesc p = 0,
bool  allow_unregistered = false 
)

Parses command line arguments.

Parameters
argsA vector of Strings with the command line arguments
descThe options description
hiddenThe hidden options description
pThe positional options description
allow_unregisteredIf true, unknown/unregistered properties are accepted
Exceptions
Error::CONFIG_INVALID_ARGUMENTon error

Definition at line 188 of file Properties.cc.

void Properties::print ( std::ostream &  out,
bool  include_default = false 
)

Prints keys and values of the configuration map.

Parameters
outThe output stream
include_defaultIf true then default values are included

Definition at line 274 of file Properties.cc.

void Hypertable::Properties::remove ( const String name)
inline

Remove a property from the map.

Parameters
nameThe name of the property

Definition at line 384 of file Properties.h.

void Hypertable::Properties::set ( const String name,
const boost::any &  v,
bool  defaulted = false 
)
inline

Set a property in the map, create if not found.

Parameters
nameThe name of the property
vThe value of the property
defaultedTrue if the value is default

Definition at line 372 of file Properties.h.

void Properties::sync_aliases ( )

Sync alias values.

After this operation all properties that are aliases to each other have the same value. Value priority: primary non-default > secondary non-default > primary default > secondary default

Definition at line 213 of file Properties.cc.

String Properties::to_str ( const boost::any &  a)
static

Helper to print boost::any used by property values.

Parameters
aReference to the boost::any value
Returns
A string with the formatted value

Definition at line 237 of file Properties.cc.

Member Data Documentation

AliasMap Hypertable::Properties::m_alias_map
private

A map with all aliases.

Definition at line 444 of file Properties.h.

Map Hypertable::Properties::m_map
private

The map containing all properties.

Definition at line 441 of file Properties.h.

bool Hypertable::Properties::m_need_alias_sync
private

Whether the aliases need to be synced.

Definition at line 438 of file Properties.h.


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