ROSE  0.11.96.11
Buffer.h
1 // WARNING: Changes to this file must be contributed back to Sawyer or else they will
2 // be clobbered by the next update from Sawyer. The Sawyer repository is at
3 // https://github.com/matzke1/sawyer.
4 
5 
6 
7 
8 #ifndef Sawyer_Buffer_H
9 #define Sawyer_Buffer_H
10 
11 #include <Sawyer/Sawyer.h>
12 #include <Sawyer/SharedPointer.h>
13 #include <boost/serialization/access.hpp>
14 #include <boost/serialization/nvp.hpp>
15 #include <string>
16 
17 namespace Sawyer {
18 namespace Container {
19 
24 template<class A, class T>
25 class Buffer: public SharedObject {
26  std::string name_;
27  bool copyOnWrite_;
28 
29 protected:
30  explicit Buffer(const std::string &name = ""): name_(generateSequentialName()+name), copyOnWrite_(false) {}
31 
32 private:
33  friend class boost::serialization::access;
34 
35  template<class S>
36  void serialize(S &s, const unsigned /*version*/) {
37  s & BOOST_SERIALIZATION_NVP(name_);
38  s & BOOST_SERIALIZATION_NVP(copyOnWrite_);
39  }
40 
41 public:
46 
50  typedef A Address;
51 
53  typedef T Value;
54 
55 public:
56  virtual ~Buffer() {}
57 
63  virtual Ptr copy() const = 0;
64 
70  virtual Address available(Address address) const = 0;
71 
76  virtual Address size() const { return available(Address(0)); }
77 
81  virtual void resize(Address n) = 0;
82 
87  virtual void sync() {}
88 
94  const std::string& name() const { return name_; }
95  void name(const std::string &s) { name_ = s; }
107  virtual Address read(Value *buf, Address address, Address n) const = 0;
108 
114  virtual Address write(const Value *buf, Address address, Address n) = 0;
115 
119  virtual const Value* data() const = 0;
120 
127  bool copyOnWrite() const { return copyOnWrite_; }
128  void copyOnWrite(bool b) { copyOnWrite_ = b; }
130 };
131 
132 } // namespace
133 } // namespace
134 
135 #endif
Sawyer::Container::Buffer::resize
virtual void resize(Address n)=0
Change the size of the buffer.
Sawyer::Container::Buffer::name
void name(const std::string &s)
Property: Name.
Definition: Buffer.h:95
Sawyer::Container::Buffer::read
virtual Address read(Value *buf, Address address, Address n) const =0
Reads data from a buffer.
Sawyer::Container::Buffer::write
virtual Address write(const Value *buf, Address address, Address n)=0
Writes data to a buffer.
Sawyer::Container::Buffer::data
virtual const Value * data() const =0
Data for the buffer.
Sawyer::Container::Buffer::name
const std::string & name() const
Property: Name.
Definition: Buffer.h:94
Sawyer::Container::Buffer::Ptr
SharedPointer< Buffer > Ptr
Reference counting smart pointer.
Definition: Buffer.h:45
Sawyer::generateSequentialName
std::string generateSequentialName(size_t length=3)
Generate a sequential name.
Sawyer::Container::Buffer::copyOnWrite
void copyOnWrite(bool b)
Property: Copy on write.
Definition: Buffer.h:128
Sawyer::Container::Buffer::available
virtual Address available(Address address) const =0
Distance to end of buffer.
Sawyer::Container::Buffer::copy
virtual Ptr copy() const =0
Create a new copy of buffer data.
Sawyer::Container::Buffer
Base class for all buffers.
Definition: Buffer.h:25
Sawyer::SharedPointer
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
Sawyer
Name space for the entire library.
Definition: Access.h:13
Sawyer::SharedObject
Base class for reference counted objects.
Definition: SharedObject.h:64
Sawyer::Container::Buffer::sync
virtual void sync()
Synchronize buffer with persistent storage.
Definition: Buffer.h:87
Sawyer::Container::Buffer::Address
A Address
Key type for addressing data.
Definition: Buffer.h:50
Sawyer::Container::Buffer::size
virtual Address size() const
Size of buffer.
Definition: Buffer.h:76
Sawyer::Container::Buffer::Value
T Value
Type of values stored in the buffer.
Definition: Buffer.h:53
Sawyer::Container::Buffer::copyOnWrite
bool copyOnWrite() const
Property: Copy on write.
Definition: Buffer.h:127