introspection: add more types to type_string

This commit is contained in:
Danny Robson 2016-04-27 16:05:16 +10:00
parent 6e656444c6
commit b1eb9982d1
2 changed files with 12 additions and 9 deletions

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
* Copyright 2015-2016 Danny Robson <danny@nerdcruft.net>
*/
#include "introspection.hpp"
@ -35,4 +35,4 @@ constexpr char util::type_string<double>::value[];
constexpr char util::type_string<std::string>::value[];
constexpr char util::type_string<char*>::value[];
constexpr char util::type_string<char[]>::value[];
constexpr char util::type_string<const char*>::value[];

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
* Copyright 2015-2016 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_INTROSPECTION_HPP
@ -21,6 +21,7 @@
#include "./variadic.hpp"
#include <cstddef>
#include <cstdint>
#include <string>
#include <tuple>
@ -34,6 +35,9 @@ namespace util {
template <> struct type_string<bool> { static constexpr const char value[] = "bool"; };
template <> struct type_string<char> { static constexpr const char value[] = "char"; };
template <> struct type_string<void*> { static constexpr const char value[] = "void*"; };
template <> struct type_string< int8_t> { static constexpr const char value[] = "int8"; };
template <> struct type_string< int16_t> { static constexpr const char value[] = "int16"; };
template <> struct type_string< int32_t> { static constexpr const char value[] = "int32"; };
@ -48,19 +52,18 @@ namespace util {
template <> struct type_string<double > { static constexpr const char value[] = "float64"; };
template <> struct type_string<std::string> { static constexpr const char value[] = "string"; };
template <> struct type_string<char*> { static constexpr const char value[] = "string"; };
template <> struct type_string<char[]> { static constexpr const char value[] = "string"; };
template <> struct type_string<char*> { static constexpr const char value[] = "cstring"; };
template <> struct type_string<const char*> { static constexpr const char value[] = "cstring"; };
template <typename T>
constexpr
const char* type_string_v = type_string<T>::value;
template <typename T>
auto
const char*
to_string (void)
{
return type_string<T>::value;
}
{ return type_string_v<T>; }
///////////////////////////////////////////////////////////////////////////
/// Lists valid values of an enumeration