/** * OpenAPI Petstore * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * * The version of the OpenAPI document: 1.0.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ /* * Helpers.h * * This is the helper class for models and primitives */ #ifndef Helpers_H_ #define Helpers_H_ #include #include #include #include #include namespace org::openapitools::server::helpers { class ValidationException : public std::runtime_error { public: explicit ValidationException(const std::string& what) : std::runtime_error(what) { } ~ValidationException() override = default; }; /// /// Validate a string against the full-date definition of RFC 3339, section 5.6. /// bool validateRfc3339_date(const std::string& str); /// /// Validate a string against the date-time definition of RFC 3339, section 5.6. /// bool validateRfc3339_date_time(const std::string& str); namespace sfinae_helpers { struct NoType {}; template NoType operator==(const T1&, const T2&); template class EqualsOperatorAvailable { public: enum { value = !std::is_same< decltype(std::declval() == std::declval()), NoType >::value }; }; } // namespace sfinae_helpers /// /// Determine if the given vector only has unique elements. T must provide the == operator. /// template bool hasOnlyUniqueItems(const std::vector& vec) { static_assert(sfinae_helpers::EqualsOperatorAvailable::value, "hasOnlyUniqueItems cannot be called, passed template type does not provide == operator."); if (vec.size() <= 1) { return true; } // Compare every element of vec to every other element of vec. // This isn't an elegant way to do this, since it's O(n^2), // but it's the best solution working only with the == operator. // This could be greatly improved if our models provided a valid hash // and/or the < operator for (size_t i = 0; i < vec.size() - 1; i++) { for (size_t j = i + 1; j < vec.size(); j++) { if (vec[i] == vec[j]) { return false; } } } return true; } std::string toStringValue(const std::string &value); std::string toStringValue(const int32_t value); std::string toStringValue(const int64_t value); std::string toStringValue(const bool value); std::string toStringValue(const float value); std::string toStringValue(const double value); bool fromStringValue(const std::string &inStr, std::string &value); bool fromStringValue(const std::string &inStr, int32_t &value); bool fromStringValue(const std::string &inStr, int64_t &value); bool fromStringValue(const std::string &inStr, bool &value); bool fromStringValue(const std::string &inStr, float &value); bool fromStringValue(const std::string &inStr, double &value); template bool fromStringValue(const std::vector &inStr, std::vector &value){ try{ for(auto & item : inStr){ T itemValue; if(fromStringValue(item, itemValue)){ value.push_back(itemValue); } } } catch(...){ return false; } return value.size() > 0; } template bool fromStringValue(const std::string &inStr, std::vector &value, char separator = ','){ std::vector inStrings; std::istringstream f(inStr); std::string s; while (std::getline(f, s, separator)) { inStrings.push_back(s); } return fromStringValue(inStrings, value); } } // namespace org::openapitools::server::helpers #endif // Helpers_H_