2 #include <boost/property_tree/json_parser.hpp>
3 #include <boost/optional/optional.hpp>
4 #include <boost/filesystem.hpp>
14 if (file.has_value()) {
15 boost::property_tree::read_json(file.value(),
contents);
30 if (path.has_value()) {
31 if (!boost::filesystem::exists(path.value())) {
32 throw std::invalid_argument(
33 "No such file. [translationTablePath=" + path.value().string() +
"]"
35 }
else if (!boost::filesystem::is_regular_file(path.value())) {
36 throw std::invalid_argument(
37 "Translation-Table is not a file. [translationTablePath=" + path.value().string() +
"]"
40 boost::property_tree::read_json(path.value().string(),
contents);
54 boost::property_tree::json_parser::write_json(out, contents);
63 const boost::property_tree::ptree &style
65 const auto parseConstraintNode = [](
const boost::property_tree::ptree &node) {
66 std::unordered_set<std::string> fields;
67 std::for_each(std::cbegin(node),
69 [&fields](
const boost::property_tree::ptree::value_type &field) {
70 const std::string title = field.second.data();
78 const boost::optional<const boost::property_tree::ptree &>
name =
79 style.get_child_optional(
"name");
80 const boost::optional<const boost::property_tree::ptree &> requiredFieldsNode =
81 style.get_child_optional(
"requiredFields");
82 const boost::optional<const boost::property_tree::ptree &> optionalFieldsNode =
83 style.get_child_optional(
"optionalFields");
85 return {
name ? std::string{
name.value().data()} :
"",
86 requiredFieldsNode ? parseConstraintNode(requiredFieldsNode.value())
87 : std::unordered_set<std::string>{},
88 optionalFieldsNode ? parseConstraintNode(optionalFieldsNode.value())
89 : std::unordered_set<std::string>{}};
98 std::vector<StyleProperties> props;
99 const boost::optional<const boost::property_tree::ptree &> styles =
100 contents.get_child_optional(
"styles");
102 std::transform(std::cbegin(styles.value()),
103 std::cend(styles.value()),
104 std::back_inserter(props),
105 [
this](
const boost::property_tree::ptree::value_type &style) {
106 return this->parseStyle(style.second);
109 throw std::logic_error(
"Property \"styles\" not found in provided Translation-Table.");
128 const std::string &
name
129 )
const noexcept -> std::optional<StyleProperties> {
130 const auto propItr = std::find_if(std::cbegin(styleProperties), std::cend(styleProperties),
132 return (propItr != std::cend(styleProperties)) ? std::optional(*propItr) : std::nullopt;
142 const std::vector<std::string> &names
143 )
const noexcept -> std::vector<StyleProperties> {
144 if (names.empty())
return getStyleProperties();
145 std::vector<StyleProperties> result;
146 for (
const auto &style : names) {
147 const auto props = stylePropertiesOf(style);
148 if (props) result.push_back(props.value());