Update use of fc::string and fc::vector.
This commit is contained in:
parent
59a121d64b
commit
b07aed4a22
34 changed files with 199 additions and 533 deletions
|
|
@ -61,11 +61,7 @@ include_directories( vendor/boost_1.51/include )
|
|||
include_directories( ${Boost_INCLUDE_DIR} )
|
||||
include_directories( ${OPENSSL_INCLUDE_DIR} )
|
||||
|
||||
SET( ALL_OPENSSL_LIBRARIES
|
||||
${OPENSSL_LIBRARIES}
|
||||
${SSL_EAY_RELEASE}
|
||||
${LIB_EAY_RELEASE}
|
||||
)
|
||||
SET( ALL_OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} ${SSL_EAY_RELEASE} ${LIB_EAY_RELEASE})
|
||||
|
||||
set( fc_sources
|
||||
src/variant.cpp
|
||||
|
|
@ -99,12 +95,15 @@ set( fc_sources
|
|||
src/log/file_appender.cpp
|
||||
src/log/logger_config.cpp
|
||||
src/crypto/base36.cpp
|
||||
src/crypto/bigint.cpp
|
||||
src/crypto/base32.cpp
|
||||
src/crypto/base64.cpp
|
||||
src/crypto/base58.cpp
|
||||
src/crypto/bigint.cpp
|
||||
src/crypto/hex.cpp
|
||||
src/crypto/sha1.cpp
|
||||
src/crypto/sha256.cpp
|
||||
src/crypto/sha224.cpp
|
||||
src/crypto/sha512.cpp
|
||||
src/crypto/dh.cpp
|
||||
src/crypto/blowfish.cpp
|
||||
src/network/tcp_socket.cpp
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace fc
|
||||
{
|
||||
fc::vector<char> from_base32( const fc::string& b32 );
|
||||
fc::string to_base32( const fc::vector<char>& vec );
|
||||
std::vector<char> from_base32( const fc::string& b32 );
|
||||
fc::string to_base32( const std::vector<char>& vec );
|
||||
fc::string to_base32( const char* data, size_t len );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace fc
|
||||
{
|
||||
fc::vector<char> from_base36( const fc::string& b36 );
|
||||
fc::string to_base36( const fc::vector<char>& vec );
|
||||
std::vector<char> from_base36( const fc::string& b36 );
|
||||
fc::string to_base36( const std::vector<char>& vec );
|
||||
fc::string to_base36( const char* data, size_t len );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ typedef bignum_st BIGNUM;
|
|||
namespace fc {
|
||||
class bigint {
|
||||
public:
|
||||
bigint( const fc::vector<char>& bige );
|
||||
bigint( const std::vector<char>& bige );
|
||||
bigint( const char* bige, uint32_t l );
|
||||
bigint( unsigned long i = 0 );
|
||||
bigint( const bigint& c );
|
||||
|
|
@ -52,7 +52,7 @@ namespace fc {
|
|||
operator fc::string()const;
|
||||
|
||||
// returns bignum as bigendian bytes
|
||||
operator fc::vector<char>()const;
|
||||
operator std::vector<char>()const;
|
||||
|
||||
BIGNUM* dup()const;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <fc/vector.hpp>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -9,13 +9,13 @@ namespace fc {
|
|||
bool generate_params( int s, uint8_t g );
|
||||
bool generate_pub_key();
|
||||
bool compute_shared_key( const char* buf, uint32_t s );
|
||||
bool compute_shared_key( const vector<char>& pubk);
|
||||
bool compute_shared_key( const std::vector<char>& pubk);
|
||||
bool validate();
|
||||
|
||||
vector<char> p;
|
||||
vector<char> pub_key;
|
||||
vector<char> priv_key;
|
||||
vector<char> shared_key;
|
||||
std::vector<char> p;
|
||||
std::vector<char> pub_key;
|
||||
std::vector<char> priv_key;
|
||||
std::vector<char> shared_key;
|
||||
bool valid;
|
||||
uint8_t g;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/io/buffered_iostream.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <vector>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/filesystem.hpp>
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ namespace fc
|
|||
open_stdout = 0x02,
|
||||
open_stderr = 0x04,
|
||||
open_all = open_stdin|open_stdout|open_stderr,
|
||||
suppress_console = 0x08
|
||||
};
|
||||
|
||||
virtual ~iprocess(){}
|
||||
|
|
@ -30,7 +31,7 @@ namespace fc
|
|||
*
|
||||
* @return *this
|
||||
*/
|
||||
virtual iprocess& exec( const fc::path& exe, vector<string> args,
|
||||
virtual iprocess& exec( const fc::path& exe, std::vector<std::string> args,
|
||||
const fc::path& work_dir = fc::path(), exec_opts opts = open_all ) = 0;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace fc {
|
|||
~process();
|
||||
|
||||
virtual iprocess& exec( const fc::path& exe,
|
||||
vector<string> args,
|
||||
std::vector<std::string> args,
|
||||
const fc::path& work_dir = fc::path(),
|
||||
exec_opts opts = open_all );
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
class appender;
|
||||
class log_message;
|
||||
class string;
|
||||
class variant;
|
||||
|
||||
class appender_factory : public fc::retainable {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace fc
|
|||
|
||||
fc::string format;
|
||||
console_appender::stream::type stream;
|
||||
fc::vector<level_color> level_colors;
|
||||
std::vector<level_color> level_colors;
|
||||
bool flush;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ namespace fc
|
|||
void to_variant( const log_message& l, variant& v );
|
||||
void from_variant( const variant& l, log_message& c );
|
||||
|
||||
typedef fc::vector<log_message> log_messages;
|
||||
typedef std::vector<log_message> log_messages;
|
||||
|
||||
|
||||
} // namespace fc
|
||||
|
|
|
|||
|
|
@ -21,16 +21,16 @@ namespace fc {
|
|||
bool enabled;
|
||||
/// if any appenders are sepecified, then parent's appenders are not set.
|
||||
bool additivity;
|
||||
fc::vector<string> appenders;
|
||||
std::vector<string> appenders;
|
||||
|
||||
logger_config& add_appender( const string& s );
|
||||
};
|
||||
|
||||
struct logging_config {
|
||||
static logging_config default_config();
|
||||
fc::vector<string> includes;
|
||||
fc::vector<appender_config> appenders;
|
||||
fc::vector<logger_config> loggers;
|
||||
std::vector<string> includes;
|
||||
std::vector<appender_config> appenders;
|
||||
std::vector<logger_config> loggers;
|
||||
};
|
||||
|
||||
void configure_logging( const fc::path& log_config );
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace fc {
|
|||
fc::string val;
|
||||
};
|
||||
|
||||
typedef fc::vector<header> headers;
|
||||
typedef std::vector<header> headers;
|
||||
|
||||
struct reply
|
||||
{
|
||||
|
|
@ -31,8 +31,8 @@ namespace fc {
|
|||
};
|
||||
reply( status_code c = OK):status(c){}
|
||||
int status;
|
||||
fc::vector<header> headers;
|
||||
fc::vector<char> body;
|
||||
std::vector<header> headers;
|
||||
std::vector<char> body;
|
||||
};
|
||||
|
||||
struct request
|
||||
|
|
@ -41,11 +41,11 @@ namespace fc {
|
|||
fc::string method;
|
||||
fc::string domain;
|
||||
fc::string path;
|
||||
fc::vector<header> headers;
|
||||
fc::vector<char> body;
|
||||
std::vector<header> headers;
|
||||
std::vector<char> body;
|
||||
};
|
||||
|
||||
fc::vector<header> parse_urlencoded_params( const fc::string& f );
|
||||
std::vector<header> parse_urlencoded_params( const fc::string& f );
|
||||
|
||||
/**
|
||||
* Connections have reference semantics, all copies refer to the same
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
#pragma once
|
||||
#include <fc/vector.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/thread/mutex.hpp>
|
||||
#include <fc/thread/unique_lock.hpp>
|
||||
#ifdef emit
|
||||
#undef emit
|
||||
#endif
|
||||
|
|
@ -10,72 +13,90 @@ namespace fc {
|
|||
|
||||
template<typename Signature>
|
||||
class signal {
|
||||
private:
|
||||
typedef std::function<Signature> func_type;
|
||||
typedef std::vector<std::shared_ptr<func_type>> list_type;
|
||||
public:
|
||||
typedef int64_t connection_id_type;
|
||||
typedef void* connection_id_type;
|
||||
|
||||
template<typename Functor>
|
||||
connection_id_type connect( Functor&& f ) {
|
||||
auto c = new std::function<Signature>( fc::forward<Functor>(f) );
|
||||
_handlers.push_back( c );
|
||||
return reinterpret_cast<connection_id_type>(c);
|
||||
fc::unique_lock<fc::mutex> lock(_mutex);
|
||||
//auto c = new std::function<Signature>( fc::forward<Functor>(f) );
|
||||
_handlers.push_back( std::make_shared<func_type>(f) );
|
||||
return reinterpret_cast<connection_id_type>(_handlers.back().get());
|
||||
}
|
||||
#ifdef WIN32
|
||||
template<typename Arg>
|
||||
void emit( Arg&& arg ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Arg>(arg) );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg) );
|
||||
}
|
||||
}
|
||||
void operator()() {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])();
|
||||
}
|
||||
}
|
||||
template<typename Arg>
|
||||
void operator()( Arg&& arg ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Arg>(arg) );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg) );
|
||||
}
|
||||
}
|
||||
template<typename Arg,typename Arg2>
|
||||
void emit( Arg&& arg, Arg2&& arg2 ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2) );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2) );
|
||||
}
|
||||
}
|
||||
template<typename Arg, typename Arg2>
|
||||
void operator()( Arg&& arg, Arg2&& arg2 ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2) );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2) );
|
||||
}
|
||||
}
|
||||
template<typename Arg, typename Arg2, typename Arg3>
|
||||
void emit( Arg&& arg, Arg2&& arg2, Arg3&& arg3 ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2), fc::forward<Arg3>(arg3) );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2), fc::forward<Arg3>(arg3) );
|
||||
}
|
||||
}
|
||||
template<typename Arg, typename Arg2, typename Arg3>
|
||||
void operator()( Arg&& arg, Arg2&& arg2, Arg3&& arg3 ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2), fc::forward<Arg3>(arg3) );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2), fc::forward<Arg3>(arg3) );
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<typename... Args>
|
||||
void emit( Args&&... args ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Args>(args)... );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Args>(args)... );
|
||||
}
|
||||
}
|
||||
template<typename... Args>
|
||||
void operator()( Args&&... args ) {
|
||||
for( size_t i = 0; i < _handlers.size(); ++i ) {
|
||||
(*_handlers[i])( fc::forward<Args>(args)... );
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Args>(args)... );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void disconnect( connection_id_type cid ) {
|
||||
fc::unique_lock<fc::mutex> lock(_mutex);
|
||||
auto itr = _handlers.begin();
|
||||
while( itr != _handlers.end() ) {
|
||||
if( reinterpret_cast<connection_id_type>(*itr) == cid ) {
|
||||
delete *itr;
|
||||
if( reinterpret_cast<connection_id_type>(itr->get()) == cid ) {
|
||||
_handlers.erase(itr);
|
||||
}
|
||||
++itr;
|
||||
|
|
@ -85,17 +106,25 @@ namespace fc {
|
|||
{
|
||||
_handlers.reserve(4);
|
||||
}
|
||||
~signal()
|
||||
{
|
||||
for( auto itr = _handlers.begin(); itr != _handlers.end(); ++itr )
|
||||
{
|
||||
delete *itr;
|
||||
}
|
||||
_handlers.clear();
|
||||
}
|
||||
//~signal()
|
||||
//{
|
||||
// for( auto itr = _handlers.begin(); itr != _handlers.end(); ++itr )
|
||||
// {
|
||||
// delete *itr;
|
||||
// }
|
||||
// _handlers.clear();
|
||||
//}
|
||||
|
||||
private:
|
||||
fc::vector< std::function<Signature>* > _handlers;
|
||||
fc::mutex _mutex;
|
||||
list_type _handlers;
|
||||
|
||||
list_type getHandlers()
|
||||
{
|
||||
fc::unique_lock<fc::mutex> lock(_mutex);
|
||||
list_type handlers(_handlers);
|
||||
return handlers;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace fc { namespace ssh
|
|||
class process : public iprocess
|
||||
{
|
||||
public:
|
||||
virtual iprocess& exec( const fc::path& exe, vector<string> args,
|
||||
virtual iprocess& exec( const fc::path& exe, std::vector<std::string> args,
|
||||
const fc::path& work_dir = fc::path(), exec_opts opts = open_all );
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,25 @@
|
|||
#include <fc/fwd.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
|
||||
#ifndef USE_FC_STRING
|
||||
#include <string>
|
||||
namespace fc
|
||||
{
|
||||
typedef std::string string;
|
||||
|
||||
int64_t to_int64( const fc::string& );
|
||||
uint64_t to_uint64( const fc::string& );
|
||||
double to_double( const fc::string& );
|
||||
fc::string to_string( double );
|
||||
fc::string to_string( uint64_t );
|
||||
fc::string to_string( int64_t );
|
||||
|
||||
typedef fc::optional<fc::string> ostring;
|
||||
class variant_object;
|
||||
fc::string format_string( const fc::string&, const variant_object& );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* There is debate about whether doing this is 'standard conforming', but
|
||||
|
|
@ -120,3 +139,4 @@ namespace fc {
|
|||
|
||||
} // namespace fc
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ namespace fc {
|
|||
|
||||
template<typename T1, typename T2>
|
||||
int wait_any( const fc::future<T1>& f1, const fc::future<T2>& f2, const microseconds& timeout_us = microseconds::maximum()) {
|
||||
fc::vector<fc::promise_base::ptr> proms(2);
|
||||
std::vector<fc::promise_base::ptr> proms(2);
|
||||
proms[0] = fc::static_pointer_cast<fc::promise_base>(f1.m_prom);
|
||||
proms[1] = fc::static_pointer_cast<fc::promise_base>(f2.m_prom);
|
||||
return wait_any_until(fc::move(proms), fc::time_point::now()+timeout_us );
|
||||
|
|
@ -123,15 +123,15 @@ namespace fc {
|
|||
friend void usleep(const microseconds&);
|
||||
friend void sleep_until(const time_point&);
|
||||
friend void exec();
|
||||
friend int wait_any( fc::vector<promise_base::ptr>&& v, const microseconds& );
|
||||
friend int wait_any_until( fc::vector<promise_base::ptr>&& v, const time_point& tp );
|
||||
friend int wait_any( std::vector<promise_base::ptr>&& v, const microseconds& );
|
||||
friend int wait_any_until( std::vector<promise_base::ptr>&& v, const time_point& tp );
|
||||
void wait_until( promise_base::ptr && v, const time_point& tp );
|
||||
void notify( const promise_base::ptr& v );
|
||||
|
||||
void yield(bool reschedule=true);
|
||||
void sleep_until( const time_point& t );
|
||||
void exec();
|
||||
int wait_any_until( fc::vector<promise_base::ptr>&& v, const time_point& );
|
||||
int wait_any_until( std::vector<promise_base::ptr>&& v, const time_point& );
|
||||
|
||||
void async_task( task_base* t, const priority& p, const char* desc );
|
||||
void async_task( task_base* t, const priority& p, const time_point& tp, const char* desc );
|
||||
|
|
@ -168,8 +168,8 @@ namespace fc {
|
|||
int wait_any( const fc::future<T1>& f1, const fc::future<T2>& f2, const microseconds timeout_us = microseconds::maximum()) {
|
||||
return fc::thread::current().wait_any(f1,f2,timeout_us);
|
||||
}
|
||||
int wait_any( fc::vector<promise_base::ptr>&& v, const microseconds& timeout_us = microseconds::maximum() );
|
||||
int wait_any_until( fc::vector<promise_base::ptr>&& v, const time_point& tp );
|
||||
int wait_any( std::vector<promise_base::ptr>&& v, const microseconds& timeout_us = microseconds::maximum() );
|
||||
int wait_any_until( std::vector<promise_base::ptr>&& v, const time_point& tp );
|
||||
|
||||
template<typename Functor>
|
||||
auto async( Functor&& f, const char* desc ="", priority prio = priority()) -> fc::future<decltype(f())> {
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ namespace fc
|
|||
class wait_condition
|
||||
{
|
||||
public:
|
||||
wait_condition(const char* name) : _name(name) {}
|
||||
|
||||
void wait( const microseconds& timeout = microseconds::maximum() )
|
||||
{
|
||||
typename fc::promise<T>::ptr p = new fc::promise<T>();
|
||||
typename fc::promise<T>::ptr p = new fc::promise<T>(_name);
|
||||
{ synchronized( _prom_lock )
|
||||
_promises.push_back( p );
|
||||
}
|
||||
|
|
@ -27,11 +29,16 @@ namespace fc
|
|||
template<typename LockType>
|
||||
T wait( LockType& l, const microseconds& timeout = microseconds::maximum() )
|
||||
{
|
||||
typename fc::promise<T>::ptr p( new fc::promise<T>());
|
||||
typename fc::promise<T>::ptr p( new fc::promise<T>(_name));
|
||||
{ synchronized( _prom_lock )
|
||||
_promises.push_back( p );
|
||||
}
|
||||
l.unlock();
|
||||
struct relocker {
|
||||
LockType& _lock;
|
||||
relocker(LockType& l) : _lock(l) {}
|
||||
~relocker() { _lock.lock(); }
|
||||
} lock_on_exit(l);
|
||||
return p->wait(timeout);
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +60,7 @@ namespace fc
|
|||
{
|
||||
std::deque<typename fc::promise<T>::ptr> all;
|
||||
{ synchronized( _prom_lock )
|
||||
all = fc::move(_promises);
|
||||
std::swap(all, _promises);
|
||||
}
|
||||
for( auto itr = all.begin(); itr != all.end(); ++itr )
|
||||
{
|
||||
|
|
@ -64,5 +71,6 @@ namespace fc
|
|||
private:
|
||||
fc::spin_yield_lock _prom_lock;
|
||||
std::deque<typename fc::promise<T>::ptr> _promises;
|
||||
const char *const _name;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
|
@ -35,8 +36,8 @@ namespace fc
|
|||
void from_variant( const variant& var, variant_object& vo );
|
||||
void to_variant( const mutable_variant_object& var, variant& vo );
|
||||
void from_variant( const variant& var, mutable_variant_object& vo );
|
||||
void to_variant( const vector<char>& var, variant& vo );
|
||||
void from_variant( const variant& var, vector<char>& vo );
|
||||
void to_variant( const std::vector<char>& var, variant& vo );
|
||||
void from_variant( const variant& var, std::vector<char>& vo );
|
||||
void to_variant( const time_point& var, variant& vo );
|
||||
void from_variant( const variant& var, time_point& vo );
|
||||
#ifdef __APPLE__
|
||||
|
|
@ -50,10 +51,10 @@ namespace fc
|
|||
template<typename T>
|
||||
void from_variant( const variant& var, std::shared_ptr<T>& vo );
|
||||
|
||||
typedef vector<variant> variants;
|
||||
typedef std::vector<variant> variants;
|
||||
|
||||
/**
|
||||
* @brief stores null, int64, uint64, double, bool, string, vector<variant>,
|
||||
* @brief stores null, int64, uint64, double, bool, string, std::vector<variant>,
|
||||
* and variant_object's.
|
||||
*
|
||||
* variant's allocate everything but strings, arrays, and objects on the
|
||||
|
|
@ -246,7 +247,7 @@ namespace fc
|
|||
|
||||
/** @ingroup Serializable */
|
||||
template<typename T>
|
||||
void from_variant( const variant& var, vector<T>& tmp )
|
||||
void from_variant( const variant& var, std::vector<T>& tmp )
|
||||
{
|
||||
const variants& vars = var.get_array();
|
||||
tmp.clear();
|
||||
|
|
@ -257,9 +258,9 @@ namespace fc
|
|||
|
||||
/** @ingroup Serializable */
|
||||
template<typename T>
|
||||
void to_variant( const vector<T>& t, variant& v )
|
||||
void to_variant( const std::vector<T>& t, variant& v )
|
||||
{
|
||||
vector<variant> vars(t.size());
|
||||
std::vector<variant> vars(t.size());
|
||||
for( size_t i = 0; i < t.size(); ++i )
|
||||
vars[i] = variant(t[i]);
|
||||
v = vars;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace fc
|
|||
variant _value;
|
||||
};
|
||||
|
||||
typedef vector< entry >::const_iterator iterator;
|
||||
typedef std::vector< entry >::const_iterator iterator;
|
||||
|
||||
/**
|
||||
* @name Immutable Interface
|
||||
|
|
@ -69,9 +69,9 @@ namespace fc
|
|||
|
||||
template<typename T>
|
||||
variant_object( string key, T&& val )
|
||||
:_key_value( std::make_shared<vector<entry> >() )
|
||||
:_key_value( std::make_shared<std::vector<entry> >() )
|
||||
{
|
||||
*this = variant_object( move(key), variant(forward<T>(val)) );
|
||||
*this = variant_object( std::move(key), variant(forward<T>(val)) );
|
||||
}
|
||||
variant_object( const variant_object& );
|
||||
variant_object( variant_object&& );
|
||||
|
|
@ -86,7 +86,7 @@ namespace fc
|
|||
variant_object& operator=( const mutable_variant_object& );
|
||||
|
||||
private:
|
||||
std::shared_ptr< vector< entry > > _key_value;
|
||||
std::shared_ptr< std::vector< entry > > _key_value;
|
||||
friend class mutable_variant_object;
|
||||
};
|
||||
/** @ingroup Serializable */
|
||||
|
|
@ -112,8 +112,8 @@ namespace fc
|
|||
/** @brief a key/value pair */
|
||||
typedef variant_object::entry entry;
|
||||
|
||||
typedef vector< entry >::iterator iterator;
|
||||
typedef vector< entry >::const_iterator const_iterator;
|
||||
typedef std::vector< entry >::iterator iterator;
|
||||
typedef std::vector< entry >::const_iterator const_iterator;
|
||||
|
||||
/**
|
||||
* @name Immutable Interface
|
||||
|
|
@ -173,7 +173,7 @@ namespace fc
|
|||
template<typename T>
|
||||
mutable_variant_object& operator()( string key, T&& var )
|
||||
{
|
||||
set(move(key), variant( forward<T>(var) ) );
|
||||
set(std::move(key), variant( forward<T>(var) ) );
|
||||
return *this;
|
||||
}
|
||||
///@}
|
||||
|
|
@ -181,7 +181,7 @@ namespace fc
|
|||
|
||||
template<typename T>
|
||||
explicit mutable_variant_object( T&& v )
|
||||
:_key_value( new vector<entry>() )
|
||||
:_key_value( new std::vector<entry>() )
|
||||
{
|
||||
*this = variant(fc::forward<T>(v)).get_object();
|
||||
}
|
||||
|
|
@ -192,9 +192,9 @@ namespace fc
|
|||
mutable_variant_object( string key, variant val );
|
||||
template<typename T>
|
||||
mutable_variant_object( string key, T&& val )
|
||||
:_key_value( new vector<entry>() )
|
||||
:_key_value( new std::vector<entry>() )
|
||||
{
|
||||
set( move(key), variant(forward<T>(val)) );
|
||||
set( std::move(key), variant(forward<T>(val)) );
|
||||
}
|
||||
|
||||
mutable_variant_object( mutable_variant_object&& );
|
||||
|
|
@ -205,7 +205,7 @@ namespace fc
|
|||
mutable_variant_object& operator=( const mutable_variant_object& );
|
||||
mutable_variant_object& operator=( const variant_object& );
|
||||
private:
|
||||
std::unique_ptr< vector< entry > > _key_value;
|
||||
std::unique_ptr< std::vector< entry > > _key_value;
|
||||
friend class variant_object;
|
||||
};
|
||||
/** @ingroup Serializable */
|
||||
|
|
|
|||
|
|
@ -1,402 +1,3 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fc/utility.hpp>
|
||||
|
||||
|
||||
namespace fc {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
struct data {
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
T first;
|
||||
|
||||
static data* allocate( size_t cap ) {
|
||||
data* d = nullptr;
|
||||
if( cap ){
|
||||
d = (data*)malloc(sizeof(data) + sizeof(T)*(static_cast<size_t>(cap)-1));
|
||||
d->capacity = static_cast<size_t>(cap);
|
||||
} else {
|
||||
d = (data*)malloc(sizeof(data));
|
||||
d->capacity = 1;
|
||||
}
|
||||
d->size = 0;
|
||||
return d;
|
||||
}
|
||||
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);
|
||||
} else {
|
||||
d = (data*)realloc(d,sizeof(data));
|
||||
d->capacity = 1;
|
||||
}
|
||||
if( d->size > d->capacity )
|
||||
d->size = d->capacity;
|
||||
return d;
|
||||
}
|
||||
private:
|
||||
data(){};
|
||||
};
|
||||
|
||||
template<typename T, typename IsClass=fc::false_type>
|
||||
struct vector_impl {
|
||||
public:
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
vector_impl():_data(nullptr){}
|
||||
vector_impl( vector_impl&& c):_data(c._data){c._data =nullptr; }
|
||||
vector_impl( const vector_impl& c):_data(nullptr) {
|
||||
if( c.size() ) {
|
||||
_data = detail::data<T>::allocate( c.size() );
|
||||
_data->size = c.size();
|
||||
memcpy(begin(),c.begin(), static_cast<size_t>(c.size()) );
|
||||
}
|
||||
}
|
||||
vector_impl(const_iterator b, const_iterator e ):_data(nullptr) {
|
||||
resize(e-b);
|
||||
if( size() ) memcpy( data(), b, static_cast<size_t>(size()) );
|
||||
}
|
||||
vector_impl(size_t s):_data(nullptr){
|
||||
resize(s);
|
||||
}
|
||||
~vector_impl() {
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
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]; }
|
||||
T& front() { return (&_data->first)[0]; }
|
||||
const T& front()const { return (&_data->first)[0]; }
|
||||
const T* data()const { return (&_data->first); }
|
||||
T* data() { return (&_data->first); }
|
||||
|
||||
iterator begin() { return _data ? &front() : 0;}
|
||||
const_iterator begin()const { return _data ? &front() : 0;}
|
||||
iterator end() { return _data ? (&back())+1: 0;}
|
||||
const_iterator end()const { return _data ? (&back())+1: 0;}
|
||||
|
||||
T& operator[]( size_t i ) { return (&_data->first)[i]; }
|
||||
const T& operator[]( size_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() ); }
|
||||
|
||||
void clear() {
|
||||
if( _data != nullptr ) {
|
||||
free(_data);
|
||||
}
|
||||
_data = nullptr;
|
||||
}
|
||||
|
||||
void reserve( size_t i ) {
|
||||
if( nullptr == _data )
|
||||
{
|
||||
_data = detail::data<T>::allocate( i );
|
||||
_data->size = 0;
|
||||
_data->capacity = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = detail::data<T>::reallocate( _data, i );
|
||||
}
|
||||
}
|
||||
|
||||
void resize( size_t i ) {
|
||||
if( capacity() < i ) {
|
||||
if( _data )
|
||||
_data = detail::data<T>::reallocate( _data, i );
|
||||
else
|
||||
_data = detail::data<T>::allocate( i );
|
||||
}
|
||||
if( _data ) _data->size = i;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
void push_back( U&& v ) {
|
||||
resize( size()+1 );
|
||||
back() = fc::forward<U>(v);
|
||||
}
|
||||
template<typename U>
|
||||
void emplace_back( U&& v ) {
|
||||
resize( size()+1 );
|
||||
back() = fc::forward<U>(v);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
iterator insert( const_iterator loc, U&& t ) {
|
||||
size_t pos = loc - begin();
|
||||
resize( size()+1 );
|
||||
char* src = &at(pos);
|
||||
if( src != &back() )
|
||||
memmove( src+1, src, (&back() - src) );
|
||||
&back = fc::forward<U>(t);
|
||||
return &at(pos);
|
||||
}
|
||||
|
||||
iterator insert( iterator pos, const_iterator first, const_iterator last ) {
|
||||
if( first >= last ) return pos;
|
||||
|
||||
size_t loc = pos - begin();
|
||||
size_t right_size = size() - loc;
|
||||
resize( size() + (last-first) );
|
||||
char* src = &at(loc);
|
||||
size_t s = last-first;
|
||||
memmove( src + s, src, right_size );
|
||||
memcpy( src, first, s );
|
||||
_data->size += (last-first);
|
||||
return src;
|
||||
}
|
||||
|
||||
iterator erase( iterator pos ) {
|
||||
memmove( pos, pos+1, (&back() - pos) );
|
||||
_data->size--;
|
||||
return pos;
|
||||
}
|
||||
|
||||
iterator erase( iterator first, iterator last ) {
|
||||
if( first != last ) {
|
||||
memmove( first, first + (last-first), (&back() - last) );
|
||||
_data->size -= last-first;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
vector_impl& operator=( vector_impl&& v ) {
|
||||
fc_swap(_data,v._data);
|
||||
return *this;
|
||||
}
|
||||
vector_impl& operator=( const vector_impl& v ) {
|
||||
vector_impl tmp(v);
|
||||
fc_swap(tmp._data,_data);
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
detail::data<T>* _data;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct vector_impl<T,fc::true_type> {
|
||||
public:
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
vector_impl():_data(nullptr){}
|
||||
vector_impl( vector_impl&& c):_data(c._data){c._data =nullptr; }
|
||||
vector_impl( const vector_impl& c):_data(nullptr) {
|
||||
if( c.size() ) {
|
||||
_data = detail::data<T>::allocate( c.size() );
|
||||
auto i = begin();
|
||||
auto ci = c.begin();
|
||||
auto ce = c.end();
|
||||
while( ci != ce ) {
|
||||
new (i) T(*ci);
|
||||
++i;
|
||||
++_data->size;
|
||||
++ci;
|
||||
}
|
||||
}
|
||||
}
|
||||
vector_impl(const_iterator b, const_iterator e ):_data(nullptr) {
|
||||
resize(e-b);
|
||||
for( auto i = begin(); i != end(); ++i ) {
|
||||
*i = *b;
|
||||
++b;
|
||||
}
|
||||
}
|
||||
|
||||
vector_impl(size_t s):_data(nullptr){
|
||||
resize(s);
|
||||
}
|
||||
~vector_impl() {
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
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]; }
|
||||
T& front() { return (&_data->first)[0]; }
|
||||
const T& front()const { return (&_data->first)[0]; }
|
||||
const T* data()const { return (&_data->first); }
|
||||
T* data() { return (&_data->first); }
|
||||
|
||||
iterator begin() { return _data ? &front() : 0;}
|
||||
const_iterator begin()const { return _data ? &front() : 0;}
|
||||
const_iterator end()const { return _data ? (&back())+1: 0;}
|
||||
iterator end(){ return _data ? (&back())+1: 0;}
|
||||
|
||||
T& operator[]( size_t i ) { return (&_data->first)[i]; }
|
||||
const T& operator[]( size_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() ); }
|
||||
|
||||
|
||||
void clear() {
|
||||
if( this->_data != nullptr ) {
|
||||
auto c = this->begin();
|
||||
auto e = this->end();
|
||||
while( c != e ) {
|
||||
(*c).~T();
|
||||
++c;
|
||||
}
|
||||
free(this->_data);
|
||||
}
|
||||
this->_data = nullptr;
|
||||
}
|
||||
|
||||
void reserve( size_t i ) {
|
||||
if( nullptr != this->_data && i <= this->_data->capacity )
|
||||
return;
|
||||
|
||||
auto _ndata = detail::data<T>::allocate( i );
|
||||
auto nc = &_ndata->first;
|
||||
auto c = this->begin();
|
||||
auto e = this->end();
|
||||
while( c != e ) {
|
||||
new (nc) T(fc::move( *c ));
|
||||
(*c).~T();
|
||||
++_ndata->size;
|
||||
++c;
|
||||
++nc;
|
||||
}
|
||||
fc_swap( _ndata, this->_data );
|
||||
if( _ndata ) free(_ndata);
|
||||
}
|
||||
|
||||
void resize( size_t i ) {
|
||||
this->reserve(i);
|
||||
while( i < this->_data->size ) {
|
||||
this->back().~T();
|
||||
--this->_data->size;
|
||||
}
|
||||
while( this->_data->size < i ) {
|
||||
new (&this->back()+1) T();
|
||||
++this->_data->size;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
void push_back( U&& v ) {
|
||||
this->reserve( this->size()+1 );
|
||||
new (&back()+1) T(fc::forward<U>(v));
|
||||
++this->_data->size;
|
||||
}
|
||||
template<typename U>
|
||||
void emplace_back( U&& v ) {
|
||||
this->reserve( this->size()+1 );
|
||||
new (&back()+1) T(fc::forward<U>(v));
|
||||
++this->_data->size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename U>
|
||||
iterator insert( const_iterator loc, U&& t ) {
|
||||
size_t pos = loc - this->begin();
|
||||
this->reserve( this->size()+1 );
|
||||
loc = this->begin() + pos;
|
||||
if( this->size() != 0 ) {
|
||||
new ((void*)this->end()) T( fc::move(this->back()) );
|
||||
auto cur = this->back();
|
||||
++this->_data->size;
|
||||
while( cur != loc ) {
|
||||
*cur = fc::move( *(cur-1) );
|
||||
}
|
||||
*cur = fc::forward<U>(t);
|
||||
} else {
|
||||
new (this->end()) T( fc::forward<U>(t) );
|
||||
++this->_data->size;
|
||||
}
|
||||
return &this->at(pos);
|
||||
}
|
||||
|
||||
iterator insert( iterator pos, const_iterator first, const_iterator last ) {
|
||||
//static_assert( false, "Not Implemented" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
iterator erase( iterator pos ) {
|
||||
if( pos == this->end() ) { return pos; }
|
||||
auto next = pos + 1;
|
||||
while( next != this->end() ) {
|
||||
*pos = fc::move(*next);
|
||||
++pos; ++next;
|
||||
}
|
||||
pos->~T();
|
||||
this->_data->size--;
|
||||
return pos;
|
||||
}
|
||||
|
||||
iterator erase( iterator first, iterator last ) {
|
||||
iterator c = first;
|
||||
iterator m = last;
|
||||
iterator e = this->end();
|
||||
while( c != e ) {
|
||||
if( m != e ) *c = fc::move( *m );
|
||||
else c->~T();
|
||||
++c;
|
||||
++m;
|
||||
}
|
||||
this->_data->size -= last-first;
|
||||
return last;
|
||||
}
|
||||
vector_impl& operator=( vector_impl&& v ) {
|
||||
fc_swap(_data,v._data);
|
||||
return *this;
|
||||
}
|
||||
vector_impl& operator=( const vector_impl& v ) {
|
||||
vector_impl tmp(v);
|
||||
fc_swap(tmp._data,_data);
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
detail::data<T>* _data;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief provides a light-weight vector similar to std::vector except that
|
||||
* it prevents needing to include <vector> which requires many more headers
|
||||
* and increases compile times.
|
||||
*
|
||||
* This class should have the same API as std::vector and can be expanded as
|
||||
* additional features of std::vector are required.
|
||||
*
|
||||
*/
|
||||
template<typename T>
|
||||
class vector : public detail::vector_impl<T, typename fc::is_class<T>::type> {
|
||||
public:
|
||||
vector(){}
|
||||
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)){}
|
||||
|
||||
vector( const T* b, const T* e ):detail::vector_impl<T, typename fc::is_class<T>::type>(b,e){}
|
||||
|
||||
vector& operator=( vector&& v ) {
|
||||
*((base*)this) = fc::move(v);
|
||||
return *this;
|
||||
}
|
||||
vector& operator=( const vector& v ) {
|
||||
*((base*)this) = v;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
typedef detail::vector_impl<T, typename fc::is_class<T>::type> base;
|
||||
};
|
||||
|
||||
};
|
||||
#include <vector>
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace fc
|
|||
if( len == 0 ) return fc::string();
|
||||
fc::bigint value( data, len );
|
||||
auto base36 = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
fc::vector<char> out( static_cast<size_t>(len * 1.6) + 1 );
|
||||
std::vector<char> out( static_cast<size_t>(len * 1.6) + 1 );
|
||||
int pos = out.size() - 1;
|
||||
out[pos] = '\0';
|
||||
fc::bigint _36(36);
|
||||
|
|
@ -23,12 +23,12 @@ namespace fc
|
|||
return &out[pos]; //fc::string( &out[pos], out.size() - pos);
|
||||
}
|
||||
|
||||
fc::string to_base36( const fc::vector<char>& vec )
|
||||
fc::string to_base36( const std::vector<char>& vec )
|
||||
{
|
||||
return to_base36( (const char*)vec.data(), vec.size() );
|
||||
}
|
||||
|
||||
fc::vector<char> from_base36( const fc::string& b36 )
|
||||
std::vector<char> from_base36( const fc::string& b36 )
|
||||
{
|
||||
fc::bigint value;
|
||||
|
||||
|
|
|
|||
|
|
@ -609,12 +609,12 @@ fc::string to_base58( const char* d, size_t s ) {
|
|||
return EncodeBase58( (const unsigned char*)d, (const unsigned char*)d+s ).c_str();
|
||||
}
|
||||
|
||||
fc::vector<char> from_base58( const fc::string& base58_str ) {
|
||||
std::vector<char> from_base58( const fc::string& base58_str ) {
|
||||
std::vector<unsigned char> out;
|
||||
if( !DecodeBase58( base58_str.c_str(), out ) ) {
|
||||
FC_THROW_EXCEPTION( exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) );
|
||||
}
|
||||
return fc::vector<char>((const char*)out.data(), ((const char*)out.data())+out.size() );
|
||||
return std::vector<char>((const char*)out.data(), ((const char*)out.data())+out.size() );
|
||||
}
|
||||
/**
|
||||
* @return the number of bytes decoded
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace fc {
|
|||
bigint::bigint( const char* bige, uint32_t l ) {
|
||||
n = BN_bin2bn( (const unsigned char*)bige, l, NULL );
|
||||
}
|
||||
bigint::bigint( const fc::vector<char>& bige ) {
|
||||
bigint::bigint( const std::vector<char>& bige ) {
|
||||
n = BN_bin2bn( (const unsigned char*)bige.data(), bige.size(), NULL );
|
||||
}
|
||||
bigint::bigint( BIGNUM* in )
|
||||
|
|
@ -149,8 +149,8 @@ namespace fc {
|
|||
return BN_bn2dec(n);
|
||||
}
|
||||
|
||||
bigint::operator fc::vector<char>()const {
|
||||
fc::vector<char> to(BN_num_bytes(n));
|
||||
bigint::operator std::vector<char>()const {
|
||||
std::vector<char> to(BN_num_bytes(n));
|
||||
BN_bn2bin(n,(unsigned char*)to.data());
|
||||
return to;
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ namespace fc {
|
|||
/** encodes the big int as base64 string, or a number */
|
||||
void to_variant( const bigint& bi, variant& v )
|
||||
{
|
||||
fc::vector<char> ve = bi;
|
||||
std::vector<char> ve = bi;
|
||||
v = fc::variant(base64_encode((unsigned char*)ve.data(),ve.size()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace fc {
|
|||
DH_free(dh);
|
||||
return valid = true;
|
||||
}
|
||||
bool diffie_hellman::compute_shared_key( const vector<char>& pubk ) {
|
||||
bool diffie_hellman::compute_shared_key( const std::vector<char>& pubk ) {
|
||||
return compute_shared_key( &pubk.front(), pubk.size() );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,11 +85,11 @@ namespace fc {
|
|||
|
||||
void to_variant( const sha256& bi, variant& v )
|
||||
{
|
||||
v = fc::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) );
|
||||
v = std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) );
|
||||
}
|
||||
void from_variant( const variant& v, sha256& bi )
|
||||
{
|
||||
fc::vector<char> ve = v.as< vector<char> >();
|
||||
std::vector<char> ve = v.as< std::vector<char> >();
|
||||
if( ve.size() )
|
||||
{
|
||||
memcpy(&bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include <fc/io/buffered_iostream.hpp>
|
||||
#include <fc/asio.hpp>
|
||||
#include <fc/filesystem.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <boost/process/all.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
|
|
@ -74,11 +73,12 @@ process::process()
|
|||
process::~process(){}
|
||||
|
||||
iprocess& process::exec( const fc::path& exe,
|
||||
fc::vector<fc::string> args,
|
||||
std::vector<std::string> args,
|
||||
const fc::path& work_dir, exec_opts opt )
|
||||
{
|
||||
|
||||
my->pctx.work_dir = work_dir.string();
|
||||
my->pctx.suppress_console = (opt & suppress_console) != 0;
|
||||
|
||||
if( opt&open_stdout)
|
||||
my->pctx.streams[boost::process::stdout_id] = bp::behavior::async_pipe();
|
||||
|
|
@ -96,12 +96,14 @@ iprocess& process::exec( const fc::path& exe,
|
|||
else
|
||||
my->pctx.streams[boost::process::stdin_id] = bp::behavior::close();
|
||||
|
||||
/*
|
||||
std::vector<std::string> a;
|
||||
a.reserve(size_t(args.size()));
|
||||
for( uint32_t i = 0; i < args.size(); ++i ) {
|
||||
a.push_back( fc::move(args[i]) );
|
||||
}
|
||||
my->child.reset( new bp::child( bp::create_child( exe.string(), fc::move(a), my->pctx ) ) );
|
||||
*/
|
||||
my->child.reset( new bp::child( bp::create_child( exe.string(), fc::move(args), my->pctx ) ) );
|
||||
|
||||
if( opt & open_stdout ) {
|
||||
bp::handle outh = my->child->get_handle( bp::stdout_id );
|
||||
|
|
|
|||
|
|
@ -196,12 +196,13 @@ namespace fc {
|
|||
o.write( v.c_str(), v.size() );
|
||||
return o;
|
||||
}
|
||||
|
||||
#ifdef USE_FC_STRING
|
||||
ostream& operator<<( ostream& o, const fc::string& v )
|
||||
{
|
||||
o.write( v.c_str(), v.size() );
|
||||
return o;
|
||||
}
|
||||
#endif
|
||||
|
||||
ostream& operator<<( ostream& o, const double& v )
|
||||
{
|
||||
|
|
@ -266,10 +267,12 @@ namespace fc {
|
|||
return o;
|
||||
}
|
||||
|
||||
#ifdef USE_FC_STRING
|
||||
istream& operator>>( istream& o, fc::string& v )
|
||||
{
|
||||
return o;
|
||||
}
|
||||
#endif
|
||||
|
||||
istream& operator>>( istream& o, char& v )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace fc {
|
|||
bool _additivity;
|
||||
log_level _level;
|
||||
|
||||
fc::vector<appender::ptr> _appenders;
|
||||
std::vector<appender::ptr> _appenders;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class fc::http::connection::impl
|
|||
fc::http::reply parse_reply() {
|
||||
fc::http::reply rep;
|
||||
try {
|
||||
fc::vector<char> line(1024*8);
|
||||
std::vector<char> line(1024*8);
|
||||
int s = read_until( line.data(), line.data()+line.size(), ' ' ); // HTTP/1.1
|
||||
s = read_until( line.data(), line.data()+line.size(), ' ' ); // CODE
|
||||
rep.status = static_cast<int>(to_int64(fc::string(line.data())));
|
||||
|
|
@ -131,7 +131,7 @@ fc::tcp_socket& connection::get_socket()const {
|
|||
|
||||
http::request connection::read_request()const {
|
||||
http::request req;
|
||||
fc::vector<char> line(1024*8);
|
||||
std::vector<char> line(1024*8);
|
||||
int s = my->read_until( line.data(), line.data()+line.size(), ' ' ); // METHOD
|
||||
req.method = line.data();
|
||||
s = my->read_until( line.data(), line.data()+line.size(), ' ' ); // PATH
|
||||
|
|
@ -171,12 +171,12 @@ fc::string request::get_header( const fc::string& key )const {
|
|||
}
|
||||
return fc::string();
|
||||
}
|
||||
fc::vector<header> parse_urlencoded_params( const fc::string& f ) {
|
||||
std::vector<header> parse_urlencoded_params( const fc::string& f ) {
|
||||
int num_args = 0;
|
||||
for( size_t i = 0; i < f.size(); ++i ) {
|
||||
if( f[i] == '=' ) ++num_args;
|
||||
}
|
||||
fc::vector<header> h(num_args);
|
||||
std::vector<header> h(num_args);
|
||||
int arg = 0;
|
||||
for( size_t i = 0; i < f.size(); ++i ) {
|
||||
while( f[i] != '=' && i < f.size() ) {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
namespace fc
|
||||
{
|
||||
fc::vector<fc::ip::endpoint> resolve( const fc::string& host, uint16_t port )
|
||||
std::vector<fc::ip::endpoint> resolve( const fc::string& host, uint16_t port )
|
||||
{
|
||||
auto ep = fc::asio::tcp::resolve( host, std::to_string(uint64_t(port)) );
|
||||
fc::vector<fc::ip::endpoint> eps;
|
||||
std::vector<fc::ip::endpoint> eps;
|
||||
eps.reserve(ep.size());
|
||||
for( auto itr = ep.begin(); itr != ep.end(); ++itr )
|
||||
eps.push_back( fc::ip::endpoint(itr->address().to_v4().to_ulong(), itr->port()) );
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
*/
|
||||
|
||||
namespace fc {
|
||||
#ifdef USE_FC_STRING
|
||||
string::string(const char* s, int l) :my(s,l){ }
|
||||
string::string(){}
|
||||
string::string( const fc::string& c ):my(*c.my) { }
|
||||
|
|
@ -64,6 +65,7 @@ namespace fc {
|
|||
bool operator < ( const string& a, const string& b ) { return *a.my < *b.my; }
|
||||
string operator + ( const string& s, const string& c ) { return string(s) += c; }
|
||||
string operator + ( const string& s, char c ) { return string(s) += c; }
|
||||
#endif // USE_FC_STRING
|
||||
|
||||
|
||||
int64_t to_int64( const fc::string& i )
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ namespace fc {
|
|||
|
||||
my->check_fiber_exceptions();
|
||||
}
|
||||
int thread::wait_any_until( fc::vector<promise_base::ptr>&& p, const time_point& timeout) {
|
||||
int thread::wait_any_until( std::vector<promise_base::ptr>&& p, const time_point& timeout) {
|
||||
for( size_t i = 0; i < p.size(); ++i ) {
|
||||
if( p[i]->ready() ) return i;
|
||||
}
|
||||
|
|
@ -282,10 +282,10 @@ namespace fc {
|
|||
return thread::current().exec();
|
||||
}
|
||||
|
||||
int wait_any( fc::vector<promise_base::ptr>&& v, const microseconds& timeout_us ) {
|
||||
int wait_any( std::vector<promise_base::ptr>&& v, const microseconds& timeout_us ) {
|
||||
return thread::current().wait_any_until( fc::move(v), time_point::now() + timeout_us );
|
||||
}
|
||||
int wait_any_until( fc::vector<promise_base::ptr>&& v, const time_point& tp ) {
|
||||
int wait_any_until( std::vector<promise_base::ptr>&& v, const time_point& tp ) {
|
||||
return thread::current().wait_any_until( fc::move(v), tp );
|
||||
}
|
||||
void thread::wait_until( promise_base::ptr&& p, const time_point& timeout ) {
|
||||
|
|
|
|||
|
|
@ -14,16 +14,16 @@ namespace fc
|
|||
void to_variant( const uint16_t& var, variant& vo ) { vo = uint64_t(var); }
|
||||
// TODO: warn on overflow?
|
||||
void from_variant( const variant& var, uint16_t& vo ){ vo = static_cast<uint16_t>(var.as_uint64()); }
|
||||
void to_variant( const vector<char>& var, variant& vo )
|
||||
void to_variant( const std::vector<char>& var, variant& vo )
|
||||
{
|
||||
if( var.size() )
|
||||
vo = variant(base64_encode((unsigned char*)var.data(),var.size()));
|
||||
else vo = "";
|
||||
}
|
||||
void from_variant( const variant& var, vector<char>& vo )
|
||||
void from_variant( const variant& var, std::vector<char>& vo )
|
||||
{
|
||||
std::string b64 = base64_decode( var.as_string() );
|
||||
vo = fc::vector<char>( b64.c_str(), b64.c_str() + b64.size() );
|
||||
vo = std::vector<char>( b64.c_str(), b64.c_str() + b64.size() );
|
||||
}
|
||||
/**
|
||||
* The TypeID is stored in the 'last byte' of the variant.
|
||||
|
|
|
|||
|
|
@ -96,12 +96,12 @@ namespace fc
|
|||
}
|
||||
|
||||
variant_object::variant_object()
|
||||
:_key_value(std::make_shared<fc::vector<entry>>() )
|
||||
:_key_value(std::make_shared<std::vector<entry>>() )
|
||||
{
|
||||
}
|
||||
|
||||
variant_object::variant_object( string key, variant val )
|
||||
: _key_value(std::make_shared<fc::vector<entry>>())
|
||||
: _key_value(std::make_shared<std::vector<entry>>())
|
||||
{
|
||||
//_key_value->push_back(entry(fc::move(key), fc::move(val)));
|
||||
_key_value->emplace_back(entry(fc::move(key), fc::move(val)));
|
||||
|
|
@ -116,12 +116,12 @@ namespace fc
|
|||
variant_object::variant_object( variant_object&& obj)
|
||||
: _key_value( fc::move(obj._key_value) )
|
||||
{
|
||||
obj._key_value = std::make_shared<fc::vector<entry>>();
|
||||
obj._key_value = std::make_shared<std::vector<entry>>();
|
||||
assert( _key_value != nullptr );
|
||||
}
|
||||
|
||||
variant_object::variant_object( const mutable_variant_object& obj )
|
||||
: _key_value(std::make_shared<fc::vector<entry>>(*obj._key_value))
|
||||
: _key_value(std::make_shared<std::vector<entry>>(*obj._key_value))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ namespace fc
|
|||
variant_object& variant_object::operator=( mutable_variant_object&& obj )
|
||||
{
|
||||
_key_value = fc::move(obj._key_value);
|
||||
obj._key_value.reset( new fc::vector<entry>() );
|
||||
obj._key_value.reset( new std::vector<entry>() );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -260,23 +260,23 @@ namespace fc
|
|||
}
|
||||
|
||||
mutable_variant_object::mutable_variant_object()
|
||||
:_key_value(new fc::vector<entry>)
|
||||
:_key_value(new std::vector<entry>)
|
||||
{
|
||||
}
|
||||
|
||||
mutable_variant_object::mutable_variant_object( string key, variant val )
|
||||
: _key_value(new fc::vector<entry>())
|
||||
: _key_value(new std::vector<entry>())
|
||||
{
|
||||
_key_value->push_back(entry(fc::move(key), fc::move(val)));
|
||||
}
|
||||
|
||||
mutable_variant_object::mutable_variant_object( const variant_object& obj )
|
||||
: _key_value( new fc::vector<entry>(*obj._key_value) )
|
||||
: _key_value( new std::vector<entry>(*obj._key_value) )
|
||||
{
|
||||
}
|
||||
|
||||
mutable_variant_object::mutable_variant_object( const mutable_variant_object& obj )
|
||||
: _key_value( new fc::vector<entry>(*obj._key_value) )
|
||||
: _key_value( new std::vector<entry>(*obj._key_value) )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue