// Copyright (C) 2024 Jérôme "SirLynix" 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 #include namespace Nz { class ParameterFileSection; class Stream; // TOOD: Move to NazaraUtils template concept Functor = IsFunctor_v; class NAZARA_CORE_API ParameterFile { friend ParameterFileSection; public: inline ParameterFile(Stream& stream); ParameterFile(const ParameterFile&) = delete; ParameterFile(ParameterFile&&) = delete; ~ParameterFile() = default; template void Parse(Args&&... args); ParameterFile& operator=(const ParameterFile&) = delete; ParameterFile& operator=(ParameterFile&&) = delete; struct Identifier { std::string value; }; struct List_t {}; struct OptionalBlock_t {}; static constexpr List_t List{}; static constexpr OptionalBlock_t OptionalBlock{}; private: using ValueHandler = std::function; struct KeyValue { std::string_view key; ValueHandler handler; }; struct ClosingCurlyBracket {}; struct EndOfStream {}; struct OpenCurlyBracket {}; struct String { std::string value; //< has to be a string because of text parsing }; using Token = std::variant; Token Advance(); void ConsumeChar(std::size_t count = 1); template void HandleInner(Args&&... args); Token& PeekToken(); char PeekCharacter(std::size_t advance = 1); template T& Peek(); template T Read(); template T ReadValue(); // Handlers template ValueHandler BuildBlockHandler(FixedVector* keyValues, T* value, Rest&&... rest); template ValueHandler BuildBlockHandler(FixedVector* keyValues, T&& handler, Rest&&... rest); template ValueHandler BuildBlockHandler(FixedVector* keyValues, void(O::* method)(Args...), O* object, Rest&&... rest); template ValueHandler BuildBlockHandler(FixedVector* keyValues, FunctionRef handler, Rest&&... rest); template void BuildKeyValues(FixedVector* keyValues, K&& key, Rest&&... rest); template ValueHandler GetSingleHandler(V&& value, Rest&&... rest); template static std::string_view BuildBlockKey(T&& key); template static constexpr bool ShouldIgnoreImpl = std::is_same_v || std::is_same_v; template static constexpr bool ShouldIgnore = ShouldIgnoreImpl>; std::size_t m_bufferOffset; std::string m_buffer; Stream& m_stream; Token m_nextToken; unsigned int m_currentLine; }; class ParameterFileSection { friend ParameterFile; public: ParameterFileSection(const ParameterFileSection&) = default; template void Block(Args&&... args); private: inline ParameterFileSection(ParameterFile& file); ParameterFile& m_file; }; } #include #endif // NAZARA_CORE_PARAMETERFILE_HPP