17 #ifndef COM_BORA_SOFTWARE__BALAU_APPLICATION__ENVIRONMENT_PROPERTIES 18 #define COM_BORA_SOFTWARE__BALAU_APPLICATION__ENVIRONMENT_PROPERTIES 22 #include <Balau/Application/Impl/BindingMap.hpp> 33 class EnvironmentConfigurationBuilder;
69 public: std::string_view
getName()
const {
78 public: Impl::BindingKey
getKey()
const {
89 public:
template <
typename ValueT>
bool isValue()
const {
90 return key == Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Value, ValueT>), key.name);
100 public:
template <
typename BaseT>
bool isUnique()
const {
101 return key == Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Unique, BaseT, std::default_delete<BaseT>>), key.name);
111 return key == Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Shared, EnvironmentProperties>), key.name);
126 public:
template <
typename ValueT> ValueT
getValue()
const {
127 return owner.getValue<ValueT>(
128 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Value, ValueT>), key.name)
144 public:
template <
typename ValueT> ValueT
getValue(
const ValueT & defaultValue)
const {
145 return owner.getValue<ValueT>(
146 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Value, ValueT>), key.name), defaultValue
162 public:
template <
typename BaseT> std::unique_ptr<BaseT>
getUnique()
const {
163 return owner.getUnique<BaseT>(
164 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Unique, BaseT, std::default_delete<BaseT>>), key.name)
180 public:
template <
typename BaseT> std::unique_ptr<BaseT>
getUnique(std::unique_ptr<BaseT> && defaultValue)
const {
181 return owner.getUnique<BaseT>(
182 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Unique, BaseT, std::default_delete<BaseT>>), key.name)
183 , std::move(defaultValue)
197 return owner.getComposite(
198 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Shared, EnvironmentProperties>), key.name)
211 return owner.getCompositeOrNull(
212 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Shared, EnvironmentProperties>), key.name)
223 private:
const Impl::BindingKeyView key;
235 , mapIterator(copy.mapIterator) {}
241 mapIterator = copy.mapIterator;
265 public:
Item operator * ()
const {
266 return Item(owner, Impl::BindingKeyView(mapIterator->key));
273 return mapIterator == rhs.mapIterator;
279 public:
bool operator != (
const iterator & rhs)
const {
280 return mapIterator != rhs.mapIterator;
287 , mapIterator(mapIterator_) {}
290 private: Impl::BindingMap::ConstIterator mapIterator;
307 public:
template <
typename ValueT>
309 const Impl::BindingKeyView keyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Value, ValueT>), name);
310 return bindings->hasBinding(keyView);
320 public:
template <
typename BaseT>
322 const Impl::BindingKeyView keyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Unique, BaseT, std::default_delete<BaseT>>), name);
323 return bindings->hasBinding(keyView);
333 const Impl::BindingKeyView keyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Shared, EnvironmentProperties>), name);
334 return bindings->hasBinding(keyView);
349 public:
template <
typename ValueT> ValueT
getValue(std::string_view name)
const {
350 return getValue<ValueT>(
351 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Value, ValueT>), name)
367 public:
template <
typename ValueT> ValueT
getValue(std::string_view name,
const ValueT & defaultValue)
const {
368 return getValue<ValueT>(
369 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Value, ValueT>), name), defaultValue
385 public:
template <
typename BaseT> std::unique_ptr<BaseT>
getUnique(std::string_view name)
const {
386 return getUnique<BaseT>(
387 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Unique, BaseT, std::default_delete<BaseT>>), name)
403 public:
template <
typename BaseT> std::unique_ptr<BaseT>
getUnique(std::string_view name, std::unique_ptr<BaseT> && defaultValue)
const {
404 return getUnique<BaseT>(
405 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Unique, BaseT, std::default_delete<BaseT>>), name), defaultValue
418 public: std::shared_ptr<EnvironmentProperties>
getComposite(std::string_view name)
const {
420 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Shared, EnvironmentProperties>), name)
433 return getCompositeOrNull(
434 Impl::BindingKeyView(
typeid(Impl::BindingKeyType<Impl::BindingMetaType::Shared, EnvironmentProperties>), name)
442 return iterator(*
this, bindings->begin());
449 return iterator(*
this, bindings->end());
455 public: const_iterator
begin()
const {
456 return const_iterator(*
this, bindings->begin());
462 public: const_iterator
end()
const {
463 return const_iterator(*
this, bindings->end());
470 return bindings->begin() == bindings->end();
479 : bindings(
std::move(bindings_)) {}
487 : bindings(new Impl::BindingMap()) {}
492 friend class Impl::EnvironmentConfigurationBuilder;
494 private:
template <
typename ValueT> ValueT getValue(
const Impl::BindingKeyView & keyView)
const {
495 const auto * binding = bindings->find(keyView);
497 if (binding !=
nullptr) {
498 return static_cast<const Impl::AbstractValueBinding<ValueT> *
>(binding->get())->
get(
nullptr);
504 private:
template <
typename ValueT> ValueT getValue(
const Impl::BindingKeyView & keyView,
const ValueT & defaultValue)
const {
505 const auto * binding = bindings->find(keyView);
507 if (binding !=
nullptr) {
508 return static_cast<const Impl::AbstractValueBinding<ValueT> *
>(binding->get())->
get(
nullptr);
514 private:
template <
typename BaseT,
typename DeleterT = std::default_delete<BaseT>> std::unique_ptr<BaseT> getUnique(
const Impl::BindingKeyView & keyView)
const {
515 const auto * binding = bindings->find(keyView);
517 if (binding !=
nullptr) {
518 return static_cast<const Impl::AbstractUniquePtrBinding<BaseT, DeleterT> *
>(binding->get())->
get(
nullptr);
524 private:
template <
typename BaseT,
typename DeleterT = std::default_delete<BaseT>> std::unique_ptr<BaseT> getUnique(
const Impl::BindingKeyView & keyView, std::unique_ptr<BaseT> && defaultValue)
const {
525 const auto * binding = bindings->find(keyView);
527 if (binding !=
nullptr) {
528 return static_cast<const Impl::AbstractUniquePtrBinding<BaseT, DeleterT> *
>(binding->get())->
get(
nullptr);
530 return std::move(defaultValue);
534 private: std::shared_ptr<EnvironmentProperties> getComposite(
const Impl::BindingKeyView & keyView)
const {
535 const auto * binding = bindings->find(keyView);
537 if (binding !=
nullptr) {
540 return static_cast<const Impl::AbstractSharedPtrBinding<EnvironmentProperties> *
>(binding->get())->
get(
nullptr);
546 private: std::shared_ptr<EnvironmentProperties> getCompositeOrNull(
const Impl::BindingKeyView & keyView)
const {
547 const auto * binding = bindings->find(keyView);
549 if (binding !=
nullptr) {
552 return static_cast<const Impl::AbstractSharedPtrBinding<EnvironmentProperties> *
>(binding->get())->
get(
nullptr);
554 return std::shared_ptr<EnvironmentProperties>();
558 private:
const std::unique_ptr<const Impl::BindingMap> bindings;
563 #endif // COM_BORA_SOFTWARE__BALAU_APPLICATION__ENVIRONMENT_PROPERTIES bool hasUnique(std::string_view name) const
Returns true if the composite property has a unique pointer binding matching the specified type and n...
Definition: EnvironmentProperties.hpp:321
bool operator==(const BalauException &lhs, const BalauException &rhs)
Base class comparison function for Balau exceptions.
Definition: BalauException.hpp:112
const_iterator begin() const
Get a const iterator positioned at the beginning of the environment properties list.
Definition: EnvironmentProperties.hpp:455
bool empty() const
Returns true if the environment properties object is empty.
Definition: EnvironmentProperties.hpp:469
A file on the local file system.
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
ValueT getValue() const
Get the non-polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:126
bool isValue() const
Returns true if the item is a value binding matching the specified type and name. ...
Definition: EnvironmentProperties.hpp:89
std::unique_ptr< BaseT > getUnique() const
Get the polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:162
ValueT getValue(const ValueT &defaultValue) const
Get the non-polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:144
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
Impl::BindingKey getKey() const
Get the key of the item.
Definition: EnvironmentProperties.hpp:78
A hierarchical environment properties holder created from a composite property.
Definition: EnvironmentProperties.hpp:59
ValueT getValue(std::string_view name) const
Get a non-polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:349
Environment configurations specify typed and untyped environment injector bindings.
Definition: EnvironmentConfiguration.hpp:97
std::unique_ptr< BaseT > getUnique(std::string_view name) const
Get a polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:385
The EnvironmentProperties iterator.
Definition: EnvironmentProperties.hpp:229
iterator end()
Get an iterator positioned at the end of the environment properties list.
Definition: EnvironmentProperties.hpp:448
std::string_view getName() const
Get the name of the item.
Definition: EnvironmentProperties.hpp:69
EnvironmentProperties(std::unique_ptr< const Impl::BindingMap > &&bindings_)
Create an environment properties instance.
Definition: EnvironmentProperties.hpp:478
bool hasComposite(std::string_view name) const
Returns true if the composite property has a child composite binding with the specified name...
Definition: EnvironmentProperties.hpp:332
std::shared_ptr< EnvironmentProperties > getComposite() const
Get the environment properties instance with the specified name.
Definition: EnvironmentProperties.hpp:196
std::shared_ptr< EnvironmentProperties > getCompositeOrNull() const
Get the environment properties instance with the specified name.
Definition: EnvironmentProperties.hpp:210
std::shared_ptr< EnvironmentProperties > getCompositeOrNull(std::string_view name) const
Get a child environment properties instance with the specified name.
Definition: EnvironmentProperties.hpp:432
const_iterator end() const
Get a const iterator positioned at the end of the environment properties list.
Definition: EnvironmentProperties.hpp:462
std::shared_ptr< EnvironmentProperties > getComposite(std::string_view name) const
Get a child environment properties instance with the specified name.
Definition: EnvironmentProperties.hpp:418
bool hasValue(std::string_view name) const
Returns true if the composite property has a value binding matching the specified type and name...
Definition: EnvironmentProperties.hpp:308
EnvironmentProperties()
Create an empty environment properties instance.
Definition: EnvironmentProperties.hpp:486
bool isUnique() const
Returns true if the item is a unique pointer binding matching the specified type and name...
Definition: EnvironmentProperties.hpp:100
std::unique_ptr< BaseT > getUnique(std::string_view name, std::unique_ptr< BaseT > &&defaultValue) const
Get a polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:403
Instances of the Item class are returned from iterators.
Definition: EnvironmentProperties.hpp:63
Assertion utilities for development purposes.
ValueT getValue(std::string_view name, const ValueT &defaultValue) const
Get a non-polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:367
std::unique_ptr< BaseT > getUnique(std::unique_ptr< BaseT > &&defaultValue) const
Get the polymorphic value of the specified type and name.
Definition: EnvironmentProperties.hpp:180
iterator(const iterator ©)
Create an iterator by copying the supplied iterator.
Definition: EnvironmentProperties.hpp:233
iterator const_iterator
The const iterator of EnvironmentProperties is the same as a non-const one.
Definition: EnvironmentProperties.hpp:296
bool isComposite() const
Returns true if the item is a composite binding with the specified name.
Definition: EnvironmentProperties.hpp:110
iterator begin()
Get an iterator positioned at the beginning of the environment properties list.
Definition: EnvironmentProperties.hpp:441
An injector binding candidate created via the injector configuration.
Balau exceptions for the injector framework.
Pre-defined universal from-string functions.
Thrown when no binding is found in the injector.
Definition: InjectorExceptions.hpp:75