Merge pull request #74 from bitshares/jmj_issue_1271

Missing FC Typenames (core issue #1217)
This commit is contained in:
John M. Jones 2018-08-13 09:17:19 -05:00 committed by GitHub
commit 46ba4cca5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 1 deletions

View file

@ -2,10 +2,12 @@
#include <deque>
#include <map>
#include <set>
#include <vector>
#include <fc/string.hpp>
#include <fc/optional.hpp>
#include <fc/smart_ref_fwd.hpp>
#include <fc/container/flat_fwd.hpp>
#include <fc/container/deque_fwd.hpp>
@ -69,10 +71,36 @@ namespace fc {
return n.c_str();
}
};
template<typename E> struct get_typename< std::set<E> >
{
static const char* name()
{
static std::string n = std::string("std::set<") + std::string(get_typename<E>::name()) + std::string(">");
return n.c_str();
}
};
template<typename A, typename B> struct get_typename< std::pair<A,B> >
{
static const char* name()
{
static std::string n = std::string("std::pair<") + get_typename<A>::name() + "," + get_typename<B>::name() + ">";
return n.c_str();
}
};
template<typename T> struct get_typename< fc::smart_ref<T> >
{
static const char* name()
{
static std::string n = std::string("fc::smart_ref<") + get_typename<T>::name() + std::string(">");
return n.c_str();
}
};
struct signed_int;
struct unsigned_int;
struct variant_object;
template<> struct get_typename<signed_int> { static const char* name() { return "signed_int"; } };
template<> struct get_typename<unsigned_int> { static const char* name() { return "unsigned_int"; } };
template<> struct get_typename<variant_object> { static const char* name() { return "fc::variant_object"; } };
}

View file

@ -382,5 +382,46 @@ public:
s.visit( to_static_variant(ar[1], max_depth - 1) );
}
template<typename... T> struct get_typename { static const char* name() { return typeid(static_variant<T...>).name(); } };
template< typename... T > struct get_comma_separated_typenames;
template<>
struct get_comma_separated_typenames<>
{
static const char* names() { return ""; }
};
template< typename T >
struct get_comma_separated_typenames<T>
{
static const char* names()
{
static const std::string n = get_typename<T>::name();
return n.c_str();
}
};
template< typename T, typename... Ts >
struct get_comma_separated_typenames<T, Ts...>
{
static const char* names()
{
static const std::string n =
std::string( get_typename<T>::name() )+","+
std::string( get_comma_separated_typenames< Ts... >::names() );
return n.c_str();
}
};
template< typename... T >
struct get_typename< static_variant< T... > >
{
static const char* name()
{
static const std::string n = std::string( "fc::static_variant<" )
+ get_comma_separated_typenames<T...>::names()
+ ">";
return n.c_str();
}
};
} // namespace fc