6 #ifndef DP3_COMMON_PARAMETERSET_H_
7 #define DP3_COMMON_PARAMETERSET_H_
58 explicit ParameterSet(
const std::string& theFilename,
bool caseInsensitive);
101 void adoptFile(
const std::string& theFilename,
102 const std::string& thePrefix =
"");
109 const std::string& thePrefix =
"");
117 const std::string& thePrefix =
"");
129 void writeFile(
const std::string& theFilename,
bool append =
false)
const;
153 const std::string& prefix =
"")
const;
169 void add(
const std::string& aKey,
const std::string& aValue);
174 void replace(
const std::string& aKey,
const std::string& aValue);
178 void remove(
const std::string& aKey);
193 bool isDefined(
const std::string& searchKey)
const;
197 std::string
locateModule(
const std::string& shortName)
const;
206 std::vector<ParameterValue>
getVector(
const std::string& aKey)
const;
214 bool getBool(
const std::string& aKey)
const;
215 bool getBool(
const std::string& aKey,
bool aValue)
const;
216 int getInt(
const std::string& aKey)
const;
217 int getInt(
const std::string& aKey,
int aValue)
const;
218 unsigned int getUint(
const std::string& aKey)
const;
219 unsigned int getUint(
const std::string& aKey,
unsigned int aValue)
const;
220 int16_t
getInt16(
const std::string& aKey)
const;
221 int16_t
getInt16(
const std::string& aKey, int16_t aValue)
const;
222 uint16_t
getUint16(
const std::string& aKey)
const;
223 uint16_t
getUint16(
const std::string& aKey, uint16_t aValue)
const;
224 int32_t
getInt32(
const std::string& aKey)
const;
225 int32_t
getInt32(
const std::string& aKey, int32_t aValue)
const;
226 uint32_t
getUint32(
const std::string& aKey)
const;
227 uint32_t
getUint32(
const std::string& aKey, uint32_t aValue)
const;
228 int64_t
getInt64(
const std::string& aKey)
const;
229 int64_t
getInt64(
const std::string& aKey, int64_t aValue)
const;
230 uint64_t
getUint64(
const std::string& aKey)
const;
231 uint64_t
getUint64(
const std::string& aKey, uint64_t aValue)
const;
232 float getFloat(
const std::string& aKey)
const;
233 float getFloat(
const std::string& aKey,
float aValue)
const;
234 double getDouble(
const std::string& aKey)
const;
235 double getDouble(
const std::string& aKey,
double aValue)
const;
236 std::string
getString(
const std::string& aKey)
const;
237 std::string
getString(
const std::string& aKey,
238 const std::string& aValue)
const;
241 time_t
getTime(
const std::string& aKey)
const;
242 time_t
getTime(
const std::string& aKey,
const time_t& aValue)
const;
249 bool expandable =
false)
const;
251 const std::vector<bool>& aValue,
252 bool expandable =
false)
const;
254 bool expandable =
false)
const;
256 const std::vector<int>& aValue,
257 bool expandable =
false)
const;
258 std::vector<unsigned int>
getUintVector(
const std::string& aKey,
259 bool expandable =
false)
const;
261 const std::string& aKey,
const std::vector<unsigned int>& aValue,
262 bool expandable =
false)
const;
264 bool expandable =
false)
const;
266 const std::vector<int16_t>& aValue,
267 bool expandable =
false)
const;
269 bool expandable =
false)
const;
271 const std::vector<uint16_t>& aValue,
272 bool expandable =
false)
const;
274 bool expandable =
false)
const;
276 const std::vector<int32_t>& aValue,
277 bool expandable =
false)
const;
279 bool expandable =
false)
const;
281 const std::vector<uint32_t>& aValue,
282 bool expandable =
false)
const;
284 bool expandable =
false)
const;
286 const std::vector<int64_t>& aValue,
287 bool expandable =
false)
const;
289 bool expandable =
false)
const;
291 const std::vector<uint64_t>& aValue,
292 bool expandable =
false)
const;
294 bool expandable =
false)
const {
295 static_assert(
sizeof(
size_t) == 8 ||
sizeof(
size_t) == 4);
298 auto pick_overload = [&](
const std::string& aKey,
bool expandable =
false) {
299 if constexpr (
sizeof(
size_t) == 8) {
301 }
else if constexpr (
sizeof(
size_t) == 4) {
305 return pick_overload(aKey, expandable);
308 bool expandable =
false)
const;
310 const std::vector<float>& aValue,
311 bool expandable =
false)
const;
313 bool expandable =
false)
const;
315 const std::vector<double>& aValue,
316 bool expandable =
false)
const;
318 bool expandable =
false)
const;
320 const std::string& aKey,
const std::vector<std::string>& aValue,
321 bool expandable =
false)
const;
323 bool expandable =
false)
const;
325 const std::vector<time_t>& aValue,
326 bool expandable =
false)
const;
345 explicit ParameterSet(
const std::shared_ptr<ParameterSetImpl>& set) {
349 std::shared_ptr<ParameterSetImpl> itsSet;
360 return itsSet->begin();
363 return itsSet->end();
367 return itsSet->get(aKey);
370 const std::string& aKey)
const {
371 return itsSet->get(aKey);
375 return itsSet->keyCompareMode();
381 const std::string& thePrefix) {
382 itsSet->adoptFile(theFilename, thePrefix);
386 const std::string& thePrefix) {
387 itsSet->adoptBuffer(theBuffer, thePrefix);
391 const std::string& thePrefix) {
392 itsSet->adoptCollection(*theCollection.itsSet, thePrefix);
396 const std::vector<std::string>& arguments) {
397 itsSet->adoptArguments(arguments);
402 itsSet->writeFile(theFilename, append);
406 itsSet->writeBuffer(theBuffer);
410 itsSet->writeStream(os);
414 const std::string& prefix)
const {
415 return ParameterSet(itsSet->makeSubset(baseKey, prefix));
419 itsSet->subtractSubset(fullPrefix);
423 const std::string& aValue) {
427 add(aPair.first, aPair.second);
431 const std::string& aValue) {
435 replace(aPair.first, aPair.second);
439 itsSet->remove(aKey);
443 return itsSet->find(searchKey);
447 const std::string& searchKey)
const {
448 return itsSet->find(searchKey);
452 return itsSet->isDefined(searchKey);
456 const std::string& shortName)
const {
457 return (itsSet->locateModule(shortName));
461 const std::string& shortName)
const {
462 return (itsSet->fullModuleName(shortName));
466 const std::string& aKey)
const {
472 return itsSet->getBool(aKey);
477 return itsSet->getBool(aKey, aValue);
482 return itsSet->getInt(aKey);
487 return itsSet->getInt(aKey, aValue);
492 return itsSet->getUint(aKey);
497 unsigned int aValue)
const {
498 return itsSet->getUint(aKey, aValue);
503 return itsSet->getInt16(aKey);
508 int16_t aValue)
const {
509 return itsSet->getInt16(aKey, aValue);
514 return itsSet->getUint16(aKey);
519 uint16_t aValue)
const {
520 return itsSet->getUint16(aKey, aValue);
525 return itsSet->getInt32(aKey);
530 int32_t aValue)
const {
531 return itsSet->getInt32(aKey, aValue);
536 return itsSet->getUint32(aKey);
541 uint32_t aValue)
const {
542 return itsSet->getUint32(aKey, aValue);
547 return itsSet->getInt64(aKey);
552 int64_t aValue)
const {
553 return itsSet->getInt64(aKey, aValue);
558 return itsSet->getUint64(aKey);
563 uint64_t aValue)
const {
564 return itsSet->getUint64(aKey, aValue);
569 return itsSet->getFloat(aKey);
574 float aValue)
const {
575 return itsSet->getFloat(aKey, aValue);
580 return itsSet->getDouble(aKey);
585 double aValue)
const {
586 return itsSet->getDouble(aKey, aValue);
591 return itsSet->getString(aKey);
596 const std::string& aValue)
const {
597 return itsSet->getString(aKey, aValue);
602 return itsSet->getTime(aKey);
607 const time_t& aValue)
const {
608 return itsSet->getTime(aKey, aValue);
613 bool expandable)
const {
614 return itsSet->getBoolVector(aKey, expandable);
619 const std::string& aKey,
const std::vector<bool>& aValue,
620 bool expandable)
const {
621 return itsSet->getBoolVector(aKey, aValue, expandable);
626 bool expandable)
const {
627 return itsSet->getIntVector(aKey, expandable);
632 const std::string& aKey,
const std::vector<int>& aValue,
633 bool expandable)
const {
634 return itsSet->getIntVector(aKey, aValue, expandable);
639 const std::string& aKey,
bool expandable)
const {
640 return itsSet->getUintVector(aKey, expandable);
645 const std::string& aKey,
const std::vector<unsigned int>& aValue,
646 bool expandable)
const {
647 return itsSet->getUintVector(aKey, aValue, expandable);
652 const std::string& aKey,
bool expandable)
const {
653 return itsSet->getInt16Vector(aKey, expandable);
658 const std::string& aKey,
const std::vector<int16_t>& aValue,
659 bool expandable)
const {
660 return itsSet->getInt16Vector(aKey, aValue, expandable);
665 const std::string& aKey,
bool expandable)
const {
666 return itsSet->getUint16Vector(aKey, expandable);
671 const std::string& aKey,
const std::vector<uint16_t>& aValue,
672 bool expandable)
const {
673 return itsSet->getUint16Vector(aKey, aValue, expandable);
678 const std::string& aKey,
bool expandable)
const {
679 return itsSet->getInt32Vector(aKey, expandable);
684 const std::string& aKey,
const std::vector<int32_t>& aValue,
685 bool expandable)
const {
686 return itsSet->getInt32Vector(aKey, aValue, expandable);
691 const std::string& aKey,
bool expandable)
const {
692 return itsSet->getUint32Vector(aKey, expandable);
697 const std::string& aKey,
const std::vector<uint32_t>& aValue,
698 bool expandable)
const {
699 return itsSet->getUint32Vector(aKey, aValue, expandable);
704 const std::string& aKey,
bool expandable)
const {
705 return itsSet->getInt64Vector(aKey, expandable);
710 const std::string& aKey,
const std::vector<int64_t>& aValue,
711 bool expandable)
const {
712 return itsSet->getInt64Vector(aKey, aValue, expandable);
717 const std::string& aKey,
bool expandable)
const {
718 return itsSet->getUint64Vector(aKey, expandable);
723 const std::string& aKey,
const std::vector<uint64_t>& aValue,
724 bool expandable)
const {
725 return itsSet->getUint64Vector(aKey, aValue, expandable);
730 bool expandable)
const {
731 return itsSet->getFloatVector(aKey, expandable);
736 const std::string& aKey,
const std::vector<float>& aValue,
737 bool expandable)
const {
738 return itsSet->getFloatVector(aKey, aValue, expandable);
743 const std::string& aKey,
bool expandable)
const {
744 return itsSet->getDoubleVector(aKey, expandable);
748 const std::string& aKey,
const std::vector<double>& aValue,
749 bool expandable)
const {
750 return itsSet->getDoubleVector(aKey, aValue, expandable);
755 const std::string& aKey,
bool expandable)
const {
756 return itsSet->getStringVector(aKey, expandable);
761 const std::string& aKey,
const std::vector<std::string>& aValue,
762 bool expandable)
const {
763 return itsSet->getStringVector(aKey, aValue, expandable);
768 bool expandable)
const {
769 return itsSet->getTimeVector(aKey, expandable);
774 const std::string& aKey,
const std::vector<time_t>& aValue,
775 bool expandable)
const {
776 return itsSet->getTimeVector(aKey, aValue, expandable);
780 return itsSet->unusedKeys();
Implements a KV pair as a pair<string, string>.
Definition: KVpair.h:24
A record of parameter values. The only difference with a ParameterSet is the output operator.
Definition: ParameterRecord.h:16
KVMap::iterator iterator
Definition: ParameterSetImpl.h:53
KVMap::const_iterator const_iterator
Definition: ParameterSetImpl.h:54
Implements a map of Key-Value pairs.
Definition: ParameterSet.h:28
KeyCompare::Mode keyCompareMode() const
Key comparison mode.
Definition: ParameterSet.h:374
std::vector< int > getIntVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:625
uint16_t getUint16(const std::string &aKey) const
Definition: ParameterSet.h:513
void adoptArguments(const std::vector< std::string > &arguments)
Definition: ParameterSet.h:395
void writeFile(const std::string &theFilename, bool append=false) const
Writes the Key-Values pair from the current ParCollection to the file.
Definition: ParameterSet.h:400
std::string fullModuleName(const std::string &shortName) const
Definition: ParameterSet.h:460
ParameterSet(const std::string &theFilename, KeyCompare::Mode=KeyCompare::NORMAL)
void adoptFile(const std::string &theFilename, const std::string &thePrefix="")
Definition: ParameterSet.h:380
bool isDefined(const std::string &searchKey) const
Checks if the given Key is defined in the ParameterSet.
Definition: ParameterSet.h:451
std::vector< std::string > getStringVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:754
iterator find(const std::string &searchKey)
Find a key.
Definition: ParameterSet.h:442
bool empty() const
Is the set empty?
Definition: ParameterSet.h:355
std::vector< uint64_t > getUint64Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:716
std::vector< double > getDoubleVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:742
ParameterSet makeSubset(const std::string &baseKey, const std::string &prefix="") const
Definition: ParameterSet.h:413
std::vector< std::string > unusedKeys() const
Definition: ParameterSet.h:779
int16_t getInt16(const std::string &aKey) const
Definition: ParameterSet.h:502
void writeBuffer(std::string &theBuffer) const
Definition: ParameterSet.h:405
void replace(const std::string &aKey, const std::string &aValue)
Definition: ParameterSet.h:430
std::vector< unsigned int > getUintVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:638
float getFloat(const std::string &aKey) const
Definition: ParameterSet.h:568
ParameterSetImpl::const_iterator const_iterator
Definition: ParameterSet.h:31
std::vector< size_t > getSizeTVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:293
std::vector< int16_t > getInt16Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:651
std::string locateModule(const std::string &shortName) const
Definition: ParameterSet.h:455
void remove(const std::string &aKey)
Removes the pair with the given key. Removing a non-existing key is ok.
Definition: ParameterSet.h:438
unsigned int getUint(const std::string &aKey) const
Definition: ParameterSet.h:491
time_t getTime(const std::string &aKey) const
Definition: ParameterSet.h:601
std::vector< float > getFloatVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:729
void add(const std::string &aKey, const std::string &aValue)
Definition: ParameterSet.h:422
std::vector< ParameterValue > getVector(const std::string &aKey) const
Definition: ParameterSet.h:465
ParameterSet(KeyCompare::Mode mode=KeyCompare::NORMAL)
const ParameterValue & operator[](const std::string &aKey) const
Definition: ParameterSet.h:369
ParameterSet(const std::string &theFilename, bool caseInsensitive)
std::vector< uint32_t > getUint32Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:690
std::vector< time_t > getTimeVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:767
int32_t getInt32(const std::string &aKey) const
Definition: ParameterSet.h:524
std::vector< uint16_t > getUint16Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:664
int size() const
Get the number of parameters.
Definition: ParameterSet.h:356
std::vector< int32_t > getInt32Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:677
uint32_t getUint32(const std::string &aKey) const
Definition: ParameterSet.h:535
ParameterRecord getRecord(const std::string &aKey) const
bool getBool(const std::string &aKey) const
Definition: ParameterSet.h:471
int64_t getInt64(const std::string &aKey) const
Definition: ParameterSet.h:546
void clear()
Clear the set.
Definition: ParameterSet.h:378
const ParameterValue & get(const std::string &aKey) const
Definition: ParameterSet.h:366
uint64_t getUint64(const std::string &aKey) const
Definition: ParameterSet.h:557
std::vector< int64_t > getInt64Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:703
ParameterSet(bool caseInsensitive)
iterator begin()
Iteration.
Definition: ParameterSet.h:357
void writeStream(std::ostream &os) const
Definition: ParameterSet.h:409
ParameterSet(const ParameterSet &that)
Copying is allowed.
ParameterSet & operator=(const ParameterSet &that)
Copying is allowed.
void adoptCollection(const ParameterSet &theCollection, const std::string &thePrefix="")
Definition: ParameterSet.h:390
int getInt(const std::string &aKey) const
Definition: ParameterSet.h:481
std::vector< bool > getBoolVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:612
void subtractSubset(const std::string &fullPrefix)
Definition: ParameterSet.h:418
double getDouble(const std::string &aKey) const
Definition: ParameterSet.h:579
iterator end()
Definition: ParameterSet.h:358
friend std::ostream & operator<<(std::ostream &os, const ParameterSet &thePS)
Allow printing the whole parameter collection.
ParameterSetImpl::iterator iterator
Definition: ParameterSet.h:30
void adoptBuffer(const std::string &theBuffer, const std::string &thePrefix="")
Definition: ParameterSet.h:385
ParameterSet(const char *theFilename, KeyCompare::Mode=KeyCompare::NORMAL)
This one is needed to avoid problems with the bool constructor above.
std::string getString(const std::string &aKey) const
Definition: ParameterSet.h:590
The value of a parameter.
Definition: ParameterValue.h:24
std::vector< ParameterValue > getVector() const
Get the parameter value as a vector of ParameterValues.
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53