Skip to content

Commit 93c1cca

Browse files
committed
Change the license to LGPL
1 parent f2e7207 commit 93c1cca

10 files changed

+247
-722
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ repos:
1212
entry: black
1313
language: system
1414
types: [python]
15+
1516
- id: flake8
1617
name: Flake8
1718
entry: flake8
1819
language: system
1920
types: [python]
21+
2022
- id: pyupgrade
2123
name: PyUpgrade
2224
entry: pyupgrade
@@ -55,6 +57,13 @@ repos:
5557
entry: make -j all
5658
files: Makefile
5759

60+
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
61+
rev: 0.1.0
62+
hooks:
63+
- id: yamlfmt
64+
args: [--mapping, '2', --sequence, '4', --offset, '2', --width, '150']
65+
types: [yaml]
66+
5867
- repo: https://github.com/pre-commit/pre-commit-hooks
5968
rev: v4.0.1
6069
hooks:
@@ -102,13 +111,6 @@ repos:
102111
types: [python]
103112
- id: requirements-txt-fixer
104113

105-
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
106-
rev: 0.1.0
107-
hooks:
108-
- id: yamlfmt
109-
args: [--mapping, '2', --sequence, '4', --offset, '2', --width, '150']
110-
types: [yaml]
111-
112114
#- repo: https://github.com/python/black
113115
#rev: 21.5b1
114116
#hooks:

CPPLINT.cfg

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
linelength=88
1+
# C++ version
22
filter=-build/c++11
33
filter=+build/c++17
4-
filter=-build/header_guard
5-
filter=-build/namespaces
6-
filter=-legal/copyright
4+
5+
# Formatting is handled by clang-format
6+
linelength=88
77
filter=-whitespace/parens
88
filter=-whitespace/braces
99
filter=-whitespace/indent
1010
filter=-whitespace/operators
1111
filter=-whitespace/semicolon
12-
filter=-readability/alt_tokens
12+
13+
# License is in the LICENSE file
14+
filter=-legal/copyright
15+
# Too late to use the Cpplint formatting of header guard
16+
filter=-build/header_guard
17+
# I prefer references to pointer as much as possible
1318
filter=-runtime/references
19+
# I prefer full worlds (and, or, not...) instead of symbol (!, &&, ||...)
20+
filter=-readability/alt_tokens

LICENSE

Lines changed: 160 additions & 669 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "tools"
3-
version = "1.0.0"
3+
version = "1.2.0"
44
description = "Yet another small C++ generic library, extending the standard library for ease of use."
55
authors = ["jgaffiot <j.gaffiot@laposte.net>"]
66

source/inc/ProgressBar.hh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ public:
5555
void DisplayEnd();
5656

5757
private:
58-
typedef std::chrono::high_resolution_clock PBC; // Progress Bar Clock
59-
typedef PBC::time_point PBTP; // Progress Bar Time Point
58+
typedef std::chrono::high_resolution_clock Clock;
6059

6160
double NbIteration;
6261
double previous_iter = 0.;
6362
char small_buffer[detail_bar::kSmallSize];
6463
char large_buffer[detail_bar::kLargeSize];
65-
PBTP init, now, previous;
64+
Clock::time_point init, now, previous;
6665

67-
constexpr static double ClockPeriod =
68-
static_cast<double>(PBC::period::den) / static_cast<double>(PBC::period::num);
69-
constexpr static std::chrono::duration<PBC::rep, std::chrono::milliseconds::period>
70-
delta_t{500};
66+
constexpr static double ClockPeriod = static_cast<double>(Clock::period::den)
67+
/ static_cast<double>(Clock::period::num);
68+
constexpr static std::chrono::
69+
duration<Clock::rep, std::chrono::milliseconds::period>
70+
delta_t{500};
7171
};
7272

7373
} // namespace tools

source/src/DataBase.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111

1212
#include "DataBase.hh"
1313

14-
#include <cstdlib>
1514
#include <fstream>
1615
#include <iostream>
1716
#include <memory>
18-
#include <regex>
1917
#include <string>
18+
#include <vector>
2019

2120
#include "Regex.hh"
2221
#include "String.hh"
@@ -27,8 +26,18 @@
2726
# include "TObjString.h"
2827
#endif
2928

30-
using namespace tools;
31-
using namespace std;
29+
namespace tools
30+
{
31+
using std::cerr;
32+
using std::cout;
33+
using std::endl;
34+
using std::ifstream;
35+
using std::istream;
36+
using std::ofstream;
37+
using std::ostream;
38+
using std::shared_ptr;
39+
using std::string;
40+
using std::vector;
3241

3342
////////////////////////////////////////////////////////////////
3443
////////////////////////// DataBase ///////////////////////////
@@ -507,4 +516,7 @@ void DataBase::WriteRoot(const char* filename) const {
507516
WriteRoot(&file);
508517
file.Close();
509518
}
519+
510520
#endif // DATABASE__USE_ROOT
521+
522+
} // namespace tools

source/src/DualStream.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313

1414
#include "String.hh"
1515

16-
using namespace tools;
17-
using namespace std;
16+
namespace tools
17+
{
18+
using std::cerr;
19+
using std::invalid_argument;
20+
using std::ios;
21+
using std::string;
1822

1923
DualStream::DualStream(const char* output_file_name, std::ostream& os): screen_out(os) {
2024
if (not Open(output_file_name)) {
@@ -44,11 +48,14 @@ bool DualStream::Open(const char* output_file_name) {
4448
}
4549

4650
#ifdef DUAL_TEST
51+
# include <fstream>
4752
int main() {
48-
ofstream ofs("dual.txt");
53+
std::ofstream ofs("dual.txt");
4954
DualStreamBuf bout(ofs.rdbuf());
5055
DualStreamBuf berr(ofs.rdbuf(), std::cerr);
5156
bout << "pwatout\n";
5257
berr << "pwaterr\n";
5358
}
5459
#endif
60+
61+
} // namespace tools

source/src/ProgressBar.cc

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
#include <time.h>
1313
#include <unistd.h>
1414

15-
#include <chrono>
1615
#include <cstdio>
1716
#include <cstdlib>
1817
#include <cstring>
1918
#include <iostream>
2019

21-
using namespace tools;
22-
using namespace std;
20+
namespace tools
21+
{
22+
using std::cout;
23+
using std::snprintf;
2324

2425
void display_bar_cxx98_notime(
2526
char* disp, size_t n, const uint64_t whereami, const uint64_t tot, const bool kbs) {
@@ -28,7 +29,7 @@ void display_bar_cxx98_notime(
2829
char* p = disp;
2930
struct timeval tv;
3031
static double previous_time = 0., previous = 0.;
31-
std::snprintf(disp, n, "processed: %2d%% ", progress);
32+
snprintf(disp, n, "processed: %2d%% ", progress);
3233
move_to_end(p, disp);
3334
*p++ = '[';
3435
for (int k = 0; k < 20; k++) {
@@ -48,14 +49,14 @@ void display_bar_cxx98_notime(
4849
(static_cast<double>(whereami) - previous * static_cast<double>(tot))
4950
/ static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec - previous_time) / 1024.;
5051
if (kbs) {
51-
std::snprintf(buffer, detail_bar::kSmallSize, " %.1f kB/s ", speed);
52+
snprintf(buffer, detail_bar::kSmallSize, " %.1f kB/s ", speed);
5253
} else {
53-
std::snprintf(buffer, detail_bar::kSmallSize, " %.1f evts/s ", speed * 1024.);
54+
snprintf(buffer, detail_bar::kSmallSize, " %.1f evts/s ", speed * 1024.);
5455
}
5556
strncat(disp, buffer, detail_bar::kSmallSize);
56-
std::cout << "\r";
57-
std::cout << disp;
58-
std::cout.flush();
57+
cout << "\r";
58+
cout << disp;
59+
cout.flush();
5960
previous = static_cast<double>(whereami) / static_cast<double>(tot);
6061
previous_time = static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec);
6162
}
@@ -74,7 +75,7 @@ void display_bar_cxx98(
7475
char* p = disp;
7576
struct timeval tv;
7677
static double previous_time = 0., previous = 0.;
77-
std::snprintf(disp, n, "processed: %2d%% ", progress);
78+
snprintf(disp, n, "processed: %2d%% ", progress);
7879
move_to_end(p, disp);
7980
*p++ = '[';
8081
for (int k = 0; k < 20; k++) {
@@ -97,20 +98,20 @@ void display_bar_cxx98(
9798
/ static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec - init_time)
9899
/ 1024.;
99100
if (kbs) {
100-
std::snprintf(
101+
snprintf(
101102
buffer, detail_bar::kSmallSize, " %.1f kB/s -> %.1f kB/s", speed, average);
102103
} else {
103-
std::snprintf(
104+
snprintf(
104105
buffer,
105106
detail_bar::kSmallSize,
106107
" %.1f evts/s -> %.1f evts/s",
107108
speed * 1024.,
108109
average * 1024.);
109110
}
110111
strncat(disp, buffer, detail_bar::kSmallSize);
111-
std::cout << "\r";
112-
std::cout << disp;
113-
std::cout.flush();
112+
cout << "\r";
113+
cout << disp;
114+
cout.flush();
114115
previous = static_cast<double>(whereami) / static_cast<double>(tot);
115116
previous_time = static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec);
116117
}
@@ -119,25 +120,25 @@ void display_bar_cxx98(
119120

120121
void display_end_bar(char* disp, size_t n) {
121122
snprintf(disp, n, "processed: 100%% [====================]");
122-
std::cout << "\r";
123-
std::cout << disp;
124-
std::cout.flush();
125-
std::cout << "\n";
123+
cout << "\r";
124+
cout << disp;
125+
cout.flush();
126+
cout << "\n";
126127
}
127128

128129
////////////////////////////////////////////////////////////////
129130
////////////////////////////////////////////////////////////////
130131
////////////////////////////////////////////////////////////////
131132

132133
ProgressBar::ProgressBar(double _NbIteration): NbIteration(_NbIteration) {
133-
init = PBC::now();
134+
init = Clock::now();
134135
previous = init;
135136
}
136137

137138
////////////////////////////////////////////////////////////////
138139

139140
void ProgressBar::Display(double current_iter) {
140-
now = PBC::now();
141+
now = Clock::now();
141142
if (now - previous < delta_t) {
142143
return;
143144
}
@@ -185,3 +186,5 @@ void ProgressBar::Display(double current_iter) {
185186
void ProgressBar::DisplayEnd() {
186187
cout << "\rprocessed: 100%% [====================]\n";
187188
}
189+
190+
} // namespace tools

source/src/String.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "String.hh"
1010

11-
using namespace tools;
12-
11+
namespace tools
12+
{
1313
hash_t HashRunTime(const char* str) {
1414
hash_t ret{detail_string::basis};
1515
while (*str) {
@@ -19,3 +19,5 @@ hash_t HashRunTime(const char* str) {
1919
}
2020
return ret;
2121
}
22+
23+
} // namespace tools

source/src/Vector3.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
#include "Math.hh"
1414

15-
using namespace tools;
16-
using namespace std;
17-
15+
namespace tools
16+
{
1817
void Vector3::SetMagThetaPhi(double mag, double theta, double phi) {
1918
double amag = abs(mag);
2019
v[2] = amag * cos(theta);
@@ -70,3 +69,5 @@ Vector3& Vector3::Unit() {
7069
v[2] /= norm;
7170
return *this;
7271
}
72+
73+
} // namespace tools

0 commit comments

Comments
 (0)