/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2016 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * * without restriction, including without limitation the rights to use, copy, modify, * * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to the following * * conditions: * * * * The above copyright notice and this permission notice shall be included in all copies * * or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #ifndef __DOCUMENTATION_H__ #define __DOCUMENTATION_H__ #include #include #include #include #include #include #include #include #include namespace openspace { namespace documentation { struct TestResult { bool success; std::vector offenders; }; using Optional = ghoul::Boolean; struct Verifier { virtual TestResult operator()(const ghoul::Dictionary& dict, const std::string& key) const; virtual bool test(const ghoul::Dictionary& dict, const std::string& key) const; virtual std::string documentation() const = 0; }; struct DocumentationEntry { DocumentationEntry(std::string key, Verifier* t, std::string doc = "", Optional optional = Optional::No); std::string key; std::shared_ptr tester; bool optional; std::string documentation; }; using Documentation = std::vector; TestResult testSpecification(const Documentation& d, const ghoul::Dictionary& dictionary); std::string generateDocumentation(const Documentation& d); // General verifiers template struct TemplateVerifier : public Verifier { using Type = T; }; struct BoolVerifier : public TemplateVerifier { bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; }; struct DoubleVerifier : public TemplateVerifier { bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; }; struct IntVerifier : public TemplateVerifier { bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; }; struct StringVerifier : public TemplateVerifier { bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; }; struct TableVerifier : public TemplateVerifier { TableVerifier(Documentation d = {}); TestResult operator()(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; Documentation doc; }; // Operator Verifiers template struct LessVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be BoolVerifier"); static_assert(!std::is_base_of_v, "T cannot be StringVerifier"); static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); LessVerifier(typename T::Type value); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const; typename T::Type value; }; template struct LessEqualVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be BoolVerifier"); static_assert(!std::is_base_of_v, "T cannot be StringVerifier"); static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); LessEqualVerifier(typename T::Type value); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; typename T::Type value; }; template struct GreaterVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be BoolVerifier"); static_assert(!std::is_base_of_v, "T cannot be StringVerifier"); static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); GreaterVerifier(typename T::Type value); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; typename T::Type value; }; template struct GreaterEqualVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be BoolVerifier"); static_assert(!std::is_base_of_v, "T cannot be StringVerifier"); static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); GreaterEqualVerifier(typename T::Type value); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; typename T::Type value; }; template struct EqualVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); EqualVerifier(typename T::Type value); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; typename T::Type value; }; template struct UnequalVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); UnequalVerifier(typename T::Type value); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; typename T::Type value; }; // List Verifiers template struct InListVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); InListVerifier(std::vector values); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; std::vector values; }; template struct NotInListVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); NotInListVerifier(std::vector values); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; std::vector values; }; // Range Verifiers template struct InRangeVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be BoolVerifier"); static_assert(!std::is_base_of_v, "T cannot be StringVerifier"); static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); InRangeVerifier(typename T::Type lower, typename T::Type upper); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; typename T::Type lower; typename T::Type upper; }; template struct NotInRangeVerifier : public T { static_assert(!std::is_base_of_v, "T cannot be BoolVerifier"); static_assert(!std::is_base_of_v, "T cannot be StringVerifier"); static_assert(!std::is_base_of_v, "T cannot be TableVerifier"); NotInRangeVerifier(typename T::Type lower, typename T::Type upper); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; typename T::Type lower; typename T::Type upper; }; // Misc Verifiers template struct AnnotationVerifier : public T { AnnotationVerifier(std::string annotation); bool test(const ghoul::Dictionary& dict, const std::string& key) const override; std::string documentation() const override; std::string annotation; }; using IntLessVerifier = LessVerifier; using DoubleLessVerifier = LessVerifier; using IntLessEqualVerifier = LessEqualVerifier; using DoubleLessEqualVerifier = LessEqualVerifier; using IntGreaterVerifier = GreaterVerifier; using DoubleGreaterVerifier = GreaterVerifier; using IntGreaterEqualVerifier = GreaterEqualVerifier; using DoubleGreaterEqualVerifier = GreaterEqualVerifier; using BoolEqualVerifier = EqualVerifier; using IntEqualVerifier = EqualVerifier; using DoubleEqualVerifier = EqualVerifier; using StringEqualVerifier = EqualVerifier; using BoolUnequalVerifier = UnequalVerifier; using IntUnequalVerifier = UnequalVerifier; using DoubleUnequalVerifier = UnequalVerifier; using StringUnequalVerifier = UnequalVerifier; using BoolInListVerifier = InListVerifier; using IntInListVerifier = InListVerifier; using DoubleInListVerifier = InListVerifier; using StringInListVerifier = InListVerifier; using BoolNotInListVerifier = NotInListVerifier; using IntNotInListVerifier = NotInListVerifier; using DoubleNotInListVerifier = NotInListVerifier; using StringNotInListVerifier = NotInListVerifier; using IntInRangeVerifier = InRangeVerifier; using DoubleInRangeVerifier = InRangeVerifier; using IntNotInRangeVerifier = NotInRangeVerifier; using DoubleNotInRangeVerifier = NotInRangeVerifier; using BoolAnnotationVerifier = AnnotationVerifier; using IntAnnotationVerifier = AnnotationVerifier; using DoubleAnnotationVerifier = AnnotationVerifier; using StringAnnotationVerifier = AnnotationVerifier; using TableAnnotationVerifier = AnnotationVerifier; extern template struct LessVerifier; extern template struct LessVerifier; extern template struct LessEqualVerifier; extern template struct LessEqualVerifier; extern template struct GreaterVerifier; extern template struct GreaterVerifier; extern template struct GreaterEqualVerifier; extern template struct GreaterEqualVerifier; extern template struct EqualVerifier; extern template struct EqualVerifier; extern template struct EqualVerifier; extern template struct EqualVerifier; extern template struct UnequalVerifier; extern template struct UnequalVerifier; extern template struct UnequalVerifier; extern template struct UnequalVerifier; extern template struct InListVerifier; extern template struct InListVerifier; extern template struct InListVerifier; extern template struct InListVerifier; extern template struct NotInListVerifier; extern template struct NotInListVerifier; extern template struct NotInListVerifier; extern template struct NotInListVerifier; extern template struct InRangeVerifier; extern template struct InRangeVerifier; extern template struct NotInRangeVerifier; extern template struct NotInRangeVerifier; extern template struct AnnotationVerifier; extern template struct AnnotationVerifier; extern template struct AnnotationVerifier; extern template struct AnnotationVerifier; extern template struct AnnotationVerifier; } // namespace documentation } // namespace openspace #include "documentation.inl" #endif // __DOCUMENTATION_H__