mirror of
https://gitee.com/zyjblog/oatpp.git
synced 2025-01-05 17:42:23 +08:00
API-Docs. oatpp::Any, oatpp::Enum.
This commit is contained in:
parent
e14ddf60b8
commit
6f2ba3cdcc
@ -31,7 +31,15 @@
|
||||
#define OATPP_MACRO_DTO_ENUM_PARAM_VALUE_STR(MACRO, NAME, PARAM_LIST) OATPP_MACRO_FIRSTARG_STR PARAM_LIST
|
||||
#define OATPP_MACRO_DTO_ENUM_PARAM(MACRO, NAME, PARAM_LIST) (MACRO, NAME, PARAM_LIST)
|
||||
|
||||
#define VALUE(NAME, ...) OATPP_MACRO_DTO_ENUM_PARAM(OATPP_MACRO_DTO_ENUM_VALUE, NAME, (__VA_ARGS__))
|
||||
/**
|
||||
* Enum entry value.
|
||||
* @param NAME - name of the enum. **required**.
|
||||
* @param ORDINAL_VALUE - corresponding ordinal value. **required**.
|
||||
* @param QUALIFIER - name qualifier to be used instead of the `NAME`. **optional**.
|
||||
* @param DESCRIPTION - description of the enum value. **optional**.
|
||||
*/
|
||||
#define VALUE(NAME, ...) \
|
||||
OATPP_MACRO_DTO_ENUM_PARAM(OATPP_MACRO_DTO_ENUM_VALUE, NAME, (__VA_ARGS__))
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -150,11 +158,10 @@ OATPP_ENUM_0(NAME, ORDINAL_TYPE)
|
||||
OATPP_ENUM_1(NAME, ORDINAL_TYPE, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Codegen macoro to be used in `oatpp::web::client::ApiClient` to generate REST API-Calls.
|
||||
* @param METHOD - Http method ("GET", "POST", "PUT", etc.)
|
||||
* @param PATH - Path to endpoint (without host)
|
||||
* @param NAME - Name of the generated method
|
||||
* @return - std::shared_ptr to &id:oatpp::web::protocol::http::incoming::Response;
|
||||
* Codegen macoro to generate oatpp mapping-enabled enum.
|
||||
* @param NAME - name of the enum. **required**.
|
||||
* @param UNDERLYING_TYPE - underlying ordinal type. **required**.
|
||||
* @param ... - enum values defined with &l:VALUE (...);. macro.
|
||||
*/
|
||||
#define ENUM(NAME, ...) \
|
||||
OATPP_MACRO_EXPAND(OATPP_MACRO_MACRO_BINARY_SELECTOR(OATPP_ENUM_MACRO_, (__VA_ARGS__)) (NAME, __VA_ARGS__))
|
||||
|
@ -62,32 +62,72 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Any - ObjectWrapper to hold Any oatpp mapping-enabled type.
|
||||
*/
|
||||
class Any : public ObjectWrapper<AnyHandle, __class::Any>{
|
||||
public:
|
||||
typedef Any __Wrapper;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Any();
|
||||
|
||||
/**
|
||||
* Nullptr constructor.
|
||||
*/
|
||||
Any(std::nullptr_t);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param other - other Any.
|
||||
*/
|
||||
Any(const Any& other);
|
||||
|
||||
/**
|
||||
* Move constructor.
|
||||
* @param other
|
||||
*/
|
||||
Any(Any&& other);
|
||||
|
||||
Any(const std::shared_ptr<base::Countable>& ptr, const Type* const type);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @tparam T - Underlying type of ObjectWrapper.
|
||||
* @tparam C - __class of ObjectWrapper.
|
||||
* @param polymorph - any ObjectWrapper.
|
||||
*/
|
||||
template<class T, class C>
|
||||
Any(const ObjectWrapper<T, C>& polymorph)
|
||||
: ObjectWrapper(std::make_shared<AnyHandle>(polymorph.getPtr(), polymorph.valueType), __class::Any::getType())
|
||||
{}
|
||||
|
||||
/**
|
||||
* Store any ObjectWrapper in Any.
|
||||
* @tparam T
|
||||
* @tparam C
|
||||
* @param polymorph - ObjectWrapper. Ex.: `oatpp::String`, `oatpp::List<...>`, etc.
|
||||
*/
|
||||
template<class T, class C>
|
||||
void store(const ObjectWrapper<T, C>& polymorph) {
|
||||
m_ptr = std::make_shared<AnyHandle>(polymorph.getPtr(), polymorph.valueType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get `Type` of the stored object.
|
||||
* @return - &id:oatpp::data::mapping::type::Type;.
|
||||
*/
|
||||
const Type* getStoredType() const;
|
||||
|
||||
/**
|
||||
* Retrieve stored object.
|
||||
* @tparam WrapperType - type of the object to retrieve.
|
||||
* @return - ObjectWrapper of type - `WrapperType`.
|
||||
* @throws - `std::runtime_error` - if stored type and type requested (`WrapperType`) do not match.
|
||||
*/
|
||||
template<class WrapperType>
|
||||
typename WrapperType::__Wrapper retrieve() const {
|
||||
|
||||
|
@ -72,6 +72,9 @@ enum class EnumInterpreterError : v_int32 {
|
||||
|
||||
namespace __class {
|
||||
|
||||
/**
|
||||
* Abstract Enum class.
|
||||
*/
|
||||
class AbstractEnum {
|
||||
public:
|
||||
static const ClassId CLASS_ID;
|
||||
@ -100,11 +103,32 @@ namespace __class {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum value info.
|
||||
* @tparam T - underlying enum type.
|
||||
*/
|
||||
template<typename T>
|
||||
struct EnumValueInfo {
|
||||
/**
|
||||
* Entry value. T - enum type.
|
||||
*/
|
||||
const T value;
|
||||
|
||||
/**
|
||||
* Index of the entry.
|
||||
*/
|
||||
const v_int32 index;
|
||||
|
||||
/**
|
||||
* Name of the enum entry or name-qualifier, if qualifier was specified. <br>
|
||||
* &id:oatpp::data::share::StringKeyLabel;.
|
||||
*/
|
||||
const data::share::StringKeyLabel name;
|
||||
|
||||
/**
|
||||
* Description of the enum etry. <br>
|
||||
* &id:oatpp::data::share::StringKeyLabel;.
|
||||
*/
|
||||
const data::share::StringKeyLabel description;
|
||||
};
|
||||
|
||||
@ -138,6 +162,11 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Enum interpreter `AsString`
|
||||
* @tparam T
|
||||
* @tparam notnull
|
||||
*/
|
||||
template<class T, bool notnull>
|
||||
class EnumInterpreterAsString {
|
||||
public:
|
||||
@ -153,15 +182,20 @@ public:
|
||||
static Type* getInterpretationType();
|
||||
};
|
||||
|
||||
/**
|
||||
* Enum interpreter `AsNumber`
|
||||
* @tparam T
|
||||
* @tparam notnull
|
||||
*/
|
||||
template<class T, bool notnull>
|
||||
class EnumInterpreterAsInteger {
|
||||
class EnumInterpreterAsNumber {
|
||||
private:
|
||||
typedef typename std::underlying_type<T>::type EnumUnderlyingType;
|
||||
public:
|
||||
typedef typename ObjectWrapperByUnderlyingType<EnumUnderlyingType>::ObjectWrapper UnderlyingTypeObjectWrapper;
|
||||
public:
|
||||
template <bool N>
|
||||
using InterpreterType = EnumInterpreterAsInteger<T, N>;
|
||||
using InterpreterType = EnumInterpreterAsNumber<T, N>;
|
||||
public:
|
||||
constexpr static bool notNull = notnull;
|
||||
public:
|
||||
@ -170,6 +204,11 @@ public:
|
||||
static Type* getInterpretationType();
|
||||
};
|
||||
|
||||
/**
|
||||
* Template class for `oatpp::Enum<T>`.
|
||||
* @tparam T - enum type.
|
||||
* @tparam EnumInterpreter - enum interpreter.
|
||||
*/
|
||||
template<class T, class EnumInterpreter>
|
||||
class EnumObjectWrapper : public ObjectWrapper<T, __class::Enum<T, EnumInterpreter>>{
|
||||
template<class Type, class Interpreter>
|
||||
@ -177,13 +216,31 @@ class EnumObjectWrapper : public ObjectWrapper<T, __class::Enum<T, EnumInterpret
|
||||
public:
|
||||
typedef EnumObjectWrapper __Wrapper;
|
||||
public:
|
||||
/**
|
||||
* Underlying enum type.
|
||||
*/
|
||||
typedef typename std::underlying_type<T>::type UnderlyingEnumType;
|
||||
typedef T Z__EnumType;
|
||||
typedef __class::Enum<T, EnumInterpreter> EnumObjectClass;
|
||||
|
||||
/**
|
||||
* Template parameter - `Interpreter`.
|
||||
*/
|
||||
typedef EnumInterpreter Interpreter;
|
||||
public:
|
||||
/**
|
||||
* Enum interpreted `AsString`.
|
||||
*/
|
||||
typedef EnumObjectWrapper<T, EnumInterpreterAsString<T, EnumInterpreter::notNull>> AsString;
|
||||
typedef EnumObjectWrapper<T, EnumInterpreterAsInteger<T, EnumInterpreter::notNull>> AsNumber;
|
||||
|
||||
/**
|
||||
* Enum interpreted `AsNumber`.
|
||||
*/
|
||||
typedef EnumObjectWrapper<T, EnumInterpreterAsNumber<T, EnumInterpreter::notNull>> AsNumber;
|
||||
|
||||
/**
|
||||
* Enum with `NotNull` interpretation constraint.
|
||||
*/
|
||||
typedef EnumObjectWrapper<T, typename EnumInterpreter::template InterpreterType<true>> NotNull;
|
||||
public:
|
||||
|
||||
@ -191,23 +248,47 @@ public:
|
||||
: type::ObjectWrapper<T, EnumObjectClass>(ptr, valueType)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
EnumObjectWrapper() {}
|
||||
|
||||
/**
|
||||
* Nullptr constructor.
|
||||
*/
|
||||
EnumObjectWrapper(std::nullptr_t) {}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param ptr
|
||||
*/
|
||||
EnumObjectWrapper(const std::shared_ptr<T>& ptr)
|
||||
: type::ObjectWrapper<T, EnumObjectClass>(ptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param ptr
|
||||
*/
|
||||
EnumObjectWrapper(std::shared_ptr<T>&& ptr)
|
||||
: type::ObjectWrapper<T, EnumObjectClass>(std::forward<std::shared_ptr<T>>(ptr))
|
||||
{}
|
||||
|
||||
/**
|
||||
* Copy-constructor.
|
||||
* @tparam OtherInter
|
||||
* @param other
|
||||
*/
|
||||
template<class OtherInter>
|
||||
EnumObjectWrapper(const EnumObjectWrapper<T, OtherInter>& other)
|
||||
: type::ObjectWrapper<T, EnumObjectClass>(other.getPtr())
|
||||
{}
|
||||
|
||||
/**
|
||||
* Move-constructor.
|
||||
* @tparam OtherInter
|
||||
* @param other
|
||||
*/
|
||||
template<class OtherInter>
|
||||
EnumObjectWrapper(EnumObjectWrapper<T, OtherInter>&& other)
|
||||
: type::ObjectWrapper<T, EnumObjectClass>(std::move(other.getPtr()))
|
||||
@ -232,6 +313,10 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor by value.
|
||||
* @param value
|
||||
*/
|
||||
EnumObjectWrapper(T value)
|
||||
: type::ObjectWrapper<T, EnumObjectClass>(std::make_shared<T>(value))
|
||||
{}
|
||||
@ -300,6 +385,12 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Get &l:EnumValueInfo <T>; by name.
|
||||
* @param name - name or name-qualifier of the enum entry.
|
||||
* @return - &l:EnumValueInfo <T>;.
|
||||
* @throws - `std::runtime_error` if not found.
|
||||
*/
|
||||
static const EnumValueInfo<T>& getEntryByName(const String& name) {
|
||||
auto it = EnumMeta<T>::getInfo()->byName.find(name);
|
||||
if(it != EnumMeta<T>::getInfo()->byName.end()) {
|
||||
@ -308,6 +399,12 @@ public:
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByName()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get &l:EnumValueInfo <T>; by enum value.
|
||||
* @param value - enum value.
|
||||
* @return - &l:EnumValueInfo <T>;.
|
||||
* @throws - `std::runtime_error` if not found.
|
||||
*/
|
||||
static const EnumValueInfo<T>& getEntryByValue(T value) {
|
||||
auto it = EnumMeta<T>::getInfo()->byValue.find(static_cast<v_uint64>(value));
|
||||
if(it != EnumMeta<T>::getInfo()->byValue.end()) {
|
||||
@ -316,6 +413,12 @@ public:
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByValue()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get &l:EnumValueInfo <T>; by integer value.
|
||||
* @param value - integer value.
|
||||
* @return - &l:EnumValueInfo <T>;.
|
||||
* @throws - `std::runtime_error` if not found.
|
||||
*/
|
||||
static const EnumValueInfo<T>& getEntryByUnderlyingValue(UnderlyingEnumType value) {
|
||||
auto it = EnumMeta<T>::getInfo()->byValue.find(static_cast<v_uint64>(value));
|
||||
if(it != EnumMeta<T>::getInfo()->byValue.end()) {
|
||||
@ -324,6 +427,12 @@ public:
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByUnderlyingValue()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get &l:EnumValueInfo <T>; by index.
|
||||
* @param index - index of the entry in the enum.
|
||||
* @return - &l:EnumValueInfo <T>;.
|
||||
* @throws - `std::runtime_error` if not found.
|
||||
*/
|
||||
static const EnumValueInfo<T>& getEntryByIndex(v_int32 index) {
|
||||
if(index >= 0 && index < EnumMeta<T>::getInfo()->byIndex.size()) {
|
||||
return EnumMeta<T>::getInfo()->byIndex[index];
|
||||
@ -331,6 +440,10 @@ public:
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByIndex()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get `std::vector` of &l:EnumValueInfo <T>;.
|
||||
* @return - `std::vector` of &l:EnumValueInfo <T>;.
|
||||
*/
|
||||
static const std::vector<EnumValueInfo<T>>& getEntries() {
|
||||
return EnumMeta<T>::getInfo()->byIndex;
|
||||
}
|
||||
@ -394,9 +507,9 @@ Type* EnumInterpreterAsString<T, notnull>::getInterpretationType() {
|
||||
}
|
||||
|
||||
template<class T, bool notnull>
|
||||
Void EnumInterpreterAsInteger<T, notnull>::toInterpretation(const Void& enumValue, EnumInterpreterError& error) {
|
||||
Void EnumInterpreterAsNumber<T, notnull>::toInterpretation(const Void& enumValue, EnumInterpreterError& error) {
|
||||
|
||||
typedef EnumObjectWrapper<T, EnumInterpreterAsInteger<T, notnull>> EnumOW;
|
||||
typedef EnumObjectWrapper<T, EnumInterpreterAsNumber<T, notnull>> EnumOW;
|
||||
typedef typename std::underlying_type<T>::type EnumUT;
|
||||
typedef typename ObjectWrapperByUnderlyingType<EnumUT>::ObjectWrapper UTOW;
|
||||
|
||||
@ -419,8 +532,8 @@ Void EnumInterpreterAsInteger<T, notnull>::toInterpretation(const Void& enumValu
|
||||
}
|
||||
|
||||
template<class T, bool notnull>
|
||||
Void EnumInterpreterAsInteger<T, notnull>::fromInterpretation(const Void& interValue, EnumInterpreterError& error) {
|
||||
typedef EnumObjectWrapper<T, EnumInterpreterAsInteger<T, notnull>> EnumOW;
|
||||
Void EnumInterpreterAsNumber<T, notnull>::fromInterpretation(const Void& interValue, EnumInterpreterError& error) {
|
||||
typedef EnumObjectWrapper<T, EnumInterpreterAsNumber<T, notnull>> EnumOW;
|
||||
|
||||
typedef typename std::underlying_type<T>::type EnumUT;
|
||||
typedef typename ObjectWrapperByUnderlyingType<EnumUT>::ObjectWrapper OW;
|
||||
@ -450,7 +563,7 @@ Void EnumInterpreterAsInteger<T, notnull>::fromInterpretation(const Void& interV
|
||||
}
|
||||
|
||||
template<class T, bool notnull>
|
||||
Type* EnumInterpreterAsInteger<T, notnull>::getInterpretationType() {
|
||||
Type* EnumInterpreterAsNumber<T, notnull>::getInterpretationType() {
|
||||
typedef typename std::underlying_type<T>::type EnumUT;
|
||||
return ObjectWrapperByUnderlyingType<EnumUT>::ObjectWrapper::Class::getType();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user