Skip to content

Commit

Permalink
Base: modernize C++11
Browse files Browse the repository at this point in the history
* remove redundant void-arg
* use nullptr
* replace deprecated headers
  • Loading branch information
wwmayer committed Jan 25, 2022
1 parent 7330799 commit 4d87039
Show file tree
Hide file tree
Showing 72 changed files with 628 additions and 633 deletions.
6 changes: 3 additions & 3 deletions src/Base/Axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class BaseExport Axis
{
public:
/// default constructor
Axis(void);
Axis();
Axis(const Axis&);
Axis(const Vector3d& Orig, const Vector3d& Dir);
/// Destruction
~Axis () {}

const Vector3d& getBase(void) const {return _base;}
const Vector3d& getDirection(void) const {return _dir;}
const Vector3d& getBase() const {return _base;}
const Vector3d& getDirection() const {return _dir;}
void setBase(const Vector3d& Orig) {_base=Orig;}
void setDirection(const Vector3d& Dir) {_dir=Dir;}

Expand Down
16 changes: 8 additions & 8 deletions src/Base/AxisPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
using namespace Base;

// returns a string which represents the object e.g. when printed in python
std::string AxisPy::representation(void) const
std::string AxisPy::representation() const
{
AxisPy::PointerType ptr = reinterpret_cast<AxisPy::PointerType>(_pcTwinPointer);
std::stringstream str;
Expand Down Expand Up @@ -86,7 +86,7 @@ PyObject* AxisPy::move(PyObject * args)
{
PyObject *vec;
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &vec))
return NULL;
return nullptr;
getAxisPtr()->move(static_cast<VectorPy*>(vec)->value());
Py_Return;
}
Expand All @@ -95,27 +95,27 @@ PyObject* AxisPy::multiply(PyObject * args)
{
PyObject *plm;
if (!PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm))
return NULL;
return nullptr;
Axis mult = (*getAxisPtr()) * (*static_cast<PlacementPy*>(plm)->getPlacementPtr());
return new AxisPy(new Axis(mult));
}

PyObject* AxisPy::copy(PyObject * args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
return nullptr;
return new AxisPy(new Axis(*getAxisPtr()));
}

PyObject* AxisPy::reversed(PyObject * args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
return nullptr;
Base::Axis a = getAxisPtr()->reversed();
return new AxisPy(new Axis(a));
}

Py::Object AxisPy::getBase(void) const
Py::Object AxisPy::getBase() const
{
return Py::Vector(getAxisPtr()->getBase());
}
Expand All @@ -125,7 +125,7 @@ void AxisPy::setBase(Py::Object arg)
getAxisPtr()->setBase(Py::Vector(arg).toVector());
}

Py::Object AxisPy::getDirection(void) const
Py::Object AxisPy::getDirection() const
{
return Py::Vector(getAxisPtr()->getDirection());
}
Expand All @@ -137,7 +137,7 @@ void AxisPy::setDirection(Py::Object arg)

PyObject *AxisPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
return nullptr;
}

int AxisPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
Expand Down
11 changes: 7 additions & 4 deletions src/Base/Base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
#ifndef BASE_BASE64_H
#define BASE_BASE64_H
#ifndef BASE_BASE64_H
#define BASE_BASE64_H

#include <FCGlobal.h>
#include <string>

namespace Base
{

namespace Base
{

std::string BaseExport base64_encode(unsigned char const* , unsigned int len);
std::string BaseExport base64_decode(std::string const& s);
Expand Down
10 changes: 5 additions & 5 deletions src/Base/BaseClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <assert.h>
# include <cassert>
#endif

/// Here the FreeCAD includes sorted by Base,App,Gui......
Expand Down Expand Up @@ -60,7 +60,7 @@ BaseClass::~BaseClass()
//**************************************************************************
// separator for other implementation aspects

void BaseClass::init(void)
void BaseClass::init()
{
assert(BaseClass::classTypeId == Type::badType() && "don't init() twice!");
/* Make sure superclass gets initialized before subclass. */
Expand All @@ -75,12 +75,12 @@ void BaseClass::init(void)
BaseClass::create);
}

Type BaseClass::getClassTypeId(void)
Type BaseClass::getClassTypeId()
{
return BaseClass::classTypeId;
}

Type BaseClass::getTypeId(void) const
Type BaseClass::getTypeId() const
{
return BaseClass::classTypeId;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ void BaseClass::initSubclass(Base::Type &toInit,const char* ClassName, const cha
*
* The default implementation returns 'None'.
*/
PyObject *BaseClass::getPyObject(void)
PyObject *BaseClass::getPyObject()
{
assert(0);
Py_Return;
Expand Down
17 changes: 10 additions & 7 deletions src/Base/BaseClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void * _class_::create(void){\

/// define to implement a subclass of Base::BaseClass
#define TYPESYSTEM_SOURCE_TEMPLATE_P(_class_) \
template<> Base::Type _class_::classTypeId = Base::Type::badType(); \
template<> Base::Type _class_::getClassTypeId(void) { return _class_::classTypeId; } \
template<> Base::Type _class_::getTypeId(void) const { return _class_::classTypeId; } \
template<> void * _class_::create(void){\
Expand Down Expand Up @@ -104,16 +105,16 @@ namespace Base
class BaseExport BaseClass
{
public:
static Type getClassTypeId(void);
virtual Type getTypeId(void) const;
static Type getClassTypeId();
virtual Type getTypeId() const;
bool isDerivedFrom(const Type type) const {return getTypeId().isDerivedFrom(type);}

static void init(void);
static void init();

virtual PyObject *getPyObject(void);
virtual PyObject *getPyObject();
virtual void setPyObject(PyObject *);

static void *create(void){return nullptr;}
static void *create(){return nullptr;}
private:
static Type classTypeId;
protected:
Expand All @@ -122,6 +123,8 @@ class BaseExport BaseClass
public:
/// Construction
BaseClass();
BaseClass(const BaseClass&) = default;
BaseClass& operator=(const BaseClass&) = default;
/// Destruction
virtual ~BaseClass();

Expand All @@ -137,7 +140,7 @@ template<typename T> T * freecad_dynamic_cast(Base::BaseClass * t)
if (t && t->isDerivedFrom(T::getClassTypeId()))
return static_cast<T*>(t);
else
return 0;
return nullptr;
}

/**
Expand All @@ -150,7 +153,7 @@ template<typename T> const T * freecad_dynamic_cast(const Base::BaseClass * t)
if (t && t->isDerivedFrom(T::getClassTypeId()))
return static_cast<const T*>(t);
else
return 0;
return nullptr;
}


Expand Down
12 changes: 6 additions & 6 deletions src/Base/BaseClassPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
using namespace Base;

// returns a string which represent the object e.g. when printed in python
std::string BaseClassPy::representation(void) const
std::string BaseClassPy::representation() const
{
return std::string("<binding object>");
}
Expand All @@ -42,7 +42,7 @@ PyObject* BaseClassPy::isDerivedFrom(PyObject *args)
{
char *name;
if (!PyArg_ParseTuple(args, "s", &name)) // convert args: Python->C
return NULL; // NULL triggers exception
return nullptr; // NULL triggers exception

Base::Type type = Base::Type::fromName(name);
bool v = (type != Base::Type::badType() && getBaseClassPtr()->getTypeId().isDerivedFrom(type));
Expand All @@ -52,7 +52,7 @@ PyObject* BaseClassPy::isDerivedFrom(PyObject *args)
PyObject* BaseClassPy::getAllDerivedFrom(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception
return nullptr; // NULL triggers exception

std::vector<Base::Type> ary;
Base::Type::getAllDerivedFrom(getBaseClassPtr()->getTypeId(), ary);
Expand All @@ -62,12 +62,12 @@ PyObject* BaseClassPy::getAllDerivedFrom(PyObject *args)
return Py::new_reference_to(res);
}

Py::String BaseClassPy::getTypeId(void) const
Py::String BaseClassPy::getTypeId() const
{
return Py::String(std::string(getBaseClassPtr()->getTypeId().getName()));
}

Py::String BaseClassPy::getModule(void) const
Py::String BaseClassPy::getModule() const
{
std::string module(getBaseClassPtr()->getTypeId().getName());
std::string::size_type pos = module.find_first_of("::");
Expand All @@ -82,7 +82,7 @@ Py::String BaseClassPy::getModule(void) const

PyObject *BaseClassPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
return nullptr;
}

int BaseClassPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
Expand Down
28 changes: 14 additions & 14 deletions src/Base/BoundBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class BoundBox3
*/
inline bool IsInBox (const BoundBox2d &rcbb) const;
/** Checks whether the bounding box is valid. */
bool IsValid (void) const;
bool IsValid () const;
//@}

enum OCTANT {OCT_LDB = 0, OCT_RDB, OCT_LUB, OCT_RUB,
Expand Down Expand Up @@ -173,24 +173,24 @@ class BoundBox3
BoundBox3<_Precision> Transformed(const Matrix4D& mat) const;

/** Returns the center.of the box. */
inline Vector3<_Precision> GetCenter (void) const;
inline Vector3<_Precision> GetCenter () const;
/** Compute the diagonal length of this bounding box.
* @note It's up to the client programmer to make sure that this bounding box is valid.
*/
inline _Precision CalcDiagonalLength (void) const;
void SetVoid (void);
inline _Precision CalcDiagonalLength () const;
void SetVoid ();

/** Enlarges the box with factor \a fLen. */
inline void Enlarge (_Precision fLen);
/** Shrinks the box with factor \a fLen. */
inline void Shrink (_Precision fLen);

/** Calculates expansion in x-direction. */
inline _Precision LengthX (void) const;
inline _Precision LengthX () const;
/** Calculates expansion in y-direction. */
inline _Precision LengthY (void) const;
inline _Precision LengthY () const;
/** Calculates expansion in z-direction. */
inline _Precision LengthZ (void) const;
inline _Precision LengthZ () const;
/** Moves in x-direction. */
inline void MoveX (_Precision f);
/** Moves in y-direction. */
Expand Down Expand Up @@ -400,7 +400,7 @@ inline bool BoundBox3<_Precision>::IsInBox (const BoundBox2d &rcBB) const
}

template <class _Precision>
inline bool BoundBox3<_Precision>::IsValid (void) const
inline bool BoundBox3<_Precision>::IsValid () const
{
return ((MinX <= MaxX) && (MinY <= MaxY) && (MinZ <= MaxZ));
}
Expand Down Expand Up @@ -894,23 +894,23 @@ inline BoundBox3<_Precision> BoundBox3<_Precision>::Transformed(const Matrix4D&
}

template <class _Precision>
inline Vector3<_Precision> BoundBox3<_Precision>::GetCenter (void) const
inline Vector3<_Precision> BoundBox3<_Precision>::GetCenter () const
{
return Vector3<_Precision>((MaxX + MinX) / 2,
(MaxY + MinY) / 2,
(MaxZ + MinZ) / 2);
}

template <class _Precision>
inline _Precision BoundBox3<_Precision>::CalcDiagonalLength (void) const
inline _Precision BoundBox3<_Precision>::CalcDiagonalLength () const
{
return static_cast<_Precision>(sqrt (((MaxX - MinX) * (MaxX - MinX)) +
((MaxY - MinY) * (MaxY - MinY)) +
((MaxZ - MinZ) * (MaxZ - MinZ))));
}

template <class _Precision>
inline void BoundBox3<_Precision>::SetVoid (void)
inline void BoundBox3<_Precision>::SetVoid ()
{
MinX = MinY = MinZ = std::numeric_limits<_Precision>::max();
MaxX = MaxY = MaxZ = -std::numeric_limits<_Precision>::max();
Expand All @@ -931,19 +931,19 @@ inline void BoundBox3<_Precision>::Shrink (_Precision fLen)
}

template <class _Precision>
inline _Precision BoundBox3<_Precision>::LengthX (void) const
inline _Precision BoundBox3<_Precision>::LengthX () const
{
return MaxX - MinX;
}

template <class _Precision>
inline _Precision BoundBox3<_Precision>::LengthY (void) const
inline _Precision BoundBox3<_Precision>::LengthY () const
{
return MaxY - MinY;
}

template <class _Precision>
inline _Precision BoundBox3<_Precision>::LengthZ (void) const
inline _Precision BoundBox3<_Precision>::LengthZ () const
{
return MaxZ - MinZ;
}
Expand Down

0 comments on commit 4d87039

Please sign in to comment.