diff --git a/dynare++/parser/cc/formula_parser.cc b/dynare++/parser/cc/formula_parser.cc index 39724a130dd7a7c25ee2c5e588b11b10cacc9308..6e8dbec312feb3ceac570be11e30827f104672c7 100644 --- a/dynare++/parser/cc/formula_parser.cc +++ b/dynare++/parser/cc/formula_parser.cc @@ -11,6 +11,7 @@ #include "formula_tab.hh" #include <cmath> +#include <cstring> using namespace ogp; diff --git a/dynare++/sylv/cc/Vector.cc b/dynare++/sylv/cc/Vector.cc index 47ac7440834bbaf7181d9f056964d572a642aafd..1c529113b9653b22278c215a4413f3885eac2108 100644 --- a/dynare++/sylv/cc/Vector.cc +++ b/dynare++/sylv/cc/Vector.cc @@ -413,6 +413,5 @@ ConstVector::print() const ZeroPad::ZeroPad() { - for (double & i : pad) - i = 0.0; + pad.fill(0.0); } diff --git a/dynare++/sylv/cc/Vector.hh b/dynare++/sylv/cc/Vector.hh index 80bb0def50dc9d12f48c1d46097924c1d670c83e..5873a0a12d9068d2ddb8042601917e53374a3a8b 100644 --- a/dynare++/sylv/cc/Vector.hh +++ b/dynare++/sylv/cc/Vector.hh @@ -9,6 +9,7 @@ * to avoid running virtual method invokation mechanism. Some * members, and methods are thus duplicated */ +#include <array> #include <cstdio> class GeneralMatrix; @@ -235,13 +236,13 @@ class ZeroPad public: static const int length = 16; private: - double pad[16]; + std::array<double, length> pad; public: ZeroPad(); const double * getBase() const { - return pad; + return pad.data(); } }; diff --git a/dynare++/utils/cc/exception.hh b/dynare++/utils/cc/exception.hh index dc579d2c61850b882c8f0ae0e45da2dda00a2b1a..5ddd446ffb29db7ae14a0f46f50ba3595a72a862 100644 --- a/dynare++/utils/cc/exception.hh +++ b/dynare++/utils/cc/exception.hh @@ -5,54 +5,41 @@ #ifndef OGU_EXCEPTION_H #define OGU_EXCEPTION_H -#include <cstdio> -#include <cstring> - #include <string> -#include <algorithm> +#include <iostream> +#include <utility> namespace ogu { - /** A primitive exception. */ class Exception { - static const int file_length = 100; - static const int mes_length = 500; protected: - char file[file_length]; - int line; - char mes[mes_length]; + const std::string file; + const int line; + const std::string mes; public: - Exception(const char *f, int l, const char *m) - { - strncpy(file, f, file_length-1); - file[file_length-1] = '\0'; - 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) + Exception(std::string file_arg, int line_arg, std::string mes_arg) + : file{std::move(file_arg)}, + line{line_arg}, + mes{std::move(mes_arg)} { - 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() - = default; + virtual ~Exception() = default; + 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 print() const { - print(stdout); + print(std::cout); } - const char * + + std::string message() const { return mes; diff --git a/dynare++/utils/cc/pascal_triangle.cc b/dynare++/utils/cc/pascal_triangle.cc index 21e1d36dd5feaf6c35ba6b7f250d9e0d1c4ca975..093f482468d95ce71868586be7c28f8c04a4f0b9 100644 --- a/dynare++/utils/cc/pascal_triangle.cc +++ b/dynare++/utils/cc/pascal_triangle.cc @@ -1,5 +1,6 @@ #include "pascal_triangle.hh" -#include <cstdio> + +#include <iostream> using namespace ogu; @@ -41,10 +42,10 @@ PascalRow::prolongFirst(int n) void PascalRow::print() const { - printf("k=%d\n", k); + std::cout << "k=" << k << std::endl; for (unsigned int i = 0; i < size(); i++) - printf("%d ", operator[](i)); - printf("\n"); + std::cout << operator[](i) << ' '; + std::cout << std::endl; } int diff --git a/dynare++/utils/cc/pascal_triangle.hh b/dynare++/utils/cc/pascal_triangle.hh index 6b316532df1bc2050009d6e5447078baadb1edae..4cd2adb505f68a0556d9f7158d330c2954a1f30b 100644 --- a/dynare++/utils/cc/pascal_triangle.hh +++ b/dynare++/utils/cc/pascal_triangle.hh @@ -16,8 +16,7 @@ namespace ogu { int k{1}; public: - PascalRow() - : vector<int>() + PascalRow() : vector<int>{} { push_back(2); } @@ -35,12 +34,8 @@ namespace ogu { tr.emplace_back(); } - PascalTriangle(const PascalTriangle &triang) - - = default; - PascalTriangle & - operator=(const PascalTriangle &triang) - = default; + PascalTriangle(const PascalTriangle &triang) = default; + PascalTriangle &operator=(const PascalTriangle &triang) = default; int noverk(int n, int k); void print() const; protected: