From db7f669038883f2b2f8bb36b5f80089ef6e73b3d Mon Sep 17 00:00:00 2001 From: hama Date: Sat, 31 May 2014 01:36:51 +0200 Subject: [PATCH] dayly work --- .gitignore | 2 +- rplcore/rplconfig.cpp | 5 +- rplcore/rplcontainer.cpp | 4 +- rplcore/rplcore.hpp | 17 ++--- rplcore/rplexception.cpp | 8 +-- rplcore/rpltest.cpp | 19 ++++++ rplcore/rpltest.hpp | 1 + rplcore/testrplexample.cpp | 2 +- rplmath/rplenigma.cpp | 5 +- rplmath/rplmath.hpp | 5 +- rplmath/rplmatrix.cpp | 128 ++++++++++++++++++----------------- rplmath/rplmatrix.hpp | 70 ++++++++++--------- rplmath/rplmatrix_test.cpp | 12 ---- rplmodules.hpp | 26 +++++++ rplstatic/getsrc.pl | 29 ++++++++ rplstatic/rplstatic.pro | 40 ++++++++++- unittests/main.cpp | 21 ++++++ unittests/rplmatrix_test.cpp | 48 +++++++++++++ unittests/unittests.pro | 22 ++++++ 19 files changed, 330 insertions(+), 134 deletions(-) delete mode 100644 rplmath/rplmatrix_test.cpp create mode 100644 rplmodules.hpp create mode 100644 rplstatic/getsrc.pl create mode 100644 unittests/main.cpp create mode 100644 unittests/rplmatrix_test.cpp create mode 100644 unittests/unittests.pro diff --git a/.gitignore b/.gitignore index 0d5d10b..147a93c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *-conflict_* *~ - +*.pro.user diff --git a/rplcore/rplconfig.cpp b/rplcore/rplconfig.cpp index 536e417..44d2d75 100644 --- a/rplcore/rplconfig.cpp +++ b/rplcore/rplconfig.cpp @@ -5,7 +5,7 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#include "rplcore.hpp" +#include "rplcore/rplcore.hpp" /** @class RplConfig rplconfig.hpp "rplcore/rplconfig.hpp" * @@ -174,7 +174,8 @@ bool RplConfig::write(const char* file) { if(m_readOnly) m_logger->log(LOG_ERROR, LOC_WRITE_1, "cannot write: (readonly"); else { - m_logger->log(LOG_ERROR, LOC_WRITE_2, "not implemented: write()"); + m_logger->logv(LOG_ERROR, LOC_WRITE_2, "not implemented: write(%s)", + file); } return rc; } diff --git a/rplcore/rplcontainer.cpp b/rplcore/rplcontainer.cpp index 3137aae..4a292ef 100644 --- a/rplcore/rplcontainer.cpp +++ b/rplcore/rplcontainer.cpp @@ -61,6 +61,8 @@ RplContainer::RplContainer(size_t sizeHint) : m_ixItem(0), m_ixBag(0), m_readPosition(NULL) { + if (sizeHint > 0) + m_data.reserve(sizeHint); } /** @@ -401,7 +403,7 @@ QByteArray RplContainer::dump(const char* title, nextBag(); QByteArray item; int maxLength; - for(int ixItem; ixItem < m_typeList.length(); ixItem++) { + for(int ixItem = 0; ixItem < m_typeList.length(); ixItem++) { type_tag_t currentType = (type_tag_t) m_typeList.at(ixItem); switch(currentType) { case TAG_CHAR: diff --git a/rplcore/rplcore.hpp b/rplcore/rplcore.hpp index a71da62..3753903 100644 --- a/rplcore/rplcore.hpp +++ b/rplcore/rplcore.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -28,13 +29,13 @@ #include typedef unsigned char uint8_t; -#include "../rplmodules.hpp" -#include "rpllogger.hpp" -#include "rplexception.hpp" -#include "rplcontainer.hpp" -#include "rplstring.hpp" -#include "rplconfigurator.hpp" -#include "rplconfig.hpp" -#include "rplterminator.hpp" +#include "rplmodules.hpp" +#include "rplcore/rpllogger.hpp" +#include "rplcore/rplexception.hpp" +#include "rplcore/rplcontainer.hpp" +#include "rplcore/rplstring.hpp" +#include "rplcore/rplconfigurator.hpp" +#include "rplcore/rplconfig.hpp" +#include "rplcore/rplterminator.hpp" #endif // RPLCORE_HPP diff --git a/rplcore/rplexception.cpp b/rplcore/rplexception.cpp index db0d47e..358fb0b 100644 --- a/rplcore/rplexception.cpp +++ b/rplcore/rplexception.cpp @@ -59,7 +59,7 @@ RplException::RplException(RplLoggerLevel level, int location, m_message(message) { if(logger == NULL) logger = RplLogger::globalLogger(); - logger->log(LOG_ERROR, location, message); + logger->log(level, location, message); } /** @@ -78,7 +78,7 @@ RplException::RplException(RplLoggerLevel level, int location, m_message(message) { if(logger == NULL) logger = RplLogger::globalLogger(); - logger->log(LOG_ERROR, location, message); + logger->log(level, location, message); } /** @@ -107,7 +107,7 @@ RplException::RplException(RplLoggerLevel level, int location, m_message = buffer; if(logger == NULL) logger = RplLogger::globalLogger(); - logger->log(LOG_ERROR, location, buffer); + logger->log(level, location, buffer); } /** @@ -137,7 +137,7 @@ RplException::RplException(RplLoggerLevel level, int location, m_message = buffer; if(logger == NULL) logger = RplLogger::globalLogger(); - logger->log(LOG_ERROR, location, buffer); + logger->log(level, location, buffer); } diff --git a/rplcore/rpltest.cpp b/rplcore/rpltest.cpp index 1f538c9..cf74fc0 100644 --- a/rplcore/rpltest.cpp +++ b/rplcore/rpltest.cpp @@ -73,6 +73,25 @@ bool RplTest::assertEquals(int expected, int current, const char* file, return expected == current; } +/** + * Tests the equality of two values. + * + * Differences will be logged. + * + * @param expected the expected value + * @param current the current value + * @param file the file containing the test + * @param lineNo the line number containing the test + * @return true: equal + */ +bool RplTest::assertEquals(qreal expected, qreal current, const char* file, + int lineNo) { + if(expected != current) + error("%s-%d: error: %d != %d / %x != %x)", file, lineNo, expected, current, + (unsigned int) expected, (unsigned int) current); + return expected == current; +} + /** * @brief Tests the equality of two values. * diff --git a/rplcore/rpltest.hpp b/rplcore/rpltest.hpp index 4c15120..903f729 100644 --- a/rplcore/rpltest.hpp +++ b/rplcore/rpltest.hpp @@ -24,6 +24,7 @@ private: RplTest& operator =(const RplTest& source); public: bool assertEquals(int expected, int current, const char* file, int lineNo); + bool assertEquals(qreal expected, qreal current, const char* file, int lineNo); bool assertEquals(const char* expected, const char* current, const char* file, int lineNo); bool assertEquals(const QByteArray& expected, const QByteArray& current, diff --git a/rplcore/testrplexample.cpp b/rplcore/testrplexample.cpp index e0c35f4..695fbae 100644 --- a/rplcore/testrplexample.cpp +++ b/rplcore/testrplexample.cpp @@ -5,7 +5,7 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#include "project.hpp" +include "project.hpp" #include "rplcore/rpltest.hpp" // Code to test: diff --git a/rplmath/rplenigma.cpp b/rplmath/rplenigma.cpp index 1e565ab..34efc19 100644 --- a/rplmath/rplenigma.cpp +++ b/rplmath/rplenigma.cpp @@ -94,8 +94,9 @@ RplEnigma::~RplEnigma() { * otherwise: the certificate as byte array */ QByteArray RplEnigma::readCertificate(const char* filename) { - QByteArray rc; - + QByteArray rc = "not implemented: readCertificate(): "; + rc += filename; + assert(rc.isEmpty()); return rc; } diff --git a/rplmath/rplmath.hpp b/rplmath/rplmath.hpp index 8613802..81819e9 100644 --- a/rplmath/rplmath.hpp +++ b/rplmath/rplmath.hpp @@ -11,7 +11,8 @@ #ifndef RPLCORE_HPP #include "rplcore/rplcore.hpp" #endif -#include "rplrandom.hpp" -#include "rplenigma.hpp" +#include "rplmath/rplrandom.hpp" +#include "rplmath/rplenigma.hpp" +#include "rplmath/rplmatrix.hpp" #endif // RPLMATH_HPP diff --git a/rplmath/rplmatrix.cpp b/rplmath/rplmatrix.cpp index 548ceb5..4bea419 100644 --- a/rplmath/rplmatrix.cpp +++ b/rplmath/rplmatrix.cpp @@ -1,20 +1,18 @@ /* - * Matrix.cpp + * RplMatrix.cpp * * Created on: 29.05.2014 * Author: hm */ -#include "matrixall.hpp" +#include "rplmath/rplmath.hpp" -namespace rpl { - -MatrixException::MatrixException(const Matrix& matrix, +RplMatrixException::RplMatrixException(int id, const RplMatrix& RplMatrix, const char* format, ...) : m_message() { - if (! matrix.getName().empty()) - m_message = matrix.getName() + ": "; + if (! RplMatrix.getName().empty()) + m_message = RplMatrix.getName() + ": "; char buffer[16*1024]; va_list args; @@ -23,7 +21,7 @@ MatrixException::MatrixException(const Matrix& matrix, va_end(args); m_message += buffer; } -MatrixException::MatrixException(const char* format, ...) +RplMatrixException::RplMatrixException(const char* format, ...) { char buffer[16*1024]; @@ -37,7 +35,7 @@ MatrixException::MatrixException(const char* format, ...) /** * Constructor. */ -Matrix::Matrix(const char* name) : +RplMatrix::RplMatrix(const char* name) : m_rows(0), m_cols(0), m_values(NULL), @@ -51,7 +49,7 @@ Matrix::Matrix(const char* name) : * @param rows number of rows * @param cols number of columns */ -Matrix::Matrix(int rows, int cols, const char* name): +RplMatrix::RplMatrix(int rows, int cols, const char* name): m_rows(rows), m_cols(cols), m_values(new MatVal[rows*cols]), @@ -61,7 +59,7 @@ Matrix::Matrix(int rows, int cols, const char* name): /** * Destructor. */ -Matrix::~Matrix() { +RplMatrix::~RplMatrix() { delete m_values; m_values = NULL; } @@ -71,7 +69,7 @@ Matrix::~Matrix() { * * @param source source to copy */ -Matrix::Matrix(const Matrix& source) : +RplMatrix::RplMatrix(const RplMatrix& source) : m_rows(0), m_cols(), m_values(NULL), @@ -85,49 +83,49 @@ Matrix::Matrix(const Matrix& source) : * * @param rows the row number * @param cols the column number - * @trows MatrixException + * @trows RplMatrixException */ -void Matrix::checkDefinition(int rows, int cols) const +void RplMatrix::checkDefinition(int rows, int cols) const { if (rows < 0) - throw MatrixException(*this, "row number negative: %d", rows); + throw RplMatrixException(*this, "row number negative: %d", rows); if (cols < 0) - throw MatrixException(*this, "column number negative: %d", cols); + throw RplMatrixException(*this, "column number negative: %d", cols); if (double(rows) * cols > 1.0*1000*1000) - throw MatrixException(*this, "too many elements: %d*%d", rows, cols); + throw RplMatrixException(*this, "too many elements: %d*%d", rows, cols); } /** * Checks the validity of the indexes. * - * @param row the matrix row number: 0..N-1 - * @param col the matrix column number: 0..M-1 - * @throws MatrixException + * @param row the RplMatrix row number: 0..N-1 + * @param col the RplMatrix column number: 0..M-1 + * @throws RplMatrixException */ -void Matrix::check(int row, int col) const +void RplMatrix::check(int row, int col) const { if (row < 0 || row >= m_rows) - throw MatrixException(*this, "invalid row: %d not in [0,%d[", row, + throw RplMatrixException(*this, "invalid row: %d not in [0,%d[", row, m_rows); if (col < 0 || col >= m_cols) - throw MatrixException(*this, "invalid column: %d not in [0,%d[", col, + throw RplMatrixException(*this, "invalid column: %d not in [0,%d[", col, m_cols); } /** - * Checks whether a given matrix has the same dimensions. + * Checks whether a given Matrix has the same dimensions. * - * @param operand matrix to compare - * @throws MatrixException + * @param operand Matrix to compare + * @throws RplMatrixException */ -void Matrix::checkSameDimension(const Matrix& operand) const +void RplMatrix::checkSameDimension(const RplMatrix& operand) const { if (m_rows != operand.getRows()) - throw MatrixException(*this, - "Matrix %s has different row count: %d / %d", + throw RplMatrixException(*this, + "RplMatrix %s has different row count: %d / %d", operand.getName().c_str(), m_rows, operand.getRows()); if (m_cols != operand.getCols()) - throw MatrixException(*this, - "Matrix %s has different column count: %d / %d", + throw RplMatrixException(*this, + "RplMatrix %s has different column count: %d / %d", operand.getName().c_str(), m_cols, operand.getCols()); } @@ -136,18 +134,18 @@ void Matrix::checkSameDimension(const Matrix& operand) const * * @param source the source to copy */ -Matrix& Matrix::operator =(const Matrix& source) +RplMatrix& RplMatrix::operator =(const RplMatrix& source) { resize(source.m_rows, source.m_cols, source.m_values); return *this; } /** - * Adds a matrix to the instance. + * Adds a Matrix to the instance. * - * @param operand matrix to add + * @param operand Matrix to add * @return the instance itself */ -Matrix& Matrix::operator +=(const Matrix& operand) +RplMatrix& RplMatrix::operator +=(const RplMatrix& operand) { checkSameDimension(operand); for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ @@ -161,7 +159,7 @@ Matrix& Matrix::operator +=(const Matrix& operand) * @param operand matrix to subtract * @return the instance itself */ -Matrix& Matrix::operator -=(const Matrix& operand) +RplMatrix& RplMatrix::operator -=(const RplMatrix& operand) { checkSameDimension(operand); for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ @@ -172,12 +170,12 @@ Matrix& Matrix::operator -=(const Matrix& operand) /** * Builds the sum of the instance and a given matrix. * - * @param operand matrix to add - * @return a new matrix with the sum + * @param operand RplMatrix to add + * @return a new RplMatrix with the sum */ -Matrix Matrix::operator +(const Matrix& operand) +RplMatrix RplMatrix::operator +(const RplMatrix& operand) { - Matrix rc(*this); + RplMatrix rc(*this); rc += operand; return rc; } @@ -187,9 +185,9 @@ Matrix Matrix::operator +(const Matrix& operand) * @param operand matrix to subtract * @return a new matrix with the difference */ -Matrix Matrix::operator -(const Matrix& operand) +RplMatrix RplMatrix::operator -(const RplMatrix& operand) { - Matrix rc(*this); + RplMatrix rc(*this); rc -= operand; return rc; } @@ -199,7 +197,7 @@ Matrix Matrix::operator -(const Matrix& operand) * @param scalar scalar to add * @return the instance itself */ -Matrix& Matrix::operator +=(MatVal scalar) +RplMatrix& RplMatrix::operator +=(MatVal scalar) { for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ m_values[ix] += scalar; @@ -212,7 +210,7 @@ Matrix& Matrix::operator +=(MatVal scalar) * @param scalar scalar to add * @return the instance itself */ -Matrix& Matrix::operator -=(MatVal scalar) +RplMatrix& RplMatrix::operator -=(MatVal scalar) { for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ m_values[ix] -= scalar; @@ -225,9 +223,9 @@ Matrix& Matrix::operator -=(MatVal scalar) * @param scalar scalar to add * @return a new matrix with the sum */ -Matrix Matrix::operator +(MatVal scalar) +RplMatrix RplMatrix::operator +(MatVal scalar) { - Matrix rc(*this); + RplMatrix rc(*this); rc += scalar; return rc; } @@ -237,9 +235,9 @@ Matrix Matrix::operator +(MatVal scalar) * @param scalar scalar to subtract * @return a new matrix with the sum */ -Matrix Matrix::operator -(MatVal scalar) +RplMatrix RplMatrix::operator -(MatVal scalar) { - Matrix rc(*this); + RplMatrix rc(*this); rc -= scalar; return rc; } @@ -250,7 +248,7 @@ Matrix Matrix::operator -(MatVal scalar) * @return true: the matrices are equal
* false: otherwise */ -bool Matrix::operator ==(const Matrix& operand) const +bool RplMatrix::operator ==(const RplMatrix& operand) const { checkSameDimension(operand); bool rc = true; @@ -269,7 +267,7 @@ bool Matrix::operator ==(const Matrix& operand) const * @return true: all elements are equal to the scalar
* false: otherwise */ -bool Matrix::operator ==(MatVal scalar) const +bool RplMatrix::operator ==(MatVal scalar) const { bool rc = true; for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ @@ -283,7 +281,7 @@ bool Matrix::operator ==(MatVal scalar) const /** * Sets a new row-column pair. */ -Matrix& Matrix::resize(int rows, int cols, const MatVal values[], +RplMatrix& RplMatrix::resize(int rows, int cols, const MatVal values[], MatVal defaultValue) { checkDefinition(rows, cols); @@ -313,8 +311,12 @@ Matrix& Matrix::resize(int rows, int cols, const MatVal values[], * * @return a tuple with the minimum and the maximum */ -Tuple2 Matrix::minMax() const +Tuple2 RplMatrix::minMax() const { +#ifndef DBL_MAX +#define DBL_MAX std::numeric_limits::max() +#define DBL_MIN std::numeric_limits::min() +#endif Tuple2 rc(DBL_MAX, DBL_MIN); for (int ix = m_rows*m_cols - 1; ix >= 0; ix--){ @@ -332,9 +334,9 @@ Tuple2 Matrix::minMax() const * * @return the transposed matrix */ -Matrix Matrix::transpose() const +RplMatrix RplMatrix::transpose() const { - Matrix rc(m_cols, m_rows); + RplMatrix rc(m_cols, m_rows); for (int row = 0; row < m_rows; row++){ for (int col = 0; col < m_cols; col++){ @@ -343,7 +345,7 @@ Matrix Matrix::transpose() const } return rc; } -std::string Matrix::toString(const char* prefix, const char* format, +std::string RplMatrix::toString(const char* prefix, const char* format, const char* rowSeparator, const char* colSeparator) const { char buffer[128]; @@ -368,7 +370,7 @@ std::string Matrix::toString(const char* prefix, const char* format, rc += prefix; rc += "["; for (int row = 0; row < m_rows; row++){ - for (int col; col < m_cols; col++){ + for (int col = 0; col < m_cols; col++){ snprintf(buffer, sizeof buffer, format, m_values[m_cols*row + col]); rc += buffer; rc += colSeparator; @@ -569,11 +571,11 @@ static int countNumbers(char* line, char separator){ * Reads a file with the CSV (comma separated values) format * into the instance. */ -void Matrix::readFromCvs(const char* filename, int maxLineLength) +void RplMatrix::readFromCvs(const char* filename, int maxLineLength) { FILE* fp = fopen(filename, "r"); if (fp == NULL) - throw MatrixException(*this, "Cannot open %s (%d)", filename, errno); + throw RplMatrixException(*this, "Cannot open %s (%d)", filename, errno); char* buffer = new char[maxLineLength]; char* line; char separator = findSeparator(fp, buffer, maxLineLength); @@ -601,7 +603,7 @@ void Matrix::readFromCvs(const char* filename, int maxLineLength) skipNonNumbers(line, separator); int col = -1; int length; - char* ptr; + char* ptr = line; while( (length = lengthOfNumber(ptr)) > 0){ while(*ptr == ' ') ptr++; @@ -617,11 +619,11 @@ void Matrix::readFromCvs(const char* filename, int maxLineLength) fclose(fp); delete buffer; } -void readFromXml(const char* filename, const char* tagCol, +void RplMatrix::readFromXml(const char* filename, const char* tagCol, const char* tagRow, const char* tagTable, - int maxLineLength = 1024*1024) + int maxLineLength) { - + throw RplMatrixException(*this, "readFromXml not implementes: %s %s %s %s %d", + filename, tagCol, tagRow, tagTable, maxLineLength); } -} /* namespace rpl */ diff --git a/rplmath/rplmatrix.hpp b/rplmath/rplmatrix.hpp index 9bf89f8..a20aa21 100644 --- a/rplmath/rplmatrix.hpp +++ b/rplmath/rplmatrix.hpp @@ -1,26 +1,24 @@ /* - * Matrix.hpp + * RplMatrix.hpp * * Created on: 29.05.2014 * Author: hm */ -#ifndef MATRIX_HPP_ -#define MATRIX_HPP_ +#ifndef RplMatrix_HPP_ +#define RplMatrix_HPP_ -namespace rpl { - -class Matrix; +class RplMatrix; /** - * Implements a matrix specific exception. + * Implements a RplMatrix specific exception. */ -class MatrixException +class RplMatrixException { public: - MatrixException(const Matrix& matrix, const char* format, ...); - MatrixException(const char* format, ...); -private: + explicit RplMatrixException(int id, const char* format, ...); + explicit RplMatrixException(const RplMatrix& RplMatrix, const char* format, ...); +public: const std::string getMessage() const { return m_message; } private: @@ -28,9 +26,9 @@ private: }; /** - * The type of a matrix element. + * The type of a RplMatrix element. */ -typedef double MatVal; +typedef qreal MatVal; class Tuple2 { public: @@ -43,27 +41,27 @@ public: MatVal m_value2; }; /** - * Implements a matrix with 2 dimensions. + * Implements a RplMatrix with 2 dimensions. */ -class Matrix { +class RplMatrix { public: - Matrix(const char* name = NULL); - Matrix(int rows, int cols, const char* name = NULL); - virtual ~Matrix(); - Matrix(const Matrix& source); - Matrix& operator =(const Matrix& source); + RplMatrix(const char* name = NULL); + RplMatrix(int rows, int cols, const char* name = NULL); + virtual ~RplMatrix(); + RplMatrix(const RplMatrix& source); + RplMatrix& operator =(const RplMatrix& source); public: - Matrix& operator +=(const Matrix& operand); - Matrix& operator -=(const Matrix& operand); - Matrix operator +(const Matrix& operand); - Matrix operator -(const Matrix& operand); - Matrix& operator +=(MatVal scalar); - Matrix& operator -=(MatVal scalar); - Matrix operator +(MatVal scalar); - Matrix operator -(MatVal scalar); - bool operator ==(const Matrix& operand) const; + RplMatrix& operator +=(const RplMatrix& operand); + RplMatrix& operator -=(const RplMatrix& operand); + RplMatrix operator +(const RplMatrix& operand); + RplMatrix operator -(const RplMatrix& operand); + RplMatrix& operator +=(MatVal scalar); + RplMatrix& operator -=(MatVal scalar); + RplMatrix operator +(MatVal scalar); + RplMatrix operator -(MatVal scalar); + bool operator ==(const RplMatrix& operand) const; bool operator ==(MatVal scalar) const; - inline bool operator !=(const Matrix& operand) const + inline bool operator !=(const RplMatrix& operand) const { return ! (*this == operand); } inline bool operator !=(MatVal operand) { return ! (*this == operand); } @@ -72,7 +70,7 @@ public: { return m_name; } inline MatVal get(int row, int col) const { check(row, col); return m_values[row*m_cols + col]; } - inline Matrix& set(int row, int col, MatVal value) + inline RplMatrix& set(int row, int col, MatVal value) { check(row, col); m_values[row*m_cols + col] = value; return *this; } inline int getRows() const { return m_rows; } @@ -81,11 +79,11 @@ public: public: void checkDefinition(int rows, int cols) const; void check(int row, int col) const; - void checkSameDimension(const Matrix& operand) const; - Matrix& resize(int rows, int cols, const MatVal values[] = NULL, + void checkSameDimension(const RplMatrix& operand) const; + RplMatrix& resize(int rows, int cols, const MatVal values[] = NULL, MatVal defaultValue = 0.0); Tuple2 minMax() const; - Matrix transpose() const; + RplMatrix transpose() const; std::string toString(const char* prefix = NULL, const char* format = "%f", const char* rowSeparator = "\n", @@ -100,5 +98,5 @@ protected: MatVal* m_values; std::string m_name; }; -} // namespace rpl -#endif /* MATRIX_HPP_ */ + +#endif /* RplMatrix_HPP_ */ diff --git a/rplmath/rplmatrix_test.cpp b/rplmath/rplmatrix_test.cpp deleted file mode 100644 index dbc6c7d..0000000 --- a/rplmath/rplmatrix_test.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Matrix_test.cpp - * - * Created on: 29.05.2014 - * Author: hm - */ - -#include "stdinc.hpp" - -namespace rpl { - -} /* namespace rpl */ diff --git a/rplmodules.hpp b/rplmodules.hpp new file mode 100644 index 0000000..998e0c0 --- /dev/null +++ b/rplmodules.hpp @@ -0,0 +1,26 @@ +#ifndef RPLMODULES_HPP +#define RPLMODULES_HPP + +enum { + RPLMODULE_LOGGER = 1, + RPLMODULE_CONFIG, + RPLMODULE_CONTAINER, + RPLMODULE_EXCEPTION, + RPLMODULE_TEST, // 5 + RPLMODULE_TCPSERVER, + RPLMODULE_TCPCLIENT, + RPLMODULE_TCPPEER, + RPLMODULE_TERMINATOR, + + // last element: + RPLMODULE_COUNT +}; +#define RPL_FIRST_OF(moduleNo) (moduleNo*1000+1) +class RplModules{ +public: + static int fileToNumber(const char* file); + static const char* numberToFile(int location); +}; + + +#endif // RPLMODULES_HPP diff --git a/rplstatic/getsrc.pl b/rplstatic/getsrc.pl new file mode 100644 index 0000000..7618a1f --- /dev/null +++ b/rplstatic/getsrc.pl @@ -0,0 +1,29 @@ +#! /usr/bin/perl + +use strict; + +my @rc; +push @rc, &oneDir("../rplcore/*.hpp"); +push @rc, &oneDir("../rplmath/*.hpp"); +push @rc, &oneDir("../rplnet/*.hpp"); +push @rc, "\n"; +push @rc, &oneDir("../rplcore/*.cpp"); +push @rc, &oneDir("../rplmath/*.cpp"); +push @rc, &oneDir("../rplnet/*.cpp"); + +print @rc; +exit 0; + +sub oneDir{ + my $pattern = shift; + my @rc; + open (my $INP, "ls -1 $pattern|") || die "ls -1 $pattern: $!"; + while(<$INP>) { + if (/(\S+)/){ + push(@rc, " $1 \\\n"); + } + } + return @rc; +} + + diff --git a/rplstatic/rplstatic.pro b/rplstatic/rplstatic.pro index a2352f0..9d98af1 100644 --- a/rplstatic/rplstatic.pro +++ b/rplstatic/rplstatic.pro @@ -12,9 +12,45 @@ TARGET = rplstatic TEMPLATE = lib CONFIG += staticlib -SOURCES += rplstaticlib.cpp ../rplmath/rplmatrix.cpp ../rplmath/rplenigma.cpp +INCLUDEPATH = .. + +SOURCES += \ + ../rplcore/rplconfig.cpp \ + ../rplcore/rplcontainer.cpp \ + ../rplcore/rplexception.cpp \ + ../rplcore/rpllogger.cpp \ + ../rplcore/rplstring.cpp \ + ../rplcore/rplterminator.cpp \ + ../rplcore/rpltest.cpp \ + ../rplmath/rplenigma.cpp \ + ../rplmath/rplmatrix.cpp \ + ../rplmath/rplmatrix_test.cpp \ + ../rplmath/rplrandom.cpp \ + ../rplnet/rplnetconfig.cpp \ + ../rplnet/rpltcpclient.cpp \ + ../rplnet/rpltcppeer.cpp \ + ../rplnet/rpltcpserver.cpp \ + +HEADERS += ../rplmodules.hpp \ + ../rplcore/rplconfig.hpp \ + ../rplcore/rplconfigurator.hpp \ + ../rplcore/rplcontainer.hpp \ + ../rplcore/rplcore.hpp \ + ../rplcore/rplexception.hpp \ + ../rplcore/rpllogger.hpp \ + ../rplcore/rplstring.hpp \ + ../rplcore/rplterminator.hpp \ + ../rplcore/rpltest.hpp \ + ../rplmath/rplenigma.hpp \ + ../rplmath/rplmath.hpp \ + ../rplmath/rplmatrix.hpp \ + ../rplmath/rplrandom.hpp \ + ../rplnet/rplnetconfig.hpp \ + ../rplnet/rplnet.hpp \ + ../rplnet/rpltcpclient.hpp \ + ../rplnet/rpltcppeer.hpp \ + ../rplnet/rpltcpserver.hpp \ -HEADERS += rplstaticlib.hpp ../rplmath/rplmatrix.hpp ../rplmath/rplenigma.hpp unix:!symbian { maemo5 { target.path = /opt/usr/lib diff --git a/unittests/main.cpp b/unittests/main.cpp new file mode 100644 index 0000000..5ebbca5 --- /dev/null +++ b/unittests/main.cpp @@ -0,0 +1,21 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. +*/ +#include "../rplcore/rplcore.hpp" +#include "../rplmath/rplmath.hpp" + +#include + +int main(int argc, char *argv[]) +{ + //QCoreApplication a(argc, argv); + if (argc > 1) + printf("not used: %s\n", argv[1]); + //return a.exec(); + extern void testRplMatrix(); + testRplMatrix(); +} diff --git a/unittests/rplmatrix_test.cpp b/unittests/rplmatrix_test.cpp new file mode 100644 index 0000000..5bd8215 --- /dev/null +++ b/unittests/rplmatrix_test.cpp @@ -0,0 +1,48 @@ +/* + * Matrix_test.cpp + * + * Created on: 29.05.2014 + * Author: hm + */ +#include "rplcore/rplcore.hpp" +#include "rplmath/rplmath.hpp" +#include "rplcore/rpltest.hpp" + +class TestRplMatrix : public RplTest{ +public: + TestRplMatrix() : RplTest("RplMatrix") {} + +public: + void testBasic() { + Tuple2 tuple(-2.0, 0.5); + checkE(-2.0, tuple.m_value1); + checkE(0.5, tuple.m_value2); + try{ + throw RplMatrixException(1, "String: %s and int %d", "Hi", -333); + checkF(true); + } catch (RplMatrixException exc){ + checkE("String: Hi and int -333", exc.getMessage()); + } + RplMatrix mat("mx"); + try{ + throw RplMatrixException(mat, "String: %s and int %d", "Hi", -333); + checkF(true); + } catch (RplMatrixException exc){ + checkE("mx: String: Hi and int -333", exc.getMessage()); + } + RplMatrix mat2; + try{ + throw RplMatrixException(mat2, "String: %s and int %d", "Hi", -333); + checkF(true); + } catch (RplMatrixException exc){ + checkE("String: Hi and int -333", exc.getMessage()); + } + } + virtual void doIt() { + testBasic(); + } +}; +void testRplMatrix() { + TestRplMatrix test; + test.run(); +} diff --git a/unittests/unittests.pro b/unittests/unittests.pro new file mode 100644 index 0000000..5dde07d --- /dev/null +++ b/unittests/unittests.pro @@ -0,0 +1,22 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-31T00:01:23 +# +#------------------------------------------------- + +QT += core network + +QT -= gui + +TARGET = unittests +CONFIG += console +CONFIG -= app_bundle + +INCLUDEPATH = .. + +TEMPLATE = app + +SOURCES += main.cpp \ + rplmatrix_test.cpp \ + ../rplmath/rplmatrix.cpp + -- 2.39.5