typeName.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::typeName
26 
27 Description
28  Template function which returns the un-mangled name of a given type. Useful
29  for types which do not have a type() function or typeName static data
30  defined, and/or for printing information about complex templated object
31  structures.
32 
33 SourceFiles
34  typeName.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef typeName_H
39 #define typeName_H
40 
41 #include "word.H"
42 #include <typeinfo>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 //- Return the un-mangled name given the standard type info
52 template<class String>
53 String typeName(const std::type_info& info);
54 
55 //- Return the un-mangled name as a string, given the standard type info.
56 // Returns what CXXABI provides, with the 'Foam::' namespace removed.
57 template<>
58 string typeName<string>(const std::type_info& info);
59 
60 //- Return the un-mangled name as a word, given the standard type info.
61 // Returns what CXXABI provides, with the 'Foam::' namespace removed, with
62 // white-space removed (to make a valid word), and with names camel-cased
63 // where necessary (i.e., where white-space was delimiting).
64 template<>
65 word typeName<word>(const std::type_info& info);
66 
67 //- Return the un-mangled name of the given type
68 template<class Type, class String = string>
69 inline word typeName()
70 {
71  return typeName<String>(typeid(Type));
72 }
73 
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 
76 } // End namespace Foam
77 
78 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
79 
80 #endif
81 
82 // ************************************************************************* //
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
word typeName< word >(const std::type_info &info)
Return the un-mangled name as a word, given the standard type info.
string typeName< string >(const std::type_info &info)
Return the un-mangled name as a string, given the standard type info.