LCOV - code coverage report
Current view: top level - include/meta - typeDescription.hpp (source / functions) Coverage Total Hit
Test: mxlib Lines: 27.8 % 36 10
Test Date: 2026-08-30 22:23:37 Functions: 27.8 % 18 5

            Line data    Source code
       1              : /** \file typeDescription.hpp
       2              :  * \brief Type description helper classes
       3              :  * \ingroup utils_files
       4              :  * \author Jared R. Males (jaredmales@gmail.com)
       5              :  *
       6              :  */
       7              : 
       8              : //***********************************************************************//
       9              : // Copyright 2018 Jared R. Males (jaredmales@gmail.com)
      10              : //
      11              : // This file is part of mxlib.
      12              : //
      13              : // mxlib is free software: you can redistribute it and/or modify
      14              : // it under the terms of the GNU General Public License as published by
      15              : // the Free Software Foundation, either version 3 of the License, or
      16              : // (at your option) any later version.
      17              : //
      18              : // mxlib is distributed in the hope that it will be useful,
      19              : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      20              : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21              : // GNU General Public License for more details.
      22              : //
      23              : // You should have received a copy of the GNU General Public License
      24              : // along with mxlib.  If not, see <http://www.gnu.org/licenses/>.
      25              : //***********************************************************************//
      26              : 
      27              : #ifndef typeDescription_hpp
      28              : #define typeDescription_hpp
      29              : 
      30              : #include <string>
      31              : #include <vector>
      32              : 
      33              : namespace mx
      34              : {
      35              : namespace meta
      36              : {
      37              : 
      38              : /// Struct which contains static members describing a type.
      39              : /** Specializations are provided for the fundamental types, std::string, and std::vector of fundamental types.
      40              :  *
      41              :  * \ingroup meta
      42              :  */
      43              : template <typename T>
      44              : struct typeDescription
      45              : {
      46              :     typedef T type; ///< The type iteself.
      47              : 
      48              :     /// Returns a unique numeric code for this type.
      49            0 :     static constexpr int code()
      50              :     {
      51            0 :         return -1;
      52              :     }
      53              : 
      54              :     /// Returns the name of this type.
      55            0 :     static constexpr const char *name()
      56              :     {
      57            0 :         return "unknown";
      58              :     }
      59              : };
      60              : 
      61              : template <>
      62              : struct typeDescription<bool>
      63              : {
      64              :     typedef bool type;
      65              : 
      66            1 :     static constexpr int code()
      67              :     {
      68            1 :         return 0;
      69              :     }
      70              : 
      71              :     static constexpr const char *name()
      72              :     {
      73              :         return "bool";
      74              :     }
      75              : };
      76              : 
      77              : template <>
      78              : struct typeDescription<signed char>
      79              : {
      80              :     typedef signed char type;
      81              : 
      82            0 :     static constexpr int code()
      83              :     {
      84            0 :         return 1;
      85              :     }
      86              : 
      87              :     static constexpr const char *name()
      88              :     {
      89              :         return "signed char";
      90              :     }
      91              : };
      92              : 
      93              : template <>
      94              : struct typeDescription<unsigned char>
      95              : {
      96              :     typedef unsigned char type;
      97              : 
      98            0 :     static constexpr int code()
      99              :     {
     100            0 :         return 2;
     101              :     }
     102              : 
     103              :     static constexpr const char *name()
     104              :     {
     105              :         return "unsigned char";
     106              :     }
     107              : };
     108              : 
     109              : template <>
     110              : struct typeDescription<char>
     111              : {
     112              :     typedef char type;
     113              : 
     114            0 :     static constexpr int code()
     115              :     {
     116            0 :         return 3;
     117              :     }
     118              : 
     119              :     static constexpr const char *name()
     120              :     {
     121              :         return "char";
     122              :     }
     123              : };
     124              : 
     125              : template <>
     126              : struct typeDescription<wchar_t>
     127              : {
     128              :     typedef wchar_t type;
     129              : 
     130              :     static constexpr int code()
     131              :     {
     132              :         return 4;
     133              :     }
     134              : 
     135              :     static constexpr const char *name()
     136              :     {
     137              :         return "wchar_t";
     138              :     }
     139              : };
     140              : 
     141              : template <>
     142              : struct typeDescription<char16_t>
     143              : {
     144              :     typedef char16_t type;
     145              : 
     146              :     static constexpr int code()
     147              :     {
     148              :         return 5;
     149              :     }
     150              : 
     151              :     static constexpr const char *name()
     152              :     {
     153              :         return "char16_t";
     154              :     }
     155              : };
     156              : 
     157              : template <>
     158              : struct typeDescription<char32_t>
     159              : {
     160              :     typedef char32_t type;
     161              : 
     162              :     static constexpr int code()
     163              :     {
     164              :         return 6;
     165              :     }
     166              : 
     167              :     static constexpr const char *name()
     168              :     {
     169              :         return "char32_t";
     170              :     }
     171              : };
     172              : 
     173              : template <>
     174              : struct typeDescription<int>
     175              : {
     176              :     typedef int type;
     177              : 
     178           11 :     static constexpr int code()
     179              :     {
     180           11 :         return 7;
     181              :     }
     182              : 
     183              :     static constexpr const char *name()
     184              :     {
     185              :         return "int";
     186              :     }
     187              : };
     188              : 
     189              : template <>
     190              : struct typeDescription<unsigned int>
     191              : {
     192              :     typedef unsigned int type;
     193              : 
     194            0 :     static constexpr int code()
     195              :     {
     196            0 :         return 8;
     197              :     }
     198              : 
     199              :     static constexpr const char *name()
     200              :     {
     201              :         return "unsigned int";
     202              :     }
     203              : };
     204              : 
     205              : template <>
     206              : struct typeDescription<short int>
     207              : {
     208              :     typedef short int type;
     209              : 
     210            0 :     static constexpr int code()
     211              :     {
     212            0 :         return 9;
     213              :     }
     214              : 
     215              :     static constexpr const char *name()
     216              :     {
     217              :         return "short int";
     218              :     }
     219              : };
     220              : 
     221              : template <>
     222              : struct typeDescription<short unsigned int>
     223              : {
     224              :     typedef short unsigned int type;
     225              : 
     226            0 :     static constexpr int code()
     227              :     {
     228            0 :         return 10;
     229              :     }
     230              : 
     231              :     static constexpr const char *name()
     232              :     {
     233              :         return "short unsigned int";
     234              :     }
     235              : };
     236              : 
     237              : template <>
     238              : struct typeDescription<long int>
     239              : {
     240              :     typedef long int type;
     241              : 
     242            0 :     static constexpr int code()
     243              :     {
     244            0 :         return 11;
     245              :     }
     246              : 
     247              :     static constexpr const char *name()
     248              :     {
     249              :         return "long int";
     250              :     }
     251              : };
     252              : 
     253              : template <>
     254              : struct typeDescription<long unsigned int>
     255              : {
     256              :     typedef long unsigned int type;
     257              : 
     258            0 :     static constexpr int code()
     259              :     {
     260            0 :         return 12;
     261              :     }
     262              : 
     263              :     static constexpr const char *name()
     264              :     {
     265              :         return "long unsigned int";
     266              :     }
     267              : };
     268              : 
     269              : template <>
     270              : struct typeDescription<long long int>
     271              : {
     272              :     typedef long long int type;
     273              : 
     274            0 :     static constexpr int code()
     275              :     {
     276            0 :         return 13;
     277              :     }
     278              : 
     279              :     static constexpr const char *name()
     280              :     {
     281              :         return "long long int";
     282              :     }
     283              : };
     284              : 
     285              : template <>
     286              : struct typeDescription<long long unsigned int>
     287              : {
     288              :     typedef long long unsigned int type;
     289              : 
     290            0 :     static constexpr int code()
     291              :     {
     292            0 :         return 14;
     293              :     }
     294              : 
     295              :     static constexpr const char *name()
     296              :     {
     297              :         return "long long unsigned int";
     298              :     }
     299              : };
     300              : 
     301              : template <>
     302              : struct typeDescription<float>
     303              : {
     304              :     typedef float type;
     305              : 
     306            2 :     static constexpr int code()
     307              :     {
     308            2 :         return 15;
     309              :     }
     310              : 
     311              :     static constexpr const char *name()
     312              :     {
     313              :         return "float";
     314              :     }
     315              : };
     316              : 
     317              : template <>
     318              : struct typeDescription<double>
     319              : {
     320              :     typedef double type;
     321              : 
     322            1 :     static constexpr int code()
     323              :     {
     324            1 :         return 16;
     325              :     }
     326              : 
     327              :     static constexpr const char *name()
     328              :     {
     329              :         return "double";
     330              :     }
     331              : };
     332              : 
     333              : template <>
     334              : struct typeDescription<long double>
     335              : {
     336              :     typedef long double type;
     337              : 
     338            0 :     static constexpr int code()
     339              :     {
     340            0 :         return 17;
     341              :     }
     342              : 
     343              :     static constexpr const char *name()
     344              :     {
     345              :         return "long double";
     346              :     }
     347              : };
     348              : 
     349              : template <>
     350              : struct typeDescription<std::string>
     351              : {
     352              :     typedef std::string type;
     353              : 
     354            2 :     static constexpr int code()
     355              :     {
     356            2 :         return 100;
     357              :     }
     358              : 
     359              :     static constexpr const char *name()
     360              :     {
     361              :         return "std::string";
     362              :     }
     363              : };
     364              : 
     365              : template <>
     366              : struct typeDescription<std::vector<bool>>
     367              : {
     368              :     typedef std::vector<bool> type;
     369              : 
     370              :     static constexpr int code()
     371              :     {
     372              :         return 1000;
     373              :     }
     374              : 
     375              :     static constexpr const char *name()
     376              :     {
     377              :         return "std::vector<bool>";
     378              :     }
     379              : };
     380              : 
     381              : template <>
     382              : struct typeDescription<std::vector<signed char>>
     383              : {
     384              :     typedef std::vector<signed char> type;
     385              : 
     386              :     static constexpr int code()
     387              :     {
     388              :         return 1001;
     389              :     }
     390              : 
     391              :     static constexpr const char *name()
     392              :     {
     393              :         return "std::vector<signed char>";
     394              :     }
     395              : };
     396              : 
     397              : template <>
     398              : struct typeDescription<std::vector<unsigned char>>
     399              : {
     400              :     typedef std::vector<unsigned char> type;
     401              : 
     402              :     static constexpr int code()
     403              :     {
     404              :         return 1002;
     405              :     }
     406              : 
     407              :     static constexpr const char *name()
     408              :     {
     409              :         return "std::vector<unsigned char>";
     410              :     }
     411              : };
     412              : 
     413              : template <>
     414              : struct typeDescription<std::vector<char>>
     415              : {
     416              :     typedef std::vector<char> type;
     417              : 
     418              :     static constexpr int code()
     419              :     {
     420              :         return 1003;
     421              :     }
     422              : 
     423              :     static constexpr const char *name()
     424              :     {
     425              :         return "std::vector<char>";
     426              :     }
     427              : };
     428              : 
     429              : template <>
     430              : struct typeDescription<std::vector<wchar_t>>
     431              : {
     432              :     typedef std::vector<wchar_t> type;
     433              : 
     434              :     static constexpr int code()
     435              :     {
     436              :         return 1004;
     437              :     }
     438              : 
     439              :     static constexpr const char *name()
     440              :     {
     441              :         return "std::vector<wchar_t>";
     442              :     }
     443              : };
     444              : 
     445              : template <>
     446              : struct typeDescription<std::vector<char16_t>>
     447              : {
     448              :     typedef std::vector<char16_t> type;
     449              : 
     450              :     static constexpr int code()
     451              :     {
     452              :         return 1005;
     453              :     }
     454              : 
     455              :     static constexpr const char *name()
     456              :     {
     457              :         return "std::vector<char16_t>";
     458              :     }
     459              : };
     460              : 
     461              : template <>
     462              : struct typeDescription<std::vector<char32_t>>
     463              : {
     464              :     typedef std::vector<char32_t> type;
     465              : 
     466              :     static constexpr int code()
     467              :     {
     468              :         return 1006;
     469              :     }
     470              : 
     471              :     static constexpr const char *name()
     472              :     {
     473              :         return "std::vector<char32_t>";
     474              :     }
     475              : };
     476              : 
     477              : template <>
     478              : struct typeDescription<std::vector<int>>
     479              : {
     480              :     typedef std::vector<int> type;
     481              : 
     482              :     static constexpr int code()
     483              :     {
     484              :         return 1007;
     485              :     }
     486              : 
     487              :     static constexpr const char *name()
     488              :     {
     489              :         return "std::vector<int>";
     490              :     }
     491              : };
     492              : 
     493              : template <>
     494              : struct typeDescription<std::vector<unsigned int>>
     495              : {
     496              :     typedef std::vector<unsigned int> type;
     497              : 
     498              :     static constexpr int code()
     499              :     {
     500              :         return 1008;
     501              :     }
     502              : 
     503              :     static constexpr const char *name()
     504              :     {
     505              :         return "std::vector<unsigned int>";
     506              :     }
     507              : };
     508              : 
     509              : template <>
     510              : struct typeDescription<std::vector<short int>>
     511              : {
     512              :     typedef std::vector<short int> type;
     513              : 
     514              :     static constexpr int code()
     515              :     {
     516              :         return 1009;
     517              :     }
     518              : 
     519              :     static constexpr const char *name()
     520              :     {
     521              :         return "std::vector<short int>";
     522              :     }
     523              : };
     524              : 
     525              : template <>
     526              : struct typeDescription<std::vector<short unsigned int>>
     527              : {
     528              :     typedef std::vector<short unsigned int> type;
     529              : 
     530              :     static constexpr int code()
     531              :     {
     532              :         return 1010;
     533              :     }
     534              : 
     535              :     static constexpr const char *name()
     536              :     {
     537              :         return "std::vector<short unsigned int>";
     538              :     }
     539              : };
     540              : 
     541              : template <>
     542              : struct typeDescription<std::vector<long int>>
     543              : {
     544              :     typedef std::vector<long int> type;
     545              : 
     546              :     static constexpr int code()
     547              :     {
     548              :         return 1011;
     549              :     }
     550              : 
     551              :     static constexpr const char *name()
     552              :     {
     553              :         return "std::vector<long int>";
     554              :     }
     555              : };
     556              : 
     557              : template <>
     558              : struct typeDescription<std::vector<long unsigned int>>
     559              : {
     560              :     typedef std::vector<long unsigned int> type;
     561              : 
     562              :     static constexpr int code()
     563              :     {
     564              :         return 1012;
     565              :     }
     566              : 
     567              :     static constexpr const char *name()
     568              :     {
     569              :         return "std::vector<long unsigned int>";
     570              :     }
     571              : };
     572              : 
     573              : template <>
     574              : struct typeDescription<std::vector<long long int>>
     575              : {
     576              :     typedef std::vector<long long int> type;
     577              : 
     578              :     static constexpr int code()
     579              :     {
     580              :         return 1013;
     581              :     }
     582              : 
     583              :     static constexpr const char *name()
     584              :     {
     585              :         return "std::vector<long long int>";
     586              :     }
     587              : };
     588              : 
     589              : template <>
     590              : struct typeDescription<std::vector<long long unsigned int>>
     591              : {
     592              :     typedef std::vector<long long unsigned int> type;
     593              : 
     594              :     static constexpr int code()
     595              :     {
     596              :         return 1014;
     597              :     }
     598              : 
     599              :     static constexpr const char *name()
     600              :     {
     601              :         return "std::vector<long long unsigned int>";
     602              :     }
     603              : };
     604              : 
     605              : template <>
     606              : struct typeDescription<std::vector<float>>
     607              : {
     608              :     typedef std::vector<float> type;
     609              : 
     610              :     static constexpr int code()
     611              :     {
     612              :         return 1015;
     613              :     }
     614              : 
     615              :     static constexpr const char *name()
     616              :     {
     617              :         return "std::vector<float>";
     618              :     }
     619              : };
     620              : 
     621              : template <>
     622              : struct typeDescription<std::vector<double>>
     623              : {
     624              :     typedef std::vector<double> type;
     625              : 
     626              :     static constexpr int code()
     627              :     {
     628              :         return 1016;
     629              :     }
     630              : 
     631              :     static constexpr const char *name()
     632              :     {
     633              :         return "std::vector<double>";
     634              :     }
     635              : };
     636              : 
     637              : template <>
     638              : struct typeDescription<std::vector<long double>>
     639              : {
     640              :     typedef std::vector<long double> type;
     641              : 
     642              :     static constexpr int code()
     643              :     {
     644              :         return 1017;
     645              :     }
     646              : 
     647              :     static constexpr const char *name()
     648              :     {
     649              :         return "std::vector<long double>";
     650              :     }
     651              : };
     652              : 
     653              : template <>
     654              : struct typeDescription<std::vector<std::string>>
     655              : {
     656              :     typedef std::vector<std::string> type;
     657              : 
     658              :     static constexpr int code()
     659              :     {
     660              :         return 1100;
     661              :     }
     662              : 
     663              :     static constexpr const char *name()
     664              :     {
     665              :         return "std::vector<std::string>";
     666              :     }
     667              : };
     668              : 
     669              : // For additions:
     670              : /*template<>
     671              : struct typeDescription<>
     672              : {
     673              :    typedef  type;
     674              : 
     675              :    static  constexpr int code() { return  ;
     676              : 
     677              :    static constexpr const char * name(){ return "";}
     678              : };*/
     679              : 
     680              : } // namespace meta
     681              : } // namespace mx
     682              : 
     683              : #endif // typeDescription_hpp
        

Generated by: LCOV version 2.0-1