Skip to content

Commit

Permalink
Merge pull request #7 from jgaffiot/change_license
Browse files Browse the repository at this point in the history
Change the license to LGPL
  • Loading branch information
jgaffiot authored Jun 23, 2021
2 parents f2e7207 + 93c1cca commit ef79c94
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 722 deletions.
16 changes: 9 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ repos:
entry: black
language: system
types: [python]

- id: flake8
name: Flake8
entry: flake8
language: system
types: [python]

- id: pyupgrade
name: PyUpgrade
entry: pyupgrade
Expand Down Expand Up @@ -55,6 +57,13 @@ repos:
entry: make -j all
files: Makefile

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.1.0
hooks:
- id: yamlfmt
args: [--mapping, '2', --sequence, '4', --offset, '2', --width, '150']
types: [yaml]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
Expand Down Expand Up @@ -102,13 +111,6 @@ repos:
types: [python]
- id: requirements-txt-fixer

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.1.0
hooks:
- id: yamlfmt
args: [--mapping, '2', --sequence, '4', --offset, '2', --width, '150']
types: [yaml]

#- repo: https://github.com/python/black
#rev: 21.5b1
#hooks:
Expand Down
17 changes: 12 additions & 5 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
linelength=88
# C++ version
filter=-build/c++11
filter=+build/c++17
filter=-build/header_guard
filter=-build/namespaces
filter=-legal/copyright

# Formatting is handled by clang-format
linelength=88
filter=-whitespace/parens
filter=-whitespace/braces
filter=-whitespace/indent
filter=-whitespace/operators
filter=-whitespace/semicolon
filter=-readability/alt_tokens

# License is in the LICENSE file
filter=-legal/copyright
# Too late to use the Cpplint formatting of header guard
filter=-build/header_guard
# I prefer references to pointer as much as possible
filter=-runtime/references
# I prefer full worlds (and, or, not...) instead of symbol (!, &&, ||...)
filter=-readability/alt_tokens
829 changes: 160 additions & 669 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tools"
version = "1.0.0"
version = "1.2.0"
description = "Yet another small C++ generic library, extending the standard library for ease of use."
authors = ["jgaffiot <[email protected]>"]

Expand Down
14 changes: 7 additions & 7 deletions source/inc/ProgressBar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ public:
void DisplayEnd();

private:
typedef std::chrono::high_resolution_clock PBC; // Progress Bar Clock
typedef PBC::time_point PBTP; // Progress Bar Time Point
typedef std::chrono::high_resolution_clock Clock;

double NbIteration;
double previous_iter = 0.;
char small_buffer[detail_bar::kSmallSize];
char large_buffer[detail_bar::kLargeSize];
PBTP init, now, previous;
Clock::time_point init, now, previous;

constexpr static double ClockPeriod =
static_cast<double>(PBC::period::den) / static_cast<double>(PBC::period::num);
constexpr static std::chrono::duration<PBC::rep, std::chrono::milliseconds::period>
delta_t{500};
constexpr static double ClockPeriod = static_cast<double>(Clock::period::den)
/ static_cast<double>(Clock::period::num);
constexpr static std::chrono::
duration<Clock::rep, std::chrono::milliseconds::period>
delta_t{500};
};

} // namespace tools
Expand Down
20 changes: 16 additions & 4 deletions source/src/DataBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

#include "DataBase.hh"

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <memory>
#include <regex>
#include <string>
#include <vector>

#include "Regex.hh"
#include "String.hh"
Expand All @@ -27,8 +26,18 @@
# include "TObjString.h"
#endif

using namespace tools;
using namespace std;
namespace tools
{
using std::cerr;
using std::cout;
using std::endl;
using std::ifstream;
using std::istream;
using std::ofstream;
using std::ostream;
using std::shared_ptr;
using std::string;
using std::vector;

////////////////////////////////////////////////////////////////
////////////////////////// DataBase ///////////////////////////
Expand Down Expand Up @@ -507,4 +516,7 @@ void DataBase::WriteRoot(const char* filename) const {
WriteRoot(&file);
file.Close();
}

#endif // DATABASE__USE_ROOT

} // namespace tools
13 changes: 10 additions & 3 deletions source/src/DualStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

#include "String.hh"

using namespace tools;
using namespace std;
namespace tools
{
using std::cerr;
using std::invalid_argument;
using std::ios;
using std::string;

DualStream::DualStream(const char* output_file_name, std::ostream& os): screen_out(os) {
if (not Open(output_file_name)) {
Expand Down Expand Up @@ -44,11 +48,14 @@ bool DualStream::Open(const char* output_file_name) {
}

#ifdef DUAL_TEST
# include <fstream>
int main() {
ofstream ofs("dual.txt");
std::ofstream ofs("dual.txt");
DualStreamBuf bout(ofs.rdbuf());
DualStreamBuf berr(ofs.rdbuf(), std::cerr);
bout << "pwatout\n";
berr << "pwaterr\n";
}
#endif

} // namespace tools
45 changes: 24 additions & 21 deletions source/src/ProgressBar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include <time.h>
#include <unistd.h>

#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace tools;
using namespace std;
namespace tools
{
using std::cout;
using std::snprintf;

void display_bar_cxx98_notime(
char* disp, size_t n, const uint64_t whereami, const uint64_t tot, const bool kbs) {
Expand All @@ -28,7 +29,7 @@ void display_bar_cxx98_notime(
char* p = disp;
struct timeval tv;
static double previous_time = 0., previous = 0.;
std::snprintf(disp, n, "processed: %2d%% ", progress);
snprintf(disp, n, "processed: %2d%% ", progress);
move_to_end(p, disp);
*p++ = '[';
for (int k = 0; k < 20; k++) {
Expand All @@ -48,14 +49,14 @@ void display_bar_cxx98_notime(
(static_cast<double>(whereami) - previous * static_cast<double>(tot))
/ static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec - previous_time) / 1024.;
if (kbs) {
std::snprintf(buffer, detail_bar::kSmallSize, " %.1f kB/s ", speed);
snprintf(buffer, detail_bar::kSmallSize, " %.1f kB/s ", speed);
} else {
std::snprintf(buffer, detail_bar::kSmallSize, " %.1f evts/s ", speed * 1024.);
snprintf(buffer, detail_bar::kSmallSize, " %.1f evts/s ", speed * 1024.);
}
strncat(disp, buffer, detail_bar::kSmallSize);
std::cout << "\r";
std::cout << disp;
std::cout.flush();
cout << "\r";
cout << disp;
cout.flush();
previous = static_cast<double>(whereami) / static_cast<double>(tot);
previous_time = static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec);
}
Expand All @@ -74,7 +75,7 @@ void display_bar_cxx98(
char* p = disp;
struct timeval tv;
static double previous_time = 0., previous = 0.;
std::snprintf(disp, n, "processed: %2d%% ", progress);
snprintf(disp, n, "processed: %2d%% ", progress);
move_to_end(p, disp);
*p++ = '[';
for (int k = 0; k < 20; k++) {
Expand All @@ -97,20 +98,20 @@ void display_bar_cxx98(
/ static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec - init_time)
/ 1024.;
if (kbs) {
std::snprintf(
snprintf(
buffer, detail_bar::kSmallSize, " %.1f kB/s -> %.1f kB/s", speed, average);
} else {
std::snprintf(
snprintf(
buffer,
detail_bar::kSmallSize,
" %.1f evts/s -> %.1f evts/s",
speed * 1024.,
average * 1024.);
}
strncat(disp, buffer, detail_bar::kSmallSize);
std::cout << "\r";
std::cout << disp;
std::cout.flush();
cout << "\r";
cout << disp;
cout.flush();
previous = static_cast<double>(whereami) / static_cast<double>(tot);
previous_time = static_cast<double>(tv.tv_sec + 1.0e-6 * tv.tv_usec);
}
Expand All @@ -119,25 +120,25 @@ void display_bar_cxx98(

void display_end_bar(char* disp, size_t n) {
snprintf(disp, n, "processed: 100%% [====================]");
std::cout << "\r";
std::cout << disp;
std::cout.flush();
std::cout << "\n";
cout << "\r";
cout << disp;
cout.flush();
cout << "\n";
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

ProgressBar::ProgressBar(double _NbIteration): NbIteration(_NbIteration) {
init = PBC::now();
init = Clock::now();
previous = init;
}

////////////////////////////////////////////////////////////////

void ProgressBar::Display(double current_iter) {
now = PBC::now();
now = Clock::now();
if (now - previous < delta_t) {
return;
}
Expand Down Expand Up @@ -185,3 +186,5 @@ void ProgressBar::Display(double current_iter) {
void ProgressBar::DisplayEnd() {
cout << "\rprocessed: 100%% [====================]\n";
}

} // namespace tools
6 changes: 4 additions & 2 deletions source/src/String.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "String.hh"

using namespace tools;

namespace tools
{
hash_t HashRunTime(const char* str) {
hash_t ret{detail_string::basis};
while (*str) {
Expand All @@ -19,3 +19,5 @@ hash_t HashRunTime(const char* str) {
}
return ret;
}

} // namespace tools
7 changes: 4 additions & 3 deletions source/src/Vector3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#include "Math.hh"

using namespace tools;
using namespace std;

namespace tools
{
void Vector3::SetMagThetaPhi(double mag, double theta, double phi) {
double amag = abs(mag);
v[2] = amag * cos(theta);
Expand Down Expand Up @@ -70,3 +69,5 @@ Vector3& Vector3::Unit() {
v[2] /= norm;
return *this;
}

} // namespace tools

0 comments on commit ef79c94

Please sign in to comment.