// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_CORE_PARAMETERFILE_HPP #define NAZARA_CORE_PARAMETERFILE_HPP #include #include #include #include #include #include #include #include #include namespace Nz { class Stream; class NAZARA_CORE_API ParameterFile { public: inline ParameterFile(Stream& stream); ParameterFile(const ParameterFile&) = delete; ParameterFile(ParameterFile&&) = delete; ~ParameterFile() = default; template void Block(Args&&... args); template void Handle(Args&&... args); ParameterFile& operator=(const ParameterFile&) = delete; ParameterFile& operator=(ParameterFile&&) = delete; struct Keyword { std::string str; }; struct Array_t {}; struct OptionalBlock_t {}; static constexpr inline Array_t Array{}; static constexpr inline OptionalBlock_t OptionalBlock{}; private: using ValueHandler = std::function; struct KeyValue { std::string_view key; ValueHandler handler; }; template static std::string_view BuildBlockKey(T&& key); template static ValueHandler BuildBlockHandler(ParameterFile& file, ValueHandler handler); template static ValueHandler BuildBlockHandler(ParameterFile& file, T* value); template static ValueHandler BuildBlockHandler(ParameterFile& file, T&& handler, std::enable_if_t>* = nullptr); template static ValueHandler BuildBlockHandler(ParameterFile& file, FunctionRef handler); template static void BuildKeyValues(ParameterFile& file, FixedVector& keyValues, K&& key, V&& value, Rest&&... rest); template static ValueHandler GetSingleHandler(ParameterFile& file, V&& value, Rest&&... rest); template void HandleInner(std::string_view listEnd, Args&&... args); template static T ReadValue(ParameterFile& file); template static constexpr bool ShouldIgnoreImpl = std::is_same_v || std::is_same_v; template static constexpr bool ShouldIgnore = ShouldIgnoreImpl>>; bool EnsureLine(bool peek = false); std::string ReadKeyword(bool peek = false); std::string ReadString(); std::string m_currentLine; Stream& m_stream; }; } #include #endif // NAZARA_CORE_PARAMETERFILE_HPP