pstore2
sstring_view_archive.hpp
Go to the documentation of this file.
1 //===- include/pstore/core/sstring_view_archive.hpp -------*- mode: C++ -*-===//
2 //* _ _ _ *
3 //* ___ ___| |_ _ __(_)_ __ __ _ __ _(_) _____ __ *
4 //* / __/ __| __| '__| | '_ \ / _` | \ \ / / |/ _ \ \ /\ / / *
5 //* \__ \__ \ |_| | | | | | | (_| | \ V /| | __/\ V V / *
6 //* |___/___/\__|_| |_|_| |_|\__, | \_/ |_|\___| \_/\_/ *
7 //* |___/ *
8 //* _ _ *
9 //* __ _ _ __ ___| |__ (_)_ _____ *
10 //* / _` | '__/ __| '_ \| \ \ / / _ \ *
11 //* | (_| | | | (__| | | | |\ V / __/ *
12 //* \__,_|_| \___|_| |_|_| \_/ \___| *
13 //* *
14 //===----------------------------------------------------------------------===//
15 //
16 // Part of the pstore project, under the Apache License v2.0 with LLVM Exceptions.
17 // See https://github.com/SNSystems/pstore/blob/master/LICENSE.txt for license
18 // information.
19 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20 //
21 //===----------------------------------------------------------------------===//
24 
25 #ifndef PSTORE_CORE_SSTRING_VIEW_ARCHIVE_HPP
26 #define PSTORE_CORE_SSTRING_VIEW_ARCHIVE_HPP
27 
33 
34 namespace pstore {
35  namespace serialize {
36 
42  inline sstring_view<std::shared_ptr<char const>>
43  read_string_view (database const & db, typed_address<char> addr, std::size_t const length) {
44  return sstring_view<std::shared_ptr<char const>> (db.getro (addr, length), length);
45  }
46 
48  template <>
49  struct serializer<sstring_view<std::shared_ptr<char const>>> {
51 
52  template <typename Archive>
53  static auto write (Archive && archive, value_type const & str)
54  -> archive_result_type<Archive> {
55  return string_helper::write (std::forward<Archive> (archive), str);
56  }
57 
63  static void read (archive::database_reader && archive, value_type & str) {
64  readsv (archive, str);
65  }
66  static void read (archive::database_reader & archive, value_type & str) {
67  readsv (archive, str);
68  }
69 
70  private:
71  template <typename DBReader>
72  static void readsv (DBReader && archive, value_type & str) {
73  std::size_t const length =
74  string_helper::read_length (std::forward<DBReader> (archive));
75  new (&str) value_type (read_string_view (
76  archive.get_db (), typed_address<char> (archive.get_address ()), length));
77  archive.skip (length);
78  }
79  };
80 
81  template <>
82  struct serializer<sstring_view<char const *>> {
84 
85  template <typename Archive>
86  static auto write (Archive && archive, value_type const & str)
87  -> archive_result_type<Archive> {
88  return string_helper::write (archive, str);
89  }
90  // note that there's no read() implementation.
91  };
92 
95  template <typename Pointer>
96  struct is_compatible<sstring_view<Pointer>, sstring_view<Pointer>> : std::true_type {};
97 
100  template <typename Pointer1, typename Pointer2>
101  struct is_compatible<sstring_view<Pointer1>, sstring_view<Pointer2>> : std::true_type {};
102 
104  template <typename Pointer1>
105  struct is_compatible<sstring_view<Pointer1>, std::string> : std::true_type {};
106 
108  template <typename Pointer1>
109  struct is_compatible<std::string, sstring_view<Pointer1>> : std::true_type {};
110 
111 
114  template <typename PointerType>
115  struct serializer<sstring_view<PointerType> const> {
117  template <typename Archive>
118  static auto write (Archive && archive, value_type const & str)
119  -> archive_result_type<Archive> {
120  return serializer::write (std::forward<Archive> (archive), str);
121  }
122  template <typename Archive>
123  static void read (Archive && archive, value_type & str) {
124  serialize::read_uninit (std::forward<Archive> (archive), str);
125  }
126  };
127 
128  } // end namespace serialize
129 } // end namespace pstore
130 
131 #endif // PSTORE_CORE_SSTRING_VIEW_ARCHIVE_HPP
Provides the database_reader and database_writer class which enable the serializer to read and write ...
Implements sstring_view, a class which is based on std::string_view but holds a pointer which may be ...
std::shared_ptr< void const > getro(address const addr, std::size_t const size) const
Definition: database.hpp:128
The primary template for serialization of non standard layout types.
Definition: types.hpp:118
An archive-reader which reads data from a database.
Definition: db_archive.hpp:102
static auto write(Archive &&archive, StringType const &str) -> archive_result_type< Archive >
Writes an instance of a string type (e.g.
Definition: standard_types.hpp:52
static auto write(Archive &&archive, Ty const &v) -> archive_result_type< Archive >
Writes an single value of type Ty to an archive.
Definition: types.hpp:133
Definition: chunked_sequence.hpp:607
Provides serialization capabilities for trivial and user-defined types.
Definition: address.hpp:231
static void read(archive::database_reader &&archive, value_type &str)
Reads an instance of sstring_view from an archiver.
Definition: sstring_view_archive.hpp:63
Provides serialization capabilities for common types.
static void read(Archive &&archive, Ty &v)
Reads a value of type Ty from an archive.
Definition: types.hpp:153
Definition: nonpod2.cpp:40
Definition: database.hpp:40
sstring_view< std::shared_ptr< char const > > read_string_view(database const &db, typed_address< char > addr, std::size_t const length)
Definition: sstring_view_archive.hpp:43
Definition: sstring_view.hpp:113
Implements a prefix-style variable-length integer.
If the two types T1 and T2 have a compatible representation when serialized, provides the member cons...
Definition: types.hpp:321