mirror of
https://github.com/fraillt/bitsery.git
synced 2026-06-08 08:13:56 +00:00
Implement brief syntax for optional and bitset
This commit is contained in:
committed by
Mindaugas Vinkelis
parent
be2f295310
commit
b714459a2b
36
include/bitsery/brief_syntax/bitset.h
Normal file
36
include/bitsery/brief_syntax/bitset.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2018 Mindaugas Vinkelis
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#ifndef BITSERY_BRIEF_SYNTAX_TYPE_STD_BITSET_H
|
||||
#define BITSERY_BRIEF_SYNTAX_TYPE_STD_BITSET_H
|
||||
|
||||
#include "../ext/std_bitset.h"
|
||||
|
||||
namespace bitsery {
|
||||
template<typename S, size_t N>
|
||||
void
|
||||
serialize(S& s, std::bitset<N>& obj)
|
||||
{
|
||||
s.ext(obj, ext::StdBitset{});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
36
include/bitsery/brief_syntax/optional.h
Normal file
36
include/bitsery/brief_syntax/optional.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2018 Mindaugas Vinkelis
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#ifndef BITSERY_BRIEF_SYNTAX_TYPE_STD_OPTIONAL_H
|
||||
#define BITSERY_BRIEF_SYNTAX_TYPE_STD_OPTIONAL_H
|
||||
|
||||
#include "../ext/std_optional.h"
|
||||
|
||||
namespace bitsery {
|
||||
template<typename S, typename Ts>
|
||||
void
|
||||
serialize(S& s, std::optional<Ts>& obj)
|
||||
{
|
||||
s.ext(obj, ext::StdOptional{});
|
||||
}
|
||||
} // namespace bitsery
|
||||
#endif
|
||||
@@ -23,12 +23,14 @@
|
||||
#include <bitsery/brief_syntax.h>
|
||||
#include <bitsery/brief_syntax/array.h>
|
||||
#include <bitsery/brief_syntax/atomic.h>
|
||||
#include <bitsery/brief_syntax/bitset.h>
|
||||
#include <bitsery/brief_syntax/chrono.h>
|
||||
#include <bitsery/brief_syntax/deque.h>
|
||||
#include <bitsery/brief_syntax/forward_list.h>
|
||||
#include <bitsery/brief_syntax/list.h>
|
||||
#include <bitsery/brief_syntax/map.h>
|
||||
#include <bitsery/brief_syntax/memory.h>
|
||||
#include <bitsery/brief_syntax/optional.h>
|
||||
#include <bitsery/brief_syntax/queue.h>
|
||||
#include <bitsery/brief_syntax/set.h>
|
||||
#include <bitsery/brief_syntax/stack.h>
|
||||
@@ -473,6 +475,12 @@ TEST(BriefSyntax, StdAtomic)
|
||||
0x1337);
|
||||
}
|
||||
|
||||
TEST(BriefSyntax, StdBitset)
|
||||
{
|
||||
std::bitset<17> bits{ 0b10101010101010101 };
|
||||
EXPECT_TRUE(procBriefSyntax(bits) == bits);
|
||||
}
|
||||
|
||||
#if __cplusplus > 201402L
|
||||
|
||||
TEST(BriefSyntax, StdTuple)
|
||||
@@ -490,6 +498,12 @@ TEST(BriefSyntax, StdVariant)
|
||||
EXPECT_TRUE(procBriefSyntax(t1) == t1);
|
||||
}
|
||||
|
||||
TEST(BriefSyntax, StdOptional)
|
||||
{
|
||||
std::optional<uint32_t> opt{ 54654 };
|
||||
EXPECT_TRUE(procBriefSyntax(opt) == opt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST(BriefSyntax, NestedTypes)
|
||||
|
||||
Reference in New Issue
Block a user