📄 classtype.hpp
字号:
Constructors, Initters, Assignments, and Destructors */ public: DataMember_body(const std::string &name, const std::string &typ); virtual ~DataMember_body() {} private: // Disallow these unless specifically allowed. DataMember_body(const DataMember_body &); DataMember_body &operator=(const DataMember_body &); /*-------------------------------------------------------------------------- Accessors and Convertors */ public: const std::string& name() const { return m_name; } const std::string& typeName() const { return m_typeName; } virtual const Type &type() const = 0; // Because in the get case we require that the caller // know the type of the member, we can do a cast to the // right typed-member type. In the set case though, the // value that is passed in may not be the actual type of // the member, since there may be some kind of conversion. // We could also require the user to know the type, and do // a conversion, but the conversion would have to take place // outside of the set() method. This would require the use of // of a temporary object, which would then have to be copied to // the actual object in class, which might be inefficient. template <typename Val_NT, typename Obj_T> Val_NT &ref(Obj_T *op) const { ObjHolder_tmpl<Obj_T> oh(op); // I cannot use something like casting the Member to the // Member_body_tmpl1<Val_NT>, because this Val_NT is the actual // type, not a Type construct, which is what Member_body_tmpl1 // actually uses. I also can't have the derived type return a // ObjHolder, because then it would have to allocate it. Thus // I pass a ObjHolder down to get a pointer to the value. PtrHolder_tmpl<Val_NT> vph; this->getPtr(oh, &vph); assert(vph.ptr != NULL); return *vph.ptr; } virtual void getPtr(const ObjHolder &oh, PtrHolder *vh) const = 0; /*-------------------------------------------------------------------------- Methods */ public: virtual const BoundDataMember_body *bind(const ObjHolder &oh) const = 0; /*-------------------------------------------------------------------------- Data */ private: const std::string m_name; const std::string m_typeName;};/*-----------------------------------------------------------------------------\|------------------------------------------------------------------------------|| || DataMember || ||------------------------------------------------------------------------------|\------------------------------------------------------------------------------/ <Class comments>- */class DataMember { /*-------------------------------------------------------------------------- Constructors, Initters, Assignments, and Destructors */ public: explicit DataMember(const DataMember_body *b) : m_body(b) {} private: // Implicit for these should be fine. // Member(const Member &); // Member &operator=(const Member &); /*-------------------------------------------------------------------------- Accessors and Convertors */ public: const std::string &name() const { return m_body->name(); } const std::string &typeName() const { return m_body->typeName(); } inline Type type() const; template <typename Val_T, typename Obj_T> Val_T &ref(Obj_T *op) const { return m_body->ref<Val_T>(op); } /*-------------------------------------------------------------------------- Data */ public: const DataMember_body *m_body;};/*-----------------------------------------------------------------------------\|------------------------------------------------------------------------------|| || ClassType_body Inlines || ||------------------------------------------------------------------------------|\------------------------------------------------------------------------------/- *//*------------------------------------------------------------------------------ Constructors, Initters, Assignments, and Destructors */inlineClassType_body::~ClassType_body() {}/*------------------------------------------------------------------------------ Methods */template <typename T>const BoundDataMember_body *ClassType_body::getBoundDataMember(T *o, const std::string &n) const { ObjHolder_tmpl<T> oh(o); const DataMember_body *b = getDataMember(n); assert(b != NULL); return b->bind(oh);}template <typename T>const BoundMemberFunction_body *ClassType_body::getBoundMemberFunction(T *o, const std::string &n) const { ObjHolder_tmpl<T> oh(o); const MemberFunction_body *b = getMemberFunction(n); assert(b != NULL); return b->bind(oh);}template <typename T>T *ClassType_body::newInstance() const { // Create a ObjHolder for the new instance to be stored into. ObjHolder_tmpl<T> tph; this->newInstance(&tph); return tph.ptr;}/*-----------------------------------------------------------------------------\|------------------------------------------------------------------------------|| || ClassType Inlines || ||------------------------------------------------------------------------------|\------------------------------------------------------------------------------/- *//*------------------------------------------------------------------------------ Methods */inline DataMemberClassType::getDataMember(const std::string &n) const { return DataMember(m_body->getDataMember(n));}inline MemberFunctionClassType::getMemberFunction(const std::string &n) const { return MemberFunction(m_body->getMemberFunction(n));}template <typename T>inline BoundDataMemberClassType::getBoundDataMember(T *o, const std::string &n) const { return BoundDataMember(m_body->getBoundDataMember(o, n));}template <typename T>inline BoundMemberFunction ClassType::getBoundMemberFunction(T *o, const std::string &n) const { return BoundMemberFunction(m_body->getBoundMemberFunction(o, n));}inline boolClassType::derivesFrom(const ClassType &c) const { return m_body->derivesFrom(*c.m_body);}inline boolClassType::inheritsFrom(const ClassType &c) const { return derivesFrom(c);}/*------------------------------------------------------------------------------ Static Objects *//*-----------------------------------------------------------------------------\|------------------------------------------------------------------------------|| || Member_body Inlines || ||------------------------------------------------------------------------------|\------------------------------------------------------------------------------/ <Class comments>- *//*-----------------------------------------------------------------------------\|------------------------------------------------------------------------------|| || Member Inlines || ||------------------------------------------------------------------------------|\------------------------------------------------------------------------------/- *//*------------------------------------------------------------------------------ Accessors and Convertors */inline TypeDataMember::type() const { return m_body->type(); }static const char ClassType_h_id[] ="$Id: ClassType.hpp,v 1.1 2007/10/25 14:05:23 tdevadit Exp $";} // namespace#endif/* Local Variables: *//* c-basic-offset: 4 *//* indent-tabs-mode: nil *//* End: *//* vim: set filetype=cpp tabstop=8 shiftwidth=4 softtabstop=4 expandtab: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -