Various modernizations

parent d5fcfb65
Pipeline #566 failed with stages
in 5 minutes and 58 seconds
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "formula_tab.hh" #include "formula_tab.hh"
#include <cmath> #include <cmath>
#include <cstring>
using namespace ogp; using namespace ogp;
......
...@@ -413,6 +413,5 @@ ConstVector::print() const ...@@ -413,6 +413,5 @@ ConstVector::print() const
ZeroPad::ZeroPad() ZeroPad::ZeroPad()
{ {
for (double & i : pad) pad.fill(0.0);
i = 0.0;
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* to avoid running virtual method invokation mechanism. Some * to avoid running virtual method invokation mechanism. Some
* members, and methods are thus duplicated */ * members, and methods are thus duplicated */
#include <array>
#include <cstdio> #include <cstdio>
class GeneralMatrix; class GeneralMatrix;
...@@ -235,13 +236,13 @@ class ZeroPad ...@@ -235,13 +236,13 @@ class ZeroPad
public: public:
static const int length = 16; static const int length = 16;
private: private:
double pad[16]; std::array<double, length> pad;
public: public:
ZeroPad(); ZeroPad();
const double * const double *
getBase() const getBase() const
{ {
return pad; return pad.data();
} }
}; };
......
...@@ -5,54 +5,41 @@ ...@@ -5,54 +5,41 @@
#ifndef OGU_EXCEPTION_H #ifndef OGU_EXCEPTION_H
#define OGU_EXCEPTION_H #define OGU_EXCEPTION_H
#include <cstdio>
#include <cstring>
#include <string> #include <string>
#include <algorithm> #include <iostream>
#include <utility>
namespace ogu namespace ogu
{ {
/** A primitive exception. */ /** A primitive exception. */
class Exception class Exception
{ {
static const int file_length = 100;
static const int mes_length = 500;
protected: protected:
char file[file_length]; const std::string file;
int line; const int line;
char mes[mes_length]; const std::string mes;
public: public:
Exception(const char *f, int l, const char *m) Exception(std::string file_arg, int line_arg, std::string mes_arg)
{ : file{std::move(file_arg)},
strncpy(file, f, file_length-1); line{line_arg},
file[file_length-1] = '\0'; mes{std::move(mes_arg)}
line = l;
strncpy(mes, m, std::min(mes_length-1, (int) strlen(m)));
mes[mes_length-1] = '\0';
}
Exception(const char *f, int l, const std::string &m)
{ {
strncpy(file, f, file_length-1);
file[file_length-1] = '\0';
line = l;
strncpy(mes, m.c_str(), std::min(mes_length-1, (int) m.length()));
mes[mes_length-1] = '\0';
} }
virtual ~Exception() virtual ~Exception() = default;
= default;
void void
print(FILE *fd) const print(std::ostream &out) const
{ {
fprintf(fd, "%s:%d: %s\n", file, line, mes); out << file << ':' << line << ": " << mes << std::endl;
} }
void void
print() const print() const
{ {
print(stdout); print(std::cout);
} }
const char *
std::string
message() const message() const
{ {
return mes; return mes;
......
#include "pascal_triangle.hh" #include "pascal_triangle.hh"
#include <cstdio>
#include <iostream>
using namespace ogu; using namespace ogu;
...@@ -41,10 +42,10 @@ PascalRow::prolongFirst(int n) ...@@ -41,10 +42,10 @@ PascalRow::prolongFirst(int n)
void void
PascalRow::print() const PascalRow::print() const
{ {
printf("k=%d\n", k); std::cout << "k=" << k << std::endl;
for (unsigned int i = 0; i < size(); i++) for (unsigned int i = 0; i < size(); i++)
printf("%d ", operator[](i)); std::cout << operator[](i) << ' ';
printf("\n"); std::cout << std::endl;
} }
int int
......
...@@ -16,8 +16,7 @@ namespace ogu ...@@ -16,8 +16,7 @@ namespace ogu
{ {
int k{1}; int k{1};
public: public:
PascalRow() PascalRow() : vector<int>{}
: vector<int>()
{ {
push_back(2); push_back(2);
} }
...@@ -35,12 +34,8 @@ namespace ogu ...@@ -35,12 +34,8 @@ namespace ogu
{ {
tr.emplace_back(); tr.emplace_back();
} }
PascalTriangle(const PascalTriangle &triang) PascalTriangle(const PascalTriangle &triang) = default;
PascalTriangle &operator=(const PascalTriangle &triang) = default;
= default;
PascalTriangle &
operator=(const PascalTriangle &triang)
= default;
int noverk(int n, int k); int noverk(int n, int k);
void print() const; void print() const;
protected: protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment