windows port
This commit is contained in:
parent
afbbf4e8db
commit
161ce54cb8
40 changed files with 351 additions and 208 deletions
|
|
@ -2,7 +2,7 @@
|
|||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
fc::string to_base58( const char* d, uint32_t s );
|
||||
fc::string to_base58( const char* d, size_t s );
|
||||
fc::vector<char> from_base58( const fc::string& base58_str );
|
||||
size_t from_base58( const fc::string& base58_str, char* out_data, size_t out_data_len );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,26 +15,13 @@ namespace fc {
|
|||
*/
|
||||
template<typename T>
|
||||
struct datastream {
|
||||
datastream( T start, uint32_t s )
|
||||
datastream( T start, size_t s )
|
||||
:m_start(start),m_pos(start),m_end(start+s){};
|
||||
|
||||
template<typename DATA>
|
||||
inline datastream& operator<<(const DATA& d) {
|
||||
static_assert( !fc::is_class<DATA>::type::value, "no serialization defined" );
|
||||
write( (const char*)&d, sizeof(d) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename DATA>
|
||||
inline datastream& operator>>(DATA& d) {
|
||||
static_assert( !fc::is_class<DATA>::type::value, "no serialization defined" );
|
||||
read((char*)&d, sizeof(d) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void skip( uint32_t s ){ m_pos += s; }
|
||||
inline bool read( char* d, uint32_t s ) {
|
||||
if( m_end - m_pos >= (int32_t)s ) {
|
||||
inline void skip( size_t s ){ m_pos += s; }
|
||||
inline bool read( char* d, size_t s ) {
|
||||
if( m_end - m_pos >= (size_t)s ) {
|
||||
memcpy( d, m_pos, s );
|
||||
m_pos += s;
|
||||
return true;
|
||||
|
|
@ -44,7 +31,7 @@ struct datastream {
|
|||
return false;
|
||||
}
|
||||
|
||||
inline bool write( const char* d, uint32_t s ) {
|
||||
inline bool write( const char* d, size_t s ) {
|
||||
if( m_end - m_pos >= (int32_t)s ) {
|
||||
memcpy( m_pos, d, s );
|
||||
m_pos += s;
|
||||
|
|
@ -81,9 +68,9 @@ struct datastream {
|
|||
|
||||
T pos()const { return m_pos; }
|
||||
inline bool valid()const { return m_pos <= m_end && m_pos >= m_start; }
|
||||
inline bool seekp(uint32_t p) { m_pos = m_start + p; return m_pos <= m_end; }
|
||||
inline uint32_t tellp()const { return m_pos - m_start; }
|
||||
inline uint32_t remaining()const { return m_end - m_pos; }
|
||||
inline bool seekp(size_t p) { m_pos = m_start + p; return m_pos <= m_end; }
|
||||
inline size_t tellp()const { return m_pos - m_start; }
|
||||
inline size_t remaining()const { return m_end - m_pos; }
|
||||
private:
|
||||
T m_start;
|
||||
T m_pos;
|
||||
|
|
@ -93,23 +80,117 @@ struct datastream {
|
|||
template<>
|
||||
struct datastream<size_t> {
|
||||
datastream( size_t init_size = 0):m_size(init_size){};
|
||||
template<typename DATA>
|
||||
inline datastream& operator<<(const DATA& d) {
|
||||
static_assert( !fc::is_class<DATA>::type::value, "no serialzation defined" );
|
||||
m_size += sizeof(d);
|
||||
return *this;
|
||||
}
|
||||
inline bool skip( uint32_t s ) { m_size += s; return true; }
|
||||
inline bool write( const char* d, uint32_t s ) { m_size += s; return true; }
|
||||
inline bool skip( size_t s ) { m_size += s; return true; }
|
||||
inline bool write( const char* d,size_t s ) { m_size += s; return true; }
|
||||
inline bool put(char c) { ++m_size; return true; }
|
||||
inline bool valid()const { return true; }
|
||||
inline bool seekp(uint32_t p) { m_size = p; return true; }
|
||||
inline uint32_t tellp()const { return m_size; }
|
||||
inline uint32_t remaining()const { return 0; }
|
||||
inline bool seekp(size_t p) { m_size = p; return true; }
|
||||
inline size_t tellp()const { return m_size; }
|
||||
inline size_t remaining()const { return 0; }
|
||||
private:
|
||||
uint32_t m_size;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
/*
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const size_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return *this;
|
||||
}
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, size_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const int32_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, int32_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint32_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, uint32_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const int64_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, int64_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint64_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, uint64_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const int16_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, int16_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint16_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, uint16_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const int8_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, int8_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
template<typename ST>
|
||||
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint8_t& d) {
|
||||
ds.write( (const char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
template<typename ST, typename DATA>
|
||||
inline datastream<ST>& operator>>(datastream<ST>& ds, uint8_t& d) {
|
||||
ds.read((char*)&d, sizeof(d) );
|
||||
return ds;
|
||||
}
|
||||
|
||||
|
||||
} // namespace fc
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace fc {
|
|||
void create_directories( const path& p );
|
||||
path absolute( const path& p );
|
||||
path canonical( const path& p );
|
||||
uint64_t file_size( const path& p );
|
||||
size_t file_size( const path& p );
|
||||
bool remove( const path& p );
|
||||
void copy( const path& from, const path& to );
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ namespace fc {
|
|||
template<typename T,unsigned int S,typename A>
|
||||
fwd<T,S,A>::fwd() {
|
||||
check_size<sizeof(T),sizeof(_store)>();
|
||||
new (this) T();
|
||||
new (this) T;
|
||||
}
|
||||
template<typename T,unsigned int S,typename A>
|
||||
fwd<T,S,A>::fwd( const fwd<T,S,A>& f ){
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/lexical_cast.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
class string;
|
||||
|
||||
class istream {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ namespace fc {
|
|||
struct impl : public impl_base {
|
||||
impl(T& i):st(i){}
|
||||
|
||||
virtual size_t readsome( char* buf, size_t len ) { return st.readsome(buf,len); }
|
||||
virtual size_t readsome( char* buf, size_t len ) { return size_t(st.readsome(buf,len)); }
|
||||
virtual void read( char* buf, size_t len ) {
|
||||
st.read(buf,len);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace fc {
|
|||
inline uint64_t to_uint64( uint64_t d ) { return d; }
|
||||
|
||||
fc::string to_string( double d );
|
||||
fc::string to_string( size_t d );
|
||||
fc::string to_string( uint64_t d );
|
||||
fc::string to_string( uint32_t d );
|
||||
fc::string to_string( uint16_t d );
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ namespace fc {
|
|||
|
||||
template<typename U>
|
||||
optional& operator=( U&& u ) {
|
||||
if( &u == &**this ) return *this;
|
||||
if( !_valid ) {
|
||||
new (&**this) T( fc::forward<U>(u) );
|
||||
_valid = true;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
#include <fc/shared_impl.hpp>
|
||||
#include <fc/future.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
class istream;
|
||||
class ostream;
|
||||
class path;
|
||||
class string;
|
||||
template<typename> class vector;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ namespace fc {
|
|||
raw::pack(ps,v );
|
||||
fc::vector<char> vec(ps.tellp());
|
||||
if( vec.size() ) {
|
||||
datastream<char*> ds( vec.data(), vec.size() );
|
||||
datastream<char*> ds( vec.data(), size_t(vec.size()) );
|
||||
raw::pack(ds,v);
|
||||
}
|
||||
return vec;
|
||||
|
|
@ -256,7 +256,7 @@ namespace fc {
|
|||
inline T unpack( const fc::vector<char>& s ) {
|
||||
T tmp;
|
||||
if( s.size() ) {
|
||||
datastream<const char*> ds( s.data(), s.size() );
|
||||
datastream<const char*> ds( s.data(), size_t(s.size()) );
|
||||
raw::unpack(ds,tmp);
|
||||
}
|
||||
return tmp;
|
||||
|
|
|
|||
|
|
@ -78,9 +78,11 @@ struct reflector{
|
|||
#else
|
||||
#define TEMPLATE
|
||||
#endif
|
||||
//#include <boost/typeof/typeof.hpp>
|
||||
|
||||
#define FC_REFLECT_VISIT_MEMBER( r, visitor, elem ) \
|
||||
visitor.TEMPLATE operator()<decltype(((type*)0)->elem), type, &type::elem>( BOOST_PP_STRINGIZE(elem) );
|
||||
{ typedef decltype(((type*)nullptr)->elem) member_type; \
|
||||
visitor.TEMPLATE operator()<member_type,type,&type::elem>( BOOST_PP_STRINGIZE(elem) ); \
|
||||
}
|
||||
|
||||
|
||||
#define FC_REFLECT_BASE_MEMBER_COUNT( r, OP, elem ) \
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ shared_impl<T>::shared_impl( U&& u ):_impl(fc::forward<U>(u)){}
|
|||
|
||||
template<typename T>
|
||||
shared_impl<T>::shared_impl( const shared_impl<T>& u ):_impl(u._impl){}
|
||||
template<typename T>
|
||||
shared_impl<T>::shared_impl( shared_impl<T>& u ):_impl(u._impl){}
|
||||
//template<typename T>
|
||||
//shared_impl<T>::shared_impl( shared_impl<T>& u ):_impl(u._impl){}
|
||||
|
||||
template<typename T>
|
||||
shared_impl<T>::shared_impl( shared_impl<T>&& u ):_impl(fc::move(u._impl)){}
|
||||
|
|
@ -57,8 +57,6 @@ TYPE::TYPE( TYPE&& c )\
|
|||
:my(fc::move(c.my)){}\
|
||||
TYPE::TYPE( const TYPE& c )\
|
||||
:my(c.my){}\
|
||||
TYPE::TYPE( TYPE& c )\
|
||||
:my(c.my){}\
|
||||
TYPE::TYPE() \
|
||||
:my( new fc::shared_impl<TYPE>::impl( ) ){}\
|
||||
TYPE::~TYPE(){}\
|
||||
|
|
|
|||
|
|
@ -110,10 +110,10 @@ namespace fc {
|
|||
bool operator !()const;
|
||||
|
||||
template<typename U>
|
||||
shared_impl( U&& u );
|
||||
explicit shared_impl( U&& u );
|
||||
|
||||
shared_impl( const shared_impl& u );
|
||||
shared_impl( shared_impl& u );
|
||||
// shared_impl( shared_impl& u );
|
||||
shared_impl( shared_impl&& u );
|
||||
shared_impl& operator=( shared_impl&& u );
|
||||
shared_impl& operator=( const shared_impl& u );
|
||||
|
|
@ -132,7 +132,6 @@ namespace fc {
|
|||
TYPE( TYPE* ); \
|
||||
TYPE( TYPE&& ); \
|
||||
TYPE( const TYPE& ); \
|
||||
TYPE( TYPE& ); \
|
||||
template<typename A1> \
|
||||
TYPE( A1&& ); \
|
||||
template<typename A1,typename A2> \
|
||||
|
|
@ -155,7 +154,8 @@ namespace fc {
|
|||
#define FC_START_SHARED_IMPL( SCOPED_TYPE ) \
|
||||
namespace fc { \
|
||||
template<> \
|
||||
struct fc::shared_impl<SCOPED_TYPE>::impl : public fc::retainable { \
|
||||
class fc::shared_impl<SCOPED_TYPE>::impl : public fc::retainable { \
|
||||
public:\
|
||||
SCOPED_TYPE self() { return SCOPED_TYPE(this); } \
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/log.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
|
|
@ -30,24 +31,20 @@ namespace fc {
|
|||
:_ptr(o.get()) {
|
||||
if(_ptr != nullptr ) _ptr->retain();
|
||||
}
|
||||
shared_ptr( const shared_ptr& o )
|
||||
:_ptr(o.get()) {
|
||||
if(_ptr != nullptr ) _ptr->retain();
|
||||
}
|
||||
|
||||
shared_ptr( T* t, bool inc = false )
|
||||
:_ptr(t) { if( inc && t != nullptr) t->retain(); }
|
||||
|
||||
shared_ptr():_ptr(nullptr){}
|
||||
|
||||
shared_ptr( const shared_ptr& p ) {
|
||||
_ptr = p._ptr;
|
||||
if( _ptr ) _ptr->retain();
|
||||
}
|
||||
shared_ptr( shared_ptr& p ) {
|
||||
_ptr = p._ptr;
|
||||
if( _ptr != nullptr ) _ptr->retain();
|
||||
}
|
||||
shared_ptr( shared_ptr&& p ) {
|
||||
_ptr = p._ptr;
|
||||
p._ptr = nullptr;
|
||||
}
|
||||
|
||||
shared_ptr( shared_ptr&& p )
|
||||
:_ptr(p._ptr){ p._ptr = nullptr; }
|
||||
|
||||
~shared_ptr() { if( nullptr != _ptr ) { _ptr->release(); } }
|
||||
|
||||
shared_ptr& reset( T* v = nullptr, bool inc = false ) {
|
||||
|
|
@ -60,9 +57,9 @@ namespace fc {
|
|||
|
||||
shared_ptr& operator=(const shared_ptr& p ) {
|
||||
if( _ptr == p._ptr ) return *this;
|
||||
if( p._ptr != nullptr ) p._ptr->retain();
|
||||
if( _ptr != nullptr ) _ptr->release();
|
||||
_ptr = p._ptr;
|
||||
if( _ptr != nullptr ) _ptr->retain();
|
||||
return *this;
|
||||
}
|
||||
shared_ptr& operator=(shared_ptr&& p ) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace fc {
|
|||
struct file_attrib {
|
||||
file_attrib();
|
||||
|
||||
size_t size;
|
||||
uint64_t size;
|
||||
uint32_t uid;
|
||||
uint32_t gid;
|
||||
uint32_t permissions;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ namespace fc {
|
|||
|
||||
class istream;
|
||||
class ostream;
|
||||
class string;
|
||||
|
||||
namespace ssh {
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace std {
|
|||
}
|
||||
|
||||
namespace fc {
|
||||
// typedef std::string string;
|
||||
/**
|
||||
* Including <string> results in 4000 lines of code
|
||||
* that must be included to build your header. This
|
||||
|
|
@ -55,17 +56,17 @@ namespace fc {
|
|||
const_iterator begin()const;
|
||||
const_iterator end()const;
|
||||
|
||||
char& operator[](uint64_t idx);
|
||||
const char& operator[](uint64_t idx)const;
|
||||
char& operator[](size_t idx);
|
||||
const char& operator[](size_t idx)const;
|
||||
|
||||
string& operator =( const string& c );
|
||||
string& operator =( string&& c );
|
||||
|
||||
void reserve( uint64_t );
|
||||
uint64_t size()const;
|
||||
uint64_t find( char c, uint64_t pos = 0 )const;
|
||||
void reserve( size_t );
|
||||
size_t size()const;
|
||||
size_t find( char c, size_t pos = 0 )const;
|
||||
|
||||
void resize( uint64_t s );
|
||||
void resize( size_t s );
|
||||
void clear();
|
||||
|
||||
const char* c_str()const;
|
||||
|
|
@ -82,11 +83,11 @@ namespace fc {
|
|||
friend string operator + ( const string&, const string& );
|
||||
friend string operator + ( const string&, char c );
|
||||
|
||||
fc::string substr( int32_t start, int32_t len = 0x7fffffff )const;
|
||||
fc::string substr( size_t start, size_t len = fc::string::npos )const;
|
||||
|
||||
private:
|
||||
fc::fwd<std::string,32> my;
|
||||
};
|
||||
|
||||
} // namespace FC
|
||||
} // namespace fc
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
#ifndef _FC_SUPER_FAST_HASH_HPP_
|
||||
#define _FC_SUPER_FAST_HASH_HPP_
|
||||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
class string;
|
||||
uint32_t super_fast_hash (const char * data, int len);
|
||||
uint32_t super_fast_hash (const fc::string& str );
|
||||
}
|
||||
|
||||
|
||||
#endif // _FC_SUPER_FAST_HASH_HPP_
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
#define _FC_THREAD_HPP_
|
||||
#include <fc/task.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
class string;
|
||||
class time_point;
|
||||
class microseconds;
|
||||
|
||||
|
|
|
|||
|
|
@ -85,9 +85,8 @@ namespace fc {
|
|||
struct tuple<BOOST_PP_ENUM_PARAMS(n,A)> { \
|
||||
enum size_enum { size = n }; \
|
||||
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){} \
|
||||
explicit 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( 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(){}\
|
||||
template<typename V>\
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
namespace fc {
|
||||
class string;
|
||||
class value;
|
||||
template<typename T> class get_typename{};
|
||||
template<> struct get_typename<int32_t> { static const char* name() { return "int32_t"; } };
|
||||
template<> struct get_typename<int64_t> { static const char* name() { return "int64_t"; } };
|
||||
|
|
@ -16,4 +17,5 @@ namespace fc {
|
|||
template<> struct get_typename<char> { static const char* name() { return "char"; } };
|
||||
template<> struct get_typename<void> { static const char* name() { return "char"; } };
|
||||
template<> struct get_typename<string> { static const char* name() { return "string"; } };
|
||||
template<> struct get_typename<value> { static const char* name() { return "value"; } };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,12 @@
|
|||
#include <fc/string.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/aligned.hpp>
|
||||
#include <fc/typename.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
namespace fc {
|
||||
template<BOOST_PP_ENUM_PARAMS(9, typename A)> struct tuple;
|
||||
|
||||
|
|
@ -23,16 +27,17 @@ namespace fc {
|
|||
*/
|
||||
class value {
|
||||
public:
|
||||
struct key_val;
|
||||
struct object {
|
||||
typedef fc::vector<key_val>::const_iterator const_iterator;
|
||||
class key_val;
|
||||
class object {
|
||||
public:
|
||||
typedef std::vector<key_val>::const_iterator const_iterator;
|
||||
//fc::string type;
|
||||
fc::vector<key_val> fields;
|
||||
std::vector<key_val> fields;
|
||||
};
|
||||
struct array {
|
||||
class array {
|
||||
public:
|
||||
array( size_t s = 0 ):fields(s){}
|
||||
//fc::string type;
|
||||
fc::vector<value> fields;
|
||||
std::vector<value> fields;
|
||||
};
|
||||
|
||||
struct const_visitor {
|
||||
|
|
@ -85,21 +90,28 @@ namespace fc {
|
|||
|
||||
value& operator=( value&& v );
|
||||
value& operator=( const value& v );
|
||||
value& operator=( value& v );
|
||||
|
||||
|
||||
/**
|
||||
* Include fc/value_cast.hpp for implementation
|
||||
*/
|
||||
template<typename T>
|
||||
explicit value( T&& v );
|
||||
explicit value( const T& v );
|
||||
|
||||
template<typename T>
|
||||
value& operator=( T&& v ) {
|
||||
value tmp(fc::forward<T>(v) );
|
||||
fc_swap(*this,tmp);
|
||||
return *this;
|
||||
value& operator=( const T& v );
|
||||
/*
|
||||
{
|
||||
slog("operator= %p", this);
|
||||
value tmp(fc::forward<T>(v));
|
||||
slog( "swap...tmp %p this %p", &tmp, this );
|
||||
T tmp = fc::move(a);
|
||||
a = fc::move(b);
|
||||
b = fc::move(tmp);
|
||||
slog( "return" );
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
||||
/** used to iterate over object fields, use array index + size to iterate over array */
|
||||
object::const_iterator find( const char* key )const;
|
||||
|
|
@ -145,30 +157,45 @@ namespace fc {
|
|||
template<typename T>
|
||||
friend T value_cast( const value& v );
|
||||
|
||||
aligned<24> holder;
|
||||
aligned<40> holder;
|
||||
};
|
||||
bool operator == ( const value& v, std::nullptr_t );
|
||||
bool operator != ( const value& v, std::nullptr_t );
|
||||
|
||||
struct value::key_val {
|
||||
class value::key_val {
|
||||
public:
|
||||
key_val(){};
|
||||
|
||||
key_val( fc::string k, value v = value())
|
||||
:key(fc::move(k)),val(fc::move(v)){}
|
||||
key_val( fc::string k )
|
||||
:key(fc::move(k)){}
|
||||
|
||||
// key_val( fc::string k, value v )
|
||||
// :key(fc::move(k)),val(fc::move(v)){
|
||||
// slog("key_val(key,val)");}
|
||||
|
||||
key_val( const fc::string& k, const value& v )
|
||||
:key(k),val(v){}
|
||||
|
||||
key_val( key_val&& m )
|
||||
:key(fc::move(m.key)),val(fc::move(m.val)){}
|
||||
:key(fc::move(m.key)),val(fc::move(m.val)){ }
|
||||
|
||||
key_val( const key_val& m )
|
||||
:key(m.key),val(m.val){}
|
||||
|
||||
~key_val(){ }
|
||||
|
||||
key_val& operator=( key_val&& k ) {
|
||||
key = fc::move(k.key);
|
||||
val = fc::move(k.val);
|
||||
slog( "swap key");
|
||||
fc_swap( key, k.key );
|
||||
slog( "swap val");
|
||||
fc_swap( val, k.val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
key_val& operator=( const key_val& k ) {
|
||||
slog( "copy key");
|
||||
key = k.key;
|
||||
slog( "copy val");
|
||||
val = k.val;
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,6 +274,7 @@ namespace fc {
|
|||
virtual value_holder* copy_helper( char* c )const;
|
||||
};
|
||||
|
||||
void new_value_holder_void( value* v );
|
||||
} // namespace detail
|
||||
|
||||
|
||||
|
|
@ -300,9 +301,15 @@ namespace fc {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
value::value( T&& v ) {
|
||||
new (holder) detail::value_holder();
|
||||
fc::pack( *this, fc::forward<T>(v) );
|
||||
value::value( const T& v ) {
|
||||
detail::new_value_holder_void(this);
|
||||
fc::pack( *this, v);
|
||||
}
|
||||
template<typename T>
|
||||
value& value::operator=( const T& v ) {
|
||||
this->~value();
|
||||
value tmp(v);
|
||||
*this = fc::move(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace fc {
|
|||
inline void pack( fc::value& jsv, const int16_t& v ) { jsv = v; }
|
||||
inline void pack( fc::value& jsv, const int32_t& v ) { jsv = v; }
|
||||
inline void pack( fc::value& jsv, const int64_t& v ) { jsv = v; }
|
||||
inline void pack( fc::value& jsv, const fc::string& v ) { jsv = v; }
|
||||
inline void pack( fc::value& jsv, const fc::string& v ) { jsv = value(v); }
|
||||
inline void pack( fc::value& jsv, fc::string& v ) { jsv = v; }
|
||||
inline void pack( fc::value& jsv, fc::string&& v ) { jsv = fc::move(v); }
|
||||
inline void pack( fc::value& jsv, const char* v ) { jsv = fc::string(v); }
|
||||
|
|
@ -93,7 +93,8 @@ namespace fc {
|
|||
*/
|
||||
template<typename T>
|
||||
inline void pack_helper( const T& v, const char* name )const {
|
||||
fc::pack( obj[name], v );
|
||||
value* o = &obj[name];
|
||||
fc::pack( *o, v );
|
||||
}
|
||||
template<typename T>
|
||||
inline void pack_helper( const fc::optional<T>& v, const char* name )const {
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ namespace fc {
|
|||
namespace detail {
|
||||
template<typename T>
|
||||
struct data {
|
||||
uint64_t size;
|
||||
uint64_t capacity;
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
T first;
|
||||
|
||||
static data* allocate( uint64_t cap ) {
|
||||
static data* allocate( size_t cap ) {
|
||||
data* d = nullptr;
|
||||
if( cap ){
|
||||
d = (data*)malloc(sizeof(data) + sizeof(T)*(static_cast<size_t>(cap)-1));
|
||||
|
|
@ -26,7 +26,7 @@ namespace fc {
|
|||
d->size = 0;
|
||||
return d;
|
||||
}
|
||||
static data* reallocate( data* d, uint64_t cap ) {
|
||||
static data* reallocate( data* d, size_t cap ) {
|
||||
if( cap ){
|
||||
d = (data*)realloc(d,sizeof(data) + sizeof(T)*(static_cast<size_t>(cap)-1));
|
||||
d->capacity = static_cast<size_t>(cap);
|
||||
|
|
@ -62,7 +62,7 @@ namespace fc {
|
|||
resize(e-b);
|
||||
if( size() ) memcpy( data(), b, static_cast<size_t>(size()) );
|
||||
}
|
||||
vector_impl(uint64_t s):_data(nullptr){
|
||||
vector_impl(size_t s):_data(nullptr){
|
||||
resize(s);
|
||||
}
|
||||
~vector_impl() {
|
||||
|
|
@ -70,8 +70,8 @@ namespace fc {
|
|||
}
|
||||
|
||||
|
||||
uint64_t size()const { return _data ? _data->size : 0; }
|
||||
uint64_t capacity()const { return _data ? _data->capacity : 0; }
|
||||
size_t size()const { return _data ? _data->size : 0; }
|
||||
size_t capacity()const { return _data ? _data->capacity : 0; }
|
||||
|
||||
T& back() { return (&_data->first)[-1+_data->size]; }
|
||||
const T& back()const { return (&_data->first)[-1+_data->size]; }
|
||||
|
|
@ -85,11 +85,11 @@ namespace fc {
|
|||
iterator end() { return _data ? (&back())+1: 0;}
|
||||
const_iterator end()const { return _data ? (&back())+1: 0;}
|
||||
|
||||
T& operator[]( uint64_t i ) { return (&_data->first)[i]; }
|
||||
const T& operator[]( uint64_t i )const { return (&_data->first)[i]; }
|
||||
T& operator[]( size_t i ) { return (&_data->first)[i]; }
|
||||
const T& operator[]( size_t i )const { return (&_data->first)[i]; }
|
||||
|
||||
T& at( uint64_t i ) { return (&_data->first)[i]; }
|
||||
const T& at( uint64_t i )const { return (&_data->first)[i]; }
|
||||
T& at( size_t i ) { return (&_data->first)[i]; }
|
||||
const T& at( size_t i )const { return (&_data->first)[i]; }
|
||||
|
||||
void pop_back() { erase( &back() ); }
|
||||
|
||||
|
|
@ -100,11 +100,11 @@ namespace fc {
|
|||
_data = nullptr;
|
||||
}
|
||||
|
||||
void reserve( uint64_t i ) {
|
||||
void reserve( size_t i ) {
|
||||
_data = detail::data<T>::reallocate( _data, i );
|
||||
}
|
||||
|
||||
void resize( uint64_t i ) {
|
||||
void resize( size_t i ) {
|
||||
if( capacity() < i ) {
|
||||
if( _data )
|
||||
_data = detail::data<T>::reallocate( _data, i );
|
||||
|
|
@ -122,7 +122,7 @@ namespace fc {
|
|||
|
||||
template<typename U>
|
||||
iterator insert( const_iterator loc, U&& t ) {
|
||||
uint64_t pos = loc - begin();
|
||||
size_t pos = loc - begin();
|
||||
resize( size()+1 );
|
||||
char* src = &at(pos);
|
||||
if( src != &back() )
|
||||
|
|
@ -134,11 +134,11 @@ namespace fc {
|
|||
iterator insert( iterator pos, const_iterator first, const_iterator last ) {
|
||||
if( first >= last ) return pos;
|
||||
|
||||
uint64_t loc = pos - begin();
|
||||
uint64_t right_size = size() - loc;
|
||||
size_t loc = pos - begin();
|
||||
size_t right_size = size() - loc;
|
||||
resize( size() + (last-first) );
|
||||
char* src = &at(loc);
|
||||
uint64_t s = last-first;
|
||||
size_t s = last-first;
|
||||
memmove( src + s, src, right_size );
|
||||
memcpy( src, first, s );
|
||||
_data->size += (last-first);
|
||||
|
|
@ -201,7 +201,7 @@ namespace fc {
|
|||
}
|
||||
}
|
||||
|
||||
vector_impl(uint64_t s):_data(nullptr){
|
||||
vector_impl(size_t s):_data(nullptr){
|
||||
resize(s);
|
||||
}
|
||||
~vector_impl() {
|
||||
|
|
@ -209,8 +209,8 @@ namespace fc {
|
|||
}
|
||||
|
||||
|
||||
uint64_t size()const { return _data ? _data->size : 0; }
|
||||
uint64_t capacity()const { return _data ? _data->capacity : 0; }
|
||||
size_t size()const { return _data ? _data->size : 0; }
|
||||
size_t capacity()const { return _data ? _data->capacity : 0; }
|
||||
|
||||
T& back() { return (&_data->first)[-1+_data->size]; }
|
||||
const T& back()const { return (&_data->first)[-1+_data->size]; }
|
||||
|
|
@ -223,11 +223,11 @@ namespace fc {
|
|||
const_iterator begin()const { return _data ? &front() : 0;}
|
||||
const_iterator end()const { return _data ? (&back())+1: 0;}
|
||||
|
||||
T& operator[]( uint64_t i ) { return (&_data->first)[i]; }
|
||||
const T& operator[]( uint64_t i )const { return (&_data->first)[i]; }
|
||||
T& operator[]( size_t i ) { return (&_data->first)[i]; }
|
||||
const T& operator[]( size_t i )const { return (&_data->first)[i]; }
|
||||
|
||||
T& at( uint64_t i ) { return (&_data->first)[i]; }
|
||||
const T& at( uint64_t i )const { return (&_data->first)[i]; }
|
||||
T& at( size_t i ) { return (&_data->first)[i]; }
|
||||
const T& at( size_t i )const { return (&_data->first)[i]; }
|
||||
|
||||
void pop_back() { erase( &back() ); }
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ namespace fc {
|
|||
this->_data = nullptr;
|
||||
}
|
||||
|
||||
void reserve( uint64_t i ) {
|
||||
void reserve( size_t i ) {
|
||||
if( nullptr != this->_data && i <= this->_data->capacity )
|
||||
return;
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ namespace fc {
|
|||
if( _ndata ) free(_ndata);
|
||||
}
|
||||
|
||||
void resize( uint64_t i ) {
|
||||
void resize( size_t i ) {
|
||||
this->reserve(i);
|
||||
while( i < this->_data->size ) {
|
||||
this->back().~T();
|
||||
|
|
@ -285,7 +285,7 @@ namespace fc {
|
|||
|
||||
template<typename U>
|
||||
iterator insert( const_iterator loc, U&& t ) {
|
||||
uint64_t pos = loc - this->begin();
|
||||
size_t pos = loc - this->begin();
|
||||
this->reserve( this->size()+1 );
|
||||
loc = this->begin() + pos;
|
||||
if( this->size() != 0 ) {
|
||||
|
|
@ -351,7 +351,7 @@ namespace fc {
|
|||
class vector : public detail::vector_impl<T, typename fc::is_class<T>::type> {
|
||||
public:
|
||||
vector(){}
|
||||
vector( uint64_t s ):detail::vector_impl<T, typename fc::is_class<T>::type>(s){}
|
||||
vector( size_t s ):detail::vector_impl<T, typename fc::is_class<T>::type>(s){}
|
||||
vector( const vector& v ):detail::vector_impl<T, typename fc::is_class<T>::type>(v){}
|
||||
vector( vector&& v ):detail::vector_impl<T, typename fc::is_class<T>::type>(fc::move(v)){}
|
||||
|
||||
|
|
|
|||
|
|
@ -606,7 +606,7 @@ inline bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vch
|
|||
|
||||
namespace fc {
|
||||
|
||||
fc::string to_base58( const char* d, uint32_t s ) {
|
||||
fc::string to_base58( const char* d, size_t s ) {
|
||||
return EncodeBase58( (const unsigned char*)d, (const unsigned char*)d+s ).c_str();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,12 +83,12 @@ fc::string error_frame::to_detail_string()const {
|
|||
}
|
||||
fc::string error_frame::to_string()const {
|
||||
fc::stringstream ss;
|
||||
int64_t prev = 0;
|
||||
size_t prev = 0;
|
||||
auto next = desc.find( '$' );
|
||||
while( prev != int64_t(fc::string::npos) && prev < int64_t(desc.size()) ) {
|
||||
while( prev != size_t(fc::string::npos) && prev < size_t(desc.size()) ) {
|
||||
// slog( "prev: %d next %d %s", prev, next, desc.substr(prev,next).c_str() );
|
||||
// print everything from the last pos until the first '$'
|
||||
ss << desc.substr( prev, next-prev );
|
||||
ss << desc.substr( prev, size_t(next-prev) );
|
||||
|
||||
// if we got to the end, return it.
|
||||
if( next == string::npos ) { return ss.str(); }
|
||||
|
|
@ -128,7 +128,7 @@ fc::string error_frame::to_string()const {
|
|||
}
|
||||
fc::string error_report::to_string()const {
|
||||
fc::stringstream ss;
|
||||
for( int i = 0; i < stack.size(); ++i ) {
|
||||
for( uint32_t i = 0; i < stack.size(); ++i ) {
|
||||
ss << stack[i].to_string() << "\n";
|
||||
}
|
||||
return ss.str();
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ namespace fc {
|
|||
void create_directories( const path& p ) { boost::filesystem::create_directories(p); }
|
||||
bool is_directory( const path& p ) { return boost::filesystem::is_directory(p); }
|
||||
bool is_regular_file( const path& p ) { return boost::filesystem::is_regular_file(p); }
|
||||
uint64_t file_size( const path& p ) { return boost::filesystem::file_size(p); }
|
||||
size_t file_size( const path& p ) { return boost::filesystem::file_size(p); }
|
||||
void copy( const path& f, const path& t ) { boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); }
|
||||
bool remove( const path& f ) { return boost::filesystem::remove( f ); }
|
||||
fc::path canonical( const fc::path& p ) { return boost::filesystem::canonical(p); }
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace fc {
|
|||
my->ifs.open( file.string().c_str(), std::ios::binary );
|
||||
}
|
||||
size_t ifstream::readsome( char* buf, size_t len ) {
|
||||
return my->ifs.readsome( buf, len );
|
||||
return size_t(my->ifs.readsome( buf, len ));
|
||||
}
|
||||
ifstream& ifstream::read( char* buf, size_t len ) {
|
||||
my->ifs.read(buf,len);
|
||||
|
|
@ -61,6 +61,7 @@ namespace fc {
|
|||
case cur: my->ifs.seekg( p, std::ios_base::cur ); return *this;
|
||||
case end: my->ifs.seekg( p, std::ios_base::end ); return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
void ifstream::close() { return my->ifs.close(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -103,10 +103,10 @@ namespace fc {
|
|||
|
||||
size_t cin_t::readsome( char* buf, size_t len ) {
|
||||
cin_buffer& b = get_cin_buffer();
|
||||
size_t avail = b.write_pos - b.read_pos;
|
||||
avail = (fc::min)(len,avail);
|
||||
size_t u = 0;
|
||||
while( avail && len ) {
|
||||
int64_t avail = b.write_pos - b.read_pos;
|
||||
avail = (fc::min)(int64_t(len),avail);
|
||||
int64_t u = 0;
|
||||
while( (avail>0) && (len>0) ) {
|
||||
*buf = b.buf[b.read_pos&0xfffff];
|
||||
++b.read_pos;
|
||||
++buf;
|
||||
|
|
@ -114,7 +114,7 @@ namespace fc {
|
|||
--len;
|
||||
++u;
|
||||
}
|
||||
return u;
|
||||
return size_t(u);
|
||||
}
|
||||
|
||||
cin_t::~cin_t() {
|
||||
|
|
|
|||
16
src/json.cpp
16
src/json.cpp
|
|
@ -6,6 +6,8 @@
|
|||
#include <fc/interprocess/file_mapping.hpp>
|
||||
#include <fc/error_report.hpp>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace fc { namespace json {
|
||||
|
|
@ -21,7 +23,7 @@ namespace fc { namespace json {
|
|||
string(){}
|
||||
|
||||
string& operator=( const fc::string& s ) {
|
||||
json_data = fc::vector<char>(s.begin(),s.end());
|
||||
json_data = std::vector<char>(s.begin(),s.end());
|
||||
return *this;
|
||||
}
|
||||
template<typename T>
|
||||
|
|
@ -38,7 +40,7 @@ namespace fc { namespace json {
|
|||
json_data = s.json_data;
|
||||
return *this;
|
||||
}
|
||||
fc::vector<char> json_data;
|
||||
std::vector<char> json_data;
|
||||
};
|
||||
|
||||
} }
|
||||
|
|
@ -444,6 +446,7 @@ struct temp_set {
|
|||
* Warn on extra ',' or missing ','
|
||||
*/
|
||||
void read_values( fc::value::array& a, char* in, char* end, error_collector& ec ) {
|
||||
if( in >= end ) return;
|
||||
char* ve = 0;
|
||||
char* v = read_value( in, end, ve );
|
||||
while( *v == ',' ) {
|
||||
|
|
@ -571,7 +574,7 @@ char* read_key_val( std::map<fc::string,fc::json::string>& obj, bool sc, char* i
|
|||
temp_set ntemp(name_end,'\0');
|
||||
temp_set vtemp(val_end,'\0');
|
||||
//slog( "name: '%1%'", fc::string(name,name_end) );
|
||||
obj[name] = fc::vector<char>(val,val_end);
|
||||
obj[name] = std::vector<char>(val,val_end);
|
||||
// obj.fields.push_back( key_val( name, to_value( val, val_end, ec ) ) );
|
||||
return val_end;
|
||||
}
|
||||
|
|
@ -664,7 +667,6 @@ char* read_key_val( fc::value::object& obj, bool sc, char* in, char* end, error_
|
|||
}
|
||||
temp_set ntemp(name_end,'\0');
|
||||
temp_set vtemp(val_end,'\0');
|
||||
//slog( "name: '%1%'", fc::string(name,name_end) );
|
||||
obj.fields.push_back( fc::value::key_val( name, to_value( val, val_end, ec ) ) );
|
||||
return val_end;
|
||||
}
|
||||
|
|
@ -701,7 +703,7 @@ std::map<fc::string,fc::json::string> read_key_vals( char* in, char* end, error_
|
|||
*/
|
||||
fc::value to_value( fc::vector<char>&& v, error_collector& ec ) {
|
||||
if( v.size() == 0 ) return fc::value();
|
||||
return to_value( &v.front(), &v.front() + v.size(), ec );
|
||||
return to_value( v.data(), v.data() + v.size(), ec );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -945,7 +947,9 @@ fc::string pretty_print( fc::vector<char>&& v, uint8_t indent ) {
|
|||
}
|
||||
|
||||
value from_string( const fc::string& s ) {
|
||||
return from_string( s.c_str(), s.c_str() + s.size() );
|
||||
std::vector<char> v(s.begin(),s.end());
|
||||
//slog( "from_string( '%s' )", s.c_str() );
|
||||
return from_string( v.data(), v.data()+v.size() );
|
||||
}
|
||||
value from_string( fc::vector<char>&& v ) {
|
||||
error_collector ec;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <fc/sstream.hpp>
|
||||
#include <fc/thread.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace fc { namespace json {
|
||||
|
||||
class rpc_stream_connection::impl : public fc::retainable {
|
||||
|
|
@ -32,6 +34,8 @@ namespace fc { namespace json {
|
|||
fc::string line;
|
||||
fc::getline( in, line );
|
||||
while( !in.eof() ) {
|
||||
// std::cerr<<"\n**line size: "<<line.size()<<"\n\n";
|
||||
// slog( "line size: '%d'", line.size() );
|
||||
try {
|
||||
fc::value v= fc::json::from_string( line );
|
||||
self.handle_message(v);
|
||||
|
|
@ -51,11 +55,12 @@ namespace fc { namespace json {
|
|||
|
||||
rpc_stream_connection::rpc_stream_connection( fc::istream& i, fc::ostream& o )
|
||||
:my( new impl(i,o,*this) ){
|
||||
slog( "%p", this );
|
||||
}
|
||||
rpc_stream_connection::rpc_stream_connection(){ }
|
||||
rpc_stream_connection::rpc_stream_connection(const rpc_stream_connection& c):my(c.my){}
|
||||
rpc_stream_connection::rpc_stream_connection(){ slog( "%p...",this); }
|
||||
rpc_stream_connection::rpc_stream_connection(const rpc_stream_connection& c):my(c.my){ slog( "%p",this); }
|
||||
rpc_stream_connection::~rpc_stream_connection(){
|
||||
// slog( "%p", my.get() );
|
||||
slog( "my %p", my.get() );
|
||||
}
|
||||
|
||||
// the life of the streams must exceed the life of all copies
|
||||
|
|
|
|||
12
src/log.cpp
12
src/log.cpp
|
|
@ -15,7 +15,6 @@ namespace fc {
|
|||
const char* thread_name();
|
||||
void* thread_ptr();
|
||||
|
||||
/*
|
||||
const char* short_name( const char* file_name ) {
|
||||
const char* end = file_name + strlen(file_name);
|
||||
--end;
|
||||
|
|
@ -27,7 +26,6 @@ namespace fc {
|
|||
}
|
||||
return file_name;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#define isatty _isatty
|
||||
|
|
@ -36,14 +34,13 @@ namespace fc {
|
|||
|
||||
void log( const char* color, const char* file_name, size_t line_num,
|
||||
const char* method_name, const char* format, ... ) {
|
||||
fc::unique_lock<boost::mutex> lock(log_mutex());
|
||||
#ifndef WIN32
|
||||
if(isatty(fileno(stderr)))
|
||||
std::cerr<<"\r"<<color;
|
||||
fprintf( stderr, "\r%s",color);
|
||||
#endif
|
||||
|
||||
fprintf( stderr, "%-15s %-15s %-5zd %-15s ", thread_name(), fc::path(file_name).filename().generic_string().c_str(), line_num, method_name );
|
||||
//std::cerr<<thread_ptr()<< thread_name()<< short_name(file_name)<< line_num<< method_name ;
|
||||
fc::unique_lock<boost::mutex> lock(log_mutex());
|
||||
// fc::string sname = fc::path(file_name).filename().generic_string();
|
||||
fprintf( stderr, "%-15s %-15s %-5d %-15s ", thread_name(), short_name(file_name), int(line_num), method_name );
|
||||
va_list args;
|
||||
va_start(args,format);
|
||||
vfprintf( stderr, format, args );
|
||||
|
|
@ -54,6 +51,7 @@ namespace fc {
|
|||
#endif
|
||||
fprintf( stderr, "\n" );
|
||||
fflush( stderr );
|
||||
return;
|
||||
}
|
||||
|
||||
/** used to add extra fields to be printed (thread,fiber,time,etc) */
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace fc {
|
||||
void pack( fc::value& v, const fc::public_key_t& s ) {
|
||||
fc::vector<char> ve = fc::raw::pack( s );
|
||||
v = to_base58( ve.data(), ve.size() );
|
||||
v = to_base58( ve.data(), size_t(ve.size()) );
|
||||
}
|
||||
void unpack( const fc::value& v, fc::public_key_t& s ) {
|
||||
try {
|
||||
|
|
@ -71,9 +71,9 @@ namespace fc {
|
|||
bool verify_data( const char* key, uint32_t key_size, uint32_t pe, const sha1& digest, const char* sig )
|
||||
{
|
||||
RSA* pub = get_pub( key,key_size,pe);
|
||||
bool v = RSA_verify( NID_sha1, (const uint8_t*)digest.data(), 20, (uint8_t*)sig, key_size, pub );
|
||||
auto v = RSA_verify( NID_sha1, (const uint8_t*)digest.data(), 20, (uint8_t*)sig, key_size, pub );
|
||||
RSA_free(pub);
|
||||
return v;
|
||||
return 0 != v;
|
||||
}
|
||||
bool sign_data( const fc::vector<char>& key, uint32_t key_size, uint32_t pe, const sha1& digest, char* sig )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ fc::future<int> process::exec( const fc::path& exe, fc::vector<fc::string>&& arg
|
|||
my->pctx.streams[boost::process::stdin_id] = bp::behavior::close();
|
||||
|
||||
std::vector<std::string> a;
|
||||
a.reserve(args.size());
|
||||
a.reserve(size_t(args.size()));
|
||||
for( uint32_t i = 0; i < args.size(); ++i ) {
|
||||
a.push_back( args[i] );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -478,7 +478,7 @@ namespace fc { namespace ssh {
|
|||
}
|
||||
}
|
||||
try {
|
||||
uint64_t wrote = 0;
|
||||
size_t wrote = 0;
|
||||
char* pos = reinterpret_cast<char*>(mr.get_address());
|
||||
while( progress( wrote, fsize ) && wrote < fsize ) {
|
||||
int r = libssh2_channel_write( chan, pos, fsize - wrote );
|
||||
|
|
@ -800,7 +800,7 @@ namespace fc { namespace ssh {
|
|||
}
|
||||
|
||||
bool detail::process_istream::eof()const {
|
||||
return libssh2_channel_eof( proc.chan );
|
||||
return 0 != libssh2_channel_eof( proc.chan );
|
||||
}
|
||||
|
||||
ostream& detail::process_ostream::write( const char* buf, size_t len ) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace fc {
|
|||
return *this;
|
||||
}
|
||||
size_t stringstream::readsome( char* buf, size_t len ) {
|
||||
return my->ss.readsome(buf,len);
|
||||
return static_cast<size_t>(my->ss.readsome(buf,len));
|
||||
}
|
||||
istream& stringstream::read( char* buf, size_t len ) {
|
||||
my->ss.read(buf,len);
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ namespace fc {
|
|||
|
||||
string::string(const char* s, int l) :my(s,l){ }
|
||||
string::string(){}
|
||||
string::string( const string& c ):my(c.my) { }
|
||||
string::string( string&& m ):my(fc::move(m.my)) {}
|
||||
string::string( const fc::string& c ):my(*c.my) { }
|
||||
string::string( string&& m ):my(fc::move(*m.my)) {}
|
||||
string::string( const char* c ):my(c){}
|
||||
string::string( const_iterator b, const_iterator e ):my(b,e){}
|
||||
string::string( const std::string& s ):my(s) {}
|
||||
|
|
@ -27,16 +27,16 @@ namespace fc {
|
|||
string::const_iterator string::begin()const { return my->c_str(); }
|
||||
string::const_iterator string::end()const { return my->c_str() + my->size(); }
|
||||
|
||||
char& string::operator[](uint64_t idx) { return (*my)[idx]; }
|
||||
const char& string::operator[](uint64_t idx)const { return (*my)[idx]; }
|
||||
char& string::operator[](size_t idx) { return (*my)[idx]; }
|
||||
const char& string::operator[](size_t idx)const { return (*my)[idx]; }
|
||||
|
||||
void string::reserve(uint64_t r) { my->reserve(r); }
|
||||
uint64_t string::size()const { return my->size(); }
|
||||
uint64_t string::find(char c, uint64_t p)const { return my->find(c,p); }
|
||||
void string::reserve(size_t r) { my->reserve(r); }
|
||||
size_t string::size()const { return my->size(); }
|
||||
size_t string::find(char c, size_t p)const { return my->find(c,p); }
|
||||
void string::clear() { my->clear(); }
|
||||
void string::resize( uint64_t s ) { my->resize(s); }
|
||||
void string::resize( size_t s ) { my->resize(s); }
|
||||
|
||||
fc::string string::substr( int32_t start, int32_t len )const { return my->substr(start,len); }
|
||||
fc::string string::substr( size_t start, size_t len )const { return my->substr(start,len); }
|
||||
const char* string::c_str()const { return my->c_str(); }
|
||||
|
||||
bool string::operator == ( const char* s )const { return *my == s; }
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ namespace fc {
|
|||
template<typename T>
|
||||
struct value_holder_impl : value_holder {
|
||||
static_assert( !fc::is_class<T>::value, "only fundamental types can be stored without specialization" );
|
||||
value_holder_impl(){
|
||||
static_assert( sizeof(value_holder_impl) <= 40, "Validate size" );
|
||||
}
|
||||
virtual const char* type()const { return fc::get_typename<T>::name(); }
|
||||
virtual void visit( value::const_visitor&& v )const{ v(val); }
|
||||
virtual void visit( value_visitor&& v ) { v(val); }
|
||||
|
|
@ -53,14 +56,12 @@ namespace fc {
|
|||
virtual void visit( value::const_visitor&& v )const{ v(); }
|
||||
virtual void visit( value_visitor&& v ) { v(); }
|
||||
// typedef void_t T;
|
||||
/*
|
||||
virtual const char* type()const { return "void"; }
|
||||
virtual void clear() { }
|
||||
virtual size_t size()const { return 0; }
|
||||
// virtual const char* type()const { return "void"; }
|
||||
// virtual void clear() { }
|
||||
// virtual size_t size()const { return 0; }
|
||||
|
||||
virtual value_holder* move_helper( char* c ){ return new(c) value_holder_impl(); }
|
||||
virtual value_holder* copy_helper( char* c )const{ return new(c) value_holder_impl();}
|
||||
*/
|
||||
virtual value_holder* move_helper( char* c ){ return new(c) value_holder_impl<void>(); }
|
||||
virtual value_holder* copy_helper( char* c )const{ return new(c) value_holder_impl<void>();}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -68,7 +69,9 @@ namespace fc {
|
|||
template<>
|
||||
struct value_holder_impl<fc::string> : value_holder {
|
||||
template<typename V>
|
||||
value_holder_impl( V&& v ):val( fc::forward<V>(v) ){}
|
||||
value_holder_impl( V&& v ):val( fc::forward<V>(v) ){
|
||||
static_assert( sizeof(value_holder_impl<fc::string>) <= 40, "Validate size" );
|
||||
}
|
||||
|
||||
virtual const char* type()const { return "string"; }
|
||||
virtual void visit( value::const_visitor&& v )const { v(val); }
|
||||
|
|
@ -124,12 +127,17 @@ namespace fc {
|
|||
|
||||
value::array val;
|
||||
};
|
||||
static_assert( sizeof( value_holder_impl<value::object> ) <= 40, "sanity check" );
|
||||
static_assert( sizeof( value_holder_impl<value::array> ) <= 40, "sanity check" );
|
||||
|
||||
value_holder::~value_holder(){}
|
||||
const char* value_holder::type()const { return "void"; }
|
||||
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::move_helper( char* c ) { return new(c) value_holder_impl<void>(); }
|
||||
value_holder* value_holder::copy_helper( char* c )const { return new(c) value_holder_impl<void>(); }
|
||||
|
||||
void new_value_holder_void( value* v ) {
|
||||
new (v) value_holder_impl<void>();
|
||||
}
|
||||
|
||||
void value_holder::clear() {}
|
||||
size_t value_holder::size()const { return 0; }
|
||||
|
|
@ -150,7 +158,7 @@ namespace fc {
|
|||
value_holder* value_holder_impl<value::array>::copy_helper( char* c )const{ return new(c) value_holder_impl(val); }
|
||||
|
||||
void value_holder_impl<value::array>::clear() { val.fields.clear(); }
|
||||
size_t value_holder_impl<value::array>::size()const { return val.fields.size(); }
|
||||
size_t value_holder_impl<value::array>::size()const { return static_cast<size_t>(val.fields.size()); }
|
||||
void value_holder_impl<value::array>::visit( value::const_visitor&& v )const { v(val); }
|
||||
void value_holder_impl<value::array>::visit( value_visitor&& v ) { v(val); }
|
||||
void value_holder_impl<value::array>::push_back( value&& v ) { val.fields.push_back( fc::move(v) ); }
|
||||
|
|
@ -158,19 +166,19 @@ namespace fc {
|
|||
|
||||
void value_holder_impl<value::object>::visit( value::const_visitor&& v )const { v(val); }
|
||||
void value_holder_impl<value::object>::visit( value_visitor&& v ) { v(val); }
|
||||
value_holder* value_holder_impl<value::object>::move_helper( char* c ) { return new(c) value_holder_impl( fc::move(val) ); }
|
||||
value_holder* value_holder_impl<value::object>::copy_helper( char* c )const { return new(c) value_holder_impl(val); }
|
||||
value_holder* value_holder_impl<value::object>::move_helper( char* c ) { return new(c) value_holder_impl<value::object>( fc::move(val) ); }
|
||||
value_holder* value_holder_impl<value::object>::copy_helper( char* c )const { return new(c) value_holder_impl<value::object>(val); }
|
||||
void value_holder_impl<value::object>::reserve( size_t s ) { val.fields.reserve(s); }
|
||||
|
||||
void value_holder_impl<value::object>::clear() { val = value::object(); }
|
||||
size_t value_holder_impl<value::object>::size()const { return val.fields.size(); }
|
||||
} // namespace detail
|
||||
|
||||
static detail::value_holder* gh( aligned<24>& h ) {
|
||||
static detail::value_holder* gh( aligned<40>& h ) {
|
||||
return (detail::value_holder*)h._store._data;
|
||||
}
|
||||
static const detail::value_holder* gh( const aligned<24>& h ) {
|
||||
return (const detail::value_holder*)&h._store._data;
|
||||
static const detail::value_holder* gh( const aligned<40>& h ) {
|
||||
return (const detail::value_holder*)h._store._data;
|
||||
}
|
||||
|
||||
value::value() {
|
||||
|
|
@ -224,12 +232,15 @@ value::value( bool v){
|
|||
new (holder) detail::value_holder_impl<bool>(v);
|
||||
}
|
||||
value::value( fc::string&& v){
|
||||
static_assert( sizeof(holder) >= sizeof( detail::value_holder_impl<fc::string> ), "size check" );
|
||||
new (holder) detail::value_holder_impl<fc::string>(fc::move(v));
|
||||
}
|
||||
value::value( fc::string& v){
|
||||
static_assert( sizeof(holder) >= sizeof( detail::value_holder_impl<fc::string> ), "size check" );
|
||||
new (holder) detail::value_holder_impl<fc::string>(v);
|
||||
}
|
||||
value::value( const fc::string& v){
|
||||
static_assert( sizeof(holder) >= sizeof( detail::value_holder_impl<fc::string> ), "size check" );
|
||||
new (holder) detail::value_holder_impl<fc::string>(v);
|
||||
}
|
||||
value::value( value::object&& o ){
|
||||
|
|
@ -276,12 +287,6 @@ value& value::operator=( const value& v ){
|
|||
gh(v.holder)->copy_helper(holder);
|
||||
return *this;
|
||||
}
|
||||
value& value::operator=( value& v ){
|
||||
if( this == &v ) return *this;
|
||||
gh(holder)->~value_holder();
|
||||
gh(v.holder)->copy_helper(holder);
|
||||
return *this;
|
||||
}
|
||||
bool value::is_null()const {
|
||||
return strcmp(gh(holder)->type(), "void") == 0;
|
||||
}
|
||||
|
|
@ -298,7 +303,7 @@ value::object::const_iterator value::find( const char* key )const {
|
|||
return o->val.fields.end();
|
||||
}
|
||||
FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() );
|
||||
return nullptr;
|
||||
return value::object::const_iterator();
|
||||
}
|
||||
value::object::const_iterator value::begin()const {
|
||||
if( strcmp(gh(holder)->type(), "object") == 0 ) {
|
||||
|
|
@ -306,7 +311,8 @@ value::object::const_iterator value::begin()const {
|
|||
return o->val.fields.begin();
|
||||
}
|
||||
FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() );
|
||||
return nullptr;
|
||||
return value::object::const_iterator();
|
||||
//return nullptr;
|
||||
}
|
||||
value::object::const_iterator value::end()const {
|
||||
if( strcmp(gh(holder)->type(), "object" ) == 0 ) {
|
||||
|
|
@ -314,20 +320,22 @@ value::object::const_iterator value::end()const {
|
|||
return o->val.fields.end();
|
||||
}
|
||||
FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() );
|
||||
return nullptr;
|
||||
return value::object::const_iterator();
|
||||
//return nullptr;
|
||||
}
|
||||
value& value::operator[]( const char* key ) {
|
||||
if( strcmp(gh(holder)->type(), "object") == 0) {
|
||||
detail::value_holder_impl<value::object>* o = static_cast<detail::value_holder_impl<value::object>*>(gh(holder));
|
||||
detail::value_holder_impl<value::object>* o = dynamic_cast<detail::value_holder_impl<value::object>*>(gh(holder));
|
||||
for( auto i = o->val.fields.begin();
|
||||
i != o->val.fields.end(); ++i ) {
|
||||
if( strcmp( i->key.c_str(), key ) == 0 )
|
||||
return i->val;
|
||||
}
|
||||
o->val.fields.reserve(o->val.fields.size()+1);
|
||||
o->val.fields.push_back( key_val(key) );
|
||||
return o->val.fields.back().val;
|
||||
} else if (strcmp(gh(holder)->type(), "void" ) == 0 ) {
|
||||
new (holder) detail::value_holder_impl<value::object>(value::object());
|
||||
new (gh(holder)) detail::value_holder_impl<value::object>(value::object());
|
||||
return (*this)[key];
|
||||
}
|
||||
FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() );
|
||||
|
|
|
|||
|
|
@ -33,6 +33,21 @@ FC_STUB( test, (add)(namep_test)(sub)(sub1)(sub2)(sub3)(sub4)(sub5)(sub6)(sub7)(
|
|||
|
||||
int main( int argc, char** argv ) {
|
||||
try {
|
||||
slog( "Hello World\n" );
|
||||
fc::value v = std::string("goodbye");
|
||||
slog(".");
|
||||
fc::value v2;
|
||||
slog("..");
|
||||
v2["a"];
|
||||
slog("........ v2[a] %p = v %p", &v2["a"], &v);
|
||||
v2["a"] = v;
|
||||
slog("...");
|
||||
fc::value& b = v2["b"];
|
||||
slog( "....");
|
||||
b = std::string("hello");
|
||||
slog(".....");
|
||||
return 0;
|
||||
|
||||
fc::ptr<test> t( new test() );
|
||||
fc::json::rpc_tcp_server serv;
|
||||
serv.add_interface( t );
|
||||
|
|
|
|||
Loading…
Reference in a new issue