.. _program_listing_file_src_microsoft_shortlist_utils_ParameterTree.h: Program Listing for File ParameterTree.h ======================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/microsoft/shortlist/utils/ParameterTree.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include #include #include #include "microsoft/shortlist/utils/StringUtils.h" namespace marian { namespace quicksand { class ParameterTree { private: enum ParameterType { PARAM_TYPE_INT32, PARAM_TYPE_INT64, PARAM_TYPE_UINT64, PARAM_TYPE_FLOAT, PARAM_TYPE_DOUBLE, PARAM_TYPE_BOOL, PARAM_TYPE_STRING }; class RegisteredParam { private: std::string m_name; ParameterType m_type; void * m_data; public: RegisteredParam() {} RegisteredParam(const std::string& name, ParameterType type, void * data) { m_name = name; m_type = type; m_data = data; } const std::string& Name() const {return m_name;} const ParameterType& Type() const {return m_type;} void * Data() const {return m_data;} }; static std::shared_ptr m_empty_tree; std::string m_name; std::string m_text; std::vector< std::shared_ptr > m_children; std::unordered_set m_registered_param_names; std::vector m_registered_params; public: ParameterTree(); ParameterTree(const std::string& name); ~ParameterTree(); inline const std::string& Text() const { return m_text; } inline void SetText(const std::string& text) { m_text = text; } inline const std::string& Name() const { return m_name; } inline void SetName(const std::string& name) { m_name = name; } void Clear(); void ReplaceVariables( const std::unordered_map& vars, bool error_on_unknown_vars = true); void RegisterInt32(const std::string& name, int32_t * param); void RegisterInt64(const std::string& name, int64_t * param); void RegisterFloat(const std::string& name, float * param); void RegisterDouble(const std::string& name, double * param); void RegisterBool(const std::string& name, bool * param); void RegisterString(const std::string& name, std::string * param); static std::shared_ptr FromBinaryReader(const void*& current); void SetRegisteredParams(); int32_t GetInt32Req(const std::string& name) const; int64_t GetInt64Req(const std::string& name) const; uint64_t GetUInt64Req(const std::string& name) const; double GetDoubleReq(const std::string& name) const; float GetFloatReq(const std::string& name) const; std::string GetStringReq(const std::string& name) const; bool GetBoolReq(const std::string& name) const; int32_t GetInt32Or(const std::string& name, int32_t defaultValue) const; int64_t GetInt64Or(const std::string& name, int64_t defaultValue) const; uint64_t GetUInt64Or(const std::string& name, uint64_t defaultValue) const; std::string GetStringOr(const std::string& name, const std::string& defaultValue) const; double GetDoubleOr(const std::string& name, double defaultValue) const; float GetFloatOr(const std::string& name, float defaultValue) const; bool GetBoolOr(const std::string& name, bool defaultValue) const; std::vector GetFileListReq(const std::string& name) const; std::vector GetFileListOptional(const std::string& name) const; std::vector GetStringListReq(const std::string& name, const std::string& sep = " ") const; std::vector GetStringListOptional(const std::string& name, const std::string& sep = " ") const; std::shared_ptr GetChildReq(const std::string& name) const; std::shared_ptr GetChildOrEmpty(const std::string& name) const; std::vector< std::shared_ptr > GetChildren(const std::string& name) const; inline const std::vector< std::shared_ptr >& GetChildren() const { return m_children; } void ReadBinary(const void*& current); void AddParam(const std::string& name, const std::string& text); template void AddParam(const std::string& name, const T& obj); void SetParam(const std::string& name, const std::string& text); template void SetParam(const std::string& name, const T& obj); void AddChild(std::shared_ptr child); std::string ToString() const; bool HasChild(const std::string& name) const; bool HasParam(const std::string& name) const; std::shared_ptr Clone() const; void Merge(const ParameterTree& other); private: void ReplaceVariablesInternal( const std::unordered_map& vars, bool error_on_unknown_vars); void RegisterItemInternal(const std::string& name, ParameterType type, void * param); const std::string * GetParamInternal(const std::string& name) const; void ToStringInternal(int32_t depth, std::ostream& ss) const; }; template void ParameterTree::AddParam(const std::string& name, const T& obj) { AddParam(name, StringUtils::ToString(obj)); } template void ParameterTree::SetParam(const std::string& name, const T& obj) { SetParam(name, StringUtils::ToString(obj)); } } // namespace quicksand } // namespace marian