-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
246 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright 2024 René Ferdinand Rivera Morell | ||
Distributed under the Boost Software License, Version 1.0. | ||
(See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt) | ||
*/ | ||
|
||
#include "mod_summary.h" | ||
|
||
#include "output.h" | ||
|
||
namespace b2 { | ||
|
||
void summary::group(value_ref group) | ||
{ | ||
group_order.push_back(group); | ||
groups.emplace(group, group_t(new group_t::element_type)); | ||
} | ||
|
||
void summary::message(value_ref group, value_ref message) | ||
{ | ||
groups[group]->push_back(message); | ||
} | ||
|
||
int summary::count(value_ref group) { return (int)(groups[group]->size()); } | ||
|
||
void summary::print(value_ref group, value_ref format) | ||
{ | ||
std::string format_str = format; | ||
auto & g = groups[group]; | ||
std::sort(g->begin(), g->end(), [](value_ref a, value_ref b) -> bool { | ||
return std::strcmp(a->str(), b->str()) < 0; | ||
}); | ||
for (auto const & m : *g) | ||
{ | ||
std::string m_str = m; | ||
out_printf(format->str(), m_str.c_str()); | ||
} | ||
} | ||
|
||
} // namespace b2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2024 René Ferdinand Rivera Morell | ||
Distributed under the Boost Software License, Version 1.0. | ||
(See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt) | ||
*/ | ||
|
||
#ifndef B2_MOD_SUMMARY_H | ||
#define B2_MOD_SUMMARY_H | ||
|
||
#include "config.h" | ||
|
||
#include "bind.h" | ||
#include "value.h" | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace b2 { | ||
|
||
class summary : public object | ||
{ | ||
public: | ||
void group(value_ref group); | ||
void message(value_ref group, value_ref message); | ||
int count(value_ref group); | ||
void print(value_ref group, value_ref format); | ||
|
||
private: | ||
using group_t = std::unique_ptr<std::vector<value_ref>>; | ||
using groups_t = std::unordered_map<value_ref, | ||
group_t, | ||
value_ref::hash_function, | ||
value_ref::equal_function>; | ||
|
||
groups_t groups; | ||
std::vector<value_ref> group_order; | ||
}; | ||
|
||
struct summary_module : b2::bind::module_<summary_module> | ||
{ | ||
const char * module_name = "summary"; | ||
|
||
template <class Binder> | ||
void def(Binder & binder) | ||
{ | ||
binder.def_class("summary", type_<summary>()) | ||
.def(init_<>()) | ||
.def(&summary::group, "group", "group" * _1) | ||
.def(&summary::message, "message", "group" * _1, | ||
"message" * _1n) | ||
.def(&summary::count, "count", "group" * _1) | ||
.def(&summary::print, "print", "group" * _1, | ||
"format" * _1); | ||
} | ||
}; | ||
|
||
} // namespace b2 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.