cpp-hocon  0.3.0
simple_config_origin.hpp
1 #pragma once
2 
3 #include <hocon/config_origin.hpp>
4 
5 #include <string>
6 #include <vector>
7 #include <memory>
8 
9 namespace hocon {
10 
11  enum class origin_type { GENERIC, FILE, RESOURCE };
12 
13  class simple_config_origin : public config_origin, public std::enable_shared_from_this<simple_config_origin> {
14  public:
15  simple_config_origin(std::string description, int line_number, int end_line_number,
16  origin_type org_type, std::string resource_or_null, std::vector<std::string> comments_or_null);
17 
19  simple_config_origin(std::string description, int line_number = -1, int end_line_number = -1,
20  origin_type org_type = origin_type::GENERIC);
21 
22  int line_number() const override;
23 
24  std::string const& description() const override;
25  std::vector<std::string> const& comments() const override;
26 
31  shared_origin with_line_number(int line_number) const override;
32 
33  shared_origin with_comments(std::vector<std::string> comments) const override;
34  std::shared_ptr<const simple_config_origin> append_comments(std::vector<std::string> comments) const;
35  std::shared_ptr<const simple_config_origin> prepend_comments(std::vector<std::string> comments) const;
36 
37  static shared_origin merge_origins(shared_origin a, shared_origin b);
38  static shared_origin merge_origins(std::vector<shared_value> const& stack);
39  static shared_origin merge_origins(std::vector<shared_origin> const& stack);
40 
41  bool operator==(const simple_config_origin &other) const;
42  bool operator!=(const simple_config_origin &other) const;
43 
44  private:
45  static std::shared_ptr<const simple_config_origin> merge_two(std::shared_ptr<const simple_config_origin> a,
46  std::shared_ptr<const simple_config_origin> b);
47 
48  // this picks the best pair to merge, because the pair has the most in
49  // common. we want to merge two lines in the same file rather than something
50  // else with one of the lines; because two lines in the same file can be
51  // better consolidated.
52  static std::shared_ptr<const simple_config_origin> merge_three(std::shared_ptr<const simple_config_origin> a,
53  std::shared_ptr<const simple_config_origin> b,
54  std::shared_ptr<const simple_config_origin> c);
55 
56  static int similarity(std::shared_ptr<const simple_config_origin> a,
57  std::shared_ptr<const simple_config_origin> b);
58 
59  std::string _description;
60  int _line_number;
61  int _end_line_number;
62  origin_type _origin_type;
63  std::string _resource_or_null;
64  std::vector<std::string> _comments_or_null;
65  };
66 
67 } // namespace hocon
hocon
Factory for creating config_document instances.
Definition: config.hpp:18
hocon::simple_config_origin
Definition: simple_config_origin.hpp:13
hocon::simple_config_origin::description
std::string const & description() const override
Returns a string describing the origin of a value or exception.
hocon::simple_config_origin::simple_config_origin
simple_config_origin(std::string description, int line_number=-1, int end_line_number=-1, origin_type org_type=origin_type::GENERIC)
This constructor replaces the new_simple method in the original library.
hocon::simple_config_origin::with_line_number
shared_origin with_line_number(int line_number) const override
Returns a pointer to a copy of this origin with the specified line number as both starting and ending...
hocon::simple_config_origin::comments
std::vector< std::string > const & comments() const override
Returns any comments that appeared to "go with" this place in the file.
hocon::simple_config_origin::line_number
int line_number() const override
Returns a line number where the value or exception originated.
hocon::simple_config_origin::with_comments
shared_origin with_comments(std::vector< std::string > comments) const override
Returns a.
hocon::config_origin
Represents the origin (such as filename and line number) of a config_value for use in error messages.
Definition: config_origin.hpp:31