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>
91 #include "mrfCommon.h"
94 class epicsShareClass alarm_exception :
public std::exception
96 const short sevr, stat;
98 explicit alarm_exception(
short sevr = INVALID_ALARM,
short stat = COMM_ALARM) : sevr(sevr), stat(stat) {}
99 virtual ~alarm_exception() throw() {}
100 virtual const char *what() throw();
101 inline
short severity()
const {
return sevr; }
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;
132 return a.type()==b.type() && strcmp(a.name(),b.name())==0;
135 bool operator!=(
const propertyBase& a,
const propertyBase& b)
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;
201 const char *
const name;
202 getter_t
const getter;
203 setter_t
const setter;
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;
228 const char *
const name;
229 getter_t
const getter;
230 setter_t
const setter;
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)();
256 const char *
const name;
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();}
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>
353 virtual ~propertyInstance() {}
355 virtual const char* name()
const{
return prop.name;}
356 virtual const std::type_info& type()
const{
return prop.type();}
357 virtual void exec() {
358 (inst->*prop.execer)();
382 bool operator()(
const Object* a,
const Object* b)
const{
return a->name()<b->name();}
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;}
394 const Object* parent()
const{
return m_obj_parent;}
396 virtual void lock()
const =0;
397 virtual void unlock()
const =0;
399 typedef m_obj_children_t::const_iterator child_iterator;
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;
405 mrf::auto_ptr<property<P> > getProperty(
const char* pname)
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);
422 typedef std::map<std::string, std::string> create_args_t;
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();
466 explicit ObjectInst(
const std::string& n) : Base(n) {}
468 ObjectInst(
const std::string& n, A& a) : Base(n, a) {}
472 virtual propertyBase* getPropertyBase(
const char* pname,
const std::type_info& ptype)
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);
487 virtual void visitProperties(
bool (*cb)(
propertyBase*,
void*),
void* arg)
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();
User implementation hook.
Definition: object.h:460
Base object inspection.
Definition: object.h:379
final array implementation
Definition: object.h:317
final scalar implementation
Definition: object.h:276
virtual void show(std::ostream &strm) const
Print the value of the field w/o leading or trailing whitespace.
Definition: object.h:300
virtual void set(P v)
The setter for this property.
Definition: object.h:289
An un-bound, typed array property.
Definition: object.h:223
An un-bound momentary/command.
Definition: object.h:252
An un-bound, typed scalar property.
Definition: object.h:196
virtual property< P > * bind(C *)
Binder for scalar instances.
Definition: object.h:309
Requested operation is not implemented by the property.
Definition: object.h:109
An un-typed, un-bound property for class C.
Definition: object.h:185
virtual propertyBase * bind(C *)=0
Create a bound property with the given instance.
An un-typed property.
Definition: object.h:121
A bound, typed array property.
Definition: object.h:151
A momentary/command.
Definition: object.h:171
A bound, typed scalar property.
Definition: object.h:141
virtual void set(P)=0
The setter for this property.