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" 56 using Deleter = void (*)(AstObject *);
59 using ObjectPtr = std::unique_ptr<AstObject, Deleter>;
64 Object(
Object const &
object) : _objPtr(object.getRawPtrCopy(), &detail::annulAstObject) {}
83 return !(*
this == rhs); };
88 static std::shared_ptr<Object>
fromString(std::string
const &str) {
89 auto *rawPtr =
reinterpret_cast<AstObject *
>(astFromString(str.c_str()));
90 return Object::_basicFromAstObject(rawPtr);
104 template <
typename Class>
118 void clear(std::string
const &attrib) {
127 bool ret = astHasAttribute(
getRawPtr(), attrib.c_str());
202 astLock(
getRawPtr(), static_cast<int>(wait));
228 void show(std::ostream &os,
bool showComments =
true)
const;
235 std::string
show(
bool showComments =
true)
const;
249 bool test(std::string
const &attrib)
const {
250 bool res = astTest(
getRawPtr(), attrib.c_str());
280 astUnlock(
getRawPtr(), static_cast<int>(report));
291 AstObject
const *
getRawPtr()
const {
return &*_objPtr; };
293 AstObject *
getRawPtr() {
return &*_objPtr; };
300 explicit Object(AstObject *
object);
308 template <
typename ShimT,
typename AstT>
309 static std::shared_ptr<ShimT>
makeShim(AstObject *p) {
310 return std::shared_ptr<ShimT>(
new ShimT(reinterpret_cast<AstT *>(p)));
318 template <
typename T,
typename AstT>
320 auto *rawptr =
reinterpret_cast<AstT *
>(astCopy(
getRawPtr()));
321 auto retptr = std::shared_ptr<T>(
new T(rawptr));
347 bool getB(std::string
const &attrib)
const {
348 bool val = astGetI(
getRawPtr(), attrib.c_str());
360 std::string
const getC(std::string
const &attrib)
const {
361 char const *rawval = astGetC(
getRawPtr(), attrib.c_str());
363 return std::string(rawval);
373 double getD(std::string
const &attrib)
const {
374 double val = astGetD(
getRawPtr(), attrib.c_str());
386 float getF(std::string
const &attrib)
const {
387 float val = astGetF(
getRawPtr(), attrib.c_str());
399 int getI(std::string
const &attrib)
const {
400 int val = astGetI(
getRawPtr(), attrib.c_str());
412 long int getL(std::string
const &attrib)
const {
413 long int val = astGetL(
getRawPtr(), attrib.c_str());
439 void set(std::string
const &setting) { astSet(
getRawPtr(),
"%s", setting.c_str()); }
448 void setB(std::string
const &attrib,
bool value) {
449 astSetI(
getRawPtr(), attrib.c_str(), value);
460 void setC(std::string
const &attrib, std::string
const &value) {
461 astSetC(
getRawPtr(), attrib.c_str(), value.c_str());
472 void setD(std::string
const &attrib,
double value) {
473 astSetD(
getRawPtr(), attrib.c_str(), value);
484 void setF(std::string
const &attrib,
float value) {
485 astSetF(
getRawPtr(), attrib.c_str(), value);
496 void setI(std::string
const &attrib,
int value) {
497 astSetI(
getRawPtr(), attrib.c_str(), value);
508 void setL(std::string
const &attrib,
long int value) {
509 astSetL(
getRawPtr(), attrib.c_str(), value);
521 static std::shared_ptr<Object> _basicFromAstObject(AstObject *rawObj);
526 AstObject * getRawPtrCopy()
const {
527 AstObject * rawPtrCopy =
reinterpret_cast<AstObject *
>(astCopy(
getRawPtr()));
535 void swapRawPointers(
Object &other) noexcept {
536 swap(_objPtr, other._objPtr);
bool test(std::string const &attrib) const
Definition: Object.h:249
AstObject const * getRawPtr() const
Definition: Object.h:291
long int getL(std::string const &attrib) const
Definition: Object.h:412
void setB(std::string const &attrib, bool value)
Definition: Object.h:448
int getI(std::string const &attrib) const
Definition: Object.h:399
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
std::string getClassName() const
Definition: Object.h:138
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:49
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:220
std::shared_ptr< T > copyImpl() const
Definition: Object.h:319
std::shared_ptr< Object > copy() const
Return a deep copy of this object.
Definition: Object.h:108
void setL(std::string const &attrib, long int value)
Definition: Object.h:508
std::unique_ptr< AstObject, Deleter > ObjectPtr
unique pointer holding an AST raw pointer
Definition: Object.h:59
bool hasAttribute(std::string const &attrib) const
Definition: Object.h:126
static std::shared_ptr< Class > fromAstObject(AstObject *rawObj, bool copy)
Definition: Object.cc:132
std::string getID() const
Get ID: object identification string that is not copied.
Definition: Object.h:141
Object(Object const &object)
Copy constructor: make a deep copy.
Definition: Object.h:64
int getObjSize() const
Get ObjSize: the in-memory size of the AST object in bytes.
Definition: Object.h:155
bool getB(std::string const &attrib) const
Definition: Object.h:347
void unlock(bool report=false)
Definition: Object.h:279
Definition: MapSplit.h:38
bool getUseDefs() const
Get UseDefs: allow use of default values for Object attributes?
Definition: Object.h:165
void setC(std::string const &attrib, std::string const &value)
Definition: Object.h:460
static std::shared_ptr< ShimT > makeShim(AstObject *p)
Definition: Object.h:309
void setID(std::string const &id)
Set ID: object identification string that is not copied.
Definition: Object.h:214
std::string getIdent() const
Get Ident: object identification string that is copied.
Definition: Object.h:144
void setF(std::string const &attrib, float value)
Definition: Object.h:484
bool same(Object const &other) const
Definition: Object.h:211
int getRefCount() const
Definition: Object.h:162
void setIdent(std::string const &ident)
Set Ident: object identification string that is copied.
Definition: Object.h:217
void setD(std::string const &attrib, double value)
Definition: Object.h:472
int getNObject() const
Definition: Object.h:152
double getD(std::string const &attrib) const
Definition: Object.h:373
static std::shared_ptr< Object > fromString(std::string const &str)
Definition: Object.h:88
void show(std::ostream &os, bool showComments=true) const
Definition: Object.cc:152
float getF(std::string const &attrib) const
Definition: Object.h:386
void setI(std::string const &attrib, int value)
Definition: Object.h:496
std::string const getC(std::string const &attrib) const
Definition: Object.h:360
Definition: FrameDict.h:67
bool operator==(Object const &rhs) const
Definition: Object.cc:82
bool operator!=(Object const &rhs) const
Definition: Object.h:82
void clear(std::string const &attrib)
Definition: Object.h:118
void lock(bool wait)
Definition: Object.h:201