/***************************************************************************************** * * * 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. * ****************************************************************************************/ namespace std { std::string to_string(std::string value); } namespace openspace { namespace documentation { template LessVerifier::LessVerifier(typename T::Type value) : value(std::move(value)) { } template bool LessVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { return T::test(dict, key) && dict.value(key) < value; } template std::string LessVerifier::documentation() const { return T::documentation() + '\n' + "Less than: " + std::to_string(value); } template LessEqualVerifier::LessEqualVerifier(typename T::Type value) : value(std::move(value)) {} template bool LessEqualVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { return T::test(dict, key) && dict.value(key) <= value; } template std::string LessEqualVerifier::documentation() const { return T::documentation() + '\n' + "Less or equal to: " + std::to_string(value); } template GreaterVerifier::GreaterVerifier(typename T::Type value) : value(std::move(value)) {} template bool GreaterVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { return T::test(dict, key) && dict.value(key) > value; } template std::string GreaterVerifier::documentation() const { return T::documentation() + '\n' + "Greater than: " + std::to_string(value); } template GreaterEqualVerifier::GreaterEqualVerifier(typename T::Type value) : value(std::move(value)) {} template bool GreaterEqualVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { return T::test(dict, key) && dict.value(key) >= value; } template std::string GreaterEqualVerifier::documentation() const { return T::documentation() + '\n' + "Greater or equal to: " + std::to_string(value); } template EqualVerifier::EqualVerifier(typename T::Type value) : value(std::move(value)) {} template bool EqualVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { return T::test(dict, key) && dict.value(key) == value; } template std::string EqualVerifier::documentation() const { return T::documentation() + '\n' + "Equal to: " + std::to_string(value); } template UnequalVerifier::UnequalVerifier(typename T::Type value) : value(std::move(value)) {} template bool UnequalVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { return T::test(dict, key) && dict.value(key) != value; } template std::string UnequalVerifier::documentation() const { return T::documentation() + '\n' + "Unequal to: " + std::to_string(value); } template InListVerifier::InListVerifier(std::vector values) : values(std::move(values)) {} template bool InListVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { if (T::test(dict, key)) { typename T::Type value = dict.value(key); auto it = std::find(values.begin(), values.end(), value); return it != values.end(); } else { return false; } } template std::string InListVerifier::documentation() const { std::string result = T::documentation() + '\n' + "In list {"; std::stringstream s; std::copy(values.begin(), values.end(), std::ostream_iterator(s, ",")); std::string joined = s.str(); // We need to remove a trailing ',' at the end of the string result += joined.substr(0, joined.size() - 1); result += "}"; return result; } template NotInListVerifier::NotInListVerifier(std::vector values) : values(std::move(values)) {} template bool NotInListVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { if (T::test(dict, key)) { typename T::Type value = dict.value(key); auto it = std::find(values.begin(), values.end(), value); return it == values.end(); } else { return false; } } template std::string NotInListVerifier::documentation() const { std::string result = T::documentation() + '\n' + "Not in list {"; std::stringstream s; std::copy(values.begin(), values.end(), std::ostream_iterator(s, ",")); std::string joined = s.str(); // We need to remove a trailing ',' at the end of the string result += joined.substr(0, joined.size() - 1); result += "}"; return result; } template InRangeVerifier::InRangeVerifier(typename T::Type lower, typename T::Type upper) : lower(std::move(lower)) , upper(std::move(upper)) { ghoul_assert(lower <= upper, "Lower value must be smaller or equal to upper value"); } template bool InRangeVerifier::test(const ghoul::Dictionary& d, const std::string& key) const { if (T::test(d, key)) { typename T::Type val = d.value(key); return val >= lower && val <= upper; } else { return false; } } template std::string InRangeVerifier::documentation() const { return T::documentation() + '\n' + "In range: (" + std::to_string(lower) + "," + std::to_string(upper) + ")"; } template NotInRangeVerifier::NotInRangeVerifier(typename T::Type lower, typename T::Type upper) : lower(std::move(lower)) , upper(std::move(upper)) { ghoul_assert(lower <= upper, "Lower value must be smaller or equal to upper value"); } template bool NotInRangeVerifier::test(const ghoul::Dictionary& d, const std::string& k) const { if (T::test(d, k)) { typename T::Type val = d.value(k); return !(val >= lower && val <= upper); } else { return false; } } template std::string NotInRangeVerifier::documentation() const { return T::documentation() + '\n' + "Not in range: (" + std::to_string(lower) + "," + std::to_string(upper) + ")"; } template AnnotationVerifier::AnnotationVerifier(std::string annotation) : annotation(std::move(annotation)) {} template bool AnnotationVerifier::test(const ghoul::Dictionary& dict, const std::string& key) const { return T::test(dict, key); } template std::string AnnotationVerifier::documentation() const { return T::documentation() + '\n' + annotation; } } // namespace documentation } // namespace openspace