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>
19 #include <boost/serialization/access.hpp>
20 #include <boost/serialization/nvp.hpp>
21 #include <boost/serialization/string.hpp>
36 template<
class A =
size_t,
class T = boost::u
int8_t>
40 unsigned accessibility_;
48 friend class boost::serialization::access;
54 void serialize(S &s,
const unsigned ) {
55 s & BOOST_SERIALIZATION_NVP(buffer_);
56 s & BOOST_SERIALIZATION_NVP(offset_);
57 s & BOOST_SERIALIZATION_NVP(accessibility_);
58 s & BOOST_SERIALIZATION_NVP(name_);
77 : buffer_(other.buffer_), offset_(other.offset_), accessibility_(other.accessibility_), name_(other.name_) {}
83 const std::string &
name=
"")
84 : buffer_(
buffer), offset_(
offset), accessibility_(accessBits), name_(
name) {}
123 const std::string &
name=
"") {
124 boost::iostreams::mapped_file::mapmode mode = (accessBits & Access::PRIVATE ? boost::iostreams::mapped_file::priv
125 : (accessBits & Access::WRITABLE ? boost::iostreams::mapped_file::readwrite
126 : boost::iostreams::mapped_file::readonly));
169 const std::string &
name()
const {
return name_; }
181 bool isAccessible(
unsigned requiredAccess,
unsigned prohibitedAccess)
const {
182 return requiredAccess==(accessibility_ & requiredAccess) && 0==(accessibility_ & prohibitedAccess);
A homogeneous interval of an address space.
Allocates memory as needed.
T Value
Type of values stored by the underlying buffer.
A Address
Address types expected to be used by the underlying 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(const typename Buffer< Address, Value >::Ptr &buffer, Address offset=0, unsigned accessBits=0, const std::string &name="")
Construct a segment with buffer.
A offset() const
Property: buffer offset.
AddressSegment(const AddressSegment &other)
Copy constructor.
AddressSegment & accessibility(unsigned bits)
Property: access rights.
AddressSegment & name(const std::string &s)
Property: name.
static AddressSegment fileInstance(const std::string &fileName, unsigned accessBits=Access::READABLE, const std::string &name="")
Map a file into an address space.
static AddressSegment staticInstance(const Value *buffer, Address size, unsigned accessBits=0, const std::string &name="")
Create a segment that points to a static buffer.
bool isAccessible(unsigned requiredAccess, unsigned prohibitedAccess) const
Determines whether this segment is accessible.
AddressSegment & offset(A n)
Property: buffer offset.
AddressSegment()
Default constructor.
static AddressSegment nullInstance(Address size, unsigned accessBits=0, const std::string &name="")
Create a segment that points to no data.
AddressSegment & buffer(const typename Buffer< A, T >::Ptr &b)
Property: buffer.
static AddressSegment anonymousInstance(Address size, unsigned accessBits=0, const std::string &name="")
Create a segment with no backing store.
Reference-counting intrusive smart pointer.
Name space for the entire library.
Buffer< A, T >::Ptr buffer() const
Property: buffer.
unsigned accessibility() const
Property: access rights.
const std::string & name() const
Property: name.