CClassInfo.h
Go to the documentation of this file.
1 #ifndef istd_CClassInfo_included
2 #define istd_CClassInfo_included
3 
4 
5 // STL includes
6 #include <typeinfo>
7 
8 // Qt includes
9 #include <QtCore/QByteArray>
10 
11 // ACF includes
12 #include <istd/IPolymorphic.h>
13 
14 
15 namespace istd
16 {
17 
18 
22 class CClassInfo: virtual public istd::IPolymorphic
23 {
24 public:
25  CClassInfo();
26  explicit CClassInfo(const std::type_info& info);
27  explicit CClassInfo(const QByteArray& name);
28  explicit CClassInfo(const istd::IPolymorphic& object);
29 
34  bool IsValid() const;
39  const QByteArray& GetName() const;
40 
44  bool IsVoid() const;
45 
49  bool IsConst() const;
50 
54  CClassInfo GetConstCasted(bool enableConst = true) const;
55 
59  bool ConstCast(bool enableConst = true);
60 
64  bool IsTemplateClass() const;
69  int GetTemplateParamsCount() const;
73  CClassInfo GetTemplateParam(int paramIndex = 0) const;
74 
75  template <class C>
76  bool IsType() const;
77 
78  CClassInfo& operator=(const std::type_info& info);
79  CClassInfo& operator=(const CClassInfo& info);
80  bool operator==(const CClassInfo& info) const;
81  bool operator!=(const CClassInfo& info) const;
82  bool operator<(const CClassInfo& info) const;
83  bool operator>(const CClassInfo& info) const;
84 
85  // static methods
89  template <class C>
90  static CClassInfo GetInfo();
94  template <class C>
95  static QByteArray GetName();
99  static QByteArray GetName(const std::type_info& info);
103  static QByteArray GetName(const istd::IPolymorphic& object);
104 
108  static QByteArray GetUndecoratedName(const QByteArray& rawName);
109 
110 private:
111  QByteArray m_name;
112 };
113 
114 
115 // inline methods
116 
118 {
119 }
120 
121 
122 inline CClassInfo::CClassInfo(const std::type_info& info)
123 : m_name(GetName(info))
124 {
125 }
126 
127 
128 inline CClassInfo::CClassInfo(const QByteArray& name)
129 : m_name(GetUndecoratedName(name))
130 {
131 }
132 
133 
135 : m_name(GetUndecoratedName(typeid(object).name()))
136 {
137 }
138 
139 
140 inline bool CClassInfo::IsValid() const
141 {
142  return !m_name.isEmpty();
143 }
144 
145 
146 inline const QByteArray& CClassInfo::GetName() const
147 {
148  return m_name;
149 }
150 
151 
152 inline bool CClassInfo::IsVoid() const
153 {
154  return *this == istd::CClassInfo::GetInfo<void>();
155 }
156 
157 
158 template <class C>
159 inline bool CClassInfo::IsType() const
160 {
161  return m_name == GetName(typeid(C));
162 }
163 
164 
165 inline CClassInfo& CClassInfo::operator=(const std::type_info& info)
166 {
167  m_name = GetName(info);
168 
169  return *this;
170 }
171 
172 
174 {
175  m_name = info.m_name;
176 
177  return *this;
178 }
179 
180 
181 inline bool CClassInfo::operator==(const CClassInfo& info) const
182 {
183  return m_name == info.m_name;
184 }
185 
186 
187 inline bool CClassInfo::operator!=(const CClassInfo& info) const
188 {
189  return m_name != info.m_name;
190 }
191 
192 
193 inline bool CClassInfo::operator<(const CClassInfo& info) const
194 {
195  return m_name < info.m_name;
196 }
197 
198 
199 inline bool CClassInfo::operator>(const CClassInfo& info) const
200 {
201  return m_name > info.m_name;
202 }
203 
204 
205 // public static methods
206 
207 template <class C>
209 {
210  CClassInfo retVal(typeid(C));
211 
212  return retVal;
213 }
214 
215 
216 template <class C>
218 {
219  return GetUndecoratedName(typeid(C).name());
220 }
221 
222 
223 } // namespace istd
224 
225 
226 #endif // !istd_CClassInfo_included
227 
228 
bool IsConst() const
Check if this class information represents const class.
int GetTemplateParamsCount() const
Get number of template parameters if this class is template class.
bool IsType() const
Definition: CClassInfo.h:159
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition: CClassInfo.h:146
static QByteArray GetUndecoratedName(const QByteArray &rawName)
Get undecorated class name from raw name.
bool operator>(const CClassInfo &info) const
Definition: CClassInfo.h:199
CClassInfo & operator=(const std::type_info &info)
Definition: CClassInfo.h:165
bool operator!=(const CClassInfo &info) const
Definition: CClassInfo.h:187
bool IsValid() const
Check if this class info object is valid.
Definition: CClassInfo.h:140
CClassInfo GetConstCasted(bool enableConst=true) const
Get class with enabled or disabled const attribute.
bool operator==(const CClassInfo &info) const
Definition: CClassInfo.h:181
Base interface for all used interfaces and implementations.
Definition: IPolymorphic.h:17
bool ConstCast(bool enableConst=true)
Enable or disable const attribute.
bool IsTemplateClass() const
Check if this class information represents template class.
bool IsVoid() const
Check if this class information represents void type.
Definition: CClassInfo.h:152
static CClassInfo GetInfo()
Get class name defined as template parameter.
Definition: CClassInfo.h:208
bool operator<(const CClassInfo &info) const
Definition: CClassInfo.h:193
Represents platform independent type info and provide set of static class manipulation functions...
Definition: CClassInfo.h:22
CClassInfo GetTemplateParam(int paramIndex=0) const
Get class info of some template parameter if this class is template.

© 2007-2017 Witold Gantzke and Kirill Lepskiy