App: Apply clang format (part 2)

This commit is contained in:
wmayer
2024-11-21 12:27:35 +01:00
committed by wwmayer
parent 164f1e3813
commit fadfc7e270
44 changed files with 12163 additions and 8775 deletions

View File

@@ -41,12 +41,11 @@ using namespace Base;
using namespace std;
//**************************************************************************
// PropertyFileIncluded
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TYPESYSTEM_SOURCE(App::PropertyFileIncluded , App::Property)
TYPESYSTEM_SOURCE(App::PropertyFileIncluded, App::Property)
PropertyFileIncluded::PropertyFileIncluded() = default;
@@ -78,7 +77,7 @@ void PropertyFileIncluded::aboutToSetValue()
std::string PropertyFileIncluded::getDocTransientPath() const
{
std::string path;
PropertyContainer *co = getContainer();
PropertyContainer* co = getContainer();
if (co->isDerivedFrom(DocumentObject::getClassTypeId())) {
path = static_cast<DocumentObject*>(co)->getDocument()->TransientDir.getValue();
std::replace(path.begin(), path.end(), '\\', '/');
@@ -86,7 +85,8 @@ std::string PropertyFileIncluded::getDocTransientPath() const
return path;
}
std::string PropertyFileIncluded::getUniqueFileName(const std::string& path, const std::string& filename) const
std::string PropertyFileIncluded::getUniqueFileName(const std::string& path,
const std::string& filename) const
{
Base::Uuid uuid;
Base::FileInfo fi(path + "/" + filename);
@@ -99,8 +99,8 @@ std::string PropertyFileIncluded::getUniqueFileName(const std::string& path, con
std::string PropertyFileIncluded::getExchangeTempFile() const
{
return Base::FileInfo::getTempFileName(Base::FileInfo
(getValue()).fileName().c_str(), getDocTransientPath().c_str());
return Base::FileInfo::getTempFileName(Base::FileInfo(getValue()).fileName().c_str(),
getDocTransientPath().c_str());
}
std::string PropertyFileIncluded::getOriginalFileName() const
@@ -111,8 +111,9 @@ std::string PropertyFileIncluded::getOriginalFileName() const
void PropertyFileIncluded::setValue(const char* sFile, const char* sName)
{
if (sFile && sFile[0] != '\0') {
if (_cValue == sFile)
if (_cValue == sFile) {
throw Base::FileSystemError("Not possible to set the same file!");
}
// keep the path to the original file
_OriginalName = sFile;
@@ -126,7 +127,7 @@ void PropertyFileIncluded::setValue(const char* sFile, const char* sName)
throw Base::FileSystemError(str.str());
}
aboutToSetValue(); // undo/redo by moving the file away with temp name
aboutToSetValue(); // undo/redo by moving the file away with temp name
// remove old file (if not moved by undo)
Base::FileInfo value(_cValue);
@@ -144,16 +145,16 @@ void PropertyFileIncluded::setValue(const char* sFile, const char* sName)
std::string dir = pathTrans;
std::string fnp = fi.fileNamePure();
std::string ext = fi.extension();
int i=0;
int i = 0;
do {
i++;
std::stringstream str;
str << dir << "/" << fnp << i;
if (!ext.empty())
if (!ext.empty()) {
str << "." << ext;
}
fi.setFile(str.str());
}
while (fi.exists());
} while (fi.exists());
_cValue = fi.filePath();
_BaseFileName = fi.fileName();
@@ -189,7 +190,7 @@ void PropertyFileIncluded::setValue(const char* sFile, const char* sName)
Base::FileInfo dst(_cValue);
dst.setPermissions(Base::FileInfo::ReadOnly);
}
// otherwise copy from origin location
// otherwise copy from origin location
else {
// if file already exists in transient dir make a new unique name
Base::FileInfo fi(_cValue);
@@ -198,16 +199,16 @@ void PropertyFileIncluded::setValue(const char* sFile, const char* sName)
std::string dir = fi.dirPath();
std::string fnp = fi.fileNamePure();
std::string ext = fi.extension();
int i=0;
int i = 0;
do {
i++;
std::stringstream str;
str << dir << "/" << fnp << i;
if (!ext.empty())
if (!ext.empty()) {
str << "." << ext;
}
fi.setFile(str.str());
}
while (fi.exists());
} while (fi.exists());
_cValue = fi.filePath();
_BaseFileName = fi.fileName();
@@ -231,40 +232,41 @@ void PropertyFileIncluded::setValue(const char* sFile, const char* sName)
const char* PropertyFileIncluded::getValue() const
{
return _cValue.c_str();
return _cValue.c_str();
}
PyObject *PropertyFileIncluded::getPyObject()
PyObject* PropertyFileIncluded::getPyObject()
{
PyObject *p = PyUnicode_DecodeUTF8(_cValue.c_str(),_cValue.size(),nullptr);
PyObject* p = PyUnicode_DecodeUTF8(_cValue.c_str(), _cValue.size(), nullptr);
if (!p) {
throw Base::UnicodeError("PropertyFileIncluded: UTF-8 conversion failure");
}
return p;
}
namespace App {
namespace App
{
const char* getNameFromFile(PyObject* value)
{
const char* string = nullptr;
PyObject *oname = PyObject_GetAttrString (value, "name");
PyObject* oname = PyObject_GetAttrString(value, "name");
if (oname) {
if (PyUnicode_Check (oname)) {
string = PyUnicode_AsUTF8 (oname);
if (PyUnicode_Check(oname)) {
string = PyUnicode_AsUTF8(oname);
}
else if (PyBytes_Check (oname)) {
string = PyBytes_AsString (oname);
else if (PyBytes_Check(oname)) {
string = PyBytes_AsString(oname);
}
Py_DECREF (oname);
Py_DECREF(oname);
}
if (!string)
if (!string) {
throw Base::TypeError("Unable to get filename");
}
return string;
}
bool isIOFile(PyObject* file)
{
PyObject* io = PyImport_ImportModule("io");
@@ -274,9 +276,9 @@ bool isIOFile(PyObject* file)
Py_DECREF(io);
return isFile;
}
}
} // namespace App
void PropertyFileIncluded::setPyObject(PyObject *value)
void PropertyFileIncluded::setPyObject(PyObject* value)
{
if (PyUnicode_Check(value)) {
std::string string = PyUnicode_AsUTF8(value);
@@ -286,15 +288,16 @@ void PropertyFileIncluded::setPyObject(PyObject *value)
std::string string = PyBytes_AsString(value);
setValue(string.c_str());
}
else if (isIOFile(value)){
else if (isIOFile(value)) {
std::string string = getNameFromFile(value);
setValue(string.c_str());
}
else if (PyTuple_Check(value)) {
if (PyTuple_Size(value) != 2)
throw Base::TypeError("Tuple needs size of (filePath,newFileName)");
PyObject* file = PyTuple_GetItem(value,0);
PyObject* name = PyTuple_GetItem(value,1);
if (PyTuple_Size(value) != 2) {
throw Base::TypeError("Tuple needs size of (filePath,newFileName)");
}
PyObject* file = PyTuple_GetItem(value, 0);
PyObject* name = PyTuple_GetItem(value, 1);
// decoding file
std::string fileStr;
@@ -330,7 +333,7 @@ void PropertyFileIncluded::setPyObject(PyObject *value)
throw Base::TypeError(error);
}
setValue(fileStr.c_str(),nameStr.c_str());
setValue(fileStr.c_str(), nameStr.c_str());
}
else if (PyDict_Check(value)) {
Py::Dict dict(value);
@@ -349,39 +352,40 @@ void PropertyFileIncluded::setPyObject(PyObject *value)
}
}
void PropertyFileIncluded::Save (Base::Writer &writer) const
void PropertyFileIncluded::Save(Base::Writer& writer) const
{
// when saving a document under a new file name the transient directory
// name changes and thus the stored file name doesn't work any more.
if (!_cValue.empty() && !Base::FileInfo(_cValue).exists()) {
Base::FileInfo fi(getDocTransientPath() + "/" + _BaseFileName);
if (fi.exists())
if (fi.exists()) {
_cValue = fi.filePath();
}
}
if (writer.isForceXML()) {
if (!_cValue.empty()) {
Base::FileInfo file(_cValue.c_str());
writer.Stream() << writer.ind() << "<FileIncluded data=\""
<< file.fileName() << "\">" << std::endl;
writer.Stream() << writer.ind() << "<FileIncluded data=\"" << file.fileName() << "\">"
<< std::endl;
// write the file in the XML stream
writer.incInd();
writer.insertBinFile(_cValue.c_str());
writer.decInd();
writer.Stream() << writer.ind() <<"</FileIncluded>" << endl;
writer.Stream() << writer.ind() << "</FileIncluded>" << endl;
}
else {
writer.Stream() << writer.ind() << "<FileIncluded data=\"\"/>" << std::endl;
}
}
else {
// instead initiate an extra file
// instead initiate an extra file
if (!_cValue.empty()) {
Base::FileInfo file(_cValue.c_str());
std::string filename = writer.addFile(file.fileName().c_str(), this);
filename = encodeAttribute(filename);
writer.Stream() << writer.ind() << "<FileIncluded file=\""
<< filename << "\"/>" << std::endl;
writer.Stream() << writer.ind() << "<FileIncluded file=\"" << filename << "\"/>"
<< std::endl;
}
else {
writer.Stream() << writer.ind() << "<FileIncluded file=\"\"/>" << std::endl;
@@ -389,14 +393,14 @@ void PropertyFileIncluded::Save (Base::Writer &writer) const
}
}
void PropertyFileIncluded::Restore(Base::XMLReader &reader)
void PropertyFileIncluded::Restore(Base::XMLReader& reader)
{
reader.readElement("FileIncluded");
if (reader.hasAttribute("file")) {
string file (reader.getAttribute("file") );
string file(reader.getAttribute("file"));
if (!file.empty()) {
// initiate a file read
reader.addFile(file.c_str(),this);
reader.addFile(file.c_str(), this);
// is in the document transient path
aboutToSetValue();
_cValue = getDocTransientPath() + "/" + file;
@@ -406,7 +410,7 @@ void PropertyFileIncluded::Restore(Base::XMLReader &reader)
}
// section is XML stream
else if (reader.hasAttribute("data")) {
string file (reader.getAttribute("data") );
string file(reader.getAttribute("data"));
if (!file.empty()) {
// is in the document transient path
aboutToSetValue();
@@ -422,7 +426,7 @@ void PropertyFileIncluded::Restore(Base::XMLReader &reader)
}
}
void PropertyFileIncluded::SaveDocFile (Base::Writer &writer) const
void PropertyFileIncluded::SaveDocFile(Base::Writer& writer) const
{
Base::ifstream from(Base::FileInfo(_cValue.c_str()), std::ios::in | std::ios::binary);
if (!from) {
@@ -440,7 +444,7 @@ void PropertyFileIncluded::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
void PropertyFileIncluded::RestoreDocFile(Base::Reader& reader)
{
Base::FileInfo fi(_cValue.c_str());
if (fi.exists() && !fi.isWritable()) {
@@ -469,7 +473,7 @@ void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
hasSetValue();
}
Property *PropertyFileIncluded::Copy() const
Property* PropertyFileIncluded::Copy() const
{
std::unique_ptr<PropertyFileIncluded> prop(new PropertyFileIncluded());
@@ -486,8 +490,8 @@ Property *PropertyFileIncluded::Copy() const
if (!done) {
std::stringstream str;
str << "PropertyFileIncluded::Copy(): "
<< "Renaming the file '" << file.filePath() << "' to '"
<< newName.filePath() << "' failed.";
<< "Renaming the file '" << file.filePath() << "' to '" << newName.filePath()
<< "' failed.";
throw Base::FileSystemError(str.str());
}
}
@@ -497,14 +501,14 @@ Property *PropertyFileIncluded::Copy() const
if (!done) {
std::stringstream str;
str << "PropertyFileIncluded::Copy(): "
<< "Copying the file '" << file.filePath() << "' to '"
<< newName.filePath() << "' failed.";
<< "Copying the file '" << file.filePath() << "' to '" << newName.filePath()
<< "' failed.";
throw Base::FileSystemError(str.str());
}
}
// remember the new name for the Undo
Base::Console().Log("Copy '%s' to '%s'\n",_cValue.c_str(),newName.filePath().c_str());
Base::Console().Log("Copy '%s' to '%s'\n", _cValue.c_str(), newName.filePath().c_str());
prop->_cValue = newName.filePath().c_str();
// make backup files writable to avoid copying them again on undo/redo
@@ -514,10 +518,10 @@ Property *PropertyFileIncluded::Copy() const
return prop.release();
}
void PropertyFileIncluded::Paste(const Property &from)
void PropertyFileIncluded::Paste(const Property& from)
{
aboutToSetValue();
const PropertyFileIncluded &prop = dynamic_cast<const PropertyFileIncluded&>(from);
const PropertyFileIncluded& prop = dynamic_cast<const PropertyFileIncluded&>(from);
// make sure that source and destination file are different
if (_cValue != prop._cValue) {
// delete old file (if still there)
@@ -540,8 +544,8 @@ void PropertyFileIncluded::Paste(const Property &from)
if (!fiSrc.renameFile(fiDst.filePath().c_str())) {
std::stringstream str;
str << "PropertyFileIncluded::Paste(): "
<< "Renaming the file '" << fiSrc.filePath() << "' to '"
<< fiDst.filePath() << "' failed.";
<< "Renaming the file '" << fiSrc.filePath() << "' to '" << fiDst.filePath()
<< "' failed.";
throw Base::FileSystemError(str.str());
}
}
@@ -549,8 +553,8 @@ void PropertyFileIncluded::Paste(const Property &from)
if (!fiSrc.copyTo(fiDst.filePath().c_str())) {
std::stringstream str;
str << "PropertyFileIncluded::Paste(): "
<< "Copying the file '" << fiSrc.filePath() << "' to '"
<< fiDst.filePath() << "' failed.";
<< "Copying the file '" << fiSrc.filePath() << "' to '" << fiDst.filePath()
<< "' failed.";
throw Base::FileSystemError(str.str());
}
}
@@ -569,7 +573,7 @@ void PropertyFileIncluded::Paste(const Property &from)
hasSetValue();
}
unsigned int PropertyFileIncluded::getMemSize () const
unsigned int PropertyFileIncluded::getMemSize() const
{
unsigned int mem = Property::getMemSize();
mem += _cValue.size();
@@ -591,7 +595,7 @@ std::string PropertyFileIncluded::getFilter() const
// PropertyFile
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TYPESYSTEM_SOURCE(App::PropertyFile , App::PropertyString)
TYPESYSTEM_SOURCE(App::PropertyFile, App::PropertyString)
PropertyFile::PropertyFile()
{
@@ -610,7 +614,7 @@ std::string PropertyFile::getFilter() const
return m_filter;
}
void PropertyFile::setPyObject(PyObject *value)
void PropertyFile::setPyObject(PyObject* value)
{
if (PyDict_Check(value)) {
Py::Dict dict(value);
@@ -626,4 +630,3 @@ void PropertyFile::setPyObject(PyObject *value)
PropertyString::setPyObject(value);
}
}