/** * Tribufu API * REST API to access Tribufu services. * * The version of the OpenAPI document: 1.1.0 * Contact: contact@tribufu.com * * NOTE: This class is auto generated by OpenAPI-Generator 7.14.0-SNAPSHOT. * https://openapi-generator.tech * Do not edit the class manually. */ /* * ModelBase.h * * This is the base class for all model classes */ #ifndef TRIBUFU_MODELS_ModelBase_H_ #define TRIBUFU_MODELS_ModelBase_H_ #include "tribufu++/HttpContent.h" #include "tribufu++/MultipartFormData.h" #include #include #include #include #include namespace tribufu { namespace models { class ModelBase { public: ModelBase(); virtual ~ModelBase(); virtual void validate() = 0; virtual web::json::value toJson() const = 0; virtual bool fromJson(const web::json::value &json) = 0; virtual void toMultipart(std::shared_ptr multipart, const utility::string_t &namePrefix) const = 0; virtual bool fromMultiPart(std::shared_ptr multipart, const utility::string_t &namePrefix) = 0; virtual bool isSet() const; static utility::string_t toString(const bool val); static utility::string_t toString(const float val); static utility::string_t toString(const double val); static utility::string_t toString(const int32_t val); static utility::string_t toString(const int64_t val); static utility::string_t toString(const utility::string_t &val); static utility::string_t toString(const utility::datetime &val); static utility::string_t toString(const web::json::value &val); static utility::string_t toString(const std::shared_ptr &val); template static utility::string_t toString(const std::shared_ptr &val); template static utility::string_t toString(const std::vector &val); template static utility::string_t toString(const std::set &val); static web::json::value toJson(bool val); static web::json::value toJson(float val); static web::json::value toJson(double val); static web::json::value toJson(int32_t val); static web::json::value toJson(int64_t val); static web::json::value toJson(const utility::string_t &val); static web::json::value toJson(const utility::datetime &val); static web::json::value toJson(const web::json::value &val); static web::json::value toJson(const std::shared_ptr &val); template static web::json::value toJson(const std::shared_ptr &val); static web::json::value toJson(const std::shared_ptr &val); template static web::json::value toJson(const std::vector &val); template static web::json::value toJson(const std::set &val); template static web::json::value toJson(const std::map &val); static bool fromString(const utility::string_t &val, bool &); static bool fromString(const utility::string_t &val, float &); static bool fromString(const utility::string_t &val, double &); static bool fromString(const utility::string_t &val, int32_t &); static bool fromString(const utility::string_t &val, int64_t &); static bool fromString(const utility::string_t &val, utility::string_t &); static bool fromString(const utility::string_t &val, utility::datetime &); static bool fromString(const utility::string_t &val, web::json::value &); static bool fromString(const utility::string_t &val, std::shared_ptr &); template static bool fromString(const utility::string_t &val, std::shared_ptr &); static bool fromString(const utility::string_t &val, std::shared_ptr &outVal); template static bool fromString(const utility::string_t &val, std::vector &); template static bool fromString(const utility::string_t &val, std::set &); template static bool fromString(const utility::string_t &val, std::map &); static bool fromJson(const web::json::value &val, bool &); static bool fromJson(const web::json::value &val, float &); static bool fromJson(const web::json::value &val, double &); static bool fromJson(const web::json::value &val, int32_t &); static bool fromJson(const web::json::value &val, int64_t &); static bool fromJson(const web::json::value &val, utility::string_t &); static bool fromJson(const web::json::value &val, utility::datetime &); static bool fromJson(const web::json::value &val, web::json::value &); static bool fromJson(const web::json::value &val, std::shared_ptr &); template static bool fromJson(const web::json::value &val, std::shared_ptr &); static bool fromJson(const web::json::value &val, std::shared_ptr &outVal); template static bool fromJson(const web::json::value &val, std::vector &); template static bool fromJson(const web::json::value &val, std::set &); template static bool fromJson(const web::json::value &val, std::map &); static std::shared_ptr toHttpContent( const utility::string_t &name, bool value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static std::shared_ptr toHttpContent( const utility::string_t &name, float value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static std::shared_ptr toHttpContent( const utility::string_t &name, double value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static std::shared_ptr toHttpContent( const utility::string_t &name, int32_t value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static std::shared_ptr toHttpContent( const utility::string_t &name, int64_t value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static std::shared_ptr toHttpContent( const utility::string_t &name, const utility::string_t &value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static std::shared_ptr toHttpContent( const utility::string_t &name, const utility::datetime &value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static std::shared_ptr toHttpContent( const utility::string_t &name, const web::json::value &value, const utility::string_t &contentType = utility::conversions::to_string_t("application/json")); static std::shared_ptr toHttpContent(const utility::string_t &name, const std::shared_ptr &); template static std::shared_ptr toHttpContent( const utility::string_t &name, const std::shared_ptr &, const utility::string_t &contentType = utility::conversions::to_string_t("application/json")); static std::shared_ptr toHttpContent( const utility::string_t &name, const std::shared_ptr &value, const utility::string_t &contentType = utility::conversions::to_string_t("application/json")); template static std::shared_ptr toHttpContent( const utility::string_t &name, const std::vector &value, const utility::string_t &contentType = utility::conversions::to_string_t("")); template static std::shared_ptr toHttpContent( const utility::string_t &name, const std::set &value, const utility::string_t &contentType = utility::conversions::to_string_t("")); template static std::shared_ptr toHttpContent( const utility::string_t &name, const std::map &value, const utility::string_t &contentType = utility::conversions::to_string_t("")); static bool fromHttpContent(std::shared_ptr val, bool &); static bool fromHttpContent(std::shared_ptr val, float &); static bool fromHttpContent(std::shared_ptr val, double &); static bool fromHttpContent(std::shared_ptr val, int64_t &); static bool fromHttpContent(std::shared_ptr val, int32_t &); static bool fromHttpContent(std::shared_ptr val, utility::string_t &); static bool fromHttpContent(std::shared_ptr val, utility::datetime &); static bool fromHttpContent(std::shared_ptr val, web::json::value &); static bool fromHttpContent(std::shared_ptr val, std::shared_ptr &); template static bool fromHttpContent(std::shared_ptr val, std::shared_ptr &); template static bool fromHttpContent(std::shared_ptr val, std::vector &); template static bool fromHttpContent(std::shared_ptr val, std::set &); template static bool fromHttpContent(std::shared_ptr val, std::map &); static utility::string_t toBase64(utility::string_t value); static utility::string_t toBase64(std::shared_ptr value); static std::shared_ptr fromBase64(const utility::string_t &encoded); protected: bool m_IsSet; }; template utility::string_t ModelBase::toString(const std::shared_ptr &val) { utility::stringstream_t ss; if (val != nullptr) { val->toJson().serialize(ss); } return utility::string_t(ss.str()); } // std::vector to string template utility::string_t ModelBase::toString(const std::vector &val) { utility::string_t strArray; for (const auto &item : val) { strArray.append(toString(item) + ","); } if (val.count() > 0) { strArray.pop_back(); } return strArray; } // std::set to string template utility::string_t ModelBase::toString(const std::set &val) { utility::string_t strArray; for (const auto &item : val) { strArray.append(toString(item) + ","); } if (val.count() > 0) { strArray.pop_back(); } return strArray; } template web::json::value ModelBase::toJson(const std::shared_ptr &val) { web::json::value retVal; if (val != nullptr) { retVal = val->toJson(); } return retVal; } // std::vector to json template web::json::value ModelBase::toJson(const std::vector &value) { std::vector ret; for (const auto &x : value) { ret.push_back(toJson(x)); } return web::json::value::array(ret); } // std::set to json template web::json::value ModelBase::toJson(const std::set &value) { // There's no prototype web::json::value::array(...) taking a std::set parameter. Converting to std::vector // to get an array. std::vector ret; for (const auto &x : value) { ret.push_back(toJson(x)); } return web::json::value::array(ret); } template web::json::value ModelBase::toJson(const std::map &val) { web::json::value obj; for (const auto &itemkey : val) { obj[itemkey.first] = toJson(itemkey.second); } return obj; } template bool ModelBase::fromString(const utility::string_t &val, std::shared_ptr &outVal) { bool ok = false; if (outVal == nullptr) { outVal = std::make_shared(); } if (outVal != nullptr) { ok = outVal->fromJson(web::json::value::parse(val)); } return ok; } template bool ModelBase::fromString(const utility::string_t &val, std::vector &outVal) { bool ok = true; web::json::value jsonValue = web::json::value::parse(val); if (jsonValue.is_array()) { for (const web::json::value &jitem : jsonValue.as_array()) { T item; ok &= fromJson(jitem, item); outVal.push_back(item); } } else { T item; ok = fromJson(jsonValue, item); outVal.push_back(item); } return ok; } template bool ModelBase::fromString(const utility::string_t &val, std::set &outVal) { bool ok = true; web::json::value jsonValue = web::json::value::parse(val); if (jsonValue.is_array()) { for (const web::json::value &jitem : jsonValue.as_array()) { T item; ok &= fromJson(jitem, item); outVal.insert(item); } } else { T item; ok = fromJson(jsonValue, item); outVal.insert(item); } return ok; } template bool ModelBase::fromString(const utility::string_t &val, std::map &outVal) { bool ok = false; web::json::value jsonValue = web::json::value::parse(val); if (jsonValue.is_array()) { for (const web::json::value &jitem : jsonValue.as_array()) { T item; ok &= fromJson(jitem, item); outVal.insert({val, item}); } } else { T item; ok = fromJson(jsonValue, item); outVal.insert({val, item}); } return ok; } template bool ModelBase::fromJson(const web::json::value &val, std::shared_ptr &outVal) { bool ok = false; if (outVal == nullptr) { outVal = std::make_shared(); } if (outVal != nullptr) { ok = outVal->fromJson(val); } return ok; } template bool ModelBase::fromJson(const web::json::value &val, std::vector &outVal) { bool ok = true; if (val.is_array()) { for (const web::json::value &jitem : val.as_array()) { T item; ok &= fromJson(jitem, item); outVal.push_back(item); } } else { ok = false; } return ok; } template bool ModelBase::fromJson(const web::json::value &val, std::set &outVal) { bool ok = true; if (val.is_array()) { for (const web::json::value &jitem : val.as_array()) { T item; ok &= fromJson(jitem, item); outVal.insert(item); } } else { T item; ok = fromJson(val, item); outVal.insert(item); } return ok; } template bool ModelBase::fromJson(const web::json::value &jval, std::map &outVal) { bool ok = true; if (jval.is_object()) { auto obj = jval.as_object(); for (auto objItr = obj.begin(); objItr != obj.end(); objItr++) { T itemVal; ok &= fromJson(objItr->second, itemVal); outVal.insert(std::pair(objItr->first, itemVal)); } } else { ok = false; } return ok; } template std::shared_ptr ModelBase::toHttpContent(const utility::string_t &name, const std::shared_ptr &value, const utility::string_t &contentType) { std::shared_ptr content = std::make_shared(); if (value != nullptr) { content->setName(name); content->setContentDisposition(utility::conversions::to_string_t("form-data")); content->setContentType(contentType); content->setData(std::make_shared( utility::conversions::to_utf8string(value->toJson().serialize()))); } return content; } template std::shared_ptr ModelBase::toHttpContent(const utility::string_t &name, const std::vector &value, const utility::string_t &contentType) { web::json::value json_array = ModelBase::toJson(value); std::shared_ptr content = std::make_shared(); content->setName(name); content->setContentDisposition(utility::conversions::to_string_t("form-data")); content->setContentType(contentType); content->setData( std::make_shared(utility::conversions::to_utf8string(json_array.serialize()))); return content; } template std::shared_ptr ModelBase::toHttpContent(const utility::string_t &name, const std::set &value, const utility::string_t &contentType) { web::json::value json_array = ModelBase::toJson(value); std::shared_ptr content = std::make_shared(); content->setName(name); content->setContentDisposition(utility::conversions::to_string_t("form-data")); content->setContentType(contentType); content->setData( std::make_shared(utility::conversions::to_utf8string(json_array.serialize()))); return content; } template std::shared_ptr ModelBase::toHttpContent(const utility::string_t &name, const std::map &value, const utility::string_t &contentType) { web::json::value jobj = ModelBase::toJson(value); std::shared_ptr content = std::make_shared(); content->setName(name); content->setContentDisposition(utility::conversions::to_string_t("form-data")); content->setContentType(contentType); content->setData( std::make_shared(utility::conversions::to_utf8string(jobj.serialize()))); return content; } template bool ModelBase::fromHttpContent(std::shared_ptr val, std::shared_ptr &outVal) { utility::string_t str; if (val == nullptr) return false; if (outVal == nullptr) { outVal = std::make_shared(); } ModelBase::fromHttpContent(val, str); return fromString(str, outVal); } template bool ModelBase::fromHttpContent(std::shared_ptr val, std::vector &outVal) { utility::string_t str; if (val == nullptr) return false; ModelBase::fromHttpContent(val, str); return fromString(str, outVal); } template bool ModelBase::fromHttpContent(std::shared_ptr val, std::set &outVal) { utility::string_t str; if (val == nullptr) return false; ModelBase::fromHttpContent(val, str); return fromString(str, outVal); } template bool ModelBase::fromHttpContent(std::shared_ptr val, std::map &outVal) { utility::string_t str; if (val == nullptr) return false; ModelBase::fromHttpContent(val, str); return fromString(str, outVal); } } } #endif /* TRIBUFU_MODELS_ModelBase_H_ */