• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            visualfc

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              42 隨筆 :: 0 文章 :: 119 評(píng)論 :: 0 Trackbacks
            原創(chuàng) visualfc

            介紹一個(gè)通用c++ typeid實(shí)現(xiàn).

            主要功能:
                通用的typeid實(shí)現(xiàn),可以在VS60/VS2005以及mingw32下保證相同的類型名輸出.
                程序使用boost::type_traits來實(shí)現(xiàn),沒有使用內(nèi)置的typeid.不支持RTTI操作.

            項(xiàng)目地址:
                http://code.google.com/p/typeid

            程序例子:
            1.  vfc::type_id(100).name();    // output "int"
            2.  vfc::type_id_t<int>::name(); // output "int"
            3.  vfc::type_id_t<const int &>::name(); // output "int const &"

            4.  struct a 
            5.  {
            6.      const int * test(intconst char *);
            7.  };
            8.  VFC_MAKE_ID(a,0x2003);

            9.  vfc::type_id(&a::test).name(); //output  "int const * (a::*)(int,char const *)"
            主要類介紹:
               template<typename T>  vfc::type_id_t<>  獲取類型的typeid名
               template<typename T>  vfc::type_id(const T & t) 獲取變量的類型的type_id_t類型.

            主要函數(shù):
               type_id(100).std_name() 輸出 std::string 類型的name
               type_id(100).name()     輸出 const char * 類型的name

            定義類型:
               VFC_TYPE_ID(type,id) 實(shí)現(xiàn)類型的定義,type為類型,id為類型自定義數(shù)值標(biāo)識(shí)
            例: VFC_TYPE_ID(std::string,0x2001)


            下面給出一個(gè)完整的例子:  

            1. #include "vfc_type.h"
            2. struct a
            3. {
            4.     const int * test(int,int)
            5.     {
            6.         return NULL;
            7.     }

            8.     void test1() const
            9.     {
            10.     }
            11.     const char * test2(intintvolatile
            12.     {
            13.         return NULL;
            14.     }
            15.     const int & test3(int *, const char *) const volatile
            16.     {
            17.         static int i = 100;
            18.         return i;
            19.     }
            20. };

            21. void test(const char *, int k)
            22. {
            23. };

            24. VFC_TYPE_ID(a,0x2000);



            25. int main(int argc, char* argv[])
            26. {
            27.     typedef void (*T1)(void);
            28.     typedef int (*T2)(void);
            29.     typedef int (*T3)(int,int,int,int,int,int,int,int,int);
            30.     typedef const char * (*T4)(int &,int *,char **,char &,const int &);

            31.     typedef int U1;
            32.     typedef int U2[5];
            33.     typedef const int & U3;
            34.     typedef char U4[5][6][7];

            35.     printf("T1 type %s\n",vfc::type_id_t<T1>::name());
            36.     printf("T2 type %s\n",vfc::type_id_t<T2>::name());
            37.     printf("T3 type %s\n",vfc::type_id_t<T3>::name());
            38.     printf("T4 type %s\n",vfc::type_id_t<T4>::name());

            39.     printf("U1 type %s\n",vfc::type_id_t<U1>::name());
            40.     printf("U2 type %s\n",vfc::type_id_t<U2>::name());
            41.     printf("U3 type %s\n",vfc::type_id_t<U3>::name());
            42.     printf("U4 type %s\n",vfc::type_id_t<U4>::name());

            43.     printf("\'d\' type %s\n",vfc::type_id('d').name());
            44.     printf("100 type %s\n",vfc::type_id(100).name());
            45.     printf("100.0 type %s\n",vfc::type_id(100.0).name());
            46.     printf("\"str\" type %s\n",vfc::type_id("str").name());

            47.     const char * str = "ok";
            48.     printf("const char * str type %s\n",vfc::type_id(str).name());

            49.     a * pa;
            50.     printf("a type %s\n",vfc::type_id_t<a>::name());
            51.     printf("pa type %s\n",vfc::type_id(pa).name());
            52.     printf("a::test type %s\n",vfc::type_id(&a::test).name());
            53.     printf("a::test type %s\n",vfc::type_id(&a::test1).name());
            54.     printf("a::test type %s\n",vfc::type_id(&a::test2).name());
            55.     printf("a::test type %s\n",vfc::type_id(&a::test3).name());
            56.     printf("test %s\n",vfc::type_id(&test).name());

            57.     return 0;
            58. }
            在VS60,VS2005和mingw32下編譯得到相同輸出結(jié)果如下:
            1. T1 type void (*)()
            2. T2 type int (*)()
            3. T3 type int (*)(int,int,int,int,int,int,int,int,int)
            4. T4 type char const * (*)(int &,int *,char * *,char &,int const &)
            5. U1 type int
            6. U2 type int [5]
            7. U3 type int const &
            8. U4 type char [7] [6] [5]
            9. 'd' type char
            10. 100 type int
            11. 100.0 type double
            12. "str" type char [4]
            13. const char * str type char const *
            14. a type a
            15. pa type a *
            16. a::test type int const * (a::*)(int,int)
            17. a::test type void (a::*)()const
            18. a::test type char const * (a::*)(int,int)volatile
            19. a::test type int const & (a::*)(int *,char const *)const volatile
            20. test void (*)(char const *,int)
            posted on 2008-11-03 22:22 visualfc 閱讀(2253) 評(píng)論(2)  編輯 收藏 引用 所屬分類: C++

            評(píng)論

            # re: 通用C++ typeid實(shí)現(xiàn)(不支持RTTI) 2008-11-04 00:06 踏雪赤兔
            看了一下代碼,貌似不是線程安全的,呵呵~
            繼續(xù)努力!  回復(fù)  更多評(píng)論
              

            # re: 通用C++ typeid實(shí)現(xiàn)(不支持RTTI)[未登錄] 2008-11-04 07:58 visualfc
            謝謝提醒.
            看來為了線程安全, 可能得將type_id_t<T>::name()接口改為type_id_t<T>().name()了.  回復(fù)  更多評(píng)論
              

            亚洲综合熟女久久久30p| 久久精品人人槡人妻人人玩AV | 99久久www免费人成精品| 99久久精品国产毛片| 麻豆久久久9性大片| 国产精品免费福利久久| 激情五月综合综合久久69| 久久天天婷婷五月俺也去| 亚洲国产精品无码久久久不卡| 精品国产福利久久久| 亚洲精品国产自在久久| 国产精品久久久久影视不卡| 久久国产精品无| 亚洲伊人久久大香线蕉苏妲己| 久久国产AVJUST麻豆| 久久精品夜色噜噜亚洲A∨ | 久久福利片| 国产成人久久精品一区二区三区 | 久久精品国产亚洲av麻豆蜜芽| 91精品国产91热久久久久福利| 久久天天躁狠狠躁夜夜avapp| 久久精品二区| 久久国产乱子精品免费女| 97热久久免费频精品99| 中文字幕久久久久人妻| 久久毛片免费看一区二区三区| 狠狠色婷婷综合天天久久丁香| 欧美午夜精品久久久久免费视| 影音先锋女人AV鲁色资源网久久| 久久久久久久尹人综合网亚洲| 无码国内精品久久人妻蜜桃| 女同久久| 久久亚洲高清综合| 国内精品久久久久久麻豆| 国产—久久香蕉国产线看观看 | 国产精品激情综合久久| …久久精品99久久香蕉国产| 久久久久久国产精品免费无码 | 一级女性全黄久久生活片免费 | 免费一级欧美大片久久网| 久久久久婷婷|