MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / buffer

Class buffer

src/include/buffer.hpp:341–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339/// \note This class wraps a data type T over the underlying byte buffer.
340template<typename T>
341class buffer : public bytes {
342public:
343 /// \brief constructor
344 buffer() : bytes() {}
345
346 /// \brief constructor
347 /// \param count the count
348 buffer(size_t count) : bytes(count * sizeof(T)) {}
349
350 /// \brief constructor
351 /// \param data the data
352 /// \param count the count
353 buffer(T* data, size_t count)
354 : bytes(reinterpret_cast<uint8_t*>(data), count * sizeof(T)) {}
355
356 /// \brief shallow copy constructor
357 /// \param other the other buffer
358 buffer(const buffer& other) : bytes(other) {}
359
360#ifdef __XRT__
361 /// \brief constructor
362 /// \param bo the bo
363 buffer(xrt::bo& bo) : bytes(bo) {}
364
365 /// \brief constructor
366 /// \param count the count
367 /// \param device the device
368 /// \param kernel the kernel
369 /// \param group_id the group id
370 /// \param flags the flags
371 buffer(xrt::device& device, size_t count)
372 : bytes(device, count * sizeof(T)) {}
373#endif
374
375 /// \brief constructor
376 /// \param vec the vector
377 buffer(const std::vector<T>& vec)
378 : bytes(reinterpret_cast<uint8_t*>(const_cast<T*>(vec.data())), vec.size() * sizeof(T))
379 {
380 }
381
382 /// \brief constructor
383 /// \param vec the vector
384 /// \warning This also creates a shallow mapping.
385 /// \warning The caller must ensure that the vector is not used (and remains valid)
386 /// \warning after constructing this buffer.
387 buffer(std::vector<T>&& vec)
388 : bytes(reinterpret_cast<uint8_t*>(vec.data()), vec.size() * sizeof(T))
389 {
390 }
391
392 /// \brief copy from
393 /// \param vec the vector
394 void copy_from(const std::vector<T>& vec) {
395 if (vec.size() * sizeof(T) != this->size_) {
396 throw std::runtime_error("Size mismatch in copy_from(vector)");
397 }
398 std::memcpy(data_, vec.data(), size_);

Callers 3

send_chunk_dataMethod · 0.85

Calls 1

sizeFunction · 0.85

Tested by

no test coverage detected