Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
bengineerd committed Nov 4, 2024
1 parent 6b9827b commit d6b2503
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
2 changes: 0 additions & 2 deletions include/rogue/interfaces/stream/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ class Frame : public rogue::EnableSharedFromThis<rogue::interfaces::stream::Fram

#ifndef NO_PYTHON


//! Python Frame data read function
/** Read data from Frame into passed Python byte array.
*
Expand All @@ -354,7 +353,6 @@ class Frame : public rogue::EnableSharedFromThis<rogue::interfaces::stream::Fram
*/
boost::python::object getMemoryviewPy();


//! Python Frame data write function
/** Write data into from Frame from passed Python byte array.
*
Expand Down
39 changes: 13 additions & 26 deletions src/rogue/interfaces/stream/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ ris::FrameIterator ris::Frame::endWrite() {

#ifndef NO_PYTHON


//! Read bytes from frame into a passed bytearray, starting from offset. Python version.
void ris::Frame::readPy(boost::python::object p, uint32_t offset) {
Py_buffer pyBuf;
Expand Down Expand Up @@ -380,7 +379,6 @@ bp::object ris::Frame::getBytearrayPy(uint32_t offset, uint32_t count) {
count = size - offset;
}


// Create a Python bytearray to hold the data
bp::object byteArray(bp::handle<>(PyByteArray_FromStringAndSize(nullptr, count)));

Expand All @@ -403,17 +401,13 @@ bp::object ris::Frame::getMemoryviewPy() {
// Create a memoryview from the bytearray
PyObject* memoryView = PyMemoryView_FromObject(byteArray.ptr());
if (!memoryView) {
throw(rogue::GeneralError::create("Frame::getMemoryviewPy",
"Failed to create memoryview."));
throw(rogue::GeneralError::create("Frame::getMemoryviewPy", "Failed to create memoryview."));
}

// Return the memoryview as a Python object
return bp::object(bp::handle<>(memoryView));

}



//! Write python buffer to frame, starting at offset. Python Version
void ris::Frame::writePy(boost::python::object p, uint32_t offset) {
Py_buffer pyBuf;
Expand Down Expand Up @@ -459,15 +453,13 @@ boost::python::object ris::Frame::getNumpy(uint32_t offset, uint32_t count, bp::
size));
}


// Convert Python dtype object to NumPy type
int numpy_type;
PyObject* dtype_pyobj = dtype.ptr(); // Get the raw PyObject from the Boost.Python object
if (PyArray_DescrCheck(dtype_pyobj)) {
numpy_type = (reinterpret_case<PyArray_Descr*>(dtype_pyobj))->type_num;
} else {
throw(rogue::GeneralError::create("Frame::getNumpy",
"Invalid dtype argument. Must be a NumPy dtype object."));
throw(rogue::GeneralError::create("Frame::getNumpy", "Invalid dtype argument. Must be a NumPy dtype object."));
}

// Create a numpy array to receive it and locate the destination data buffer
Expand Down Expand Up @@ -547,24 +539,19 @@ void ris::Frame::setup_python() {
// Create a NumPy dtype object from the NPY_UINT8 constant
PyObject* dtype_uint8 = reinterpret_cast<PyObject*>(PyArray_DescrFromType(NPY_UINT8));
if (!dtype_uint8) {
throw(rogue::GeneralError::create("Frame::setup_python",
"Failed to create default dtype object for NPY_UINT8."));
throw(
rogue::GeneralError::create("Frame::setup_python", "Failed to create default dtype object for NPY_UINT8."));
}


bp::class_<ris::Frame, ris::FramePtr, boost::noncopyable>("Frame", bp::no_init)
.def("lock", &ris::Frame::lock)
.def("getSize", &ris::Frame::getSize)
.def("getAvailable", &ris::Frame::getAvailable)
.def("getPayload", &ris::Frame::getPayload)
.def("read", &ris::Frame::readPy, (
bp::arg("offset")=0))
.def("getBa", &ris::Frame::getBytearrayPy, (
bp::arg("offset")=0,
bp::arg("count")=0))
.def("read", &ris::Frame::readPy, (bp::arg("offset") = 0))
.def("getBa", &ris::Frame::getBytearrayPy, (bp::arg("offset") = 0, bp::arg("count") = 0))
.def("getMemoryview", &ris::Frame::getMemoryviewPy)
.def("write", &ris::Frame::writePy, (
bp::arg("offset")=0))
.def("write", &ris::Frame::writePy, (bp::arg("offset") = 0))
.def("setError", &ris::Frame::setError)
.def("getError", &ris::Frame::getError)
.def("setFlags", &ris::Frame::setFlags)
Expand All @@ -575,12 +562,12 @@ void ris::Frame::setup_python() {
.def("getLastUser", &ris::Frame::getLastUser)
.def("setChannel", &ris::Frame::setChannel)
.def("getChannel", &ris::Frame::getChannel)
.def("getNumpy", &ris::Frame::getNumpy, (
bp::arg("offset")=0,
bp::arg("count")=0,
bp::arg("dtype")=bp::object(bp::handle<>(bp::borrowed(dtype_uint8)))))
.def("putNumpy", &ris::Frame::putNumpy, (
bp::arg("offset")=0))
.def("getNumpy",
&ris::Frame::getNumpy,
(bp::arg("offset") = 0,
bp::arg("count") = 0,
bp::arg("dtype") = bp::object(bp::handle<>(bp::borrowed(dtype_uint8)))))
.def("putNumpy", &ris::Frame::putNumpy, (bp::arg("offset") = 0))
.def("_debug", &ris::Frame::debug);
#endif
}
Expand Down

0 comments on commit d6b2503

Please sign in to comment.