8#ifndef Sawyer_AddressSegment_H
9#define Sawyer_AddressSegment_H
11#include <Sawyer/Access.h>
12#include <Sawyer/AllocatingBuffer.h>
13#include <Sawyer/MappedBuffer.h>
14#include <Sawyer/NullBuffer.h>
15#include <Sawyer/StaticBuffer.h>
16#include <Sawyer/Sawyer.h>
18#include <boost/cstdint.hpp>
20#ifdef SAWYER_HAVE_BOOST_SERIALIZATION
21#include <boost/serialization/string.hpp>
24#ifdef SAWYER_HAVE_CEREAL
25#include <cereal/types/string.hpp>
41template<
class A =
size_t,
class T = boost::u
int8_t>
45 unsigned accessibility_;
56#ifdef SAWYER_HAVE_BOOST_SERIALIZATION
58 friend class boost::serialization::access;
64 void serialize(S &s,
const unsigned ) {
65 s & BOOST_SERIALIZATION_NVP(buffer_);
66 s & BOOST_SERIALIZATION_NVP(offset_);
67 s & BOOST_SERIALIZATION_NVP(accessibility_);
68 s & BOOST_SERIALIZATION_NVP(name_);
72#ifdef SAWYER_HAVE_CEREAL
74 friend class cereal::access;
76 template<
class Archive>
77 void CEREAL_SERIALIZE_FUNCTION_NAME(Archive &archive) {
78 archive(CEREAL_NVP(buffer_));
79 archive(CEREAL_NVP(offset_));
80 archive(CEREAL_NVP(accessibility_));
81 archive(CEREAL_NVP(name_));
101 : buffer_(other.buffer_), offset_(other.offset_), accessibility_(other.accessibility_), name_(other.name_) {}
107 const std::string &
name=
"")
108 : buffer_(
buffer), offset_(
offset), accessibility_(accessBits), name_(
name) {}
112 buffer_ = other.buffer_;
113 offset_ = other.offset_;
114 accessibility_ = other.accessibility_;
156 const std::string &
name=
"") {
157 boost::iostreams::mapped_file::mapmode mode = (accessBits & Access::PRIVATE ? boost::iostreams::mapped_file::priv
158 : (accessBits & Access::WRITABLE ? boost::iostreams::mapped_file::readwrite
159 : boost::iostreams::mapped_file::readonly));
202 const std::string &
name()
const {
return name_; }
214 bool isAccessible(
unsigned requiredAccess,
unsigned prohibitedAccess)
const {
215 return requiredAccess==(accessibility_ & requiredAccess) && 0==(accessibility_ & prohibitedAccess);
A homogeneous interval of an address space.
static AddressSegment nullInstance(Address size, unsigned accessBits=0, const std::string &name="")
Create a segment that points to no data.
static AddressSegment fileInstance(const std::string &fileName, unsigned accessBits=Access::READABLE, const std::string &name="")
Map a file into an address space.
bool isAccessible(unsigned requiredAccess, unsigned prohibitedAccess) const
Determines whether this segment is accessible.
AddressSegment & name(const std::string &s)
Property: name.
AddressSegment & offset(A n)
Property: buffer offset.
static AddressSegment staticInstance(const Value *buffer, Address size, unsigned accessBits=0, const std::string &name="")
Create a segment that points to a static buffer.
const std::string & name() const
Property: name.
static AddressSegment anonymousInstance(Address size, unsigned accessBits=0, const std::string &name="")
Create a segment with no backing store.
A Address
Address types expected to be used by the underlying buffer.
AddressSegment()
Default constructor.
AddressSegment & operator=(const AddressSegment &other)
Assignment.
AddressSegment & accessibility(unsigned bits)
Property: access rights.
A offset() const
Property: buffer offset.
AddressSegment(const typename Buffer< Address, Value >::Ptr &buffer, Address offset=0, unsigned accessBits=0, const std::string &name="")
Construct a segment with buffer.
unsigned accessibility() const
Property: access rights.
AddressSegment(const AddressSegment &other)
Copy constructor.
Buffer< A, T >::Ptr buffer() const
Property: buffer.
static AddressSegment staticInstance(Value *buffer, Address size, unsigned accessBits=0, const std::string &name="")
Create a segment that points to a static buffer.
AddressSegment & buffer(const typename Buffer< A, T >::Ptr &b)
Property: buffer.
T Value
Type of values stored by the underlying buffer.
Allocates memory as needed.
Reference-counting intrusive smart pointer.