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()))) {
118 bool ret =
static_cast<bool>(
119 astMapDefined(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str()));
126 int const len =
size();
127 if ((ind < 0) || (ind >= len)) {
129 os <<
"ind = " << ind <<
" not in range [0, " << len - 1 <<
"]";
132 const char *rawKey = astMapKey(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), ind);
143 bool ret =
static_cast<bool>(
144 astMapHasKey(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str()));
151 int len = astMapLength(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str());
158 int const size = astMapSize(reinterpret_cast<AstKeyMap const *>(
getRawPtr()));
166 if (!astMapGetElemD(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
167 throwKeyNotFound(key);
179 astMapGet1D(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
189 if (!astMapGetElemF(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
190 throwKeyNotFound(key);
202 astMapGet1F(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
212 if (!astMapGetElemI(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
213 throwKeyNotFound(key);
225 astMapGet1I(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
235 if (!astMapGetElemS(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
236 throwKeyNotFound(key);
248 astMapGet1S(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
257 char unsigned retVal;
258 if (!astMapGetElemB(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &retVal)) {
259 throwKeyNotFound(key);
271 astMapGet1B(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(),
size, &nret,
280 int const maxChar = 1 + astMapLenC(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str());
282 if (!astMapGetElemC(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), maxChar, ind,
284 throwKeyNotFound(key);
296 int const eltLen = 1 + astMapLenC(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str());
299 astMapGet1C(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), eltLen,
size, &nret,
301 for (
int i = 0; i <
size; ++i) {
313 if (!astMapGetElemA(reinterpret_cast<AstKeyMap const *>(
getRawPtr()), key.
c_str(), ind, &rawObj)) {
314 throwKeyNotFound(key);
317 return Object::fromAstObject<Object>(rawObj,
true);
324 for (
int i = 0; i <
size; ++i) {
332 astMapPut0D(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
338 _assertVectorNotEmpty(key, vec.
size());
346 astMapPut0F(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
352 _assertVectorNotEmpty(key, vec.
size());
360 astMapPut0I(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
366 _assertVectorNotEmpty(key, vec.
size());
374 astMapPut0S(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
380 _assertVectorNotEmpty(key, vec.
size());
388 astMapPut0B(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value, comment.c_str());
395 _assertVectorNotEmpty(key, vec.
size());
403 astMapPut0C(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), value.
c_str(), comment.c_str());
409 _assertVectorNotEmpty(key, vec.
size());
422 AstObject *rawCopy =
reinterpret_cast<AstObject *
>(astCopy(obj.
getRawPtr()));
423 astMapPut0A(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), rawCopy, comment.c_str());
430 _assertVectorNotEmpty(key, vec.
size());
432 for (
int i = 0,
size = vec.size(); i <
size; ++i) {
449 astMapPutU(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), comment.c_str());
455 int const i = _getAppendIndex(key);
456 astMapPutElemD(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
462 int const i = _getAppendIndex(key);
463 astMapPutElemF(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
469 int const i = _getAppendIndex(key);
470 astMapPutElemI(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
476 int const i = _getAppendIndex(key);
477 astMapPutElemS(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
483 int const i = _getAppendIndex(key);
484 astMapPutElemB(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
490 int const i = _getAppendIndex(key);
497 int const i = _getAppendIndex(key);
498 AstObject *rawCopy =
reinterpret_cast<AstObject *
>(astCopy(value.
getRawPtr()));
499 astMapPutElemA(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, rawCopy);
505 _assertReplaceIndexInRange(key, i);
506 astMapPutElemD(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
512 _assertReplaceIndexInRange(key, i);
513 astMapPutElemF(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
519 _assertReplaceIndexInRange(key, i);
520 astMapPutElemI(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
526 _assertReplaceIndexInRange(key, i);
527 astMapPutElemS(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
533 _assertReplaceIndexInRange(key, i);
534 astMapPutElemB(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, value);
540 _assertReplaceIndexInRange(key, i);
547 _assertReplaceIndexInRange(key, i);
548 AstObject *rawCopy =
reinterpret_cast<AstObject *
>(astCopy(value.
getRawPtr()));
549 astMapPutElemA(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str(), i, rawCopy);
577 int retVal = astMapType(reinterpret_cast<AstKeyMap *>(
getRawPtr()), key.
c_str());
579 return static_cast<DataType>(retVal);
591 explicit KeyMap(AstKeyMap *rawKeyMap) :
Object(reinterpret_cast<AstObject *>(rawKeyMap)) {
594 os <<
"this is a " <<
getClassName() <<
", which is not a KeyMap";
604 os <<
"vector supplied for key \"" << key <<
"\" has zero elements";
610 void _assertReplaceIndexInRange(
std::string const &key,
int i)
const {
611 int const len =
length(key);
612 if ((i < 0) || (i >= len)) {
614 os <<
"i = " << i <<
" not in range [0, " << len - 1 <<
"] for key \"" << key <<
"\"";
620 int _getAppendIndex(
std::string const &key)
const {
621 int const i =
length(key);
624 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.