mrfioc2  2.3.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
mrf::Object Class Referenceabstract

Base object inspection. More...

#include <object.h>

Inheritance diagram for mrf::Object:
Inheritance graph
[legend]

Classes

struct  _compName
 

Public Types

typedef m_obj_children_t::const_iterator child_iterator
 
typedef std::map< std::string, std::string > create_args_t
 
typedef Object *(* create_factory_t) (const std::string &name, const std::string &klass, const create_args_t &args)
 

Public Member Functions

const std::string & name () const
 
const Objectparent () const
 
virtual void lock () const =0
 
virtual void unlock () const =0
 
child_iterator beginChild () const
 
child_iterator endChild () const
 
virtual propertyBasegetPropertyBase (const char *, const std::type_info &)=0
 
template<typename P >
mrf::auto_ptr< property< P > > getProperty (const char *pname)
 
virtual void visitProperties (bool(*)(propertyBase *, void *), void *)=0
 

Static Public Member Functions

static ObjectgetObject (const std::string &name)
 
static ObjectgetCreateObject (const std::string &name, const std::string &klass, const create_args_t &args=create_args_t())
 
static void addFactory (const std::string &klass, create_factory_t fn)
 
static void visitObjects (bool(*)(Object *, void *), void *)
 

Protected Member Functions

 Object (const std::string &n, const Object *par=0)
 
virtual ~Object ()=0
 

Detailed Description

Base object inspection.

Interface for introspection operations. Allows access to properties.

Definition at line 378 of file object.h.

Member Typedef Documentation

◆ child_iterator

typedef m_obj_children_t::const_iterator mrf::Object::child_iterator

Definition at line 399 of file object.h.

◆ create_args_t

typedef std::map<std::string, std::string> mrf::Object::create_args_t

Definition at line 422 of file object.h.

◆ create_factory_t

typedef Object*(* mrf::Object::create_factory_t) (const std::string &name, const std::string &klass, const create_args_t &args)

Definition at line 428 of file object.h.

Constructor & Destructor Documentation

◆ Object()

Object::Object ( const std::string &  n,
const Object par = 0 
)
protected

Definition at line 61 of file object.cpp.

62  :m_obj_name(n)
63  ,m_obj_parent(par)
64  ,m_obj_children()
65 {
66  initObjectsOnce();
67  epicsGuard<epicsMutex> g(*objectsLock);
68 
69  if(n.size()==0)
70  throw std::invalid_argument("Object name can not be empty string");
71 
72  objects_t::const_iterator it=objects->find(n);
73  if(it!=objects->end()) {
74  std::ostringstream strm;
75  strm<<"Object name '"<<n<<"' already exists.";
76  throw std::runtime_error(strm.str());
77  }
78  (*objects)[n]=this;
79 
80  if(m_obj_parent)
81  m_obj_parent->m_obj_children.insert(this);
82 }

◆ ~Object()

Object::~Object ( )
protectedpure virtual

Definition at line 84 of file object.cpp.

85 {
86  initObjectsOnce();
87  epicsGuard<epicsMutex> g(*objectsLock);
88 
89  if(m_obj_parent)
90  m_obj_parent->m_obj_children.erase(this);
91 
92  objects_t::iterator it=objects->find(name());
93  if(it==objects->end())
94  errlogPrintf("Can not remove object '%s' because it is not in global list.\n", name().c_str());
95  else
96  objects->erase(it);
97 }
const std::string & name() const
Definition: object.h:393

Member Function Documentation

◆ addFactory()

void Object::addFactory ( const std::string &  klass,
create_factory_t  fn 
)
static

Definition at line 138 of file object.cpp.

139 {
140  initObjectsOnce();
141  epicsGuard<epicsMutex> g(*objectsLock);
142 
143  factories_t::const_iterator it=factories->find(klass);
144  if(it!=factories->end())
145  throw std::runtime_error(SB()<<"Can't replace Object factory: "<<klass);
146  (*factories)[klass] = fn;
147 }

◆ beginChild()

child_iterator mrf::Object::beginChild ( ) const
inline

Definition at line 400 of file object.h.

400 {return m_obj_children.begin();}

◆ endChild()

child_iterator mrf::Object::endChild ( ) const
inline

Definition at line 401 of file object.h.

401 {return m_obj_children.end();}

◆ getCreateObject()

Object * Object::getCreateObject ( const std::string &  name,
const std::string &  klass,
const create_args_t args = create_args_t() 
)
static

Fetch or or create named Object Throws an exception if creation fails

Definition at line 118 of file object.cpp.

119 {
120  initObjectsOnce();
121  epicsGuard<epicsMutex> g(*objectsLock);
122  {
123  objects_t::const_iterator it=objects->find(name);
124  if(it!=objects->end())
125  return it->second;
126  }
127  if(klass.empty())
128  throw std::runtime_error(SB()<<"Object not found : "<<name);
129  {
130  factories_t::const_iterator it=factories->find(klass);
131  if(it==factories->end())
132  throw std::runtime_error(SB()<<"No such Object factory: "<<klass);
133  return (it->second)(name, klass, args);
134  }
135 }
Definition: evrdump.c:37
const std::string & name() const
Definition: object.h:393

◆ getObject()

Object * Object::getObject ( const std::string &  name)
static

Fetch named Object returns NULL if not found

Definition at line 107 of file object.cpp.

108 {
109  initObjectsOnce();
110  epicsGuard<epicsMutex> g(*objectsLock);
111  objects_t::const_iterator it=objects->find(n);
112  if(it!=objects->end())
113  return it->second;
114  return 0;
115 }

◆ getProperty()

template<typename P >
mrf::auto_ptr<property<P> > mrf::Object::getProperty ( const char *  pname)
inline

Definition at line 405 of file object.h.

406  {
407  propertyBase *b=getPropertyBase(pname, typeid(P));
408  if(!b)
409  return mrf::auto_ptr<property<P> >();
410  property<P> *p=dynamic_cast<property<P> *>(b);
411  if(!p)
412  return mrf::auto_ptr<property<P> >();
413  return mrf::auto_ptr<property<P> >(p);
414  }
virtual propertyBase * getPropertyBase(const char *, const std::type_info &)=0
Definition: object.cpp:99

◆ getPropertyBase()

propertyBase * Object::getPropertyBase ( const char *  ,
const std::type_info &   
)
pure virtual

◆ lock()

virtual void mrf::Object::lock ( ) const
pure virtual

◆ name()

const std::string& mrf::Object::name ( ) const
inline

Definition at line 393 of file object.h.

393 {return m_obj_name;}

◆ parent()

const Object* mrf::Object::parent ( ) const
inline

Definition at line 394 of file object.h.

394 {return m_obj_parent;}

◆ unlock()

virtual void mrf::Object::unlock ( ) const
pure virtual

◆ visitObjects()

void Object::visitObjects ( bool(*)(Object *, void *)  cb,
void *  arg 
)
static

Definition at line 150 of file object.cpp.

151 {
152  initObjectsOnce();
153  epicsGuard<epicsMutex> g(*objectsLock);
154 
155  for(objects_t::const_iterator it=objects->begin();
156  it!=objects->end(); ++it)
157  {
158  if(!(*cb)(it->second, arg))
159  break;
160  }
161 }

◆ visitProperties()

void Object::visitProperties ( bool(*)(propertyBase *, void *)  ,
void *   
)
pure virtual

The documentation for this class was generated from the following files: