RepastHPC  2.3.1
Public Types | Public Member Functions | List of all members
repast::Properties Class Reference

Map type object that contains key, value(string) properties. More...

#include <Properties.h>

Public Types

typedef boost::transform_iterator< KeyGetter, std::map< std::string, std::string >::const_iterator > key_iterator
 

Public Member Functions

 Properties ()
 Creates an empty Properties.
 
 Properties (const std::string &file, boost::mpi::communicator *comm=0, int maxPropFileSize=MAX_PROP_FILE_SIZE)
 Creates a new Properties using the properties defined in the specified file. More...
 
 Properties (const std::string &file, int argc, char **argv, boost::mpi::communicator *comm=0, int maxPropFileSize=MAX_PROP_FILE_SIZE)
 Creates a new Properties using the properties defined in the specified file and any properties specified in Key=Val format in the argument array. More...
 
 Properties (int argc, char **argv)
 Creates a new Properties using the properties specified in Key=Val format in the argument. More...
 
void putProperty (const std::string &key, std::string value)
 Puts a property into this Properties with the specified key and value. More...
 
void putProperty (const std::string &key, long double value)
 Puts a property into this Properties with the specified key and value. More...
 
std::string getProperty (const std::string &key) const
 Gets the property with the specified key. More...
 
bool contains (const std::string &key) const
 Gets whether or not this Properties contains the specified key. More...
 
key_iterator keys_begin () const
 Gets the start of an iterator over this Properties' keys. More...
 
key_iterator keys_end () const
 Gets the end of an iterator over this Properties' keys. More...
 
void readFile (const std::string &file, boost::mpi::communicator *comm=0, int maxPropFileSize=MAX_PROP_FILE_SIZE)
 Adds any properties defined in the specified file. More...
 
void processCommandLineArguments (int argc, char **argv)
 Processes a char** array of the given size; any component that has an equals sign is entered as a property value, overriding any previous entry read from the properies file. More...
 
int size () const
 Gets the number of properties in this Properties. More...
 
void log (std::string logName, std::vector< std::string > *keysToWrite=0)
 Writes the contents of the properties file to the specified repast log (at 'INFO' log level) More...
 
void writeToSVFile (std::string fileName, std::string separator=",")
 Writes the contents of the properties file to the specified separated-value file. More...
 
void writeToSVFile (std::string fileName, std::vector< std::string > &keysToWrite, std::string separator=",")
 Writes the contents of the properties file to the specified separated-value file. More...
 
bool writeToPropsFile (std::string filename, std::string header="")
 Writes the contents of this properties object to a file that could be read as another properties file. More...
 
bool writeToPropsFile (std::string filename, std::vector< std::string > &keysToWrite, std::string header="")
 Writes the contents of this properties object to a file that could be read as another properties file, writing only the keys specified, in the order specified. More...
 
std::string propsFileString (std::vector< std::string > &keysToWrite, std::string header="")
 Gets the string that will be written to a properties file using the writeToPropsFile methods.
 

Detailed Description

Map type object that contains key, value(string) properties.

A Properties instance can be constructed from a file. Each line is a property with the key and value separated by =. For example,

some.property = 3
another.property = hello

Constructor & Destructor Documentation

◆ Properties() [1/3]

repast::Properties::Properties ( const std::string &  file,
boost::mpi::communicator *  comm = 0,
int  maxPropFileSize = MAX_PROP_FILE_SIZE 
)

Creates a new Properties using the properties defined in the specified file.

Each line is a property with the key and value separated by =. For example,

some.property = 3
another.property = hello

Parameters
filethe properties file path
commpointer to a communicator; if null (the default), all processes read the properties file separately. If a communicator is provided, rank 0 reads the file and broadcasts it to all other ranks.
maxPropFileSizeoptional parameter; if the properties file is larger than the default MAX_PROP_FILE_SIZE, the new size can be passed here.

◆ Properties() [2/3]

repast::Properties::Properties ( const std::string &  file,
int  argc,
char **  argv,
boost::mpi::communicator *  comm = 0,
int  maxPropFileSize = MAX_PROP_FILE_SIZE 
)

Creates a new Properties using the properties defined in the specified file and any properties specified in Key=Val format in the argument array.

Properties in the argument array will supersede any in the properties file.

Each line in the properties file is a property with the key and value separated by =. For example,

some.property = 3
another.property = hello

Parameters
filethe properties file path
argccount of the elements in the argv array
arrayof char* that may include Key=Value pairs. Elements with no '=' are ignored.
commpointer to a communicator; if null (the default), all processes read the properties file separately. If a communicator is provided, rank 0 reads the file and broadcasts it to all other ranks.
maxPropFileSizeoptional parameter; if the properties file is larger than the default MAX_PROP_FILE_SIZE, the new size can be passed here.

◆ Properties() [3/3]

repast::Properties::Properties ( int  argc,
char **  argv 
)

Creates a new Properties using the properties specified in Key=Val format in the argument.

Parameters
argccount of the elements in the argv array
arrayof char* that may include Key=Value pairs. Elements with no '=' are ignored.

Member Function Documentation

◆ contains()

bool repast::Properties::contains ( const std::string &  key) const

Gets whether or not this Properties contains the specified key.

Parameters
keythe property key

◆ getProperty()

string repast::Properties::getProperty ( const std::string &  key) const

Gets the property with the specified key.

Parameters
keythe property key
Returns
the value for that key, or an empty string if the property is not found.

◆ keys_begin()

key_iterator repast::Properties::keys_begin ( ) const
inline

Gets the start of an iterator over this Properties' keys.

Returns
the start of an iterator over this Properties' keys.

◆ keys_end()

key_iterator repast::Properties::keys_end ( ) const
inline

Gets the end of an iterator over this Properties' keys.

Returns
the end of an iterator over this Properties' keys.

◆ log()

void repast::Properties::log ( std::string  logName,
std::vector< std::string > *  keysToWrite = 0 
)
inline

Writes the contents of the properties file to the specified repast log (at 'INFO' log level)

Parameters
logNamename of the log to use
keysToWriteoptional; if included, writes only the keys included in the vector and their values, in the order they appear in the vector. Will write blank values for any key name in the vector that is not in the properties file. If not included, all properties and their values are written, in map order.

◆ processCommandLineArguments()

void repast::Properties::processCommandLineArguments ( int  argc,
char **  argv 
)

Processes a char** array of the given size; any component that has an equals sign is entered as a property value, overriding any previous entry read from the properies file.

Parameters
argcthe number of entries in the array
argvthe array of char values to be mapped

◆ putProperty() [1/2]

void repast::Properties::putProperty ( const std::string &  key,
long double  value 
)

Puts a property into this Properties with the specified key and value.

Note that even though the second argument can be passed as a numeric value, it is stored as a string

Parameters
keythe property key
valuethe property value

◆ putProperty() [2/2]

void repast::Properties::putProperty ( const std::string &  key,
std::string  value 
)

Puts a property into this Properties with the specified key and value.

Parameters
keythe property key
valuethe property value

◆ readFile()

void repast::Properties::readFile ( const std::string &  file,
boost::mpi::communicator *  comm = 0,
int  maxPropFileSize = MAX_PROP_FILE_SIZE 
)

Adds any properties defined in the specified file.

Each line is a property with the key and value separated by =. For example,

some.property = 3
another.property = hello

Parameters
filethe properties file path
commpointer to a communicator; if null (the default), all processes read the properties file separately. If a communicator is provided, rank 0 reads the file and broadcasts it to all other ranks.

◆ size()

int repast::Properties::size ( ) const
inline

Gets the number of properties in this Properties.

Returns
the number of properties in this Properties.

◆ writeToPropsFile() [1/2]

bool repast::Properties::writeToPropsFile ( std::string  filename,
std::string  header = "" 
)

Writes the contents of this properties object to a file that could be read as another properties file.

If a file with the specified name already exists, the existing file will not be changed and 'false' will be returned.

◆ writeToPropsFile() [2/2]

bool repast::Properties::writeToPropsFile ( std::string  filename,
std::vector< std::string > &  keysToWrite,
std::string  header = "" 
)

Writes the contents of this properties object to a file that could be read as another properties file, writing only the keys specified, in the order specified.

If a file with the specified name already exists, the existing file will not be changed and 'false' will be returned.

◆ writeToSVFile() [1/2]

void repast::Properties::writeToSVFile ( std::string  fileName,
std::string  separator = "," 
)

Writes the contents of the properties file to the specified separated-value file.

If the file does not exist it is created and a header line is written with the key values.

Parameters
fileNamename

◆ writeToSVFile() [2/2]

void repast::Properties::writeToSVFile ( std::string  fileName,
std::vector< std::string > &  keysToWrite,
std::string  separator = "," 
)

Writes the contents of the properties file to the specified separated-value file.

If the file does not exist it is created and a header line is written with the key values.

Parameters
fileNamename

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