class Archive final {
public:
- explicit Archive() = default;
- /// Use only when flatten data comes from Archive (by casting to string)
- explicit Archive(const std::string& flatten) : buffer(flatten.cbegin(), flatten.cend())
- {
- }
-
template<typename Front, typename... Rest>
void pack(const Front& front, const Rest&... rest);
inline void pack(void) {}
template<typename... Ts>
void transform(std::tuple<Ts...>& tuple);
- /// serialize method
+ // serialize method
template<typename T, IsFundamental<T> = 0>
Archive& operator<<(const T& value);
template<typename T, IsArchival<T> = 0>
Archive& operator<<(const std::string& value);
Archive& operator<<(const Archive& archive);
- /// deserialize method
+ // deserialize method
template<typename T, IsFundamental<T> = 0>
Archive& operator>>(T& value);
template<typename T, IsArchival<T> = 0>
std::size_t size(void) const noexcept;
void reserve(std::size_t size) noexcept;
- /// It is not safe when Archive includes binary formats.
- operator std::string() const
- {
- return std::string(this->buffer.begin(), this->buffer.end());
- }
-
protected:
- void save(const void* bytes, std::size_t size);
- void load(void* bytes, std::size_t size);
+ virtual void save(const void* bytes, std::size_t size);
+ virtual void load(void* bytes, std::size_t size);
private:
template<typename T>
Archive archive;
archive.transform(tuple);
}
-
-TEST(ArchiveTests, string_conversion)
-{
- int input1 = std::numeric_limits<int>::lowest();
- int input2 = std::numeric_limits<int>::max();
-
- Archive archive;
- archive << input1 << input2;
-
- std::string flatten = archive;
- Archive restore(flatten);
-
- int output1, output2;
- restore >> output1 >> output2;
-
- EXPECT_EQ(input1, output1);
- EXPECT_EQ(input2, output2);
-}