port to windows
This commit is contained in:
parent
0995ce7e31
commit
e33e78ce51
31 changed files with 207 additions and 242 deletions
|
|
@ -95,7 +95,7 @@ set( sources
|
||||||
setup_library( fc SOURCES ${sources} )
|
setup_library( fc SOURCES ${sources} )
|
||||||
|
|
||||||
setup_executable( json_rpc_test SOURCES tests/json_rpc_test.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ${Boost_DATE_TIME_LIBRARY})
|
setup_executable( json_rpc_test SOURCES tests/json_rpc_test.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ${Boost_DATE_TIME_LIBRARY})
|
||||||
setup_executable( ssh_test SOURCES tests/ssh.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ssh2 ${OPENSSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} z ${Boost_DATE_TIME_LIBRARY})
|
setup_executable( ssh_test SOURCES tests/ssh.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ssh2 ${OPENSSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${ZLIB_LIBRARY} ${ALL_OPENSSL_LIBRARIES} ${Boost_DATE_TIME_LIBRARY})
|
||||||
|
|
||||||
#add_executable( test_vec tests/vector_test.cpp )
|
#add_executable( test_vec tests/vector_test.cpp )
|
||||||
#target_link_libraries( test_vec fc ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} )
|
#target_link_libraries( test_vec fc ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} )
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace fc {
|
||||||
fc::string string()const;
|
fc::string string()const;
|
||||||
fc::string generic_string()const;
|
fc::string generic_string()const;
|
||||||
private:
|
private:
|
||||||
fwd<boost::filesystem::path,8> _p;
|
fwd<boost::filesystem::path,32> _p;
|
||||||
};
|
};
|
||||||
|
|
||||||
class directory_iterator {
|
class directory_iterator {
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ namespace fc {
|
||||||
mutable spin_yield_lock _spin_yield;
|
mutable spin_yield_lock _spin_yield;
|
||||||
thread* _blocked_thread;
|
thread* _blocked_thread;
|
||||||
time_point _timeout;
|
time_point _timeout;
|
||||||
fc::exception_ptr _except;
|
fc::exception_ptr _exceptp;
|
||||||
bool _canceled;
|
bool _canceled;
|
||||||
const char* _desc;
|
const char* _desc;
|
||||||
detail::completion_handler* _compl;
|
detail::completion_handler* _compl;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#ifndef FC_FWD_HPP_
|
#pragma once
|
||||||
#define FC_FWD_HPP_
|
|
||||||
#include <fc/aligned.hpp>
|
#include <fc/aligned.hpp>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
|
@ -44,4 +43,3 @@ class fwd {
|
||||||
|
|
||||||
} // namespace fc
|
} // namespace fc
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace fc {
|
||||||
~file_mapping();
|
~file_mapping();
|
||||||
private:
|
private:
|
||||||
friend class mapped_region;
|
friend class mapped_region;
|
||||||
fc::fwd<boost::interprocess::file_mapping,16> my;
|
fc::fwd<boost::interprocess::file_mapping,0x24> my;
|
||||||
};
|
};
|
||||||
class mapped_region {
|
class mapped_region {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -59,14 +59,14 @@ namespace fc {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ostream& operator<<( ostream& o, const T& v ) {
|
ostream& operator<<( ostream& o, const T& v ) {
|
||||||
auto str = fc::lexical_cast<fc::string>(v);
|
auto str = fc::lexical_cast<fc::string>(v);
|
||||||
o.write( str.c_str(), str.size() );
|
o.write( str.c_str(), static_cast<size_t>(str.size()) );
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
ostream& operator<<( ostream& o, const char* v );
|
ostream& operator<<( ostream& o, const char* v );
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ostream& operator<<( ostream& o, const fc::string& str ) {
|
ostream& operator<<( ostream& o, const fc::string& str ) {
|
||||||
o.write( str.c_str(), str.size() );
|
o.write( str.c_str(), static_cast<size_t>(str.size()) );
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace fc { namespace json {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct rpc_member {
|
struct rpc_member {
|
||||||
#if BOOST_NO_VARIADIC_TEMPLATES
|
#ifdef BOOST_NO_VARIADIC_TEMPLATES
|
||||||
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
|
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
|
||||||
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
|
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
|
||||||
static std::function<fc::future<R>( BOOST_PP_ENUM_PARAMS(n,A) ) > \
|
static std::function<fc::future<R>( BOOST_PP_ENUM_PARAMS(n,A) ) > \
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ namespace fc {
|
||||||
inline double to_double( double d ) { return d; }
|
inline double to_double( double d ) { return d; }
|
||||||
|
|
||||||
int64_t to_int64( const fc::string& s );
|
int64_t to_int64( const fc::string& s );
|
||||||
inline int64_t to_int64( double d ) { return d; }
|
inline int64_t to_int64( double d ) { return static_cast<int64_t>(d); }
|
||||||
inline int64_t to_int64( int64_t d ) { return d; }
|
inline int64_t to_int64( int64_t d ) { return d; }
|
||||||
|
|
||||||
uint64_t to_uint64( const fc::string& s );
|
uint64_t to_uint64( const fc::string& s );
|
||||||
inline uint64_t to_uint64( double d ) { return d; }
|
inline uint64_t to_uint64( double d ) { return static_cast<uint64_t>(d); }
|
||||||
inline uint64_t to_uint64( uint64_t d ) { return d; }
|
inline uint64_t to_uint64( uint64_t d ) { return d; }
|
||||||
|
|
||||||
fc::string to_string( double d );
|
fc::string to_string( double d );
|
||||||
|
|
@ -47,32 +47,33 @@ namespace fc {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<int64_t, R> { static uint64_t cast( const R& v ) { return to_int64( v ); } };
|
struct lexical_cast<int64_t, R> { static int64_t cast( const R& v ) { return static_cast<int64_t>(to_int64( v )); } };
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<int32_t, R> { static uint32_t cast( const R& v ) { return to_int64( v ); } };
|
struct lexical_cast<int32_t, R> { static int32_t cast( const R& v ) { return static_cast<int32_t>(to_int64( v )); } };
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<int16_t, R> { static uint16_t cast( const R& v ) { return to_int64( v ); } };
|
struct lexical_cast<int16_t, R> { static int16_t cast( const R& v ) { return static_cast<int16_t>(to_int64( v )); } };
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<int8_t, R> { static uint8_t cast( const R& v ) { return to_int64( v ); } };
|
struct lexical_cast<int8_t, R> { static int8_t cast( const R& v ) { return static_cast<int8_t>(to_int64( v )); } };
|
||||||
|
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<uint32_t, R> { static uint32_t cast( const R& v ) { return to_uint64( v ); } };
|
struct lexical_cast<uint32_t, R> { static uint32_t cast( const R& v ) { return static_cast<uint32_t>(to_uint64( v )); } };
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<uint16_t, R> { static uint16_t cast( const R& v ) { return to_uint64( v ); } };
|
struct lexical_cast<uint16_t, R> { static uint16_t cast( const R& v ) { return static_cast<uint16_t>(to_uint64( v )); } };
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<uint8_t, R> { static uint8_t cast( const R& v ) { return to_uint64( v ); } };
|
struct lexical_cast<uint8_t, R> { static uint8_t cast( const R& v ) { return static_cast<uint8_t>(to_uint64( v )); } };
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<bool, R> { static bool cast( const R& v ) { return v; } };
|
struct lexical_cast<bool, R> { static bool cast( const R& v ) { return v != 0; } };
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct lexical_cast<char, fc::string> { static bool cast( const fc::string& v ) { return v[0]; } };// TODO: check string len
|
struct lexical_cast<char, fc::string> { static char cast( const fc::string& v )
|
||||||
|
{ return v[0]; } };// TODO: check string len
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct lexical_cast<bool, fc::string> { static bool cast( const fc::string& v ) { return v == "true"; } };
|
struct lexical_cast<bool, fc::string> { static bool cast( const fc::string& v ) { return v == "true"; } };
|
||||||
|
|
@ -81,7 +82,7 @@ namespace fc {
|
||||||
struct lexical_cast<fc::string,bool> { static fc::string cast( const bool& v ) { return v ? "true" : "false";} };
|
struct lexical_cast<fc::string,bool> { static fc::string cast( const bool& v ) { return v ? "true" : "false";} };
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
struct lexical_cast<float, R> { static float cast( const R& v ) { return to_double( v ); } };
|
struct lexical_cast<float, R> { static float cast( const R& v ) { return static_cast<float>(to_double( v )); } };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
//#include <fc/function.hpp>
|
//#include <fc/function.hpp>
|
||||||
#include <fc/future.hpp>
|
#include <fc/future.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <boost/config.hpp>
|
||||||
#include <boost/preprocessor/repeat.hpp>
|
#include <boost/preprocessor/repeat.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
|
|
@ -12,7 +13,7 @@ namespace fc {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct identity_member {
|
struct identity_member {
|
||||||
#if BOOST_NO_VARIADIC_TEMPLATES
|
#ifdef BOOST_NO_VARIADIC_TEMPLATES
|
||||||
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
|
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
|
||||||
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
|
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
|
||||||
static std::function<R( BOOST_PP_ENUM_PARAMS(n,A) ) > \
|
static std::function<R( BOOST_PP_ENUM_PARAMS(n,A) ) > \
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,8 @@ struct reflector{
|
||||||
#endif
|
#endif
|
||||||
//#include <boost/typeof/typeof.hpp>
|
//#include <boost/typeof/typeof.hpp>
|
||||||
#define FC_REFLECT_VISIT_MEMBER( r, visitor, elem ) \
|
#define FC_REFLECT_VISIT_MEMBER( r, visitor, elem ) \
|
||||||
visitor.TEMPLATE operator()<decltype(((type*)0)->elem), type, &type::elem>( BOOST_PP_STRINGIZE(elem) );
|
|
||||||
|
// visitor.TEMPLATE operator()<decltype(((type*)0)->elem), type, &type::elem>( BOOST_PP_STRINGIZE(elem) );
|
||||||
|
|
||||||
|
|
||||||
#define FC_REFLECT_BASE_MEMBER_COUNT( r, OP, elem ) \
|
#define FC_REFLECT_BASE_MEMBER_COUNT( r, OP, elem ) \
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ shared_impl<T>::shared_impl( shared_impl<T>&& u ):_impl(fc::move(u._impl)){}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
shared_impl<T>& shared_impl<T>::operator=( shared_impl<T>&& u ) {
|
shared_impl<T>& shared_impl<T>::operator=( shared_impl<T>&& u ) {
|
||||||
fc::swap(_impl,u._impl);
|
fc_swap(_impl,u._impl);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -46,7 +46,7 @@ TYPE::TYPE( A1&& a1, A2&& a2 ) \
|
||||||
:my( new typename fc::shared_impl<TYPE>::impl( fc::forward<A1>(a1), fc::forward<A2>(a2) ) ){}\
|
:my( new typename fc::shared_impl<TYPE>::impl( fc::forward<A1>(a1), fc::forward<A2>(a2) ) ){}\
|
||||||
template<typename A1,typename A2, typename A3> \
|
template<typename A1,typename A2, typename A3> \
|
||||||
TYPE::TYPE( A1&& a1, A2&& a2, A3&& a3 ) \
|
TYPE::TYPE( A1&& a1, A2&& a2, A3&& a3 ) \
|
||||||
:my( new typename fc::shared_impl<TYPE>::impl( fc::forward<A1>(a1), fc::forward<A2>(a2), fc::forward<A3>(a3) ) ){}\
|
:my( new fc::shared_impl<TYPE>::impl( fc::forward<A1>(a1), fc::forward<A2>(a2), fc::forward<A3>(a3) ) ){}\
|
||||||
TYPE::TYPE( shared_impl<TYPE>::impl* m ) \
|
TYPE::TYPE( shared_impl<TYPE>::impl* m ) \
|
||||||
:my(m){}\
|
:my(m){}\
|
||||||
TYPE::TYPE( TYPE* c )\
|
TYPE::TYPE( TYPE* c )\
|
||||||
|
|
@ -56,7 +56,7 @@ TYPE::TYPE( TYPE&& c )\
|
||||||
TYPE::TYPE( const TYPE& c )\
|
TYPE::TYPE( const TYPE& c )\
|
||||||
:my(c.my){}\
|
:my(c.my){}\
|
||||||
TYPE::TYPE() \
|
TYPE::TYPE() \
|
||||||
:my( new typename fc::shared_impl<TYPE>::impl( ) ){}\
|
:my( new fc::shared_impl<TYPE>::impl( ) ){}\
|
||||||
TYPE::~TYPE(){}\
|
TYPE::~TYPE(){}\
|
||||||
bool TYPE::operator !()const { return !my; }\
|
bool TYPE::operator !()const { return !my; }\
|
||||||
TYPE& TYPE::operator = ( const TYPE& c ) {\
|
TYPE& TYPE::operator = ( const TYPE& c ) {\
|
||||||
|
|
@ -64,11 +64,11 @@ TYPE& TYPE::operator = ( const TYPE& c ) {\
|
||||||
return *this;\
|
return *this;\
|
||||||
}\
|
}\
|
||||||
TYPE& TYPE::operator = ( TYPE&& c ) {\
|
TYPE& TYPE::operator = ( TYPE&& c ) {\
|
||||||
fc::swap( my._impl, c.my._impl );\
|
fc_swap( my._impl, c.my._impl );\
|
||||||
return *this;\
|
return *this;\
|
||||||
}\
|
}\
|
||||||
TYPE& TYPE::operator = ( TYPE* c ) {\
|
TYPE& TYPE::operator = ( TYPE* c ) {\
|
||||||
fc::swap( my._impl, c->my._impl );\
|
fc_swap( my._impl, c->my._impl );\
|
||||||
delete c;\
|
delete c;\
|
||||||
return *this;\
|
return *this;\
|
||||||
} \
|
} \
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ namespace fc {
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct shared_impl {
|
struct shared_impl {
|
||||||
struct impl;
|
class impl;
|
||||||
impl& operator* ()const;
|
impl& operator* ()const;
|
||||||
impl* operator-> ()const;
|
impl* operator-> ()const;
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ namespace fc {
|
||||||
|
|
||||||
~shared_impl();
|
~shared_impl();
|
||||||
|
|
||||||
fc::shared_ptr<shared_impl::impl> _impl;
|
fc::shared_ptr<typename shared_impl<T>::impl> _impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,11 @@ namespace fc {
|
||||||
|
|
||||||
shared_ptr& operator=(const shared_ptr& p ) {
|
shared_ptr& operator=(const shared_ptr& p ) {
|
||||||
shared_ptr tmp(p);
|
shared_ptr tmp(p);
|
||||||
fc::swap(tmp._ptr,_ptr);
|
fc_swap(tmp._ptr,_ptr);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
shared_ptr& operator=(shared_ptr&& p ) {
|
shared_ptr& operator=(shared_ptr&& p ) {
|
||||||
fc::swap(_ptr,p._ptr);
|
fc_swap(_ptr,p._ptr);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
T& operator* ()const { return *_ptr; }
|
T& operator* ()const { return *_ptr; }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef _FC_STRING_HPP_
|
#pragma once
|
||||||
#define _FC_STRING_HPP_
|
|
||||||
#include <fc/utility.hpp>
|
#include <fc/utility.hpp>
|
||||||
|
#include <fc/fwd.hpp>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -13,10 +13,10 @@ namespace std {
|
||||||
struct char_traits;
|
struct char_traits;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct allocator;
|
class allocator;
|
||||||
|
|
||||||
template<class Char, class Traits, class Allocator>
|
template<class Char, class Traits, class Allocator>
|
||||||
struct basic_string;
|
class basic_string;
|
||||||
|
|
||||||
typedef basic_string<char, char_traits<char>, allocator<char> > string;
|
typedef basic_string<char, char_traits<char>, allocator<char> > string;
|
||||||
}
|
}
|
||||||
|
|
@ -85,9 +85,8 @@ namespace fc {
|
||||||
fc::string substr( int32_t start, int32_t len = 0x7fffffff );
|
fc::string substr( int32_t start, int32_t len = 0x7fffffff );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void* my;
|
fc::fwd<std::string,32> my;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FC
|
} // namespace FC
|
||||||
|
|
||||||
#endif // _FC_STRING_HPP_
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace fc {
|
||||||
private:
|
private:
|
||||||
friend class tcp_server;
|
friend class tcp_server;
|
||||||
class impl;
|
class impl;
|
||||||
fc::fwd<impl,32> my;
|
fc::fwd<impl,0x44> my;
|
||||||
};
|
};
|
||||||
|
|
||||||
class tcp_server {
|
class tcp_server {
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ namespace fc {
|
||||||
template<typename V>
|
template<typename V>
|
||||||
void visit( V&& v)const{};
|
void visit( V&& v)const{};
|
||||||
};
|
};
|
||||||
template<typename Functor, typename Tuple>
|
template<typename Functor>
|
||||||
auto call_fused( Functor f, Tuple&& t ) -> decltype( f( ) ) {
|
auto call_fused( Functor f, const tuple<>& t ) -> decltype( f( ) ) {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,13 +72,13 @@ namespace fc {
|
||||||
typedef fc::false_type type;
|
typedef fc::false_type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define RREF_PARAMS(z,n,data) BOOST_PP_CAT(AA,n)&& BOOST_PP_CAT(a,n)
|
#define RREF_PARAMS(z,n,data) BOOST_PP_CAT(AA,n)&& BOOST_PP_CAT(p,n)
|
||||||
#define ILIST_PARAMS(z,n,data) BOOST_PP_CAT(a,n)( fc::forward<BOOST_PP_CAT(AA,n)>( BOOST_PP_CAT(a,n) ) )
|
#define ILIST_PARAMS(z,n,data) BOOST_PP_CAT(a,n)( fc::forward<BOOST_PP_CAT(AA,n)>( BOOST_PP_CAT(p,n) ) )
|
||||||
#define ILIST_PARAMS_COPY(z,n,data) BOOST_PP_CAT(a,n)( t.BOOST_PP_CAT(a,n) )
|
#define ILIST_PARAMS_COPY(z,n,data) BOOST_PP_CAT(a,n)( t.BOOST_PP_CAT(a,n) )
|
||||||
#define VISIT_PARAMS(z,n,data) v(BOOST_PP_CAT(a,n));
|
#define VISIT_PARAMS(z,n,data) v(BOOST_PP_CAT(a,n));
|
||||||
#define LIST_MEMBERS_ON(z,n,data) data.BOOST_PP_CAT(a,n)
|
#define LIST_MEMBERS_ON(z,n,data) data.BOOST_PP_CAT(a,n)
|
||||||
#define DEDUCE_MEMBERS(z,n,data) typename fc::deduce<BOOST_PP_CAT(AA,n)>::type
|
#define DEDUCE_MEMBERS(z,n,data) typename fc::deduce<BOOST_PP_CAT(AA,n)>::type
|
||||||
#define FORWARD_PARAMS(z,n,data) fc::forward<BOOST_PP_CAT(AA,n)>(BOOST_PP_CAT(a,n))
|
#define FORWARD_PARAMS(z,n,data) fc::forward<BOOST_PP_CAT(AA,n)>(BOOST_PP_CAT(p,n))
|
||||||
#define MEM_PARAMS(z,n,data) BOOST_PP_CAT(A,n) BOOST_PP_CAT(a,n);
|
#define MEM_PARAMS(z,n,data) BOOST_PP_CAT(A,n) BOOST_PP_CAT(a,n);
|
||||||
#define TUPLE(z,n,unused) \
|
#define TUPLE(z,n,unused) \
|
||||||
template<BOOST_PP_ENUM_PARAMS( n, typename A)> \
|
template<BOOST_PP_ENUM_PARAMS( n, typename A)> \
|
||||||
|
|
@ -87,6 +87,7 @@ namespace fc {
|
||||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||||
tuple( BOOST_PP_ENUM(n, RREF_PARAMS, unused ) )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS,unused){} \
|
tuple( BOOST_PP_ENUM(n, RREF_PARAMS, unused ) )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS,unused){} \
|
||||||
tuple( const tuple& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
|
tuple( const tuple& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
|
||||||
|
tuple( tuple& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
|
||||||
tuple( tuple&& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
|
tuple( tuple&& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
|
||||||
tuple(){}\
|
tuple(){}\
|
||||||
template<typename V>\
|
template<typename V>\
|
||||||
|
|
@ -99,8 +100,13 @@ namespace fc {
|
||||||
tuple<BOOST_PP_ENUM_PARAMS(n,AA)> make_tuple( BOOST_PP_ENUM( n, RREF_PARAMS, unused) ) { \
|
tuple<BOOST_PP_ENUM_PARAMS(n,AA)> make_tuple( BOOST_PP_ENUM( n, RREF_PARAMS, unused) ) { \
|
||||||
return tuple<BOOST_PP_ENUM_PARAMS(n,AA)>( BOOST_PP_ENUM( n, FORWARD_PARAMS,unused ) ); \
|
return tuple<BOOST_PP_ENUM_PARAMS(n,AA)>( BOOST_PP_ENUM( n, FORWARD_PARAMS,unused ) ); \
|
||||||
} \
|
} \
|
||||||
template<typename Functor, typename Tuple> \
|
template<typename Functor, BOOST_PP_ENUM_PARAMS(n,typename AA)> \
|
||||||
auto call_fused( Functor f, Tuple&& t ) \
|
auto call_fused( Functor f, tuple<BOOST_PP_ENUM_PARAMS(n,AA)>& t ) \
|
||||||
|
-> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \
|
||||||
|
return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \
|
||||||
|
} \
|
||||||
|
template<typename Functor, BOOST_PP_ENUM_PARAMS(n,typename AA)> \
|
||||||
|
auto call_fused( Functor f, const tuple<BOOST_PP_ENUM_PARAMS(n,AA)>& t ) \
|
||||||
-> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \
|
-> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \
|
||||||
return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \
|
return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \
|
||||||
} \
|
} \
|
||||||
|
|
@ -113,7 +119,7 @@ namespace fc {
|
||||||
typedef fc::tuple<BOOST_PP_ENUM( n, DEDUCE_MEMBERS,unused)> type; \
|
typedef fc::tuple<BOOST_PP_ENUM( n, DEDUCE_MEMBERS,unused)> type; \
|
||||||
};
|
};
|
||||||
|
|
||||||
BOOST_PP_REPEAT_FROM_TO( 1, 8, TUPLE, unused )
|
BOOST_PP_REPEAT_FROM_TO( 1, 4, TUPLE, unused )
|
||||||
|
|
||||||
|
|
||||||
#undef FORWARD_PARAMS
|
#undef FORWARD_PARAMS
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,12 @@ namespace fc {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const T& min( const T& a, const T& b ) { return a < b ? a: b; }
|
const T& min( const T& a, const T& b ) { return a < b ? a: b; }
|
||||||
|
|
||||||
|
}
|
||||||
|
// outside of namespace fc becuase of VC++ conflict with std::swap
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void swap( T& a, T& b ) {
|
void fc_swap( T& a, T& b ) {
|
||||||
T tmp = fc::move(a);
|
T tmp = fc::move(a);
|
||||||
a = fc::move(b);
|
a = fc::move(b);
|
||||||
b = fc::move(tmp);
|
b = fc::move(tmp);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif // _FC_UTILITY_HPP_
|
#endif // _FC_UTILITY_HPP_
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ namespace fc {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
value& operator=( T&& v ) {
|
value& operator=( T&& v ) {
|
||||||
value tmp(fc::forward<T>(v) );
|
value tmp(fc::forward<T>(v) );
|
||||||
fc::swap(*this,tmp);
|
fc_swap(*this,tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace fc {
|
||||||
virtual void operator()( const uint64_t& v ){ m_out = fc::numeric_cast<T>(v); }
|
virtual void operator()( const uint64_t& v ){ m_out = fc::numeric_cast<T>(v); }
|
||||||
virtual void operator()( const float& v ){ m_out = fc::numeric_cast<T>(v); }
|
virtual void operator()( const float& v ){ m_out = fc::numeric_cast<T>(v); }
|
||||||
virtual void operator()( const double& v ){ m_out = fc::numeric_cast<T>(v); }
|
virtual void operator()( const double& v ){ m_out = fc::numeric_cast<T>(v); }
|
||||||
virtual void operator()( const bool& v ){ m_out = fc::numeric_cast<T>(v); }
|
virtual void operator()( const bool& v ){ m_out = v; }
|
||||||
virtual void operator()( const fc::string& v ) { m_out = fc::lexical_cast<T>(v); }
|
virtual void operator()( const fc::string& v ) { m_out = fc::lexical_cast<T>(v); }
|
||||||
virtual void operator()( const value::object& ) { FC_THROW_MSG("bad cast"); }
|
virtual void operator()( const value::object& ) { FC_THROW_MSG("bad cast"); }
|
||||||
virtual void operator()( const value::array& ) { FC_THROW_MSG("bad cast"); }
|
virtual void operator()( const value::array& ) { FC_THROW_MSG("bad cast"); }
|
||||||
|
|
@ -36,6 +36,28 @@ namespace fc {
|
||||||
private:
|
private:
|
||||||
T& m_out;
|
T& m_out;
|
||||||
};
|
};
|
||||||
|
template<>
|
||||||
|
struct cast_visitor<bool> : value::const_visitor {
|
||||||
|
cast_visitor( bool& out )
|
||||||
|
:m_out(out){}
|
||||||
|
virtual void operator()( const int8_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const int16_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const int32_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const int64_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const uint8_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const uint16_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const uint32_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const uint64_t& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const float& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const double& v ){ m_out = v != 0; }
|
||||||
|
virtual void operator()( const bool& v ){ m_out = v; }
|
||||||
|
virtual void operator()( const fc::string& v ) { m_out = !(v != "true"); }
|
||||||
|
virtual void operator()( const value::object& ) { FC_THROW_MSG("bad cast"); }
|
||||||
|
virtual void operator()( const value::array& ) { FC_THROW_MSG("bad cast"); }
|
||||||
|
virtual void operator()( ) { FC_THROW_MSG("bad cast"); }
|
||||||
|
private:
|
||||||
|
bool& m_out;
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct cast_visitor<fc::string> : value::const_visitor {
|
struct cast_visitor<fc::string> : value::const_visitor {
|
||||||
|
|
@ -51,7 +73,7 @@ namespace fc {
|
||||||
virtual void operator()( const uint64_t& v ){ m_out = fc::lexical_cast<fc::string>(v); }
|
virtual void operator()( const uint64_t& v ){ m_out = fc::lexical_cast<fc::string>(v); }
|
||||||
virtual void operator()( const float& v ){ m_out = fc::lexical_cast<fc::string>(v); }
|
virtual void operator()( const float& v ){ m_out = fc::lexical_cast<fc::string>(v); }
|
||||||
virtual void operator()( const double& v ){ m_out = fc::lexical_cast<fc::string>(v); }
|
virtual void operator()( const double& v ){ m_out = fc::lexical_cast<fc::string>(v); }
|
||||||
virtual void operator()( const bool& v ){ m_out = fc::lexical_cast<fc::string>(v); }
|
virtual void operator()( const bool& v ){ m_out = v != 0 ? "true" : "false"; }
|
||||||
virtual void operator()( const fc::string& v ){ m_out = v; }
|
virtual void operator()( const fc::string& v ){ m_out = v; }
|
||||||
virtual void operator()( const value::object& ) { FC_THROW_MSG("bad cast"); }
|
virtual void operator()( const value::object& ) { FC_THROW_MSG("bad cast"); }
|
||||||
virtual void operator()( const value::array& ) { FC_THROW_MSG("bad cast"); }
|
virtual void operator()( const value::array& ) { FC_THROW_MSG("bad cast"); }
|
||||||
|
|
@ -165,7 +187,7 @@ namespace fc {
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct cast_visitor<void> : value::value::const_visitor {
|
struct cast_visitor<void> : value::const_visitor {
|
||||||
virtual void operator()( const int8_t& v ) { FC_THROW_MSG("bad cast");}
|
virtual void operator()( const int8_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
virtual void operator()( const int16_t& v ) { FC_THROW_MSG("bad cast");}
|
virtual void operator()( const int16_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
virtual void operator()( const int32_t& v ) { FC_THROW_MSG("bad cast");}
|
virtual void operator()( const int32_t& v ) { FC_THROW_MSG("bad cast");}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#ifndef _FC_VECTOR_HPP_
|
#pragma once
|
||||||
#define _FC_VECTOR_HPP_
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -7,15 +6,6 @@
|
||||||
#include <fc/log.hpp>
|
#include <fc/log.hpp>
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include <vector>
|
|
||||||
namespace fc {
|
|
||||||
template<typename T>
|
|
||||||
using vector = std::vector<T>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -27,8 +17,8 @@ namespace fc {
|
||||||
static data* allocate( uint64_t cap ) {
|
static data* allocate( uint64_t cap ) {
|
||||||
data* d = nullptr;
|
data* d = nullptr;
|
||||||
if( cap ){
|
if( cap ){
|
||||||
d = (data*)malloc(sizeof(data) + sizeof(T)*(cap-1));
|
d = (data*)malloc(sizeof(data) + sizeof(T)*(static_cast<size_t>(cap)-1));
|
||||||
d->capacity = cap;
|
d->capacity = static_cast<size_t>(cap);
|
||||||
} else {
|
} else {
|
||||||
d = (data*)malloc(sizeof(data));
|
d = (data*)malloc(sizeof(data));
|
||||||
d->capacity = 1;
|
d->capacity = 1;
|
||||||
|
|
@ -38,8 +28,8 @@ namespace fc {
|
||||||
}
|
}
|
||||||
static data* reallocate( data* d, uint64_t cap ) {
|
static data* reallocate( data* d, uint64_t cap ) {
|
||||||
if( cap ){
|
if( cap ){
|
||||||
d = (data*)realloc(d,sizeof(data) + sizeof(T)*(cap-1));
|
d = (data*)realloc(d,sizeof(data) + sizeof(T)*(static_cast<size_t>(cap)-1));
|
||||||
d->capacity = cap;
|
d->capacity = static_cast<size_t>(cap);
|
||||||
} else {
|
} else {
|
||||||
d = (data*)realloc(d,sizeof(data));
|
d = (data*)realloc(d,sizeof(data));
|
||||||
d->capacity = 1;
|
d->capacity = 1;
|
||||||
|
|
@ -64,13 +54,13 @@ namespace fc {
|
||||||
if( c.size() ) {
|
if( c.size() ) {
|
||||||
_data = detail::data<T>::allocate( c.size() );
|
_data = detail::data<T>::allocate( c.size() );
|
||||||
_data->size = c.size();
|
_data->size = c.size();
|
||||||
memcpy(begin(),c.begin(),c.size() );
|
memcpy(begin(),c.begin(), static_cast<size_t>(c.size()) );
|
||||||
}
|
}
|
||||||
//slog( "copy: this.size %d", size() );
|
//slog( "copy: this.size %d", size() );
|
||||||
}
|
}
|
||||||
vector_impl(const_iterator b, const_iterator e ):_data(nullptr) {
|
vector_impl(const_iterator b, const_iterator e ):_data(nullptr) {
|
||||||
resize(e-b);
|
resize(e-b);
|
||||||
if( size() ) memcpy( data(), b, size() );
|
if( size() ) memcpy( data(), b, static_cast<size_t>(size()) );
|
||||||
}
|
}
|
||||||
vector_impl(uint64_t s):_data(nullptr){
|
vector_impl(uint64_t s):_data(nullptr){
|
||||||
resize(s);
|
resize(s);
|
||||||
|
|
@ -170,12 +160,12 @@ namespace fc {
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_impl& operator=( vector_impl&& v ) {
|
vector_impl& operator=( vector_impl&& v ) {
|
||||||
fc::swap(_data,v._data);
|
fc_swap(_data,v._data);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
vector_impl& operator=( const vector_impl& v ) {
|
vector_impl& operator=( const vector_impl& v ) {
|
||||||
vector_impl tmp(v);
|
vector_impl tmp(v);
|
||||||
fc::swap(tmp._data,_data);
|
fc_swap(tmp._data,_data);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -270,7 +260,7 @@ namespace fc {
|
||||||
++c;
|
++c;
|
||||||
++nc;
|
++nc;
|
||||||
}
|
}
|
||||||
fc::swap( _ndata, this->_data );
|
fc_swap( _ndata, this->_data );
|
||||||
if( _ndata ) free(_ndata);
|
if( _ndata ) free(_ndata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,12 +334,12 @@ namespace fc {
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
vector_impl& operator=( vector_impl&& v ) {
|
vector_impl& operator=( vector_impl&& v ) {
|
||||||
fc::swap(_data,v._data);
|
fc_swap(_data,v._data);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
vector_impl& operator=( const vector_impl& v ) {
|
vector_impl& operator=( const vector_impl& v ) {
|
||||||
vector_impl tmp(v);
|
vector_impl tmp(v);
|
||||||
fc::swap(tmp._data,_data);
|
fc_swap(tmp._data,_data);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|
@ -380,6 +370,4 @@ namespace fc {
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // _FC_VECTOR_HPP_
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ namespace fc {
|
||||||
|
|
||||||
|
|
||||||
bigint& bigint::operator = ( bigint&& a ) {
|
bigint& bigint::operator = ( bigint&& a ) {
|
||||||
fc::swap( a.n, n );
|
fc_swap( a.n, n );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
bigint& bigint::operator = ( const bigint& a ) {
|
bigint& bigint::operator = ( const bigint& a ) {
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,12 @@ namespace fc {
|
||||||
}
|
}
|
||||||
bool promise_base::error()const {
|
bool promise_base::error()const {
|
||||||
{ synchronized(_spin_yield)
|
{ synchronized(_spin_yield)
|
||||||
return _except;
|
return _exceptp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void promise_base::set_exception( const fc::exception_ptr& e ){
|
void promise_base::set_exception( const fc::exception_ptr& e ){
|
||||||
_except = e;
|
_exceptp = e;
|
||||||
_set_value(nullptr);
|
_set_value(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,14 +47,14 @@ namespace fc {
|
||||||
void promise_base::_wait_until( const time_point& timeout_us ){
|
void promise_base::_wait_until( const time_point& timeout_us ){
|
||||||
{ synchronized(_spin_yield)
|
{ synchronized(_spin_yield)
|
||||||
if( _ready ) {
|
if( _ready ) {
|
||||||
if( _except ) fc::rethrow_exception( _except );
|
if( _exceptp ) fc::rethrow_exception( _exceptp );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_enqueue_thread();
|
_enqueue_thread();
|
||||||
}
|
}
|
||||||
thread::current().wait_until( ptr(this,true), timeout_us );
|
thread::current().wait_until( ptr(this,true), timeout_us );
|
||||||
if( _ready ) {
|
if( _ready ) {
|
||||||
if( _except ) fc::rethrow_exception( _except );
|
if( _exceptp ) fc::rethrow_exception( _exceptp );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FC_THROW( future_wait_timeout() );
|
FC_THROW( future_wait_timeout() );
|
||||||
|
|
@ -80,7 +80,7 @@ namespace fc {
|
||||||
}
|
}
|
||||||
_notify();
|
_notify();
|
||||||
if( nullptr != _compl ) {
|
if( nullptr != _compl ) {
|
||||||
_compl->on_complete(s,_except);
|
_compl->on_complete(s,_exceptp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void promise_base::_on_complete( detail::completion_handler* c ) {
|
void promise_base::_on_complete( detail::completion_handler* c ) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fc/log.hpp>
|
#include <fc/log.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
ostream& operator<<( ostream& o, const char* v ) {
|
ostream& operator<<( ostream& o, const char* v ) {
|
||||||
|
|
@ -86,7 +87,7 @@ namespace fc {
|
||||||
void cerr_t::close() {};
|
void cerr_t::close() {};
|
||||||
void cerr_t::flush() { std::cerr.flush(); }
|
void cerr_t::flush() { std::cerr.flush(); }
|
||||||
|
|
||||||
ostream& cerr_t::write( const fc::string& s ) { std::cerr<< *reinterpret_cast<const std::string*>(&s); return *this; }
|
ostream& cerr_t::write( const fc::string& s ) { std::cerr<< static_cast<std::string>(s); return *this; }
|
||||||
|
|
||||||
size_t cin_t::readsome( char* buf, size_t len ) {
|
size_t cin_t::readsome( char* buf, size_t len ) {
|
||||||
cin_buffer& b = get_cin_buffer();
|
cin_buffer& b = get_cin_buffer();
|
||||||
|
|
|
||||||
101
src/json.cpp
101
src/json.cpp
|
|
@ -6,6 +6,7 @@
|
||||||
#include <fc/interprocess/file_mapping.hpp>
|
#include <fc/interprocess/file_mapping.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
namespace fc { namespace json {
|
namespace fc { namespace json {
|
||||||
/**
|
/**
|
||||||
* Placeholder for unparsed json data.
|
* Placeholder for unparsed json data.
|
||||||
|
|
@ -39,6 +40,11 @@ namespace fc { namespace json {
|
||||||
fc::vector<char> json_data;
|
fc::vector<char> json_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} }
|
||||||
|
|
||||||
|
typedef std::map<fc::string,fc::json::string> jmap;
|
||||||
|
|
||||||
|
|
||||||
namespace errors {
|
namespace errors {
|
||||||
enum error_type {
|
enum error_type {
|
||||||
unknown_error = 0x0001, // Other errors not specified below
|
unknown_error = 0x0001, // Other errors not specified below
|
||||||
|
|
@ -107,9 +113,9 @@ namespace fc { namespace json {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum error_defaults {
|
enum error_defaults {
|
||||||
default_report = json::errors::all,
|
default_report = errors::all,
|
||||||
default_recover = json::errors::all,
|
default_recover = errors::all,
|
||||||
default_throw = json::errors::none,
|
default_throw = errors::none,
|
||||||
default_ignore = ~(default_report|default_recover|default_throw)
|
default_ignore = ~(default_report|default_recover|default_throw)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -181,7 +187,7 @@ namespace fc { namespace json {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace fc { namespace json {
|
||||||
fc::string escape_string( const fc::string& s ) {
|
fc::string escape_string( const fc::string& s ) {
|
||||||
// calculate escape string size.
|
// calculate escape string size.
|
||||||
uint32_t ecount = 0;
|
uint32_t ecount = 0;
|
||||||
|
|
@ -246,9 +252,9 @@ namespace fc { namespace json {
|
||||||
case '"' : out += '"'; break;
|
case '"' : out += '"'; break;
|
||||||
case 'x' : {
|
case 'x' : {
|
||||||
++i; if( i == out.end() ) return out;
|
++i; if( i == out.end() ) return out;
|
||||||
char c = from_hex(*i);
|
char c = fc::from_hex(*i);
|
||||||
++i; if( i == out.end() ) { out += c; return out; }
|
++i; if( i == out.end() ) { out += c; return out; }
|
||||||
c = c<<4 | from_hex(*i);
|
c = c<<4 | fc::from_hex(*i);
|
||||||
out += c;
|
out += c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -290,9 +296,9 @@ namespace fc { namespace json {
|
||||||
case '"' : *out = '"'; ++out; break;
|
case '"' : *out = '"'; ++out; break;
|
||||||
case 'x' : {
|
case 'x' : {
|
||||||
++i; if( *i == '\0' ){ *out = '\0'; return s; }
|
++i; if( *i == '\0' ){ *out = '\0'; return s; }
|
||||||
char c = from_hex(*i);
|
char c = fc::from_hex(*i);
|
||||||
++i; if( *i == '\0' ){ *out = c; ++out; *out = '\0'; return s; }
|
++i; if( *i == '\0' ){ *out = c; ++out; *out = '\0'; return s; }
|
||||||
c = c<<4 | from_hex(*i);
|
c = c<<4 | fc::from_hex(*i);
|
||||||
*out = c;
|
*out = c;
|
||||||
++out;
|
++out;
|
||||||
break;
|
break;
|
||||||
|
|
@ -308,6 +314,7 @@ namespace fc { namespace json {
|
||||||
*out = '\0';
|
*out = '\0';
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
} }// fc::json
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignores leading white space.
|
* Ignores leading white space.
|
||||||
|
|
@ -435,12 +442,12 @@ struct temp_set {
|
||||||
* A,B,C
|
* A,B,C
|
||||||
* Warn on extra ',' or missing ','
|
* Warn on extra ',' or missing ','
|
||||||
*/
|
*/
|
||||||
void read_values( value::array& a, char* in, char* end, fc::json::error_collector& ec ) {
|
void read_values( fc::value::array& a, char* in, char* end, error_collector& ec ) {
|
||||||
char* ve = 0;
|
char* ve = 0;
|
||||||
char* v = fc::json::read_value( in, end, ve );
|
char* v = read_value( in, end, ve );
|
||||||
while( *v == ',' ) {
|
while( *v == ',' ) {
|
||||||
wlog( "unexpected ','");
|
wlog( "unexpected ','");
|
||||||
v = fc::json::read_value( ve, end, ve );
|
v = read_value( ve, end, ve );
|
||||||
}
|
}
|
||||||
if( v == ve ) return; // no values
|
if( v == ve ) return; // no values
|
||||||
|
|
||||||
|
|
@ -451,7 +458,7 @@ void read_values( value::array& a, char* in, char* end, fc::json::error_collect
|
||||||
do { // expect comma + value | ''
|
do { // expect comma + value | ''
|
||||||
|
|
||||||
// expect comma or ''
|
// expect comma or ''
|
||||||
c = fc::json::read_value( ve, end, ce );
|
c = read_value( ve, end, ce );
|
||||||
|
|
||||||
// '' means we are done, no errors
|
// '' means we are done, no errors
|
||||||
if( c == ce ) return;
|
if( c == ce ) return;
|
||||||
|
|
@ -465,12 +472,12 @@ void read_values( value::array& a, char* in, char* end, fc::json::error_collect
|
||||||
}
|
}
|
||||||
|
|
||||||
// expect value
|
// expect value
|
||||||
v = fc::json::read_value( ce, end, ve );
|
v = read_value( ce, end, ve );
|
||||||
while ( *v == ',' ) { // but got comma
|
while ( *v == ',' ) { // but got comma
|
||||||
// expect value
|
// expect value
|
||||||
wlog( "extra comma at c->ce" );
|
wlog( "extra comma at c->ce" );
|
||||||
c = v; ce = ve;
|
c = v; ce = ve;
|
||||||
v = fc::json::read_value( ve, end, ve );
|
v = read_value( ve, end, ve );
|
||||||
}
|
}
|
||||||
if( v == ve ) {
|
if( v == ve ) {
|
||||||
wlog( "trailing comma at c->ce" );
|
wlog( "trailing comma at c->ce" );
|
||||||
|
|
@ -485,22 +492,22 @@ void read_values( value::array& a, char* in, char* end, fc::json::error_collect
|
||||||
/**
|
/**
|
||||||
* Reads one level deep, does not recruse into sub objects.
|
* Reads one level deep, does not recruse into sub objects.
|
||||||
*/
|
*/
|
||||||
char* read_key_val( std::map<fc::string,json::string>& obj, bool sc, char* in, char* end, fc::json::error_collector& ec ) {
|
char* read_key_val( std::map<fc::string,fc::json::string>& obj, bool sc, char* in, char* end, error_collector& ec ) {
|
||||||
char* name_end = 0;
|
char* name_end = 0;
|
||||||
char* name = in;
|
char* name = in;
|
||||||
do {
|
do {
|
||||||
// read first char
|
// read first char
|
||||||
name = fc::json::read_value( name, end, name_end );
|
name = read_value( name, end, name_end );
|
||||||
if( sc ) { // if we expect a ,
|
if( sc ) { // if we expect a ,
|
||||||
if( *name != ',' ) { // but didn't get one
|
if( *name != ',' ) { // but didn't get one
|
||||||
wlog( "expected ',' but got %1%", name ); // warn and accept name
|
wlog( "expected ',' but got %1%", name ); // warn and accept name
|
||||||
} else { // we got the exepcted , read the expected name
|
} else { // we got the exepcted , read the expected name
|
||||||
name = fc::json::read_value( name_end, end, name_end );
|
name = read_value( name_end, end, name_end );
|
||||||
}
|
}
|
||||||
} else { // don't start with ','
|
} else { // don't start with ','
|
||||||
while( *name == ',' ) { // while we don't have a name, keep looking
|
while( *name == ',' ) { // while we don't have a name, keep looking
|
||||||
wlog( "unexpected ',' " );
|
wlog( "unexpected ',' " );
|
||||||
name = fc::json::read_value( name_end, end, name_end );
|
name = read_value( name_end, end, name_end );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while( *name == ',' );
|
} while( *name == ',' );
|
||||||
|
|
@ -517,11 +524,11 @@ char* read_key_val( std::map<fc::string,json::string>& obj, bool sc, char* in, c
|
||||||
wlog( "unquoted name '%1%'", name );
|
wlog( "unquoted name '%1%'", name );
|
||||||
} else {
|
} else {
|
||||||
temp_set ntemp(name_end,'\0');
|
temp_set ntemp(name_end,'\0');
|
||||||
name = inplace_unescape_string(name);
|
name = fc::json::inplace_unescape_string(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* col_end = 0;
|
char* col_end = 0;
|
||||||
char* col = fc::json::read_value( name_end, end, col_end );
|
char* col = read_value( name_end, end, col_end );
|
||||||
|
|
||||||
char* val_end = 0;
|
char* val_end = 0;
|
||||||
char* val = 0;
|
char* val = 0;
|
||||||
|
|
@ -555,7 +562,7 @@ char* read_key_val( std::map<fc::string,json::string>& obj, bool sc, char* in, c
|
||||||
elog( "early end after reading name '%1%' and col '%2%'", name, col );
|
elog( "early end after reading name '%1%' and col '%2%'", name, col );
|
||||||
return name_end;
|
return name_end;
|
||||||
}
|
}
|
||||||
val = fc::json::read_value( col_end, end, val_end );
|
val = read_value( col_end, end, val_end );
|
||||||
if( val == end ) {
|
if( val == end ) {
|
||||||
wlog( "no value specified" );
|
wlog( "no value specified" );
|
||||||
}
|
}
|
||||||
|
|
@ -576,12 +583,12 @@ char* read_key_val( std::map<fc::string,json::string>& obj, bool sc, char* in, c
|
||||||
* Reads an optional ',' followed by key : value, returning the next input position
|
* Reads an optional ',' followed by key : value, returning the next input position
|
||||||
* @param sc - start with ','
|
* @param sc - start with ','
|
||||||
*/
|
*/
|
||||||
char* read_key_val( value::object& obj, bool sc, char* in, char* end, fc::json::error_collector& ec ) {
|
char* read_key_val( fc::value::object& obj, bool sc, char* in, char* end, error_collector& ec ) {
|
||||||
char* name_end = 0;
|
char* name_end = 0;
|
||||||
char* name = in;
|
char* name = in;
|
||||||
do {
|
do {
|
||||||
// read first char
|
// read first char
|
||||||
name = fc::json::read_value( name, end, name_end );
|
name = read_value( name, end, name_end );
|
||||||
if( name == name_end )
|
if( name == name_end )
|
||||||
return name;
|
return name;
|
||||||
if( sc ) { // if we expect a ,
|
if( sc ) { // if we expect a ,
|
||||||
|
|
@ -589,12 +596,12 @@ char* read_key_val( value::object& obj, bool sc, char* in, char* end, fc::json::
|
||||||
if( *name != '}' )
|
if( *name != '}' )
|
||||||
wlog( "expected ',' or '}' but got '%s'", name ); // warn and accept name
|
wlog( "expected ',' or '}' but got '%s'", name ); // warn and accept name
|
||||||
} else { // we got the exepcted , read the expected name
|
} else { // we got the exepcted , read the expected name
|
||||||
name = fc::json::read_value( name_end, end, name_end );
|
name = read_value( name_end, end, name_end );
|
||||||
}
|
}
|
||||||
} else { // don't start with ','
|
} else { // don't start with ','
|
||||||
while( *name == ',' ) { // while we don't have a name, keep looking
|
while( *name == ',' ) { // while we don't have a name, keep looking
|
||||||
wlog( "unexpected ',' " );
|
wlog( "unexpected ',' " );
|
||||||
name = fc::json::read_value( name_end, end, name_end );
|
name = read_value( name_end, end, name_end );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while( *name == ',' );
|
} while( *name == ',' );
|
||||||
|
|
@ -611,11 +618,11 @@ char* read_key_val( value::object& obj, bool sc, char* in, char* end, fc::json::
|
||||||
wlog( "unquoted name '%1%'", name );
|
wlog( "unquoted name '%1%'", name );
|
||||||
} else {
|
} else {
|
||||||
temp_set ntemp(name_end,'\0');
|
temp_set ntemp(name_end,'\0');
|
||||||
name = inplace_unescape_string(name);
|
name = fc::json::inplace_unescape_string(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* col_end = 0;
|
char* col_end = 0;
|
||||||
char* col = fc::json::read_value( name_end, end, col_end );
|
char* col = read_value( name_end, end, col_end );
|
||||||
|
|
||||||
char* val_end = 0;
|
char* val_end = 0;
|
||||||
char* val = 0;
|
char* val = 0;
|
||||||
|
|
@ -649,7 +656,7 @@ char* read_key_val( value::object& obj, bool sc, char* in, char* end, fc::json::
|
||||||
elog( "early end after reading name '%1%' and col '%2%'", name, col );
|
elog( "early end after reading name '%1%' and col '%2%'", name, col );
|
||||||
return name_end;
|
return name_end;
|
||||||
}
|
}
|
||||||
val = fc::json::read_value( col_end, end, val_end );
|
val = read_value( col_end, end, val_end );
|
||||||
if( val == end ) {
|
if( val == end ) {
|
||||||
wlog( "no value specified" );
|
wlog( "no value specified" );
|
||||||
}
|
}
|
||||||
|
|
@ -657,13 +664,13 @@ char* read_key_val( value::object& obj, bool sc, char* in, char* end, fc::json::
|
||||||
temp_set ntemp(name_end,'\0');
|
temp_set ntemp(name_end,'\0');
|
||||||
temp_set vtemp(val_end,'\0');
|
temp_set vtemp(val_end,'\0');
|
||||||
//slog( "name: '%1%'", fc::string(name,name_end) );
|
//slog( "name: '%1%'", fc::string(name,name_end) );
|
||||||
obj.fields.push_back( value::key_val( name, to_value( val, val_end, ec ) ) );
|
obj.fields.push_back( fc::value::key_val( name, to_value( val, val_end, ec ) ) );
|
||||||
return val_end;
|
return val_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
// first_key =:: '' | "name" : VALUE *list_key
|
// first_key =:: '' | "name" : VALUE *list_key
|
||||||
// list_key '' | ',' "name" : VALUE
|
// list_key '' | ',' "name" : VALUE
|
||||||
void read_key_vals( value::object& obj, char* in, char* end, fc::json::error_collector& ec ) {
|
void read_key_vals( fc::value::object& obj, char* in, char* end, error_collector& ec ) {
|
||||||
bool ex_c = false;
|
bool ex_c = false;
|
||||||
char* kv_end = in;
|
char* kv_end = in;
|
||||||
do {
|
do {
|
||||||
|
|
@ -674,8 +681,8 @@ void read_key_vals( value::object& obj, char* in, char* end, fc::json::error_col
|
||||||
}
|
}
|
||||||
// first_key =:: '' | "name" : VALUE *list_key
|
// first_key =:: '' | "name" : VALUE *list_key
|
||||||
// list_key '' | ',' "name" : VALUE
|
// list_key '' | ',' "name" : VALUE
|
||||||
std::map<fc::string,json::string> read_key_vals( char* in, char* end, fc::json::error_collector& ec ) {
|
std::map<fc::string,fc::json::string> read_key_vals( char* in, char* end, error_collector& ec ) {
|
||||||
std::map<fc::string,json::string> m;
|
std::map<fc::string,fc::json::string> m;
|
||||||
bool ex_c = false;
|
bool ex_c = false;
|
||||||
char* kv_end = in;
|
char* kv_end = in;
|
||||||
do {
|
do {
|
||||||
|
|
@ -692,7 +699,7 @@ std::map<fc::string,json::string> read_key_vals( char* in, char* end, fc::json::
|
||||||
* @brief adaptor for to_value( char*, char*, error_collector& )
|
* @brief adaptor for to_value( char*, char*, error_collector& )
|
||||||
*/
|
*/
|
||||||
fc::value to_value( fc::vector<char>&& v, error_collector& ec ) {
|
fc::value to_value( fc::vector<char>&& v, error_collector& ec ) {
|
||||||
if( v.size() == 0 ) return value();
|
if( v.size() == 0 ) return fc::value();
|
||||||
return to_value( &v.front(), &v.front() + v.size(), ec );
|
return to_value( &v.front(), &v.front() + v.size(), ec );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -703,21 +710,21 @@ fc::value to_value( fc::vector<char>&& v, error_collector& ec ) {
|
||||||
* any errors that occur while parsing the string.
|
* any errors that occur while parsing the string.
|
||||||
*/
|
*/
|
||||||
fc::value to_value( char* start, char* end, error_collector& ec ) {
|
fc::value to_value( char* start, char* end, error_collector& ec ) {
|
||||||
if( start == end ) return value();
|
if( start == end ) return fc::value();
|
||||||
|
|
||||||
char* ve = 0;
|
char* ve = 0;
|
||||||
char* s = read_value( start, end, ve );
|
char* s = read_value( start, end, ve );
|
||||||
//slog( "'%1%'", fc::string(start,ve) );
|
//slog( "'%1%'", fc::string(start,ve) );
|
||||||
switch( s[0] ) {
|
switch( s[0] ) {
|
||||||
case '[': {
|
case '[': {
|
||||||
value::array a;
|
fc::value::array a;
|
||||||
read_values( a, s+1, ve -1, ec );
|
read_values( a, s+1, ve -1, ec );
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
case '{': {
|
case '{': {
|
||||||
value::object o;
|
fc::value::object o;
|
||||||
read_key_vals( o, s+1, ve -1, ec );
|
read_key_vals( o, s+1, ve -1, ec );
|
||||||
value v = fc::move(o);
|
fc::value v = fc::move(o);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
case '0':
|
case '0':
|
||||||
|
|
@ -753,11 +760,11 @@ fc::value to_value( char* start, char* end, error_collector& ec ) {
|
||||||
}
|
}
|
||||||
case '\"': {
|
case '\"': {
|
||||||
temp_set move_end(ve,'\0');
|
temp_set move_end(ve,'\0');
|
||||||
return inplace_unescape_string( s );
|
return fc::json::inplace_unescape_string( s );
|
||||||
}
|
}
|
||||||
case 'n': {
|
case 'n': {
|
||||||
temp_set move_end(ve,'\0');
|
temp_set move_end(ve,'\0');
|
||||||
if( strcmp(s,"null" ) == 0) return value();
|
if( strcmp(s,"null" ) == 0) return fc::value();
|
||||||
}
|
}
|
||||||
case 't': {
|
case 't': {
|
||||||
temp_set move_end(ve,'\0');
|
temp_set move_end(ve,'\0');
|
||||||
|
|
@ -770,9 +777,10 @@ fc::value to_value( char* start, char* end, error_collector& ec ) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
wlog( "return unable to parse... return as string '%s'", fc::string(s,ve).c_str() );
|
wlog( "return unable to parse... return as string '%s'", fc::string(s,ve).c_str() );
|
||||||
return value( fc::string( s, ve) );
|
return fc::value( fc::string( s, ve) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
namespace fc { namespace json {
|
||||||
|
|
||||||
fc::string pretty_print( fc::vector<char>&& v, uint8_t indent ) {
|
fc::string pretty_print( fc::vector<char>&& v, uint8_t indent ) {
|
||||||
int level = 0;
|
int level = 0;
|
||||||
|
|
@ -871,8 +879,8 @@ fc::string pretty_print( fc::vector<char>&& v, uint8_t indent ) {
|
||||||
virtual void operator()( const float& v ){ os << v; }
|
virtual void operator()( const float& v ){ os << v; }
|
||||||
virtual void operator()( const double& v ){ os << v; }
|
virtual void operator()( const double& v ){ os << v; }
|
||||||
virtual void operator()( const bool& v ){ os << (v ? "true" : "false"); }
|
virtual void operator()( const bool& v ){ os << (v ? "true" : "false"); }
|
||||||
virtual void operator()( const fc::string& v ){ os << '"' << escape_string(v) <<'"'; }
|
virtual void operator()( const fc::string& v ){ os << '"' << fc::json::escape_string(v) <<'"'; }
|
||||||
virtual void operator()( const value::object& o ){
|
virtual void operator()( const fc::value::object& o ){
|
||||||
os << '{';
|
os << '{';
|
||||||
for( uint32_t i = 0; i < o.fields.size(); ++i ) {
|
for( uint32_t i = 0; i < o.fields.size(); ++i ) {
|
||||||
if( i ) os <<',';
|
if( i ) os <<',';
|
||||||
|
|
@ -918,7 +926,7 @@ fc::string pretty_print( fc::vector<char>&& v, uint8_t indent ) {
|
||||||
|
|
||||||
// memory map the file
|
// memory map the file
|
||||||
file_mapping fmap( local_path.string().c_str(), read_only );
|
file_mapping fmap( local_path.string().c_str(), read_only );
|
||||||
size_t fsize = file_size(local_path);
|
size_t fsize = static_cast<size_t>(file_size(local_path));
|
||||||
|
|
||||||
|
|
||||||
mapped_region mr( fmap, fc::read_only, 0, fsize );
|
mapped_region mr( fmap, fc::read_only, 0, fsize );
|
||||||
|
|
@ -929,8 +937,8 @@ fc::string pretty_print( fc::vector<char>&& v, uint8_t indent ) {
|
||||||
// TODO: implement a const version of to_value
|
// TODO: implement a const version of to_value
|
||||||
fc::vector<char> tmp(pos,end);
|
fc::vector<char> tmp(pos,end);
|
||||||
|
|
||||||
json::error_collector ec;
|
error_collector ec;
|
||||||
return fc::json::to_value(tmp.data(), tmp.data()+fsize,ec);
|
return to_value(tmp.data(), tmp.data()+fsize,ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
value from_string( const fc::string& s ) {
|
value from_string( const fc::string& s ) {
|
||||||
|
|
@ -945,5 +953,4 @@ fc::string pretty_print( fc::vector<char>&& v, uint8_t indent ) {
|
||||||
return from_string( fc::vector<char>(s,e) );
|
return from_string( fc::vector<char>(s,e) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} }
|
||||||
}} // fc::json
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ namespace fc { namespace json {
|
||||||
rpc_connection::rpc_connection( const rpc_connection& c )
|
rpc_connection::rpc_connection( const rpc_connection& c )
|
||||||
:my(c.my){ }
|
:my(c.my){ }
|
||||||
rpc_connection::rpc_connection( rpc_connection&& c ) {
|
rpc_connection::rpc_connection( rpc_connection&& c ) {
|
||||||
fc::swap(my,c.my);
|
fc_swap(my,c.my);
|
||||||
}
|
}
|
||||||
rpc_connection::~rpc_connection() {
|
rpc_connection::~rpc_connection() {
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ namespace fc { namespace json {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
rpc_connection& rpc_connection::operator=(rpc_connection&& m) {
|
rpc_connection& rpc_connection::operator=(rpc_connection&& m) {
|
||||||
fc::swap(m.my,my);
|
fc_swap(m.my,my);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#ifndef WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
@ -32,8 +34,10 @@ namespace fc {
|
||||||
void log( const char* color, const char* file_name, size_t line_num,
|
void log( const char* color, const char* file_name, size_t line_num,
|
||||||
const char* method_name, const char* format, ... ) {
|
const char* method_name, const char* format, ... ) {
|
||||||
fc::unique_lock<boost::mutex> lock(log_mutex());
|
fc::unique_lock<boost::mutex> lock(log_mutex());
|
||||||
|
#ifndef WIN32
|
||||||
if(isatty(fileno(stderr)))
|
if(isatty(fileno(stderr)))
|
||||||
std::cerr<<"\r"<<color;
|
std::cerr<<"\r"<<color;
|
||||||
|
#endif
|
||||||
|
|
||||||
fprintf( stderr, "%-15s %-15s %-5zd %-15s ", thread_name(), short_name(file_name), line_num, method_name );
|
fprintf( stderr, "%-15s %-15s %-5zd %-15s ", thread_name(), short_name(file_name), line_num, method_name );
|
||||||
//std::cerr<<thread_ptr()<< thread_name()<< short_name(file_name)<< line_num<< method_name ;
|
//std::cerr<<thread_ptr()<< thread_name()<< short_name(file_name)<< line_num<< method_name ;
|
||||||
|
|
@ -41,8 +45,10 @@ namespace fc {
|
||||||
va_start(args,format);
|
va_start(args,format);
|
||||||
vfprintf( stderr, format, args );
|
vfprintf( stderr, format, args );
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
#ifndef WIN32
|
||||||
if (isatty(fileno(stderr)))
|
if (isatty(fileno(stderr)))
|
||||||
fprintf( stderr, "%s", CONSOLE_DEFAULT );
|
fprintf( stderr, "%s", CONSOLE_DEFAULT );
|
||||||
|
#endif
|
||||||
fprintf( stderr, "\n" );
|
fprintf( stderr, "\n" );
|
||||||
fflush( stderr );
|
fflush( stderr );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ namespace fc {
|
||||||
} // namespace fc
|
} // namespace fc
|
||||||
|
|
||||||
FC_START_SHARED_IMPL( fc::process )
|
FC_START_SHARED_IMPL( fc::process )
|
||||||
|
public:
|
||||||
impl()
|
impl()
|
||||||
:stat( fc::asio::default_io_service() ),
|
:stat( fc::asio::default_io_service() ),
|
||||||
std_out(process_source(outp)),
|
std_out(process_source(outp)),
|
||||||
|
|
|
||||||
135
src/string.cpp
135
src/string.cpp
|
|
@ -1,13 +1,8 @@
|
||||||
#include <fc/string.hpp>
|
#include <fc/string.hpp>
|
||||||
#include <fc/utility.hpp>
|
#include <fc/utility.hpp>
|
||||||
|
#include <fc/fwd_impl.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
namespace detail {
|
|
||||||
void destroy( void* t ) {
|
|
||||||
using namespace std;
|
|
||||||
reinterpret_cast<std::string*>(t)->~string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implemented with std::string for now.
|
* Implemented with std::string for now.
|
||||||
|
|
@ -15,112 +10,48 @@ namespace detail {
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
|
||||||
string::string(const char* s, int l) {
|
string::string(const char* s, int l) :my(s,l){ }
|
||||||
static_assert( sizeof(*this) >= sizeof(std::string), "failed to reserve enough space" );
|
string::string(){}
|
||||||
new (this) std::string(s,l);
|
string::string( const string& c ):my(c.my) { }
|
||||||
}
|
string::string( string&& m ):my(fc::move(m.my)) {}
|
||||||
string::string() {
|
string::string( const char* c ):my(c){}
|
||||||
static_assert( sizeof(*this) >= sizeof(std::string), "failed to reserve enough space" );
|
string::string( const_iterator b, const_iterator e ):my(b,e){}
|
||||||
new (this) std::string();
|
string::string( const std::string& s ):my(s) {}
|
||||||
}
|
string::string( std::string&& s ):my(fc::move(s)) {}
|
||||||
|
string::~string() { }
|
||||||
string::string( const string& c ) {
|
string::operator std::string&() { return *my; }
|
||||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
string::operator const std::string&()const { return *my; }
|
||||||
new (this) std::string(reinterpret_cast<const std::string&>(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
string::string( string&& m ) {
|
|
||||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
|
||||||
new (this) std::string(reinterpret_cast<std::string&&>(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
string::string( const char* c ){
|
|
||||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
|
||||||
new (this) std::string(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
string::string( const_iterator b, const_iterator e ) {
|
|
||||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
|
||||||
new (this) std::string(b,e);
|
|
||||||
}
|
|
||||||
string::string( const std::string& s ) {
|
|
||||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
|
||||||
new (this) std::string(s);
|
|
||||||
}
|
|
||||||
string::string( std::string&& s ) {
|
|
||||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
|
||||||
new (this) std::string(fc::move(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
string::operator std::string&() {
|
|
||||||
return *reinterpret_cast<std::string*>(this);
|
|
||||||
}
|
|
||||||
string::operator const std::string&()const {
|
|
||||||
return *reinterpret_cast<const std::string*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
string::~string() {
|
|
||||||
::detail::destroy( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
string::iterator string::begin() { return &(*this)[0]; }
|
string::iterator string::begin() { return &(*this)[0]; }
|
||||||
string::iterator string::end() { return &(*this)[size()]; }
|
string::iterator string::end() { return &(*this)[size()]; }
|
||||||
string::const_iterator string::begin()const { return reinterpret_cast<const std::string*>(this)->c_str(); }
|
string::const_iterator string::begin()const { return my->c_str(); }
|
||||||
string::const_iterator string::end()const { return reinterpret_cast<const std::string*>(this)->c_str() + reinterpret_cast<const std::string*>(this)->size(); }
|
string::const_iterator string::end()const { return my->c_str() + my->size(); }
|
||||||
|
|
||||||
char& string::operator[](uint64_t idx) { return reinterpret_cast<std::string*>(this)->at(idx); }
|
char& string::operator[](uint64_t idx) { return (*my)[idx]; }
|
||||||
const char& string::operator[](uint64_t idx)const { return reinterpret_cast<const std::string*>(this)->at(idx); }
|
const char& string::operator[](uint64_t idx)const { return (*my)[idx]; }
|
||||||
|
|
||||||
void string::reserve(uint64_t r) { reinterpret_cast<std::string*>(this)->reserve(r); }
|
void string::reserve(uint64_t r) { my->reserve(r); }
|
||||||
uint64_t string::size()const { return reinterpret_cast<const std::string*>(this)->size(); }
|
uint64_t string::size()const { return my->size(); }
|
||||||
uint64_t string::find(char c, uint64_t p)const { return reinterpret_cast<const std::string*>(this)->find(c,p); }
|
uint64_t string::find(char c, uint64_t p)const { return my->find(c,p); }
|
||||||
void string::clear() { return reinterpret_cast<std::string*>(this)->clear(); }
|
void string::clear() { my->clear(); }
|
||||||
void string::resize( uint64_t s ) { reinterpret_cast<std::string*>(this)->resize(s); }
|
void string::resize( uint64_t s ) { my->resize(s); }
|
||||||
|
|
||||||
|
fc::string string::substr( int32_t start, int32_t len ) { return my->substr(start,len); }
|
||||||
|
const char* string::c_str()const { return my->c_str(); }
|
||||||
|
|
||||||
fc::string string::substr( int32_t start, int32_t len ) {
|
bool string::operator == ( const char* s )const { return *my == s; }
|
||||||
return reinterpret_cast<const std::string&>(*this).substr(start,len).c_str();
|
bool string::operator == ( const string& s )const { return *my == *s.my; }
|
||||||
}
|
bool string::operator != ( const string& s )const { return *my != *s.my; }
|
||||||
const char* string::c_str()const { return reinterpret_cast<const std::string*>(this)->c_str(); }
|
|
||||||
|
|
||||||
bool string::operator == ( const char* s )const {
|
string& string::operator =( const string& c ) { *my = *c.my; return *this; }
|
||||||
return reinterpret_cast<const std::string&>(*this) == s;
|
string& string::operator =( string&& c ) { *my = fc::move( *c.my ); return *this; }
|
||||||
}
|
|
||||||
bool string::operator == ( const string& s )const {
|
|
||||||
return reinterpret_cast<const std::string&>(*this) == reinterpret_cast<const std::string&>(s);
|
|
||||||
}
|
|
||||||
bool string::operator != ( const string& s )const {
|
|
||||||
return reinterpret_cast<const std::string&>(*this) != reinterpret_cast<const std::string&>(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
string& string::operator =( const string& c ) {
|
string& string::operator+=( const string& s ) { *my += *s.my; return *this; }
|
||||||
reinterpret_cast<std::string&>(*this) = reinterpret_cast<const std::string&>(c);
|
string& string::operator+=( char c ) { *my += c; return *this; }
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
string& string::operator =( string&& c ) {
|
|
||||||
reinterpret_cast<std::string&>(*this) = fc::move( reinterpret_cast<std::string&>(c) );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
string& string::operator+=( const string& s ) {
|
bool operator < ( const string& a, const string& b ) { return *a.my < *b.my; }
|
||||||
reinterpret_cast<std::string&>(*this) += reinterpret_cast<const std::string&>(s);
|
string operator + ( const string& s, const string& c ) { return string(s) += c; }
|
||||||
return *this;
|
string operator + ( const string& s, char c ) { return string(s) += c; }
|
||||||
}
|
|
||||||
string& string::operator+=( char c ) {
|
|
||||||
reinterpret_cast<std::string&>(*this) += c;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator < ( const string& a, const string& b ) {
|
|
||||||
return reinterpret_cast<const std::string&>(a) < reinterpret_cast<const std::string&>(b);
|
|
||||||
}
|
|
||||||
string operator + ( const string& s, const string& c ) {
|
|
||||||
return string(s) += c;
|
|
||||||
}
|
|
||||||
string operator + ( const string& s, char c ) {
|
|
||||||
return string(s) += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace fc
|
} // namespace fc
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ namespace fc {
|
||||||
}
|
}
|
||||||
|
|
||||||
thread& thread::operator=(thread&& t ) {
|
thread& thread::operator=(thread&& t ) {
|
||||||
fc::swap(t.my,my);
|
fc_swap(t.my,my);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct value_visitor {
|
class value_visitor {
|
||||||
|
public:
|
||||||
virtual void operator()( int8_t& v ){};
|
virtual void operator()( int8_t& v ){};
|
||||||
virtual void operator()( int16_t& v ){};
|
virtual void operator()( int16_t& v ){};
|
||||||
virtual void operator()( int32_t& v ){};
|
virtual void operator()( int32_t& v ){};
|
||||||
|
|
@ -24,6 +25,8 @@ namespace fc {
|
||||||
virtual void operator()( ){};
|
virtual void operator()( ){};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void value_holder::visit( value::const_visitor&& v )const {v(); }
|
||||||
|
void value_holder::visit( value_visitor&& v ) {v(); }
|
||||||
|
|
||||||
// fundamental values...
|
// fundamental values...
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -47,11 +50,11 @@ namespace fc {
|
||||||
template<>
|
template<>
|
||||||
struct value_holder_impl<void> : value_holder {
|
struct value_holder_impl<void> : value_holder {
|
||||||
value_holder_impl(){};
|
value_holder_impl(){};
|
||||||
|
virtual void visit( value::const_visitor&& v )const{ v(); }
|
||||||
|
virtual void visit( value_visitor&& v ) { v(); }
|
||||||
// typedef void_t T;
|
// typedef void_t T;
|
||||||
/*
|
/*
|
||||||
virtual const char* type()const { return "void"; }
|
virtual const char* type()const { return "void"; }
|
||||||
virtual void visit( value::const_visitor&& v )const{ v(); }
|
|
||||||
virtual void visit( value_visitor&& v ) { v(); }
|
|
||||||
virtual void clear() { }
|
virtual void clear() { }
|
||||||
virtual size_t size()const { return 0; }
|
virtual size_t size()const { return 0; }
|
||||||
|
|
||||||
|
|
@ -127,8 +130,6 @@ namespace fc {
|
||||||
value_holder* value_holder::move_helper( char* c ) { return new(c) value_holder(); }
|
value_holder* value_holder::move_helper( char* c ) { return new(c) value_holder(); }
|
||||||
value_holder* value_holder::copy_helper( char* c )const { return new(c) value_holder(); }
|
value_holder* value_holder::copy_helper( char* c )const { return new(c) value_holder(); }
|
||||||
|
|
||||||
void value_holder::visit( value::const_visitor&& v )const { v(); }
|
|
||||||
void value_holder::visit( value_visitor&& v ) { v(); }
|
|
||||||
|
|
||||||
void value_holder::clear() {}
|
void value_holder::clear() {}
|
||||||
size_t value_holder::size()const { return 0; }
|
size_t value_holder::size()const { return 0; }
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include <fc/json_rpc_client.hpp>
|
#include <fc/json_rpc_client.hpp>
|
||||||
#include <fc/json_rpc_tcp_server.hpp>
|
#include <fc/json_rpc_tcp_server.hpp>
|
||||||
#include <fc/json_rpc_tcp_connection.hpp>
|
#include <fc/json_rpc_tcp_connection.hpp>
|
||||||
|
#include <fc/reflect.hpp>
|
||||||
#include <fc/ip.hpp>
|
#include <fc/ip.hpp>
|
||||||
#include <fc/iostream.hpp>
|
#include <fc/iostream.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue