git repos / blockattack-game

blame: source/code/Libs/include/cereal/details/util.hpp

normal view · raw

7a956470 sago007 2016-02-14 17:09 1
/*! \file util.hpp
7a956470 sago007 2016-02-14 17:09 2
    \brief Internal misc utilities
7a956470 sago007 2016-02-14 17:09 3
    \ingroup Internal */
7a956470 sago007 2016-02-14 17:09 4
/*
7a956470 sago007 2016-02-14 17:09 5
  Copyright (c) 2014, Randolph Voorhies, Shane Grant
7a956470 sago007 2016-02-14 17:09 6
  All rights reserved.
7a956470 sago007 2016-02-14 17:09 7
7a956470 sago007 2016-02-14 17:09 8
  Redistribution and use in source and binary forms, with or without
7a956470 sago007 2016-02-14 17:09 9
  modification, are permitted provided that the following conditions are met:
7a956470 sago007 2016-02-14 17:09 10
      * Redistributions of source code must retain the above copyright
7a956470 sago007 2016-02-14 17:09 11
        notice, this list of conditions and the following disclaimer.
7a956470 sago007 2016-02-14 17:09 12
      * Redistributions in binary form must reproduce the above copyright
7a956470 sago007 2016-02-14 17:09 13
        notice, this list of conditions and the following disclaimer in the
7a956470 sago007 2016-02-14 17:09 14
        documentation and/or other materials provided with the distribution.
7a956470 sago007 2016-02-14 17:09 15
      * Neither the name of cereal nor the
7a956470 sago007 2016-02-14 17:09 16
        names of its contributors may be used to endorse or promote products
7a956470 sago007 2016-02-14 17:09 17
        derived from this software without specific prior written permission.
7a956470 sago007 2016-02-14 17:09 18
7a956470 sago007 2016-02-14 17:09 19
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
7a956470 sago007 2016-02-14 17:09 20
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
7a956470 sago007 2016-02-14 17:09 21
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7a956470 sago007 2016-02-14 17:09 22
  DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
7a956470 sago007 2016-02-14 17:09 23
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7a956470 sago007 2016-02-14 17:09 24
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
7a956470 sago007 2016-02-14 17:09 25
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7a956470 sago007 2016-02-14 17:09 26
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7a956470 sago007 2016-02-14 17:09 27
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
7a956470 sago007 2016-02-14 17:09 28
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7a956470 sago007 2016-02-14 17:09 29
*/
7a956470 sago007 2016-02-14 17:09 30
#ifndef CEREAL_DETAILS_UTIL_HPP_
7a956470 sago007 2016-02-14 17:09 31
#define CEREAL_DETAILS_UTIL_HPP_
7a956470 sago007 2016-02-14 17:09 32
7a956470 sago007 2016-02-14 17:09 33
#include <typeinfo>
7a956470 sago007 2016-02-14 17:09 34
#include <string>
7a956470 sago007 2016-02-14 17:09 35
7a956470 sago007 2016-02-14 17:09 36
#ifdef _MSC_VER
7a956470 sago007 2016-02-14 17:09 37
namespace cereal
7a956470 sago007 2016-02-14 17:09 38
{
7a956470 sago007 2016-02-14 17:09 39
  namespace util
7a956470 sago007 2016-02-14 17:09 40
  {
7a956470 sago007 2016-02-14 17:09 41
    //! Demangles the type encoded in a string
7a956470 sago007 2016-02-14 17:09 42
    /*! @internal */
7a956470 sago007 2016-02-14 17:09 43
    inline std::string demangle( std::string const & name )
7a956470 sago007 2016-02-14 17:09 44
    { return name; }
7a956470 sago007 2016-02-14 17:09 45
7a956470 sago007 2016-02-14 17:09 46
    //! Gets the demangled name of a type
7a956470 sago007 2016-02-14 17:09 47
    /*! @internal */
7a956470 sago007 2016-02-14 17:09 48
    template <class T> inline
7a956470 sago007 2016-02-14 17:09 49
    std::string demangledName()
7a956470 sago007 2016-02-14 17:09 50
    { return typeid( T ).name(); }
7a956470 sago007 2016-02-14 17:09 51
  } // namespace util
7a956470 sago007 2016-02-14 17:09 52
} // namespace cereal
7a956470 sago007 2016-02-14 17:09 53
#else // clang or gcc
7a956470 sago007 2016-02-14 17:09 54
#include <cxxabi.h>
7a956470 sago007 2016-02-14 17:09 55
#include <cstdlib>
7a956470 sago007 2016-02-14 17:09 56
namespace cereal
7a956470 sago007 2016-02-14 17:09 57
{
7a956470 sago007 2016-02-14 17:09 58
  namespace util
7a956470 sago007 2016-02-14 17:09 59
  {
7a956470 sago007 2016-02-14 17:09 60
    //! Demangles the type encoded in a string
7a956470 sago007 2016-02-14 17:09 61
    /*! @internal */
7a956470 sago007 2016-02-14 17:09 62
    inline std::string demangle(std::string mangledName)
7a956470 sago007 2016-02-14 17:09 63
    {
7a956470 sago007 2016-02-14 17:09 64
      int status = 0;
7a956470 sago007 2016-02-14 17:09 65
      char *demangledName = nullptr;
7a956470 sago007 2016-02-14 17:09 66
      std::size_t len;
7a956470 sago007 2016-02-14 17:09 67
7a956470 sago007 2016-02-14 17:09 68
      demangledName = abi::__cxa_demangle(mangledName.c_str(), 0, &len, &status);
7a956470 sago007 2016-02-14 17:09 69
7a956470 sago007 2016-02-14 17:09 70
      std::string retName(demangledName);
7a956470 sago007 2016-02-14 17:09 71
      free(demangledName);
7a956470 sago007 2016-02-14 17:09 72
7a956470 sago007 2016-02-14 17:09 73
      return retName;
7a956470 sago007 2016-02-14 17:09 74
    }
7a956470 sago007 2016-02-14 17:09 75
7a956470 sago007 2016-02-14 17:09 76
    //! Gets the demangled name of a type
7a956470 sago007 2016-02-14 17:09 77
    /*! @internal */
7a956470 sago007 2016-02-14 17:09 78
    template<class T> inline
7a956470 sago007 2016-02-14 17:09 79
    std::string demangledName()
7a956470 sago007 2016-02-14 17:09 80
    { return demangle(typeid(T).name()); }
7a956470 sago007 2016-02-14 17:09 81
  }
7a956470 sago007 2016-02-14 17:09 82
} // namespace cereal
7a956470 sago007 2016-02-14 17:09 83
#endif // clang or gcc branch of _MSC_VER
7a956470 sago007 2016-02-14 17:09 84
#endif // CEREAL_DETAILS_UTIL_HPP_
1970-01-01 00:00 85