From 9ce04cd7d65391b9f022b90cae776939d4d6ca1e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 20 Feb 2014 22:54:11 +0000 Subject: [PATCH] code cleaning --- latan/CompiledFunction.cpp | 6 +----- latan/CompiledFunction.hpp | 2 +- latan/Dataset.hpp | 9 ++------- latan/Exceptions.cpp | 8 ++------ latan/Exceptions.hpp | 5 +---- latan/Function.cpp | 10 +++------- latan/Function.hpp | 10 ++++++---- latan/Global.cpp | 8 +++++--- latan/Global.hpp | 1 + latan/Io.hpp | 2 +- latan/IoObject.hpp | 4 +++- latan/Mat.hpp | 2 ++ latan/Math.cpp | 2 +- latan/MathInterpreter.cpp | 4 ---- latan/MathInterpreter.hpp | 2 +- latan/ParserState.hpp | 6 +----- latan/Plot.cpp | 5 ----- latan/Plot.hpp | 5 +++-- latan/RandGen.cpp | 10 ++-------- latan/RandGen.hpp | 5 +++-- latan/Sample.cpp | 4 ---- latan/Sample.hpp | 12 ++---------- latan/StatArray.hpp | 7 +------ 23 files changed, 42 insertions(+), 87 deletions(-) diff --git a/latan/CompiledFunction.cpp b/latan/CompiledFunction.cpp index 3e4d2ab..72c635c 100644 --- a/latan/CompiledFunction.cpp +++ b/latan/CompiledFunction.cpp @@ -27,7 +27,7 @@ using namespace Latan; /****************************************************************************** * Compiled double function implementation * ******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// +// constructors //////////////////////////////////////////////////////////////// CompiledDoubleFunction::CompiledDoubleFunction(const unsigned nArg) : DoubleFunction(nArg) {} @@ -39,10 +39,6 @@ CompiledDoubleFunction::CompiledDoubleFunction(const unsigned nArg, setCode(code); } -// destructor ////////////////////////////////////////////////////////////////// -CompiledDoubleFunction::~CompiledDoubleFunction(void) -{} - // access ////////////////////////////////////////////////////////////////////// void CompiledDoubleFunction::setCode(const string &code) { diff --git a/latan/CompiledFunction.hpp b/latan/CompiledFunction.hpp index e0f7d35..afb8f6e 100644 --- a/latan/CompiledFunction.hpp +++ b/latan/CompiledFunction.hpp @@ -41,7 +41,7 @@ public: explicit CompiledDoubleFunction(const unsigned nArg, const std::string &code); // destructor - virtual ~CompiledDoubleFunction(void); + virtual ~CompiledDoubleFunction(void) = default; // access void setCode(const std::string &code); // function call diff --git a/latan/Dataset.hpp b/latan/Dataset.hpp index 6aabe32..fd3844f 100644 --- a/latan/Dataset.hpp +++ b/latan/Dataset.hpp @@ -38,12 +38,12 @@ class Dataset: public StatArray private: typedef StatArray Base; public: - // constructor + // constructors using Base::Base; Dataset(void); Dataset(const std::string &listFileName, const std::string &dataName); // destructor - virtual ~Dataset(void); + virtual ~Dataset(void) = default; // IO void load(const std::string &listFileName, const std::string &dataName); // resampling @@ -70,11 +70,6 @@ Dataset::Dataset(const std::string &listFileName, load(listFileName, dataName); } -// destructor ////////////////////////////////////////////////////////////////// -template -Dataset::~Dataset(void) -{} - // IO ////////////////////////////////////////////////////////////////////////// template void Dataset::load(const std::string &listFileName, diff --git a/latan/Exceptions.cpp b/latan/Exceptions.cpp index b5d83d8..b4b9632 100644 --- a/latan/Exceptions.cpp +++ b/latan/Exceptions.cpp @@ -33,18 +33,14 @@ using namespace std; using namespace Latan; using namespace Exceptions; -// prefix for messages -const string Latan::Exceptions::prefix = "[" + strFrom(PACKAGE_NAME) + " v" - + strFrom(PACKAGE_VERSION) + "] "; - // logic errors -CONST_EXC(Logic, logic_error(prefix + msg + ERR_SUFF)) +CONST_EXC(Logic, logic_error(Env::msgPrefix + msg + ERR_SUFF)) CONST_EXC(Definition, Logic("definition error: " + msg, loc)) CONST_EXC(Implementation, Logic("implementation error: " + msg, loc)) CONST_EXC(Range, Logic("range error: " + msg, loc)) CONST_EXC(Size, Logic("size error: " + msg, loc)) // runtime errors -CONST_EXC(Runtime, runtime_error(prefix + msg + ERR_SUFF)) +CONST_EXC(Runtime, runtime_error(Env::msgPrefix + msg + ERR_SUFF)) CONST_EXC(Compilation, Runtime("compilation error: " + msg, loc)) CONST_EXC(Io, Runtime("IO error: " + msg, loc)) CONST_EXC(Parsing, Runtime(msg, loc)) diff --git a/latan/Exceptions.hpp b/latan/Exceptions.hpp index b9dd4ca..a257c46 100644 --- a/latan/Exceptions.hpp +++ b/latan/Exceptions.hpp @@ -29,7 +29,7 @@ + strFrom(__LINE__) #define LATAN_ERROR(exc,msg) throw(Exceptions::exc(msg, SRC_LOC)) #define LATAN_WARNING(msg) \ -std::cerr << Latan::Exceptions::prefix << "warning: " << msg\ +std::cerr << Env::msgPrefix << "warning: " << msg\ << " (" << SRC_LOC << ")" << std::endl #define DECL_EXC(name, base) \ @@ -43,9 +43,6 @@ BEGIN_NAMESPACE namespace Exceptions { - // prefix for messages - extern const std::string prefix; - // logic errors DECL_EXC(Logic, std::logic_error); DECL_EXC(Definition, Logic); diff --git a/latan/Function.cpp b/latan/Function.cpp index 099c661..4b701e5 100644 --- a/latan/Function.cpp +++ b/latan/Function.cpp @@ -44,14 +44,11 @@ using namespace Latan; /****************************************************************************** * Function implementation * ******************************************************************************/ -// constructor/destructor ////////////////////////////////////////////////////// +// constructor ///////////////////////////////////////////////////////////////// Function::Function(const unsigned nArg) : nArg_(nArg) {} -Function::~Function(void) -{} - // access ////////////////////////////////////////////////////////////////////// unsigned int Function::getNArg(void) const { @@ -61,15 +58,14 @@ unsigned int Function::getNArg(void) const /****************************************************************************** * DoubleFunction implementation * ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// DoubleFunction::DoubleFunction(const unsigned nArg, vecFunc f) : Function(nArg) , buffer_(new vector(nArg)) , f_(f) {} -DoubleFunction::~DoubleFunction(void) -{} - +// function call /////////////////////////////////////////////////////////////// double DoubleFunction::evaluate(const std::vector &arg) const { return f_(arg); diff --git a/latan/Function.hpp b/latan/Function.hpp index 1b51280..5d07449 100644 --- a/latan/Function.hpp +++ b/latan/Function.hpp @@ -35,9 +35,10 @@ BEGIN_NAMESPACE class Function { public: - // constructor/destructor + // constructor explicit Function(const unsigned nArg); - virtual ~Function(void); + // destructor + virtual ~Function(void) = default; // access unsigned int getNArg(void) const; private: @@ -52,9 +53,10 @@ class DoubleFunction: public Function private: typedef std::function &)> vecFunc; public: - // constructor/destructor + // constructor explicit DoubleFunction(const unsigned nArg, vecFunc f = nullptr); - virtual ~DoubleFunction(void); + // destructor + virtual ~DoubleFunction(void) = default; // function call virtual double evaluate(const std::vector &arg) const; double operator()(std::stack &arg) const; diff --git a/latan/Global.cpp b/latan/Global.cpp index 61475df..380ed74 100644 --- a/latan/Global.cpp +++ b/latan/Global.cpp @@ -23,6 +23,8 @@ using namespace std; using namespace Latan; -const string Env::fullName = PACKAGE_STRING; -const string Env::name = PACKAGE_NAME; -const string Env::version = PACKAGE_VERSION; +const string Env::fullName = PACKAGE_STRING; +const string Env::name = PACKAGE_NAME; +const string Env::version = PACKAGE_VERSION; +const string Env::msgPrefix = "[" + strFrom(PACKAGE_NAME) + " v" + + strFrom(PACKAGE_VERSION) + "] "; \ No newline at end of file diff --git a/latan/Global.hpp b/latan/Global.hpp index accd4f2..c7cab64 100644 --- a/latan/Global.hpp +++ b/latan/Global.hpp @@ -59,6 +59,7 @@ namespace Env extern const std::string fullName; extern const std::string name; extern const std::string version; + extern const std::string msgPrefix; } // pointer type test diff --git a/latan/Io.hpp b/latan/Io.hpp index 5ffd986..06742bf 100644 --- a/latan/Io.hpp +++ b/latan/Io.hpp @@ -36,7 +36,7 @@ BEGIN_NAMESPACE /****************************************************************************** - * Generic datafile class * + * Abstract datafile class * ******************************************************************************/ typedef std::unordered_map> IoDataTable; diff --git a/latan/IoObject.hpp b/latan/IoObject.hpp index 55481a2..d376fa0 100644 --- a/latan/IoObject.hpp +++ b/latan/IoObject.hpp @@ -36,7 +36,9 @@ public: rgState = 3 }; public: - virtual ~IoObject(void) {}; + // destructor + virtual ~IoObject(void) = default; + // access virtual IoType getType(void) const = 0; }; diff --git a/latan/Mat.hpp b/latan/Mat.hpp index 329f76a..93fca98 100644 --- a/latan/Mat.hpp +++ b/latan/Mat.hpp @@ -37,6 +37,8 @@ public: DMat(void); DMat(const unsigned int nRow, const unsigned int nCol); EIGEN_EXPR_CTOR(DMat, DMat, Base, MatrixBase) + // destructor + virtual ~DMat(void) = default; // IO virtual IoType getType(void) const; }; diff --git a/latan/Math.cpp b/latan/Math.cpp index 2d499db..05e0831 100644 --- a/latan/Math.cpp +++ b/latan/Math.cpp @@ -37,7 +37,7 @@ DoubleFunction STDMATH_NAMESPACE::name(1, &name##VecFunc); #define DEF_STD_FUNC_2ARG(name) \ static double name##VecFunc(const vector &arg)\ {\ -return (name)(arg[0], arg[1]);\ + return (name)(arg[0], arg[1]);\ }\ DoubleFunction STDMATH_NAMESPACE::name(2, &name##VecFunc); diff --git a/latan/MathInterpreter.cpp b/latan/MathInterpreter.cpp index 0fbc892..7c3e8e5 100644 --- a/latan/MathInterpreter.cpp +++ b/latan/MathInterpreter.cpp @@ -400,10 +400,6 @@ MathInterpreter::MathInterpreter(const std::string &code) setCode(code); } -// destructor ////////////////////////////////////////////////////////////////// -MathInterpreter::~MathInterpreter(void) -{} - // access ////////////////////////////////////////////////////////////////////// const Instruction * MathInterpreter::operator[](const unsigned int i) const { diff --git a/latan/MathInterpreter.hpp b/latan/MathInterpreter.hpp index b890fc5..493bfb0 100644 --- a/latan/MathInterpreter.hpp +++ b/latan/MathInterpreter.hpp @@ -239,7 +239,7 @@ public: MathInterpreter(void); MathInterpreter(const std::string &code); // destructor - ~MathInterpreter(void); + ~MathInterpreter(void) = default; // access const Instruction * operator[](const unsigned int i) const; const ExprNode * getAST(void) const; diff --git a/latan/ParserState.hpp b/latan/ParserState.hpp index 6cf8875..771e691 100644 --- a/latan/ParserState.hpp +++ b/latan/ParserState.hpp @@ -34,7 +34,7 @@ public: explicit ParserState(std::istream *streamPt, std::string *namePt, DataObj *dataPt); // destructor - virtual ~ParserState(void); + virtual ~ParserState(void) = default; private: // scanner allocation/deallocation virtual void initScanner(void) = 0; @@ -56,10 +56,6 @@ ParserState::ParserState(std::istream *streamPt, std::string *namePt, , streamName(namePt) {} -template -ParserState::~ParserState(void) -{} - END_NAMESPACE #endif // Latan_ParserState_hpp_ diff --git a/latan/Plot.cpp b/latan/Plot.cpp index a436c72..c25087b 100644 --- a/latan/Plot.cpp +++ b/latan/Plot.cpp @@ -36,17 +36,12 @@ PlotCommand::PlotCommand(const string &command) : command_(command) {} -// destructor ////////////////////////////////////////////////////////////////// -PlotCommand::~PlotCommand(void) -{} - // access ////////////////////////////////////////////////////////////////////// const std::string & PlotCommand::getCommand(void) const { return command_; } - /****************************************************************************** * Plot implementation * ******************************************************************************/ diff --git a/latan/Plot.hpp b/latan/Plot.hpp index 4cf84af..c8023fa 100644 --- a/latan/Plot.hpp +++ b/latan/Plot.hpp @@ -42,10 +42,11 @@ BEGIN_NAMESPACE class PlotCommand { public: - // constructors/destructor + // constructors PlotCommand(void); PlotCommand(const std::string &command); - virtual ~PlotCommand(void); + // destructor + virtual ~PlotCommand(void) = default; // access virtual const std::string & getCommand(void) const; protected: diff --git a/latan/RandGen.cpp b/latan/RandGen.cpp index 61edaf4..5ba31a7 100644 --- a/latan/RandGen.cpp +++ b/latan/RandGen.cpp @@ -30,13 +30,11 @@ using namespace Latan; /****************************************************************************** * RandGen implementation * ******************************************************************************/ -// State implentation ////////////////////////////////////////////////////////// +// State constructor /////////////////////////////////////////////////////////// RandGen::State::State(void) {} -RandGen::State::~State(void) -{} - +// State IO type /////////////////////////////////////////////////////////////// IoObject::IoType RandGen::State::getType(void) const { return IoType::rgState; @@ -647,10 +645,6 @@ RandGen::RandGen(const State &state) setState(state); } -// destructor ////////////////////////////////////////////////////////////////// -RandGen::~RandGen(void) -{} - // state management //////////////////////////////////////////////////////////// RandGen::State RandGen::getState(void) const { diff --git a/latan/RandGen.hpp b/latan/RandGen.hpp index 162cc45..84cef25 100644 --- a/latan/RandGen.hpp +++ b/latan/RandGen.hpp @@ -42,7 +42,7 @@ public: // constructor State(void); // destructor - ~State(void); + virtual ~State(void) = default; // IO type IoType getType(void) const; }; @@ -61,6 +61,7 @@ private: } rlxd_dble_vec_t __attribute__ ((aligned (16))); public: RanLxd(void); + ~RanLxd(void) = default; void ranlxd(double r[],int n); void rlxd_init(int level,int seed); int rlxd_size(void) const; @@ -86,7 +87,7 @@ public: RandGen(const int seed); RandGen(const State &state); // destructor - virtual ~RandGen(void); + virtual ~RandGen(void) = default; // state management State getState(void) const; void setState(const State &state); diff --git a/latan/Sample.cpp b/latan/Sample.cpp index 58ac376..e691987 100644 --- a/latan/Sample.cpp +++ b/latan/Sample.cpp @@ -38,10 +38,6 @@ DMatSample::DMatSample(const unsigned int nSample, const unsigned int nRow, resizeMat(nRow, nCol); } -// destructor ////////////////////////////////////////////////////////////////// -DMatSample::~DMatSample(void) -{} - // resize all matrices ///////////////////////////////////////////////////////// void DMatSample::resizeMat(const unsigned int nRow, const unsigned int nCol) { diff --git a/latan/Sample.hpp b/latan/Sample.hpp index fc7a0ce..cdec6c7 100644 --- a/latan/Sample.hpp +++ b/latan/Sample.hpp @@ -43,7 +43,7 @@ public: // constructors using Base::Base; // destructor - virtual ~Sample(void); + virtual ~Sample(void) = default; }; /****************************************************************************** @@ -58,21 +58,13 @@ public: const unsigned int nCol); using Sample::Sample; // destructor - virtual ~DMatSample(void); + virtual ~DMatSample(void) = default; // resize all matrices void resizeMat(const unsigned int nRow, const unsigned int nCol); // IO type virtual IoType getType(void) const; }; -/****************************************************************************** - * Sample class template implementation * - ******************************************************************************/ -// destructor ////////////////////////////////////////////////////////////////// -template -Sample::~Sample(void) -{} - END_NAMESPACE #endif // Latan_Sample_hpp_ diff --git a/latan/StatArray.hpp b/latan/StatArray.hpp index 985e48e..25ac17e 100644 --- a/latan/StatArray.hpp +++ b/latan/StatArray.hpp @@ -41,7 +41,7 @@ public: EIGEN_EXPR_CTOR(StatArray, unique_arg(StatArray), Base, ArrayBase) // destructor - virtual ~StatArray(void); + virtual ~StatArray(void) = default; // access unsigned int size(void) const; // operators @@ -80,11 +80,6 @@ StatArray::StatArray(const unsigned int size) : Base(static_cast(size + offset)) {} -// destructor ////////////////////////////////////////////////////////////////// -template -StatArray::~StatArray(void) -{} - // access ////////////////////////////////////////////////////////////////////// template unsigned int StatArray::size(void) const