Commit 8bc450f5 authored by Sébastien Villemot's avatar Sébastien Villemot

Various modernizations

parent d5fcfb65
Pipeline #566 failed with stages
in 5 minutes and 58 seconds
......@@ -11,6 +11,7 @@
#include "formula_tab.hh"
#include <cmath>
#include <cstring>
using namespace ogp;
......
......@@ -413,6 +413,5 @@ ConstVector::print() const
ZeroPad::ZeroPad()
{
for (double & i : pad)
i = 0.0;
pad.fill(0.0);
}
......@@ -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();
}
};
......
......@@ -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;
......
#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
......
......@@ -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:
......
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