51 #include <boost/iterator/transform_iterator.hpp>
52 #include <boost/mpi/communicator.hpp>
53 #include <boost/filesystem.hpp>
57 #define MAX_PROP_FILE_SIZE 16384
65 struct KeyGetter:
public std::unary_function<std::map<std::string, std::string>::value_type, std::string> {
66 std::string operator()(
const std::map<std::string, std::string>::value_type& value)
const;
80 std::map<std::string, std::string> map;
84 typedef boost::transform_iterator<KeyGetter, std::map<std::string, std::string>::const_iterator> key_iterator;
107 Properties(
const std::string& file, boost::mpi::communicator* comm = 0,
int maxPropFileSize = MAX_PROP_FILE_SIZE);
134 Properties(
const std::string& file,
int argc,
char** argv, boost::mpi::communicator* comm = 0,
int maxPropFileSize = MAX_PROP_FILE_SIZE);
156 void putProperty(
const std::string& key, std::string value);
167 void putProperty(
const std::string& key,
long double value);
178 std::string
getProperty(
const std::string& key)
const;
185 bool contains(
const std::string& key)
const;
193 return key_iterator(map.begin());
202 return key_iterator(map.end());
218 void readFile(
const std::string& file, boost::mpi::communicator* comm = 0,
int maxPropFileSize = MAX_PROP_FILE_SIZE);
252 void log(std::string logName, std::vector<std::string> *keysToWrite = 0){
253 if(keysToWrite != 0){
254 std::vector<std::string>::iterator iter = keysToWrite->begin();
255 std::vector<std::string>::iterator iterEnd = keysToWrite->end();
256 while(iter != iterEnd){
257 Log4CL::instance()->get_logger(logName).log(INFO, (*iter) +
" = " + (
getProperty(*iter)));
262 std::map<std::string, std::string>::iterator iter = map.begin();
263 std::map<std::string, std::string>::iterator iterEnd = map.end();
264 while(iter != iterEnd){
265 Log4CL::instance()->get_logger(logName).log(INFO, iter->first +
" = " + iter->second);
279 void writeToSVFile(std::string fileName, std::string separator =
",");
288 void writeToSVFile(std::string fileName, std::vector<std::string> &keysToWrite, std::string separator =
",");
305 bool writeToPropsFile(std::string filename, std::vector<std::string> &keysToWrite, std::string header=
"");
312 std::string
propsFileString(std::vector<std::string> &keysToWrite, std::string header=
"");
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)
Definition: Properties.h:252
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.
Definition: Properties.cpp:98
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...
Definition: Properties.cpp:200
int size() const
Gets the number of properties in this Properties.
Definition: Properties.h:236
void putProperty(const std::string &key, std::string value)
Puts a property into this Properties with the specified key and value.
Definition: Properties.cpp:78
key_iterator keys_end() const
Gets the end of an iterator over this Properties' keys.
Definition: Properties.h:201
void writeToSVFile(std::string fileName, std::string separator=",")
Writes the contents of the properties file to the specified separated-value file.
Definition: Properties.cpp:158
key_iterator keys_begin() const
Gets the start of an iterator over this Properties' keys.
Definition: Properties.h:192
Properties()
Creates an empty Properties.
Definition: Properties.cpp:62
bool contains(const std::string &key) const
Gets whether or not this Properties contains the specified key.
Definition: Properties.cpp:86
std::string getProperty(const std::string &key) const
Gets the property with the specified key.
Definition: Properties.cpp:90
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.
Definition: Properties.cpp:220
Map type object that contains key, value(string) properties.
Definition: Properties.h:77
Unary function used in a transform_iterator that allows the map iterator to return the keys.
Definition: Properties.h:65
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 pro...
Definition: Properties.cpp:149