PtrWrapper, ObjectWrapper refactoring

This commit is contained in:
lganzzzo 2018-06-26 19:25:56 +03:00
parent 80aa0ca5ba
commit 6effe7ae30
33 changed files with 399 additions and 371 deletions

View File

@ -1,9 +1,25 @@
//
// Types.cpp
// tls-libressl
//
// Created by Leonid on 6/26/18.
// Copyright © 2018 oatpp. All rights reserved.
//
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "Types.hpp"

View File

@ -1,14 +1,31 @@
//
// Types.hpp
// tls-libressl
//
// Created by Leonid on 6/26/18.
// Copyright © 2018 oatpp. All rights reserved.
//
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_Types_hpp
#define oatpp_Types_hpp
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/data/mapping/type/Primitive.hpp"
namespace oatpp {

View File

@ -272,15 +272,15 @@ void StrBuffer::upperCase(const void* data, v_int32 size) {
// Operator
/*
oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer> operator + (const char* a, const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& b){
oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer> operator + (const char* a, const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& b){
return StrBuffer::createSharedConcatenated(a, (v_int32) std::strlen(a), b->getData(), b->getSize());
}
oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& b, const char* a){
oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& b, const char* a){
return StrBuffer::createSharedConcatenated(b->getData(), b->getSize(), a, (v_int32) std::strlen(a));
}
oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& a, const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& b) {
oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& a, const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& b) {
return StrBuffer::createSharedConcatenated(a->getData(), a->getSize(), b->getData(), b->getSize());
}

View File

@ -142,9 +142,9 @@ public:
};
/*
oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer> operator + (const char* a, const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& b);
oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& b, const char* a);
oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& a, const oatpp::data::mapping::type::BasicPtrWrapper<StrBuffer>& b);
oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer> operator + (const char* a, const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& b);
oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& b, const char* a);
oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer> operator + (const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& a, const oatpp::data::mapping::type::PolymorphicWrapper<StrBuffer>& b);
std::shared_ptr<StrBuffer> operator + (const char* a, const std::shared_ptr<StrBuffer>& b);
std::shared_ptr<StrBuffer> operator + (const std::shared_ptr<StrBuffer>& b, const char* a);

View File

@ -123,7 +123,7 @@ private:
Entry* curr = m_first;
while(curr != nullptr){
if(key.equals(curr->key)){
if(key == curr->key){
return curr;
}
curr = curr->next;

View File

@ -58,28 +58,28 @@ public:
}
virtual void write(const std::shared_ptr<oatpp::data::stream::OutputStream>& stream,
const type::AbstractPtrWrapper& variant) const = 0;
const type::AbstractObjectWrapper& variant) const = 0;
virtual type::AbstractPtrWrapper read(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
virtual type::AbstractObjectWrapper read(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const type::Type* const type) const = 0;
oatpp::String writeToString(const type::AbstractPtrWrapper& variant) const {
oatpp::String writeToString(const type::AbstractObjectWrapper& variant) const {
auto stream = stream::ChunkedBuffer::createShared();
write(stream, variant);
return stream->toString();
}
template<class Class>
typename Class::PtrWrapper readFromCaret(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret) const {
auto type = Class::PtrWrapper::Class::getType();
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::PtrWrapper::ObjectType>(read(caret, type));
typename Class::ObjectWrapper readFromCaret(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret) const {
auto type = Class::ObjectWrapper::Class::getType();
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
}
template<class Class>
typename Class::PtrWrapper readFromString(const oatpp::String& str) const {
auto type = Class::PtrWrapper::Class::getType();
typename Class::ObjectWrapper readFromString(const oatpp::String& str) const {
auto type = Class::ObjectWrapper::Class::getType();
auto caret = oatpp::parser::ParsingCaret::createShared(str.getPtr());
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::PtrWrapper::ObjectType>(read(caret, type));
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
}
};

View File

@ -31,8 +31,6 @@
#include "oatpp/core/base/memory/ObjectPool.hpp"
#include "oatpp/core/base/Controllable.hpp"
#include "oatpp/core/Types.hpp"
namespace oatpp { namespace data { namespace mapping { namespace type {
@ -52,14 +50,14 @@ template<class T>
class List : public oatpp::collection::LinkedList<T> {
friend __class::List<T>;
public:
typedef oatpp::data::mapping::type::PtrWrapper<List, __class::List<T>> PtrWrapper;
typedef oatpp::data::mapping::type::ObjectWrapper<List, __class::List<T>> ObjectWrapper;
public:
OBJECT_POOL(DTO_LIST_POOL, List, 32)
SHARED_OBJECT_POOL(SHARED_DTO_LIST_POOL, List, 32)
protected:
static AbstractPtrWrapper Z__CLASS_OBJECT_CREATOR(){
return AbstractPtrWrapper(SHARED_DTO_LIST_POOL::allocateShared(), Z__CLASS_GET_TYPE());
static AbstractObjectWrapper Z__CLASS_OBJECT_CREATOR(){
return AbstractObjectWrapper(SHARED_DTO_LIST_POOL::allocateShared(), Z__CLASS_GET_TYPE());
}
static Type* Z__CLASS_GET_TYPE(){
@ -75,11 +73,11 @@ public:
{}
public:
static PtrWrapper createShared(){
return PtrWrapper(SHARED_DTO_LIST_POOL::allocateShared());
static ObjectWrapper createShared(){
return ObjectWrapper(SHARED_DTO_LIST_POOL::allocateShared());
}
virtual void addPolymorphicItem(const AbstractPtrWrapper& item){
virtual void addPolymorphicItem(const AbstractObjectWrapper& item){
auto ptr = std::static_pointer_cast<typename T::ObjectType>(item.getPtr());
this->pushBack(T(ptr, item.valueType));
}

View File

@ -32,8 +32,6 @@
#include "oatpp/core/base/memory/ObjectPool.hpp"
#include "oatpp/core/base/Controllable.hpp"
#include "oatpp/core/Types.hpp"
namespace oatpp { namespace data { namespace mapping { namespace type {
@ -59,7 +57,7 @@ namespace __class {
class Object : public oatpp::base::Controllable {
public:
typedef oatpp::String String;
typedef oatpp::data::mapping::type::String String;
typedef oatpp::data::mapping::type::Int32 Int32;
typedef oatpp::data::mapping::type::Int64 Int64;
typedef oatpp::data::mapping::type::Float32 Float32;

View File

@ -29,7 +29,7 @@
namespace oatpp { namespace data { namespace mapping { namespace type {
String::String(const std::shared_ptr<oatpp::base::StrBuffer>& ptr, const type::Type* const valueType)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(ptr)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(ptr)
{
if(type::__class::String::getType() != valueType) {
throw std::runtime_error("Value type does not match");

View File

@ -46,7 +46,7 @@ namespace __class {
}
class String : public oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String> {
class String : public oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String> {
public:
String(const std::shared_ptr<oatpp::base::StrBuffer>& ptr, const type::Type* const valueType);
public:
@ -54,35 +54,35 @@ public:
String() {}
String(v_int32 size)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createShared(size))
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createShared(size))
{}
String(const void* data, v_int32 size, bool copyAsOwnData = true)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createShared(data, size, copyAsOwnData))
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createShared(data, size, copyAsOwnData))
{}
String(const void* data1, v_int32 size1, const void* data2, v_int32 size2)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createSharedConcatenated(data1, size1, data2, size2))
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createSharedConcatenated(data1, size1, data2, size2))
{}
String(const char* data, bool copyAsOwnData = true)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createFromCString(data, copyAsOwnData))
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createFromCString(data, copyAsOwnData))
{}
String(const std::shared_ptr<oatpp::base::StrBuffer>& ptr)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(ptr)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(ptr)
{}
String(std::shared_ptr<oatpp::base::StrBuffer>&& ptr)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(std::move(ptr))
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(std::forward<std::shared_ptr<oatpp::base::StrBuffer>>(ptr))
{}
String(const String& other)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(other)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(other)
{}
String(String&& other)
: oatpp::data::mapping::type::PtrWrapper<oatpp::base::StrBuffer, __class::String>(std::move(other))
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(std::forward<String>(other))
{}
String& operator = (const char* str) {
@ -91,21 +91,21 @@ public:
}
String& operator = (const String& other){
BasicPtrWrapper<oatpp::base::StrBuffer>::operator=(other);
m_ptr = other.m_ptr;
return *this;
}
String& operator = (String&& other){
BasicPtrWrapper<oatpp::base::StrBuffer>::operator=(std::move(other));
m_ptr = std::forward<std::shared_ptr<oatpp::base::StrBuffer>>(other.m_ptr);
return *this;
}
String operator + (const char* str) const{
return oatpp::base::StrBuffer::createSharedConcatenated(m_ptr.get()->getData(), m_ptr.get()->getSize(), str, (v_int32) std::strlen(str));
return oatpp::base::StrBuffer::createSharedConcatenated(m_ptr->getData(), m_ptr->getSize(), str, (v_int32) std::strlen(str));
}
String operator + (const String& other) const{
return oatpp::base::StrBuffer::createSharedConcatenated(m_ptr.get()->getData(), m_ptr.get()->getSize(), other.get()->getData(), other.get()->getSize());
return oatpp::base::StrBuffer::createSharedConcatenated(m_ptr->getData(), m_ptr->getSize(), other->getData(), other->getSize());
}
static const String& empty(){
@ -113,7 +113,12 @@ public:
return empty;
}
bool equals(const String& other) const {
/* bool equals(const String& other) const {
return m_ptr->equals(other.get());
}
*/
bool operator==(const String &other) const {
return m_ptr->equals(other.get());
}
@ -122,7 +127,7 @@ public:
}
};
template<typename ValueType, class Clazz>
class Primitive : public oatpp::base::Controllable {
public:
@ -130,10 +135,10 @@ public:
SHARED_OBJECT_POOL(Shared_Primitive_Type_Pool, Primitive, 32)
public:
class PtrWrapper : public oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz> {
class ObjectWrapper : public oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz> {
public:
PtrWrapper(const std::shared_ptr<Primitive>& ptr, const type::Type* const valueType)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(ptr)
ObjectWrapper(const std::shared_ptr<Primitive>& ptr, const type::Type* const valueType)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(ptr)
{
if(Clazz::getType() != valueType){
throw std::runtime_error("Value type does not match");
@ -141,32 +146,32 @@ public:
}
public:
PtrWrapper()
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>()
ObjectWrapper()
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>()
{}
PtrWrapper(const std::shared_ptr<Primitive>& ptr)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(ptr)
ObjectWrapper(const std::shared_ptr<Primitive>& ptr)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(ptr)
{}
PtrWrapper(std::shared_ptr<Primitive>&& ptr)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(std::move(ptr))
ObjectWrapper(std::shared_ptr<Primitive>&& ptr)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(std::move(ptr))
{}
PtrWrapper(const PtrWrapper& other)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(other)
ObjectWrapper(const ObjectWrapper& other)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(other)
{}
PtrWrapper(PtrWrapper&& other)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(std::move(other))
ObjectWrapper(ObjectWrapper&& other)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(std::move(other))
{}
PtrWrapper(const ValueType& value)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(Primitive::createShared(value))
ObjectWrapper(const ValueType& value)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(Primitive::createShared(value))
{}
PtrWrapper& operator = (const ValueType& value){
if(this->isNull()){
ObjectWrapper& operator = (const ValueType& value){
if(!this->m_ptr){
this->m_ptr = Primitive::createShared(value);
} else {
this->m_ptr.get()->setValue(value);
@ -174,12 +179,16 @@ public:
return *this;
}
bool operator==(const ObjectWrapper &other) const {
return getValue() == other->getValue();
}
inline operator ValueType() const {
return this->get()->getValue();
}
static const PtrWrapper& empty(){
static PtrWrapper result;
static const ObjectWrapper& empty(){
static ObjectWrapper result;
return result;
}
@ -213,12 +222,11 @@ public:
};
typedef Primitive<v_int32, __class::Int32>::PtrWrapper Int32;
typedef Primitive<v_int64, __class::Int64>::PtrWrapper Int64;
typedef Primitive<v_float32, __class::Float32>::PtrWrapper Float32;
typedef Primitive<v_float64, __class::Float64>::PtrWrapper Float64;
typedef Primitive<bool, __class::Boolean>::PtrWrapper Boolean;
typedef Primitive<v_int32, __class::Int32>::ObjectWrapper Int32;
typedef Primitive<v_int64, __class::Int64>::ObjectWrapper Int64;
typedef Primitive<v_float32, __class::Float32>::ObjectWrapper Float32;
typedef Primitive<v_float64, __class::Float64>::ObjectWrapper Float64;
typedef Primitive<bool, __class::Boolean>::ObjectWrapper Boolean;
namespace __class {
@ -307,4 +315,34 @@ namespace __class {
}}}}
namespace std {
template<>
struct hash<oatpp::data::mapping::type::String> {
typedef oatpp::data::mapping::type::String argument_type;
typedef v_word32 result_type;
result_type operator()(oatpp::data::mapping::type::String const& s) const noexcept {
p_char8 data = s->getData();
v_int32 size4 = s->getSize() >> 2;
result_type result = 0;
for(v_int32 i = 0; i < size4; i++) {
result ^= *((p_word32) data);
data += 4;
}
for(v_int32 i = 0; i < s->getSize() - (size4 << 2); i++ ) {
((p_char8) &result)[i] ^= data[i];
}
return result;
}
};
}
#endif /* oatpp_base_controllable_PrimitiveDataTypes_hpp */

View File

@ -43,40 +43,69 @@ namespace __class {
};
}
template<class T>
class BasicPtrWrapper {
template <class T>
class PolymorphicWrapper {
protected:
std::shared_ptr<T> m_ptr;
public:
typedef T ObjectType;
public:
typedef __class::Void Class;
public:
BasicPtrWrapper() {}
BasicPtrWrapper(const std::shared_ptr<T>& ptr)
PolymorphicWrapper(const std::shared_ptr<T>& ptr)
: m_ptr(ptr)
, valueType(Class::getType())
{}
BasicPtrWrapper(std::shared_ptr<T>&& ptr)
PolymorphicWrapper(const std::shared_ptr<T>& ptr, const Type* const type)
: m_ptr(ptr)
, valueType(type)
{}
PolymorphicWrapper(std::shared_ptr<T>&& ptr, const Type* const type)
: m_ptr(std::move(ptr))
, valueType(type)
{}
BasicPtrWrapper(const BasicPtrWrapper& other)
public:
PolymorphicWrapper()
: valueType(Class::getType())
{}
PolymorphicWrapper(const Type* const type)
: valueType(type)
{}
PolymorphicWrapper(const PolymorphicWrapper& other)
: m_ptr(other.m_ptr)
, valueType(other.valueType)
{}
BasicPtrWrapper(BasicPtrWrapper&& other)
: m_ptr(std::move(other.m_ptr))
PolymorphicWrapper(PolymorphicWrapper&& other)
: m_ptr(std::move(other.m_ptr))
, valueType(other.valueType)
{}
BasicPtrWrapper& operator = (const BasicPtrWrapper& other){
static PolymorphicWrapper empty(){
return PolymorphicWrapper();
}
PolymorphicWrapper& operator=(const PolymorphicWrapper<T>& other){
m_ptr = other.m_ptr;
return *this;
}
BasicPtrWrapper& operator = (BasicPtrWrapper&& other){
PolymorphicWrapper& operator=(const PolymorphicWrapper<T>&& other){
m_ptr = std::move(other.m_ptr);
return *this;
}
inline operator PolymorphicWrapper<oatpp::base::Controllable>() const {
return PolymorphicWrapper<oatpp::base::Controllable>(this->m_ptr, valueType);
}
T* operator->() const {
return m_ptr.operator->();
}
@ -89,113 +118,35 @@ public:
return m_ptr;
}
bool isNull() const {
return m_ptr.get() == nullptr;
}
static const BasicPtrWrapper& empty(){
static BasicPtrWrapper empty;
return empty;
}
inline bool operator == (const BasicPtrWrapper& other){
inline bool operator == (const PolymorphicWrapper& other){
return m_ptr.get() == other.m_ptr.get();
}
inline bool operator != (const BasicPtrWrapper& other){
inline bool operator != (const PolymorphicWrapper& other){
return m_ptr.get() != other.m_ptr.get();
}
};
template<class T, class F>
inline BasicPtrWrapper<T> static_wrapper_cast(const F& from){
return BasicPtrWrapper<T>(std::static_pointer_cast<T>(from.getPtr()));
}
template <class T>
class PolymorphicWrapper : public BasicPtrWrapper<T> {
public:
typedef T ObjectType;
public:
typedef __class::Void Class;
public:
PolymorphicWrapper(const BasicPtrWrapper<T>& other, const Type* const type)
: BasicPtrWrapper<T>(other)
, valueType(type)
{}
PolymorphicWrapper(BasicPtrWrapper<T>&& other, const Type* const type)
: BasicPtrWrapper<T>(std::move(other))
, valueType(type)
{}
public:
PolymorphicWrapper()
: BasicPtrWrapper<T>()
, valueType(Class::getType())
{}
PolymorphicWrapper(const Type* const type)
: BasicPtrWrapper<T>()
, valueType(type)
{}
PolymorphicWrapper(const std::shared_ptr<T>& ptr, const Type* const type)
: BasicPtrWrapper<T>(ptr)
, valueType(type)
{}
PolymorphicWrapper(const PolymorphicWrapper& other)
: BasicPtrWrapper<T>(other)
, valueType(other.valueType)
{}
PolymorphicWrapper(PolymorphicWrapper&& other)
: BasicPtrWrapper<T>(std::move(other))
, valueType(other.valueType)
{}
static PolymorphicWrapper empty(){
return PolymorphicWrapper();
}
PolymorphicWrapper& operator=(const BasicPtrWrapper<T>& other){
BasicPtrWrapper<T>::operator = (other);
return *this;
}
PolymorphicWrapper& operator=(const BasicPtrWrapper<T>&& other){
BasicPtrWrapper<T>::operator = (std::move(other));
return *this;
}
PolymorphicWrapper& operator=(const PolymorphicWrapper<T>& other){
BasicPtrWrapper<T>::operator = (other);
return *this;
}
PolymorphicWrapper& operator=(const PolymorphicWrapper<T>&& other){
BasicPtrWrapper<T>::operator = (std::move(other));
return *this;
}
inline operator PolymorphicWrapper<oatpp::base::Controllable>() const {
return PolymorphicWrapper<oatpp::base::Controllable>(this->m_ptr, valueType);
explicit operator bool() const {
return m_ptr.operator bool();
}
const Type* const valueType;
};
template<class T, class F>
inline PolymorphicWrapper<T> static_wrapper_cast(const F& from){
return PolymorphicWrapper<T>(std::static_pointer_cast<T>(from.getPtr()));
}
template <class T, class Clazz>
class PtrWrapper : public PolymorphicWrapper<T>{
class ObjectWrapper : public PolymorphicWrapper<T>{
public:
typedef T ObjectType;
public:
typedef Clazz Class;
public:
PtrWrapper(const std::shared_ptr<T>& ptr, const type::Type* const valueType)
ObjectWrapper(const std::shared_ptr<T>& ptr, const type::Type* const valueType)
: PolymorphicWrapper<T>(ptr, Class::getType())
{
if(Class::getType() != valueType){
@ -204,51 +155,51 @@ public:
}
public:
PtrWrapper()
ObjectWrapper()
: PolymorphicWrapper<T>(Class::getType())
{}
PtrWrapper(const std::shared_ptr<T>& ptr)
ObjectWrapper(const std::shared_ptr<T>& ptr)
: PolymorphicWrapper<T>(ptr, Class::getType())
{}
PtrWrapper(const BasicPtrWrapper<T>& other)
: PolymorphicWrapper<T>(other, Class::getType())
ObjectWrapper(const PolymorphicWrapper<T>& other)
: PolymorphicWrapper<T>(other.m_ptr, Class::getType())
{}
PtrWrapper(BasicPtrWrapper<T>&& other)
: PolymorphicWrapper<T>(std::move(other), Class::getType())
ObjectWrapper(PolymorphicWrapper<T>&& other)
: PolymorphicWrapper<T>(std::move(other.getPtr()), Class::getType())
{}
static PtrWrapper empty(){
return PtrWrapper();
static ObjectWrapper empty(){
return ObjectWrapper();
}
PtrWrapper& operator=(const BasicPtrWrapper<T>& other){
ObjectWrapper& operator=(const PolymorphicWrapper<T>& other){
if(this->valueType != other.valueType){
OATPP_LOGE("PtrWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::PtrWrapper]: Invalid class cast");
OATPP_LOGE("ObjectWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::ObjectWrapper]: Invalid class cast");
}
PolymorphicWrapper<T>::operator = (other);
return *this;
}
PtrWrapper& operator=(const BasicPtrWrapper<T>&& other){
ObjectWrapper& operator=(const PolymorphicWrapper<T>&& other){
if(this->valueType != other.valueType){
OATPP_LOGE("PtrWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::PtrWrapper]: Invalid class cast");
OATPP_LOGE("ObjectWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::ObjectWrapper]: Invalid class cast");
}
PolymorphicWrapper<T>::operator = (std::move(other));
PolymorphicWrapper<T>::operator = (std::forward<PolymorphicWrapper<T>>(other));
return *this;
}
};
typedef PolymorphicWrapper<oatpp::base::Controllable> AbstractPtrWrapper;
typedef PolymorphicWrapper<oatpp::base::Controllable> AbstractObjectWrapper;
class Type {
public:
typedef AbstractPtrWrapper (*Creator)();
typedef AbstractObjectWrapper (*Creator)();
public:
class Property; // FWD
typedef std::unordered_map<std::string, Property*> Properties;
@ -273,15 +224,13 @@ public:
const char* const name;
const Type* const type;
void set(void* object, const BasicPtrWrapper<oatpp::base::Controllable>& value) {
BasicPtrWrapper<oatpp::base::Controllable>* property =
(BasicPtrWrapper<oatpp::base::Controllable>*)(((v_int64) object) + offset);
void set(void* object, const AbstractObjectWrapper& value) {
AbstractObjectWrapper* property = (AbstractObjectWrapper*)(((v_int64) object) + offset);
*property = value;
}
BasicPtrWrapper<oatpp::base::Controllable> get(void* object) {
BasicPtrWrapper<oatpp::base::Controllable>* property =
(BasicPtrWrapper<oatpp::base::Controllable>*)(((v_int64) object) + offset);
AbstractObjectWrapper get(void* object) {
AbstractObjectWrapper* property = (AbstractObjectWrapper*)(((v_int64) object) + offset);
return *property;
}

View File

@ -31,7 +31,7 @@
\
public: \
typedef TYPE_NAME Z__CLASS; \
typedef oatpp::data::mapping::type::PtrWrapper<Z__CLASS, oatpp::data::mapping::type::__class::Object<Z__CLASS>> PtrWrapper; \
typedef oatpp::data::mapping::type::ObjectWrapper<Z__CLASS, oatpp::data::mapping::type::__class::Object<Z__CLASS>> ObjectWrapper; \
public: \
OBJECT_POOL(DTO_OBJECT_POOL_##TYPE_NAME, TYPE_NAME, 32) \
SHARED_OBJECT_POOL(SHARED_DTO_OBJECT_POOL_##TYPE_NAME, TYPE_NAME, 32) \
@ -42,8 +42,8 @@ public: \
} \
public: \
\
static PtrWrapper createShared(){ \
return PtrWrapper(SHARED_DTO_OBJECT_POOL_##TYPE_NAME::allocateShared()); \
static ObjectWrapper createShared(){ \
return ObjectWrapper(SHARED_DTO_OBJECT_POOL_##TYPE_NAME::allocateShared()); \
} \
\
static oatpp::data::mapping::type::Type::Properties* Z__CLASS_GET_FIELDS_MAP(){ \
@ -51,8 +51,8 @@ public: \
return &map; \
} \
\
static oatpp::data::mapping::type::AbstractPtrWrapper Z__CLASS_OBJECT_CREATOR(){ \
return oatpp::data::mapping::type::AbstractPtrWrapper(SHARED_DTO_OBJECT_POOL_##TYPE_NAME::allocateShared(), Z__CLASS_GET_TYPE()); \
static oatpp::data::mapping::type::AbstractObjectWrapper Z__CLASS_OBJECT_CREATOR(){ \
return oatpp::data::mapping::type::AbstractObjectWrapper(SHARED_DTO_OBJECT_POOL_##TYPE_NAME::allocateShared(), Z__CLASS_GET_TYPE()); \
} \
\
static oatpp::data::mapping::type::Type* Z__CLASS_GET_TYPE(){ \
@ -68,11 +68,11 @@ public: \
\
oatpp::data::mapping::type::Type::Property* Z__CLASS_FIELD_##NAME = \
Z__CLASS_GET_FIELD_##NAME(static_cast<oatpp::base::Controllable*>(this), \
(oatpp::data::mapping::type::BasicPtrWrapper<oatpp::base::Controllable>*)(&NAME)); \
(oatpp::data::mapping::type::AbstractObjectWrapper*)(&NAME)); \
\
static oatpp::data::mapping::type::Type::Property* \
Z__CLASS_GET_FIELD_##NAME(oatpp::base::Controllable* _this, \
oatpp::data::mapping::type::BasicPtrWrapper<oatpp::base::Controllable>* _reg) { \
oatpp::data::mapping::type::AbstractObjectWrapper* _reg) { \
static oatpp::data::mapping::type::Type::Property* field = \
new oatpp::data::mapping::type::Type::Property(Z__CLASS_GET_FIELDS_MAP(), \
(v_int64) _reg - (v_int64) _this, \
@ -87,11 +87,11 @@ TYPE NAME
\
oatpp::data::mapping::type::Type::Property* Z__CLASS_FIELD_##NAME = \
Z__CLASS_GET_FIELD_##NAME(static_cast<oatpp::base::Controllable*>(this), \
(oatpp::data::mapping::type::BasicPtrWrapper<oatpp::base::Controllable>*)(&NAME)); \
(oatpp::data::mapping::type::AbstractObjectWrapper*)(&NAME)); \
\
static oatpp::data::mapping::type::Type::Property* \
Z__CLASS_GET_FIELD_##NAME(oatpp::base::Controllable* _this, \
oatpp::data::mapping::type::BasicPtrWrapper<oatpp::base::Controllable>* _reg) { \
oatpp::data::mapping::type::AbstractObjectWrapper* _reg) { \
static oatpp::data::mapping::type::Type::Property* field = \
new oatpp::data::mapping::type::Type::Property(Z__CLASS_GET_FIELDS_MAP(), \
(v_int64) _reg - (v_int64) _this, \

View File

@ -117,75 +117,75 @@ void Deserializer::skipValue(const std::shared_ptr<oatpp::parser::ParsingCaret>&
}
}
Deserializer::AbstractPtrWrapper Deserializer::readStringValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
Deserializer::AbstractObjectWrapper Deserializer::readStringValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper(String::Class::getType());
return AbstractObjectWrapper(String::Class::getType());
} else {
return AbstractPtrWrapper(oatpp::parser::json::Utils::parseString(caret), String::Class::getType());
return AbstractObjectWrapper(oatpp::parser::json::Utils::parseString(caret).getPtr(), String::Class::getType());
}
}
Deserializer::AbstractPtrWrapper Deserializer::readInt32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
Deserializer::AbstractObjectWrapper Deserializer::readInt32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper(Int32::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Int32::ObjectWrapper::Class::getType());
} else {
return AbstractPtrWrapper(Int32::ObjectType::createAbstract(caret->parseInt32()), Int32::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Int32::ObjectType::createAbstract(caret->parseInt32()), Int32::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractPtrWrapper Deserializer::readInt64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
Deserializer::AbstractObjectWrapper Deserializer::readInt64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper(Int64::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Int64::ObjectWrapper::Class::getType());
} else {
return AbstractPtrWrapper(Int64::ObjectType::createAbstract(caret->parseInt64()), Int64::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Int64::ObjectType::createAbstract(caret->parseInt64()), Int64::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractPtrWrapper Deserializer::readFloat32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
Deserializer::AbstractObjectWrapper Deserializer::readFloat32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper(Float32::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Float32::ObjectWrapper::Class::getType());
} else {
return AbstractPtrWrapper(Float32::ObjectType::createAbstract(caret->parseFloat32()), Float32::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Float32::ObjectType::createAbstract(caret->parseFloat32()), Float32::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractPtrWrapper Deserializer::readFloat64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
Deserializer::AbstractObjectWrapper Deserializer::readFloat64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper(Float64::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Float64::ObjectWrapper::Class::getType());
} else {
return AbstractPtrWrapper(Float64::ObjectType::createAbstract(caret->parseFloat64()), Float64::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Float64::ObjectType::createAbstract(caret->parseFloat64()), Float64::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractPtrWrapper Deserializer::readBooleanValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
Deserializer::AbstractObjectWrapper Deserializer::readBooleanValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper(Boolean::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Boolean::ObjectWrapper::Class::getType());
} else {
return AbstractPtrWrapper(Boolean::ObjectType::createAbstract(caret->parseBoolean("true", "false")), Boolean::PtrWrapper::Class::getType());
return AbstractObjectWrapper(Boolean::ObjectType::createAbstract(caret->parseBoolean("true", "false")), Boolean::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractPtrWrapper Deserializer::readObjectValue(const Type* const type,
Deserializer::AbstractObjectWrapper Deserializer::readObjectValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
} else {
return readObject(type, caret, config);
}
}
Deserializer::AbstractPtrWrapper Deserializer::readListValue(const Type* const type,
Deserializer::AbstractObjectWrapper Deserializer::readListValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config){
if(caret->proceedIfFollowsText("null")){
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
} else {
return readList(type, caret, config);
}
}
Deserializer::AbstractPtrWrapper Deserializer::readValue(const Type* const type,
Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config){
@ -210,11 +210,11 @@ Deserializer::AbstractPtrWrapper Deserializer::readValue(const Type* const type,
skipValue(caret);
}
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
Deserializer::AbstractPtrWrapper Deserializer::readList(const Type* type,
Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config){
@ -231,7 +231,7 @@ Deserializer::AbstractPtrWrapper Deserializer::readList(const Type* type,
caret->findNotBlankChar();
auto item = readValue(itemType, caret, config);
if(caret->hasError()){
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
list->addPolymorphicItem(item);
@ -245,18 +245,18 @@ Deserializer::AbstractPtrWrapper Deserializer::readList(const Type* type,
if(!caret->hasError()){
caret->setError(ERROR_PARSER_ARRAY_SCOPE_CLOSE);
}
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
};
return AbstractPtrWrapper(list.getPtr(), list.valueType);
return AbstractObjectWrapper(list.getPtr(), list.valueType);
} else {
caret->setError(ERROR_PARSER_ARRAY_SCOPE_OPEN);
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
}
Deserializer::AbstractPtrWrapper Deserializer::readObject(const Type* type,
Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config){
@ -270,7 +270,7 @@ Deserializer::AbstractPtrWrapper Deserializer::readObject(const Type* type,
caret->findNotBlankChar();
auto key = Utils::parseStringToStdString(caret);
if(caret->hasError()){
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
auto fieldIterator = fieldsMap->find(key);
@ -279,7 +279,7 @@ Deserializer::AbstractPtrWrapper Deserializer::readObject(const Type* type,
caret->findNotBlankChar();
if(!caret->canContinueAtChar(':', 1)){
caret->setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
caret->findNotBlankChar();
@ -291,13 +291,13 @@ Deserializer::AbstractPtrWrapper Deserializer::readObject(const Type* type,
caret->findNotBlankChar();
if(!caret->canContinueAtChar(':', 1)){
caret->setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
caret->findNotBlankChar();
skipValue(caret);
} else {
caret->setError(ERROR_PARSER_OBJECT_SCOPE_UNKNOWN_FIELD);
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
caret->findNotBlankChar();
@ -309,7 +309,7 @@ Deserializer::AbstractPtrWrapper Deserializer::readObject(const Type* type,
if(!caret->hasError()){
caret->setError(ERROR_PARSER_OBJECT_SCOPE_CLOSE);
}
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
return object;
@ -318,7 +318,7 @@ Deserializer::AbstractPtrWrapper Deserializer::readObject(const Type* type,
caret->setError(ERROR_PARSER_OBJECT_SCOPE_OPEN);
}
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}

View File

@ -43,7 +43,7 @@ public:
typedef oatpp::data::mapping::type::Type::Property Property;
typedef oatpp::data::mapping::type::Type::Properties Properties;
typedef oatpp::data::mapping::type::AbstractPtrWrapper AbstractPtrWrapper;
typedef oatpp::data::mapping::type::AbstractObjectWrapper AbstractObjectWrapper;
typedef oatpp::data::mapping::type::Object Object;
private:
@ -54,7 +54,7 @@ private:
typedef oatpp::data::mapping::type::Float64 Float64;
typedef oatpp::data::mapping::type::Boolean Boolean;
typedef oatpp::data::mapping::type::List<AbstractPtrWrapper> AbstractList;
typedef oatpp::data::mapping::type::List<AbstractObjectWrapper> AbstractList;
public:
@ -86,34 +86,34 @@ private:
static void skipToken(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static void skipValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readStringValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readInt32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readInt64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readFloat32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readFloat64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readBooleanValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readObjectValue(const Type* const type,
static AbstractObjectWrapper readStringValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractObjectWrapper readInt32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractObjectWrapper readInt64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractObjectWrapper readFloat32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractObjectWrapper readFloat64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractObjectWrapper readBooleanValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractObjectWrapper readObjectValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config);
static AbstractPtrWrapper readListValue(const Type* const type,
static AbstractObjectWrapper readListValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config);
static AbstractPtrWrapper readValue(const Type* const type,
static AbstractObjectWrapper readValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config);
static AbstractPtrWrapper readList(const Type* const type,
static AbstractObjectWrapper readList(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config);
static AbstractPtrWrapper readObject(const Type* const type,
static AbstractObjectWrapper readObject(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config);
public:
static AbstractPtrWrapper deserialize(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
static AbstractObjectWrapper deserialize(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const std::shared_ptr<Config>& config,
const Type* const type) {
if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME){
@ -121,7 +121,7 @@ public:
} else if(type->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME){
return readList(type, caret, config);
}
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
};

View File

@ -54,11 +54,11 @@ public:
}
void write(const std::shared_ptr<oatpp::data::stream::OutputStream>& stream,
const oatpp::data::mapping::type::AbstractPtrWrapper& variant) const override {
const oatpp::data::mapping::type::AbstractObjectWrapper& variant) const override {
Serializer::serialize(stream, variant);
}
oatpp::data::mapping::type::AbstractPtrWrapper
oatpp::data::mapping::type::AbstractObjectWrapper
read(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
const oatpp::data::mapping::type::Type* const type) const override {
return Deserializer::deserialize(caret, deserializerConfig, type);

View File

@ -35,7 +35,7 @@ void Serializer::writeString(oatpp::data::stream::OutputStream* stream,
stream->writeChar('\"');
stream->write(field->name);
stream->write("\": ", 3);
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
auto encodedValue = Utils::escapeString(value->getData(), value->getSize());
@ -53,7 +53,7 @@ void Serializer::writeObject(oatpp::data::stream::OutputStream* stream,
stream->writeChar('\"');
stream->write(field->name);
stream->write("\": ", 3);
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
writeObject(stream, field->type, value.get());
@ -76,7 +76,7 @@ void Serializer::writeListOfString(oatpp::data::stream::OutputStream* stream,
stream->write(", ", 2);
}
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
auto encodedValue = Utils::escapeString(value->getData(), value->getSize());
@ -108,7 +108,7 @@ void Serializer::writeListOfObject(oatpp::data::stream::OutputStream* stream,
stream->write(", ", 2);
}
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
writeObject(stream, type, value.get());
@ -137,7 +137,7 @@ void Serializer::writeListOfList(oatpp::data::stream::OutputStream* stream,
stream->write(", ", 2);
}
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
writeListCollection(stream, value.get(), type);
@ -184,7 +184,7 @@ void Serializer::writeList(oatpp::data::stream::OutputStream* stream,
stream->writeChar('\"');
stream->write(field->name);
stream->write("\": ", 3);
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
writeListCollection(stream, value.get(), field->type);

View File

@ -47,7 +47,7 @@ public:
typedef oatpp::data::mapping::type::Object Object;
typedef oatpp::data::mapping::type::List<
oatpp::data::mapping::type::AbstractPtrWrapper
oatpp::data::mapping::type::AbstractObjectWrapper
> AbstractList;
public:
@ -79,7 +79,7 @@ private:
stream->writeChar('\"');
stream->write(field->name);
stream->write("\": ", 3);
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
stream->writeAsString(value.get()->getValue());
@ -109,7 +109,7 @@ private:
stream->write(", ", 2);
}
if(value.isNull()){
if(!value){
stream->write("null", 4);
} else {
stream->writeAsString(value.get()->getValue());
@ -145,7 +145,7 @@ private:
public:
static void serialize(const std::shared_ptr<oatpp::data::stream::OutputStream>& stream,
const oatpp::data::mapping::type::AbstractPtrWrapper& object){
const oatpp::data::mapping::type::AbstractObjectWrapper& object){
auto type = object.valueType;
if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) {
writeObject(stream.get(), type, static_cast<Object*>(object.get()));

View File

@ -27,6 +27,8 @@
#include "oatpp/core/data/mapping/type/Primitive.hpp"
#include "oatpp/core/Types.hpp"
#include <unordered_map>
namespace oatpp { namespace test { namespace base {
namespace {
@ -64,13 +66,13 @@ namespace {
typedef oatpp::String String;
template<typename T>
using PtrWrapper = oatpp::data::mapping::type::BasicPtrWrapper<T>;
using ObjectWrapper = oatpp::data::mapping::type::PolymorphicWrapper<T>;
template<typename T>
using PolymorphicWrapper = oatpp::data::mapping::type::PolymorphicWrapper<T>;
template<typename T>
using TypePtrWrapper = oatpp::data::mapping::type::PtrWrapper<T, oatpp::data::mapping::type::__class::Void>;
using TypeObjectWrapper = oatpp::data::mapping::type::ObjectWrapper<T, oatpp::data::mapping::type::__class::Void>;
typedef oatpp::data::mapping::type::Int32 Int32;
typedef oatpp::data::mapping::type::Int64 Int64;
@ -85,62 +87,72 @@ bool RegRuleTest::onRun() {
{
String reg1("");
String reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
OATPP_ASSERT(reg1);
String reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
OATPP_ASSERT(!reg1);
String reg4 = String(100);
}
{
String reg1("");
String reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
OATPP_ASSERT(reg1);
String reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
OATPP_ASSERT(!reg1);
String reg4 = String(100) + "Leonid";
}
{
String reg1 = String(100);
String reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
OATPP_ASSERT(reg1);
String reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
OATPP_ASSERT(!reg1);
}
{
String reg1(String(100) + "Leonid");
String reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
OATPP_ASSERT(reg1);
String reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
OATPP_ASSERT(!reg1);
String reg4 = String(100);
}
{
String reg1 = String(100);
String reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
OATPP_ASSERT(reg1);
String reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
OATPP_ASSERT(!reg1);
}
{
String reg1 = String(100);
String reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
OATPP_ASSERT(reg1);
String reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
OATPP_ASSERT(!reg1);
}
{
String reg1 = String(100);
String reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
OATPP_ASSERT(reg1);
String reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
OATPP_ASSERT(!reg1);
}
std::unordered_map<String, String> map;
map["str_1"] = "val_1";
map["str_2"] = "val_2";
map["str_3"] = "val_3";
OATPP_ASSERT(map.find("str_1")->second == "val_1");
OATPP_ASSERT(map.find("str_2")->second == "val_2");
OATPP_ASSERT(map.find("str_3")->second == "val_3");
return true;
}

View File

@ -46,9 +46,9 @@ typedef oatpp::parser::json::mapping::Deserializer Deserializer;
DTO_FIELD(String, _string);
DTO_FIELD(Int32, _int32);
DTO_FIELD(List<Int32>::PtrWrapper, _list);
DTO_FIELD(List<Int32>::ObjectWrapper, _list);
static PtrWrapper createTestInstance(){
static ObjectWrapper createTestInstance(){
auto result = Test1::createShared();
result->_string = "String Field";
result->_int32 = 5;

View File

@ -44,7 +44,7 @@ class TestChild : public DTO {
DTO_INIT(TestChild, DTO)
static PtrWrapper createShared(const char* name, const char* secondName){
static ObjectWrapper createShared(const char* name, const char* secondName){
auto result = createShared();
result->name = name;
result->secondName = secondName;
@ -67,18 +67,18 @@ class Test : public DTO {
DTO_FIELD(Float64, _float64);
DTO_FIELD(Boolean, _boolean);
DTO_FIELD(List<String>::PtrWrapper, _list_string) = List<String>::createShared();
DTO_FIELD(List<Int32>::PtrWrapper, _list_int32) = List<Int32>::createShared();
DTO_FIELD(List<Int64>::PtrWrapper, _list_int64) = List<Int64>::createShared();
DTO_FIELD(List<Float32>::PtrWrapper, _list_float32) = List<Float32>::createShared();
DTO_FIELD(List<Float64>::PtrWrapper, _list_float64) = List<Float64>::createShared();
DTO_FIELD(List<Boolean>::PtrWrapper, _list_boolean) = List<Boolean>::createShared();
DTO_FIELD(List<String>::ObjectWrapper, _list_string) = List<String>::createShared();
DTO_FIELD(List<Int32>::ObjectWrapper, _list_int32) = List<Int32>::createShared();
DTO_FIELD(List<Int64>::ObjectWrapper, _list_int64) = List<Int64>::createShared();
DTO_FIELD(List<Float32>::ObjectWrapper, _list_float32) = List<Float32>::createShared();
DTO_FIELD(List<Float64>::ObjectWrapper, _list_float64) = List<Float64>::createShared();
DTO_FIELD(List<Boolean>::ObjectWrapper, _list_boolean) = List<Boolean>::createShared();
DTO_FIELD(List<TestChild::PtrWrapper>::PtrWrapper, _list_object) = List<TestChild::PtrWrapper>::createShared();
DTO_FIELD(List<List<TestChild::PtrWrapper>::PtrWrapper>::PtrWrapper, _list_list_object) = List<List<TestChild::PtrWrapper>::PtrWrapper>::createShared();
DTO_FIELD(List<TestChild::ObjectWrapper>::ObjectWrapper, _list_object) = List<TestChild::ObjectWrapper>::createShared();
DTO_FIELD(List<List<TestChild::ObjectWrapper>::ObjectWrapper>::ObjectWrapper, _list_list_object) = List<List<TestChild::ObjectWrapper>::ObjectWrapper>::createShared();
DTO_FIELD(Test::PtrWrapper, obj1);
DTO_FIELD(TestChild::PtrWrapper, child1);
DTO_FIELD(Test::ObjectWrapper, obj1);
DTO_FIELD(TestChild::ObjectWrapper, child1);
};
@ -90,7 +90,7 @@ bool DTOMapperTest::onRun(){
auto mapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
Test::PtrWrapper test1 = Test::createShared();
Test::ObjectWrapper test1 = Test::createShared();
test1->_string = "string value";
test1->_int32 = 32;
@ -137,9 +137,9 @@ bool DTOMapperTest::onRun(){
test1->_list_object->pushBack(TestChild::createShared("child", "2"));
test1->_list_object->pushBack(TestChild::createShared("child", "3"));
auto l1 = DTO::List<TestChild::PtrWrapper>::createShared();
auto l2 = DTO::List<TestChild::PtrWrapper>::createShared();
auto l3 = DTO::List<TestChild::PtrWrapper>::createShared();
auto l1 = DTO::List<TestChild::ObjectWrapper>::createShared();
auto l2 = DTO::List<TestChild::ObjectWrapper>::createShared();
auto l3 = DTO::List<TestChild::ObjectWrapper>::createShared();
l1->pushBack(TestChild::createShared("list_1", "item_1"));
l1->pushBack(TestChild::createShared("list_1", "item_2"));
@ -169,22 +169,22 @@ bool DTOMapperTest::onRun(){
auto caret = oatpp::parser::ParsingCaret::createShared(result);
auto obj = mapper->readFromCaret<Test>(caret);
OATPP_ASSERT(obj->_string.isNull() == false);
OATPP_ASSERT(obj->_string.equals(test1->_string));
OATPP_ASSERT(obj->_string);
OATPP_ASSERT(obj->_string == test1->_string);
OATPP_ASSERT(obj->_int32.isNull() == false);
OATPP_ASSERT(obj->_int32);
OATPP_ASSERT(obj->_int32->getValue() == test1->_int32->getValue());
OATPP_ASSERT(obj->_int64.isNull() == false);
OATPP_ASSERT(obj->_int64);
OATPP_ASSERT(obj->_int64->getValue() == test1->_int64->getValue());
OATPP_ASSERT(obj->_float32.isNull() == false);
OATPP_ASSERT(obj->_float32);
OATPP_ASSERT(obj->_float32->getValue() == test1->_float32->getValue());
OATPP_ASSERT(obj->_float64.isNull() == false);
OATPP_ASSERT(obj->_float64);
OATPP_ASSERT(obj->_float64->getValue() == test1->_float64->getValue());
OATPP_ASSERT(obj->_boolean.isNull() == false);
OATPP_ASSERT(obj->_boolean);
OATPP_ASSERT(obj->_boolean->getValue() == test1->_boolean->getValue());
result = mapper->writeToString(obj);

View File

@ -72,73 +72,73 @@ bool DeserializerTest::onRun(){
auto obj1 = mapper->readFromString<Test1>("{}");
OATPP_ASSERT(obj1.isNull() == false);
OATPP_ASSERT(obj1->strF.isNull());
OATPP_ASSERT(obj1);
OATPP_ASSERT(!obj1->strF);
obj1 = mapper->readFromString<Test1>("{\"strF\":\"value1\"}");
OATPP_ASSERT(obj1.isNull() == false);
OATPP_ASSERT(obj1->strF.isNull() == false);
OATPP_ASSERT(obj1);
OATPP_ASSERT(obj1->strF);
OATPP_ASSERT(obj1->strF->equals("value1"));
obj1 = mapper->readFromString<Test1>("{\n\r\t\f\"strF\"\n\r\t\f:\n\r\t\f\"value1\"\n\r\t\f}");
OATPP_ASSERT(obj1.isNull() == false);
OATPP_ASSERT(obj1->strF.isNull() == false);
OATPP_ASSERT(obj1);
OATPP_ASSERT(obj1->strF);
OATPP_ASSERT(obj1->strF->equals("value1"));
auto obj2 = mapper->readFromString<Test2>("{\"int32F\": null}");
OATPP_ASSERT(obj2.isNull() == false);
OATPP_ASSERT(obj2->int32F.isNull() == true);
OATPP_ASSERT(obj2);
OATPP_ASSERT(!obj2->int32F);
obj2 = mapper->readFromString<Test2>("{\"int32F\": 32}");
OATPP_ASSERT(obj2.isNull() == false);
OATPP_ASSERT(obj2);
OATPP_ASSERT(obj2->int32F->getValue() == 32);
obj2 = mapper->readFromString<Test2>("{\"int32F\": -32}");
OATPP_ASSERT(obj2.isNull() == false);
OATPP_ASSERT(obj2);
OATPP_ASSERT(obj2->int32F->getValue() == -32);
auto obj3 = mapper->readFromString<Test3>("{\"float32F\": null}");
OATPP_ASSERT(obj3.isNull() == false);
OATPP_ASSERT(obj3->float32F.isNull() == true);
OATPP_ASSERT(obj3);
OATPP_ASSERT(!obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 32}");
OATPP_ASSERT(obj3.isNull() == false);
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F->getValue() == 32);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 1.32e1}");
OATPP_ASSERT(obj3.isNull() == false);
OATPP_ASSERT(obj3->float32F.isNull() == false);
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 1.32e+1 }");
OATPP_ASSERT(obj3.isNull() == false);
OATPP_ASSERT(obj3->float32F.isNull() == false);
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 1.32e-1 }");
OATPP_ASSERT(obj3.isNull() == false);
OATPP_ASSERT(obj3->float32F.isNull() == false);
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": -1.32E-1 }");
OATPP_ASSERT(obj3.isNull() == false);
OATPP_ASSERT(obj3->float32F.isNull() == false);
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": -1.32E1 }");
OATPP_ASSERT(obj3.isNull() == false);
OATPP_ASSERT(obj3->float32F.isNull() == false);
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
auto list = mapper->readFromString<Test1::List<Test1::Int32>>("[1, 2, 3]");
OATPP_ASSERT(list.isNull() == false);
OATPP_ASSERT(list);
OATPP_ASSERT(list->count() == 3);
OATPP_ASSERT(list->get(0)->getValue() == 1);
OATPP_ASSERT(list->get(1)->getValue() == 2);

View File

@ -79,8 +79,8 @@ void ApiClient::formatPath(oatpp::data::stream::OutputStream* stream,
stream->write(seg.text.data(), seg.text.size());
} else {
auto key = oatpp::String((p_char8) seg.text.data(), (v_int32) seg.text.length(), false);
auto& param = params->get(key, oatpp::data::mapping::type::AbstractPtrWrapper::empty());
if(param.isNull()){
auto& param = params->get(key, oatpp::data::mapping::type::AbstractObjectWrapper::empty());
if(!param){
OATPP_LOGD(TAG, "Path parameter '%s' not provided in the api call", (const char*) seg.text.c_str());
throw std::runtime_error("[oatpp::web::client::ApiClient]: Path parameter missing");
}

View File

@ -57,7 +57,7 @@ public:
protected:
typedef oatpp::collection::ListMap<
oatpp::String,
oatpp::data::mapping::type::AbstractPtrWrapper
oatpp::data::mapping::type::AbstractObjectWrapper
> StringToParamMap;
protected:
typedef std::unordered_map<std::string, oatpp::String> PathVariablesMap;

View File

@ -88,12 +88,12 @@ void BodyDecoder::decode(const std::shared_ptr<Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::OutputStream>& toStream) {
auto transferEncoding = headers->get(Header::TRANSFER_ENCODING, nullptr);
if(!transferEncoding.isNull() && transferEncoding->equals(Header::Value::TRANSFER_ENCODING_CHUNKED)) {
if(transferEncoding && transferEncoding->equals(Header::Value::TRANSFER_ENCODING_CHUNKED)) {
doChunkedDecoding(bodyStream, toStream);
} else {
oatpp::os::io::Library::v_size contentLength = 0;
auto contentLengthStr = headers->get(Header::CONTENT_LENGTH, nullptr);
if(contentLengthStr.isNull()) {
if(!contentLengthStr) {
return; // DO NOTHING // it is an empty or invalid body
} else {
bool success;
@ -221,12 +221,12 @@ oatpp::async::Action BodyDecoder::decodeAsync(oatpp::async::AbstractCoroutine* p
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<oatpp::data::stream::OutputStream>& toStream) {
auto transferEncoding = headers->get(Header::TRANSFER_ENCODING, nullptr);
if(!transferEncoding.isNull() && transferEncoding->equals(Header::Value::TRANSFER_ENCODING_CHUNKED)) {
if(transferEncoding && transferEncoding->equals(Header::Value::TRANSFER_ENCODING_CHUNKED)) {
return doChunkedDecodingAsync(parentCoroutine, actionOnReturn, bodyStream, toStream);
} else {
oatpp::os::io::Library::v_size contentLength = 0;
auto contentLengthStr = headers->get(Header::CONTENT_LENGTH, nullptr);
if(contentLengthStr.isNull()) {
if(!contentLengthStr) {
return actionOnReturn; // DO NOTHING // it is an empty or invalid body
} else {
bool success;

View File

@ -58,7 +58,7 @@ private:
};
template<class Type>
class ToDtoDecoder : public oatpp::async::CoroutineWithResult<ToDtoDecoder<Type>, typename Type::PtrWrapper> {
class ToDtoDecoder : public oatpp::async::CoroutineWithResult<ToDtoDecoder<Type>, typename Type::ObjectWrapper> {
private:
std::shared_ptr<Protocol::Headers> m_headers;
std::shared_ptr<oatpp::data::stream::InputStream> m_bodyStream;
@ -113,7 +113,7 @@ public:
}
template<class Type>
static typename Type::PtrWrapper decodeToDto(const std::shared_ptr<Protocol::Headers>& headers,
static typename Type::ObjectWrapper decodeToDto(const std::shared_ptr<Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper){
return objectMapper->readFromString<Type>(decodeToString(headers, bodyStream));
@ -139,7 +139,7 @@ public:
template<class DtoType, typename ParentCoroutineType>
static oatpp::async::Action
decodeToDtoAsync(oatpp::async::AbstractCoroutine* parentCoroutine,
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::PtrWrapper&),
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::ObjectWrapper&),
const std::shared_ptr<Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) {

View File

@ -89,13 +89,13 @@ public:
}
template<class Type>
typename Type::PtrWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return objectMapper->readFromString<Type>
(protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream));
}
template<class Type>
void readBodyToDto(oatpp::data::mapping::type::BasicPtrWrapper<Type>& objectWrapper,
void readBodyToDto(oatpp::data::mapping::type::PolymorphicWrapper<Type>& objectWrapper,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
objectWrapper = objectMapper->readFromString<Type>
(protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream));
@ -117,7 +117,7 @@ public:
template<class DtoType, typename ParentCoroutineType>
oatpp::async::Action readBodyToDtoAsync(oatpp::async::AbstractCoroutine* parentCoroutine,
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::PtrWrapper&),
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::ObjectWrapper&),
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return protocol::http::incoming::BodyDecoder::decodeToDtoAsync<DtoType>(parentCoroutine, callback, headers, bodyStream, objectMapper);
}

View File

@ -67,7 +67,7 @@ public:
}
template<class Type>
typename Type::PtrWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return objectMapper->readFromString<Type>
(protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream));
}
@ -88,7 +88,7 @@ public:
template<class DtoType, typename ParentCoroutineType>
oatpp::async::Action readBodyToDtoAsync(oatpp::async::AbstractCoroutine* parentCoroutine,
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::PtrWrapper&),
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::ObjectWrapper&),
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return protocol::http::incoming::BodyDecoder::decodeToDtoAsync<DtoType>(parentCoroutine, callback, headers, bodyStream, objectMapper);
}

View File

@ -37,10 +37,10 @@ public:
OBJECT_POOL(Http_Outgoing_DtoBody_Pool, DtoBody, 32)
SHARED_OBJECT_POOL(Shared_Http_Outgoing_DtoBody_Pool, DtoBody, 32)
private:
oatpp::data::mapping::type::AbstractPtrWrapper m_dto;
oatpp::data::mapping::type::AbstractObjectWrapper m_dto;
oatpp::data::mapping::ObjectMapper* m_objectMapper;
public:
DtoBody(const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
DtoBody(const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
oatpp::data::mapping::ObjectMapper* objectMapper,
bool chunked)
: ChunkedBufferBody(oatpp::data::stream::ChunkedBuffer::createShared(), chunked)
@ -49,19 +49,19 @@ public:
{}
public:
static std::shared_ptr<DtoBody> createShared(const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
static std::shared_ptr<DtoBody> createShared(const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
oatpp::data::mapping::ObjectMapper* objectMapper) {
return Shared_Http_Outgoing_DtoBody_Pool::allocateShared(dto, objectMapper, false);
}
static std::shared_ptr<DtoBody> createShared(const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
static std::shared_ptr<DtoBody> createShared(const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
oatpp::data::mapping::ObjectMapper* objectMapper,
bool chunked) {
return Shared_Http_Outgoing_DtoBody_Pool::allocateShared(dto, objectMapper, chunked);
}
void declareHeaders(const std::shared_ptr<Headers>& headers) override {
if(m_dto.isNull()) {
if(!m_dto) {
throw std::runtime_error("Sending null object");
}
m_objectMapper->write(m_buffer, m_dto);

View File

@ -42,7 +42,7 @@ ResponseFactory::createShared(const Status& status, const std::shared_ptr<oatpp:
std::shared_ptr<Response>
ResponseFactory::createShared(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
oatpp::data::mapping::ObjectMapper* objectMapper) {
return Response::createShared(status, DtoBody::createShared(dto, objectMapper));
}

View File

@ -39,7 +39,7 @@ public:
static std::shared_ptr<Response> createShared(const Status& status, const oatpp::String& text);
static std::shared_ptr<Response> createShared(const Status& status, const std::shared_ptr<oatpp::data::stream::ChunkedBuffer>& segBuffer);
static std::shared_ptr<Response> createShared(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
oatpp::data::mapping::ObjectMapper* objectMapper);
};

View File

@ -35,19 +35,19 @@ bool HttpProcessor::considerConnectionKeepAlive(const std::shared_ptr<protocol::
if(request) {
auto& inKeepAlive = request->headers->get(protocol::http::Header::CONNECTION, nullptr);
if(!inKeepAlive.isNull() && oatpp::base::StrBuffer::equalsCI_FAST(inKeepAlive.get(), protocol::http::Header::Value::CONNECTION_KEEP_ALIVE)) {
if(inKeepAlive && oatpp::base::StrBuffer::equalsCI_FAST(inKeepAlive.get(), protocol::http::Header::Value::CONNECTION_KEEP_ALIVE)) {
if(response->headers->putIfNotExists(protocol::http::Header::CONNECTION, inKeepAlive)){
return true;
} else {
auto& outKeepAlive = response->headers->get(protocol::http::Header::CONNECTION, nullptr);
return (!outKeepAlive.isNull() && oatpp::base::StrBuffer::equalsCI_FAST(outKeepAlive.get(), protocol::http::Header::Value::CONNECTION_KEEP_ALIVE));
return (outKeepAlive && oatpp::base::StrBuffer::equalsCI_FAST(outKeepAlive.get(), protocol::http::Header::Value::CONNECTION_KEEP_ALIVE));
}
}
}
if(!response->headers->putIfNotExists(protocol::http::Header::CONNECTION, protocol::http::Header::Value::CONNECTION_CLOSE)) {
auto& outKeepAlive = response->headers->get(protocol::http::Header::CONNECTION, nullptr);
return (!outKeepAlive.isNull() && oatpp::base::StrBuffer::equalsCI_FAST(outKeepAlive.get(), protocol::http::Header::Value::CONNECTION_KEEP_ALIVE));
return (outKeepAlive && oatpp::base::StrBuffer::equalsCI_FAST(outKeepAlive.get(), protocol::http::Header::Value::CONNECTION_KEEP_ALIVE));
}
return false;

View File

@ -203,13 +203,13 @@ public:
}
std::shared_ptr<OutgoingResponse> createDtoResponse(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return OutgoingResponseFactory::createShared(status, dto, objectMapper.get());
}
std::shared_ptr<OutgoingResponse> createDtoResponse(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto) const {
const oatpp::data::mapping::type::AbstractObjectWrapper& dto) const {
return OutgoingResponseFactory::createShared(status, dto, m_defaultObjectMapper.get());
}

View File

@ -33,15 +33,15 @@ oatpp::String Endpoint::Info::toString() {
stream << "\nEndpoint\n";
if(!name.isNull()) {
if(name) {
stream << "name: '" << name << "'\n";
}
if(!path.isNull()){
if(path){
stream << "path: '" << path << "'\n";
}
if(!method.isNull()){
if(method){
stream << "method: '" << method << "'\n";
}