.. _program_listing_file_uconfig_Objects.h: Program Listing for File Objects.h ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``uconfig/Objects.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "detail/detail.h" #include #include #include #include #include #include namespace uconfig { struct Error: public std::runtime_error { using std::runtime_error::runtime_error; }; struct ParseError: public Error { using Error::Error; }; struct EmitError: public Error { using Error::Error; }; class Object { public: // template // using iface_type; virtual ~Object() = default; virtual bool Initialized() const noexcept = 0; virtual bool Optional() const noexcept = 0; virtual void Validate() const {}; }; template class Config: public Object { public: template using iface_type = ConfigIface; template friend class ConfigIface; Config(bool optional = false); Config(const Config& other); Config& operator=(const Config& other); Config(Config&& other) noexcept; Config& operator=(Config&& other) noexcept; virtual ~Config() = default; template bool Parse(const F& parser, const std::string& path, const typename F::source_type* source, bool throw_on_fail = true); template void Emit(const F& emitter, const std::string& path, typename F::dest_type* destination, bool throw_on_fail = true); virtual bool Initialized() const noexcept override; virtual bool Optional() const noexcept override; protected: virtual void Init(const std::string& config_path) = 0; template void Register(const std::string& element_path, T* element) noexcept; private: void Reset() noexcept; template void SetFormat() noexcept; template std::vector>>& Interfaces() noexcept; private: bool optional_ = false; std::unordered_set elements_; std::unordered_set register_formats_; std::tuple>>...> interfaces_; }; template class Variable: public Object { public: template using iface_type = VariableIface; template friend class VariableIface; Variable(); Variable(T&& init_value); Variable(const T& init_value); Variable(const Variable&) = default; Variable& operator=(const Variable&) = default; Variable(Variable&& other) noexcept = default; Variable& operator=(Variable&& other) noexcept = default; Variable& operator=(T&& other) noexcept; virtual ~Variable() = default; virtual bool Initialized() const noexcept override; virtual bool Optional() const noexcept override; T& Get(); const T& Get() const; T& operator*(); const T& operator*() const; T* operator->(); const T* operator->() const; explicit operator T&(); explicit operator const T&() const; #ifndef DOXYGEN_SHOULD_SKIP_THIS /* enable left and right-handed comparisons */ template friend bool operator==(const Variable& lhs, const Variable& rhs); template ::value, bool>> friend bool operator==(const U& lhs, const Variable& rhs); template ::value, bool>> friend bool operator==(const Variable& lhs, const U& rhs); template friend bool operator!=(const Variable& lhs, const Variable& rhs); template ::value, bool>> friend bool operator!=(const U& lhs, const Variable& rhs); template ::value, bool>> friend bool operator!=(const Variable& lhs, const U& rhs); template friend bool operator>(const U& lhs, const Variable& rhs); template friend bool operator>(const Variable& lhs, const U& rhs); template friend bool operator<(const U& lhs, const Variable& rhs); template friend bool operator<(const Variable& lhs, const U& rhs); template friend bool operator>=(const U& lhs, const Variable& rhs); template friend bool operator>=(const Variable& lhs, const U& rhs); template friend bool operator<=(const U& lhs, const Variable& rhs); template friend bool operator<=(const Variable& lhs, const U& rhs); #endif /* DOXYGEN_SHOULD_SKIP_THIS */ protected: bool optional_ = false; std::optional value_ = std::nullopt; }; template class Vector: public Variable> { public: template using iface_type = VectorIface; template friend class VectorIface; Vector(bool optional = false); Vector(std::vector&& init_value); Vector(const std::vector& init_value); Vector(const Vector&) = default; Vector& operator=(const Vector&) = default; Vector(Vector&& other) noexcept = default; Vector& operator=(Vector&& other) noexcept = default; Vector& operator=(std::vector&& vector) noexcept; virtual ~Vector() = default; T& operator[](std::size_t pos); const T& operator[](std::size_t pos) const; #ifndef DOXYGEN_SHOULD_SKIP_THIS // operator== for Vector> and std::vector. template friend bool operator==(const Vector>& lhs, const std::vector& rhs); #endif /* DOXYGEN_SHOULD_SKIP_THIS */ }; } // namespace uconfig #include "impl/Objects.ipp"