4 #include "config_mergeable.hpp"
5 #include "config_origin.hpp"
6 #include "config_object.hpp"
7 #include "config_resolve_options.hpp"
8 #include "config_value.hpp"
9 #include "config_list.hpp"
10 #include "config_exception.hpp"
16 #include <leatherman/locale/locale.hpp>
20 enum class time_unit { NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS };
248 virtual shared_object
root()
const;
258 std::shared_ptr<const config_mergeable>
with_fallback(std::shared_ptr<const config_mergeable> other)
const override;
448 virtual void check_valid(shared_config reference, std::vector<std::string> restrict_to_paths)
const;
542 virtual std::set<std::pair<std::string, std::shared_ptr<const config_value>>>
entry_set()
const;
567 virtual bool get_bool(std::string
const&
path)
const;
568 virtual int get_int(std::string
const&
path)
const;
569 virtual int64_t get_long(std::string
const&
path)
const;
570 virtual double get_double(std::string
const&
path)
const;
571 virtual std::string get_string(std::string
const&
path)
const;
572 virtual std::shared_ptr<const config_object> get_object(std::string
const&
path)
const;
573 virtual shared_config get_config(std::string
const&
path)
const;
574 virtual unwrapped_value get_any_ref(std::string
const&
path)
const;
575 virtual std::shared_ptr<const config_value> get_value(std::string
const&
path)
const;
578 std::vector<T> get_homogeneous_unwrapped_list(std::string
const&
path)
const {
579 auto list = boost::get<std::vector<unwrapped_value>>(get_list(
path)->unwrapped());
580 std::vector<T> T_list;
581 for (
auto item : list) {
583 T_list.push_back(boost::get<T>(item));
584 }
catch (boost::bad_get &ex) {
585 throw config_exception(leatherman::locale::format(
"The list did not contain only the desired type."));
591 virtual shared_list get_list(std::string
const& path)
const;
592 virtual std::vector<bool> get_bool_list(std::string
const& path)
const;
593 virtual std::vector<int> get_int_list(std::string
const& path)
const;
594 virtual std::vector<int64_t> get_long_list(std::string
const& path)
const;
595 virtual std::vector<double> get_double_list(std::string
const& path)
const;
596 virtual std::vector<std::string> get_string_list(std::string
const& path)
const;
597 virtual std::vector<shared_object> get_object_list(std::string
const& path)
const;
598 virtual std::vector<shared_config> get_config_list(std::string
const& path)
const;
660 virtual shared_config
at_key(std::string
const& key)
const;
677 virtual shared_config
with_value(std::string
const&
path, std::shared_ptr<const config_value>
value)
const;
681 config(shared_object
object);
683 static shared_object env_variables_as_config_object();
686 shared_value find(std::string
const& path_expression,
config_value::type expected)
const;
689 shared_config at_key(shared_origin origin, std::string
const& key)
const;
691 static shared_includer default_includer();
706 static duration parse_duration(std::string input, shared_origin origin_for_exception, std::string path_for_exception);
708 static duration convert(int64_t number, time_unit units);
709 static duration convert(
double number, time_unit units);
710 static time_unit get_units(std::string
const& unit_string);
713 shared_value has_path_peek(std::string
const& path_expression)
const;
714 shared_value peek_path(
path desired_path)
const;
716 static void find_paths(std::set<std::pair<std::string, std::shared_ptr<const config_value>>>& entries,
717 path parent, shared_object obj);
719 static shared_value find_key(shared_object
self, std::string
const& key,
721 static shared_value find_key_or_null(shared_object
self, std::string
const& key,
723 static shared_value find_or_null(shared_object
self,
path desired_path,
725 shared_value find_or_null(std::string
const& path_expression,
config_value::type expected)
const;
728 shared_object _object;
732 std::vector<int64_t> config::get_homogeneous_unwrapped_list(std::string
const&
path)
const;
A set of options related to parsing.
An opaque handle to something that can be parsed, obtained from config_include_context.
A set of options related to resolving substitutions.
An immutable value, following the JSON type schema.
type
The type of a configuration value (following the JSON type schema).
An immutable map from config paths to config values.
virtual shared_config with_only_path(std::string const &path) const
Clone the config with only the given path (and its children) retained; all sibling paths are removed.
virtual shared_config with_value(std::string const &path, std::shared_ptr< const config_value > value) const
Returns a.
virtual bool is_resolved() const
Checks whether the config is completely resolved.
virtual shared_config at_key(std::string const &key) const
Places the config inside a.
virtual bool get_is_null(std::string const &path) const
Checks whether a value is set to null at the given path, but throws an exception if the value is enti...
static shared_config parse_file_any_syntax(std::string file_basename, config_parse_options options)
Parses a file with a flexible extension.
std::shared_ptr< const config_mergeable > with_fallback(std::shared_ptr< const config_mergeable > other) const override
Returns a new value computed by merging this value with another, with keys in this value "winning" ov...
virtual shared_origin origin() const
Gets the origin of the.
virtual std::set< std::pair< std::string, std::shared_ptr< const config_value > > > entry_set() const
Returns the set of path-value pairs, excluding any null values, found by recursing the root object.
virtual bool is_empty() const
Returns true if the.
virtual shared_config without_path(std::string const &path) const
Clone the config with the given path removed.
shared_value to_fallback_value() const override
Converts a config to its root object and a config_value to itself.
virtual shared_config resolve_with(shared_config source, config_resolve_options options) const
Like config#resolve_with(config) but allows you to specify non-default options.
virtual int64_t get_duration(std::string const &path, time_unit unit) const
Gets a value as an integer number of the specified units.
virtual bool has_path_or_null(std::string const &path) const
Checks whether a value is present at the given path, even if the value is null.
virtual shared_object root() const
Gets the.
virtual shared_config at_path(std::string const &path) const
Places the config inside another.
virtual shared_config resolve(config_resolve_options options) const
Like config#resolve() but allows you to specify non-default options.
virtual bool has_path(std::string const &path) const
Checks whether a value is present and non-null at the given path.
static shared_config parse_string(std::string s, config_parse_options options)
Parses a string (which should be valid HOCON or JSON by default, or the syntax specified in the optio...
virtual void check_valid(shared_config reference, std::vector< std::string > restrict_to_paths) const
Validates this config against a reference config, throwing an exception if it is invalid.
static shared_config parse_string(std::string s)
Parses a string (which should be valid HOCON or JSON).
static shared_config parse_file_any_syntax(std::string file_basename)
Like parseFileAnySyntax(File,ConfigParseOptions) but always uses default parse options.
virtual shared_config resolve_with(shared_config source) const
Like config#resolve() except that substitution values are looked up in the given source,...
virtual shared_config resolve() const
Returns a replacement config with all substitutions (the ${foo.bar} syntax, see the spec) resolved.
Factory for creating config_document instances.
std::pair< int64_t, int > duration
A duration represented as a 64-bit integer of seconds plus a 32-bit number of nanoseconds representin...
bool operator==(config_document const &lhs, config_document const &rhs)
Config documents compare via rendered strings.
All exceptions thrown by the library are subclasses of config_exception.