PLaSK library

Loading...
Searching...
No Matches
data.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__LOG_DATA_H
15#define PLASK__LOG_DATA_H
16
17#include <string>
18
19#include "log.hpp"
20#include "id.hpp"
21
22 namespace plask {
23
27 template <typename ArgT, typename ValT>
28 class DataLog {
29
30 int cntr;
31 std::string global_prefix;
32 std::string chart_name;
33 std::string axis_arg_name;
34 std::string axis_val_name;
35
36 protected:
37
44 DataLog& operator()(const ArgT& arg, const ValT& val, int counter) {
45 writelog(LOG_DATA, "{}: {}: {}={} {}={} ({}) [{}]",
46 global_prefix, chart_name, axis_arg_name, str(arg), axis_val_name, str(val), str(abs(val)), counter+1);
47 return *this;
48 };
49
50 public:
51
52 DataLog(const std::string& global_prefix, const std::string& chart_name, const std::string& axis_arg_name, const std::string& axis_val_name) :
53 cntr(0), global_prefix(global_prefix), chart_name(chart_name), axis_arg_name(axis_arg_name), axis_val_name(axis_val_name)
54 {
55 }
56
57 DataLog(const std::string& global_prefix, const std::string& axis_arg_name, const std::string& axis_val_name) :
58 cntr(0), global_prefix(global_prefix), chart_name(axis_val_name + "(" + axis_arg_name + ")_" + getUniqueString()), axis_arg_name(axis_arg_name), axis_val_name(axis_val_name)
59 {
60 // chart_name = axis_arg_name(axis_arg_name)_getUniqueString()
61 }
62
68 DataLog& operator()(const ArgT& arg, const ValT& val) {
69 writelog(LOG_DATA, "{}: {}: {}={} {}={} ({})",
70 global_prefix, chart_name, axis_arg_name, str(arg), axis_val_name, str(val), str(abs(val)));
71 return *this;
72 }
73
79 inline int count(const ArgT& arg, const ValT& val) { (*this)(arg, val, cntr); return ++cntr; };
80
81
83 int counter() const { return cntr; }
84
86 void resetCounter() { cntr = 0; }
87
89 void throwError(const ArgT& arg) const {
90 writelog(LOG_ERROR_DETAIL, "{0}: {4}: {1}={3} {2}=ERROR", global_prefix, axis_arg_name, axis_val_name, str(arg), chart_name);
91 throw;
92 }
93
95 std::string chartName() const { return chart_name; }
96};
97
98 template <> DataLog<std::string, std::string>&
99 DataLog<std::string, std::string>::operator()(const std::string& arg, const std::string& val, int counter);
100
101 template <> DataLog<std::string, std::string>&
102 DataLog<std::string, std::string>::operator()(const std::string& arg, const std::string& val);
103
104}
105
106#endif // PLASK__LOG_DATA_H