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"
52 using Deleter = void (*)(AstObject *);
55 using ObjectPtr = std::unique_ptr<AstObject, Deleter>;
67 static std::shared_ptr<Object>
fromString(std::string
const & str) {
68 auto * rawPtr =
reinterpret_cast<AstObject *
>(astFromString(str.c_str()));
83 template <
typename Class>
97 void clear(std::string
const & attrib) {
106 bool ret = astHasAttribute(
getRawPtr(), attrib.c_str());
172 astLock(
getRawPtr(), static_cast<int>(wait));
197 void show(std::ostream & os)
const;
204 std::string
show()
const;
218 bool test(std::string
const & attrib) {
219 bool res = astTest(
getRawPtr(), attrib.c_str());
249 astUnlock(
getRawPtr(), static_cast<int>(report));
260 AstObject
const *
getRawPtr()
const {
return &*_objPtr; };
262 AstObject *
getRawPtr() {
return &*_objPtr; };
271 _objPtr(object, &detail::annulAstObject)
275 throw std::runtime_error(
"Null pointer");
295 template <
typename ShimT,
typename AstT>
296 static std::shared_ptr<ShimT>
makeShim(AstObject * p) {
297 return std::shared_ptr<ShimT>(
new ShimT(reinterpret_cast<AstT*>(p)));
305 template<
typename T,
typename AstT>
307 auto * rawptr =
reinterpret_cast<AstT *
>(astCopy(
getRawPtr()));
308 auto retptr = std::shared_ptr<T>(
new T(rawptr));
334 bool getB(std::string
const & attrib)
const {
335 bool val = astGetI(
getRawPtr(), attrib.c_str());
347 std::string
const getC(std::string
const & attrib)
const {
348 char const * rawval = astGetC(
getRawPtr(), attrib.c_str());
350 return std::string(rawval);
360 double getD(std::string
const & attrib)
const {
361 double val = astGetD(
getRawPtr(), attrib.c_str());
373 float getF(std::string
const & attrib)
const {
374 float val = astGetF(
getRawPtr(), attrib.c_str());
386 int getI(std::string
const & attrib)
const {
387 int val = astGetI(
getRawPtr(), attrib.c_str());
399 long int getL(std::string
const & attrib)
const {
400 long int val = astGetL(
getRawPtr(), attrib.c_str());
426 void set(std::string
const & setting) { astSet(
getRawPtr(), setting.c_str()); }
435 void setB(std::string
const & attrib,
bool value) {
436 astSetI(
getRawPtr(), attrib.c_str(), value);
447 void setC(std::string
const & attrib, std::string
const & value) {
448 astSetC(
getRawPtr(), attrib.c_str(), value.c_str());
459 void setD(std::string
const & attrib,
double value) {
460 astSetD(
getRawPtr(), attrib.c_str(), value);
471 void setF(std::string
const & attrib,
float value) {
472 astSetF(
getRawPtr(), attrib.c_str(), value);
483 void setI(std::string
const & attrib,
int value) {
484 astSetI(
getRawPtr(), attrib.c_str(), value);
495 void setL(std::string
const & attrib,
long int value) {
496 astSetL(
getRawPtr(), attrib.c_str(), value);
int getObjSize() const
Get ObjSize: the in-memory size of the Object in bytes.
Definition: Object.h:129
void setUseDefs(bool usedefs)
Set UseDefs: allow use of default values for Object attributes?
Definition: Object.h:190
void setI(std::string const &attrib, int value)
Definition: Object.h:483
static std::shared_ptr< ShimT > makeShim(AstObject *p)
Definition: Object.h:296
int getNobject() const
Get Nobject: number of Objects in class.
Definition: Object.h:126
Object(AstObject *object)
Definition: Object.h:270
void setF(std::string const &attrib, float value)
Definition: Object.h:471
std::string getIdent() const
Get Ident: object identification string that is copied.
Definition: Object.h:123
std::shared_ptr< Object > copy() const
Return a deep copy of this object.
Definition: Object.h:87
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:53
static std::shared_ptr< Object > fromString(std::string const &str)
Definition: Object.h:67
bool getUseDefs() const
Get UseDefs: allow use of default values for Object attributes?
Definition: Object.h:135
std::string getClass() const
Definition: Object.h:117
std::string getID() const
Get ID: object identification string that is not copied.
Definition: Object.h:120
bool hasAttribute(std::string const &attrib) const
Definition: Object.h:105
virtual std::shared_ptr< Object > _copyPolymorphic() const =0
bool same(Object const &other) const
Definition: Object.h:181
std::string const getC(std::string const &attrib) const
Definition: Object.h:347
void setIdent(std::string const &ident)
Set Ident: object identification string that is copied.
Definition: Object.h:187
void setB(std::string const &attrib, bool value)
Definition: Object.h:435
void setID(std::string const &id)
Set ID: object identification string that is not copied.
Definition: Object.h:184
std::unique_ptr< AstObject, Deleter > ObjectPtr
unique pointer holding an AST raw pointer
Definition: Object.h:55
static std::shared_ptr< Object > _basicFromAstObject(AstObject *rawObj)
Definition: Object.cc:78
void setC(std::string const &attrib, std::string const &value)
Definition: Object.h:447
Definition: MapSplit.h:38
std::string show() const
Definition: Object.cc:150
void unlock(bool report=false)
Definition: Object.h:248
float getF(std::string const &attrib) const
Definition: Object.h:373
double getD(std::string const &attrib) const
Definition: Object.h:360
void clear(std::string const &attrib)
Definition: Object.h:97
void setL(std::string const &attrib, long int value)
Definition: Object.h:495
void setD(std::string const &attrib, double value)
Definition: Object.h:459
static std::shared_ptr< Class > fromAstObject(AstObject *rawObj, bool copy)
Definition: Object.cc:120
void lock(bool wait)
Definition: Object.h:171
bool test(std::string const &attrib)
Definition: Object.h:218
void set(std::string const &setting)
Definition: Object.h:426
long int getL(std::string const &attrib) const
Definition: Object.h:399
std::shared_ptr< T > _copyImpl() const
Definition: Object.h:306
int getI(std::string const &attrib) const
Definition: Object.h:386
int getRefCount() const
Get RefCount: count of active Object pointers.
Definition: Object.h:132
bool getB(std::string const &attrib) const
Definition: Object.h:334
AstObject const * getRawPtr() const
Definition: Object.h:260