54 #pragma warning( disable: 4251 ) 55 #pragma warning( disable: 4275 ) 64 #pragma warning( disable: 4661 ) 68 #if (defined __GNUC__ && __GNUC__ < 3) 83 #include <compilerDependencies.h> 84 #include <epicsThread.h> 85 #include <epicsTypes.h> 96 const short sevr, stat;
98 explicit alarm_exception(
short sevr = INVALID_ALARM,
short stat = COMM_ALARM) : sevr(sevr), stat(stat) {}
100 virtual const char *what()
throw();
102 inline short status()
const {
return stat; }
123 virtual const char* name()
const=0;
124 virtual const std::type_info& type()
const=0;
126 virtual void show(std::ostream&)
const;
144 virtual void set(P)=0;
145 virtual P
get()
const=0;
158 virtual void set(
const P* arr, epicsUInt32 L)=0;
165 virtual epicsUInt32
get(P*, epicsUInt32)
const=0;
173 virtual void exec()=0;
187 virtual const std::type_info& type()
const=0;
194 template<
class C,
typename P>
198 typedef void (C::*setter_t)(P);
199 typedef P (C::*getter_t)()
const;
206 :name(n), getter(g), setter(s) {}
208 virtual const std::type_info&
type()
const{
return typeid(P);}
212 template<
class C,
typename P>
215 makeUnboundProperty(
const char* n, P (C::*g)()
const,
void (C::*s)(P)=0)
221 template<
class C,
typename P>
225 typedef void (C::*setter_t)(
const P*, epicsUInt32);
226 typedef epicsUInt32 (C::*getter_t)(P*, epicsUInt32)
const;
233 :name(n), getter(g), setter(s) {}
235 virtual const std::type_info&
type()
const{
return typeid(P[1]);}
239 template<
class C,
typename P>
242 makeUnboundProperty(
const char* n,
243 epicsUInt32 (C::*g)(P*, epicsUInt32)
const,
244 void (C::*s)(
const P*, epicsUInt32)=0)
254 typedef void (C::*exec_t)();
260 virtual const std::type_info&
type()
const{
return typeid(void);}
267 makeUnboundProperty(
const char* n,
274 template<
class C,
typename P>
287 virtual const char*
name()
const{
return prop.
name;}
288 virtual const std::type_info&
type()
const{
return prop.
type();}
289 virtual void set(P v)
293 (inst->*(prop.
setter))(v);
295 virtual P
get()
const{
298 return (inst->*(prop.
getter))();
300 virtual void show(std::ostream& strm)
const 307 template<
class C,
typename P>
315 template<
class C,
typename P>
328 virtual const char*
name()
const{
return prop.
name;}
329 virtual const std::type_info&
type()
const{
return prop.
type();}
330 virtual void set(
const P* a, epicsUInt32 l)
331 { (inst->*(prop.
setter))(a,l); }
332 virtual epicsUInt32
get(P* a, epicsUInt32 l)
const 333 {
return (inst->*(prop.
getter))(a,l); }
337 template<
class C,
typename P>
355 virtual const char*
name()
const{
return prop.
name;}
356 virtual const std::type_info&
type()
const{
return prop.
type();}
385 const std::string m_obj_name;
386 const Object *
const m_obj_parent;
387 typedef std::set<Object*,_compName> m_obj_children_t;
388 mutable m_obj_children_t m_obj_children;
393 const std::string&
name()
const{
return m_obj_name;}
396 virtual void lock()
const =0;
397 virtual void unlock()
const =0;
400 child_iterator
beginChild()
const{
return m_obj_children.begin();}
401 child_iterator
endChild()
const{
return m_obj_children.end();}
403 virtual propertyBase* getPropertyBase(
const char*,
const std::type_info&)=0;
409 return mrf::auto_ptr<property<P> >();
412 return mrf::auto_ptr<property<P> >();
413 return mrf::auto_ptr<property<P> >(p);
416 virtual void visitProperties(
bool (*)(
propertyBase*,
void*),
void*)=0;
420 static Object* getObject(
const std::string& name);
426 static Object* getCreateObject(
const std::string& name,
const std::string& klass,
const create_args_t&
args = create_args_t());
428 typedef Object* (*create_factory_t)(
const std::string& name,
const std::string& klass,
const create_args_t&
args);
430 static void addFactory(
const std::string& klass, create_factory_t fn);
432 static void visitObjects(
bool (*)(
Object*,
void*),
void*);
458 template<
class C,
typename Base = Object>
461 typedef std::multimap<std::string, detail::unboundPropertyBase<C>*> m_props_t;
462 static m_props_t *m_props;
464 static int initObject();
476 throw std::runtime_error(emsg);
477 typename m_props_t::const_iterator it=m_props->lower_bound(pname),
478 end=m_props->upper_bound(pname);
480 if(it->second->type()==ptype)
481 return it->second->bind(static_cast<C*>(
this));
484 return Base::getPropertyBase(pname, ptype);
491 throw std::runtime_error(emsg);
493 mrf::auto_ptr<propertyBase> cur;
494 for(
typename m_props_t::const_iterator it=m_props->begin();
495 it!=m_props->end(); ++it)
497 cur.reset(it->second->bind(static_cast<C*>(
this)));
500 if(!(*cb)(cur.get(), arg))
503 Base::visitProperties(cb, arg);
507 #define OBJECT_BEGIN2(klass, Base) namespace mrf {\ 508 template<> ObjectInst<klass, Base>::m_props_t* ObjectInst<klass, Base>::m_props = 0; \ 509 template<> int ObjectInst<klass, Base>::initObject() { \ 510 const char *klassname = #klass; (void)klassname; \ 511 try { mrf::auto_ptr<m_props_t> props(new m_props_t); { 513 #define OBJECT_BEGIN(klass) OBJECT_BEGIN2(klass, Object) 515 #define OBJECT_PROP1(NAME, GET) \ 516 props->insert(std::make_pair(static_cast<const char*>(NAME), detail::makeUnboundProperty(NAME, GET) )) 518 #define OBJECT_PROP2(NAME, GET, SET) \ 519 props->insert(std::make_pair(static_cast<const char*>(NAME), detail::makeUnboundProperty(NAME, GET, SET) )) 521 #define OBJECT_FACTORY(FN) addFactory(klassname, FN) 523 #define OBJECT_END(klass) \ 524 } m_props = props.release(); return 1; \ 525 } catch(std::exception& e) { \ 526 std::cerr<<"Failed to build property table for "<<typeid(klass).name()<<"\n"<<e.what()<<"\n"; \ 527 throw std::runtime_error("Failed to build"); \ 529 static int done_##klass EPICS_UNUSED = klass::initObject(); 533 #endif // MRFOBJECT_H A bound, typed scalar property.
virtual const char * name() const
virtual const std::type_info & type() const
ObjectInst(const std::string &n, A &a)
std::map< std::string, std::string > create_args_t
propertyInstance(C *c, const unboundProperty< C, void > &p)
alarm_exception(short sevr=INVALID_ALARM, short stat=COMM_ALARM)
virtual const std::type_info & type() const =0
const Object * parent() const
m_obj_children_t::const_iterator child_iterator
A bound, typed array property.
virtual ~alarm_exception()
bool operator()(const Object *a, const Object *b) const
virtual void show(std::ostream &strm) const
Print the value of the field w/o leading or trailing whitespace.
unboundProperty(const char *n, getter_t g, setter_t s)
virtual const char * name() const
An un-typed, un-bound property for class C.
unboundProperty(const char *n, exec_t e)
virtual ~propertyInstance()
virtual void visitProperties(bool(*cb)(propertyBase *, void *), void *arg)
virtual propertyBase * getPropertyBase(const char *pname, const std::type_info &ptype)
opNotImplemented(const std::string &m)
virtual const std::type_info & type() const
virtual const char * name() const
User implementation hook.
virtual const std::type_info & type() const
virtual ~propertyInstance()
virtual const char * name() const =0
final scalar implementation
final array implementation
virtual ~propertyInstance()
propertyInstance(C *c, const unboundProperty< C, P > &p)
virtual ~unboundPropertyBase()
virtual const std::type_info & type() const
propertyInstance(C *c, const unboundProperty< C, P[1]> &p)
child_iterator beginChild() const
Requested operation is not implemented by the property.
const std::string & name() const
child_iterator endChild() const
mrf::auto_ptr< property< P > > getProperty(const char *pname)
An un-bound, typed scalar property.
unboundProperty(const char *n, getter_t g, setter_t s)
An un-bound momentary/command.
ObjectInst(const std::string &n)
virtual const std::type_info & type() const
virtual const std::type_info & type() const
An un-bound, typed array property.