Pothos  0.7.0-gf7fbae99
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  static const SharedBuffer &null(void);
27 
29  SharedBuffer(void);
30 
41  static SharedBuffer make(const size_t numBytes, const long nodeAffinity = -1);
42 
56  static SharedBuffer makeCirc(const size_t numBytes, const long nodeAffinity = -1);
57 
64  SharedBuffer(const size_t address, const size_t length, std::shared_ptr<void> container);
65 
74  SharedBuffer(const size_t address, const size_t length, const SharedBuffer &buffer);
75 
77  size_t getAddress(void) const;
78 
80  size_t getLength(void) const;
81 
86  size_t getAlias(void) const;
87 
93  size_t getEnd(void) const;
94 
99  bool unique(void) const;
100 
104  size_t useCount(void) const;
105 
109  explicit operator bool(void) const;
110 
114  const std::shared_ptr<void> &getContainer(void) const;
115 
116 private:
117  static SharedBuffer makeCircUnprotected(const size_t numBytes, const long nodeAffinity);
118  size_t _address;
119  size_t _length;
120  size_t _alias;
121  std::shared_ptr<void> _container;
122 };
123 
128 inline bool operator==(const SharedBuffer &lhs, const SharedBuffer &rhs);
129 
130 } //namespace Pothos
131 
132 inline size_t Pothos::SharedBuffer::getAddress(void) const
133 {
134  return _address;
135 }
136 
137 inline size_t Pothos::SharedBuffer::getLength(void) const
138 {
139  return _length;
140 }
141 
142 inline size_t Pothos::SharedBuffer::getAlias(void) const
143 {
144  return _alias;
145 }
146 
147 inline size_t Pothos::SharedBuffer::getEnd(void) const
148 {
149  return _address + _length;
150 }
151 
152 inline bool Pothos::SharedBuffer::unique(void) const
153 {
154  return _container.unique();
155 }
156 
157 inline size_t Pothos::SharedBuffer::useCount(void) const
158 {
159  return _container.use_count();
160 }
161 
162 inline Pothos::SharedBuffer::operator bool(void) const
163 {
164  return bool(_container);
165 }
166 
167 inline const std::shared_ptr<void> &Pothos::SharedBuffer::getContainer(void) const
168 {
169  return _container;
170 }
171 
172 inline bool Pothos::operator==(const SharedBuffer &lhs, const SharedBuffer &rhs)
173 {
174  return lhs.getContainer() == rhs.getContainer();
175 }
#define POTHOS_API
Definition: Config.hpp:41
size_t getAlias(void) const
Definition: SharedBuffer.hpp:142
POTHOS_API bool operator==(const Callable &lhs, const Callable &rhs)
Definition: ArchiveEntry.hpp:20
size_t getAddress(void) const
Get the address of the first byte of the buffer.
Definition: SharedBuffer.hpp:132
const std::shared_ptr< void > & getContainer(void) const
Definition: SharedBuffer.hpp:167
size_t getLength(void) const
Get the length of the buffer in bytes.
Definition: SharedBuffer.hpp:137
Definition: SharedBuffer.hpp:21
size_t getEnd(void) const
Definition: SharedBuffer.hpp:147
bool unique(void) const
Definition: SharedBuffer.hpp:152
size_t useCount(void) const
Definition: SharedBuffer.hpp:157