btool
A parser/converter/transpiler for .bib files
BibElement.cpp
Go to the documentation of this file.
1 #include <StyleProperties.hpp>
2 #include <BibElement.hpp>
3 #include <algorithm>
4 #include <iostream>
5 #include <utility>
6 
12 auto BibElement::isCompliantTo(const StyleProperties &props) const -> bool {
13  return
14  style == props.name
15  && std::all_of(
16  std::cbegin(props.requiredFields),
17  std::cend(props.requiredFields),
18  [this](const std::string &requiredFieldName) {
19  return findAttribute(requiredFieldName).has_value();
20  })
21  && std::all_of(
22  std::cbegin(attributes),
23  std::cend(attributes),
24  [&props](const Field &field) {
25  const auto inRequiredFields = props.requiredFields.find(field.name) != props.requiredFields.end();
26  const auto inOptionalFields = props.optionalFields.find(field.name) != props.optionalFields.end();
27  return inRequiredFields || inOptionalFields;
28  }
29  );
30 }
31 
37 auto BibElement::operator==(const BibElement &other) const noexcept -> bool {
38  return id == other.id && style == other.style && attributes == other.attributes;
39 }
40 
46 [[nodiscard]] auto BibElement::findAttribute(
47  const std::string &key
48 ) const noexcept -> std::optional<Field> {
49  const auto itr = std::find_if(
50  std::cbegin(attributes),
51  std::cend(attributes),
52  [&key](const auto &field) {
53  return field.name == key;
54  }
55  );
56  return itr == std::cend(attributes) ? std::nullopt : std::optional(*itr);
57 }
58 
65 auto operator<<(std::ostream &os, BibElement const &elem) -> std::ostream & {
66  os << "(id=" << elem.id << ", style=" << elem.style << ", attributes=[";
67  std::for_each(std::cbegin(elem.attributes), std::cend(elem.attributes), [&os](const Field &attribute) {
68  os << attribute;
69  });
70  return os << "])";
71 }
Field::name
std::string name
the name of the Field
Definition: Field.hpp:12
StyleProperties
style-properties-container
Definition: StyleProperties.hpp:11
operator<<
auto operator<<(std::ostream &os, BibElement const &elem) -> std::ostream &
Definition: BibElement.cpp:65
BibElement::operator==
auto operator==(const BibElement &other) const noexcept -> bool
Definition: BibElement.cpp:37
Field
Field-Container.
Definition: Field.hpp:11
BibElement::isCompliantTo
auto isCompliantTo(const StyleProperties &props) const -> bool
Definition: BibElement.cpp:12
BibElement::findAttribute
auto findAttribute(const std::string &key) const noexcept -> std::optional< Field >
Definition: BibElement.cpp:46
StyleProperties.hpp
BibElement.hpp
BibElement
bib-element-Container
Definition: BibElement.hpp:14