From 941098088504160a86f10e1542d7870bf9c6883e Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 23 Aug 2013 20:14:46 -0400 Subject: [PATCH] various updates --- include/fc/crypto/blowfish.hpp | 8 ++++---- include/fc/exception/exception.hpp | 2 +- include/fc/reflect/reflect.hpp | 16 ++++++++++++++++ include/fc/time.hpp | 7 ++++--- include/fc/uint128.hpp | 15 +++++++++++++++ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/include/fc/crypto/blowfish.hpp b/include/fc/crypto/blowfish.hpp index 2ee62b1..fcda4e5 100644 --- a/include/fc/crypto/blowfish.hpp +++ b/include/fc/crypto/blowfish.hpp @@ -149,12 +149,12 @@ public: void reset_chain() { m_oChain = m_oChain0; } // encrypt/decrypt Buffer in Place - void encrypt(unsigned char* buf, uint64_t n, int iMode=CBC); - void decrypt(unsigned char* buf, uint64_t n, int iMode=CBC); + void encrypt(unsigned char* buf, uint64_t n, int iMode=CFB); + void decrypt(unsigned char* buf, uint64_t n, int iMode=CFB); // encrypt/decrypt from Input Buffer to Output Buffer - void encrypt(const unsigned char* in, unsigned char* out, uint64_t n, int iMode=CBC); - void decrypt(const unsigned char* in, unsigned char* out, uint64_t n, int iMode=CBC); + void encrypt(const unsigned char* in, unsigned char* out, uint64_t n, int iMode=CFB); + void decrypt(const unsigned char* in, unsigned char* out, uint64_t n, int iMode=CFB); //Private Functions private: diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index d907f72..968d9d0 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -224,7 +224,7 @@ do { if( !(TEST) ) { FC_THROW_EXCEPTION( assert_exception, #TEST ": " __VA_ARGS */ #define FC_RETHROW_EXCEPTION( ER, LOG_LEVEL, FORMAT, ... ) \ do { \ - er.append_log( FC_LOG_MESSAGE( LOG_LEVEL, FORMAT, __VA_ARGS__ ) ); \ + ER.append_log( FC_LOG_MESSAGE( LOG_LEVEL, FORMAT, __VA_ARGS__ ) ); \ throw;\ } while(false) diff --git a/include/fc/reflect/reflect.hpp b/include/fc/reflect/reflect.hpp index fa07257..043875b 100644 --- a/include/fc/reflect/reflect.hpp +++ b/include/fc/reflect/reflect.hpp @@ -168,6 +168,19 @@ template<> struct reflector {\ }; \ FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \ }; } +#define FC_REFLECT_DERIVED_TEMPLATE( TEMPLATE_ARGS, TYPE, INHERITS, MEMBERS ) \ +namespace fc { \ + template struct get_typename { static const char* name() { return BOOST_PP_STRINGIZE(TYPE); } }; \ +template struct reflector {\ + typedef TYPE type; \ + typedef fc::true_type is_defined; \ + typedef fc::false_type is_enum; \ + enum member_count_enum { \ + local_member_count = 0 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_MEMBER_COUNT, +, MEMBERS ),\ + total_member_count = local_member_count BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_BASE_MEMBER_COUNT, +, INHERITS )\ + }; \ + FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \ +}; } //BOOST_PP_SEQ_SIZE(MEMBERS), @@ -182,6 +195,9 @@ template<> struct reflector {\ #define FC_REFLECT( TYPE, MEMBERS ) \ FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, MEMBERS ) +#define FC_REFLECT_TEMPLATE( TEMPLATE_ARGS, TYPE, MEMBERS ) \ + FC_REFLECT_DERIVED_TEMPLATE( TEMPLATE_ARGS, TYPE, BOOST_PP_SEQ_NIL, MEMBERS ) + #define FC_REFLECT_EMPTY( TYPE ) \ FC_REFLECT_DERIVED( TYPE, BOOST_PP_SEQ_NIL, BOOST_PP_SEQ_NIL ) diff --git a/include/fc/time.hpp b/include/fc/time.hpp index 7b38eaf..4d9bfc1 100644 --- a/include/fc/time.hpp +++ b/include/fc/time.hpp @@ -74,9 +74,10 @@ namespace fc { utc_seconds = t.time_since_epoch().count() / 1000000ll; return *this; } - friend bool operator < ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds < b.utc_seconds; } - friend bool operator > ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds > b.utc_seconds; } - friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; } + friend bool operator < ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds < b.utc_seconds; } + friend bool operator > ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds > b.utc_seconds; } + friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; } + time_point_sec& operator += ( uint32_t m ) { utc_seconds+=m; return *this; } private: uint32_t utc_seconds; diff --git a/include/fc/uint128.hpp b/include/fc/uint128.hpp index 2115da8..2d84c4f 100644 --- a/include/fc/uint128.hpp +++ b/include/fc/uint128.hpp @@ -94,4 +94,19 @@ namespace fc inline void unpack( Stream& s, uint128& u ) { s.read( (char*)&u, sizeof(u) ); } } + uint64_t city_hash64(const char *buf, size_t len); } // namespace fc + +namespace std +{ + template struct hash; + + template<> + struct hash + { + size_t operator()( const fc::uint128& s )const + { + return fc::city_hash64((char*)&s, sizeof(s)); + } + }; +}