mirror of
https://github.com/oatpp/oatpp.git
synced 2025-02-17 17:29:57 +08:00
DTOs. Do not explicitly write <Type>::ObjectWrapper.
This commit is contained in:
parent
0e9ccbe3ba
commit
6acd2c3f39
@ -57,6 +57,7 @@ public: \
|
||||
typedef TYPE_NAME Z__CLASS; \
|
||||
typedef TYPE_EXTEND Z__CLASS_EXTENDED; \
|
||||
typedef oatpp::data::mapping::type::ObjectWrapper<Z__CLASS, oatpp::data::mapping::type::__class::Object<Z__CLASS>> ObjectWrapper; \
|
||||
typedef ObjectWrapper __Wrapper; \
|
||||
public: \
|
||||
OBJECT_POOL(DTO_OBJECT_POOL_##TYPE_NAME, TYPE_NAME, 32) \
|
||||
SHARED_OBJECT_POOL(SHARED_DTO_OBJECT_POOL_##TYPE_NAME, TYPE_NAME, 32) \
|
||||
@ -109,11 +110,11 @@ Z__CLASS_GET_FIELD_##NAME(oatpp::base::Countable* _this, \
|
||||
new oatpp::data::mapping::type::Type::Property(Z__CLASS_GET_FIELDS_MAP(), \
|
||||
(v_int64) _reg - (v_int64) _this, \
|
||||
#NAME, \
|
||||
TYPE::Class::getType()); \
|
||||
TYPE::__Wrapper::Class::getType()); \
|
||||
return field; \
|
||||
} \
|
||||
\
|
||||
TYPE NAME
|
||||
TYPE::__Wrapper NAME
|
||||
|
||||
#define OATPP_MACRO_DTO_FIELD_2(TYPE, NAME, QUALIFIER) \
|
||||
\
|
||||
@ -128,11 +129,11 @@ Z__CLASS_GET_FIELD_##NAME(oatpp::base::Countable* _this, \
|
||||
new oatpp::data::mapping::type::Type::Property(Z__CLASS_GET_FIELDS_MAP(), \
|
||||
(v_int64) _reg - (v_int64) _this, \
|
||||
QUALIFIER, \
|
||||
TYPE::Class::getType()); \
|
||||
TYPE::__Wrapper::Class::getType()); \
|
||||
return field; \
|
||||
} \
|
||||
\
|
||||
TYPE NAME
|
||||
TYPE::__Wrapper NAME
|
||||
|
||||
/**
|
||||
* Codegen macro to generate fields of DTO object.
|
||||
|
@ -111,9 +111,9 @@ public:
|
||||
* @throws - depends on implementation.
|
||||
*/
|
||||
template<class Class>
|
||||
typename Class::ObjectWrapper readFromCaret(oatpp::parser::Caret& caret) const {
|
||||
auto type = Class::ObjectWrapper::Class::getType();
|
||||
return read(caret, type).template staticCast<typename Class::ObjectWrapper>();
|
||||
typename Class::__Wrapper readFromCaret(oatpp::parser::Caret& caret) const {
|
||||
auto type = Class::__Wrapper::Class::getType();
|
||||
return read(caret, type).template staticCast<typename Class::__Wrapper>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,10 +125,10 @@ public:
|
||||
* @throws - depends on implementation.
|
||||
*/
|
||||
template<class Class>
|
||||
typename Class::ObjectWrapper readFromString(const oatpp::String& str) const {
|
||||
auto type = Class::ObjectWrapper::Class::getType();
|
||||
typename Class::__Wrapper readFromString(const oatpp::String& str) const {
|
||||
auto type = Class::__Wrapper::Class::getType();
|
||||
oatpp::parser::Caret caret(str);
|
||||
auto result = read(caret, type).template staticCast<typename Class::ObjectWrapper>();
|
||||
auto result = read(caret, type).template staticCast<typename Class::__Wrapper>();
|
||||
if(!result) {
|
||||
throw oatpp::parser::ParsingError(caret.getErrorMessage(), caret.getErrorCode(), caret.getPosition());
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
};
|
||||
|
||||
class Any : public ObjectWrapper<AnyHandle, __class::Any>{
|
||||
public:
|
||||
typedef Any __Wrapper;
|
||||
public:
|
||||
|
||||
Any();
|
||||
@ -87,15 +89,15 @@ public:
|
||||
const Type* getStoredType() const;
|
||||
|
||||
template<class WrapperType>
|
||||
WrapperType retrieve() const {
|
||||
typename WrapperType::__Wrapper retrieve() const {
|
||||
|
||||
if(m_ptr) {
|
||||
|
||||
if(m_ptr->type != WrapperType::Class::getType()) {
|
||||
if(m_ptr->type != WrapperType::__Wrapper::Class::getType()) {
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Any::retrieve()]: Error. The value type doesn't match.");
|
||||
}
|
||||
|
||||
return WrapperType(std::static_pointer_cast<typename WrapperType::ObjectType>(m_ptr->ptr), m_ptr->type);
|
||||
return typename WrapperType::__Wrapper(std::static_pointer_cast<typename WrapperType::__Wrapper::ObjectType>(m_ptr->ptr), m_ptr->type);
|
||||
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ class ListTypeTemplate : public oatpp::collection::LinkedList<T> {
|
||||
friend Class;
|
||||
public:
|
||||
typedef oatpp::data::mapping::type::ObjectWrapper<ListTypeTemplate, Class> ObjectWrapper;
|
||||
typedef ObjectWrapper __Wrapper;
|
||||
public:
|
||||
OBJECT_POOL(DTO_LIST_POOL, ListTypeTemplate, 32)
|
||||
SHARED_OBJECT_POOL(SHARED_DTO_LIST_POOL, ListTypeTemplate, 32)
|
||||
@ -85,7 +86,7 @@ public:
|
||||
};
|
||||
|
||||
template<class T>
|
||||
using List = ListTypeTemplate<T, __class::List<T>>;
|
||||
using List = ListTypeTemplate<typename T::__Wrapper, __class::List<typename T::__Wrapper>>;
|
||||
|
||||
namespace __class {
|
||||
|
||||
|
@ -42,11 +42,16 @@ namespace __class {
|
||||
|
||||
}
|
||||
|
||||
template<class Key, class Value>
|
||||
class ListMap : public oatpp::collection::ListMap<Key, Value> {
|
||||
template<class KeyOW, class ValueOW>
|
||||
class ListMap : public oatpp::collection::ListMap<typename KeyOW::__Wrapper, typename ValueOW::__Wrapper> {
|
||||
public:
|
||||
typedef typename KeyOW::__Wrapper Key;
|
||||
typedef typename ValueOW::__Wrapper Value;
|
||||
public:
|
||||
friend __class::ListMap<Key, Value>;
|
||||
public:
|
||||
typedef oatpp::data::mapping::type::ObjectWrapper<ListMap, __class::ListMap<Key, Value>> ObjectWrapper;
|
||||
typedef ObjectWrapper __Wrapper;
|
||||
public:
|
||||
OBJECT_POOL(DTO_LISTMAP_POOL, ListMap, 32)
|
||||
SHARED_OBJECT_POOL(SHARED_DTO_LISTMAP_POOL, ListMap, 32)
|
||||
|
@ -60,6 +60,8 @@ namespace __class {
|
||||
* Mapping-enables String is &id:type::ObjectWrapper; over &id:oatpp::base::StrBuffer;
|
||||
*/
|
||||
class String : public type::ObjectWrapper<base::StrBuffer, __class::String> {
|
||||
public:
|
||||
typedef String __Wrapper;
|
||||
public:
|
||||
String(const std::shared_ptr<base::StrBuffer>& ptr, const type::Type* const valueType);
|
||||
public:
|
||||
@ -175,6 +177,8 @@ public:
|
||||
* ObjectWrapper template for &l:Primitive;.
|
||||
*/
|
||||
class ObjectWrapper : public type::ObjectWrapper<Primitive, Clazz> {
|
||||
public:
|
||||
typedef ObjectWrapper __Wrapper;
|
||||
public:
|
||||
ObjectWrapper(const std::shared_ptr<Primitive>& ptr, const type::Type* const valueType)
|
||||
: type::ObjectWrapper<Primitive, Clazz>(ptr)
|
||||
|
@ -97,11 +97,17 @@ class ObjectWrapper {
|
||||
protected:
|
||||
std::shared_ptr<T> m_ptr;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Convenience self-typedef.
|
||||
*/
|
||||
typedef ObjectWrapper __Wrapper;
|
||||
|
||||
/**
|
||||
* Static object type
|
||||
*/
|
||||
typedef T ObjectType;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Static object class information.
|
||||
*/
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
*/
|
||||
template<class T>
|
||||
Param& add(const oatpp::String& name) {
|
||||
return add(name, T::Class::getType());
|
||||
return add(name, T::__Wrapper::Class::getType());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -220,7 +220,7 @@ public:
|
||||
*/
|
||||
template<class T>
|
||||
void addConsumes(const oatpp::String& contentType) {
|
||||
consumes.push_back({contentType, T::Class::getType()});
|
||||
consumes.push_back({contentType, T::__Wrapper::Class::getType()});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +232,7 @@ public:
|
||||
*/
|
||||
template<class T>
|
||||
void addResponse(const oatpp::web::protocol::http::Status& status, const oatpp::String& contentType, const oatpp::String& responseDescription = oatpp::String()) {
|
||||
responses[status] = {contentType, T::Class::getType(), responseDescription.get() == nullptr ? status.description : responseDescription};
|
||||
responses[status] = {contentType, T::__Wrapper::Class::getType(), responseDescription.get() == nullptr ? status.description : responseDescription};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,7 +115,7 @@ void AnyTest::onRun() {
|
||||
bool wasError = false;
|
||||
|
||||
try {
|
||||
auto obj = any.retrieve<Dto2::ObjectWrapper>(); // wrong object
|
||||
auto obj = any.retrieve<Dto2>(); // wrong object
|
||||
} catch (std::runtime_error& e) {
|
||||
wasError = true;
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ namespace {
|
||||
DTO_FIELD(Float64, field_float64);
|
||||
DTO_FIELD(Boolean, field_boolean);
|
||||
|
||||
DTO_FIELD(List<String>::ObjectWrapper, field_list_string);
|
||||
DTO_FIELD(List<Int32>::ObjectWrapper, field_list_int32);
|
||||
DTO_FIELD(List<Int64>::ObjectWrapper, field_list_int64);
|
||||
DTO_FIELD(List<Float32>::ObjectWrapper, field_list_float32);
|
||||
DTO_FIELD(List<Float64>::ObjectWrapper, field_list_float64);
|
||||
DTO_FIELD(List<Boolean>::ObjectWrapper, field_list_boolean);
|
||||
DTO_FIELD(List<String>, field_list_string);
|
||||
DTO_FIELD(List<Int32>, field_list_int32);
|
||||
DTO_FIELD(List<Int64>, field_list_int64);
|
||||
DTO_FIELD(List<Float32>, field_list_float32);
|
||||
DTO_FIELD(List<Float64>, field_list_float64);
|
||||
DTO_FIELD(List<Boolean>, field_list_boolean);
|
||||
|
||||
DTO_FIELD(Fields<String>::ObjectWrapper, field_map_string_string);
|
||||
DTO_FIELD(Fields<String>, field_map_string_string);
|
||||
|
||||
DTO_FIELD(TestDto::ObjectWrapper, obj1);
|
||||
|
||||
|
@ -50,7 +50,7 @@ typedef oatpp::parser::json::mapping::Deserializer Deserializer;
|
||||
|
||||
DTO_FIELD(String, field_string);
|
||||
DTO_FIELD(Int32, field_int32);
|
||||
DTO_FIELD(List<Int32>::ObjectWrapper, field_list);
|
||||
DTO_FIELD(List<Int32>, field_list);
|
||||
|
||||
static ObjectWrapper createTestInstance(){
|
||||
auto result = Test1::createShared();
|
||||
|
@ -65,18 +65,18 @@ class Test : public oatpp::Object {
|
||||
DTO_FIELD(Float64, field_float64);
|
||||
DTO_FIELD(Boolean, field_boolean);
|
||||
|
||||
DTO_FIELD(List<String>::ObjectWrapper, field_list_string) = List<String>::createShared();
|
||||
DTO_FIELD(List<Int32>::ObjectWrapper, field_list_int32) = List<Int32>::createShared();
|
||||
DTO_FIELD(List<Int64>::ObjectWrapper, field_list_int64) = List<Int64>::createShared();
|
||||
DTO_FIELD(List<Float32>::ObjectWrapper, field_list_float32) = List<Float32>::createShared();
|
||||
DTO_FIELD(List<Float64>::ObjectWrapper, field_list_float64) = List<Float64>::createShared();
|
||||
DTO_FIELD(List<Boolean>::ObjectWrapper, field_list_boolean) = List<Boolean>::createShared();
|
||||
DTO_FIELD(List<String>, field_list_string) = List<String>::createShared();
|
||||
DTO_FIELD(List<Int32>, field_list_int32) = List<Int32>::createShared();
|
||||
DTO_FIELD(List<Int64>, field_list_int64) = List<Int64>::createShared();
|
||||
DTO_FIELD(List<Float32>, field_list_float32) = List<Float32>::createShared();
|
||||
DTO_FIELD(List<Float64>, field_list_float64) = List<Float64>::createShared();
|
||||
DTO_FIELD(List<Boolean>, field_list_boolean) = List<Boolean>::createShared();
|
||||
|
||||
DTO_FIELD(List<TestChild::ObjectWrapper>::ObjectWrapper, field_list_object) = List<TestChild::ObjectWrapper>::createShared();
|
||||
DTO_FIELD(List<List<TestChild::ObjectWrapper>::ObjectWrapper>::ObjectWrapper, field_list_list_object) = List<List<TestChild::ObjectWrapper>::ObjectWrapper>::createShared();
|
||||
DTO_FIELD(List<TestChild>, field_list_object) = List<TestChild>::createShared();
|
||||
DTO_FIELD(List<List<TestChild>>, field_list_list_object) = List<List<TestChild>>::createShared();
|
||||
|
||||
DTO_FIELD(Test::ObjectWrapper, obj1);
|
||||
DTO_FIELD(TestChild::ObjectWrapper, child1);
|
||||
DTO_FIELD(Test, obj1);
|
||||
DTO_FIELD(TestChild, child1);
|
||||
|
||||
};
|
||||
|
||||
@ -84,7 +84,7 @@ class TestAny : public oatpp::Object {
|
||||
|
||||
DTO_INIT(TestAny, Object)
|
||||
|
||||
DTO_FIELD(List<Any>::ObjectWrapper, anyList) = List<Any>::createShared();
|
||||
DTO_FIELD(List<Any>, anyList) = List<Any>::createShared();
|
||||
|
||||
};
|
||||
|
||||
@ -153,9 +153,9 @@ void DTOMapperTest::onRun(){
|
||||
test1->field_list_object->pushBack(TestChild::createShared("child", "2"));
|
||||
test1->field_list_object->pushBack(TestChild::createShared("child", "3"));
|
||||
|
||||
auto l1 = oatpp::List<TestChild::ObjectWrapper>::createShared();
|
||||
auto l2 = oatpp::List<TestChild::ObjectWrapper>::createShared();
|
||||
auto l3 = oatpp::List<TestChild::ObjectWrapper>::createShared();
|
||||
auto l1 = oatpp::List<TestChild>::createShared();
|
||||
auto l2 = oatpp::List<TestChild>::createShared();
|
||||
auto l3 = oatpp::List<TestChild>::createShared();
|
||||
|
||||
l1->pushBack(TestChild::createShared("list_1", "item_1"));
|
||||
l1->pushBack(TestChild::createShared("list_1", "item_2"));
|
||||
@ -207,6 +207,10 @@ void DTOMapperTest::onRun(){
|
||||
OATPP_LOGV(TAG, "json='%s'", (const char*) result->getData());
|
||||
|
||||
{
|
||||
|
||||
TestAny::ObjectWrapper::__Wrapper objOW1;
|
||||
TestAny::__Wrapper objOW2;
|
||||
|
||||
auto obj = TestAny::createShared();
|
||||
obj->anyList->pushBack(oatpp::String("Hello Any!!!"));
|
||||
obj->anyList->pushBack(oatpp::Int32(32));
|
||||
|
@ -72,9 +72,9 @@ class Test4 : public DTO {
|
||||
|
||||
DTO_INIT(Test4, DTO)
|
||||
|
||||
DTO_FIELD(EmptyDto::ObjectWrapper, object);
|
||||
DTO_FIELD(List<EmptyDto::ObjectWrapper>::ObjectWrapper, list);
|
||||
DTO_FIELD(Fields<EmptyDto::ObjectWrapper>::ObjectWrapper, map);
|
||||
DTO_FIELD(EmptyDto, object);
|
||||
DTO_FIELD(List<EmptyDto>, list);
|
||||
DTO_FIELD(Fields<EmptyDto>, map);
|
||||
|
||||
};
|
||||
|
||||
|
@ -38,7 +38,7 @@ class TestDto : public oatpp::data::mapping::type::Object {
|
||||
|
||||
DTO_FIELD(String, testValue);
|
||||
DTO_FIELD(Int32, testValueInt);
|
||||
DTO_FIELD(Fields<String>::ObjectWrapper, testMap);
|
||||
DTO_FIELD(Fields<String>, testMap);
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user