TSubelementStaticInfo.h
Go to the documentation of this file.
1 #ifndef icomp_TSubelementStaticInfo_included
2 #define icomp_TSubelementStaticInfo_included
3 
4 
5 // Qt includes
6 #include <QtCore/QByteArray>
7 #include <QtCore/QMap>
8 
9 // ACF includes
12 
13 
14 namespace icomp
15 {
16 
17 
18 template <class ComponentType>
20  virtual public IElementStaticInfo,
21  virtual public IComponentInterfaceExtractor
22 {
23 public:
24  typedef void* (*InterfaceExtractorPtr)(ComponentType& component);
25 
29  TSubelementStaticInfo(const QByteArray& name, CBaseComponentStaticInfo& owner);
30 
36  virtual void RegisterInterfaceExtractor(const QByteArray& interfaceName, InterfaceExtractorPtr extractorPtr);
37 
38  // reimplemented (icomp::IElementStaticInfo)
39  virtual Ids GetMetaIds(int metaGroupId) const;
40  virtual const IElementStaticInfo* GetSubelementInfo(const QByteArray& subcomponentId) const;
41 
42  // reimplemented (icomp::IComponentInterfaceExtractor)
43  virtual void* GetComponentInterface(
44  const istd::CClassInfo& interfaceType,
45  IComponent& component,
46  const QByteArray& subId) const;
47 
48 private:
49  typedef QMap<QByteArray, InterfaceExtractorPtr> InterfaceExtractors;
50  InterfaceExtractors m_interfaceExtractors;
51 };
52 
53 
54 template <class InterfaceType, class ComponentType>
56 {
57 public:
58  typedef void* (*InterfaceExtractorPtr)(ComponentType& component);
59  typedef InterfaceType* (*ExtractorPtr)(ComponentType& component);
60 
62  {
63  istd::CClassInfo interfaceInfo = istd::CClassInfo::GetInfo<InterfaceType>();
64 
65  staticInfo.RegisterInterfaceExtractor(interfaceInfo.GetName(), reinterpret_cast<InterfaceExtractorPtr>(extractorPtr));
66  }
67 };
68 
69 
70 // public methods
71 
72 template <class ComponentType>
74 {
75  owner.RegisterSubelementInfo(name, this);
76 }
77 
78 
79 template <class ComponentType>
80 void TSubelementStaticInfo<ComponentType>::RegisterInterfaceExtractor(const QByteArray& interfaceName, InterfaceExtractorPtr extractorPtr)
81 {
82  m_interfaceExtractors[interfaceName] = extractorPtr;
83 }
84 
85 
86 // reimplemented (icomp::IElementStaticInfo)
87 
88 template <class ComponentType>
90 {
91  Ids retVal;
92 
93  if (metaGroupId == MGI_INTERFACES){
94  for ( typename InterfaceExtractors::const_iterator iter = m_interfaceExtractors.begin();
95  iter != m_interfaceExtractors.end();
96  ++iter){
97  retVal.insert(iter.key());
98  }
99  }
100 
101  return retVal;
102 }
103 
104 
105 template <class ComponentType>
106 const IElementStaticInfo* TSubelementStaticInfo<ComponentType>::GetSubelementInfo(const QByteArray& /*subcomponentId*/) const
107 {
108  return NULL;
109 }
110 
111 
112 // reimplemented (icomp::IComponentInterfaceExtractor)
113 
114 template <class ComponentType>
116  const istd::CClassInfo& interfaceType,
117  IComponent& component,
118  const QByteArray& subId) const
119 {
120  ComponentType* nativeTypePtr = dynamic_cast<ComponentType*>(&component);
121  if ((nativeTypePtr != NULL) && subId.isEmpty()){
122  if (!interfaceType.IsValid() || interfaceType.IsVoid() || (interfaceType == CBaseComponentStaticInfo::s_compInterfaceType)){
123  return &component;
124  }
125 
126  typename InterfaceExtractors::ConstIterator foundIter = m_interfaceExtractors.constFind(interfaceType.GetName());
127  if (foundIter != m_interfaceExtractors.constEnd()){
128  InterfaceExtractorPtr extractorPtr = foundIter.value();
129 
130  return extractorPtr(*nativeTypePtr);
131  }
132 
133  if (interfaceType.IsConst()){
134  istd::CClassInfo nonConstType = interfaceType.GetConstCasted(false);
135 
136  foundIter = m_interfaceExtractors.constFind(nonConstType.GetName());
137  if (foundIter != m_interfaceExtractors.constEnd()){
138  InterfaceExtractorPtr extractorPtr = foundIter.value();
139 
140  return extractorPtr(*nativeTypePtr);
141  }
142  }
143  }
144 
145  return NULL;
146 }
147 
148 
149 } // namespace icomp
150 
151 
152 #endif // !icomp_TSubelementStaticInfo_included
153 
154 
bool IsConst() const
Check if this class information represents const class.
InterfaceType *(* ExtractorPtr)(ComponentType &component)
Main component interface.
Definition: IComponent.h:31
TSubelementStaticInfo(const QByteArray &name, CBaseComponentStaticInfo &owner)
Constructor attaching this subelement info to the component.
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition: CClassInfo.h:146
virtual Ids GetMetaIds(int metaGroupId) const
Get list of meta IDs associated with some meta key.
Provide extracting of some interface from component.
bool IsValid() const
Check if this class info object is valid.
Definition: CClassInfo.h:140
virtual void * GetComponentInterface(const istd::CClassInfo &interfaceType, IComponent &component, const QByteArray &subId) const
Extract instance implemented specified interface from some component.
CClassInfo GetConstCasted(bool enableConst=true) const
Get class with enabled or disabled const attribute.
virtual const IElementStaticInfo * GetSubelementInfo(const QByteArray &subcomponentId) const
Return number of interfaces for specific slot.
Standard implementation of static info for base component classes.
static istd::CClassInfo s_compInterfaceType
#define NULL
Definition: istd.h:64
bool IsVoid() const
Check if this class information represents void type.
Definition: CClassInfo.h:152
SubElementInterfaceRegistrator(TSubelementStaticInfo< ComponentType > &staticInfo, ExtractorPtr extractorPtr)
void *(* InterfaceExtractorPtr)(ComponentType &component)
virtual void RegisterSubelementInfo(const QByteArray &subcomponentId, const IElementStaticInfo *staticInfoPtr)
Register static subcomponent info.
Represents platform independent type info and provide set of static class manipulation functions...
Definition: CClassInfo.h:22
This interface provide static information about element meta info.
virtual void RegisterInterfaceExtractor(const QByteArray &interfaceName, InterfaceExtractorPtr extractorPtr)
Register interface ID for this static component info.
void *(* InterfaceExtractorPtr)(ComponentType &component)

© 2007-2017 Witold Gantzke and Kirill Lepskiy