📄 classtype_tmpl.hpp
字号:
| |
| VoidMember |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Base case of recursion.
- */
template <typename Obj_TP>
struct VoidMember {
VoidMember() {}
void registerMember(typename MemberList_base<Obj_TP>::dataMember_map_t *,
ClassType_body::dataMember_vector_t *,
typename MemberList_base<Obj_TP>::memberFunction_map_t *,
ClassType_body::memberFunction_vector_t *) { }
};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| MemberList |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
<Type comments>
- */
template <typename Obj_TP, const char *Name_TP
, typename T001 = VoidMember<Obj_TP>
, typename T002 = VoidMember<Obj_TP>
, typename T003 = VoidMember<Obj_TP>
, typename T004 = VoidMember<Obj_TP>
, typename T005 = VoidMember<Obj_TP>
, typename T006 = VoidMember<Obj_TP>
, typename T007 = VoidMember<Obj_TP>
, typename T008 = VoidMember<Obj_TP>
, typename T009 = VoidMember<Obj_TP>
, typename T010 = VoidMember<Obj_TP>
>
class MemberList : public MemberList_name_base<Obj_TP, Name_TP> {
/*--------------------------------------------------------------------------
Constructors, Initters, Assignments, and Destructors */
protected:
MemberList() :
member001()
, member002()
, member003()
, member004()
, member005()
, member006()
, member007()
, member008()
, member009()
, member010()
{
// XXX - It's probably possible to just have each member insert
// itself into the maps, then construct the vectors by
// traversing the maps after everyone is inserted.
member001.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member002.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member003.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member004.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member005.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member006.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member007.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member008.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member009.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
member010.registerMember(&this->m_dataMember_map, &this->m_dataMember_vector, &this->m_memberFunction_map, &this->m_memberFunction_vector);
}
private:
// Disallow these unless specifically allowed.
MemberList(const MemberList &);
MemberList &operator=(const MemberList &);
/*--------------------------------------------------------------------------
Data */
private:
T001 member001;
T002 member002;
T003 member003;
T004 member004;
T005 member005;
T006 member006;
T007 member007;
T008 member008;
T009 member009;
T010 member010;
};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| BaseInfo_base |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Used to store information about a base class. Templated just on the
bottom most class.
- */
template <typename Bottom_TP>
class BaseInfo_base {
public:
virtual Bottom_TP *downCast(const ObjHolder &) const = 0;
virtual void upCast(Bottom_TP *, ObjHolder *) const = 0;
};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| BaseInfo |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Used to store information about a base class. Contains functions for
casting.
- */
template <typename Bottom_TP, typename Base_TP>
class BaseInfo : public BaseInfo_base<Bottom_TP> {
typedef typename BaseList_base<Bottom_TP>::map_t map_t;
public:
// Constructor inserts this BaseInfo object into a map for finding
// BaseInfo objects to use for conversion. The map is on the base
// type. There is one map per bottom class.
BaseInfo(map_t *map) {
map->insert(typename map_t::value_type(&typeid(Base_TP), this));
}
virtual Bottom_TP *downCast(const ObjHolder &ph) const {
IXCR_DCDCL(const ObjHolder_tmpl<Base_TP> &, ph_b, ph);
return dynamic_cast<Bottom_TP *>(ph_b.ptr);
}
virtual void upCast(Bottom_TP *p, ObjHolder *ph) const {
IXCR_DCDCL(ObjHolder_tmpl<Base_TP> *, ph_b, ph);
ph_b->ptr = p;
}
};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| VoidBase |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Tag structure. This is used for some partial template specialization at
the base of the recursion.
- */
struct VoidBase {};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| BaseInfo<Bottom_TP, VoidBase> |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Partial specialization for no base present. This makes the BaseList class
above work correctly with the default template arguments.
- */
template <typename Bottom_TP>
class BaseInfo<Bottom_TP, VoidBase> : public BaseInfo_base<Bottom_TP> {
public:
BaseInfo(typename BaseList_base<Bottom_TP>::map_t *) {}
// These should never be called, because this BaseInfo should never
// appear in any map.
virtual Bottom_TP *downCast(const ObjHolder &ph) const {
ixcr_check(false); return 0; }
virtual void upCast(Bottom_TP *p, ObjHolder *ph) const {
ixcr_check(false); }
};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| Bases<Bot_TP, Der_TP, VoidBase, N> |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Partial specialization for base case of recursion.
- */
template <typename Bot_TP, typename Der_TP, int N>
class Bases<Bot_TP, Der_TP, VoidBase, N> { };
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| BaseList_base |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Holds the map from type_info * to BaseInfo objects.
- */
template <typename Bottom_TP>
class BaseList_base : public virtual ClassType_body {
public:
typedef std::map<const std::type_info *, BaseInfo_base<Bottom_TP> *,
TypeInfoCmp> map_t;
map_t m_base_info_map;
};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| BaseList |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
Used to split the list of bases out into separate Bases classes.
- */
template <typename Bottom_TP, typename Der_TP, typename B01_TP = VoidBase,
typename B02_TP = VoidBase >
class BaseList : public Bases<Bottom_TP, Der_TP, B01_TP, 1>,
public Bases<Bottom_TP, Der_TP, B02_TP, 2>,
public virtual BaseList_base<Bottom_TP> {
public:
BaseList()
: caster01(&this->m_base_info_map)
, caster02(&this->m_base_info_map)
{ }
protected:
BaseInfo<Bottom_TP, B01_TP> caster01;
BaseInfo<Bottom_TP, B02_TP> caster02;
};
/*-----------------------------------------------------------------------------\
|------------------------------------------------------------------------------|
| |
| ClassType_body_tmpl |
| |
|------------------------------------------------------------------------------|
\------------------------------------------------------------------------------/
<Type comments>
- */
template <typename Obj_TP>
class ClassType_body_tmpl
: public Members<Obj_TP>, public Bases<Obj_TP, Obj_TP, Obj_TP, 0>,
public virtual ClassType_body {
/*--------------------------------------------------------------------------
Constructors, Initters, Assignments, and Destructors */
public:
// The way tp_name is being used here is a bit convoluted. The
// name of the class should be quickly accessible to
// ClassType_body, so that no virtual function calls are needed to
// access it. The name is a const char * template parameter of
// Members<Obj_TP>. So this is made available through the tp_name
// static data member. Since no constructors are involved, the
// data member is valid without worrying about initialization
// order.
ClassType_body_tmpl()
: ClassType_body(this->tp_name, typeid(Obj_TP)) {}
private:
// Disallow these unless specifically allowed.
ClassType_body_tmpl(const ClassType_body_tmpl &);
ClassType_body_tmpl &operator=(const ClassType_body_tmpl &);
/*--------------------------------------------------------------------------
Methods */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -