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>(
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>(
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);
189 if (!astMapGetElemF(
reinterpret_cast<AstKeyMap
const *
>(
getRawPtr()),
key.
c_str(), ind, &retVal)) {
190 throwKeyNotFound(
key);
212 if (!astMapGetElemI(
reinterpret_cast<AstKeyMap
const *
>(
getRawPtr()),
key.
c_str(), ind, &retVal)) {
213 throwKeyNotFound(
key);
235 if (!astMapGetElemS(
reinterpret_cast<AstKeyMap
const *
>(
getRawPtr()),
key.
c_str(), ind, &retVal)) {
236 throwKeyNotFound(
key);
257 char unsigned retVal;
258 if (!astMapGetElemB(
reinterpret_cast<AstKeyMap
const *
>(
getRawPtr()),
key.
c_str(), ind, &retVal)) {
259 throwKeyNotFound(
key);
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());
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());
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);
585 return std::static_pointer_cast<KeyMap>(copyImpl<KeyMap, AstKeyMap>());
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 {
612 if ((i < 0) || (i >= len)) {
614 os <<
"i = " << i <<
" not in range [0, " << len - 1 <<
"] for key \"" <<
key <<
"\"";
624 os <<
"key \"" <<
key <<
"\" not found";
Channel provides input/output of AST objects.
KeyMap is used to store a set of values with associated keys which identify the values.
void append(std::string const &key, float value)
Append an element to a vector of floats in a KeyMap.
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.
double getD(std::string const &key, int ind) const
Get one double value for a given key.
std::vector< std::shared_ptr< Object > > getA(std::string const &key) const
Get all Objects for a given key; each object is deep copied.
std::vector< float > getF(std::string const &key) const
Get all float values for a given key.
KeyMap(KeyMap const &)=default
Copy constructor: make a deep copy.
KeyMap(KeyMap &&)=default
KeyMap & operator=(KeyMap &&)=default
void append(std::string const &key, std::string const &value)
Append an element to a vector of strings in a KeyMap.
bool hasKey(std::string const &key) const
Does this map contain the specified 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.
int getI(std::string const &key, int ind) const
Get one int value for a given key.
void replace(std::string const &key, int i, Object const &value)
Replace an element of a vector of Objects 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.
void putI(std::string const &key, std::vector< int > const &vec, std::string const &comment="")
Add a vector of ints.
void append(std::string const &key, short int value)
Append an element to a vector of short int in a KeyMap.
void putB(std::string const &key, std::vector< char unsigned > const &vec, std::string const &comment="")
Add a vector of chars.
void putC(std::string const &key, std::string const &value, std::string const &comment="")
Add a string.
void putB(std::string const &key, char unsigned value, std::string const &comment="")
Add a char.
std::vector< int > getI(std::string const &key) const
Get all int values for a given key.
virtual std::shared_ptr< Object > copyPolymorphic() const override
Return a deep copy of this object.
void remove(std::string const &key)
Remove the specified entry.
float getF(std::string const &key, int ind) const
Get one float 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.
std::vector< short int > getS(std::string const &key) const
Get all short int values for a given key.
bool defined(std::string const &key) const
Does this map contain the specified key, and if so, does it have a defined value?
void replace(std::string const &key, int i, float value)
Replace an element of a vector of floats in a KeyMap.
void putS(std::string const &key, short int value, std::string const &comment="")
Add a short int.
void replace(std::string const &key, int i, std::string const &value)
Replace an element of a vector of strings in a KeyMap.
std::vector< char unsigned > getB(std::string const &key) const
Get all char values for a given key.
void replace(std::string const &key, int i, int value)
Replace an element of a vector of ints in a KeyMap.
void putU(std::string const &key, std::string const &comment="")
Add a new entry, but no value is stored with the entry.
void rename(std::string const &oldKey, std::string const &newKey)
Rename the specified entry.
std::shared_ptr< KeyMap > copy() const
Return a deep copy of this object.
std::vector< double > getD(std::string const &key) const
Get all double values for a given key.
short int getS(std::string const &key, int ind) const
Get one short int value for a given key.
std::string key(int ind) const
Get the key at the specified index.
int size() const
Get the number of keys.
KeyMap & operator=(KeyMap const &)=delete
void append(std::string const &key, char unsigned value)
Append an element to a vector of char in a KeyMap.
void replace(std::string const &key, int i, char unsigned value)
Replace an element of a vector of char in a KeyMap.
void replace(std::string const &key, int i, double value)
Replace an element of a vector of doubles in a KeyMap.
void putF(std::string const &key, float value, std::string const &comment="")
Add a float.
void putF(std::string const &key, std::vector< float > const &vec, std::string const &comment="")
Add a vector of floats.
void append(std::string const &key, double value)
Append an element to a vector of doubles in a KeyMap.
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, std::vector< short int > const &vec, std::string const &comment="")
Add a vector of short int.
std::string getC(std::string const &key, int ind) const
Get one std::string value for a given key.
void putC(std::string const &key, std::vector< std::string > const &vec, std::string const &comment="")
Add a vector of strings.
void putI(std::string const &key, int value, std::string const &comment="")
Add an int.
char unsigned getB(std::string const &key, int ind) const
Get one char value for a given key.
KeyMap(std::string const &options="")
Construct an empty KeyMap.
KeyMap(AstKeyMap *rawKeyMap)
Construct a KeyMap from a raw AstKeyMap.
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.
std::vector< std::string > getC(std::string const &key) const
Get all std::string values for a given key.
DataType type(std::string const &key)
Get the type suffix for a given key.
void putD(std::string const &key, std::vector< double > const &vec, std::string const &comment="")
Add a vector of double.
void putD(std::string const &key, double value, std::string const &comment="")
Add a double value.
Abstract base class for all AST objects.
std::string getClassName() const
Get Class: the name of the class (e.g.
AstObject const * getRawPtr() const
Get the raw AST pointer.
AST wrapper classes and functions.
DataType
Data types held by a KeyMap.
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Throw std::runtime_error if AST's state is bad.