22 #ifndef ASTSHIM_OBJECT_H
23 #define ASTSHIM_OBJECT_H
28 #include "astshim/base.h"
29 #include "astshim/detail/utils.h"
30 #include "astshim/MapSplit.h"
53 using Deleter = void (*)(AstObject *);
56 using ObjectPtr = std::unique_ptr<AstObject, Deleter>;
68 static std::shared_ptr<Object>
fromString(std::string
const &str) {
69 auto *rawPtr =
reinterpret_cast<AstObject *
>(astFromString(str.c_str()));
70 return Object::_basicFromAstObject(rawPtr);
84 template <
typename Class>
98 void clear(std::string
const &attrib) {
107 bool ret = astHasAttribute(
getRawPtr(), attrib.c_str());
182 astLock(
getRawPtr(), static_cast<int>(wait));
207 void show(std::ostream &os)
const;
214 std::string
show()
const;
228 bool test(std::string
const &attrib) {
229 bool res = astTest(
getRawPtr(), attrib.c_str());
259 astUnlock(
getRawPtr(), static_cast<int>(report));
270 AstObject
const *
getRawPtr()
const {
return &*_objPtr; };
272 AstObject *
getRawPtr() {
return &*_objPtr; };
279 explicit Object(AstObject *
object) : _objPtr(object, &detail::annulAstObject) {
282 throw std::runtime_error(
"Null pointer");
292 template <
typename ShimT,
typename AstT>
293 static std::shared_ptr<ShimT>
makeShim(AstObject *p) {
294 return std::shared_ptr<ShimT>(
new ShimT(reinterpret_cast<AstT *>(p)));
302 template <
typename T,
typename AstT>
304 auto *rawptr =
reinterpret_cast<AstT *
>(astCopy(
getRawPtr()));
305 auto retptr = std::shared_ptr<T>(
new T(rawptr));
331 bool getB(std::string
const &attrib)
const {
332 bool val = astGetI(
getRawPtr(), attrib.c_str());
344 std::string
const getC(std::string
const &attrib)
const {
345 char const *rawval = astGetC(
getRawPtr(), attrib.c_str());
347 return std::string(rawval);
357 double getD(std::string
const &attrib)
const {
358 double val = astGetD(
getRawPtr(), attrib.c_str());
370 float getF(std::string
const &attrib)
const {
371 float val = astGetF(
getRawPtr(), attrib.c_str());
383 int getI(std::string
const &attrib)
const {
384 int val = astGetI(
getRawPtr(), attrib.c_str());
396 long int getL(std::string
const &attrib)
const {
397 long int val = astGetL(
getRawPtr(), attrib.c_str());
423 void set(std::string
const &setting) { astSet(
getRawPtr(),
"%s", setting.c_str()); }
432 void setB(std::string
const &attrib,
bool value) {
433 astSetI(
getRawPtr(), attrib.c_str(), value);
444 void setC(std::string
const &attrib, std::string
const &value) {
445 astSetC(
getRawPtr(), attrib.c_str(), value.c_str());
456 void setD(std::string
const &attrib,
double value) {
457 astSetD(
getRawPtr(), attrib.c_str(), value);
468 void setF(std::string
const &attrib,
float value) {
469 astSetF(
getRawPtr(), attrib.c_str(), value);
480 void setI(std::string
const &attrib,
int value) {
481 astSetI(
getRawPtr(), attrib.c_str(), value);
492 void setL(std::string
const &attrib,
long int value) {
493 astSetL(
getRawPtr(), attrib.c_str(), value);
506 static std::shared_ptr<Object> _basicFromAstObject(AstObject *rawObj);
int getObjSize() const
Get ObjSize: the in-memory size of the AST object in bytes.
Definition: Object.h:135
virtual std::shared_ptr< Object > copyPolymorphic() const =0
void setUseDefs(bool usedefs)
Set UseDefs: allow use of default values for Object attributes?
Definition: Object.h:200
void setI(std::string const &attrib, int value)
Definition: Object.h:480
static std::shared_ptr< ShimT > makeShim(AstObject *p)
Definition: Object.h:293
Object(AstObject *object)
Definition: Object.h:279
void setF(std::string const &attrib, float value)
Definition: Object.h:468
std::string getIdent() const
Get Ident: object identification string that is copied.
Definition: Object.h:124
std::shared_ptr< Object > copy() const
Return a deep copy of this object.
Definition: Object.h:88
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:49
static std::shared_ptr< Object > fromString(std::string const &str)
Definition: Object.h:68
bool getUseDefs() const
Get UseDefs: allow use of default values for Object attributes?
Definition: Object.h:145
std::string getID() const
Get ID: object identification string that is not copied.
Definition: Object.h:121
bool hasAttribute(std::string const &attrib) const
Definition: Object.h:106
bool same(Object const &other) const
Definition: Object.h:191
std::string const getC(std::string const &attrib) const
Definition: Object.h:344
void setIdent(std::string const &ident)
Set Ident: object identification string that is copied.
Definition: Object.h:197
void setB(std::string const &attrib, bool value)
Definition: Object.h:432
void setID(std::string const &id)
Set ID: object identification string that is not copied.
Definition: Object.h:194
std::unique_ptr< AstObject, Deleter > ObjectPtr
unique pointer holding an AST raw pointer
Definition: Object.h:56
void setC(std::string const &attrib, std::string const &value)
Definition: Object.h:444
Definition: MapSplit.h:38
std::string show() const
Definition: Object.cc:152
void unlock(bool report=false)
Definition: Object.h:258
float getF(std::string const &attrib) const
Definition: Object.h:370
double getD(std::string const &attrib) const
Definition: Object.h:357
void clear(std::string const &attrib)
Definition: Object.h:98
std::shared_ptr< T > copyImpl() const
Definition: Object.h:303
void setL(std::string const &attrib, long int value)
Definition: Object.h:492
void setD(std::string const &attrib, double value)
Definition: Object.h:456
static std::shared_ptr< Class > fromAstObject(AstObject *rawObj, bool copy)
Definition: Object.cc:122
void lock(bool wait)
Definition: Object.h:181
bool test(std::string const &attrib)
Definition: Object.h:228
void set(std::string const &setting)
Definition: Object.h:423
long int getL(std::string const &attrib) const
Definition: Object.h:396
int getI(std::string const &attrib) const
Definition: Object.h:383
int getRefCount() const
Definition: Object.h:142
int getNObject() const
Definition: Object.h:132
bool getB(std::string const &attrib) const
Definition: Object.h:331
std::string getClassName() const
Definition: Object.h:118
AstObject const * getRawPtr() const
Definition: Object.h:270