diff --git a/README.md b/README.md new file mode 100644 index 0000000..31b0e44 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +fc +== + +FC stands for fast-compiling c++ library and provides a set of utility libraries useful +for the development of asynchronous libraries. Some of the highlights include: + + - Cooperative Multi-Tasking Library with support for Futures, mutexes, signals. + - Wrapper on Boost ASIO for handling async opperations cooperatively with easy to code synchronous style. + - Reflection for C++ allowing automatic serialization in Json & Binary of C++ Structs + - Automatic generation of client / server stubs for reflected interfaces with support for JSON-RPC + - Cryptographic Primitives for a variaty of hashes and encryption algorithms + - Logging Infrastructure + - Wraps many Boost APIs, such as boost::filesystem, boost::thread, and boost::exception to acceleate compiles + - Support for unofficial Boost.Process library. diff --git a/include/fc/optional.hpp b/include/fc/optional.hpp index 48ef53f..102b238 100644 --- a/include/fc/optional.hpp +++ b/include/fc/optional.hpp @@ -1,84 +1,88 @@ #pragma once #include +#include namespace fc { +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4521) /* multiple copy ctors */ +#endif + /** * @brief provides stack-based nullable value similar to boost::optional * * Simply including boost::optional adds 35,000 lines to each object file, using * fc::optional adds less than 400. */ - -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4521) /* multiple copy ctors */ -#endif - template - class optional { + class optional + { public: - optional():_valid(0){} - ~optional(){ if( _valid ) (**this).~T(); } + optional():_valid(false){} + ~optional(){ reset(); } optional( const optional& o ) - :_valid(false) { - if( o._valid ) new (&**this) T( *o ); + :_valid(false) + { + if( o._valid ) new (ptr()) T( *o ); _valid = o._valid; } optional( optional& o ) - :_valid(false) { - if( o._valid ) new (&**this) T( *o ); + :_valid(false) + { + if( o._valid ) new (ptr()) T( *o ); _valid = o._valid; } optional( optional&& o ) - :_valid(false) { - if( o._valid ) new (&**this) T( fc::move(*o) ); + :_valid(false) + { + if( o._valid ) new (ptr()) T( fc::move(*o) ); _valid = o._valid; + o.reset(); } template optional( U&& u ) - :_valid(false) { - new (&**this) T( fc::forward(u) ); + :_valid(false) + { + new (ptr()) T( fc::forward(u) ); _valid = true; } template - optional& operator=( U&& u ) { - if( !_valid ) { - new (&**this) T( fc::forward(u) ); - _valid = true; - } else { - **this = static_cast(fc::forward(u)); - } + optional& operator=( U&& u ) + { + reset(); + new (ptr()) T( fc::forward(u) ); return *this; } optional& operator=( const optional& o ) { if (this != &o) { if( _valid && o._valid ) { - **this = *o; + ref() = *o; } else if( !_valid && o._valid ) { - *this = *o; + new (ptr()) T( *o ); + _valid = true; } else if (_valid) { - (**this).~T(); - _valid = false; + reset(); } } return *this; } - optional& operator=( optional&& o ) { - if (this != &o) { + optional& operator=( optional&& o ) + { + if (this != &o) + { if( _valid && o._valid ) { - **this = fc::move(*o); + ref() = fc::move(*o); } else if ( !_valid && o._valid ) { *this = fc::move(*o); } else if (_valid) { - (**this).~T(); - _valid = false; + reset(); } } return *this; @@ -87,13 +91,33 @@ namespace fc { bool operator!()const { return !_valid; } operator bool()const { return _valid; } - T& operator*() { void* v = &_value[0]; return *static_cast(v); } - const T& operator*()const { const void* v = &_value[0]; return *static_cast(v); } + T& operator*() { assert(_valid); return ref(); } + const T& operator*()const { assert(_valid); return ref(); } - T* operator->() { void* v = &_value[0]; return static_cast(v); } - const T* operator->()const { const void* v = &_value[0]; return static_cast(v); } + T* operator->() + { + assert( _valid ); + return ptr(); + } + const T* operator->()const + { + assert( _valid ); + return ptr(); + } private: + void reset() + { + if( _valid ) + { + ref().~T(); // cal destructor + } + } + T& ref() { return *ptr(); } + const T& ref()const { return *ptr(); } + T* ptr() { void* v = &_value[0]; return static_cast(v); } + const T* ptr()const { const void* v = &_value[0]; return static_cast(v); } + // force alignment... to 8 byte boundaries double _value[8 * ((sizeof(T)+7)/8)]; bool _valid; diff --git a/src/crypto/base58.cpp b/src/crypto/base58.cpp index f86a983..71a7787 100644 --- a/src/crypto/base58.cpp +++ b/src/crypto/base58.cpp @@ -605,11 +605,11 @@ inline bool DecodeBase58(const std::string& str, std::vector& vch namespace fc { -fc::string to_base58( const char* d, size_t s ) { +std::string to_base58( const char* d, size_t s ) { return EncodeBase58( (const unsigned char*)d, (const unsigned char*)d+s ).c_str(); } -std::vector from_base58( const fc::string& base58_str ) { +std::vector from_base58( const std::string& base58_str ) { std::vector out; if( !DecodeBase58( base58_str.c_str(), out ) ) { FC_THROW_EXCEPTION( exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) ); @@ -619,7 +619,7 @@ std::vector from_base58( const fc::string& base58_str ) { /** * @return the number of bytes decoded */ -size_t from_base58( const fc::string& base58_str, char* out_data, size_t out_data_len ) { +size_t from_base58( const std::string& base58_str, char* out_data, size_t out_data_len ) { //slog( "%s", base58_str.c_str() ); std::vector out; if( !DecodeBase58( base58_str.c_str(), out ) ) { diff --git a/vendor/cyoencode-1.0.2/LICENSE.TXT b/vendor/cyoencode-1.0.2/LICENSE.TXT new file mode 100644 index 0000000..4e10e73 --- /dev/null +++ b/vendor/cyoencode-1.0.2/LICENSE.TXT @@ -0,0 +1,27 @@ +All the files in this library are covered under the terms of the Berkeley +Software Distribution (BSD) License: + +Copyright (c) 2009-2012, Graham Bull. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/vendor/cyoencode-1.0.2/src/build.sh b/vendor/cyoencode-1.0.2/src/build.sh new file mode 100755 index 0000000..67c0907 --- /dev/null +++ b/vendor/cyoencode-1.0.2/src/build.sh @@ -0,0 +1,2 @@ +gcc test.c CyoEncode.c CyoDecode.c -o test + diff --git a/vendor/cyoencode-1.0.2/src/cyoencode-vc100.vcxproj b/vendor/cyoencode-1.0.2/src/cyoencode-vc100.vcxproj new file mode 100644 index 0000000..8c3a8d2 --- /dev/null +++ b/vendor/cyoencode-1.0.2/src/cyoencode-vc100.vcxproj @@ -0,0 +1,162 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + cyoencode-vc100 + {C773C1E9-CAC6-40AF-A400-567F73AB0178} + cyoencodevc100 + Win32Proj + + + + Application + Unicode + true + + + Application + Unicode + true + + + Application + Unicode + + + Application + Unicode + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + true + true + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + false + false + + + + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + EditAndContinue + + + true + Console + MachineX86 + + + + + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + ProgramDatabase + + + true + Console + + + + + MaxSpeed + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level4 + ProgramDatabase + + + true + Console + true + true + MachineX86 + + + + + MaxSpeed + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level4 + ProgramDatabase + + + true + Console + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vendor/cyoencode-1.0.2/src/cyoencode-vc71.vcproj b/vendor/cyoencode-1.0.2/src/cyoencode-vc71.vcproj new file mode 100644 index 0000000..26c46ff --- /dev/null +++ b/vendor/cyoencode-1.0.2/src/cyoencode-vc71.vcproj @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vendor/cyoencode-1.0.2/src/cyoencode-vc80.vcproj b/vendor/cyoencode-1.0.2/src/cyoencode-vc80.vcproj new file mode 100644 index 0000000..c08685a --- /dev/null +++ b/vendor/cyoencode-1.0.2/src/cyoencode-vc80.vcproj @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vendor/cyoencode-1.0.2/src/cyoencode-vc90.vcproj b/vendor/cyoencode-1.0.2/src/cyoencode-vc90.vcproj new file mode 100644 index 0000000..ee5927b --- /dev/null +++ b/vendor/cyoencode-1.0.2/src/cyoencode-vc90.vcproj @@ -0,0 +1,341 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +