// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #include #include #include #include // Used by the config options #include #include #include namespace anki { class ConfigSet::Option { public: enum Type { NONE, FLOAT, UNSIGNED, STRING }; String m_name; String m_helpMsg; String m_str; F64 m_float = 0.0; F64 m_minFloat = 0.0; F64 m_maxFloat = 0.0; U64 m_unsigned = 0; U64 m_minUnsigned = 0; U64 m_maxUnsigned = 0; Type m_type = NONE; Option() = default; Option(const Option&) = delete; // Non-copyable Option(Option&& b) : m_name(std::move(b.m_name)) , m_helpMsg(std::move(b.m_helpMsg)) , m_str(std::move(b.m_str)) , m_float(b.m_float) , m_minFloat(b.m_minFloat) , m_maxFloat(b.m_maxFloat) , m_unsigned(b.m_unsigned) , m_minUnsigned(b.m_minUnsigned) , m_maxUnsigned(b.m_maxUnsigned) , m_type(b.m_type) { } ~Option() = default; Option& operator=(const Option&) = delete; // Non-copyable Option& operator=(Option&& b) = delete; }; ConfigSet::ConfigSet() { m_alloc = HeapAllocator(allocAligned, nullptr); #define ANKI_CONFIG_OPTION(name, ...) newOption(ANKI_STRINGIZE(name), __VA_ARGS__); #include #include #include #include #include #undef ANKI_CONFIG_OPTION } ConfigSet::~ConfigSet() { for(Option& o : m_options) { o.m_name.destroy(m_alloc); o.m_str.destroy(m_alloc); o.m_helpMsg.destroy(m_alloc); } m_options.destroy(m_alloc); } ConfigSet& ConfigSet::operator=(const ConfigSet& b) { m_alloc = b.m_alloc; // Not a copy but we are fine for(const Option& o : b.m_options) { Option newO; newO.m_name.create(m_alloc, o.m_name.toCString()); if(o.m_type == Option::STRING) { newO.m_str.create(m_alloc, o.m_str.toCString()); } newO.m_float = o.m_float; newO.m_minFloat = o.m_minFloat; newO.m_maxFloat = o.m_maxFloat; newO.m_unsigned = o.m_unsigned; newO.m_minUnsigned = o.m_minUnsigned; newO.m_maxUnsigned = o.m_maxUnsigned; newO.m_type = o.m_type; m_options.emplaceBack(m_alloc, std::move(newO)); } return *this; } ConfigSet::Option* ConfigSet::tryFind(CString optionName) { for(List