6 #ifndef DP3_COMMON_PARAMETERSET_H_
7 #define DP3_COMMON_PARAMETERSET_H_
61 explicit ParameterSet(
const std::string& theFilename,
bool caseInsensitive);
104 void adoptFile(
const std::string& theFilename,
105 const std::string& thePrefix =
"");
112 const std::string& thePrefix =
"");
120 const std::string& thePrefix =
"");
132 void writeFile(
const std::string& theFilename,
bool append =
false)
const;
156 const std::string& prefix =
"")
const;
172 void add(
const std::string& aKey,
const std::string& aValue);
177 void replace(
const std::string& aKey,
const std::string& aValue);
181 void remove(
const std::string& aKey);
196 bool isDefined(
const std::string& searchKey)
const;
200 std::string
locateModule(
const std::string& shortName)
const;
209 std::vector<ParameterValue>
getVector(
const std::string& aKey)
const;
217 bool getBool(
const std::string& aKey)
const;
218 bool getBool(
const std::string& aKey,
bool aValue)
const;
219 int getInt(
const std::string& aKey)
const;
220 int getInt(
const std::string& aKey,
int aValue)
const;
221 unsigned int getUint(
const std::string& aKey)
const;
222 unsigned int getUint(
const std::string& aKey,
unsigned int aValue)
const;
223 int16_t
getInt16(
const std::string& aKey)
const;
224 int16_t
getInt16(
const std::string& aKey, int16_t aValue)
const;
225 uint16_t
getUint16(
const std::string& aKey)
const;
226 uint16_t
getUint16(
const std::string& aKey, uint16_t aValue)
const;
227 int32_t
getInt32(
const std::string& aKey)
const;
228 int32_t
getInt32(
const std::string& aKey, int32_t aValue)
const;
229 uint32_t
getUint32(
const std::string& aKey)
const;
230 uint32_t
getUint32(
const std::string& aKey, uint32_t aValue)
const;
231 int64_t
getInt64(
const std::string& aKey)
const;
232 int64_t
getInt64(
const std::string& aKey, int64_t aValue)
const;
233 uint64_t
getUint64(
const std::string& aKey)
const;
234 uint64_t
getUint64(
const std::string& aKey, uint64_t aValue)
const;
235 float getFloat(
const std::string& aKey)
const;
236 float getFloat(
const std::string& aKey,
float aValue)
const;
237 double getDouble(
const std::string& aKey)
const;
238 double getDouble(
const std::string& aKey,
double aValue)
const;
239 std::string
getString(
const std::string& aKey)
const;
240 std::string
getString(
const std::string& aKey,
241 const std::string& aValue)
const;
244 time_t
getTime(
const std::string& aKey)
const;
245 time_t
getTime(
const std::string& aKey,
const time_t& aValue)
const;
252 bool expandable =
false)
const;
254 const std::vector<bool>& aValue,
255 bool expandable =
false)
const;
257 bool expandable =
false)
const;
259 const std::vector<int>& aValue,
260 bool expandable =
false)
const;
261 std::vector<unsigned int>
getUintVector(
const std::string& aKey,
262 bool expandable =
false)
const;
264 const std::string& aKey,
const std::vector<unsigned int>& aValue,
265 bool expandable =
false)
const;
267 bool expandable =
false)
const;
269 const std::vector<int16_t>& aValue,
270 bool expandable =
false)
const;
272 bool expandable =
false)
const;
274 const std::vector<uint16_t>& aValue,
275 bool expandable =
false)
const;
277 bool expandable =
false)
const;
279 const std::vector<int32_t>& aValue,
280 bool expandable =
false)
const;
282 bool expandable =
false)
const;
284 const std::vector<uint32_t>& aValue,
285 bool expandable =
false)
const;
287 bool expandable =
false)
const;
289 const std::vector<int64_t>& aValue,
290 bool expandable =
false)
const;
292 bool expandable =
false)
const;
294 const std::vector<uint64_t>& aValue,
295 bool expandable =
false)
const;
297 bool expandable =
false)
const {
298 static_assert(
sizeof(
size_t) == 8 ||
sizeof(
size_t) == 4);
301 auto pick_overload = [&](
const std::string& aKey,
bool expandable =
false) {
302 if constexpr (
sizeof(
size_t) == 8) {
304 }
else if constexpr (
sizeof(
size_t) == 4) {
308 return pick_overload(aKey, expandable);
311 bool expandable =
false)
const;
313 const std::vector<float>& aValue,
314 bool expandable =
false)
const;
316 bool expandable =
false)
const;
318 const std::vector<double>& aValue,
319 bool expandable =
false)
const;
321 bool expandable =
false)
const;
323 const std::string& aKey,
const std::vector<std::string>& aValue,
324 bool expandable =
false)
const;
326 bool expandable =
false)
const;
328 const std::vector<time_t>& aValue,
329 bool expandable =
false)
const;
348 explicit ParameterSet(
const std::shared_ptr<ParameterSetImpl>& set) {
352 std::shared_ptr<ParameterSetImpl> itsSet;
369 return itsSet->begin();
372 return itsSet->end();
376 return itsSet->get(aKey);
379 const std::string& aKey)
const {
380 return itsSet->get(aKey);
384 return itsSet->keyCompareMode();
390 const std::string& thePrefix) {
391 itsSet->adoptFile(theFilename, thePrefix);
395 const std::string& thePrefix) {
396 itsSet->adoptBuffer(theBuffer, thePrefix);
400 const std::string& thePrefix) {
401 itsSet->adoptCollection(*theCollection.itsSet, thePrefix);
405 const std::vector<std::string>& arguments) {
406 itsSet->adoptArguments(arguments);
411 itsSet->writeFile(theFilename, append);
415 itsSet->writeBuffer(theBuffer);
419 itsSet->writeStream(os);
423 const std::string& prefix)
const {
424 return ParameterSet(itsSet->makeSubset(baseKey, prefix));
428 itsSet->subtractSubset(fullPrefix);
432 const std::string& aValue) {
436 add(aPair.first, aPair.second);
440 const std::string& aValue) {
444 replace(aPair.first, aPair.second);
448 itsSet->remove(aKey);
452 return itsSet->find(searchKey);
456 const std::string& searchKey)
const {
457 return itsSet->find(searchKey);
461 return itsSet->isDefined(searchKey);
465 const std::string& shortName)
const {
466 return (itsSet->locateModule(shortName));
470 const std::string& shortName)
const {
471 return (itsSet->fullModuleName(shortName));
475 const std::string& aKey)
const {
481 return itsSet->getBool(aKey);
486 return itsSet->getBool(aKey, aValue);
491 return itsSet->getInt(aKey);
496 return itsSet->getInt(aKey, aValue);
501 return itsSet->getUint(aKey);
506 unsigned int aValue)
const {
507 return itsSet->getUint(aKey, aValue);
512 return itsSet->getInt16(aKey);
517 int16_t aValue)
const {
518 return itsSet->getInt16(aKey, aValue);
523 return itsSet->getUint16(aKey);
528 uint16_t aValue)
const {
529 return itsSet->getUint16(aKey, aValue);
534 return itsSet->getInt32(aKey);
539 int32_t aValue)
const {
540 return itsSet->getInt32(aKey, aValue);
545 return itsSet->getUint32(aKey);
550 uint32_t aValue)
const {
551 return itsSet->getUint32(aKey, aValue);
556 return itsSet->getInt64(aKey);
561 int64_t aValue)
const {
562 return itsSet->getInt64(aKey, aValue);
567 return itsSet->getUint64(aKey);
572 uint64_t aValue)
const {
573 return itsSet->getUint64(aKey, aValue);
578 return itsSet->getFloat(aKey);
583 float aValue)
const {
584 return itsSet->getFloat(aKey, aValue);
589 return itsSet->getDouble(aKey);
594 double aValue)
const {
595 return itsSet->getDouble(aKey, aValue);
600 return itsSet->getString(aKey);
605 const std::string& aValue)
const {
606 return itsSet->getString(aKey, aValue);
611 return itsSet->getTime(aKey);
616 const time_t& aValue)
const {
617 return itsSet->getTime(aKey, aValue);
622 bool expandable)
const {
623 return itsSet->getBoolVector(aKey, expandable);
628 const std::string& aKey,
const std::vector<bool>& aValue,
629 bool expandable)
const {
630 return itsSet->getBoolVector(aKey, aValue, expandable);
635 bool expandable)
const {
636 return itsSet->getIntVector(aKey, expandable);
641 const std::string& aKey,
const std::vector<int>& aValue,
642 bool expandable)
const {
643 return itsSet->getIntVector(aKey, aValue, expandable);
648 const std::string& aKey,
bool expandable)
const {
649 return itsSet->getUintVector(aKey, expandable);
654 const std::string& aKey,
const std::vector<unsigned int>& aValue,
655 bool expandable)
const {
656 return itsSet->getUintVector(aKey, aValue, expandable);
661 const std::string& aKey,
bool expandable)
const {
662 return itsSet->getInt16Vector(aKey, expandable);
667 const std::string& aKey,
const std::vector<int16_t>& aValue,
668 bool expandable)
const {
669 return itsSet->getInt16Vector(aKey, aValue, expandable);
674 const std::string& aKey,
bool expandable)
const {
675 return itsSet->getUint16Vector(aKey, expandable);
680 const std::string& aKey,
const std::vector<uint16_t>& aValue,
681 bool expandable)
const {
682 return itsSet->getUint16Vector(aKey, aValue, expandable);
687 const std::string& aKey,
bool expandable)
const {
688 return itsSet->getInt32Vector(aKey, expandable);
693 const std::string& aKey,
const std::vector<int32_t>& aValue,
694 bool expandable)
const {
695 return itsSet->getInt32Vector(aKey, aValue, expandable);
700 const std::string& aKey,
bool expandable)
const {
701 return itsSet->getUint32Vector(aKey, expandable);
706 const std::string& aKey,
const std::vector<uint32_t>& aValue,
707 bool expandable)
const {
708 return itsSet->getUint32Vector(aKey, aValue, expandable);
713 const std::string& aKey,
bool expandable)
const {
714 return itsSet->getInt64Vector(aKey, expandable);
719 const std::string& aKey,
const std::vector<int64_t>& aValue,
720 bool expandable)
const {
721 return itsSet->getInt64Vector(aKey, aValue, expandable);
726 const std::string& aKey,
bool expandable)
const {
727 return itsSet->getUint64Vector(aKey, expandable);
732 const std::string& aKey,
const std::vector<uint64_t>& aValue,
733 bool expandable)
const {
734 return itsSet->getUint64Vector(aKey, aValue, expandable);
739 bool expandable)
const {
740 return itsSet->getFloatVector(aKey, expandable);
745 const std::string& aKey,
const std::vector<float>& aValue,
746 bool expandable)
const {
747 return itsSet->getFloatVector(aKey, aValue, expandable);
752 const std::string& aKey,
bool expandable)
const {
753 return itsSet->getDoubleVector(aKey, expandable);
757 const std::string& aKey,
const std::vector<double>& aValue,
758 bool expandable)
const {
759 return itsSet->getDoubleVector(aKey, aValue, expandable);
764 const std::string& aKey,
bool expandable)
const {
765 return itsSet->getStringVector(aKey, expandable);
770 const std::string& aKey,
const std::vector<std::string>& aValue,
771 bool expandable)
const {
772 return itsSet->getStringVector(aKey, aValue, expandable);
777 bool expandable)
const {
778 return itsSet->getTimeVector(aKey, expandable);
783 const std::string& aKey,
const std::vector<time_t>& aValue,
784 bool expandable)
const {
785 return itsSet->getTimeVector(aKey, aValue, expandable);
789 return itsSet->unusedKeys();
Input stream for a blob.
Definition: BlobIStream.h:43
Output stream for a blob.
Definition: BlobOStream.h:40
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:31
KeyCompare::Mode keyCompareMode() const
Key comparison mode.
Definition: ParameterSet.h:383
std::vector< int > getIntVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:634
uint16_t getUint16(const std::string &aKey) const
Definition: ParameterSet.h:522
void adoptArguments(const std::vector< std::string > &arguments)
Definition: ParameterSet.h:404
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:409
std::string fullModuleName(const std::string &shortName) const
Definition: ParameterSet.h:469
ParameterSet(const std::string &theFilename, KeyCompare::Mode=KeyCompare::NORMAL)
void adoptFile(const std::string &theFilename, const std::string &thePrefix="")
Definition: ParameterSet.h:389
bool isDefined(const std::string &searchKey) const
Checks if the given Key is defined in the ParameterSet.
Definition: ParameterSet.h:460
std::vector< std::string > getStringVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:763
iterator find(const std::string &searchKey)
Find a key.
Definition: ParameterSet.h:451
bool empty() const
Is the set empty?
Definition: ParameterSet.h:364
std::vector< uint64_t > getUint64Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:725
std::vector< double > getDoubleVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:751
ParameterSet makeSubset(const std::string &baseKey, const std::string &prefix="") const
Definition: ParameterSet.h:422
std::vector< std::string > unusedKeys() const
Definition: ParameterSet.h:788
int16_t getInt16(const std::string &aKey) const
Definition: ParameterSet.h:511
void writeBuffer(std::string &theBuffer) const
Definition: ParameterSet.h:414
void replace(const std::string &aKey, const std::string &aValue)
Definition: ParameterSet.h:439
std::vector< unsigned int > getUintVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:647
float getFloat(const std::string &aKey) const
Definition: ParameterSet.h:577
ParameterSetImpl::const_iterator const_iterator
Definition: ParameterSet.h:34
std::vector< size_t > getSizeTVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:296
std::vector< int16_t > getInt16Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:660
std::string locateModule(const std::string &shortName) const
Definition: ParameterSet.h:464
void remove(const std::string &aKey)
Removes the pair with the given key. Removing a non-existing key is ok.
Definition: ParameterSet.h:447
unsigned int getUint(const std::string &aKey) const
Definition: ParameterSet.h:500
time_t getTime(const std::string &aKey) const
Definition: ParameterSet.h:610
std::vector< float > getFloatVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:738
void add(const std::string &aKey, const std::string &aValue)
Definition: ParameterSet.h:431
std::vector< ParameterValue > getVector(const std::string &aKey) const
Definition: ParameterSet.h:474
ParameterSet(KeyCompare::Mode mode=KeyCompare::NORMAL)
const ParameterValue & operator[](const std::string &aKey) const
Definition: ParameterSet.h:378
ParameterSet(const std::string &theFilename, bool caseInsensitive)
std::vector< uint32_t > getUint32Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:699
std::vector< time_t > getTimeVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:776
int32_t getInt32(const std::string &aKey) const
Definition: ParameterSet.h:533
std::vector< uint16_t > getUint16Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:673
int size() const
Get the number of parameters.
Definition: ParameterSet.h:365
std::vector< int32_t > getInt32Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:686
uint32_t getUint32(const std::string &aKey) const
Definition: ParameterSet.h:544
ParameterRecord getRecord(const std::string &aKey) const
bool getBool(const std::string &aKey) const
Definition: ParameterSet.h:480
int64_t getInt64(const std::string &aKey) const
Definition: ParameterSet.h:555
void clear()
Clear the set.
Definition: ParameterSet.h:387
const ParameterValue & get(const std::string &aKey) const
Definition: ParameterSet.h:375
uint64_t getUint64(const std::string &aKey) const
Definition: ParameterSet.h:566
std::vector< int64_t > getInt64Vector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:712
ParameterSet(bool caseInsensitive)
iterator begin()
Iteration.
Definition: ParameterSet.h:366
void writeStream(std::ostream &os) const
Definition: ParameterSet.h:418
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:399
int getInt(const std::string &aKey) const
Definition: ParameterSet.h:490
std::vector< bool > getBoolVector(const std::string &aKey, bool expandable=false) const
Definition: ParameterSet.h:621
void subtractSubset(const std::string &fullPrefix)
Definition: ParameterSet.h:427
double getDouble(const std::string &aKey) const
Definition: ParameterSet.h:588
iterator end()
Definition: ParameterSet.h:367
friend std::ostream & operator<<(std::ostream &os, const ParameterSet &thePS)
Allow printing the whole parameter collection.
ParameterSetImpl::iterator iterator
Definition: ParameterSet.h:33
void adoptBuffer(const std::string &theBuffer, const std::string &thePrefix="")
Definition: ParameterSet.h:394
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:599
The value of a parameter.
Definition: ParameterValue.h:24
std::vector< ParameterValue > getVector() const
Get the parameter value as a vector of ParameterValues.
std::ostream & operator<<(std::ostream &os, const KVpair &kv)
blob::BlobIStream & operator>>(blob::BlobIStream &, ParameterSet &)
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53