btool
A parser/converter/transpiler for .bib files
AbstractGenerator.cpp
Go to the documentation of this file.
1 #include <AbstractGenerator.hpp>
2 #include <GeneratorException.hpp>
3 #include <Field.hpp>
4 #include <unordered_set>
5 #include <utility>
6 
13  const std::string &message,
14  const std::string &type
15 ) -> void {
16  throw GeneratorException{"[" + type + " generator]: " + message};
17 }
18 
23 AbstractGenerator::AbstractGenerator(std::vector<BibElement> elements) : elements{std::move(elements)} {}
24 
29 auto AbstractGenerator::write() -> std::string {
30  return "";
31 }
32 
34  const std::vector<BibElement> &values
35 ) noexcept -> std::unordered_set<std::string> {
36  std::unordered_set<std::string> result{};
37  std::for_each(std::cbegin(values),
38  std::cend(values),
39  [&](const BibElement &element) {
40  std::transform(std::cbegin(element.attributes),
41  std::cend(element.attributes),
42  std::inserter(result, std::end(result)),
43  [](const Field &field) {
44  return field.name;
45  });
46  });
47  return result;
48 }
49 
56  const std::vector<Field> &fields
57 ) noexcept -> std::vector<Field> {
58  std::vector<Field> sortedFields{std::cbegin(fields), std::cend(fields)};
59  std::sort(std::begin(sortedFields), std::end(sortedFields), [](const Field &l, const Field &r) {
60  return l.name < r.name;
61  });
62  return sortedFields;
63 }
AbstractGenerator::write
auto write() -> std::string override
Definition: AbstractGenerator.cpp:29
Field::name
std::string name
the name of the Field
Definition: Field.hpp:12
AbstractGenerator::fail
virtual auto fail(const std::string &message, const std::string &type="unknown") -> void
Definition: AbstractGenerator.cpp:12
Field
Field-Container.
Definition: Field.hpp:11
AbstractGenerator.hpp
BibElement::attributes
std::vector< Field > attributes
the attributes of the element
Definition: BibElement.hpp:17
GeneratorException
Definition: GeneratorException.hpp:11
Field.hpp
AbstractGenerator::uniqueFieldsOf
static auto uniqueFieldsOf(const std::vector< BibElement > &values) noexcept -> std::unordered_set< std::string >
Definition: AbstractGenerator.cpp:33
AbstractGenerator::sortedFields
static auto sortedFields(const std::vector< Field > &set) noexcept -> std::vector< Field >
Definition: AbstractGenerator.cpp:55
GeneratorException.hpp
AbstractGenerator::AbstractGenerator
AbstractGenerator(std::vector< BibElement > elements)
Definition: AbstractGenerator.cpp:23
AbstractGenerator::elements
std::vector< BibElement > elements
Elements to write.
Definition: AbstractGenerator.hpp:16
BibElement
bib-element-Container
Definition: BibElement.hpp:14