22 #ifndef ASTSHIM_KEYMAP_H 23 #define ASTSHIM_KEYMAP_H 41 os <<
"Key \"" << key <<
"\" not found or has an undefined value";
94 :
Object(reinterpret_cast<AstObject *>(astKeyMap(
"%s",
options.c_str()))) {}
116 bool ret =
static_cast<bool>(
117 astMapDefined(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str()));
124 int const len =
size();
125 if ((ind < 0) || (ind >= len)) {
127 os <<
"ind = " << ind <<
" not in range [0, " << len - 1 <<
"]";
130 const char *rawKey = astMapKey(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), ind);
141 bool ret =
static_cast<bool>(
142 astMapHasKey(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str()));
149 int len = astMapLength(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str());
156 int const size = astMapSize(reinterpret_cast<AstKeyMap const *>(
getRawPtr()));
164 if (!astMapGetElemD(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
165 throwKeyNotFound(key);
177 astMapGet1D(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
187 if (!astMapGetElemF(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
188 throwKeyNotFound(key);
200 astMapGet1F(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
210 if (!astMapGetElemI(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
211 throwKeyNotFound(key);
223 astMapGet1I(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
233 if (!astMapGetElemS(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
234 throwKeyNotFound(key);
246 astMapGet1S(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
255 char unsigned retVal;
256 if (!astMapGetElemB(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
257 throwKeyNotFound(key);
269 astMapGet1B(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
278 int const maxChar = 1 + astMapLenC(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str());
280 if (!astMapGetElemC(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), maxChar, ind,
282 throwKeyNotFound(key);
294 int const eltLen = 1 + astMapLenC(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str());
297 astMapGet1C(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), eltLen,
size, &nret,
299 for (
int i = 0; i <
size; ++i) {
311 if (!astMapGetElemA(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &rawObj)) {
312 throwKeyNotFound(key);
315 return Object::fromAstObject<Object>(rawObj,
true);
322 for (
int i = 0; i <
size; ++i) {
330 astMapPut0D(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
336 _assertVectorNotEmpty(key, vec.
size());
344 astMapPut0F(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
350 _assertVectorNotEmpty(key, vec.
size());
358 astMapPut0I(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
364 _assertVectorNotEmpty(key, vec.
size());
372 astMapPut0S(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
378 _assertVectorNotEmpty(key, vec.
size());
386 astMapPut0B(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
393 _assertVectorNotEmpty(key, vec.
size());
401 astMapPut0C(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value.
c_str(), comment.c_str());
407 _assertVectorNotEmpty(key, vec.
size());
420 AstObject *rawCopy =
reinterpret_cast<AstObject *
>(astCopy(obj.
getRawPtr()));
421 astMapPut0A(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), rawCopy, comment.c_str());
428 _assertVectorNotEmpty(key, vec.
size());
430 for (
int i = 0,
size = vec.size(); i <
size; ++i) {
447 astMapPutU(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), comment.c_str());
453 int const i = _getAppendIndex(key);
454 astMapPutElemD(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
460 int const i = _getAppendIndex(key);
461 astMapPutElemF(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
467 int const i = _getAppendIndex(key);
468 astMapPutElemI(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
474 int const i = _getAppendIndex(key);
475 astMapPutElemS(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
481 int const i = _getAppendIndex(key);
482 astMapPutElemB(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
488 int const i = _getAppendIndex(key);
495 int const i = _getAppendIndex(key);
496 AstObject *rawCopy =
reinterpret_cast<AstObject *
>(astCopy(value.
getRawPtr()));
497 astMapPutElemA(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, rawCopy);
503 _assertReplaceIndexInRange(key, i);
504 astMapPutElemD(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
510 _assertReplaceIndexInRange(key, i);
511 astMapPutElemF(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
517 _assertReplaceIndexInRange(key, i);
518 astMapPutElemI(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
524 _assertReplaceIndexInRange(key, i);
525 astMapPutElemS(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
531 _assertReplaceIndexInRange(key, i);
532 astMapPutElemB(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
538 _assertReplaceIndexInRange(key, i);
545 _assertReplaceIndexInRange(key, i);
546 AstObject *rawCopy =
reinterpret_cast<AstObject *
>(astCopy(value.
getRawPtr()));
547 astMapPutElemA(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, rawCopy);
575 int retVal = astMapType(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str());
577 return static_cast<DataType>(retVal);
589 explicit KeyMap(AstKeyMap *rawKeyMap) :
Object(reinterpret_cast<AstObject *>(rawKeyMap)) {
592 os <<
"this is a " <<
getClassName() <<
", which is not a KeyMap";
602 os <<
"vector supplied for key \"" << key <<
"\" has zero elements";
608 void _assertReplaceIndexInRange(
std::string const &key,
int i)
const {
609 int const len =
length(key);
610 if ((i < 0) || (i >= len)) {
612 os <<
"i = " << i <<
" not in range [0, " << len - 1 <<
"] for key \"" << key <<
"\"";
618 int _getAppendIndex(
std::string const &key)
const {
619 int const i =
length(key);
622 os <<
"key \"" << key <<
"\" not found";
void rename(std::string const &oldKey, std::string const &newKey)
Rename the specified entry.
void append(std::string const &key, short int value)
Append an element to a vector of short int in a KeyMap.
void replace(std::string const &key, int i, int value)
Replace an element of a vector of ints in a KeyMap.
void putI(std::string const &key, std::vector< int > const &vec, std::string const &comment="")
Add a vector of ints.
KeyMap is used to store a set of values with associated keys which identify the values.
int getI(std::string const &key, int ind) const
Get one int value for a given key.
void putU(std::string const &key, std::string const &comment="")
Add a new entry, but no value is stored with the entry.
short int getS(std::string const &key, int ind) const
Get one short int value for a given key.
AstObject const * getRawPtr() const
Get the raw AST pointer.
KeyMap(std::string const &options="")
Construct an empty KeyMap.
AST wrapper classes and functions.
void replace(std::string const &key, int i, std::string const &value)
Replace an element of a vector of strings in a KeyMap.
virtual std::shared_ptr< Object > copyPolymorphic() const override
Return a deep copy of this object.
void putB(std::string const &key, std::vector< char unsigned > const &vec, std::string const &comment="")
Add a vector of chars.
std::string getClassName() const
Get Class: the name of the class (e.g.
void putC(std::string const &key, std::vector< std::string > const &vec, std::string const &comment="")
Add a vector of strings.
bool defined(std::string const &key) const
Does this map contain the specified key, and if so, does it have a defined value? ...
Channel provides input/output of AST objects.
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Throw std::runtime_error if AST's state is bad.
std::vector< std::string > getC(std::string const &key) const
Get all std::string values for a given key.
void putI(std::string const &key, int value, std::string const &comment="")
Add an int.
double getD(std::string const &key, int ind) const
Get one double value for a given key.
void replace(std::string const &key, int i, short int value)
Replace an element of a vector of short int in a KeyMap.
int length(std::string const &key) const
Get the size of the vector for the specified key; return 0 if key not found or value is undefined...
int size() const
Get the number of keys.
void putF(std::string const &key, std::vector< float > const &vec, std::string const &comment="")
Add a vector of floats.
std::vector< float > getF(std::string const &key) const
Get all float values for a given key.
void append(std::string const &key, float value)
Append an element to a vector of floats in a KeyMap.
void replace(std::string const &key, int i, double value)
Replace an element of a vector of doubles in a KeyMap.
std::string getC(std::string const &key, int ind) const
Get one std::string value for a given key.
std::vector< double > getD(std::string const &key) const
Get all double values for a given key.
void replace(std::string const &key, int i, float value)
Replace an element of a vector of floats in a KeyMap.
std::vector< short int > getS(std::string const &key) const
Get all short int values for a given key.
void append(std::string const &key, int value)
Append an element to a vector of ints in a KeyMap.
void putS(std::string const &key, short int value, std::string const &comment="")
Add a short int.
void append(std::string const &key, double value)
Append an element to a vector of doubles in a KeyMap.
void putB(std::string const &key, char unsigned value, std::string const &comment="")
Add a char.
void append(std::string const &key, std::string const &value)
Append an element to a vector of strings in a KeyMap.
void append(std::string const &key, char unsigned value)
Append an element to a vector of char in a KeyMap.
bool hasKey(std::string const &key) const
Does this map contain the specified key?
void replace(std::string const &key, int i, char unsigned value)
Replace an element of a vector of char in a KeyMap.
void putD(std::string const &key, std::vector< double > const &vec, std::string const &comment="")
Add a vector of double.
void replace(std::string const &key, int i, Object const &value)
Replace an element of a vector of Objects in a KeyMap.
void putS(std::string const &key, std::vector< short int > const &vec, std::string const &comment="")
Add a vector of short int.
std::shared_ptr< KeyMap > copy() const
Return a deep copy of this object.
void putF(std::string const &key, float value, std::string const &comment="")
Add a float.
char unsigned getB(std::string const &key, int ind) const
Get one char value for a given key.
T static_pointer_cast(T... args)
KeyMap & operator=(KeyMap const &)=delete
std::vector< char unsigned > getB(std::string const &key) const
Get all char values for a given key.
DataType
Data types held by a KeyMap.
std::string key(int ind) const
Get the key at the specified index.
float getF(std::string const &key, int ind) const
Get one float value for a given key.
std::shared_ptr< Object > getA(std::string const &key, int ind) const
Get one Object for a given key; the object is deep copied.
std::vector< std::shared_ptr< Object > > getA(std::string const &key) const
Get all Objects for a given key; each object is deep copied.
void putC(std::string const &key, std::string const &value, std::string const &comment="")
Add a string.
void putA(std::string const &key, Object const &obj, std::string const &comment="")
Add an Object, which is deep copied.
void append(std::string const &key, Object const &value)
Append an element to a vector of Objects in a KeyMap.
KeyMap(AstKeyMap *rawKeyMap)
Construct a KeyMap from a raw AstKeyMap.
Abstract base class for all AST objects.
DataType type(std::string const &key)
Get the type suffix for a given key.
void putA(std::string const &key, std::vector< std::shared_ptr< Object const >> const &vec, std::string const &comment="")
Add a vector of shared pointer to Object; the objects are deep copied.
void putD(std::string const &key, double value, std::string const &comment="")
Add a double value.
std::vector< int > getI(std::string const &key) const
Get all int values for a given key.