20 #ifndef PSTORE_CORE_DB_ARCHIVE_HPP 21 #define PSTORE_CORE_DB_ARCHIVE_HPP 42 : transaction_ (trans) {}
47 template <
typename Ty>
49 std::shared_ptr<Ty> ptr;
51 std::tie (ptr, addr) = transaction_.template alloc_rw<Ty> ();
53 return addr.to_address ();
56 template <
typename Span>
59 typename std::remove_const<typename Span::element_type>::type;
61 std::shared_ptr<element_type> ptr;
63 std::tie (ptr, addr) = transaction_.template alloc_rw<element_type> (
64 unsigned_cast (sp.size ()));
65 std::copy (std::begin (sp), std::end (sp), ptr.get ());
66 return addr.to_address ();
69 void flush () noexcept {}
114 void skip (std::size_t
const distance) noexcept { addr_ += distance; }
123 template <
typename Ty,
typename =
typename std::enable_if<
124 std::is_standard_layout<Ty>::value>::type>
132 template <
typename SpanType,
133 typename =
typename std::enable_if<std::is_standard_layout<
134 typename SpanType::element_type>::value>::type>
135 void getn (SpanType span);
144 template <
typename Ty,
typename>
147 auto const extra_for_alignment =
calc_alignment (addr_.absolute (),
alignof (Ty));
148 PSTORE_ASSERT (extra_for_alignment <
sizeof (Ty));
149 addr_ += extra_for_alignment;
152 addr_ +=
sizeof (Ty);
154 new (&v) Ty (*result);
159 template <
typename SpanType,
typename>
161 using element_type =
typename SpanType::element_type;
164 auto const extra_for_alignment =
166 PSTORE_ASSERT (extra_for_alignment <
sizeof (element_type));
167 addr_ += extra_for_alignment;
170 auto const size = unsigned_cast (span.size_bytes ());
175 auto first = src.get ();
176 std::copy (first, first + size, reinterpret_cast<std::uint8_t *> (span.data ()));
193 #endif // PSTORE_CORE_DB_ARCHIVE_HPP The basic archive reader and writer types.
An archive-reader which reads data from a database.
Definition: db_archive.hpp:102
The base class for archive-writer objects.
Definition: archive.hpp:139
Definition: address.hpp:81
constexpr Ty calc_alignment(Ty const v, std::size_t const align) noexcept
Calculate the value that must be added to p v in order that it has the alignment given by align...
Definition: aligned.hpp:86
auto put(Ty const &value) -> result_type
Writes an instance of a standard-layout type T to the database.
Definition: db_archive.hpp:48
The data store transaction class.
Definition: transaction.hpp:191
Definition: address.hpp:231
database_reader(pstore::database const &db, pstore::address const addr) noexcept
Constructs the reader using an input database and an address.
Definition: db_archive.hpp:108
void getn(SpanType span)
Reads a span of a trivial type from the current store address.
Definition: db_archive.hpp:160
auto make_writer(transaction_base &transaction) noexcept -> database_writer
A convenience function which simplifies the construction of a database_writer instance if the caller ...
Definition: db_archive.hpp:92
void get(Ty &v)
Reads a single instance of a standard-layout type Ty from the current store address.
Definition: db_archive.hpp:145
database_reader make_reader(pstore::database const &db, pstore::address const addr) noexcept
A convenience function which provides symmetry with the make_writer() function.
Definition: db_archive.hpp:186
Definition: nonpod2.cpp:40
Definition: database.hpp:40
Definition: db_archive.hpp:78
Provides an pstore-specific error codes and a suitable error category for them.
Definition: db_archive.hpp:37
database_writer(transaction_base &transaction)
Constructs the writer using the transaction.
Definition: db_archive.hpp:85
The database transaction class.
Definition: transaction.hpp:43