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>;
86 static std::shared_ptr<Object>
fromString(std::string
const &str) {
87 auto *rawPtr =
reinterpret_cast<AstObject *
>(astFromString(str.c_str()));
88 return Object::_basicFromAstObject(rawPtr);
102 template <
typename Class>
116 void clear(std::string
const &attrib) {
125 bool ret = astHasAttribute(
getRawPtr(), attrib.c_str());
200 astLock(
getRawPtr(), static_cast<int>(wait));
226 void show(std::ostream &os,
bool showComments =
true)
const;
233 std::string
show(
bool showComments =
true)
const;
247 bool test(std::string
const &attrib)
const {
248 bool res = astTest(
getRawPtr(), attrib.c_str());
278 astUnlock(
getRawPtr(), static_cast<int>(report));
289 AstObject
const *
getRawPtr()
const {
return &*_objPtr; };
291 AstObject *
getRawPtr() {
return &*_objPtr; };
298 explicit Object(AstObject *
object) : _objPtr(object, &detail::annulAstObject) {
301 throw std::runtime_error(
"Null pointer");
311 template <
typename ShimT,
typename AstT>
312 static std::shared_ptr<ShimT>
makeShim(AstObject *p) {
313 return std::shared_ptr<ShimT>(
new ShimT(reinterpret_cast<AstT *>(p)));
321 template <
typename T,
typename AstT>
323 auto *rawptr =
reinterpret_cast<AstT *
>(astCopy(
getRawPtr()));
324 auto retptr = std::shared_ptr<T>(
new T(rawptr));
350 bool getB(std::string
const &attrib)
const {
351 bool val = astGetI(
getRawPtr(), attrib.c_str());
363 std::string
const getC(std::string
const &attrib)
const {
364 char const *rawval = astGetC(
getRawPtr(), attrib.c_str());
366 return std::string(rawval);
376 double getD(std::string
const &attrib)
const {
377 double val = astGetD(
getRawPtr(), attrib.c_str());
389 float getF(std::string
const &attrib)
const {
390 float val = astGetF(
getRawPtr(), attrib.c_str());
402 int getI(std::string
const &attrib)
const {
403 int val = astGetI(
getRawPtr(), attrib.c_str());
415 long int getL(std::string
const &attrib)
const {
416 long int val = astGetL(
getRawPtr(), attrib.c_str());
442 void set(std::string
const &setting) { astSet(
getRawPtr(),
"%s", setting.c_str()); }
451 void setB(std::string
const &attrib,
bool value) {
452 astSetI(
getRawPtr(), attrib.c_str(), value);
463 void setC(std::string
const &attrib, std::string
const &value) {
464 astSetC(
getRawPtr(), attrib.c_str(), value.c_str());
475 void setD(std::string
const &attrib,
double value) {
476 astSetD(
getRawPtr(), attrib.c_str(), value);
487 void setF(std::string
const &attrib,
float value) {
488 astSetF(
getRawPtr(), attrib.c_str(), value);
499 void setI(std::string
const &attrib,
int value) {
500 astSetI(
getRawPtr(), attrib.c_str(), value);
511 void setL(std::string
const &attrib,
long int value) {
512 astSetL(
getRawPtr(), attrib.c_str(), value);
524 static std::shared_ptr<Object> _basicFromAstObject(AstObject *rawObj);
529 void swapRawPointers(
Object &other) noexcept {
530 swap(_objPtr, other._objPtr);
bool test(std::string const &attrib) const
Definition: Object.h:247
AstObject const * getRawPtr() const
Definition: Object.h:289
long int getL(std::string const &attrib) const
Definition: Object.h:415
void setB(std::string const &attrib, bool value)
Definition: Object.h:451
int getI(std::string const &attrib) const
Definition: Object.h:402
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
std::string getClassName() const
Definition: Object.h:136
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:218
std::shared_ptr< T > copyImpl() const
Definition: Object.h:322
std::shared_ptr< Object > copy() const
Return a deep copy of this object.
Definition: Object.h:106
void setL(std::string const &attrib, long int value)
Definition: Object.h:511
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:124
static std::shared_ptr< Class > fromAstObject(AstObject *rawObj, bool copy)
Definition: Object.cc:131
std::string getID() const
Get ID: object identification string that is not copied.
Definition: Object.h:139
int getObjSize() const
Get ObjSize: the in-memory size of the AST object in bytes.
Definition: Object.h:153
bool getB(std::string const &attrib) const
Definition: Object.h:350
void unlock(bool report=false)
Definition: Object.h:277
Definition: MapSplit.h:38
bool getUseDefs() const
Get UseDefs: allow use of default values for Object attributes?
Definition: Object.h:163
void setC(std::string const &attrib, std::string const &value)
Definition: Object.h:463
static std::shared_ptr< ShimT > makeShim(AstObject *p)
Definition: Object.h:312
void setID(std::string const &id)
Set ID: object identification string that is not copied.
Definition: Object.h:212
std::string getIdent() const
Get Ident: object identification string that is copied.
Definition: Object.h:142
void setF(std::string const &attrib, float value)
Definition: Object.h:487
bool same(Object const &other) const
Definition: Object.h:209
int getRefCount() const
Definition: Object.h:160
void setIdent(std::string const &ident)
Set Ident: object identification string that is copied.
Definition: Object.h:215
void setD(std::string const &attrib, double value)
Definition: Object.h:475
int getNObject() const
Definition: Object.h:150
double getD(std::string const &attrib) const
Definition: Object.h:376
static std::shared_ptr< Object > fromString(std::string const &str)
Definition: Object.h:86
void show(std::ostream &os, bool showComments=true) const
Definition: Object.cc:151
float getF(std::string const &attrib) const
Definition: Object.h:389
void setI(std::string const &attrib, int value)
Definition: Object.h:499
Object(AstObject *object)
Definition: Object.h:298
std::string const getC(std::string const &attrib) const
Definition: Object.h:363
Definition: FrameDict.h:65
bool operator==(Object const &rhs) const
Definition: Object.cc:81
bool operator!=(Object const &rhs) const
Definition: Object.h:81
void clear(std::string const &attrib)
Definition: Object.h:116
void lock(bool wait)
Definition: Object.h:199