16 #ifndef PSTORE_MCREPO_SECTION_HPP 17 #define PSTORE_MCREPO_SECTION_HPP 23 #include <type_traits> 30 #define PSTORE_MCREPO_SECTION_KINDS \ 35 X (mergeable_1_byte_c_string) \ 36 X (mergeable_2_byte_c_string) \ 37 X (mergeable_4_byte_c_string) \ 38 X (mergeable_const_4) \ 39 X (mergeable_const_8) \ 40 X (mergeable_const_16) \ 41 X (mergeable_const_32) \ 48 X (linked_definitions) 51 enum class section_kind : std::uint8_t {
52 PSTORE_MCREPO_SECTION_KINDS last
55 constexpr
auto num_section_kinds =
56 static_cast<std::underlying_type<section_kind>::type
> (section_kind::last);
58 std::ostream & operator<< (std::ostream & os, section_kind kind);
60 constexpr
auto first_repo_metadata_section = section_kind::linked_definitions;
62 constexpr
bool is_target_section (section_kind
const t) noexcept {
63 using utype = std::underlying_type<section_kind>::type;
64 return static_cast<utype
> (t) < static_cast<utype> (first_repo_metadata_section);
73 unsigned section_alignment (T
const & section) noexcept;
76 std::uint64_t section_size (T
const & section) noexcept;
102 section_kind
const & kind ()
const noexcept {
return kind_; }
107 template <typename IntType, typename = std::enable_if<std::is_unsigned<IntType>::value>>
109 static_assert (
sizeof (std::uintptr_t) >=
sizeof (IntType),
110 "sizeof uintptr_t must be at least sizeof IntType");
111 return static_cast<std::size_t
> (
112 this->aligned_impl (static_cast<std::uintptr_t> (a)));
117 std::uint8_t *
aligned (std::uint8_t *
const a)
const {
118 return reinterpret_cast<std::uint8_t *
> (
119 this->aligned_impl (reinterpret_cast<std::uintptr_t> (a)));
124 virtual std::size_t size_bytes ()
const = 0;
131 virtual std::uint8_t * write (std::uint8_t * out)
const = 0;
137 virtual std::uintptr_t aligned_impl (std::uintptr_t v)
const = 0;
139 section_kind
const kind_;
145 template <
typename T>
151 template <
typename ValueType>
154 using value_type = ValueType
const;
155 using size_type = std::size_t;
156 using difference_type = std::ptrdiff_t;
157 using reference = ValueType
const &;
158 using const_reference = reference;
159 using pointer = ValueType
const *;
160 using const_pointer = pointer;
161 using iterator = const_pointer;
162 using const_iterator = iterator;
168 PSTORE_ASSERT (end >= begin);
170 iterator begin ()
const {
return begin_; }
171 iterator end ()
const {
return end_; }
172 const_iterator cbegin ()
const {
return begin (); }
173 const_iterator cend ()
const {
return end (); }
175 const_pointer data ()
const {
return begin_; }
177 size_type size ()
const noexcept {
178 PSTORE_ASSERT (end_ >= begin_);
179 return static_cast<size_type
> (end_ - begin_);
181 bool empty ()
const noexcept {
return size () == 0U; }
184 const_pointer begin_;
199 virtual std::size_t size_bytes ()
const = 0;
200 virtual unsigned align ()
const = 0;
201 virtual std::size_t size ()
const = 0;
213 template <
typename T>
219 #endif // PSTORE_MCREPO_SECTION_HPP Definition: generic_section.hpp:112
A simple wrapper around the elements of one of the three arrays that make up a section.
Definition: section.hpp:152
Maps from the type of data that is associated with a fragment's section to a "dispatcher" subclass wh...
Definition: section.hpp:146
transaction< transaction_lock > begin(database &db, transaction_lock &lock)
Creates a new transaction. Every operation performed on a transaction instance can be potentially und...
Definition: transaction.hpp:311
This class is used to add virtual methods to a fragment's section.
Definition: section.hpp:195
An empty class used as the base type for all sections.
Definition: section.hpp:69
Maps from the type of data that is associated with a fragment's section to a "dispatcher" subclass wh...
Definition: section.hpp:214
Definition: nonpod2.cpp:40
std::uint8_t * aligned(std::uint8_t *const a) const
Definition: section.hpp:117
An implementation of the standard assert() macro with the exception that it will, on failure...
A section creation dispatcher is used to instantiate and construct each of a fragment's sections in p...
Definition: section.hpp:91
std::size_t aligned(IntType a) const
Definition: section.hpp:108
Definition: generic_section.hpp:46