Skip to content

Instantly share code, notes, and snippets.

@allsey87
Created May 10, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allsey87/17961cd8b5d49c617b687fb6228b800f to your computer and use it in GitHub Desktop.
Save allsey87/17961cd8b5d49c617b687fb6228b800f to your computer and use it in GitHub Desktop.
Using smart pointers to cleanly integrate object orientated C libraries into a C++ application
struct SBuffer {
/* shared pointers to pixel data */
std::shared_ptr<image_u8_t> Y, U, V;
/* index (set by capture thread) */
unsigned int Index = -1;
/* capture time */
std::chrono::time_point<std::chrono::steady_clock> Timestamp;
/* default constructor */
SBuffer() :
Y(image_u8_create(0, 0), image_u8_destroy),
U(image_u8_create(0, 0), image_u8_destroy),
V(image_u8_create(0, 0), image_u8_destroy) {}
/* argument constructor */
SBuffer(unsigned int un_width, unsigned int un_height) :
Y(image_u8_create(un_width, un_height), image_u8_destroy),
U(image_u8_create(un_width, un_height), image_u8_destroy),
V(image_u8_create(un_width, un_height), image_u8_destroy) {}
/* copy constructor */
SBuffer(const SBuffer& s_other_buffer) :
Y(image_u8_copy(s_other_buffer.Y.get()), image_u8_destroy),
U(image_u8_copy(s_other_buffer.U.get()), image_u8_destroy),
V(image_u8_copy(s_other_buffer.V.get()), image_u8_destroy) {}
/* move constructor */
SBuffer(SBuffer&& s_other_buffer) :
Y(image_u8_create(0, 0), image_u8_destroy),
U(image_u8_create(0, 0), image_u8_destroy),
V(image_u8_create(0, 0), image_u8_destroy) {
Y.swap(s_other_buffer.Y);
U.swap(s_other_buffer.U);
V.swap(s_other_buffer.V);
Index = s_other_buffer.Index;
s_other_buffer.Index = -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment