Base: modernize C++: use default member init

This commit is contained in:
wmayer
2023-08-23 12:10:14 +02:00
committed by wwmayer
parent a60c9c2cf1
commit 4fb07bcfd6
18 changed files with 112 additions and 102 deletions

View File

@@ -117,13 +117,10 @@ ConsoleOutput* ConsoleOutput::instance = nullptr;
ConsoleSingleton::ConsoleSingleton()
: _bVerbose(true)
, _bCanRefresh(true)
, connectionMode(Direct)
#ifdef FC_DEBUG
,_defaultLogLevel(FC_LOGLEVEL_LOG)
: _defaultLogLevel(FC_LOGLEVEL_LOG)
#else
,_defaultLogLevel(FC_LOGLEVEL_MSG)
: _defaultLogLevel(FC_LOGLEVEL_MSG)
#endif
{
}

View File

@@ -511,8 +511,7 @@ enum class ContentType {
class BaseExport ILogger
{
public:
ILogger()
:bErr(true), bMsg(true), bLog(true), bWrn(true), bCritical(true), bNotification(false){}
ILogger() = default;
virtual ~ILogger() = 0;
/** Used to send a Log message at the given level.
@@ -562,7 +561,12 @@ public:
}
virtual const char *Name(){return nullptr;}
bool bErr, bMsg, bLog, bWrn, bCritical, bNotification;
bool bErr{true};
bool bMsg{true};
bool bLog{true};
bool bWrn{true};
bool bCritical{true};
bool bNotification{false};
};
@@ -810,9 +814,9 @@ protected:
static PyObject *sPyGetStatus (PyObject *self,PyObject *args);
static PyObject *sPyGetObservers (PyObject *self,PyObject *args);
bool _bVerbose;
bool _bCanRefresh;
ConnectionMode connectionMode;
bool _bVerbose{true};
bool _bCanRefresh{true};
ConnectionMode connectionMode{Direct};
// Singleton!
ConsoleSingleton();

View File

@@ -36,13 +36,7 @@ using namespace Base;
* A constructor.
* A more elaborate description of the constructor.
*/
ClassTemplate::ClassTemplate()
: enumPtr(nullptr)
, enumVar(TVal1)
, publicVar(0)
, handler(nullptr)
{
}
ClassTemplate::ClassTemplate() = default;
/**
* A destructor.

View File

@@ -101,8 +101,8 @@ public:
TVal2, /**< enum value TVal2. */
TVal3 /**< enum value TVal3. */
}
*enumPtr, /**< enum pointer. Details. */
enumVar; /**< enum variable. Details. */
*enumPtr{nullptr}, /**< enum pointer. Details. */
enumVar{TVal1}; /**< enum variable. Details. */
/**
* A pure virtual member.
@@ -127,13 +127,13 @@ public:
* a public variable.
* Details.
*/
int publicVar;
int publicVar{0};
/**
* a function variable.
* Details.
*/
int (*handler)(int a,int b);
int (*handler)(int a,int b){nullptr};
std::string something;
};

View File

@@ -81,9 +81,7 @@ public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DOMTreeErrorReporter() :
fSawErrors(false) {
}
DOMTreeErrorReporter() = default;
~DOMTreeErrorReporter() override = default;
@@ -109,7 +107,7 @@ public:
// method. Its used by the main code to suppress output if there are
// errors.
// -----------------------------------------------------------------------
bool fSawErrors;
bool fSawErrors{false};
};
@@ -1441,7 +1439,6 @@ static XercesDOMParser::ValSchemes gValScheme = XercesDOMParser::Val_Au
/** Default construction
*/
ParameterManager::ParameterManager()
: ParameterGrp(), _pDocument(nullptr), paramSerializer(nullptr)
{
_Manager = this;

View File

@@ -414,8 +414,8 @@ public:
private:
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *_pDocument;
ParameterSerializer * paramSerializer;
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *_pDocument{nullptr};
ParameterSerializer * paramSerializer{nullptr};
bool gDoNamespaces ;
bool gDoSchema ;

View File

@@ -55,10 +55,8 @@ typedef struct {
} PyBaseProxy;
// Constructor
PyObjectBase::PyObjectBase(void* p,PyTypeObject *T)
: _pcTwinPointer(p)
, baseProxy(nullptr)
, attrDict(nullptr)
PyObjectBase::PyObjectBase(void* voidp, PyTypeObject *T)
: _pcTwinPointer(voidp)
{
#if PY_VERSION_HEX < 0x030b0000
Py_TYPE(this) = T;

View File

@@ -342,10 +342,10 @@ protected:
void * _pcTwinPointer;
public:
PyObject* baseProxy;
PyObject* baseProxy{nullptr};
private:
PyObject* attrDict;
PyObject* attrDict{nullptr};
};

View File

@@ -56,9 +56,7 @@ using namespace std;
// ---------------------------------------------------------------------------
Base::XMLReader::XMLReader(const char* FileName, std::istream& str)
: DocumentSchema(0), ProgramVersion(""), FileVersion(0), Level(0),
CharacterCount(0), ReadType(None), _File(FileName), _valid(false),
_verbose(true)
: _File(FileName)
{
#ifdef _MSC_VER
str.imbue(std::locale::empty());

View File

@@ -214,11 +214,11 @@ public:
//@}
/// Schema Version of the document
int DocumentSchema;
int DocumentSchema{0};
/// Version of FreeCAD that wrote this document
std::string ProgramVersion;
/// Version of the file format
int FileVersion;
int FileVersion{0};
/// sets simultaneously the global and local PartialRestore bits
void setPartialRestore(bool on);
@@ -278,10 +278,10 @@ protected:
//@}
int Level;
int Level{0};
std::string LocalName;
std::string Characters;
unsigned int CharacterCount;
unsigned int CharacterCount{0};
std::streamsize CharacterOffset{-1};
std::map<std::string,std::string> AttrMap;
@@ -297,14 +297,14 @@ protected:
EndElement,
StartCDATA,
EndCDATA
} ReadType;
} ReadType{None};
FileInfo _File;
XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* parser;
XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken token;
bool _valid;
bool _verbose;
bool _valid{false};
bool _verbose{true};
std::vector<std::string> FileNames;

View File

@@ -78,7 +78,6 @@ SequencerBase& SequencerBase::Instance ()
}
SequencerBase::SequencerBase()
: nProgress(0), nTotalSteps(0), _bLocked(false), _bCanceled(false), _nLastPercentage(-1)
{
SequencerP::appendInstance(this);
}

View File

@@ -236,13 +236,15 @@ protected:
virtual void resetData();
protected:
size_t nProgress; /**< Stores the current amount of progress.*/
size_t nTotalSteps; /**< Stores the total number of steps */
//NOLINTBEGIN
size_t nProgress{0}; /**< Stores the current amount of progress.*/
size_t nTotalSteps{0}; /**< Stores the total number of steps */
//NOLINTEND
private:
bool _bLocked; /**< Lock/unlock sequencer. */
bool _bCanceled; /**< Is set to true if the last pending operation was canceled */
int _nLastPercentage; /**< Progress in percent. */
bool _bLocked{false}; /**< Lock/unlock sequencer. */
bool _bCanceled{false}; /**< Is set to true if the last pending operation was canceled */
int _nLastPercentage{-1}; /**< Progress in percent. */
};
/** This special sequencer might be useful if you want to suppress any indication

View File

@@ -40,9 +40,7 @@
using namespace Base;
Stream::Stream() : _swap(false)
{
}
Stream::Stream() = default;
Stream::~Stream() = default;
@@ -82,56 +80,56 @@ OutputStream& OutputStream::operator << (uint8_t uch)
OutputStream& OutputStream::operator << (int16_t s)
{
if (_swap) SwapEndian<int16_t>(s);
if (isSwapped()) SwapEndian<int16_t>(s);
_out.write((const char*)&s, sizeof(int16_t));
return *this;
}
OutputStream& OutputStream::operator << (uint16_t us)
{
if (_swap) SwapEndian<uint16_t>(us);
if (isSwapped()) SwapEndian<uint16_t>(us);
_out.write((const char*)&us, sizeof(uint16_t));
return *this;
}
OutputStream& OutputStream::operator << (int32_t i)
{
if (_swap) SwapEndian<int32_t>(i);
if (isSwapped()) SwapEndian<int32_t>(i);
_out.write((const char*)&i, sizeof(int32_t));
return *this;
}
OutputStream& OutputStream::operator << (uint32_t ui)
{
if (_swap) SwapEndian<uint32_t>(ui);
if (isSwapped()) SwapEndian<uint32_t>(ui);
_out.write((const char*)&ui, sizeof(uint32_t));
return *this;
}
OutputStream& OutputStream::operator << (int64_t l)
{
if (_swap) SwapEndian<int64_t>(l);
if (isSwapped()) SwapEndian<int64_t>(l);
_out.write((const char*)&l, sizeof(int64_t));
return *this;
}
OutputStream& OutputStream::operator << (uint64_t ul)
{
if (_swap) SwapEndian<uint64_t>(ul);
if (isSwapped()) SwapEndian<uint64_t>(ul);
_out.write((const char*)&ul, sizeof(uint64_t));
return *this;
}
OutputStream& OutputStream::operator << (float f)
{
if (_swap) SwapEndian<float>(f);
if (isSwapped()) SwapEndian<float>(f);
_out.write((const char*)&f, sizeof(float));
return *this;
}
OutputStream& OutputStream::operator << (double d)
{
if (_swap) SwapEndian<double>(d);
if (isSwapped()) SwapEndian<double>(d);
_out.write((const char*)&d, sizeof(double));
return *this;
}
@@ -163,56 +161,56 @@ InputStream& InputStream::operator >> (uint8_t& uch)
InputStream& InputStream::operator >> (int16_t& s)
{
_in.read((char*)&s, sizeof(int16_t));
if (_swap) SwapEndian<int16_t>(s);
if (isSwapped()) SwapEndian<int16_t>(s);
return *this;
}
InputStream& InputStream::operator >> (uint16_t& us)
{
_in.read((char*)&us, sizeof(uint16_t));
if (_swap) SwapEndian<uint16_t>(us);
if (isSwapped()) SwapEndian<uint16_t>(us);
return *this;
}
InputStream& InputStream::operator >> (int32_t& i)
{
_in.read((char*)&i, sizeof(int32_t));
if (_swap) SwapEndian<int32_t>(i);
if (isSwapped()) SwapEndian<int32_t>(i);
return *this;
}
InputStream& InputStream::operator >> (uint32_t& ui)
{
_in.read((char*)&ui, sizeof(uint32_t));
if (_swap) SwapEndian<uint32_t>(ui);
if (isSwapped()) SwapEndian<uint32_t>(ui);
return *this;
}
InputStream& InputStream::operator >> (int64_t& l)
{
_in.read((char*)&l, sizeof(int64_t));
if (_swap) SwapEndian<int64_t>(l);
if (isSwapped()) SwapEndian<int64_t>(l);
return *this;
}
InputStream& InputStream::operator >> (uint64_t& ul)
{
_in.read((char*)&ul, sizeof(uint64_t));
if (_swap) SwapEndian<uint64_t>(ul);
if (isSwapped()) SwapEndian<uint64_t>(ul);
return *this;
}
InputStream& InputStream::operator >> (float& f)
{
_in.read((char*)&f, sizeof(float));
if (_swap) SwapEndian<float>(f);
if (isSwapped()) SwapEndian<float>(f);
return *this;
}
InputStream& InputStream::operator >> (double& d)
{
_in.read((char*)&d, sizeof(double));
if (_swap) SwapEndian<double>(d);
if (isSwapped()) SwapEndian<double>(d);
return *this;
}
@@ -284,11 +282,12 @@ ByteArrayOStreambuf::seekpos(std::streambuf::pos_type pos,
// ----------------------------------------------------------------------
ByteArrayIStreambuf::ByteArrayIStreambuf(const QByteArray& data) : _buffer(data)
ByteArrayIStreambuf::ByteArrayIStreambuf(const QByteArray& data)
: _buffer(data)
, _beg(0)
, _end(data.size())
, _cur(0)
{
_beg = 0;
_end = data.size();
_cur = 0;
}
ByteArrayIStreambuf::~ByteArrayIStreambuf() = default;
@@ -416,7 +415,7 @@ IODeviceOStreambuf::seekpos(std::streambuf::pos_type pos,
// ----------------------------------------------------------------------
IODeviceIStreambuf::IODeviceIStreambuf(QIODevice* dev) : device(dev), buffer{}
IODeviceIStreambuf::IODeviceIStreambuf(QIODevice* dev) : device(dev)
{
setg (buffer+pbSize, // beginning of putback area
buffer+pbSize, // read position
@@ -441,7 +440,7 @@ using std::memcpy;
* - use number of characters read
* - but at most size of putback area
*/
int numPutback;
int numPutback{};
numPutback = gptr() - eback();
if (numPutback > pbSize) {
numPutback = pbSize;
@@ -454,7 +453,7 @@ using std::memcpy;
numPutback);
// read at most bufSize new characters
int num;
int num{};
num = device->read(buffer+pbSize, bufSize);
if (num <= 0) {
// ERROR or EOF
@@ -488,7 +487,7 @@ IODeviceIStreambuf::seekoff(std::streambuf::off_type off,
endpos = device->size();
break;
default:
return pos_type(off_type(-1));
return {off_type(-1)};
}
if (endpos != curpos) {
@@ -514,7 +513,6 @@ IODeviceIStreambuf::seekpos(std::streambuf::pos_type pos,
// http://www.icce.rug.nl/documents/cplusplus/cplusplus24.html
PyStreambuf::PyStreambuf(PyObject* o, std::size_t buf_size, std::size_t put_back)
: inp(o)
, type(Unknown)
, put_back(std::max(put_back, std::size_t(1)))
, buffer(std::max(buf_size, put_back) + put_back)
{
@@ -529,7 +527,7 @@ PyStreambuf::PyStreambuf(PyObject* o, std::size_t buf_size, std::size_t put_back
PyStreambuf::~PyStreambuf()
{
sync();
PyStreambuf::sync();
Py_DECREF(inp);
}
@@ -547,7 +545,7 @@ PyStreambuf::int_type PyStreambuf::underflow()
start += put_back;
}
std::size_t n;
std::size_t n{};
Py::Tuple arg(1);
long len = static_cast<long>(buffer.size() - (start - base));
arg.setItem(0, Py::Long(len));
@@ -731,7 +729,7 @@ Streambuf::Streambuf(const std::string& data)
{
_beg = data.begin();
_end = data.end();
_cur = _beg;
_cur = _beg; //NOLINT
}
Streambuf::~Streambuf() = default;

View File

@@ -49,14 +49,19 @@ public:
ByteOrder byteOrder() const;
void setByteOrder(ByteOrder);
virtual ~Stream();
protected:
Stream();
Stream(const Stream&) = default;
Stream(Stream&&) = default;
Stream& operator=(const Stream&) = default;
virtual ~Stream();
Stream& operator=(Stream&&) = default;
bool _swap;
bool isSwapped() const { return _swap; };
private:
bool _swap{false};
};
/**
@@ -82,7 +87,9 @@ public:
OutputStream& operator << (double d);
OutputStream (const OutputStream&) = delete;
OutputStream (OutputStream&&) = delete;
void operator = (const OutputStream&) = delete;
void operator = (OutputStream&&) = delete;
private:
std::ostream& _out;
@@ -117,7 +124,9 @@ public:
}
InputStream (const InputStream&) = delete;
InputStream (InputStream&&) = delete;
void operator = (const InputStream&) = delete;
void operator = (InputStream&&) = delete;
private:
std::istream& _in;
@@ -149,7 +158,9 @@ protected:
public:
ByteArrayOStreambuf(const ByteArrayOStreambuf&) = delete;
ByteArrayOStreambuf(ByteArrayOStreambuf&&) = delete;
ByteArrayOStreambuf& operator=(const ByteArrayOStreambuf&) = delete;
ByteArrayOStreambuf& operator=(ByteArrayOStreambuf&&) = delete;
private:
QBuffer* _buffer;
@@ -180,7 +191,9 @@ protected:
std::ios::in | std::ios::out) override;
public:
ByteArrayIStreambuf(const ByteArrayIStreambuf&) = delete;
ByteArrayIStreambuf(ByteArrayIStreambuf&&) = delete;
ByteArrayIStreambuf& operator=(const ByteArrayIStreambuf&) = delete;
ByteArrayIStreambuf& operator=(ByteArrayIStreambuf&&) = delete;
private:
const QByteArray& _buffer;
@@ -210,9 +223,11 @@ protected:
std::ios::in | std::ios::out) override;
public:
IODeviceOStreambuf(const IODeviceOStreambuf&) = delete;
IODeviceOStreambuf(IODeviceOStreambuf&&) = delete;
IODeviceOStreambuf& operator=(const IODeviceOStreambuf&) = delete;
IODeviceOStreambuf& operator=(IODeviceOStreambuf&&) = delete;
protected:
private:
QIODevice* device;
};
@@ -238,9 +253,11 @@ protected:
std::ios::in | std::ios::out) override;
public:
IODeviceIStreambuf(const IODeviceIStreambuf&) = delete;
IODeviceIStreambuf(IODeviceIStreambuf&&) = delete;
IODeviceIStreambuf& operator=(const IODeviceIStreambuf&) = delete;
IODeviceIStreambuf& operator=(IODeviceIStreambuf&&) = delete;
protected:
private:
QIODevice* device;
/* data buffer:
* - at most, pbSize characters in putback area plus
@@ -248,7 +265,7 @@ protected:
*/
static const int pbSize = 4; // size of putback area
static const int bufSize = 1024; // size of the data buffer
char buffer[bufSize+pbSize]; // data buffer
char buffer[bufSize+pbSize]{}; // data buffer
};
class BaseExport PyStreambuf : public std::streambuf
@@ -286,11 +303,13 @@ private:
public:
PyStreambuf(const PyStreambuf&) = delete;
PyStreambuf(PyStreambuf&&) = delete;
PyStreambuf& operator=(const PyStreambuf&) = delete;
PyStreambuf& operator=(PyStreambuf&&) = delete;
private:
PyObject* inp;
Type type;
Type type{Unknown};
const std::size_t put_back;
std::vector<char> buffer;
};
@@ -316,7 +335,9 @@ protected:
public:
Streambuf(const Streambuf&) = delete;
Streambuf(Streambuf&&) = delete;
Streambuf& operator=(const Streambuf&) = delete;
Streambuf& operator=(Streambuf&&) = delete;
private:
std::string::const_iterator _beg;
@@ -338,6 +359,8 @@ class ofstream : public std::ofstream
{
public:
ofstream() = default;
ofstream(const ofstream&) = delete;
ofstream(ofstream&&) = delete;
ofstream(const FileInfo& fi, ios_base::openmode mode =
std::ios::out | std::ios::trunc)
#ifdef _MSC_VER
@@ -354,6 +377,9 @@ public:
std::ofstream::open(fi.filePath().c_str(), mode);
#endif
}
ofstream& operator = (const ofstream&) = delete;
ofstream& operator = (ofstream&&) = delete;
};
/**
@@ -366,6 +392,8 @@ class ifstream : public std::ifstream
{
public:
ifstream() = default;
ifstream(const ifstream&) = delete;
ifstream(ifstream&&) = delete;
ifstream(const FileInfo& fi, ios_base::openmode mode =
std::ios::in)
#ifdef _MSC_VER
@@ -382,6 +410,9 @@ public:
std::ifstream::open(fi.filePath().c_str(), mode);
#endif
}
ifstream& operator = (const ifstream&) = delete;
ifstream& operator = (ifstream&&) = delete;
};
} // namespace Base

View File

@@ -26,10 +26,7 @@
using namespace Base;
ViewProjMethod::ViewProjMethod()
: hasTransform(false)
{
}
ViewProjMethod::ViewProjMethod() = default;
bool ViewProjMethod::isValid() const
{

View File

@@ -65,7 +65,7 @@ protected:
void transformInput(const Base::Vector3d&, Base::Vector3d&) const;
private:
bool hasTransform;
bool hasTransform{false};
Base::Matrix4D transform;
};

View File

@@ -77,10 +77,6 @@ struct cdata_filter {
// ---------------------------------------------------------------------------
Writer::Writer()
: indent(0)
, indBuf{}
, forceXML(false)
, fileVersion(1)
{
indBuf[0] = '\0';
}

View File

@@ -24,7 +24,6 @@
#define BASE_WRITER_H
#include <memory>
#include <set>
#include <string>
#include <sstream>
@@ -150,11 +149,11 @@ protected:
std::vector<std::string> Errors;
std::set<std::string> Modes;
short indent;
char indBuf[1024];
short indent{0};
char indBuf[1024]{};
bool forceXML;
int fileVersion;
bool forceXML{false};
int fileVersion{1};
public:
Writer(const Writer&) = delete;