Pothos  0.4.1-gb758ed46
The Pothos dataflow programming software suite
SharedBuffer.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <Pothos/Config.hpp>
13 #include <memory> //shared_ptr
14 
15 namespace Pothos {
16 
22 {
23 public:
24 
26  SharedBuffer(void);
27 
38  static SharedBuffer make(const size_t numBytes, const long nodeAffinity = -1);
39 
53  static SharedBuffer makeCirc(const size_t numBytes, const long nodeAffinity = -1);
54 
61  SharedBuffer(const size_t address, const size_t length, std::shared_ptr<void> container);
62 
71  SharedBuffer(const size_t address, const size_t length, const SharedBuffer &buffer);
72 
74  size_t getAddress(void) const;
75 
77  size_t getLength(void) const;
78 
83  size_t getAlias(void) const;
84 
90  size_t getEnd(void) const;
91 
96  bool unique(void) const;
97 
101  size_t useCount(void) const;
102 
106  explicit operator bool(void) const;
107 
111  const std::shared_ptr<void> &getContainer(void) const;
112 
113 private:
114  static SharedBuffer makeCircUnprotected(const size_t numBytes, const long nodeAffinity);
115  size_t _address;
116  size_t _length;
117  size_t _alias;
118  std::shared_ptr<void> _container;
119 };
120 
125 inline bool operator==(const SharedBuffer &lhs, const SharedBuffer &rhs);
126 
127 } //namespace Pothos
128 
129 inline size_t Pothos::SharedBuffer::getAddress(void) const
130 {
131  return _address;
132 }
133 
134 inline size_t Pothos::SharedBuffer::getLength(void) const
135 {
136  return _length;
137 }
138 
139 inline size_t Pothos::SharedBuffer::getAlias(void) const
140 {
141  return _alias;
142 }
143 
144 inline size_t Pothos::SharedBuffer::getEnd(void) const
145 {
146  return _address + _length;
147 }
148 
149 inline bool Pothos::SharedBuffer::unique(void) const
150 {
151  return _container.unique();
152 }
153 
154 inline size_t Pothos::SharedBuffer::useCount(void) const
155 {
156  return _container.use_count();
157 }
158 
159 inline Pothos::SharedBuffer::operator bool(void) const
160 {
161  return bool(_container);
162 }
163 
164 inline const std::shared_ptr<void> &Pothos::SharedBuffer::getContainer(void) const
165 {
166  return _container;
167 }
168 
169 inline bool Pothos::operator==(const SharedBuffer &lhs, const SharedBuffer &rhs)
170 {
171  return lhs.getContainer() == rhs.getContainer();
172 }
#define POTHOS_API
Definition: Config.hpp:41
size_t useCount(void) const
Definition: SharedBuffer.hpp:154
Definition: Testing.hpp:134
bool operator==(const ManagedBuffer &lhs, const ManagedBuffer &rhs)
Definition: ManagedBuffer.hpp:261
size_t getLength(void) const
Get the length of the buffer in bytes.
Definition: SharedBuffer.hpp:134
size_t getAddress(void) const
Get the address of the first byte of the buffer.
Definition: SharedBuffer.hpp:129
size_t getAlias(void) const
Definition: SharedBuffer.hpp:139
Definition: SharedBuffer.hpp:21
const std::shared_ptr< void > & getContainer(void) const
Definition: SharedBuffer.hpp:164
size_t getEnd(void) const
Definition: SharedBuffer.hpp:144
bool unique(void) const
Definition: SharedBuffer.hpp:149