MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/Imath / BufferAPI

Class BufferAPI

src/python/PyImath/PyImathBufferProtocol.cpp:24–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22//
23template <class ArrayT>
24class BufferAPI
25{
26 using T = typename ArrayT::BaseType;
27 static_assert (std::is_same<ArrayT, FixedArray<T> >::value,
28 "BufferAPI is only valid for FixedArray classes");
29
30 public:
31
32 virtual ~BufferAPI()
33 { delete[] shape; delete[] stride; }
34
35 // The size, in bytes, of the smallest individual element of a buffer
36 // element. For example, a V3fArray is a 2D array of 4-byte floats.
37 Py_ssize_t atomicSize() const
38 { return FixedArrayAtomicSize<T>::value; }
39
40 // NonCopyable
41 BufferAPI (const BufferAPI &rhs) = delete;
42 BufferAPI &operator= (const BufferAPI &rhs) = delete;
43
44 // API
45 virtual bool sharedBuffer() const = 0;
46 virtual Py_ssize_t numBytes() const = 0;
47 virtual bool readOnly() const = 0;
48 virtual void * buffer() = 0;
49
50 protected:
51
52 BufferAPI (const unsigned int length, const unsigned int interleave)
53 : dimensions (FixedArrayDimension<T>::value),
54 shape (new Py_ssize_t[dimensions]),
55 stride (new Py_ssize_t[dimensions])
56 {
57 shape[0] = Py_ssize_t (length);
58 stride[0] = atomicSize() * FixedArrayWidth<T>::value * interleave;
59 for (int d=1; d<dimensions; d++)
60 {
61 shape[d] = FixedArrayWidth<T>::value * interleave;
62 stride[d] = atomicSize();
63 }
64 }
65
66 public:
67
68 // The number of dimensions in the data buffer (e.g. a one dimensional
69 // FixedArray of V3fs would have a data buffer dimension of 2).
70 int dimensions;
71
72 Py_ssize_t *shape;
73 Py_ssize_t *stride;
74};
75
76
77// The SharedBuffer class is used for buffers that will be shared between

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected