ConfigMap Class Reference

ConfigMap defines a simple container for configuration parameter/value pairs. More...

#include <ConfigMap.h>

Inheritance diagram for ConfigMap:

TraceSource List of all members.

Public Member Functions

 ConfigMap ()
 Creates an empty map.
virtual ~ConfigMap ()
 Destroys the map.
void readParams (std::istream &paramStream)
 Reads parameter name/value pairs from an input stream, until end-of-stream is encountered.
void dumpParams (std::ostream &dumpStream) const
 Dumps all parameter settings to a stream.
void mergeFrom (const ConfigMap &)
 Merges in all the parameters from another map.
std::string getStringParam (std::string paramName, std::string defaultVal="") const
 Gets the value of a string-typed parameter.
int getIntParam (std::string paramName, int defaultVal=0) const
 Gets the value of an integer-typed parameter.
long getLongParam (std::string paramName, long defaultVal=0) const
 Gets the value of a long-typed parameter.
bool getBoolParam (std::string paramName, bool defaultVal=false) const
 Gets the value of an boolean-typed parameter.
bool isParamSet (std::string paramName) const
 Determines whether a parameter has an associated value.
void setStringParam (std::string paramName, std::string paramVal)
 Sets an individual parameter value.
void clear ()
 Clears all parameters.
virtual void initTraceSource (SharedTraceTarget pTraceTarget, std::string name)
 For use when initialization has to be deferred until after construction.
void trace (TraceLevel level, std::string message) const
 Records a trace message.
bool isTracing () const
 
Returns:
true iff tracing is enabled for this source

bool isTracingLevel (TraceLevel level) const
 Determines whether a particular level is being traced.
TraceTargetgetTraceTarget () const
 
Returns:
the TraceTarget for this source

SharedTraceTarget getSharedTraceTarget () const
 
Returns:
the SharedTraceTarget for this source

std::string getTraceSourceName () const
 Gets the name of this source.
void setTraceSourceName (std::string const &n)
 Sets the name of this source.
TraceLevel getMinimumTraceLevel () const
void disableTracing ()

Private Types

typedef std::map< std::string,
std::string > 
StringMap
typedef StringMap::iterator StringMapIter
typedef StringMap::const_iterator StringMapConstIter

Private Attributes

StringMap paramVals

Detailed Description

ConfigMap defines a simple container for configuration parameter/value pairs.

Definition at line 37 of file ConfigMap.h.


Member Typedef Documentation

typedef std::map<std::string,std::string> ConfigMap::StringMap [private]

Definition at line 39 of file ConfigMap.h.

typedef StringMap::iterator ConfigMap::StringMapIter [private]

Definition at line 40 of file ConfigMap.h.

typedef StringMap::const_iterator ConfigMap::StringMapConstIter [private]

Definition at line 41 of file ConfigMap.h.


Constructor & Destructor Documentation

ConfigMap::ConfigMap (  )  [explicit]

Creates an empty map.

Definition at line 32 of file ConfigMap.cpp.

00033 {
00034 }

ConfigMap::~ConfigMap (  )  [virtual]

Destroys the map.

Definition at line 36 of file ConfigMap.cpp.

00037 {
00038 }


Member Function Documentation

void ConfigMap::readParams ( std::istream &  paramStream  ) 

Reads parameter name/value pairs from an input stream, until end-of-stream is encountered.

Each pair should be on a line by itself, with whitespace between the name and value.

Parameters:
paramStream the stream from which to read parameters

Definition at line 40 of file ConfigMap.cpp.

References TraceSource::name, and paramVals.

Referenced by TestBase::readParams().

00041 {
00042     for (;;) {
00043         std::string name,value;
00044         paramStream >> name;
00045         if (name == "") {
00046             break;
00047         }
00048         paramStream >> value;
00049         paramVals[name] = value;
00050     }
00051 }

void ConfigMap::dumpParams ( std::ostream &  dumpStream  )  const

Dumps all parameter settings to a stream.

Parameters:
dumpStream target stream

Definition at line 53 of file ConfigMap.cpp.

References paramVals.

Referenced by TestBase::readParams().

00054 {
00055     for (StringMapConstIter pPair = paramVals.begin();
00056          pPair != paramVals.end(); ++pPair)
00057     {
00058         dumpStream << pPair->first;
00059         dumpStream << " ";
00060         dumpStream << pPair->second;
00061         dumpStream << std::endl;
00062     }
00063 }

void ConfigMap::mergeFrom ( const ConfigMap  ) 

Merges in all the parameters from another map.

New values override current values.

Definition at line 65 of file ConfigMap.cpp.

References paramVals.

Referenced by TestBase::readParams().

00066 {
00067     for (StringMapConstIter pPair = that.paramVals.begin();
00068          pPair != that.paramVals.end();
00069          ++pPair)
00070     {
00071         this->paramVals[pPair->first] = pPair->second;
00072     }
00073 }

std::string ConfigMap::getStringParam ( std::string  paramName,
std::string  defaultVal = "" 
) const

Gets the value of a string-typed parameter.

Parameters:
paramName name of the parameter
defaultVal the default value to return if the parameter is not set
Returns:
the parameter value

Definition at line 76 of file ConfigMap.cpp.

References paramVals, and TRACE_CONFIG.

Referenced by CacheTestBase::CacheTestBase(), TestOptionsTest::extra(), Database::init(), JniUtilParams::readConfig(), DeviceAccessSchedulerParams::readConfig(), TestOptionsTest::test1(), TestOptionsTest::test2(), TestBase::TestBase(), SegStreamTest::testRead(), and SegStreamTest::testWrite().

00079 {
00080     StringMapConstIter pPair = paramVals.find(paramName);
00081     if (pPair == paramVals.end()) {
00082         FENNEL_TRACE(
00083             TRACE_CONFIG,
00084             "parameter " << paramName
00085             << " using default value of '"
00086             << defaultVal << "'");
00087         return defaultVal;
00088     } else {
00089         FENNEL_TRACE(
00090             TRACE_CONFIG,
00091             "parameter " << paramName
00092             << " using specified value of '"
00093             << pPair->second << "'");
00094         return pPair->second;
00095     }
00096 }

int ConfigMap::getIntParam ( std::string  paramName,
int  defaultVal = 0 
) const

Gets the value of an integer-typed parameter.

Parameters:
paramName name of the parameter
defaultVal the default value to return if the parameter is not set
Returns:
the parameter value

Definition at line 98 of file ConfigMap.cpp.

References paramVals, and TRACE_CONFIG.

Referenced by BTreeTxnTest::BTreeTxnTest(), CacheTestBase::CacheTestBase(), TestOptionsTest::extra(), PagingTestBase::PagingTestBase(), ParallelExecStreamSchedulerTest::ParallelExecStreamSchedulerTest(), DeviceAccessSchedulerParams::readConfig(), CacheParams::readConfig(), Database::readDeviceParams(), TestOptionsTest::test1(), TestOptionsTest::test2(), TestBase::TestBase(), BTreeTxnTest::testCheckpoint(), ThreadedTestBase::ThreadedTestBase(), and CmdInterpreter::visit().

00101 {
00102     StringMapConstIter pPair = paramVals.find(paramName);
00103     if (pPair == paramVals.end()) {
00104         FENNEL_TRACE(
00105             TRACE_CONFIG,
00106             "parameter " << paramName
00107             << " using default value of '"
00108             << defaultVal << "'");
00109         return defaultVal;
00110     } else {
00111         FENNEL_TRACE(
00112             TRACE_CONFIG,
00113             "parameter " << paramName
00114             << " using specified value of '"
00115             << pPair->second << "'");
00116         return boost::lexical_cast<int>(pPair->second);
00117     }
00118 }

long ConfigMap::getLongParam ( std::string  paramName,
long  defaultVal = 0 
) const

Gets the value of a long-typed parameter.

Parameters:
paramName name of the parameter
defaultVal the default value to return if the parameter is not set
Returns:
the parameter value

Definition at line 149 of file ConfigMap.cpp.

References paramVals, and TRACE_CONFIG.

00152 {
00153     StringMapConstIter pPair = paramVals.find(paramName);
00154     if (pPair == paramVals.end()) {
00155         FENNEL_TRACE(
00156             TRACE_CONFIG,
00157             "parameter " << paramName
00158             << " using default value of '"
00159             << defaultVal << "'");
00160         return defaultVal;
00161     } else {
00162         FENNEL_TRACE(
00163             TRACE_CONFIG,
00164             "parameter " << paramName
00165             << " using specified value of '"
00166             << pPair->second << "'");
00167         // REVIEW jvs 25-Nov-2008:  There used to be a note here,
00168         // but it didn't actually explain why this doesn't use
00169         // boost::lexical_cast; probably an old Boost bug.
00170         return atol(pPair->second.c_str());
00171     }
00172 }

bool ConfigMap::getBoolParam ( std::string  paramName,
bool  defaultVal = false 
) const

Gets the value of an boolean-typed parameter.

Parameters:
paramName name of the parameter
defaultVal the default value to return if the parameter is not set
Returns:
the parameter value

Definition at line 120 of file ConfigMap.cpp.

References paramVals, and TRACE_CONFIG.

Referenced by Database::init().

00123 {
00124     StringMapConstIter pPair = paramVals.find(paramName);
00125     if (pPair == paramVals.end()) {
00126         FENNEL_TRACE(
00127             TRACE_CONFIG,
00128             "parameter " << paramName
00129             << " using default value of '"
00130             << defaultVal << "'");
00131         return defaultVal;
00132     } else {
00133         FENNEL_TRACE(
00134             TRACE_CONFIG,
00135             "parameter " << paramName
00136             << " using specified value of '"
00137             << pPair->second << "'");
00138         // boost only likes 1/0, so preprocess true/false
00139         if (strcasecmp(pPair->second.c_str(), "true") == 0) {
00140             return true;
00141         } else if (strcasecmp(pPair->second.c_str(), "false") == 0) {
00142             return false;
00143         } else {
00144             return boost::lexical_cast<bool>(pPair->second);
00145         }
00146     }
00147 }

bool ConfigMap::isParamSet ( std::string  paramName  )  const

Determines whether a parameter has an associated value.

Parameters:
paramName name of the parameter
Returns:
true iff the named parameter has been set

Definition at line 174 of file ConfigMap.cpp.

References paramVals.

Referenced by Database::readDeviceParams(), TestBase::readParams(), and BTreeTxnTest::testCaseSetUp().

00175 {
00176     return paramVals.find(paramName) != paramVals.end();
00177 }

void ConfigMap::setStringParam ( std::string  paramName,
std::string  paramVal 
)

Sets an individual parameter value.

Parameters:
paramName name of the parameter
paramVal new value to set

Definition at line 179 of file ConfigMap.cpp.

References paramVals.

Referenced by DatabaseTest::DatabaseTest(), TestBase::readParams(), BackupRestoreTest::testBackupCleanup(), BTreeTxnTest::testCaseSetUp(), DatabaseTest::testForceTxns(), BackupRestoreTest::testHeaderBackupRestore(), SegPageEntryIterTest::testIter(), and CmdInterpreter::visit().

00182 {
00183     paramVals[paramName] = paramVal;
00184 }

void ConfigMap::clear (  ) 

Clears all parameters.

Definition at line 186 of file ConfigMap.cpp.

References paramVals.

Referenced by TestBase::~TestBase().

00187 {
00188     paramVals.clear();
00189 }

void TraceSource::initTraceSource ( SharedTraceTarget  pTraceTarget,
std::string  name 
) [virtual, inherited]

For use when initialization has to be deferred until after construction.

Parameters:
pTraceTarget the TraceTarget to which messages will be sent
name the name of this source

Definition at line 46 of file TraceSource.cpp.

References TraceSource::isTracing(), TraceSource::minimumLevel, TraceSource::name, TraceSource::pTraceTarget, and TRACE_OFF.

Referenced by TestBase::beforeTestCase(), TestBase::TestBase(), and TraceSource::TraceSource().

00049 {
00050     assert(!pTraceTarget.get());
00051 
00052     pTraceTarget = pTraceTargetInit;
00053     name = nameInit;
00054     if (isTracing()) {
00055         minimumLevel = pTraceTarget->getSourceTraceLevel(name);
00056     } else {
00057         minimumLevel = TRACE_OFF;
00058     }
00059 }

void TraceSource::trace ( TraceLevel  level,
std::string  message 
) const [inherited]

Records a trace message.

Normally only called via FENNEL_TRACE.

Parameters:
level severity level of event being trace
message the text of the message

Definition at line 61 of file TraceSource.cpp.

References TraceSource::getTraceTarget(), TraceSource::isTracing(), TraceSource::name, and TraceTarget::notifyTrace().

Referenced by Calculator::exec(), and ExecStreamScheduler::traceStreamBufferContents().

00062 {
00063     if (isTracing()) {
00064         getTraceTarget().notifyTrace(name,level,message);
00065     }
00066 }

bool TraceSource::isTracing (  )  const [inline, inherited]

Returns:
true iff tracing is enabled for this source

Definition at line 88 of file TraceSource.h.

Referenced by TraceSource::initTraceSource(), CalcExecStream::prepare(), and TraceSource::trace().

00089     {
00090         return pTraceTarget.get() ? true : false;
00091     }

bool TraceSource::isTracingLevel ( TraceLevel  level  )  const [inline, inherited]

Determines whether a particular level is being traced.

Parameters:
level trace level to test
Returns:
true iff tracing is enabled for the given level

Definition at line 100 of file TraceSource.h.

Referenced by ExecStreamScheduler::addGraph(), SimpleExecStreamGovernor::assignCachePages(), SimpleExecStreamGovernor::distributeCachePages(), Calculator::exec(), ExecStreamScheduler::ExecStreamScheduler(), LcsClusterNodeWriter::getLastClusterPageForWrite(), LcsClusterNodeWriter::moveFromTempToIndex(), JavaSinkExecStream::stuffByteBuffer(), and ExecStreamScheduler::traceStreamBuffers().

00101     {
00102         return level >= minimumLevel;
00103     }

TraceTarget& TraceSource::getTraceTarget (  )  const [inline, inherited]

Returns:
the TraceTarget for this source

Definition at line 108 of file TraceSource.h.

Referenced by TraceSource::trace().

00109     {
00110         assert(isTracing());
00111         return *(pTraceTarget.get());
00112     }

SharedTraceTarget TraceSource::getSharedTraceTarget (  )  const [inline, inherited]

Returns:
the SharedTraceTarget for this source

Definition at line 117 of file TraceSource.h.

Referenced by Database::init(), LcsClusterAppendExecStream::initLoad(), and CalcExecStream::prepare().

00118     {
00119         return pTraceTarget;
00120     }

std::string TraceSource::getTraceSourceName (  )  const [inline, inherited]

Gets the name of this source.

Useful to construct nested names for subcomponents that are also TraceSources.

Returns:
the name

Definition at line 127 of file TraceSource.h.

Referenced by LcsClusterAppendExecStream::initLoad().

00128     {
00129         return name;
00130     }

void TraceSource::setTraceSourceName ( std::string const &  n  )  [inline, inherited]

Sets the name of this source.

Useful to construct dynamic names for fine-grained filtering.

Definition at line 136 of file TraceSource.h.

00137     {
00138         name = n;
00139     }

TraceLevel TraceSource::getMinimumTraceLevel (  )  const [inline, inherited]

Definition at line 141 of file TraceSource.h.

00142     {
00143         return minimumLevel;
00144     }

void TraceSource::disableTracing (  )  [inherited]

Definition at line 68 of file TraceSource.cpp.

References TraceSource::minimumLevel, TraceSource::pTraceTarget, and TRACE_OFF.

Referenced by TestBase::afterTestCase().

00069 {
00070     pTraceTarget.reset();
00071     minimumLevel = TRACE_OFF;
00072 }


Member Data Documentation

StringMap ConfigMap::paramVals [private]

Definition at line 43 of file ConfigMap.h.

Referenced by clear(), dumpParams(), getBoolParam(), getIntParam(), getLongParam(), getStringParam(), isParamSet(), mergeFrom(), readParams(), and setStringParam().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:29 2009 for Fennel by  doxygen 1.5.1