diff --git a/.gitignore b/.gitignore index 2c423e1..ee38be5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .idea/ .vs/ build/ -cmake-build-debug/ +cmake-build-* CTestConfig.cmake diff --git a/CHANGELOG.md b/CHANGELOG.md index 22d63d1..55546de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# [4.5.1](https://github.com/fraillt/bitsery/compare/v4.5.0...v4.5.1) (2019-01-16) + +### Improvements +* template specializations, where possible, was changed to avoid using variadics, some Visual Studio compilers has [issues](https://developercommunity.visualstudio.com/content/problem/3437/error-with-c11-variadics.html) with variadic templates. +* reduced compile warnings for VisualStudio: + * added explicit casts + * renamed `struct` to `class` where class is used as friend. e.g. `friend class bitsery::Access`, because it is more conventional usage. + # [4.5.0](https://github.com/fraillt/bitsery/compare/v4.4.0...v4.5.0) (2019-01-10) ### Features diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a33729..3dbe8e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.1) project(bitsery LANGUAGES CXX - VERSION 4.5.0) + VERSION 4.5.1) #======== build options =================================== option(BITSERY_BUILD_EXAMPLES "Build examples" OFF) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cec949e..01523df 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,16 @@ you contribute: 6. Open a pull request against Bitsery *master* branch. Currently ongoing development is on *master*. At some point an integration branch will be set-up, and pull-requests should target that, but for now its all against master. You may see feature branches come and go, too. +If you're working with visual studio, there is how to build and run all tests from command line +```shell +mkdir build +cd build +cmake -DBITSERY_BUILD_TESTS=ON -DGTEST_ROOT="" -DCMAKE_CXX_FLAGS_RELEASE=/MT .. +cmake --build . --config Release +(cd tests && ctest -C Release && cd ..) +``` +/MT option might be optional, depending on how gtest was built. + ## Style guide -Just use your own judgment and stick to the style of the surrounding code. \ No newline at end of file +Just use your own judgment and stick to the style of the surrounding code. diff --git a/include/bitsery/bitsery.h b/include/bitsery/bitsery.h index 591f2c1..d9069fe 100644 --- a/include/bitsery/bitsery.h +++ b/include/bitsery/bitsery.h @@ -26,7 +26,7 @@ #define BITSERY_MAJOR_VERSION 4 #define BITSERY_MINOR_VERSION 5 -#define BITSERY_PATCH_VERSION 0 +#define BITSERY_PATCH_VERSION 1 #define BITSERY_QUOTE_MACRO(name) #name #define BITSERY_BUILD_VERSION_STR(major,minor, patch) \ diff --git a/include/bitsery/details/serialization_common.h b/include/bitsery/details/serialization_common.h index a41c98d..53b3137 100644 --- a/include/bitsery/details/serialization_common.h +++ b/include/bitsery/details/serialization_common.h @@ -34,7 +34,8 @@ namespace bitsery { //this allows to call private serialize method, and construct instance (if no default constructor is provided) for your type //just make friend it in your class - struct Access { + class Access { + public: template static auto serialize(S &s, T &obj) -> decltype(obj.serialize(s)) { obj.serialize(s); diff --git a/include/bitsery/ext/compact_value.h b/include/bitsery/ext/compact_value.h index 0808a06..7d52239 100644 --- a/include/bitsery/ext/compact_value.h +++ b/include/bitsery/ext/compact_value.h @@ -96,7 +96,7 @@ namespace bitsery { template TResult zigZagDecode(TUnsigned v, std::true_type) const { - return (v >> 1) ^ -(v & 1); + return (v >> 1) ^ (~(v & 1) + 1); // same as -(v & 1), but no warning on VisualStudio } // write/read bytes one by one diff --git a/include/bitsery/ext/std_map.h b/include/bitsery/ext/std_map.h index bb9afca..91eac90 100644 --- a/include/bitsery/ext/std_map.h +++ b/include/bitsery/ext/std_map.h @@ -68,12 +68,12 @@ namespace bitsery { } } private: - template - void reserve(std::unordered_map& obj, size_t size) const { + template + void reserve(std::unordered_map& obj, size_t size) const { obj.reserve(size); } - template - void reserve(std::unordered_multimap& obj, size_t size) const { + template + void reserve(std::unordered_multimap& obj, size_t size) const { obj.reserve(size); } template diff --git a/include/bitsery/ext/std_set.h b/include/bitsery/ext/std_set.h index 106c7ac..5349d53 100644 --- a/include/bitsery/ext/std_set.h +++ b/include/bitsery/ext/std_set.h @@ -65,14 +65,17 @@ namespace bitsery { } private: - template - void reserve(std::unordered_set& obj, size_t size) const { + template + void reserve(std::unordered_set& obj, size_t size) const { obj.reserve(size); } - template - void reserve(std::unordered_multiset& obj, size_t size) const { + template + void reserve(std::unordered_multiset& obj, size_t size) const { obj.reserve(size); } + + + template void reserve(T& , size_t ) const { //for ordered container do nothing diff --git a/include/bitsery/ext/value_range.h b/include/bitsery/ext/value_range.h index e4ccade..251e596 100644 --- a/include/bitsery/ext/value_range.h +++ b/include/bitsery/ext/value_range.h @@ -96,7 +96,8 @@ namespace bitsery { constexpr RangeSpec(T minValue, T maxValue, T precision) : min{minValue}, max{maxValue}, - bitsRequired{calcRequiredBits>({}, ((max - min) / precision))} { + bitsRequired{calcRequiredBits>( + {}, static_cast>((max - min) / precision))} { } @@ -163,7 +164,8 @@ namespace bitsery { public: template - explicit constexpr ValueRange(Args &&... args):_range{std::forward(args)...} {} + constexpr ValueRange(const TValue& min, const TValue& max, Args &&... args) + :_range{min, max, std::forward(args)...} {} template void serialize(Ser &, Writer &writer, const T &v, Fnc &&) const { diff --git a/include/bitsery/flexible/deque.h b/include/bitsery/flexible/deque.h index e60c3d8..3f62395 100644 --- a/include/bitsery/flexible/deque.h +++ b/include/bitsery/flexible/deque.h @@ -28,8 +28,8 @@ #include "../details/flexible_common.h" namespace bitsery { - template - void serialize(S &s, std::deque &obj) { + template + void serialize(S &s, std::deque &obj) { flexible::processContainer(s, obj); } } diff --git a/include/bitsery/flexible/forward_list.h b/include/bitsery/flexible/forward_list.h index be156e3..d45ffc1 100644 --- a/include/bitsery/flexible/forward_list.h +++ b/include/bitsery/flexible/forward_list.h @@ -28,8 +28,8 @@ #include "../details/flexible_common.h" namespace bitsery { - template - void serialize(S &s, std::forward_list &obj) { + template + void serialize(S &s, std::forward_list &obj) { flexible::processContainer(s, obj); } } diff --git a/include/bitsery/flexible/list.h b/include/bitsery/flexible/list.h index a71e22f..1e9e302 100644 --- a/include/bitsery/flexible/list.h +++ b/include/bitsery/flexible/list.h @@ -28,8 +28,8 @@ #include "../details/flexible_common.h" namespace bitsery { - template - void serialize(S &s, std::list &obj) { + template + void serialize(S &s, std::list &obj) { flexible::processContainer(s, obj); } } diff --git a/include/bitsery/flexible/map.h b/include/bitsery/flexible/map.h index 17715fa..beda904 100644 --- a/include/bitsery/flexible/map.h +++ b/include/bitsery/flexible/map.h @@ -28,23 +28,19 @@ #include "../ext/std_map.h" namespace bitsery { - template - void serialize(S &s, std::map &obj, size_t maxSize = std::numeric_limits::max()) { - using TKey = typename std::map::key_type; - using TValue = typename std::map::mapped_type; + template + void serialize(S &s, std::map &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdMap{maxSize}, - [&s](TKey& key, TValue& value) { + [&s](Key& key, T& value) { s.object(key); s.object(value); }); } - template - void serialize(S &s, std::multimap &obj, size_t maxSize = std::numeric_limits::max()) { - using TKey = typename std::multimap::key_type; - using TValue = typename std::multimap::mapped_type; + template + void serialize(S &s, std::multimap &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdMap{maxSize}, - [&s](TKey& key, TValue& value) { + [&s](Key& key, T& value) { s.object(key); s.object(value); }); diff --git a/include/bitsery/flexible/set.h b/include/bitsery/flexible/set.h index 423fff4..aeeacbc 100644 --- a/include/bitsery/flexible/set.h +++ b/include/bitsery/flexible/set.h @@ -28,13 +28,13 @@ #include "../ext/std_set.h" namespace bitsery { - template - void serialize(S &s, std::set &obj, size_t maxSize = std::numeric_limits::max()) { + template + void serialize(S &s, std::set &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdSet{maxSize}); } - template - void serialize(S &s, std::multiset &obj, size_t maxSize = std::numeric_limits::max()) { + template + void serialize(S &s, std::multiset &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdSet{maxSize}); } diff --git a/include/bitsery/flexible/string.h b/include/bitsery/flexible/string.h index 0705296..35459ff 100644 --- a/include/bitsery/flexible/string.h +++ b/include/bitsery/flexible/string.h @@ -28,8 +28,8 @@ #include "../details/flexible_common.h" namespace bitsery { - template - void serialize(S &s, std::basic_string &str) { + template + void serialize(S &s, std::basic_string &str) { flexible::processContainer(s, str); } } diff --git a/include/bitsery/flexible/unordered_map.h b/include/bitsery/flexible/unordered_map.h index 9fe4e95..117f0fb 100644 --- a/include/bitsery/flexible/unordered_map.h +++ b/include/bitsery/flexible/unordered_map.h @@ -28,23 +28,19 @@ #include "../ext/std_map.h" namespace bitsery { - template - void serialize(S &s, std::unordered_map &obj, size_t maxSize = std::numeric_limits::max()) { - using TKey = typename std::unordered_map::key_type; - using TValue = typename std::unordered_map::mapped_type; + template + void serialize(S &s, std::unordered_map &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdMap{maxSize}, - [&s](TKey& key, TValue& value) { + [&s](Key& key, T& value) { s.object(key); s.object(value); }); } - template - void serialize(S &s, std::unordered_multimap &obj, size_t maxSize = std::numeric_limits::max()) { - using TKey = typename std::unordered_multimap::key_type; - using TValue = typename std::unordered_multimap::mapped_type; + template + void serialize(S &s, std::unordered_multimap &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdMap{maxSize}, - [&s](TKey& key, TValue& value) { + [&s](Key& key, T& value) { s.object(key); s.object(value); }); diff --git a/include/bitsery/flexible/unordered_set.h b/include/bitsery/flexible/unordered_set.h index 949f807..cfa8567 100644 --- a/include/bitsery/flexible/unordered_set.h +++ b/include/bitsery/flexible/unordered_set.h @@ -28,13 +28,13 @@ #include "../ext/std_set.h" namespace bitsery { - template - void serialize(S &s, std::unordered_set &obj, size_t maxSize = std::numeric_limits::max()) { + template + void serialize(S &s, std::unordered_set &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdSet{maxSize}); } - template - void serialize(S &s, std::unordered_multiset &obj, size_t maxSize = std::numeric_limits::max()) { + template + void serialize(S &s, std::unordered_multiset &obj, size_t maxSize = std::numeric_limits::max()) { s.ext(obj, ext::StdSet{maxSize}); } diff --git a/include/bitsery/flexible/vector.h b/include/bitsery/flexible/vector.h index 205b9fc..f4d4683 100644 --- a/include/bitsery/flexible/vector.h +++ b/include/bitsery/flexible/vector.h @@ -28,8 +28,8 @@ #include "../details/flexible_common.h" namespace bitsery { - template - void serialize(S &s, std::vector &obj) { + template + void serialize(S &s, std::vector &obj) { flexible::processContainer(s, obj); } } diff --git a/include/bitsery/traits/deque.h b/include/bitsery/traits/deque.h index a640fb6..23f6626 100644 --- a/include/bitsery/traits/deque.h +++ b/include/bitsery/traits/deque.h @@ -31,9 +31,9 @@ namespace bitsery { namespace traits { - template - struct ContainerTraits> - : public StdContainer, true, false> {}; + template + struct ContainerTraits> + : public StdContainer, true, false> {}; } diff --git a/include/bitsery/traits/forward_list.h b/include/bitsery/traits/forward_list.h index 173e43f..a95f2b9 100644 --- a/include/bitsery/traits/forward_list.h +++ b/include/bitsery/traits/forward_list.h @@ -32,22 +32,22 @@ namespace bitsery { namespace traits { - template - struct ContainerTraits> { - using TValue = typename std::forward_list::value_type; + template + struct ContainerTraits> { + using TValue = T; static constexpr bool isResizable = true; static constexpr bool isContiguous = false; - static size_t size(const std::forward_list& container) { + static size_t size(const std::forward_list& container) { return static_cast(std::distance(container.begin(), container.end())); } - static void resize(std::forward_list& container, size_t size) { + static void resize(std::forward_list& container, size_t size) { resizeImpl(container, size, std::is_default_constructible{}); } private: - static void resizeImpl(std::forward_list& container, size_t size, std::true_type) { + static void resizeImpl(std::forward_list& container, size_t size, std::true_type) { container.resize(size); } - static void resizeImpl(std::forward_list& container, size_t newSize, std::false_type) { + static void resizeImpl(std::forward_list& container, size_t newSize, std::false_type) { const auto oldSize = size(container); for (auto it = oldSize; it < newSize; ++it) { container.push_front(::bitsery::Access::create()); diff --git a/include/bitsery/traits/list.h b/include/bitsery/traits/list.h index 6f1b691..fc15fdd 100644 --- a/include/bitsery/traits/list.h +++ b/include/bitsery/traits/list.h @@ -31,9 +31,9 @@ namespace bitsery { namespace traits { - template - struct ContainerTraits> - : public StdContainer, true, false> {}; + template + struct ContainerTraits> + : public StdContainer, true, false> {}; } diff --git a/include/bitsery/traits/string.h b/include/bitsery/traits/string.h index 209bb2e..fe9ce38 100644 --- a/include/bitsery/traits/string.h +++ b/include/bitsery/traits/string.h @@ -33,18 +33,18 @@ namespace bitsery { // specialization for string, because string is already included for std::char_traits - template - struct ContainerTraits> - :public StdContainer, true, true> {}; + template + struct ContainerTraits> + :public StdContainer, true, true> {}; - template - struct TextTraits> { - using TValue = typename ContainerTraits>::TValue; + template + struct TextTraits> { + using TValue = typename ContainerTraits>::TValue; //string is automatically null-terminated static constexpr bool addNUL = false; //is is not 100% accurate, but for performance reasons assume that string stores text, not binary data - static size_t length(const std::basic_string& str) { + static size_t length(const std::basic_string& str) { return str.size(); } }; @@ -60,9 +60,9 @@ namespace bitsery { } }; - template - struct BufferAdapterTraits> - :public StdContainerForBufferAdapter> {}; + template + struct BufferAdapterTraits> + :public StdContainerForBufferAdapter> {}; } diff --git a/include/bitsery/traits/vector.h b/include/bitsery/traits/vector.h index 0c810ef..fdff9e0 100644 --- a/include/bitsery/traits/vector.h +++ b/include/bitsery/traits/vector.h @@ -30,18 +30,18 @@ namespace bitsery { namespace traits { - template - struct ContainerTraits> - :public StdContainer, true, true> {}; + template + struct ContainerTraits> + :public StdContainer, true, true> {}; //bool vector is not contiguous, do not copy it directly to buffer template struct ContainerTraits> :public StdContainer, true, false> {}; - template - struct BufferAdapterTraits> - :public StdContainerForBufferAdapter> {}; + template + struct BufferAdapterTraits> + :public StdContainerForBufferAdapter> {}; } diff --git a/tests/data_endianness.cpp b/tests/data_endianness.cpp index a5a76c1..5c3a38d 100644 --- a/tests/data_endianness.cpp +++ b/tests/data_endianness.cpp @@ -56,19 +56,19 @@ using InverseReader = bitsery::AdapterReader(0x1122334455667788); - src.b = 0xBBCCDDEE; - src.c = static_cast(0xCCDD); - src.d = static_cast(0xDD); - src.e = static_cast(0xEE); + src.a = static_cast(0x1122334455667788u); + src.b = 0xBBCCDDEEu; + src.c = static_cast(0xCCDDu); + src.d = static_cast(0xDDu); + src.e = static_cast(0xEEu); //fill expected result after swap IntegralTypes resInv{}; - resInv.a = static_cast(0x8877665544332211); - resInv.b = 0xEEDDCCBB; - resInv.c = static_cast(0xDDCC); - resInv.d = static_cast(0xDD); - resInv.e = static_cast(0xEE); + resInv.a = static_cast(0x8877665544332211u); + resInv.b = 0xEEDDCCBBu; + resInv.c = static_cast(0xDDCCu); + resInv.d = static_cast(0xDDu); + resInv.e = static_cast(0xEEu); //create and write to buffer Buffer buf{}; diff --git a/tests/not_default_constructible.cpp b/tests/not_default_constructible.cpp index 9adc846..37e6586 100644 --- a/tests/not_default_constructible.cpp +++ b/tests/not_default_constructible.cpp @@ -35,7 +35,7 @@ using testing::ContainerEq; using testing::Eq; //forward declare, for testing with std::unordered_map -struct HasherForNonDefaultConstructible; +class HasherForNonDefaultConstructible; class NonDefaultConstructible { int32_t i{0}; @@ -65,7 +65,8 @@ public: } }; -struct HasherForNonDefaultConstructible { +class HasherForNonDefaultConstructible { +public: size_t operator()(const NonDefaultConstructible& o) const { return std::hash()(o.i); } diff --git a/tests/serialization_ext_growable.cpp b/tests/serialization_ext_growable.cpp index b0910c3..3c334de 100644 --- a/tests/serialization_ext_growable.cpp +++ b/tests/serialization_ext_growable.cpp @@ -52,9 +52,9 @@ TEST(SerializeExtensionGrowable, WriteSessionsDataAtBufferEndAfterFlush) { ser.value1b(v); }); - EXPECT_THAT(ctx.getBufferSize(), Eq(1)); + EXPECT_THAT(ctx.getBufferSize(), Eq(1u)); ctx.bw->flush(); - EXPECT_THAT(ctx.getBufferSize(), Gt(1)); + EXPECT_THAT(ctx.getBufferSize(), Gt(1u)); } diff --git a/tests/serialization_size.cpp b/tests/serialization_size.cpp index 43347b4..16f4139 100644 --- a/tests/serialization_size.cpp +++ b/tests/serialization_size.cpp @@ -37,26 +37,26 @@ bool SerializeDeserializeContainerSize(SerializationContext& ctx, const size_t s TEST(SerializeSize, WhenLengthLessThan128Then1Byte) { SerializationContext ctx1{}; EXPECT_TRUE(SerializeDeserializeContainerSize(ctx1, 127)); - EXPECT_THAT(ctx1.getBufferSize(), Eq(1)); + EXPECT_THAT(ctx1.getBufferSize(), Eq(1u)); SerializationContext ctx2; EXPECT_TRUE(SerializeDeserializeContainerSize(ctx2, 128)); - EXPECT_THAT(ctx2.getBufferSize(), testing::Gt(1)); + EXPECT_THAT(ctx2.getBufferSize(), testing::Gt(1u)); } TEST(SerializeSize, WhenLengthLessThan16384Then2Bytes) { SerializationContext ctx1; EXPECT_TRUE(SerializeDeserializeContainerSize(ctx1, 16383)); - EXPECT_THAT(ctx1.getBufferSize(), Eq(2)); + EXPECT_THAT(ctx1.getBufferSize(), Eq(2u)); SerializationContext ctx2; EXPECT_TRUE(SerializeDeserializeContainerSize(ctx2, 16384)); - EXPECT_THAT(ctx2.getBufferSize(), testing::Gt(2)); + EXPECT_THAT(ctx2.getBufferSize(), testing::Gt(2u)); } TEST(SerializeSize, WhenGreaterThan16383Then4Bytes) { SerializationContext ctx1; EXPECT_TRUE(SerializeDeserializeContainerSize(ctx1, 16384)); - EXPECT_THAT(ctx1.getBufferSize(), Eq(4)); + EXPECT_THAT(ctx1.getBufferSize(), Eq(4u)); SerializationContext ctx2; EXPECT_TRUE(SerializeDeserializeContainerSize(ctx2, 66384)); - EXPECT_THAT(ctx2.getBufferSize(), Eq(4)); -} \ No newline at end of file + EXPECT_THAT(ctx2.getBufferSize(), Eq(4u)); +}