JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
demangle.hpp
Go to the documentation of this file.
1/** \file jsonv/demangle.hpp
2 *
3 * Copyright (c) 2015 by Travis Gockel. All rights reserved.
4 *
5 * This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
6 * as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
7 * version.
8 *
9 * \author Travis Gockel (travis@gockelhut.com)
10**/
11#pragma once
12
13#include <jsonv/config.hpp>
14#include <string_view>
15
16#include <functional>
17#include <string>
18
19namespace jsonv
20{
21
22/** \addtogroup Serialization
23 * \{
24**/
25
26/** Convert the input \a source from a mangled type into a human-friendly version. This is used by \c formats (and the
27 * associated serialization functions) to give more user-friendly names in type errors.
28 *
29 * \see demangle_function
30 * \see set_demangle_function
31**/
32JSONV_NODISCARD JSONV_PUBLIC std::string demangle(std::string_view source);
33
34/** Type of function used in setting a custom demangler.
35 *
36 * \see demangle
37 * \see set_demangle_function
38**/
39using demangle_function = std::function<std::string (std::string_view source)>;
40
41/** Sets the global demangle function. This controls the behavior of \c demangle -- the provided \a func will be called
42 * by \c demangle.
43 *
44 * \see demangle
45**/
47
48/** Resets the demangle function to the default.
49 *
50 * \see set_demangle_function
51**/
53
54/** Get the demangled type name of the current exception. This is meant to be called from `catch (...)` blocks to
55 * attempt to get more information about the exception type when it doesn't derive from a known entity.
56 *
57 * \returns The demangled type name of the current exception or "unknown" if this cannot be discovered. Failure to
58 * discover is not an error -- this can happen if the exception is foreign to C++ (it does not have a
59 * \c std::type_info implementation) or if discovery is not known for this platform.
60**/
62
63/** \} **/
64
65}
An adapter for enumeration types.
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
Definition config.hpp:121
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
Definition config.hpp:102
std::function< std::string(std::string_view source)> demangle_function
Type of function used in setting a custom demangler.
Definition demangle.hpp:39
JSONV_PUBLIC std::string demangle(std::string_view source)
Convert the input source from a mangled type into a human-friendly version.
JSONV_PUBLIC void reset_demangle_function()
Resets the demangle function to the default.
JSONV_PUBLIC void set_demangle_function(demangle_function func)
Sets the global demangle function.
JSONV_PUBLIC std::string current_exception_type_name()
Get the demangled type name of the current exception.