From 0048778f80269ddbf9f2b6dd9bbcd5dab3494232 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 27 Oct 2018 18:12:36 +0200 Subject: [PATCH] remove trailing whitespaces --- src/App/PropertyContainerPyImp.cpp | 49 +++++++++++++++--------------- src/Base/Persistence.cpp | 14 ++++----- src/Base/Persistence.h | 4 +-- src/Base/PersistencePyImp.cpp | 45 +++++++++++++-------------- 4 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/App/PropertyContainerPyImp.cpp b/src/App/PropertyContainerPyImp.cpp index fe7b3821d2..43e06e700d 100644 --- a/src/App/PropertyContainerPyImp.cpp +++ b/src/App/PropertyContainerPyImp.cpp @@ -230,8 +230,8 @@ Py::List PropertyContainerPy::getPropertiesList(void) const } -PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwds) { - +PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwds) +{ int compression = 3; char* property; static char* kwds_def[] = {"Property", "Compression",NULL}; @@ -239,36 +239,37 @@ PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwd if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwds_def, &property, &compression)) { return NULL; } - + Property* prop = getPropertyContainerPtr()->getPropertyByName(property); if (!prop) { PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", property); return 0; - } - + } + //setup the stream. the in flag is needed to make "read" work std::stringstream stream(std::stringstream::out | std::stringstream::in | std::stringstream::binary); try { - prop->dumpToStream(stream, compression); + prop->dumpToStream(stream, compression); } - catch(...) { + catch (...) { PyErr_SetString(PyExc_IOError, "Unable parse content into binary representation"); return NULL; } - + //build the byte array with correct size - if(!stream.seekp(0, stream.end)) { + if (!stream.seekp(0, stream.end)) { PyErr_SetString(PyExc_IOError, "Unable to find end of stream"); return NULL; - } + } + std::stringstream::pos_type offset = stream.tellp(); - if(!stream.seekg(0, stream.beg)) { + if (!stream.seekg(0, stream.beg)) { PyErr_SetString(PyExc_IOError, "Unable to find begin of stream"); return NULL; } - + PyObject* ba = PyByteArray_FromStringAndSize(NULL, offset); - + //use the buffer protocol to access the underlying array and write into it Py_buffer buf = Py_buffer(); PyObject_GetBuffer(ba, &buf, PyBUF_WRITABLE); @@ -279,48 +280,48 @@ PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwd } PyBuffer_Release(&buf); } - catch(...) { + catch (...) { PyBuffer_Release(&buf); PyErr_SetString(PyExc_IOError, "Error copying data into byte array"); return NULL; } - - return ba; + + return ba; } -PyObject* PropertyContainerPy::restorePropertyContent(PyObject *args) { - +PyObject* PropertyContainerPy::restorePropertyContent(PyObject *args) +{ PyObject* buffer; char* property; if( !PyArg_ParseTuple(args, "sO", &property, &buffer) ) return NULL; - + Property* prop = getPropertyContainerPtr()->getPropertyByName(property); if (!prop) { PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", property); return 0; } - + //check if it really is a buffer if( !PyObject_CheckBuffer(buffer) ) { PyErr_SetString(PyExc_TypeError, "Must be a buffer object"); return NULL; } - + Py_buffer buf; if(PyObject_GetBuffer(buffer, &buf, PyBUF_SIMPLE) < 0) return NULL; - + if(!PyBuffer_IsContiguous(&buf, 'C')) { PyErr_SetString(PyExc_TypeError, "Buffer must be contiguous"); return NULL; } - + //check if it really is a buffer try { typedef boost::iostreams::basic_array_source Device; boost::iostreams::stream stream((char*)buf.buf, buf.len); - prop->restoreFromStream(stream); + prop->restoreFromStream(stream); } catch(...) { PyErr_SetString(PyExc_IOError, "Unable to restore content"); diff --git a/src/Base/Persistence.cpp b/src/Base/Persistence.cpp index bcb0d4589b..ba14ec766d 100644 --- a/src/Base/Persistence.cpp +++ b/src/Base/Persistence.cpp @@ -99,8 +99,8 @@ std::string Persistence::encodeAttribute(const std::string& str) return tmp; } -void Persistence::dumpToStream(std::ostream& stream, int compression) { - +void Persistence::dumpToStream(std::ostream& stream, int compression) +{ //we need to close the zipstream to get a good result, the only way to do this is to delete the ZipWriter. //Hence the scope... { @@ -108,8 +108,8 @@ void Persistence::dumpToStream(std::ostream& stream, int compression) { Base::ZipWriter writer(stream); writer.setLevel(compression); writer.putNextEntry("Persistence.xml"); - writer.setMode("BinaryBrep"); - + writer.setMode("BinaryBrep"); + //save the content (we need to encapsulte it with xml tags to be able to read single element xmls like happen for properties) writer.Stream() << "" << std::endl; Save(writer); @@ -118,14 +118,14 @@ void Persistence::dumpToStream(std::ostream& stream, int compression) { } } -void Persistence::restoreFromStream(std::istream& stream) { - +void Persistence::restoreFromStream(std::istream& stream) +{ zipios::ZipInputStream zipstream(stream); Base::XMLReader reader("", zipstream); if (!reader.isValid()) throw Base::ValueError("Unable to construct reader"); - + reader.readElement("Content"); Restore(reader); reader.readFiles(zipstream); diff --git a/src/Base/Persistence.h b/src/Base/Persistence.h index 5b305e9845..2a48c2ad4a 100644 --- a/src/Base/Persistence.h +++ b/src/Base/Persistence.h @@ -148,10 +148,10 @@ public: virtual void RestoreDocFile(Reader &/*reader*/); /// Encodes an attribute upon saving. static std::string encodeAttribute(const std::string&); - + //dump the binary persistence data into into the stream void dumpToStream(std::ostream& stream, int compression); - + //restore the binary persistence data from a stream. Must have the format used by dumpToStream void restoreFromStream(std::istream& stream); }; diff --git a/src/Base/PersistencePyImp.cpp b/src/Base/PersistencePyImp.cpp index 6d796778d1..bd8b5d41c1 100644 --- a/src/Base/PersistencePyImp.cpp +++ b/src/Base/PersistencePyImp.cpp @@ -43,8 +43,8 @@ std::string PersistencePy::representation(void) const Py::String PersistencePy::getContent(void) const { Base::StringWriter writer; - // force all objects to write pure XML without files - writer.setForceXML(true); + // force all objects to write pure XML without files + writer.setForceXML(true); getPersistencePtr()->Save(writer); return Py::String (writer.getString()); @@ -55,38 +55,39 @@ Py::Int PersistencePy::getMemSize(void) const return Py::Int((long)getPersistencePtr()->getMemSize()); } -PyObject* PersistencePy::dumpContent(PyObject *args, PyObject *kwds) { - +PyObject* PersistencePy::dumpContent(PyObject *args, PyObject *kwds) +{ int compression = 3; static char* kwds_def[] = {"Compression",NULL}; PyErr_Clear(); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwds_def, &compression)) { return NULL; } - + //setup the stream. the in flag is needed to make "read" work std::stringstream stream(std::stringstream::out | std::stringstream::in | std::stringstream::binary); try { - getPersistencePtr()->dumpToStream(stream, compression); + getPersistencePtr()->dumpToStream(stream, compression); } - catch(...) { + catch (...) { PyErr_SetString(PyExc_IOError, "Unable parse content into binary representation"); - return NULL; + return NULL; } - + //build the byte array with correct size if(!stream.seekp(0, stream.end)) { PyErr_SetString(PyExc_IOError, "Unable to find end of stream"); return NULL; - } + } + std::stringstream::pos_type offset = stream.tellp(); - if(!stream.seekg(0, stream.beg)) { + if (!stream.seekg(0, stream.beg)) { PyErr_SetString(PyExc_IOError, "Unable to find begin of stream"); return NULL; } - + PyObject* ba = PyByteArray_FromStringAndSize(NULL, offset); - + //use the buffer protocol to access the underlying array and write into it Py_buffer buf = Py_buffer(); PyObject_GetBuffer(ba, &buf, PyBUF_WRITABLE); @@ -102,12 +103,12 @@ PyObject* PersistencePy::dumpContent(PyObject *args, PyObject *kwds) { PyErr_SetString(PyExc_IOError, "Error copying data into byte array"); return NULL; } - - return ba; + + return ba; } -PyObject* PersistencePy::restoreContent(PyObject *args) { - +PyObject* PersistencePy::restoreContent(PyObject *args) +{ PyObject* buffer; if( !PyArg_ParseTuple(args, "O", &buffer) ) return NULL; @@ -117,23 +118,23 @@ PyObject* PersistencePy::restoreContent(PyObject *args) { PyErr_SetString(PyExc_TypeError, "Must be a buffer object"); return NULL; } - + Py_buffer buf; if(PyObject_GetBuffer(buffer, &buf, PyBUF_SIMPLE) < 0) return NULL; - + if(!PyBuffer_IsContiguous(&buf, 'C')) { PyErr_SetString(PyExc_TypeError, "Buffer must be contiguous"); return NULL; } - + //check if it really is a buffer try { typedef boost::iostreams::basic_array_source Device; boost::iostreams::stream stream((char*)buf.buf, buf.len); - getPersistencePtr()->restoreFromStream(stream); + getPersistencePtr()->restoreFromStream(stream); } - catch(...) { + catch (...) { PyErr_SetString(PyExc_IOError, "Unable to restore content"); return NULL; }