| QxOrm 1.4.8 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

get_class_name.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** https://www.qxorm.com/
    00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
    00005 **
    00006 ** This file is part of the QxOrm library
    00007 **
    00008 ** This software is provided 'as-is', without any express or implied
    00009 ** warranty. In no event will the authors be held liable for any
    00010 ** damages arising from the use of this software
    00011 **
    00012 ** Commercial Usage
    00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
    00014 ** accordance with the commercial license agreement provided with the
    00015 ** Software or, alternatively, in accordance with the terms contained in
    00016 ** a written agreement between you and Lionel Marty
    00017 **
    00018 ** GNU General Public License Usage
    00019 ** Alternatively, this file may be used under the terms of the GNU
    00020 ** General Public License version 3.0 as published by the Free Software
    00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
    00022 ** packaging of this file. Please review the following information to
    00023 ** ensure the GNU General Public License version 3.0 requirements will be
    00024 ** met : http://www.gnu.org/copyleft/gpl.html
    00025 **
    00026 ** If you are unsure which license is appropriate for your use, or
    00027 ** if you have questions regarding the use of this file, please contact :
    00028 ** contact@qxorm.com
    00029 **
    00030 ****************************************************************************/
    00031
    00032 #ifndef _QX_GET_CLASS_NAME_H_
    00033 #define _QX_GET_CLASS_NAME_H_
    00034
    00035 #ifdef _MSC_VER
    00036 #pragma once
    00037 #endif
    00038
    00046 #ifndef _QX_NO_RTTI
    00047 #include <typeinfo>
    00048 #endif // _QX_NO_RTTI
    00049
    00050 #include <QxTraits/remove_attr.h>
    00051
    00052 #define QX_REGISTER_CLASS_NAME_SEP_INF "<"
    00053 #define QX_REGISTER_CLASS_NAME_SEP_SUP ">"
    00054 #define QX_REGISTER_CLASS_NAME_SEP_NXT ", "
    00055
    00056 #define QX_REGISTER_CLASS_NAME_SEP_INF_XML_TAG "-"
    00057 #define QX_REGISTER_CLASS_NAME_SEP_SUP_XML_TAG "-"
    00058 #define QX_REGISTER_CLASS_NAME_SEP_NXT_XML_TAG "_"
    00059
    00060 #define QX_GET_CLASS_NAME(TYPE) \
    00061 qx::trait::get_class_name< qx::trait::remove_attr< TYPE >::type >::get()
    00062
    00063 #define QX_GET_CLASS_NAME_STD_STR(TYPE) \
    00064 std::string(qx::trait::get_class_name< qx::trait::remove_attr< TYPE >::type >::get())
    00065
    00066 #define QX_GET_CLASS_NAME_XML_TAG(TYPE) \
    00067 qx::trait::get_class_name< qx::trait::remove_attr< TYPE >::type >::get_xml_tag()
    00068
    00069 #define QX_GET_CLASS_NAME_XML_TAG_STD_STR(TYPE) \
    00070 std::string(qx::trait::get_class_name< qx::trait::remove_attr< TYPE >::type >::get_xml_tag())
    00071
    00072 #define QX_GET_CLASS_NAME_WITH_TYPENAME(TYPE) \
    00073 qx::trait::get_class_name< typename qx::trait::remove_attr< TYPE >::type >::get()
    00074
    00075 #define QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(TYPE) \
    00076 std::string(qx::trait::get_class_name< typename qx::trait::remove_attr< TYPE >::type >::get())
    00077
    00078 #define QX_GET_CLASS_NAME_XML_TAG_WITH_TYPENAME(TYPE) \
    00079 qx::trait::get_class_name< typename qx::trait::remove_attr< TYPE >::type >::get_xml_tag()
    00080
    00081 #define QX_GET_CLASS_NAME_XML_TAG_STD_STR_WITH_TYPENAME(TYPE) \
    00082 std::string(qx::trait::get_class_name< typename qx::trait::remove_attr< TYPE >::type >::get_xml_tag())
    00083
    00084 #define QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG() \
    00085 static inline const char * get_xml_tag() \
    00086 { \
    00087    static std::string result_xml; \
    00088    if (! result_xml.empty()) { return result_xml.c_str(); } \
    00089    QString tmp = get_class_name::get(); \
    00090    tmp.replace(QX_REGISTER_CLASS_NAME_SEP_INF, QX_REGISTER_CLASS_NAME_SEP_INF_XML_TAG); \
    00091    tmp.replace(QX_REGISTER_CLASS_NAME_SEP_SUP, QX_REGISTER_CLASS_NAME_SEP_SUP_XML_TAG); \
    00092    tmp.replace(QX_REGISTER_CLASS_NAME_SEP_NXT, QX_REGISTER_CLASS_NAME_SEP_NXT_XML_TAG); \
    00093    tmp.replace("::", "."); \
    00094    tmp.replace(" ", ""); \
    00095    result_xml = tmp.toLatin1().constData(); \
    00096    return result_xml.c_str(); \
    00097 }
    00098
    00099 #ifdef _QX_NO_RTTI
    00100 #define QX_REGISTER_CLASS_NAME_NO_RTTI(className) std::string(#className)
    00101 #endif // _QX_NO_RTTI
    00102
    00103 namespace qx {
    00104 namespace trait {
    00105
    00110 template <typename T>
    00111 struct get_class_name
    00112 {
    00113
    00114    static inline const char * get()
    00115    {
    00116       static std::string result;
    00117       if (! result.empty()) { return result.c_str(); }
    00118
    00119 #ifndef _QX_NO_RTTI
    00120       T * dummy = NULL; Q_UNUSED(dummy);
    00121       result = std::string(typeid(dummy).name());
    00122 #else // _QX_NO_RTTI
    00123       result = QX_REGISTER_CLASS_NAME_NO_RTTI(T);
    00124 #endif // _QX_NO_RTTI
    00125
    00126       qDebug("[QxOrm] Unable to define correct class name : '%s' => use macro 'QX_REGISTER_CLASS_NAME()' or 'QX_REGISTER_CLASS_NAME_TEMPLATE_X()'", result.c_str());
    00127       return result.c_str();
    00128    }
    00129
    00130    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG();
    00131
    00132 };
    00133
    00134 } // namespace trait
    00135 } // namespace qx
    00136
    00137 #define QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className) \
    00138 static std::string result; \
    00139 if (! result.empty()) { return result.c_str(); } \
    00140 result = std::string(#className);
    00141
    00142 #define QX_REGISTER_CLASS_NAME(className) \
    00143 namespace qx { namespace trait { \
    00144 template <> \
    00145 struct get_class_name< className > \
    00146 { \
    00147    static inline const char * get() \
    00148    { \
    00149       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00150       return result.c_str(); \
    00151    } \
    00152    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00153 }; \
    00154 } } // namespace qx::trait
    00155
    00156 #define QX_REGISTER_CLASS_NAME_TEMPLATE_1(className) \
    00157 namespace qx { namespace trait { \
    00158 template <typename T> \
    00159 struct get_class_name< className<T> > \
    00160 { \
    00161    static inline const char * get() \
    00162    { \
    00163       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00164       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00165       return result.c_str(); \
    00166    } \
    00167    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00168 }; \
    00169 } } // namespace qx::trait
    00170
    00171 #define QX_REGISTER_CLASS_NAME_TEMPLATE_2(className) \
    00172 namespace qx { namespace trait { \
    00173 template <typename T1, typename T2> \
    00174 struct get_class_name< className<T1, T2> > \
    00175 { \
    00176    static inline const char * get() \
    00177    { \
    00178       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00179       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00180       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00181       return result.c_str(); \
    00182    } \
    00183    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00184 }; \
    00185 } } // namespace qx::trait
    00186
    00187 #define QX_REGISTER_CLASS_NAME_TEMPLATE_3(className) \
    00188 namespace qx { namespace trait { \
    00189 template <typename T1, typename T2, typename T3> \
    00190 struct get_class_name< className<T1, T2, T3> > \
    00191 { \
    00192    static inline const char * get() \
    00193    { \
    00194       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00195       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00196       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00197       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T3) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00198       return result.c_str(); \
    00199    } \
    00200    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00201 }; \
    00202 } } // namespace qx::trait
    00203
    00204 #define QX_REGISTER_CLASS_NAME_TEMPLATE_4(className) \
    00205 namespace qx { namespace trait { \
    00206 template <typename T1, typename T2, typename T3, typename T4> \
    00207 struct get_class_name< className<T1, T2, T3, T4> > \
    00208 { \
    00209    static inline const char * get() \
    00210    { \
    00211       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00212       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00213       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00214       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T3) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00215       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T4) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00216       return result.c_str(); \
    00217    } \
    00218    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00219 }; \
    00220 } } // namespace qx::trait
    00221
    00222 #define QX_REGISTER_CLASS_NAME_TEMPLATE_5(className) \
    00223 namespace qx { namespace trait { \
    00224 template <typename T1, typename T2, typename T3, typename T4, typename T5> \
    00225 struct get_class_name< className<T1, T2, T3, T4, T5> > \
    00226 { \
    00227    static inline const char * get() \
    00228    { \
    00229       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00230       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00231       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00232       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T3) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00233       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T4) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00234       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T5) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00235       return result.c_str(); \
    00236    } \
    00237    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00238 }; \
    00239 } } // namespace qx::trait
    00240
    00241 #define QX_REGISTER_CLASS_NAME_TEMPLATE_6(className) \
    00242 namespace qx { namespace trait { \
    00243 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> \
    00244 struct get_class_name< className<T1, T2, T3, T4, T5, T6> > \
    00245 { \
    00246    static inline const char * get() \
    00247    { \
    00248       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00249       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00250       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00251       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T3) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00252       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T4) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00253       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T5) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00254       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T6) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00255       return result.c_str(); \
    00256    } \
    00257    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00258 }; \
    00259 } } // namespace qx::trait
    00260
    00261 #define QX_REGISTER_CLASS_NAME_TEMPLATE_7(className) \
    00262 namespace qx { namespace trait { \
    00263 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
    00264 struct get_class_name< className<T1, T2, T3, T4, T5, T6, T7> > \
    00265 { \
    00266    static inline const char * get() \
    00267    { \
    00268       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00269       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00270       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00271       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T3) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00272       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T4) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00273       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T5) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00274       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T6) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00275       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T7) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00276       return result.c_str(); \
    00277    } \
    00278    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00279 }; \
    00280 } } // namespace qx::trait
    00281
    00282 #define QX_REGISTER_CLASS_NAME_TEMPLATE_8(className) \
    00283 namespace qx { namespace trait { \
    00284 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
    00285 struct get_class_name< className<T1, T2, T3, T4, T5, T6, T7, T8> > \
    00286 { \
    00287    static inline const char * get() \
    00288    { \
    00289       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00290       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00291       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00292       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T3) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00293       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T4) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00294       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T5) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00295       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T6) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00296       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T7) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00297       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T8) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00298       return result.c_str(); \
    00299    } \
    00300    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00301 }; \
    00302 } } // namespace qx::trait
    00303
    00304 #define QX_REGISTER_CLASS_NAME_TEMPLATE_9(className) \
    00305 namespace qx { namespace trait { \
    00306 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> \
    00307 struct get_class_name< className<T1, T2, T3, T4, T5, T6, T7, T8, T9> > \
    00308 { \
    00309    static inline const char * get() \
    00310    { \
    00311       QX_REGISTER_CLASS_NAME_TEMPLATE_INIT(className); \
    00312       result += QX_REGISTER_CLASS_NAME_SEP_INF + QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T1) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00313       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T2) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00314       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T3) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00315       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T4) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00316       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T5) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00317       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T6) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00318       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T7) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00319       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T8) + QX_REGISTER_CLASS_NAME_SEP_NXT; \
    00320       result += QX_GET_CLASS_NAME_STD_STR_WITH_TYPENAME(T9) + QX_REGISTER_CLASS_NAME_SEP_SUP; \
    00321       return result.c_str(); \
    00322    } \
    00323    QX_GET_CLASS_NAME_IMPLEMENT_FCT_GET_XML_TAG(); \
    00324 }; \
    00325 } } // namespace qx::trait
    00326
    00327 #endif // _QX_GET_CLASS_NAME_H_