diff --git a/core/base/PtrWrapper.cpp b/core/Types.cpp similarity index 97% rename from core/base/PtrWrapper.cpp rename to core/Types.cpp index 73b4537a..1942f55f 100644 --- a/core/base/PtrWrapper.cpp +++ b/core/Types.cpp @@ -22,4 +22,4 @@ * ***************************************************************************/ -#include "PtrWrapper.hpp" +#include "Types.hpp" diff --git a/core/Types.hpp b/core/Types.hpp new file mode 100644 index 00000000..7da1f764 --- /dev/null +++ b/core/Types.hpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * + * Project _____ __ ____ _ _ + * ( _ ) /__\ (_ _)_| |_ _| |_ + * )(_)( /(__)\ )( (_ _)(_ _) + * (_____)(__)(__)(__) |_| |_| + * + * + * Copyright 2018-present, Leonid Stryzhevskyi, + * + * 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 { + + 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; + typedef oatpp::data::mapping::type::Float64 Float64; + typedef oatpp::data::mapping::type::Boolean Boolean; + +} + +#endif /* oatpp_Types_hpp */ diff --git a/core/base/Environment.hpp b/core/base/Environment.hpp index d80f8194..9f470b80 100644 --- a/core/base/Environment.hpp +++ b/core/base/Environment.hpp @@ -32,6 +32,7 @@ #include #include +#define OATPP_VERSION "0.18.6" #define OATPP_ASSERT(EXP) \ if(!(EXP)) { \ diff --git a/core/base/PtrWrapper.hpp b/core/base/PtrWrapper.hpp deleted file mode 100644 index 5ae9ba34..00000000 --- a/core/base/PtrWrapper.hpp +++ /dev/null @@ -1,105 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi, - * - * 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_base_PtrWrapper -#define oatpp_base_PtrWrapper - -#include "Controllable.hpp" - -namespace oatpp { namespace base { - -template -class PtrWrapper { -protected: - std::shared_ptr m_ptr; -public: - - PtrWrapper() {} - - PtrWrapper(const std::shared_ptr& ptr) - : m_ptr(ptr) - {} - - PtrWrapper(std::shared_ptr&& ptr) - : m_ptr(std::move(ptr)) - {} - - PtrWrapper(const PtrWrapper& other) - : m_ptr(other.m_ptr) - {} - - PtrWrapper(PtrWrapper&& other) - : m_ptr(std::move(other.m_ptr)) - {} - - PtrWrapper& operator = (const PtrWrapper& other){ - m_ptr = other.m_ptr; - return *this; - } - - PtrWrapper& operator = (PtrWrapper&& other){ - m_ptr = std::move(other.m_ptr); - return *this; - } - - T* operator->() const { - return m_ptr.operator->(); - } - - T* get() const { - return m_ptr.get(); - } - - std::shared_ptr getPtr() const { - return m_ptr; - } - - bool isNull() const { - return m_ptr.get() == nullptr; - } - - static const PtrWrapper& empty(){ - static PtrWrapper empty; - return empty; - } - - inline bool operator == (const PtrWrapper& other){ - return m_ptr.get() == other.m_ptr.get(); - } - - inline bool operator != (const PtrWrapper& other){ - return m_ptr.get() != other.m_ptr.get(); - } - -}; - -template -inline PtrWrapper static_wrapper_cast(const F& from){ - return PtrWrapper(std::static_pointer_cast(from.getPtr())); -} - -}} - - -#endif /* oatpp_base_PtrWrapper */ diff --git a/core/base/String.cpp b/core/base/StrBuffer.cpp similarity index 59% rename from core/base/String.cpp rename to core/base/StrBuffer.cpp index 041521a0..19ec4ee0 100644 --- a/core/base/String.cpp +++ b/core/base/StrBuffer.cpp @@ -22,17 +22,17 @@ * ***************************************************************************/ -#include "String.hpp" +#include "StrBuffer.hpp" namespace oatpp { namespace base { -void String::set(const void* data, v_int32 size, bool hasOwnData) { +void StrBuffer::set(const void* data, v_int32 size, bool hasOwnData) { m_data = (p_char8) data; m_size = size; m_hasOwnData = hasOwnData; } -void String::setAndCopy(const void* data, const void* originData, v_int32 size){ +void StrBuffer::setAndCopy(const void* data, const void* originData, v_int32 size){ m_data = (p_char8) data; m_size = size; //m_hasOwnData = false; @@ -42,17 +42,17 @@ void String::setAndCopy(const void* data, const void* originData, v_int32 size){ m_data[size] = 0; } -std::shared_ptr String::allocShared(const void* data, v_int32 size, bool copyAsOwnData) { +std::shared_ptr StrBuffer::allocShared(const void* data, v_int32 size, bool copyAsOwnData) { if(copyAsOwnData) { memory::AllocationExtras extras(size + 1); - const auto& ptr = memory::allocateSharedWithExtras(extras); + const auto& ptr = memory::allocateSharedWithExtras(extras); ptr->setAndCopy(extras.extraPtr, data, size); return ptr; } - return std::make_shared(data, size, copyAsOwnData); + return std::make_shared(data, size, copyAsOwnData); } -p_char8 String::allocString(const void* originData, v_int32 size, bool copyAsOwnData) { +p_char8 StrBuffer::allocStrBuffer(const void* originData, v_int32 size, bool copyAsOwnData) { if(copyAsOwnData) { p_char8 data = new v_char8[size + 1]; data[size] = 0; @@ -64,102 +64,94 @@ p_char8 String::allocString(const void* originData, v_int32 size, bool copyAsOwn return (p_char8) originData; } -String::~String() { +StrBuffer::~StrBuffer() { if(m_hasOwnData) { delete [] m_data; } m_data = nullptr; } -std::shared_ptr String::createShared(const void* data, v_int32 size, bool copyAsOwnData) { +std::shared_ptr StrBuffer::createShared(const void* data, v_int32 size, bool copyAsOwnData) { return allocShared(data, size, copyAsOwnData); } -std::shared_ptr String::createShared(const char* data, bool copyAsOwnData) { +std::shared_ptr StrBuffer::createShared(const char* data, bool copyAsOwnData) { return allocShared(data, (v_int32) std::strlen(data), copyAsOwnData); } -std::shared_ptr String::createShared(String* other, bool copyAsOwnData) { +std::shared_ptr StrBuffer::createShared(StrBuffer* other, bool copyAsOwnData) { return allocShared(other->getData(), other->getSize(), copyAsOwnData); } -std::shared_ptr String::createShared(v_int32 size) { +std::shared_ptr StrBuffer::createShared(v_int32 size) { return allocShared(nullptr, size, true); } -std::shared_ptr String::createSharedConcatenated(const void* data1, v_int32 size1, const void* data2, v_int32 size2) { +std::shared_ptr StrBuffer::createSharedConcatenated(const void* data1, v_int32 size1, const void* data2, v_int32 size2) { const auto& ptr = allocShared(nullptr, size1 + size2, true); std::memcpy(ptr->m_data, data1, size1); std::memcpy(ptr->m_data + size1, data2, size2); return ptr; } -p_char8 String::getData() const { +p_char8 StrBuffer::getData() const { return m_data; } -v_int32 String::getSize() const { +v_int32 StrBuffer::getSize() const { return m_size; } -const char* String::c_str() const { +const char* StrBuffer::c_str() const { return (const char*) m_data; } -std::string String::std_str() const { +std::string StrBuffer::std_str() const { return std::string((const char*) m_data, m_size); } -bool String::hasOwnData() const { +bool StrBuffer::hasOwnData() const { return m_hasOwnData; } -std::shared_ptr String::toLowerCase() const { +std::shared_ptr StrBuffer::toLowerCase() const { const auto& ptr = allocShared(m_data, m_size, true); lowerCase(ptr->m_data, ptr->m_size); return ptr; } -std::shared_ptr String::toUpperCase() const { +std::shared_ptr StrBuffer::toUpperCase() const { const auto& ptr = allocShared(m_data, m_size, true); upperCase(ptr->m_data, ptr->m_size); return ptr; } -bool String::equals(const void* data, v_int32 size) const { +bool StrBuffer::equals(const void* data, v_int32 size) const { if(m_size == size) { return equals(m_data, data, size); } return false; } -bool String::equals(const char* data) const { +bool StrBuffer::equals(const char* data) const { if(m_size == (v_int32) std::strlen(data)) { return equals(m_data, data, m_size); } return false; } -bool String::equals(String* other) const { - return equals((String*) this, other); -} - -bool String::equals(const String::PtrWrapper& other) const { - return equals((String*) this, other.get()); +bool StrBuffer::equals(StrBuffer* other) const { + return equals((StrBuffer*) this, other); } -bool String::equals(const std::shared_ptr& other) const { - return equals((String*) this, other.get()); -} - -bool String::startsWith(const void* data, v_int32 size) const { +bool StrBuffer::startsWith(const void* data, v_int32 size) const { if(m_size >= size) { return equals(m_data, data, size); } return false; } -bool String::startsWith(const char* data) const { +bool StrBuffer::startsWith(const char* data) const { v_int32 length = (v_int32) std::strlen(data); if(m_size >= length) { return equals(m_data, data, length); @@ -167,7 +159,7 @@ bool String::startsWith(const char* data) const { return false; } -bool String::startsWith(String* data) const { +bool StrBuffer::startsWith(StrBuffer* data) const { if(m_size >= data->m_size) { return equals(m_data, data, data->m_size); } @@ -176,11 +168,11 @@ bool String::startsWith(String* data) const { // static -v_int32 String::compare(const void* data1, const void* data2, v_int32 size) { +v_int32 StrBuffer::compare(const void* data1, const void* data2, v_int32 size) { return std::memcmp(data1, data2, size); } -v_int32 String::compare(String* str1, String* str2) { +v_int32 StrBuffer::compare(StrBuffer* str1, StrBuffer* str2) { if(str1 == str2) { return 0; } @@ -191,25 +183,25 @@ v_int32 String::compare(String* str1, String* str2) { } } -bool String::equals(const void* data1, const void* data2, v_int32 size) { +bool StrBuffer::equals(const void* data1, const void* data2, v_int32 size) { return (data1 == data2) || (std::memcmp(data1, data2, size) == 0); } -bool String::equals(const char* data1, const char* data2) { +bool StrBuffer::equals(const char* data1, const char* data2) { if(data1 == data2) return true; if(data1 == nullptr && data2 == nullptr) return false; v_int32 size = (v_int32) std::strlen(data1); return (size == (v_int32) std::strlen(data2) && std::memcmp(data1, data2, size) == 0); } -bool String::equals(String* str1, String* str2) { +bool StrBuffer::equals(StrBuffer* str1, StrBuffer* str2) { return (str1 == str2) || (str1 != nullptr && str2 != nullptr && str1->m_size == str2->m_size && (str1->m_data == str2->m_data || std::memcmp(str1->m_data, str2->m_data, str1->m_size) == 0) ); } -bool String::equalsCI(const void* data1, const void* data2, v_int32 size) { +bool StrBuffer::equalsCI(const void* data1, const void* data2, v_int32 size) { for(v_int32 i = 0; i < size; i++) { v_char8 a = ((p_char8) data1) [i]; v_char8 b = ((p_char8) data2) [i]; @@ -222,21 +214,21 @@ bool String::equalsCI(const void* data1, const void* data2, v_int32 size) { return true; } -bool String::equalsCI(const char* data1, const char* data2) { +bool StrBuffer::equalsCI(const char* data1, const char* data2) { if(data1 == data2) return true; if(data1 == nullptr && data2 == nullptr) return false; v_int32 size = (v_int32) std::strlen(data1); return (size == (v_int32) std::strlen(data2) && equalsCI(data1, data2, size) == 0); } -bool String::equalsCI(String* str1, String* str2) { +bool StrBuffer::equalsCI(StrBuffer* str1, StrBuffer* str2) { return (str1 == str2) || (str1 != nullptr && str2 != nullptr && str1->m_size == str2->m_size && (str1->m_data == str2->m_data || equalsCI(str1->m_data, str2->m_data, str1->m_size)) ); } -bool String::equalsCI_FAST(const void* data1, const void* data2, v_int32 size) { +bool StrBuffer::equalsCI_FAST(const void* data1, const void* data2, v_int32 size) { for(v_int32 i = 0; i < size; i++) { if((((p_char8) data1) [i] | 32) != (((p_char8) data2) [i] | 32)) { return false; @@ -245,59 +237,37 @@ bool String::equalsCI_FAST(const void* data1, const void* data2, v_int32 size) { return true; } -bool String::equalsCI_FAST(const char* data1, const char* data2) { +bool StrBuffer::equalsCI_FAST(const char* data1, const char* data2) { if(data1 == data2) return true; if(data1 == nullptr && data2 == nullptr) return false; v_int32 size = (v_int32) std::strlen(data1); return (size == (v_int32) std::strlen(data2) && equalsCI_FAST(data1, data2, size) == 0); } -bool String::equalsCI_FAST(String* str1, String* str2) { +bool StrBuffer::equalsCI_FAST(StrBuffer* str1, StrBuffer* str2) { return (str1 == str2) || (str1 != nullptr && str2 != nullptr && str1->m_size == str2->m_size && (str1->m_data == str2->m_data || equalsCI_FAST(str1->m_data, str2->m_data, str1->m_size)) ); } -bool String::equalsCI_FAST(const String::PtrWrapper& str1, const char* str2) { +bool StrBuffer::equalsCI_FAST(StrBuffer* str1, const char* str2) { v_int32 len = (v_int32) std::strlen(str2); return (str1->getSize() == len && equalsCI_FAST(str1->m_data, str2, str1->m_size)); } -void String::lowerCase(const void* data, v_int32 size) { +void StrBuffer::lowerCase(const void* data, v_int32 size) { for(v_int32 i = 0; i < size; i++) { v_char8 a = ((p_char8) data)[i]; if(a >= 'A' && a <= 'Z') ((p_char8) data)[i] = a | 32; } } -void String::upperCase(const void* data, v_int32 size) { +void StrBuffer::upperCase(const void* data, v_int32 size) { for(v_int32 i = 0; i < size; i++) { v_char8 a = ((p_char8) data)[i]; if(a >= 'a' && a <= 'z') ((p_char8) data)[i] = a & 223; } } - -// Operator - -oatpp::base::PtrWrapper operator + (const char* a, const oatpp::base::PtrWrapper& b){ - return String::createSharedConcatenated(a, (v_int32) std::strlen(a), b->getData(), b->getSize()); -} - -oatpp::base::PtrWrapper operator + (const oatpp::base::PtrWrapper& b, const char* a){ - return String::createSharedConcatenated(b->getData(), b->getSize(), a, (v_int32) std::strlen(a)); -} - -oatpp::base::PtrWrapper operator + (const oatpp::base::PtrWrapper& a, const oatpp::base::PtrWrapper& b) { - return String::createSharedConcatenated(a->getData(), a->getSize(), b->getData(), b->getSize()); -} - -std::shared_ptr operator + (const char* a, const std::shared_ptr& b){ - return String::createSharedConcatenated(a, (v_int32) std::strlen(a), b->getData(), b->getSize()); -} - -std::shared_ptr operator + (const std::shared_ptr& b, const char* a){ - return String::createSharedConcatenated(b->getData(), b->getSize(), a, (v_int32) std::strlen(a)); -} - + }} diff --git a/core/base/StrBuffer.hpp b/core/base/StrBuffer.hpp new file mode 100644 index 00000000..f5375ba8 --- /dev/null +++ b/core/base/StrBuffer.hpp @@ -0,0 +1,146 @@ +/*************************************************************************** + * + * Project _____ __ ____ _ _ + * ( _ ) /__\ (_ _)_| |_ _| |_ + * )(_)( /(__)\ )( (_ _)(_ _) + * (_____)(__)(__)(__) |_| |_| + * + * + * Copyright 2018-present, Leonid Stryzhevskyi, + * + * 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_base_StrBuffer_hpp +#define oatpp_base_StrBuffer_hpp + +#include "memory/ObjectPool.hpp" +#include "./Controllable.hpp" + +#include // c + +namespace oatpp { namespace base { + +class StrBuffer : public oatpp::base::Controllable { +public: + OBJECT_POOL_THREAD_LOCAL(StrBuffer_Pool, StrBuffer, 32) +private: + p_char8 m_data; + v_int32 m_size; + bool m_hasOwnData; +private: + + void set(const void* data, v_int32 size, bool hasOwnData); + void setAndCopy(const void* data, const void* originData, v_int32 size); + static std::shared_ptr allocShared(const void* data, v_int32 size, bool copyAsOwnData); + + /** + * Allocate memory for string or use originData + * if copyAsOwnData == false return originData + */ + static p_char8 allocStrBuffer(const void* originData, v_int32 size, bool copyAsOwnData); + +public: + StrBuffer() + : m_data((p_char8)"[]") + , m_size(11) + , m_hasOwnData(false) + {} + + StrBuffer(const void* data, v_int32 size, bool copyAsOwnData) + : m_data(allocStrBuffer(data, size, copyAsOwnData)) + , m_size(size) + , m_hasOwnData(copyAsOwnData) + {} +public: + + virtual ~StrBuffer(); + + static std::shared_ptr createShared(v_int32 size); + static std::shared_ptr createShared(const void* data, v_int32 size, bool copyAsOwnData = true); + static std::shared_ptr createShared(const char* data, bool copyAsOwnData = true); + static std::shared_ptr createShared(StrBuffer* other, bool copyAsOwnData = true); + + static std::shared_ptr createSharedConcatenated(const void* data1, v_int32 size1, const void* data2, v_int32 size2); + + static std::shared_ptr createFromCString(const char* data, bool copyAsOwnData = true) { + if(data != nullptr) { + return allocShared(data, (v_int32) std::strlen(data), copyAsOwnData); + } + return nullptr; + } + + p_char8 getData() const; + v_int32 getSize() const; + + const char* c_str() const; + std::string std_str() const; + + bool hasOwnData() const; + + /** + * (correct for ACII only) + */ + std::shared_ptr toLowerCase() const; + + /** + * (correct for ACII only) + */ + std::shared_ptr toUpperCase() const; + + bool equals(const void* data, v_int32 size) const; + bool equals(const char* data) const; + bool equals(StrBuffer* other) const; + + bool startsWith(const void* data, v_int32 size) const; + bool startsWith(const char* data) const; + bool startsWith(StrBuffer* data) const; + +public: + + static v_int32 compare(const void* data1, const void* data2, v_int32 size); + static v_int32 compare(StrBuffer* str1, StrBuffer* str2); + + static bool equals(const void* data1, const void* data2, v_int32 size); + static bool equals(const char* data1, const char* data2); + static bool equals(StrBuffer* str1, StrBuffer* str2); + + // Case Insensitive (correct for ASCII only) + + static bool equalsCI(const void* data1, const void* data2, v_int32 size); + static bool equalsCI(const char* data1, const char* data2); + static bool equalsCI(StrBuffer* str1, StrBuffer* str2); + + // Case Insensitive Fast (ASCII only, correct compare if one of strings contains letters only) + + static bool equalsCI_FAST(const void* data1, const void* data2, v_int32 size); + static bool equalsCI_FAST(const char* data1, const char* data2); + static bool equalsCI_FAST(StrBuffer* str1, StrBuffer* str2); + static bool equalsCI_FAST(StrBuffer* str1, const char* str2); + + /** + * lower case chars in the buffer @data (correct for ACII only) + */ + static void lowerCase(const void* data, v_int32 size); + + /** + * upper case chars in the buffer @data (correct for ACII only) + */ + static void upperCase(const void* data, v_int32 size); + +}; + +}} + +#endif /* oatpp_base_StrBuffer_hpp */ diff --git a/core/base/String.hpp b/core/base/String.hpp deleted file mode 100644 index 5ec61747..00000000 --- a/core/base/String.hpp +++ /dev/null @@ -1,213 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi, - * - * 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_base_String_hpp -#define oatpp_base_String_hpp - -#include "memory/ObjectPool.hpp" -#include "./Controllable.hpp" -#include "./PtrWrapper.hpp" - -#include // c - -namespace oatpp { namespace base { - -class String : public oatpp::base::Controllable { -public: - - class PtrWrapper : public oatpp::base::PtrWrapper { - public: - - PtrWrapper() {} - - PtrWrapper(const std::shared_ptr& ptr) - : oatpp::base::PtrWrapper(ptr) - {} - - PtrWrapper(std::shared_ptr&& ptr) - : oatpp::base::PtrWrapper(std::move(ptr)) - {} - - PtrWrapper(const char* str) - : oatpp::base::PtrWrapper(createFromCString(str)) - {} - - PtrWrapper(const oatpp::base::PtrWrapper& other) - : oatpp::base::PtrWrapper(other) - {} - - PtrWrapper(oatpp::base::PtrWrapper&& other) - : oatpp::base::PtrWrapper(std::move(other)) - {} - - PtrWrapper& operator = (const char* str) { - m_ptr = String::createFromCString(str); - return *this; - } - - PtrWrapper& operator = (const oatpp::base::PtrWrapper& other){ - oatpp::base::PtrWrapper::operator=(other); - return *this; - } - - PtrWrapper& operator = (oatpp::base::PtrWrapper&& other){ - oatpp::base::PtrWrapper::operator=(std::move(other)); - return *this; - } - - PtrWrapper operator + (const char* str) const{ - return String::createSharedConcatenated(m_ptr.get()->m_data, m_ptr.get()->m_size, str, (v_int32) std::strlen(str)); - } - - PtrWrapper operator + (const oatpp::base::PtrWrapper& other) const{ - return String::createSharedConcatenated(m_ptr.get()->m_data, m_ptr.get()->m_size, other.get()->m_data, other.get()->m_size); - } - - static const PtrWrapper& empty(){ - static PtrWrapper empty; - return empty; - } - - }; - -public: - OBJECT_POOL_THREAD_LOCAL(String_Pool, String, 32) -private: - p_char8 m_data; - v_int32 m_size; - bool m_hasOwnData; -private: - - void set(const void* data, v_int32 size, bool hasOwnData); - void setAndCopy(const void* data, const void* originData, v_int32 size); - static std::shared_ptr allocShared(const void* data, v_int32 size, bool copyAsOwnData); - - /** - * Allocate memory for string or use originData - * if copyAsOwnData == false return originData - */ - static p_char8 allocString(const void* originData, v_int32 size, bool copyAsOwnData); - -public: - String() - : m_data((p_char8)"[]") - , m_size(11) - , m_hasOwnData(false) - {} - - String(const void* data, v_int32 size, bool copyAsOwnData) - : m_data(allocString(data, size, copyAsOwnData)) - , m_size(size) - , m_hasOwnData(copyAsOwnData) - {} -public: - - virtual ~String(); - - static std::shared_ptr createShared(v_int32 size); - static std::shared_ptr createShared(const void* data, v_int32 size, bool copyAsOwnData = true); - static std::shared_ptr createShared(const char* data, bool copyAsOwnData = true); - static std::shared_ptr createShared(String* other, bool copyAsOwnData = true); - - static std::shared_ptr createSharedConcatenated(const void* data1, v_int32 size1, const void* data2, v_int32 size2); - - static std::shared_ptr createFromCString(const char* data, bool copyAsOwnData = true) { - if(data != nullptr) { - return allocShared(data, (v_int32) std::strlen(data), copyAsOwnData); - } - return nullptr; - } - - p_char8 getData() const; - v_int32 getSize() const; - - const char* c_str() const; - std::string std_str() const; - - bool hasOwnData() const; - - /** - * (correct for ACII only) - */ - std::shared_ptr toLowerCase() const; - - /** - * (correct for ACII only) - */ - std::shared_ptr toUpperCase() const; - - bool equals(const void* data, v_int32 size) const; - bool equals(const char* data) const; - bool equals(String* other) const; - bool equals(const String::PtrWrapper& other) const; - bool equals(const std::shared_ptr& other) const; - - bool startsWith(const void* data, v_int32 size) const; - bool startsWith(const char* data) const; - bool startsWith(String* data) const; - -public: - - static v_int32 compare(const void* data1, const void* data2, v_int32 size); - static v_int32 compare(String* str1, String* str2); - - static bool equals(const void* data1, const void* data2, v_int32 size); - static bool equals(const char* data1, const char* data2); - static bool equals(String* str1, String* str2); - - // Case Insensitive (correct for ASCII only) - - static bool equalsCI(const void* data1, const void* data2, v_int32 size); - static bool equalsCI(const char* data1, const char* data2); - static bool equalsCI(String* str1, String* str2); - - // Case Insensitive Fast (ASCII only, correct compare if one of strings contains letters only) - - static bool equalsCI_FAST(const void* data1, const void* data2, v_int32 size); - static bool equalsCI_FAST(const char* data1, const char* data2); - static bool equalsCI_FAST(String* str1, String* str2); - static bool equalsCI_FAST(const String::PtrWrapper& str1, const char* str2); - - /** - * lower case chars in the buffer @data (correct for ACII only) - */ - static void lowerCase(const void* data, v_int32 size); - - /** - * upper case chars in the buffer @data (correct for ACII only) - */ - static void upperCase(const void* data, v_int32 size); - -}; - -oatpp::base::PtrWrapper operator + (const char* a, const oatpp::base::PtrWrapper& b); -oatpp::base::PtrWrapper operator + (const oatpp::base::PtrWrapper& b, const char* a); -oatpp::base::PtrWrapper operator + (const oatpp::base::PtrWrapper& a, const oatpp::base::PtrWrapper& b); - -std::shared_ptr operator + (const char* a, const std::shared_ptr& b); -std::shared_ptr operator + (const std::shared_ptr& b, const char* a); - -}} - -#endif /* oatpp_base_String_hpp */ diff --git a/core/collection/LinkedList.hpp b/core/collection/LinkedList.hpp index 70e72ce9..0f9e61b5 100644 --- a/core/collection/LinkedList.hpp +++ b/core/collection/LinkedList.hpp @@ -27,7 +27,7 @@ #include "oatpp/core/base/memory/ObjectPool.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" + #include "oatpp/core/base/Controllable.hpp" #include "oatpp/core/base/Environment.hpp" diff --git a/core/collection/ListMap.hpp b/core/collection/ListMap.hpp index dd62ddc7..e215a2f6 100644 --- a/core/collection/ListMap.hpp +++ b/core/collection/ListMap.hpp @@ -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; diff --git a/core/concurrency/Runnable.hpp b/core/concurrency/Runnable.hpp index 8fde5bd3..e45fd570 100644 --- a/core/concurrency/Runnable.hpp +++ b/core/concurrency/Runnable.hpp @@ -25,7 +25,7 @@ #ifndef concurrency_Runnable_hpp #define concurrency_Runnable_hpp -#include "oatpp/core/base/PtrWrapper.hpp" + namespace oatpp { namespace concurrency { diff --git a/core/concurrency/Thread.hpp b/core/concurrency/Thread.hpp index 6a8e781e..df1e0366 100644 --- a/core/concurrency/Thread.hpp +++ b/core/concurrency/Thread.hpp @@ -30,7 +30,7 @@ #include "oatpp/core/base/memory/ObjectPool.hpp" #include "oatpp/core/base/Controllable.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" + #include #include diff --git a/core/data/buffer/IOBuffer.hpp b/core/data/buffer/IOBuffer.hpp index 5bff3869..60164063 100644 --- a/core/data/buffer/IOBuffer.hpp +++ b/core/data/buffer/IOBuffer.hpp @@ -27,7 +27,7 @@ #include "oatpp/core/base/memory/ObjectPool.hpp" #include "oatpp/core/base/Controllable.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" + namespace oatpp { namespace data{ namespace buffer { diff --git a/core/data/mapping/ObjectMapper.hpp b/core/data/mapping/ObjectMapper.hpp index 91f7434e..f5d9f3ff 100644 --- a/core/data/mapping/ObjectMapper.hpp +++ b/core/data/mapping/ObjectMapper.hpp @@ -58,28 +58,28 @@ public: } virtual void write(const std::shared_ptr& stream, - const type::AbstractPtrWrapper& variant) const = 0; + const type::AbstractObjectWrapper& variant) const = 0; - virtual type::AbstractPtrWrapper read(const std::shared_ptr& caret, + virtual type::AbstractObjectWrapper read(oatpp::parser::ParsingCaret& caret, const type::Type* const type) const = 0; - std::shared_ptr 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 - typename Class::PtrWrapper readFromCaret(const std::shared_ptr& caret) const { - auto type = Class::PtrWrapper::Class::getType(); - return oatpp::base::static_wrapper_cast(read(caret, type)); + typename Class::ObjectWrapper readFromCaret(oatpp::parser::ParsingCaret& caret) const { + auto type = Class::ObjectWrapper::Class::getType(); + return oatpp::data::mapping::type::static_wrapper_cast(read(caret, type)); } template - typename Class::PtrWrapper readFromString(const oatpp::base::String::PtrWrapper& str) const { - auto type = Class::PtrWrapper::Class::getType(); - auto caret = oatpp::parser::ParsingCaret::createShared(str.getPtr()); - return oatpp::base::static_wrapper_cast(read(caret, type)); + typename Class::ObjectWrapper readFromString(const oatpp::String& str) const { + auto type = Class::ObjectWrapper::Class::getType(); + oatpp::parser::ParsingCaret caret(str); + return oatpp::data::mapping::type::static_wrapper_cast(read(caret, type)); } }; diff --git a/core/data/mapping/type/List.hpp b/core/data/mapping/type/List.hpp index 99d2545c..38736613 100644 --- a/core/data/mapping/type/List.hpp +++ b/core/data/mapping/type/List.hpp @@ -31,8 +31,6 @@ #include "oatpp/core/base/memory/ObjectPool.hpp" #include "oatpp/core/base/Controllable.hpp" -#include "oatpp/core/base/String.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" namespace oatpp { namespace data { namespace mapping { namespace type { @@ -52,14 +50,14 @@ template class List : public oatpp::collection::LinkedList { friend __class::List; public: - typedef oatpp::data::mapping::type::PtrWrapper> PtrWrapper; + typedef oatpp::data::mapping::type::ObjectWrapper> 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(item.getPtr()); this->pushBack(T(ptr, item.valueType)); } diff --git a/core/data/mapping/type/Object.hpp b/core/data/mapping/type/Object.hpp index 0588667b..fb2a1ff4 100644 --- a/core/data/mapping/type/Object.hpp +++ b/core/data/mapping/type/Object.hpp @@ -32,8 +32,6 @@ #include "oatpp/core/base/memory/ObjectPool.hpp" #include "oatpp/core/base/Controllable.hpp" -#include "oatpp/core/base/String.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" namespace oatpp { namespace data { namespace mapping { namespace type { @@ -59,12 +57,12 @@ namespace __class { class Object : public oatpp::base::Controllable { public: - typedef oatpp::data::mapping::type::StringPtrWrapper String; - typedef oatpp::data::mapping::type::Int32::PtrWrapper Int32; - typedef oatpp::data::mapping::type::Int64::PtrWrapper Int64; - typedef oatpp::data::mapping::type::Float32::PtrWrapper Float32; - typedef oatpp::data::mapping::type::Float64::PtrWrapper Float64; - typedef oatpp::data::mapping::type::Boolean::PtrWrapper Boolean; + 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; + typedef oatpp::data::mapping::type::Float64 Float64; + typedef oatpp::data::mapping::type::Boolean Boolean; template using List = oatpp::data::mapping::type::List; protected: diff --git a/core/data/mapping/type/Primitive.cpp b/core/data/mapping/type/Primitive.cpp index c4d80980..54e45b16 100644 --- a/core/data/mapping/type/Primitive.cpp +++ b/core/data/mapping/type/Primitive.cpp @@ -24,42 +24,49 @@ #include "./Primitive.hpp" +#include "oatpp/core/utils/ConversionUtils.hpp" + namespace oatpp { namespace data { namespace mapping { namespace type { -StringPtrWrapper::StringPtrWrapper(const std::shared_ptr& ptr, const type::Type* const valueType) - : oatpp::data::mapping::type::PtrWrapper(ptr) +String::String(const std::shared_ptr& ptr, const type::Type* const valueType) + : oatpp::data::mapping::type::ObjectWrapper(ptr) { if(type::__class::String::getType() != valueType) { throw std::runtime_error("Value type does not match"); } } -StringPtrWrapper::operator std::string() const { - if(m_ptr){ - return m_ptr->std_str(); - } - return ""; +String operator + (const char* a, const String& b) { + return oatpp::base::StrBuffer::createSharedConcatenated(a, (v_int32) std::strlen(a), b->getData(), b->getSize()); +} + +String operator + (const String& b, const char* a) { + return oatpp::base::StrBuffer::createSharedConcatenated(b->getData(), b->getSize(), a, (v_int32) std::strlen(a)); +} + +String operator + (const String& a, const String& b) { + return oatpp::base::StrBuffer::createSharedConcatenated(a->getData(), a->getSize(), b->getData(), b->getSize()); } namespace __class { - type::Int32::PtrWrapper Int32::parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success) { + type::Int32 Int32::parseFromString(const oatpp::String& str, bool& success) { return utils::conversion::strToInt32(str, success); } - type::Int64::PtrWrapper Int64::parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success) { + type::Int64 Int64::parseFromString(const oatpp::String& str, bool& success) { return utils::conversion::strToInt64(str, success); } - type::Float32::PtrWrapper Float32::parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success) { + type::Float32 Float32::parseFromString(const oatpp::String& str, bool& success) { return utils::conversion::strToFloat32(str, success); } - type::Float64::PtrWrapper Float64::parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success) { + type::Float64 Float64::parseFromString(const oatpp::String& str, bool& success) { return utils::conversion::strToFloat64(str, success); } - type::Boolean::PtrWrapper Boolean::parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success) { + type::Boolean Boolean::parseFromString(const oatpp::String& str, bool& success) { return utils::conversion::strToBool(str, success); } diff --git a/core/data/mapping/type/Primitive.hpp b/core/data/mapping/type/Primitive.hpp index 7c755bbf..7c9f24bc 100644 --- a/core/data/mapping/type/Primitive.hpp +++ b/core/data/mapping/type/Primitive.hpp @@ -27,13 +27,11 @@ #include "./Type.hpp" -#include "oatpp/core/utils/ConversionUtils.hpp" - #include "oatpp/core/base/memory/ObjectPool.hpp" #include "oatpp/core/base/Controllable.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/base/StrBuffer.hpp" + -#include "oatpp/core/base/PtrWrapper.hpp" namespace oatpp { namespace data { namespace mapping { namespace type { @@ -47,76 +45,84 @@ namespace __class { class Boolean; // FWD } - -class StringPtrWrapper : public oatpp::data::mapping::type::PtrWrapper { + +class String : public oatpp::data::mapping::type::ObjectWrapper { public: - StringPtrWrapper(const std::shared_ptr& ptr, const type::Type* const valueType); + String(const std::shared_ptr& ptr, const type::Type* const valueType); public: - StringPtrWrapper() {} + String() {} - StringPtrWrapper(const std::shared_ptr& ptr) - : type::PtrWrapper(ptr) + String(v_int32 size) + : oatpp::data::mapping::type::ObjectWrapper(oatpp::base::StrBuffer::createShared(size)) {} - StringPtrWrapper(std::shared_ptr&& ptr) - : type::PtrWrapper(std::move(ptr)) + String(const char* data, v_int32 size, bool copyAsOwnData = true) + : oatpp::data::mapping::type::ObjectWrapper(oatpp::base::StrBuffer::createShared(data, size, copyAsOwnData)) {} - StringPtrWrapper(const char* str) - : type::PtrWrapper(oatpp::base::String::createFromCString(str)) + String(const char* data1, v_int32 size1, const char* data2, v_int32 size2) + : oatpp::data::mapping::type::ObjectWrapper(oatpp::base::StrBuffer::createSharedConcatenated(data1, size1, data2, size2)) {} - StringPtrWrapper(const std::string& str) - : type::PtrWrapper - (oatpp::base::String::createShared(str.data(), str.size())) + String(const char* data, bool copyAsOwnData = true) + : oatpp::data::mapping::type::ObjectWrapper(oatpp::base::StrBuffer::createFromCString(data, copyAsOwnData)) {} - StringPtrWrapper(const oatpp::base::PtrWrapper& other) - : type::PtrWrapper(other) + String(const std::shared_ptr& ptr) + : oatpp::data::mapping::type::ObjectWrapper(ptr) {} - StringPtrWrapper(oatpp::base::PtrWrapper&& other) - : type::PtrWrapper(std::move(other)) + String(std::shared_ptr&& ptr) + : oatpp::data::mapping::type::ObjectWrapper(std::forward>(ptr)) {} - StringPtrWrapper& operator = (const char* str) { - m_ptr = oatpp::base::String::createFromCString(str); + String(const String& other) + : oatpp::data::mapping::type::ObjectWrapper(other) + {} + + String(String&& other) + : oatpp::data::mapping::type::ObjectWrapper(std::forward(other)) + {} + + String& operator = (const char* str) { + m_ptr = oatpp::base::StrBuffer::createFromCString(str); return *this; } - StringPtrWrapper& operator = (const std::string& str) { - m_ptr = oatpp::base::String::createShared(str.data(), str.size()); + String& operator = (const String& other){ + m_ptr = other.m_ptr; return *this; } - StringPtrWrapper& operator = (const oatpp::base::PtrWrapper& other){ - oatpp::base::PtrWrapper::operator=(other); + String& operator = (String&& other){ + m_ptr = std::forward>(other.m_ptr); return *this; } - StringPtrWrapper& operator = (oatpp::base::PtrWrapper&& other){ - oatpp::base::PtrWrapper::operator=(std::move(other)); - return *this; - } - - StringPtrWrapper operator + (const char* str) const{ - return oatpp::base::String::createSharedConcatenated(m_ptr.get()->getData(), m_ptr.get()->getSize(), str, (v_int32) std::strlen(str)); - } - - StringPtrWrapper operator + (const oatpp::base::PtrWrapper& other) const{ - return oatpp::base::String::createSharedConcatenated(m_ptr.get()->getData(), m_ptr.get()->getSize(), other.get()->getData(), other.get()->getSize()); - } - - operator std::string() const; - - static const StringPtrWrapper& empty(){ - static StringPtrWrapper empty; + static const String& empty(){ + static String empty; return empty; } + bool operator==(const String &other) const { + return m_ptr->equals(other.get()); + } + + bool operator!=(const String &other) const { + return !m_ptr->equals(other.get()); + } + + explicit operator bool() const { + return m_ptr.operator bool(); + } + }; - + +String operator + (const char* a, const String& b); +String operator + (const String& b, const char* a); +String operator + (const String& a, const String& b); + template class Primitive : public oatpp::base::Controllable { public: @@ -124,10 +130,10 @@ public: SHARED_OBJECT_POOL(Shared_Primitive_Type_Pool, Primitive, 32) public: - class PtrWrapper : public oatpp::data::mapping::type::PtrWrapper { + class ObjectWrapper : public oatpp::data::mapping::type::ObjectWrapper { public: - PtrWrapper(const std::shared_ptr& ptr, const type::Type* const valueType) - : oatpp::data::mapping::type::PtrWrapper(ptr) + ObjectWrapper(const std::shared_ptr& ptr, const type::Type* const valueType) + : oatpp::data::mapping::type::ObjectWrapper(ptr) { if(Clazz::getType() != valueType){ throw std::runtime_error("Value type does not match"); @@ -135,32 +141,32 @@ public: } public: - PtrWrapper() - : oatpp::data::mapping::type::PtrWrapper() + ObjectWrapper() + : oatpp::data::mapping::type::ObjectWrapper() {} - PtrWrapper(const std::shared_ptr& ptr) - : oatpp::data::mapping::type::PtrWrapper(ptr) + ObjectWrapper(const std::shared_ptr& ptr) + : oatpp::data::mapping::type::ObjectWrapper(ptr) {} - PtrWrapper(std::shared_ptr&& ptr) - : oatpp::data::mapping::type::PtrWrapper(std::move(ptr)) + ObjectWrapper(std::shared_ptr&& ptr) + : oatpp::data::mapping::type::ObjectWrapper(std::move(ptr)) {} - PtrWrapper(const PtrWrapper& other) - : oatpp::data::mapping::type::PtrWrapper(other) + ObjectWrapper(const ObjectWrapper& other) + : oatpp::data::mapping::type::ObjectWrapper(other) {} - PtrWrapper(PtrWrapper&& other) - : oatpp::data::mapping::type::PtrWrapper(std::move(other)) + ObjectWrapper(ObjectWrapper&& other) + : oatpp::data::mapping::type::ObjectWrapper(std::move(other)) {} - PtrWrapper(const ValueType& value) - : oatpp::data::mapping::type::PtrWrapper(Primitive::createShared(value)) + ObjectWrapper(const ValueType& value) + : oatpp::data::mapping::type::ObjectWrapper(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); @@ -168,12 +174,20 @@ public: return *this; } + bool operator==(const ObjectWrapper &other) const { + return getValue() == other->getValue(); + } + + 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; } @@ -207,12 +221,11 @@ public: }; - -typedef Primitive Int32; -typedef Primitive Int64; -typedef Primitive Float32; -typedef Primitive Float64; -typedef Primitive Boolean; +typedef Primitive::ObjectWrapper Int32; +typedef Primitive::ObjectWrapper Int64; +typedef Primitive::ObjectWrapper Float32; +typedef Primitive::ObjectWrapper Float64; +typedef Primitive::ObjectWrapper Boolean; namespace __class { @@ -225,7 +238,7 @@ namespace __class { return &type; } - static type::StringPtrWrapper parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success){ + static oatpp::data::mapping::type::String parseFromString(const oatpp::data::mapping::type::String& str, bool& success){ success = true; return str; } @@ -241,7 +254,7 @@ namespace __class { return &type; } - static type::Int32::PtrWrapper parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success); + static type::Int32 parseFromString(const oatpp::data::mapping::type::String& str, bool& success); }; @@ -254,7 +267,7 @@ namespace __class { return &type; } - static type::Int64::PtrWrapper parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success); + static type::Int64 parseFromString(const oatpp::data::mapping::type::String& str, bool& success); }; @@ -267,7 +280,7 @@ namespace __class { return &type; } - static type::Float32::PtrWrapper parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success); + static type::Float32 parseFromString(const oatpp::data::mapping::type::String& str, bool& success); }; @@ -280,7 +293,7 @@ namespace __class { return &type; } - static type::Float64::PtrWrapper parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success); + static type::Float64 parseFromString(const oatpp::data::mapping::type::String& str, bool& success); }; @@ -293,32 +306,42 @@ namespace __class { return &type; } - static type::Boolean::PtrWrapper parseFromString(const oatpp::base::String::PtrWrapper& str, bool& success); + static type::Boolean parseFromString(const oatpp::data::mapping::type::String& str, bool& success); }; } -template -base::PtrWrapper -primitiveToStr(const oatpp::data::mapping::type::PolymorphicWrapper& primitive) { - auto type = primitive.valueType; - if(type == oatpp::data::mapping::type::__class::String::getType()) { - return std::static_pointer_cast(primitive.getPtr()); - } else if(type == oatpp::data::mapping::type::__class::Int32::getType()) { - return utils::conversion::int32ToStr(static_cast(primitive.get())->getValue()); - } else if(type == oatpp::data::mapping::type::__class::Int64::getType()) { - return utils::conversion::int64ToStr(static_cast(primitive.get())->getValue()); - } else if(type == oatpp::data::mapping::type::__class::Float32::getType()) { - return utils::conversion::float32ToStr(static_cast(primitive.get())->getValue()); - } else if(type == oatpp::data::mapping::type::__class::Float64::getType()) { - return utils::conversion::float64ToStr(static_cast(primitive.get())->getValue()); - } else if(type == oatpp::data::mapping::type::__class::Boolean::getType()) { - return utils::conversion::boolToStr(static_cast(primitive.get())->getValue()); - } - throw std::runtime_error("[oatpp::data::mapping::type::primitiveToStr]: Invalid primitive type"); -} - }}}} +namespace std { + + template<> + struct hash { + + 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 */ diff --git a/core/data/mapping/type/Type.hpp b/core/data/mapping/type/Type.hpp index e717d9d8..a7a8045d 100644 --- a/core/data/mapping/type/Type.hpp +++ b/core/data/mapping/type/Type.hpp @@ -25,7 +25,7 @@ #ifndef oatpp_data_type_Type_hpp #define oatpp_data_type_Type_hpp -#include "oatpp/core/base/PtrWrapper.hpp" +#include "oatpp/core/base/Controllable.hpp" #include #include @@ -44,45 +44,47 @@ namespace __class { } template -class PolymorphicWrapper : public oatpp::base::PtrWrapper { +class PolymorphicWrapper { +protected: + std::shared_ptr m_ptr; public: typedef T ObjectType; public: typedef __class::Void Class; public: - PolymorphicWrapper(const oatpp::base::PtrWrapper& other, const Type* const type) - : oatpp::base::PtrWrapper(other) - , valueType(type) - {} - PolymorphicWrapper(oatpp::base::PtrWrapper&& other, const Type* const type) - : oatpp::base::PtrWrapper(std::move(other)) - , valueType(type) - {} -public: - - PolymorphicWrapper() - : oatpp::base::PtrWrapper() + PolymorphicWrapper(const std::shared_ptr& ptr) + : m_ptr(ptr) , valueType(Class::getType()) {} - PolymorphicWrapper(const Type* const type) - : oatpp::base::PtrWrapper() + PolymorphicWrapper(const std::shared_ptr& ptr, const Type* const type) + : m_ptr(ptr) , valueType(type) {} - PolymorphicWrapper(const std::shared_ptr& ptr, const Type* const type) - : oatpp::base::PtrWrapper(ptr) + PolymorphicWrapper(std::shared_ptr&& ptr, const Type* const type) + : m_ptr(std::move(ptr)) , valueType(type) {} +public: + + PolymorphicWrapper() + : valueType(Class::getType()) + {} + + PolymorphicWrapper(const Type* const type) + : valueType(type) + {} + PolymorphicWrapper(const PolymorphicWrapper& other) - : oatpp::base::PtrWrapper(other) + : m_ptr(other.m_ptr) , valueType(other.valueType) {} PolymorphicWrapper(PolymorphicWrapper&& other) - : oatpp::base::PtrWrapper(std::move(other)) + : m_ptr(std::move(other.m_ptr)) , valueType(other.valueType) {} @@ -90,23 +92,13 @@ public: return PolymorphicWrapper(); } - PolymorphicWrapper& operator=(const oatpp::base::PtrWrapper& other){ - oatpp::base::PtrWrapper::operator = (other); - return *this; - } - - PolymorphicWrapper& operator=(const oatpp::base::PtrWrapper&& other){ - oatpp::base::PtrWrapper::operator = (std::move(other)); - return *this; - } - PolymorphicWrapper& operator=(const PolymorphicWrapper& other){ - oatpp::base::PtrWrapper::operator = (other); + m_ptr = other.m_ptr; return *this; } PolymorphicWrapper& operator=(const PolymorphicWrapper&& other){ - oatpp::base::PtrWrapper::operator = (std::move(other)); + m_ptr = std::move(other.m_ptr); return *this; } @@ -114,18 +106,47 @@ public: return PolymorphicWrapper(this->m_ptr, valueType); } + T* operator->() const { + return m_ptr.operator->(); + } + + T* get() const { + return m_ptr.get(); + } + + std::shared_ptr getPtr() const { + return m_ptr; + } + + inline bool operator == (const PolymorphicWrapper& other){ + return m_ptr.get() == other.m_ptr.get(); + } + + inline bool operator != (const PolymorphicWrapper& other){ + return m_ptr.get() != other.m_ptr.get(); + } + + explicit operator bool() const { + return m_ptr.operator bool(); + } + const Type* const valueType; }; +template +inline PolymorphicWrapper static_wrapper_cast(const F& from){ + return PolymorphicWrapper(std::static_pointer_cast(from.getPtr())); +} + template -class PtrWrapper : public PolymorphicWrapper{ +class ObjectWrapper : public PolymorphicWrapper{ public: typedef T ObjectType; public: typedef Clazz Class; public: - PtrWrapper(const std::shared_ptr& ptr, const type::Type* const valueType) + ObjectWrapper(const std::shared_ptr& ptr, const type::Type* const valueType) : PolymorphicWrapper(ptr, Class::getType()) { if(Class::getType() != valueType){ @@ -134,51 +155,51 @@ public: } public: - PtrWrapper() + ObjectWrapper() : PolymorphicWrapper(Class::getType()) {} - PtrWrapper(const std::shared_ptr& ptr) + ObjectWrapper(const std::shared_ptr& ptr) : PolymorphicWrapper(ptr, Class::getType()) {} - PtrWrapper(const oatpp::base::PtrWrapper& other) - : PolymorphicWrapper(other, Class::getType()) + ObjectWrapper(const PolymorphicWrapper& other) + : PolymorphicWrapper(other.m_ptr, Class::getType()) {} - PtrWrapper(oatpp::base::PtrWrapper&& other) - : PolymorphicWrapper(std::move(other), Class::getType()) + ObjectWrapper(PolymorphicWrapper&& other) + : PolymorphicWrapper(std::move(other.getPtr()), Class::getType()) {} - static PtrWrapper empty(){ - return PtrWrapper(); + static ObjectWrapper empty(){ + return ObjectWrapper(); } - PtrWrapper& operator=(const oatpp::base::PtrWrapper& other){ + ObjectWrapper& operator=(const PolymorphicWrapper& 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::operator = (other); return *this; } - PtrWrapper& operator=(const oatpp::base::PtrWrapper&& other){ + ObjectWrapper& operator=(const PolymorphicWrapper&& 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::operator = (std::move(other)); + PolymorphicWrapper::operator = (std::forward>(other)); return *this; } }; -typedef PolymorphicWrapper AbstractPtrWrapper; +typedef PolymorphicWrapper AbstractObjectWrapper; class Type { public: - typedef AbstractPtrWrapper (*Creator)(); + typedef AbstractObjectWrapper (*Creator)(); public: class Property; // FWD typedef std::unordered_map Properties; @@ -203,15 +224,13 @@ public: const char* const name; const Type* const type; - void set(void* object, const oatpp::base::PtrWrapper& value) { - oatpp::base::PtrWrapper* property = - (oatpp::base::PtrWrapper*)(((v_int64) object) + offset); + void set(void* object, const AbstractObjectWrapper& value) { + AbstractObjectWrapper* property = (AbstractObjectWrapper*)(((v_int64) object) + offset); *property = value; } - oatpp::base::PtrWrapper get(void* object) { - oatpp::base::PtrWrapper* property = - (oatpp::base::PtrWrapper*)(((v_int64) object) + offset); + AbstractObjectWrapper get(void* object) { + AbstractObjectWrapper* property = (AbstractObjectWrapper*)(((v_int64) object) + offset); return *property; } diff --git a/core/data/mapping/type/macro/zzz_macro_define_DTO_.hpp b/core/data/mapping/type/macro/zzz_macro_define_DTO_.hpp index a9ee2400..d1f00cc3 100644 --- a/core/data/mapping/type/macro/zzz_macro_define_DTO_.hpp +++ b/core/data/mapping/type/macro/zzz_macro_define_DTO_.hpp @@ -31,7 +31,7 @@ \ public: \ typedef TYPE_NAME Z__CLASS; \ - typedef oatpp::data::mapping::type::PtrWrapper> PtrWrapper; \ + typedef oatpp::data::mapping::type::ObjectWrapper> 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 ↦ \ } \ \ - 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(this), \ - (oatpp::base::PtrWrapper*)(&NAME)); \ + (oatpp::data::mapping::type::AbstractObjectWrapper*)(&NAME)); \ \ static oatpp::data::mapping::type::Type::Property* \ Z__CLASS_GET_FIELD_##NAME(oatpp::base::Controllable* _this, \ - oatpp::base::PtrWrapper* _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(this), \ - (oatpp::base::PtrWrapper*)(&NAME)); \ + (oatpp::data::mapping::type::AbstractObjectWrapper*)(&NAME)); \ \ static oatpp::data::mapping::type::Type::Property* \ Z__CLASS_GET_FIELD_##NAME(oatpp::base::Controllable* _this, \ - oatpp::base::PtrWrapper* _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, \ diff --git a/core/data/stream/ChunkedBuffer.cpp b/core/data/stream/ChunkedBuffer.cpp index 7ffad2de..9d8dcb45 100644 --- a/core/data/stream/ChunkedBuffer.cpp +++ b/core/data/stream/ChunkedBuffer.cpp @@ -181,9 +181,9 @@ os::io::Library::v_size ChunkedBuffer::readSubstring(void *buffer, } -std::shared_ptr ChunkedBuffer::getSubstring(os::io::Library::v_size pos, +oatpp::String ChunkedBuffer::getSubstring(os::io::Library::v_size pos, os::io::Library::v_size count){ - auto str = oatpp::base::String::createShared((v_int32) count); + auto str = oatpp::String((v_int32) count); readSubstring(str->getData(), pos, count); return str; } diff --git a/core/data/stream/ChunkedBuffer.hpp b/core/data/stream/ChunkedBuffer.hpp index 75205d45..0d8db1bd 100644 --- a/core/data/stream/ChunkedBuffer.hpp +++ b/core/data/stream/ChunkedBuffer.hpp @@ -149,10 +149,10 @@ public: os::io::Library::v_size pos, os::io::Library::v_size count); - std::shared_ptr getSubstring(os::io::Library::v_size pos, + oatpp::String getSubstring(os::io::Library::v_size pos, os::io::Library::v_size count); - std::shared_ptr toString() { + oatpp::String toString() { return getSubstring(0, m_size); } diff --git a/core/data/stream/Stream.cpp b/core/data/stream/Stream.cpp index d2892742..002f2357 100644 --- a/core/data/stream/Stream.cpp +++ b/core/data/stream/Stream.cpp @@ -137,7 +137,7 @@ oatpp::async::Action IOStream::readExactSizeDataAsyncInline(oatpp::data::stream: // Functions const std::shared_ptr& operator << -(const std::shared_ptr& s, const base::String::PtrWrapper& str) { +(const std::shared_ptr& s, const oatpp::String& str) { s->write(str); return s; } diff --git a/core/data/stream/Stream.hpp b/core/data/stream/Stream.hpp index 052ce059..9e4c5944 100644 --- a/core/data/stream/Stream.hpp +++ b/core/data/stream/Stream.hpp @@ -27,11 +27,11 @@ #include "oatpp/core/data/buffer/IOBuffer.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" #include "oatpp/core/async/Coroutine.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" + #include "oatpp/core/os/io/Library.hpp" namespace oatpp { namespace data{ namespace stream { @@ -45,7 +45,7 @@ public: return write((p_char8)data, std::strlen(data)); } - os::io::Library::v_size write(const oatpp::base::PtrWrapper& str){ + os::io::Library::v_size write(const oatpp::String& str){ return write(str->getData(), str->getSize()); } @@ -131,7 +131,7 @@ public: }; const std::shared_ptr& operator << -(const std::shared_ptr& s, const base::String::PtrWrapper& str); +(const std::shared_ptr& s, const oatpp::String& str); const std::shared_ptr& operator << (const std::shared_ptr& s, const char* str); diff --git a/core/parser/ParsingCaret.cpp b/core/parser/ParsingCaret.cpp index b47abe9e..919b37c8 100644 --- a/core/parser/ParsingCaret.cpp +++ b/core/parser/ParsingCaret.cpp @@ -26,6 +26,7 @@ #include #include +#include namespace oatpp { namespace parser { @@ -50,7 +51,7 @@ namespace oatpp { namespace parser { , m_error(nullptr) {} - ParsingCaret::ParsingCaret(const std::shared_ptr& str) + ParsingCaret::ParsingCaret(const oatpp::String& str) : m_data(str->getData()) , m_size(str->getSize()) , m_pos(0) @@ -65,7 +66,7 @@ namespace oatpp { namespace parser { return std::shared_ptr(new ParsingCaret(parseData, dataSize)); } - std::shared_ptr ParsingCaret::createShared(const std::shared_ptr& str){ + std::shared_ptr ParsingCaret::createShared(const oatpp::String& str){ return std::shared_ptr(new ParsingCaret(str->getData(), str->getSize())); } @@ -277,7 +278,7 @@ namespace oatpp { namespace parser { if(len > 0){ - auto str = base::String::createShared(&m_data[ipos], len, true); + auto str = oatpp::String((const char*)&m_data[ipos], len, true); v_int32 result = atoi((const char*)str->getData()); if(negative){ @@ -442,7 +443,7 @@ namespace oatpp { namespace parser { } - std::shared_ptr ParsingCaret::parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData){ + oatpp::String ParsingCaret::parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData){ if(m_data[m_pos] == openChar){ @@ -455,7 +456,7 @@ namespace oatpp { namespace parser { if(m_data[m_pos] == escapeChar){ m_pos++; }else if(m_data[m_pos] == closeChar){ - std::shared_ptr result = base::String::createShared(&m_data[ipos], m_pos - ipos, saveAsOwnData); + oatpp::String result = oatpp::String((const char*)&m_data[ipos], m_pos - ipos, saveAsOwnData); m_pos++; return result; } @@ -473,7 +474,7 @@ namespace oatpp { namespace parser { } - std::shared_ptr ParsingCaret::parseName(bool saveAsOwnData){ + oatpp::String ParsingCaret::parseName(bool saveAsOwnData){ v_int32 ipos = m_pos; while(m_pos < m_size){ @@ -488,7 +489,7 @@ namespace oatpp { namespace parser { }else{ if(ipos < m_pos){ - return base::String::createShared(&m_data[ipos], m_pos - ipos, saveAsOwnData); + return oatpp::String((const char*)&m_data[ipos], m_pos - ipos, saveAsOwnData); }else{ m_error = ERROR_NAME_EXPECTED; return nullptr; @@ -499,7 +500,7 @@ namespace oatpp { namespace parser { } if(ipos < m_pos){ - return base::String::createShared(&m_data[ipos], m_pos - ipos, saveAsOwnData); + return oatpp::String((const char*)&m_data[ipos], m_pos - ipos, saveAsOwnData); }else{ m_error = ERROR_NAME_EXPECTED; return nullptr; @@ -507,7 +508,12 @@ namespace oatpp { namespace parser { } - std::shared_ptr ParsingCaret::findTextFromList(const std::shared_ptr>>& list){ + bool ParsingCaret::findText(p_char8 text, v_int32 textSize) { + m_pos = (v_int32)(std::search(&m_data[m_pos], &m_data[m_size], text, text + textSize) - m_data); + return m_pos != m_size; + } + + oatpp::String ParsingCaret::findTextFromList(const std::shared_ptr>& list){ while(m_pos < m_size){ diff --git a/core/parser/ParsingCaret.hpp b/core/parser/ParsingCaret.hpp index 623e3875..1ea6740a 100644 --- a/core/parser/ParsingCaret.hpp +++ b/core/parser/ParsingCaret.hpp @@ -26,7 +26,7 @@ #define oatpp_parser_ParsingCaret_hpp #include "oatpp/core/collection/LinkedList.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" namespace oatpp { namespace parser { @@ -52,7 +52,12 @@ public: , m_end(-1) {} - void end(){ + void start() { + m_start = m_caret.m_pos; + m_end = -1; + } + + void end() { m_end = m_caret.m_pos; } @@ -61,18 +66,21 @@ public: } v_int32 getSize(){ + if(m_end == -1) { + return m_caret.m_pos - m_start; + } return m_end - m_start; } - std::shared_ptr toString(bool saveAsOwnData){ + oatpp::String toString(bool saveAsOwnData){ v_int32 end = m_end; if(end == -1){ end = m_caret.m_pos; } - return oatpp::base::String::createShared(&m_caret.m_data[m_start], end - m_start, saveAsOwnData); + return oatpp::String((const char*)&m_caret.m_data[m_start], end - m_start, saveAsOwnData); } - std::shared_ptr toString(){ + oatpp::String toString(){ return toString(true); } @@ -93,12 +101,12 @@ private: public: ParsingCaret(const char* text); ParsingCaret(p_char8 parseData, v_int32 dataSize); - ParsingCaret(const std::shared_ptr& str); + ParsingCaret(const oatpp::String& str); public: static std::shared_ptr createShared(const char* text); static std::shared_ptr createShared(p_char8 parseData, v_int32 dataSize); - static std::shared_ptr createShared(const std::shared_ptr& str); + static std::shared_ptr createShared(const oatpp::String& str); virtual ~ParsingCaret(); @@ -153,10 +161,11 @@ public: bool proceedIfFollowsWord(const char* text); // not increases pos if false bool proceedIfFollowsWord(p_char8 text, v_int32 textSize); // not increases pos if false - std::shared_ptr parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData); - std::shared_ptr parseName(bool saveAsOwnData); + oatpp::String parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData); + oatpp::String parseName(bool saveAsOwnData); - std::shared_ptr findTextFromList(const std::shared_ptr>>& list); + bool findText(p_char8 text, v_int32 textSize); + oatpp::String findTextFromList(const std::shared_ptr>& list); bool notAtCharFromSet(const char* set) const; bool notAtCharFromSet(p_char8 set, v_int32 setSize) const; diff --git a/core/utils/ConversionUtils.cpp b/core/utils/ConversionUtils.cpp index 1f228e5b..f38f3cde 100644 --- a/core/utils/ConversionUtils.cpp +++ b/core/utils/ConversionUtils.cpp @@ -33,7 +33,7 @@ namespace oatpp { namespace utils { namespace conversion { return (v_int32) std::strtol(str, &end, 10); } - v_int32 strToInt32(const base::PtrWrapper& str, bool& success){ + v_int32 strToInt32(const oatpp::String& str, bool& success){ char* end; v_int32 result = (v_int32) std::strtol((const char*)str->getData(), &end, 10); success = (((v_int64)end - (v_int64)str->getData()) == str->getSize()); @@ -45,7 +45,7 @@ namespace oatpp { namespace utils { namespace conversion { return std::strtoll(str, &end, 10); } - v_int64 strToInt64(const base::PtrWrapper& str, bool& success){ + v_int64 strToInt64(const oatpp::String& str, bool& success){ char* end; v_int64 result = std::strtoll((const char*)str->getData(), &end, 10); success = (((v_int64)end - (v_int64)str->getData()) == str->getSize()); @@ -60,22 +60,22 @@ namespace oatpp { namespace utils { namespace conversion { return sprintf((char*)data, "%lld", value); } - base::PtrWrapper int32ToStr(v_int32 value){ + oatpp::String int32ToStr(v_int32 value){ v_char8 buff [100]; v_int32 size = int32ToCharSequence(value, &buff[0]); if(size > 0){ - return base::String::createShared(&buff[0], size, true); + return oatpp::String((const char*)&buff[0], size, true); } - return base::PtrWrapper::empty(); + return oatpp::String::empty(); } - base::PtrWrapper int64ToStr(v_int64 value){ + oatpp::String int64ToStr(v_int64 value){ v_char8 buff [100]; v_int32 size = int64ToCharSequence(value, &buff[0]); if(size > 0){ - return base::String::createShared(&buff[0], size, true); + return oatpp::String((const char*)&buff[0], size, true); } - return base::PtrWrapper::empty(); + return oatpp::String::empty(); } std::string int32ToStdStr(v_int32 value){ @@ -101,7 +101,7 @@ namespace oatpp { namespace utils { namespace conversion { return std::strtof(str, &end); } - v_float32 strToFloat32(const base::PtrWrapper& str, bool& success) { + v_float32 strToFloat32(const oatpp::String& str, bool& success) { char* end; v_float32 result = std::strtof((const char*)str->getData(), &end); success = (((v_int64)end - (v_int64)str->getData()) == str->getSize()); @@ -113,7 +113,7 @@ namespace oatpp { namespace utils { namespace conversion { return std::strtod(str, &end); } - v_float64 strToFloat64(const base::PtrWrapper& str, bool& success) { + v_float64 strToFloat64(const oatpp::String& str, bool& success) { char* end; v_float64 result = std::strtod((const char*)str->getData(), &end); success = (((v_int64)end - (v_int64)str->getData()) == str->getSize()); @@ -128,33 +128,33 @@ namespace oatpp { namespace utils { namespace conversion { return sprintf((char*)data, "%f", value); } - base::PtrWrapper float32ToStr(v_float32 value){ + oatpp::String float32ToStr(v_float32 value){ v_char8 buff [100]; v_int32 size = float32ToCharSequence(value, &buff[0]); if(size > 0){ - return base::String::createShared(&buff[0], size, true); + return oatpp::String((const char*)&buff[0], size, true); } - return base::PtrWrapper::empty(); + return oatpp::String::empty(); } - base::PtrWrapper float64ToStr(v_float64 value){ + oatpp::String float64ToStr(v_float64 value){ v_char8 buff [100]; v_int32 size = float32ToCharSequence(value, &buff[0]); if(size > 0){ - return base::String::createShared(&buff[0], size, true); + return oatpp::String((const char*)&buff[0], size, true); } - return base::PtrWrapper::empty(); + return oatpp::String::empty(); } - base::PtrWrapper boolToStr(bool value) { + oatpp::String boolToStr(bool value) { if(value){ - return base::String::createShared((p_char8)"true", 4, false); + return oatpp::String("true", 4, false); } else { - return base::String::createShared((p_char8)"false", 5, false); + return oatpp::String("false", 5, false); } } - bool strToBool(const base::PtrWrapper& str, bool& success) { + bool strToBool(const oatpp::String& str, bool& success) { if(str->equals((p_char8)"true", 4)){ success = true; return true; diff --git a/core/utils/ConversionUtils.hpp b/core/utils/ConversionUtils.hpp index 1c885147..0aabad04 100644 --- a/core/utils/ConversionUtils.hpp +++ b/core/utils/ConversionUtils.hpp @@ -25,9 +25,10 @@ #ifndef oatpp_utils_ConversionUtils_hpp #define oatpp_utils_ConversionUtils_hpp -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/data/mapping/type/Primitive.hpp" +#include "oatpp/core/Types.hpp" + -#include "oatpp/core/base/PtrWrapper.hpp" #include "oatpp/core/base/Controllable.hpp" #include "oatpp/core/base/Environment.hpp" @@ -36,15 +37,15 @@ namespace oatpp { namespace utils { namespace conversion { v_int32 strToInt32(const char* str); - v_int32 strToInt32(const base::PtrWrapper& str, bool& success); + v_int32 strToInt32(const oatpp::String& str, bool& success); v_int64 strToInt64(const char* str); - v_int64 strToInt64(const base::PtrWrapper& str, bool& success); + v_int64 strToInt64(const oatpp::String& str, bool& success); v_int32 int32ToCharSequence(v_int32 value, p_char8 data); v_int32 int64ToCharSequence(v_int64 value, p_char8 data); - base::PtrWrapper int32ToStr(v_int32 value); - base::PtrWrapper int64ToStr(v_int64 value); + oatpp::String int32ToStr(v_int32 value); + oatpp::String int64ToStr(v_int64 value); std::string int32ToStdStr(v_int32 value); std::string int64ToStdStr(v_int64 value); @@ -55,29 +56,48 @@ namespace oatpp { namespace utils { namespace conversion { } template - base::PtrWrapper primitiveToStr(T value, const char* pattern){ + oatpp::String primitiveToStr(T value, const char* pattern){ v_char8 buff [100]; v_int32 size = primitiveToCharSequence(value, &buff[0], pattern); if(size > 0){ - return base::String::createShared(&buff[0], size, true); + return oatpp::String((const char*)&buff[0], size, true); } - return base::PtrWrapper::empty(); + return oatpp::String::empty(); } v_float32 strToFloat32(const char* str); - v_float32 strToFloat32(const base::PtrWrapper& str, bool& success); + v_float32 strToFloat32(const oatpp::String& str, bool& success); v_float64 strToFloat64(const char* str); - v_float64 strToFloat64(const base::PtrWrapper& str, bool& success); + v_float64 strToFloat64(const oatpp::String& str, bool& success); v_int32 float32ToCharSequence(v_float32 value, p_char8 data); v_int32 float64ToCharSequence(v_float64 value, p_char8 data); - base::PtrWrapper float32ToStr(v_float32 value); - base::PtrWrapper float64ToStr(v_float64 value); + oatpp::String float32ToStr(v_float32 value); + oatpp::String float64ToStr(v_float64 value); - base::PtrWrapper boolToStr(bool value); - bool strToBool(const base::PtrWrapper& str, bool& success); + oatpp::String boolToStr(bool value); + bool strToBool(const oatpp::String& str, bool& success); + template + oatpp::String + primitiveToStr(const oatpp::data::mapping::type::PolymorphicWrapper& primitive) { + auto type = primitive.valueType; + if(type == oatpp::data::mapping::type::__class::String::getType()) { + return std::static_pointer_cast(primitive.getPtr()); + } else if(type == oatpp::data::mapping::type::__class::Int32::getType()) { + return utils::conversion::int32ToStr(static_cast(primitive.get())->getValue()); + } else if(type == oatpp::data::mapping::type::__class::Int64::getType()) { + return utils::conversion::int64ToStr(static_cast(primitive.get())->getValue()); + } else if(type == oatpp::data::mapping::type::__class::Float32::getType()) { + return utils::conversion::float32ToStr(static_cast(primitive.get())->getValue()); + } else if(type == oatpp::data::mapping::type::__class::Float64::getType()) { + return utils::conversion::float64ToStr(static_cast(primitive.get())->getValue()); + } else if(type == oatpp::data::mapping::type::__class::Boolean::getType()) { + return utils::conversion::boolToStr(static_cast(primitive.get())->getValue()); + } + throw std::runtime_error("[oatpp::utils::conversion::primitiveToStr]: Invalid primitive type"); + } }}} diff --git a/encoding/Hex.hpp b/encoding/Hex.hpp index 0858a521..b333cb34 100644 --- a/encoding/Hex.hpp +++ b/encoding/Hex.hpp @@ -27,7 +27,7 @@ #include "oatpp/core/data/stream/Stream.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" + #include "oatpp/core/base/Environment.hpp" namespace oatpp { namespace encoding { diff --git a/network/Connection.cpp b/network/Connection.cpp index aa61b417..3a481edd 100644 --- a/network/Connection.cpp +++ b/network/Connection.cpp @@ -66,7 +66,7 @@ Connection::Library::v_size Connection::read(void *buff, Library::v_size count){ return ERROR_IO_WAIT_RETRY; // For async io. In case socket is non_blocking } else if(e == EINTR) { return ERROR_IO_RETRY; - } else if(e == EPIPE) { + } else if(e == ECONNRESET) { return ERROR_IO_PIPE; } else { //OATPP_LOGD("Connection", "write errno=%d", e); diff --git a/network/ConnectionProvider.hpp b/network/ConnectionProvider.hpp index bd33bd9f..44f7f995 100644 --- a/network/ConnectionProvider.hpp +++ b/network/ConnectionProvider.hpp @@ -59,16 +59,16 @@ public: class ClientConnectionProvider : public ConnectionProvider { protected: - oatpp::base::String::PtrWrapper m_host; + oatpp::String m_host; v_word16 m_port; public: - ClientConnectionProvider(const oatpp::base::String::PtrWrapper& host, v_word16 port) + ClientConnectionProvider(const oatpp::String& host, v_word16 port) : m_host(host) , m_port(port) {} - oatpp::base::String::PtrWrapper getHost() { + oatpp::String getHost() { return m_host; } diff --git a/network/Url.cpp b/network/Url.cpp new file mode 100644 index 00000000..625d8cd6 --- /dev/null +++ b/network/Url.cpp @@ -0,0 +1,160 @@ +/*************************************************************************** + * + * Project _____ __ ____ _ _ + * ( _ ) /__\ (_ _)_| |_ _| |_ + * )(_)( /(__)\ )( (_ _)(_ _) + * (_____)(__)(__)(__) |_| |_| + * + * + * Copyright 2018-present, Leonid Stryzhevskyi, + * + * 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 "Url.hpp" + +#include + +namespace oatpp { namespace network { + +oatpp::String Url::Parser::parseScheme(oatpp::parser::ParsingCaret& caret) { + v_int32 pos0 = caret.getPosition(); + caret.findChar(':'); + v_int32 size = caret.getPosition() - pos0; + if(size > 0) { + v_char8 buff[size]; + std::memcpy(buff, &caret.getData()[pos0], size); + oatpp::base::StrBuffer::lowerCase(buff, size); + return oatpp::String((const char*)buff, size, true); + } + return nullptr; +} + +Url::Authority Url::Parser::parseAuthority(oatpp::parser::ParsingCaret& caret) { + + p_char8 data = caret.getData(); + v_int32 pos0 = caret.getPosition(); + v_int32 pos = pos0; + + v_int32 hostPos = pos0; + v_int32 atPos = -1; + v_int32 portPos = -1; + + while (pos < caret.getSize()) { + v_char8 a = data[pos]; + if(a == '@') { + atPos = pos; + pos ++; + hostPos = pos; + } else if(a == ':') { + pos ++; + portPos = pos; // last ':' in authority proceeds port in case it goes after '@' + } else if(a == '/' || a == '?' || a == '#') { + if(pos == pos0) { + return Url::Authority(); + } + break; + } else { + pos ++; + } + } + + caret.setPosition(pos); + + Url::Authority result; + + if(atPos > -1) { + result.userInfo = oatpp::String((const char*)&data[pos0], atPos - pos0, true); + } + + if(portPos > hostPos) { + result.host = oatpp::String((const char*)&data[hostPos], portPos - 1 - hostPos, true); + char* end; + result.port = (v_int32) std::strtol((const char*)&data[portPos], &end, 10); + bool success = (((v_int64)end - (v_int64)&data[portPos]) == pos - portPos); + if(!success) { + caret.setError("Invalid port string"); + } + } else { + result.host = oatpp::String((const char*)&data[hostPos], pos - pos0, true); + } + + return result; + +} + +oatpp::String Url::Parser::parsePath(oatpp::parser::ParsingCaret& caret) { + oatpp::parser::ParsingCaret::Label label(caret); + caret.findCharFromSet((p_char8)"?#", 2); + if(label.getSize() > 0) { + return label.toString(true); + } + return nullptr; +} + +void Url::Parser::parseQueryParamsToMap(Url::Parameters& params, oatpp::parser::ParsingCaret& caret) { + + if(caret.findChar('?')) { + + do { + caret.inc(); + oatpp::parser::ParsingCaret::Label nameLabel(caret); + if(caret.findChar('=')) { + nameLabel.end(); + caret.inc(); + oatpp::parser::ParsingCaret::Label valueLabel(caret); + caret.findChar('&'); + params.put(nameLabel.toString(), valueLabel.toString()); + } + } while (caret.canContinueAtChar('&')); + + } + +} + +void Url::Parser::parseQueryParamsToMap(Url::Parameters& params, const oatpp::String& str) { + oatpp::parser::ParsingCaret caret(str.getPtr()); + parseQueryParamsToMap(params, caret); +} + +std::shared_ptr Url::Parser::parseQueryParams(oatpp::parser::ParsingCaret& caret) { + auto params = Url::Parameters::createShared(); + parseQueryParamsToMap(*params, caret); + return params; +} + +std::shared_ptr Url::Parser::parseQueryParams(const oatpp::String& str) { + auto params = Url::Parameters::createShared(); + parseQueryParamsToMap(*params, str); + return params; +} + +Url Url::Parser::parseUrl(oatpp::parser::ParsingCaret& caret) { + Url result; + result.scheme = parseScheme(caret); + if(caret.canContinueAtChar(':', 1)) { + if(caret.proceedIfFollowsText((p_char8)"//", 2)) { + if(!caret.isAtChar('/')) { + result.authority = parseAuthority(caret); + } + result.path = parsePath(caret); + result.queryParams = parseQueryParams(caret); + } else { + result.authority = parseAuthority(caret); + } + } + return result; +} + +}} diff --git a/network/Url.hpp b/network/Url.hpp new file mode 100644 index 00000000..f77037bc --- /dev/null +++ b/network/Url.hpp @@ -0,0 +1,113 @@ +/*************************************************************************** + * + * Project _____ __ ____ _ _ + * ( _ ) /__\ (_ _)_| |_ _| |_ + * )(_)( /(__)\ )( (_ _)(_ _) + * (_____)(__)(__)(__) |_| |_| + * + * + * Copyright 2018-present, Leonid Stryzhevskyi, + * + * 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_network_Url_hpp +#define oatpp_network_Url_hpp + +#include "oatpp/core/parser/ParsingCaret.hpp" +#include "oatpp/core/collection/ListMap.hpp" +#include "oatpp/core/Types.hpp" + +namespace oatpp { namespace network { + +class Url : public oatpp::base::Controllable { +public: + typedef oatpp::collection::ListMap Parameters; +public: + + struct Authority { + oatpp::String userInfo; + oatpp::String host; + v_int32 port = -1; + }; + +public: + + class Parser { + public: + + /** + * parse ":" + * example "http", "https", "ftp" + * returns lowercase string before ':' char + * caret should be at the first char of the scheme + */ + static oatpp::String parseScheme(oatpp::parser::ParsingCaret& caret); + + /** + * parse utl authority components. + * userinfo is not parsed into login and password separately as + * inclusion of password in userinfo is deprecated and ignored here + * caret should be at the first char of the authority (not at "//") + */ + static Url::Authority parseAuthority(oatpp::parser::ParsingCaret& caret); + + /** + * parse path of the url + * caret should be at the first char of the path + */ + static oatpp::String parsePath(oatpp::parser::ParsingCaret& caret); + + /** + * parse query params in form of "?=&=..." referred by ParsingCaret + * and put that params to Parameters map + */ + static void parseQueryParamsToMap(Url::Parameters& params, oatpp::parser::ParsingCaret& caret); + + /** + * parse query params in form of "?=&=..." referred by str + * and put that params to Parameters map + */ + static void parseQueryParamsToMap(Url::Parameters& params, const oatpp::String& str); + + /** + * parse query params in form of "?=&=..." referred by ParsingCaret + */ + static std::shared_ptr parseQueryParams(oatpp::parser::ParsingCaret& caret); + + /** + * parse query params in form of "?=&=..." referred by str + */ + static std::shared_ptr parseQueryParams(const oatpp::String& str); + + /** + * parse Url + */ + static Url parseUrl(oatpp::parser::ParsingCaret& caret); + + + }; + +public: + + oatpp::String scheme; + Authority authority; + oatpp::String path; + std::shared_ptr queryParams; + +}; + +}} + +#endif /* oatpp_network_url_Url_hpp */ diff --git a/network/client/SimpleTCPConnectionProvider.cpp b/network/client/SimpleTCPConnectionProvider.cpp index d92a3095..795afcb5 100644 --- a/network/client/SimpleTCPConnectionProvider.cpp +++ b/network/client/SimpleTCPConnectionProvider.cpp @@ -81,13 +81,13 @@ oatpp::async::Action SimpleTCPConnectionProvider::getConnectionAsync(oatpp::asyn class ConnectCoroutine : public oatpp::async::CoroutineWithResult> { private: - oatpp::base::String::PtrWrapper m_host; + oatpp::String m_host; v_int32 m_port; oatpp::os::io::Library::v_handle m_clientHandle; struct sockaddr_in m_client; public: - ConnectCoroutine(const oatpp::base::String::PtrWrapper& host, v_int32 port) + ConnectCoroutine(const oatpp::String& host, v_int32 port) : m_host(host) , m_port(port) {} diff --git a/network/client/SimpleTCPConnectionProvider.hpp b/network/client/SimpleTCPConnectionProvider.hpp index eb486e86..8b775549 100644 --- a/network/client/SimpleTCPConnectionProvider.hpp +++ b/network/client/SimpleTCPConnectionProvider.hpp @@ -28,19 +28,19 @@ #include "oatpp/network/ConnectionProvider.hpp" #include "oatpp/core/data/stream/Stream.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" namespace oatpp { namespace network { namespace client { class SimpleTCPConnectionProvider : public base::Controllable, public ClientConnectionProvider { public: - SimpleTCPConnectionProvider(const oatpp::base::String::PtrWrapper& host, v_int32 port) + SimpleTCPConnectionProvider(const oatpp::String& host, v_int32 port) : ClientConnectionProvider(host, port) {} public: static std::shared_ptr - createShared(const oatpp::base::String::PtrWrapper& host, v_int32 port){ + createShared(const oatpp::String& host, v_int32 port){ return std::shared_ptr(new SimpleTCPConnectionProvider(host, port)); } diff --git a/network/server/ConnectionHandler.hpp b/network/server/ConnectionHandler.hpp index 6a953f79..ce966b03 100644 --- a/network/server/ConnectionHandler.hpp +++ b/network/server/ConnectionHandler.hpp @@ -26,7 +26,7 @@ #define network_server_ConnectionHandler_hpp #include "oatpp/core/data/stream/Stream.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" + namespace oatpp { namespace network { namespace server { diff --git a/network/server/Server.hpp b/network/server/Server.hpp index a188c590..f69fb4c0 100644 --- a/network/server/Server.hpp +++ b/network/server/Server.hpp @@ -31,8 +31,8 @@ #include "oatpp/core/concurrency/Runnable.hpp" -#include "oatpp/core/base/String.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" +#include "oatpp/core/Types.hpp" + #include "oatpp/core/base/Controllable.hpp" #include "oatpp/core/base/Environment.hpp" @@ -56,7 +56,7 @@ private: std::atomic m_status; - std::shared_ptr m_port; + oatpp::String m_port; std::shared_ptr m_connectionProvider; std::shared_ptr m_connectionHandler; diff --git a/network/server/SimpleTCPConnectionProvider.hpp b/network/server/SimpleTCPConnectionProvider.hpp index 76e1bd41..2a737bfe 100644 --- a/network/server/SimpleTCPConnectionProvider.hpp +++ b/network/server/SimpleTCPConnectionProvider.hpp @@ -28,7 +28,7 @@ #include "oatpp/network/ConnectionProvider.hpp" #include "oatpp/core/data/stream/Stream.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" #include "oatpp/core/os/io/Library.hpp" namespace oatpp { namespace network { namespace server { diff --git a/parser/json/Utils.cpp b/parser/json/Utils.cpp index f0ac8597..8bcfce51 100644 --- a/parser/json/Utils.cpp +++ b/parser/json/Utils.cpp @@ -200,13 +200,13 @@ v_int32 Utils::escapeUtf8Char(p_char8 sequence, p_char8 buffer){ } } -std::shared_ptr Utils::escapeString(p_char8 data, v_int32 size) { +oatpp::String Utils::escapeString(p_char8 data, v_int32 size) { v_int32 safeSize; v_int32 escapedSize = calcEscapedStringSize(data, size, safeSize); if(escapedSize == size) { - return String::createShared(data, size, true); + return String((const char*)data, size, true); } - auto result = String::createShared(escapedSize); + auto result = String(escapedSize); v_int32 i = 0; p_char8 resultData = result->getData(); v_int32 pos = 0; @@ -322,14 +322,14 @@ void Utils::unescapeStringToBuffer(p_char8 data, v_int32 size, p_char8 resultDat } -std::shared_ptr Utils::unescapeString(p_char8 data, v_int32 size, +oatpp::String Utils::unescapeString(p_char8 data, v_int32 size, const char* & error, v_int32& errorPosition) { v_int32 unescapedSize = calcUnescapedStringSize(data, size, error, errorPosition); if(error != nullptr){ return nullptr; } - auto result = String::createShared(unescapedSize); + auto result = String(unescapedSize); if(unescapedSize == size) { std::memcpy(result->getData(), data, size); } else { @@ -355,14 +355,14 @@ std::string Utils::unescapeStringToStdString(p_char8 data, v_int32 size, return result; } -p_char8 Utils::preparseString(const std::shared_ptr& caret, v_int32& size){ +p_char8 Utils::preparseString(ParsingCaret& caret, v_int32& size){ - if(caret->canContinueAtChar('"', 1)){ + if(caret.canContinueAtChar('"', 1)){ - const p_char8 data = caret->getData(); - v_int32 pos = caret->getPosition(); + const p_char8 data = caret.getData(); + v_int32 pos = caret.getPosition(); v_int32 pos0 = pos; - v_int32 length = caret->getSize(); + v_int32 length = caret.getSize(); while (pos < length) { v_char8 a = data[pos]; @@ -375,33 +375,33 @@ p_char8 Utils::preparseString(const std::shared_ptr& caret, v_int3 pos ++; } } - caret->setPosition(caret->getSize()); - caret->setError(ERROR_PARSER_QUOTE_EXPECTED); + caret.setPosition(caret.getSize()); + caret.setError(ERROR_PARSER_QUOTE_EXPECTED); } else { - caret->setError(ERROR_PARSER_QUOTE_EXPECTED); + caret.setError(ERROR_PARSER_QUOTE_EXPECTED); } return nullptr; } -std::shared_ptr Utils::parseString(const std::shared_ptr& caret) { +oatpp::String Utils::parseString(ParsingCaret& caret) { v_int32 size; p_char8 data = preparseString(caret, size); if(data != nullptr) { - v_int32 pos = caret->getPosition(); + v_int32 pos = caret.getPosition(); const char* error; v_int32 errorPosition; auto result = unescapeString(data, size, error, errorPosition); if(error != nullptr){ - caret->setError(error); - caret->setPosition(pos + errorPosition); + caret.setError(error); + caret.setPosition(pos + errorPosition); } else { - caret->setPosition(pos + size + 1); + caret.setPosition(pos + size + 1); } return result; @@ -412,23 +412,23 @@ std::shared_ptr Utils::parseString(const std::shared_ptr& caret){ +std::string Utils::parseStringToStdString(ParsingCaret& caret){ v_int32 size; p_char8 data = preparseString(caret, size); if(data != nullptr) { - v_int32 pos = caret->getPosition(); + v_int32 pos = caret.getPosition(); const char* error; v_int32 errorPosition; const std::string& result = unescapeStringToStdString(data, size, error, errorPosition); if(error != nullptr){ - caret->setError(error); - caret->setPosition(pos + errorPosition); + caret.setError(error); + caret.setPosition(pos + errorPosition); } else { - caret->setPosition(pos + size + 1); + caret.setPosition(pos + size + 1); } return result; diff --git a/parser/json/Utils.hpp b/parser/json/Utils.hpp index 87ef68d4..361ef6d5 100644 --- a/parser/json/Utils.hpp +++ b/parser/json/Utils.hpp @@ -26,7 +26,7 @@ #define oatpp_parser_json_Utils_hpp #include "oatpp/core/parser/ParsingCaret.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" #include @@ -39,23 +39,23 @@ public: static const char* const ERROR_PARSER_QUOTE_EXPECTED; public: - typedef oatpp::base::String String; + typedef oatpp::String String; typedef oatpp::parser::ParsingCaret ParsingCaret; private: static v_int32 escapeUtf8Char(p_char8 sequence, p_char8 buffer); static v_int32 calcEscapedStringSize(p_char8 data, v_int32 size, v_int32& safeSize); static v_int32 calcUnescapedStringSize(p_char8 data, v_int32 size, const char* & error, v_int32& errorPosition); static void unescapeStringToBuffer(p_char8 data, v_int32 size, p_char8 resultData); - static p_char8 preparseString(const std::shared_ptr& caret, v_int32& size); + static p_char8 preparseString(ParsingCaret& caret, v_int32& size); public: - static std::shared_ptr escapeString(p_char8 data, v_int32 size); - static std::shared_ptr unescapeString(p_char8 data, v_int32 size, const char* & error, v_int32& errorPosition); + static String escapeString(p_char8 data, v_int32 size); + static String unescapeString(p_char8 data, v_int32 size, const char* & error, v_int32& errorPosition); static std::string unescapeStringToStdString(p_char8 data, v_int32 size, const char* & error, v_int32& errorPosition); - static std::shared_ptr parseString(const std::shared_ptr& caret); - static std::string parseStringToStdString(const std::shared_ptr& caret); + static String parseString(ParsingCaret& caret); + static std::string parseStringToStdString(ParsingCaret& caret); }; diff --git a/parser/json/mapping/Deserializer.cpp b/parser/json/mapping/Deserializer.cpp index 8d37fa26..8d12427f 100644 --- a/parser/json/mapping/Deserializer.cpp +++ b/parser/json/mapping/Deserializer.cpp @@ -36,11 +36,11 @@ const char* const Deserializer::ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING = "':' - const char* const Deserializer::ERROR_PARSER_ARRAY_SCOPE_OPEN = "'[' - expected"; const char* const Deserializer::ERROR_PARSER_ARRAY_SCOPE_CLOSE = "']' - expected"; -void Deserializer::skipScope(const std::shared_ptr& caret, v_char8 charOpen, v_char8 charClose){ +void Deserializer::skipScope(oatpp::parser::ParsingCaret& caret, v_char8 charOpen, v_char8 charClose){ - p_char8 data = caret->getData(); - v_int32 size = caret->getSize(); - v_int32 pos = caret->getPosition(); + p_char8 data = caret.getData(); + v_int32 size = caret.getSize(); + v_int32 pos = caret.getPosition(); v_int32 scopeCounter = 0; bool isInString = false; @@ -55,7 +55,7 @@ void Deserializer::skipScope(const std::shared_ptr& if(!isInString){ scopeCounter --; if(scopeCounter == 0){ - caret->setPosition(pos + 1); + caret.setPosition(pos + 1); return; } } @@ -70,17 +70,17 @@ void Deserializer::skipScope(const std::shared_ptr& } } -void Deserializer::skipString(const std::shared_ptr& caret){ - p_char8 data = caret->getData(); - v_int32 size = caret->getSize(); - v_int32 pos = caret->getPosition(); +void Deserializer::skipString(oatpp::parser::ParsingCaret& caret){ + p_char8 data = caret.getData(); + v_int32 size = caret.getSize(); + v_int32 pos = caret.getPosition(); v_int32 scopeCounter = 0; while(pos < size){ v_char8 a = data[pos]; if(a == '"'){ scopeCounter ++; if(scopeCounter == 2) { - caret->setPosition(pos + 1); + caret.setPosition(pos + 1); return; } } else if(a == '\\'){ @@ -90,103 +90,103 @@ void Deserializer::skipString(const std::shared_ptr } } -void Deserializer::skipToken(const std::shared_ptr& caret){ - p_char8 data = caret->getData(); - v_int32 size = caret->getSize(); - v_int32 pos = caret->getPosition(); +void Deserializer::skipToken(oatpp::parser::ParsingCaret& caret){ + p_char8 data = caret.getData(); + v_int32 size = caret.getSize(); + v_int32 pos = caret.getPosition(); while(pos < size){ v_char8 a = data[pos]; if(a == ' ' || a == '\t' || a == '\n' || a == '\r' || a == '\b' || a == '\f' || a == '}' || a == ',' || a == ']') { - caret->setPosition(pos); + caret.setPosition(pos); return; } pos ++; } } -void Deserializer::skipValue(const std::shared_ptr& caret){ - if(caret->isAtChar('{')){ +void Deserializer::skipValue(oatpp::parser::ParsingCaret& caret){ + if(caret.isAtChar('{')){ skipScope(caret, '{', '}'); - } else if(caret->isAtChar('[')){ + } else if(caret.isAtChar('[')){ skipScope(caret, '[', ']'); - } else if(caret->isAtChar('"')){ + } else if(caret.isAtChar('"')){ skipString(caret); } else { skipToken(caret); } } -Deserializer::AbstractPtrWrapper Deserializer::readStringValue(const std::shared_ptr& caret){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper(String::Class::getType()); +Deserializer::AbstractObjectWrapper Deserializer::readStringValue(oatpp::parser::ParsingCaret& caret){ + if(caret.proceedIfFollowsText("null")){ + 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& caret){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper(Int32::PtrWrapper::Class::getType()); +Deserializer::AbstractObjectWrapper Deserializer::readInt32Value(oatpp::parser::ParsingCaret& caret){ + if(caret.proceedIfFollowsText("null")){ + return AbstractObjectWrapper(Int32::ObjectWrapper::Class::getType()); } else { - return AbstractPtrWrapper(Int32::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& caret){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper(Int64::PtrWrapper::Class::getType()); +Deserializer::AbstractObjectWrapper Deserializer::readInt64Value(oatpp::parser::ParsingCaret& caret){ + if(caret.proceedIfFollowsText("null")){ + return AbstractObjectWrapper(Int64::ObjectWrapper::Class::getType()); } else { - return AbstractPtrWrapper(Int64::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& caret){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper(Float32::PtrWrapper::Class::getType()); +Deserializer::AbstractObjectWrapper Deserializer::readFloat32Value(oatpp::parser::ParsingCaret& caret){ + if(caret.proceedIfFollowsText("null")){ + return AbstractObjectWrapper(Float32::ObjectWrapper::Class::getType()); } else { - return AbstractPtrWrapper(Float32::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& caret){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper(Float64::PtrWrapper::Class::getType()); +Deserializer::AbstractObjectWrapper Deserializer::readFloat64Value(oatpp::parser::ParsingCaret& caret){ + if(caret.proceedIfFollowsText("null")){ + return AbstractObjectWrapper(Float64::ObjectWrapper::Class::getType()); } else { - return AbstractPtrWrapper(Float64::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& caret){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper(Boolean::PtrWrapper::Class::getType()); +Deserializer::AbstractObjectWrapper Deserializer::readBooleanValue(oatpp::parser::ParsingCaret& caret){ + if(caret.proceedIfFollowsText("null")){ + return AbstractObjectWrapper(Boolean::ObjectWrapper::Class::getType()); } else { - return AbstractPtrWrapper(Boolean::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, - const std::shared_ptr& caret, +Deserializer::AbstractObjectWrapper Deserializer::readObjectValue(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper::empty(); + if(caret.proceedIfFollowsText("null")){ + return AbstractObjectWrapper::empty(); } else { return readObject(type, caret, config); } } -Deserializer::AbstractPtrWrapper Deserializer::readListValue(const Type* const type, - const std::shared_ptr& caret, +Deserializer::AbstractObjectWrapper Deserializer::readListValue(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config){ - if(caret->proceedIfFollowsText("null")){ - return AbstractPtrWrapper::empty(); + if(caret.proceedIfFollowsText("null")){ + return AbstractObjectWrapper::empty(); } else { return readList(type, caret, config); } } -Deserializer::AbstractPtrWrapper Deserializer::readValue(const Type* const type, - const std::shared_ptr& caret, +Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config){ auto typeName = type->name; @@ -210,15 +210,15 @@ Deserializer::AbstractPtrWrapper Deserializer::readValue(const Type* const type, skipValue(caret); } - return AbstractPtrWrapper::empty(); + return AbstractObjectWrapper::empty(); } -Deserializer::AbstractPtrWrapper Deserializer::readList(const Type* type, - const std::shared_ptr& caret, +Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config){ - if(caret->canContinueAtChar('[', 1)) { + if(caret.canContinueAtChar('[', 1)) { auto listWrapper = type->creator(); oatpp::data::mapping::type::PolymorphicWrapper @@ -226,99 +226,99 @@ Deserializer::AbstractPtrWrapper Deserializer::readList(const Type* type, Type* itemType = *type->params.begin(); - while(!caret->isAtChar(']') && caret->canContinue()){ + while(!caret.isAtChar(']') && caret.canContinue()){ - caret->findNotBlankChar(); + caret.findNotBlankChar(); auto item = readValue(itemType, caret, config); - if(caret->hasError()){ - return AbstractPtrWrapper::empty(); + if(caret.hasError()){ + return AbstractObjectWrapper::empty(); } list->addPolymorphicItem(item); - caret->findNotBlankChar(); + caret.findNotBlankChar(); - caret->canContinueAtChar(',', 1); + caret.canContinueAtChar(',', 1); } - if(!caret->canContinueAtChar(']', 1)){ - if(!caret->hasError()){ - caret->setError(ERROR_PARSER_ARRAY_SCOPE_CLOSE); + if(!caret.canContinueAtChar(']', 1)){ + 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(); + caret.setError(ERROR_PARSER_ARRAY_SCOPE_OPEN); + return AbstractObjectWrapper::empty(); } } -Deserializer::AbstractPtrWrapper Deserializer::readObject(const Type* type, - const std::shared_ptr& caret, +Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config){ - if(caret->canContinueAtChar('{', 1)) { + if(caret.canContinueAtChar('{', 1)) { auto object = type->creator(); auto fieldsMap = type->properties; - while (!caret->isAtChar('}') && caret->canContinue()) { + while (!caret.isAtChar('}') && caret.canContinue()) { - caret->findNotBlankChar(); + caret.findNotBlankChar(); auto key = Utils::parseStringToStdString(caret); - if(caret->hasError()){ - return AbstractPtrWrapper::empty(); + if(caret.hasError()){ + return AbstractObjectWrapper::empty(); } auto fieldIterator = fieldsMap->find(key); if(fieldIterator != fieldsMap->end()){ - caret->findNotBlankChar(); - if(!caret->canContinueAtChar(':', 1)){ - caret->setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING); - return AbstractPtrWrapper::empty(); + caret.findNotBlankChar(); + if(!caret.canContinueAtChar(':', 1)){ + caret.setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING); + return AbstractObjectWrapper::empty(); } - caret->findNotBlankChar(); + caret.findNotBlankChar(); auto field = fieldIterator->second; field->set(object.get(), readValue(field->type, caret, config)); } else if (config->allowUnknownFields) { - caret->findNotBlankChar(); - if(!caret->canContinueAtChar(':', 1)){ - caret->setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING); - return AbstractPtrWrapper::empty(); + caret.findNotBlankChar(); + if(!caret.canContinueAtChar(':', 1)){ + caret.setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING); + return AbstractObjectWrapper::empty(); } - caret->findNotBlankChar(); + caret.findNotBlankChar(); skipValue(caret); } else { - caret->setError(ERROR_PARSER_OBJECT_SCOPE_UNKNOWN_FIELD); - return AbstractPtrWrapper::empty(); + caret.setError(ERROR_PARSER_OBJECT_SCOPE_UNKNOWN_FIELD); + return AbstractObjectWrapper::empty(); } - caret->findNotBlankChar(); - caret->canContinueAtChar(',', 1); + caret.findNotBlankChar(); + caret.canContinueAtChar(',', 1); }; - if(!caret->canContinueAtChar('}', 1)){ - if(!caret->hasError()){ - caret->setError(ERROR_PARSER_OBJECT_SCOPE_CLOSE); + if(!caret.canContinueAtChar('}', 1)){ + if(!caret.hasError()){ + caret.setError(ERROR_PARSER_OBJECT_SCOPE_CLOSE); } - return AbstractPtrWrapper::empty(); + return AbstractObjectWrapper::empty(); } return object; } else { - caret->setError(ERROR_PARSER_OBJECT_SCOPE_OPEN); + caret.setError(ERROR_PARSER_OBJECT_SCOPE_OPEN); } - return AbstractPtrWrapper::empty(); + return AbstractObjectWrapper::empty(); } diff --git a/parser/json/mapping/Deserializer.hpp b/parser/json/mapping/Deserializer.hpp index 120be90a..1a548393 100644 --- a/parser/json/mapping/Deserializer.hpp +++ b/parser/json/mapping/Deserializer.hpp @@ -33,7 +33,7 @@ #include "oatpp/core/parser/ParsingCaret.hpp" #include "oatpp/core/collection/LinkedList.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" namespace oatpp { namespace parser { namespace json { namespace mapping { @@ -43,18 +43,18 @@ 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: - typedef oatpp::data::mapping::type::StringPtrWrapper 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; typedef oatpp::data::mapping::type::Float64 Float64; typedef oatpp::data::mapping::type::Boolean Boolean; - typedef oatpp::data::mapping::type::List AbstractList; + typedef oatpp::data::mapping::type::List AbstractList; public: @@ -81,39 +81,39 @@ public: static const char* const ERROR_PARSER_ARRAY_SCOPE_CLOSE; private: - static void skipScope(const std::shared_ptr& caret, v_char8 charOpen, v_char8 charClose); - static void skipString(const std::shared_ptr& caret); - static void skipToken(const std::shared_ptr& caret); - static void skipValue(const std::shared_ptr& caret); + static void skipScope(oatpp::parser::ParsingCaret& caret, v_char8 charOpen, v_char8 charClose); + static void skipString(oatpp::parser::ParsingCaret& caret); + static void skipToken(oatpp::parser::ParsingCaret& caret); + static void skipValue(oatpp::parser::ParsingCaret& caret); - static AbstractPtrWrapper readStringValue(const std::shared_ptr& caret); - static AbstractPtrWrapper readInt32Value(const std::shared_ptr& caret); - static AbstractPtrWrapper readInt64Value(const std::shared_ptr& caret); - static AbstractPtrWrapper readFloat32Value(const std::shared_ptr& caret); - static AbstractPtrWrapper readFloat64Value(const std::shared_ptr& caret); - static AbstractPtrWrapper readBooleanValue(const std::shared_ptr& caret); - static AbstractPtrWrapper readObjectValue(const Type* const type, - const std::shared_ptr& caret, + static AbstractObjectWrapper readStringValue(oatpp::parser::ParsingCaret& caret); + static AbstractObjectWrapper readInt32Value(oatpp::parser::ParsingCaret& caret); + static AbstractObjectWrapper readInt64Value(oatpp::parser::ParsingCaret& caret); + static AbstractObjectWrapper readFloat32Value(oatpp::parser::ParsingCaret& caret); + static AbstractObjectWrapper readFloat64Value(oatpp::parser::ParsingCaret& caret); + static AbstractObjectWrapper readBooleanValue(oatpp::parser::ParsingCaret& caret); + static AbstractObjectWrapper readObjectValue(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config); - static AbstractPtrWrapper readListValue(const Type* const type, - const std::shared_ptr& caret, + static AbstractObjectWrapper readListValue(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config); - static AbstractPtrWrapper readValue(const Type* const type, - const std::shared_ptr& caret, + static AbstractObjectWrapper readValue(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config); - static AbstractPtrWrapper readList(const Type* const type, - const std::shared_ptr& caret, + static AbstractObjectWrapper readList(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config); - static AbstractPtrWrapper readObject(const Type* const type, - const std::shared_ptr& caret, + static AbstractObjectWrapper readObject(const Type* const type, + oatpp::parser::ParsingCaret& caret, const std::shared_ptr& config); public: - static AbstractPtrWrapper deserialize(const std::shared_ptr& caret, + static AbstractObjectWrapper deserialize(oatpp::parser::ParsingCaret& caret, const std::shared_ptr& 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(); } }; diff --git a/parser/json/mapping/ObjectMapper.hpp b/parser/json/mapping/ObjectMapper.hpp index e856e4b5..b6af669a 100644 --- a/parser/json/mapping/ObjectMapper.hpp +++ b/parser/json/mapping/ObjectMapper.hpp @@ -54,12 +54,12 @@ public: } void write(const std::shared_ptr& 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 - read(const std::shared_ptr& caret, + oatpp::data::mapping::type::AbstractObjectWrapper + read(oatpp::parser::ParsingCaret& caret, const oatpp::data::mapping::type::Type* const type) const override { return Deserializer::deserialize(caret, deserializerConfig, type); } diff --git a/parser/json/mapping/Serializer.cpp b/parser/json/mapping/Serializer.cpp index 85e45dd6..c0b15189 100644 --- a/parser/json/mapping/Serializer.cpp +++ b/parser/json/mapping/Serializer.cpp @@ -31,11 +31,11 @@ namespace oatpp { namespace parser { namespace json { namespace mapping { void Serializer::writeString(oatpp::data::stream::OutputStream* stream, void* object, Property* field) { - auto value = oatpp::base::static_wrapper_cast(field->get(object)); + auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); 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()); @@ -49,11 +49,11 @@ void Serializer::writeObject(oatpp::data::stream::OutputStream* stream, void* object, Property* field){ - auto value = oatpp::base::static_wrapper_cast(field->get(object)); + auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); 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()); @@ -68,7 +68,7 @@ void Serializer::writeListOfString(oatpp::data::stream::OutputStream* stream, auto curr = list->getFirstNode(); while(curr != nullptr){ - auto value = oatpp::base::static_wrapper_cast(curr->getData()); + auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); if(first){ first = false; @@ -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()); @@ -100,7 +100,7 @@ void Serializer::writeListOfObject(oatpp::data::stream::OutputStream* stream, auto curr = list->getFirstNode(); while(curr != nullptr){ - auto value = oatpp::base::static_wrapper_cast(curr->getData()); + auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); if(first){ first = false; @@ -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()); @@ -129,7 +129,7 @@ void Serializer::writeListOfList(oatpp::data::stream::OutputStream* stream, auto curr = list->getFirstNode(); while(curr != nullptr){ - auto value = oatpp::base::static_wrapper_cast(curr->getData()); + auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); if(first){ first = false; @@ -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); @@ -160,15 +160,15 @@ void Serializer::writeListCollection(oatpp::data::stream::OutputStream* stream, if(itemTypeName == oatpp::data::mapping::type::__class::String::CLASS_NAME){ writeListOfString(stream, list); } else if(itemTypeName == oatpp::data::mapping::type::__class::Int32::CLASS_NAME) { - writeListOfSimpleData(stream, list); + writeListOfSimpleData(stream, list); } else if(itemTypeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) { - writeListOfSimpleData(stream, list); + writeListOfSimpleData(stream, list); } else if(itemTypeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) { - writeListOfSimpleData(stream, list); + writeListOfSimpleData(stream, list); } else if(itemTypeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) { - writeListOfSimpleData(stream, list); + writeListOfSimpleData(stream, list); } else if(itemTypeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) { - writeListOfSimpleData(stream, list); + writeListOfSimpleData(stream, list); } else if(itemTypeName == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) { writeListOfObject(stream, list, itemType); } else if(itemTypeName == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME) { @@ -180,11 +180,11 @@ void Serializer::writeListCollection(oatpp::data::stream::OutputStream* stream, void Serializer::writeList(oatpp::data::stream::OutputStream* stream, void* object, Property* field){ - auto value = oatpp::base::static_wrapper_cast(field->get(object)); + auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); 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); @@ -214,15 +214,15 @@ void Serializer::writeObject(oatpp::data::stream::OutputStream* stream, if(typeName == oatpp::data::mapping::type::__class::String::CLASS_NAME){ writeString(stream, object, field); } else if(typeName == oatpp::data::mapping::type::__class::Int32::CLASS_NAME) { - writeSimpleData(stream, object, field); + writeSimpleData(stream, object, field); } else if(typeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) { - writeSimpleData(stream, object, field); + writeSimpleData(stream, object, field); } else if(typeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) { - writeSimpleData(stream, object, field); + writeSimpleData(stream, object, field); } else if(typeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) { - writeSimpleData(stream, object, field); + writeSimpleData(stream, object, field); } else if(typeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) { - writeSimpleData(stream, object, field); + writeSimpleData(stream, object, field); } else if(typeName == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) { writeObject(stream, object, field); } else if(typeName == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME) { diff --git a/parser/json/mapping/Serializer.hpp b/parser/json/mapping/Serializer.hpp index 5de1384d..31d0cd53 100644 --- a/parser/json/mapping/Serializer.hpp +++ b/parser/json/mapping/Serializer.hpp @@ -34,7 +34,7 @@ #include "oatpp/core/parser/ParsingCaret.hpp" #include "oatpp/core/collection/LinkedList.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" namespace oatpp { namespace parser { namespace json { namespace mapping { @@ -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: @@ -64,7 +64,7 @@ public: }; public: - typedef oatpp::base::String String; + typedef oatpp::String String; private: static void writeString(oatpp::data::stream::OutputStream* stream, @@ -75,11 +75,11 @@ private: static void writeSimpleData(oatpp::data::stream::OutputStream* stream, void* object, Property* field){ - auto value = oatpp::base::static_wrapper_cast(field->get(object)); + auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); stream->writeChar('\"'); stream->write(field->name); stream->write("\": ", 3); - if(value.isNull()){ + if(!value){ stream->write("null", 4); } else { stream->writeAsString(value.get()->getValue()); @@ -101,7 +101,7 @@ private: auto curr = list->getFirstNode(); while(curr != nullptr){ - auto value = oatpp::base::static_wrapper_cast(curr->getData()); + auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); if(first){ first = false; @@ -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& 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.get())); diff --git a/test/core/base/RegRuleTest.cpp b/test/core/base/RegRuleTest.cpp index 0eba458f..3e7edae9 100644 --- a/test/core/base/RegRuleTest.cpp +++ b/test/core/base/RegRuleTest.cpp @@ -25,7 +25,9 @@ #include "RegRuleTest.hpp" #include "oatpp/core/data/mapping/type/Primitive.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" + +#include namespace oatpp { namespace test { namespace base { @@ -61,18 +63,17 @@ namespace { }; - typedef oatpp::base::String String; + typedef oatpp::String String; template - using PtrWrapper = oatpp::base::PtrWrapper; + using ObjectWrapper = oatpp::data::mapping::type::PolymorphicWrapper; template using PolymorphicWrapper = oatpp::data::mapping::type::PolymorphicWrapper; template - using TypePtrWrapper = oatpp::data::mapping::type::PtrWrapper; + using TypeObjectWrapper = oatpp::data::mapping::type::ObjectWrapper; - typedef oatpp::data::mapping::type::StringPtrWrapper StringPtrWrapper; typedef oatpp::data::mapping::type::Int32 Int32; typedef oatpp::data::mapping::type::Int64 Int64; typedef oatpp::data::mapping::type::Float32 Float32; @@ -84,64 +85,74 @@ namespace { bool RegRuleTest::onRun() { { - String::PtrWrapper reg1(""); - String::PtrWrapper reg2(reg1); - OATPP_ASSERT(!reg1.isNull()); - String::PtrWrapper reg3(std::move(reg1)); - OATPP_ASSERT(reg1.isNull()); - String::PtrWrapper reg4 = String::createShared(100); + String reg1(""); + String reg2(reg1); + OATPP_ASSERT(reg1); + String reg3(std::move(reg1)); + OATPP_ASSERT(!reg1); + String reg4 = String(100); } { - String::PtrWrapper reg1(""); - base::PtrWrapper reg2(reg1); - OATPP_ASSERT(!reg1.isNull()); - base::PtrWrapper reg3(std::move(reg1)); - OATPP_ASSERT(reg1.isNull()); - base::PtrWrapper reg4 = String::createShared(100) + "Leonid"; + String reg1(""); + String reg2(reg1); + OATPP_ASSERT(reg1); + String reg3(std::move(reg1)); + OATPP_ASSERT(!reg1); + String reg4 = String(100) + "Leonid"; } { - base::PtrWrapper reg1 = String::createShared(100); - String::PtrWrapper reg2(reg1); - OATPP_ASSERT(!reg1.isNull()); - String::PtrWrapper reg3(std::move(reg1)); - OATPP_ASSERT(reg1.isNull()); + String reg1 = String(100); + String reg2(reg1); + OATPP_ASSERT(reg1); + String reg3(std::move(reg1)); + OATPP_ASSERT(!reg1); } { - String::PtrWrapper reg1(String::createShared(100) + "Leonid"); - StringPtrWrapper reg2(reg1); - OATPP_ASSERT(!reg1.isNull()); - StringPtrWrapper reg3(std::move(reg1)); - OATPP_ASSERT(reg1.isNull()); - StringPtrWrapper reg4 = String::createShared(100); + String reg1(String(100) + "Leonid"); + String reg2(reg1); + OATPP_ASSERT(reg1); + String reg3(std::move(reg1)); + OATPP_ASSERT(!reg1); + String reg4 = String(100); } { - StringPtrWrapper reg1 = String::createShared(100); - String::PtrWrapper reg2(reg1); - OATPP_ASSERT(!reg1.isNull()); - String::PtrWrapper reg3(std::move(reg1)); - OATPP_ASSERT(reg1.isNull()); + String reg1 = String(100); + String reg2(reg1); + OATPP_ASSERT(reg1); + String reg3(std::move(reg1)); + OATPP_ASSERT(!reg1); } { - base::PtrWrapper reg1 = String::createShared(100); - StringPtrWrapper reg2(reg1); - OATPP_ASSERT(!reg1.isNull()); - StringPtrWrapper reg3(std::move(reg1)); - OATPP_ASSERT(reg1.isNull()); + String reg1 = String(100); + String reg2(reg1); + OATPP_ASSERT(reg1); + String reg3(std::move(reg1)); + OATPP_ASSERT(!reg1); } { - StringPtrWrapper reg1 = String::createShared(100); - base::PtrWrapper reg2(reg1); - OATPP_ASSERT(!reg1.isNull()); - base::PtrWrapper reg3(std::move(reg1)); - OATPP_ASSERT(reg1.isNull()); + String reg1 = String(100); + String reg2(reg1); + OATPP_ASSERT(reg1); + String reg3(std::move(reg1)); + OATPP_ASSERT(!reg1); } + std::unordered_map 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; } diff --git a/test/core/base/collection/LinkedListTest.cpp b/test/core/base/collection/LinkedListTest.cpp index 1e607818..4319dbd8 100644 --- a/test/core/base/collection/LinkedListTest.cpp +++ b/test/core/base/collection/LinkedListTest.cpp @@ -24,7 +24,7 @@ #include "LinkedListTest.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" #include "oatpp/core/collection/LinkedList.hpp" #include "oatpp/test/Checker.hpp" #include diff --git a/test/core/base/memory/PerfTest.cpp b/test/core/base/memory/PerfTest.cpp index a3fca971..bed77929 100644 --- a/test/core/base/memory/PerfTest.cpp +++ b/test/core/base/memory/PerfTest.cpp @@ -25,7 +25,7 @@ #include "PerfTest.hpp" #include "oatpp/core/collection/LinkedList.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" #include "oatpp/core/concurrency/Thread.hpp" #include diff --git a/test/parser/json/mapping/DTOMapperPerfTest.cpp b/test/parser/json/mapping/DTOMapperPerfTest.cpp index ae02f760..3eb9b21d 100644 --- a/test/parser/json/mapping/DTOMapperPerfTest.cpp +++ b/test/parser/json/mapping/DTOMapperPerfTest.cpp @@ -46,9 +46,9 @@ typedef oatpp::parser::json::mapping::Deserializer Deserializer; DTO_FIELD(String, _string); DTO_FIELD(Int32, _int32); - DTO_FIELD(List::PtrWrapper, _list); + DTO_FIELD(List::ObjectWrapper, _list); - static PtrWrapper createTestInstance(){ + static ObjectWrapper createTestInstance(){ auto result = Test1::createShared(); result->_string = "String Field"; result->_int32 = 5; @@ -83,9 +83,9 @@ bool DTOMapperPerfTest::onRun() { { PerformanceChecker checker("Deserializer"); - auto caret = oatpp::parser::ParsingCaret::createShared(test1_Text); + oatpp::parser::ParsingCaret caret(test1_Text); for(v_int32 i = 0; i < numIterations; i ++) { - caret->setPosition(0); + caret.setPosition(0); mapper->readFromCaret(caret); } } diff --git a/test/parser/json/mapping/DTOMapperTest.cpp b/test/parser/json/mapping/DTOMapperTest.cpp index 676b2e63..4c0d258b 100644 --- a/test/parser/json/mapping/DTOMapperTest.cpp +++ b/test/parser/json/mapping/DTOMapperTest.cpp @@ -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::PtrWrapper, _list_string) = List::createShared(); - DTO_FIELD(List::PtrWrapper, _list_int32) = List::createShared(); - DTO_FIELD(List::PtrWrapper, _list_int64) = List::createShared(); - DTO_FIELD(List::PtrWrapper, _list_float32) = List::createShared(); - DTO_FIELD(List::PtrWrapper, _list_float64) = List::createShared(); - DTO_FIELD(List::PtrWrapper, _list_boolean) = List::createShared(); + DTO_FIELD(List::ObjectWrapper, _list_string) = List::createShared(); + DTO_FIELD(List::ObjectWrapper, _list_int32) = List::createShared(); + DTO_FIELD(List::ObjectWrapper, _list_int64) = List::createShared(); + DTO_FIELD(List::ObjectWrapper, _list_float32) = List::createShared(); + DTO_FIELD(List::ObjectWrapper, _list_float64) = List::createShared(); + DTO_FIELD(List::ObjectWrapper, _list_boolean) = List::createShared(); - DTO_FIELD(List::PtrWrapper, _list_object) = List::createShared(); - DTO_FIELD(List::PtrWrapper>::PtrWrapper, _list_list_object) = List::PtrWrapper>::createShared(); + DTO_FIELD(List::ObjectWrapper, _list_object) = List::createShared(); + DTO_FIELD(List::ObjectWrapper>::ObjectWrapper, _list_list_object) = List::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::createShared(); - auto l2 = DTO::List::createShared(); - auto l3 = DTO::List::createShared(); + auto l1 = DTO::List::createShared(); + auto l2 = DTO::List::createShared(); + auto l3 = DTO::List::createShared(); l1->pushBack(TestChild::createShared("list_1", "item_1")); l1->pushBack(TestChild::createShared("list_1", "item_2")); @@ -166,25 +166,25 @@ bool DTOMapperTest::onRun(){ OATPP_LOGD(TAG, "..."); auto config = oatpp::parser::json::mapping::Deserializer::Config::createShared(); - auto caret = oatpp::parser::ParsingCaret::createShared(result); + oatpp::parser::ParsingCaret caret(result); auto obj = mapper->readFromCaret(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); diff --git a/test/parser/json/mapping/DeserializerTest.cpp b/test/parser/json/mapping/DeserializerTest.cpp index fa68908c..c5e905f1 100644 --- a/test/parser/json/mapping/DeserializerTest.cpp +++ b/test/parser/json/mapping/DeserializerTest.cpp @@ -72,73 +72,73 @@ bool DeserializerTest::onRun(){ auto obj1 = mapper->readFromString("{}"); - OATPP_ASSERT(obj1.isNull() == false); - OATPP_ASSERT(obj1->strF.isNull()); + OATPP_ASSERT(obj1); + OATPP_ASSERT(!obj1->strF); obj1 = mapper->readFromString("{\"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("{\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("{\"int32F\": null}"); - OATPP_ASSERT(obj2.isNull() == false); - OATPP_ASSERT(obj2->int32F.isNull() == true); + OATPP_ASSERT(obj2); + OATPP_ASSERT(!obj2->int32F); obj2 = mapper->readFromString("{\"int32F\": 32}"); - OATPP_ASSERT(obj2.isNull() == false); + OATPP_ASSERT(obj2); OATPP_ASSERT(obj2->int32F->getValue() == 32); obj2 = mapper->readFromString("{\"int32F\": -32}"); - OATPP_ASSERT(obj2.isNull() == false); + OATPP_ASSERT(obj2); OATPP_ASSERT(obj2->int32F->getValue() == -32); auto obj3 = mapper->readFromString("{\"float32F\": null}"); - OATPP_ASSERT(obj3.isNull() == false); - OATPP_ASSERT(obj3->float32F.isNull() == true); + OATPP_ASSERT(obj3); + OATPP_ASSERT(!obj3->float32F); obj3 = mapper->readFromString("{\"float32F\": 32}"); - OATPP_ASSERT(obj3.isNull() == false); + OATPP_ASSERT(obj3); OATPP_ASSERT(obj3->float32F->getValue() == 32); obj3 = mapper->readFromString("{\"float32F\": 1.32e1}"); - OATPP_ASSERT(obj3.isNull() == false); - OATPP_ASSERT(obj3->float32F.isNull() == false); + OATPP_ASSERT(obj3); + OATPP_ASSERT(obj3->float32F); obj3 = mapper->readFromString("{\"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("{\"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("{\"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("{\"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>("[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); diff --git a/web/client/ApiClient.cpp b/web/client/ApiClient.cpp index 23fafe1c..11ced688 100644 --- a/web/client/ApiClient.cpp +++ b/web/client/ApiClient.cpp @@ -78,13 +78,13 @@ void ApiClient::formatPath(oatpp::data::stream::OutputStream* stream, if(seg.type == PathSegment::SEG_PATH) { stream->write(seg.text.data(), seg.text.size()); } else { - auto key = base::String::createShared((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()){ - OATPP_LOGD(TAG, "Path parameter '%s' not provided in the api call", (const char*) seg.text.c_str()); + auto key = oatpp::String(seg.text.data(), (v_int32) seg.text.length(), false); + 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", seg.text.c_str()); throw std::runtime_error("[oatpp::web::client::ApiClient]: Path parameter missing"); } - auto value = oatpp::data::mapping::type::primitiveToStr(param); + auto value = oatpp::utils::conversion::primitiveToStr(param); stream->data::stream::OutputStream::write(value); } } @@ -99,13 +99,13 @@ void ApiClient::addPathQueryParams(oatpp::data::stream::OutputStream* stream, stream->write("?", 1); stream->data::stream::OutputStream::write(curr->getKey()); stream->write("=", 1); - stream->data::stream::OutputStream::write(oatpp::data::mapping::type::primitiveToStr(curr->getValue())); + stream->data::stream::OutputStream::write(oatpp::utils::conversion::primitiveToStr(curr->getValue())); curr = curr->getNext(); while (curr != nullptr) { stream->write("&", 1); stream->data::stream::OutputStream::write(curr->getKey()); stream->write("=", 1); - stream->data::stream::OutputStream::write(oatpp::data::mapping::type::primitiveToStr(curr->getValue())); + stream->data::stream::OutputStream::write(oatpp::utils::conversion::primitiveToStr(curr->getValue())); curr = curr->getNext(); } } @@ -122,7 +122,7 @@ std::shared_ptr ApiClient::convertParamsMap(const auto curr = params->getFirstEntry(); while (curr != nullptr) { - result->put(curr->getKey(), oatpp::data::mapping::type::primitiveToStr(curr->getValue())); + result->put(curr->getKey(), oatpp::utils::conversion::primitiveToStr(curr->getValue())); curr = curr->getNext(); } diff --git a/web/client/ApiClient.hpp b/web/client/ApiClient.hpp index 36b46713..1100e135 100644 --- a/web/client/ApiClient.hpp +++ b/web/client/ApiClient.hpp @@ -43,7 +43,7 @@ #include "oatpp/core/utils/ConversionUtils.hpp" #include "oatpp/core/base/Controllable.hpp" -#include "oatpp/core/base/PtrWrapper.hpp" + #include #include @@ -56,26 +56,26 @@ public: static constexpr const char* const TAG = "Client"; protected: typedef oatpp::collection::ListMap< - oatpp::base::String::PtrWrapper, - oatpp::data::mapping::type::AbstractPtrWrapper + oatpp::String, + oatpp::data::mapping::type::AbstractObjectWrapper > StringToParamMap; protected: - typedef std::unordered_map> PathVariablesMap; + typedef std::unordered_map PathVariablesMap; private: typedef oatpp::collection::ListMap< - oatpp::base::String::PtrWrapper, - oatpp::base::String::PtrWrapper + oatpp::String, + oatpp::String > StringToStringMap; public: typedef oatpp::web::protocol::http::Status Status; typedef oatpp::web::protocol::http::Header Header; public: - typedef oatpp::data::mapping::type::StringPtrWrapper String; - typedef oatpp::data::mapping::type::Int32::PtrWrapper Int32; - typedef oatpp::data::mapping::type::Int64::PtrWrapper Int64; - typedef oatpp::data::mapping::type::Float32::PtrWrapper Float32; - typedef oatpp::data::mapping::type::Float64::PtrWrapper Float64; - typedef oatpp::data::mapping::type::Boolean::PtrWrapper Boolean; + 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; + typedef oatpp::data::mapping::type::Float64 Float64; + typedef oatpp::data::mapping::type::Boolean Boolean; public: typedef oatpp::web::protocol::http::incoming::Response Response; public: @@ -133,7 +133,7 @@ public: protected: - virtual oatpp::base::String::PtrWrapper formatPath(const PathPattern& pathPattern, + virtual oatpp::String formatPath(const PathPattern& pathPattern, const std::shared_ptr& pathParams, const std::shared_ptr& queryParams) { oatpp::data::stream::ChunkedBuffer stream; @@ -144,7 +144,7 @@ protected: return stream.toString(); } - virtual std::shared_ptr executeRequest(const oatpp::base::String::PtrWrapper& method, + virtual std::shared_ptr executeRequest(const oatpp::String& method, const PathPattern& pathPattern, const std::shared_ptr& headers, const std::shared_ptr& pathParams, @@ -160,7 +160,7 @@ protected: virtual oatpp::async::Action executeRequestAsync(oatpp::async::AbstractCoroutine* parentCoroutine, AsyncCallback callback, - const oatpp::base::String::PtrWrapper& method, + const oatpp::String& method, const PathPattern& pathPattern, const std::shared_ptr& headers, const std::shared_ptr& pathParams, diff --git a/web/client/HttpRequestExecutor.cpp b/web/client/HttpRequestExecutor.cpp index 7cd0a05a..f60ebaee 100644 --- a/web/client/HttpRequestExecutor.cpp +++ b/web/client/HttpRequestExecutor.cpp @@ -41,19 +41,16 @@ namespace oatpp { namespace web { namespace client { std::shared_ptr -HttpRequestExecutor::execute(const String::PtrWrapper& method, - const String::PtrWrapper& path, +HttpRequestExecutor::execute(const String& method, + const String& path, const std::shared_ptr& headers, const std::shared_ptr& body) { - //auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); - //stream << "/" << path; - //ENV::log("HTTP_EXECUTOR", "Execute: '%s'", (const char*) stream->toStringAsString()->getData()); - auto connection = m_connectionProvider->getConnection(); if(!connection){ - return nullptr; // TODO ERROR HERE + throw RequestExecutionError(RequestExecutionError::ERROR_CODE_CANT_CONNECT, + "[oatpp::web::client::HttpRequestExecutor::execute()]: ConnectionProvider failed to provide Connection"); } auto request = oatpp::web::protocol::http::outgoing::Request::createShared(method, path, headers, body); @@ -65,56 +62,52 @@ HttpRequestExecutor::execute(const String::PtrWrapper& method, request->send(upStream); upStream->flush(); - //auto upStream = oatpp::data::stream::ChunkedBuffer::createShared(); - //request->send(upStream); - //ENV::log("request", "request:'%s'\n", (const char*) upStream->toStringAsString()->getData()); - //upStream->flushToStream(connection); - auto readCount = connection->read(ioBuffer->getData(), ioBuffer->getSize()); - //((p_char8) ioBuffer->getData())[readCount] = 0; - //ENV::log("asd", "response='%s'", (const char*) ioBuffer->getData()); - - if(readCount > 0) { - - oatpp::parser::ParsingCaret caret((p_char8) ioBuffer->getData(), ioBuffer->getSize()); - auto line = protocol::http::Protocol::parseResponseStartingLine(caret); - if(!line){ - return nullptr; // TODO ERROR HERE - } - - oatpp::web::protocol::http::Status error; - auto headers = protocol::http::Protocol::parseHeaders(caret, error); - - if(error.code != 0){ - return nullptr; // TODO ERROR HERE - } - - auto bodyStream = oatpp::data::stream::InputStreamBufferedProxy::createShared(connection, - ioBuffer, - caret.getPosition(), - (v_int32) readCount); - - return Response::createShared(line->statusCode, line->description, headers, bodyStream); + if(readCount == 0) { + throw RequestExecutionError(RequestExecutionError::ERROR_CODE_NO_RESPONSE, + "[oatpp::web::client::HttpRequestExecutor::execute()]: No response from server"); + } else if(readCount < 0) { + throw RequestExecutionError(RequestExecutionError::ERROR_CODE_CANT_READ_RESPONSE, + "[oatpp::web::client::HttpRequestExecutor::execute()]: Failed to read response. Check out the RequestExecutionError::getReadErrorCode() for more information", (v_int32) readCount); + } + oatpp::parser::ParsingCaret caret((p_char8) ioBuffer->getData(), ioBuffer->getSize()); + auto line = protocol::http::Protocol::parseResponseStartingLine(caret); + if(!line){ + throw RequestExecutionError(RequestExecutionError::ERROR_CODE_CANT_PARSE_STARTING_LINE, + "[oatpp::web::client::HttpRequestExecutor::execute()]: Failed to parse response. Invalid starting line"); } - return nullptr; + oatpp::web::protocol::http::Status error; + auto responseHeaders = protocol::http::Protocol::parseHeaders(caret, error); + + if(error.code != 0){ + throw RequestExecutionError(RequestExecutionError::ERROR_CODE_CANT_PARSE_HEADERS, + "[oatpp::web::client::HttpRequestExecutor::execute()]: Failed to parse response. Invalid headers section"); + } + + auto bodyStream = oatpp::data::stream::InputStreamBufferedProxy::createShared(connection, + ioBuffer, + caret.getPosition(), + (v_int32) readCount); + + return Response::createShared(line->statusCode, line->description, responseHeaders, bodyStream); } oatpp::async::Action HttpRequestExecutor::executeAsync(oatpp::async::AbstractCoroutine* parentCoroutine, AsyncCallback callback, - const String::PtrWrapper& method, - const String::PtrWrapper& path, + const String& method, + const String& path, const std::shared_ptr& headers, const std::shared_ptr& body) { class ExecutorCoroutine : public oatpp::async::CoroutineWithResult> { private: std::shared_ptr m_connectionProvider; - String::PtrWrapper m_method; - String::PtrWrapper m_path; + String m_method; + String m_path; std::shared_ptr m_headers; std::shared_ptr m_body; private: @@ -125,8 +118,8 @@ oatpp::async::Action HttpRequestExecutor::executeAsync(oatpp::async::AbstractCor public: ExecutorCoroutine(const std::shared_ptr& connectionProvider, - const String::PtrWrapper& method, - const String::PtrWrapper& path, + const String& method, + const String& path, const std::shared_ptr& headers, const std::shared_ptr& body) : m_connectionProvider(connectionProvider) diff --git a/web/client/HttpRequestExecutor.hpp b/web/client/HttpRequestExecutor.hpp index cd238f75..52d5a433 100644 --- a/web/client/HttpRequestExecutor.hpp +++ b/web/client/HttpRequestExecutor.hpp @@ -44,15 +44,18 @@ public: return std::shared_ptr(new HttpRequestExecutor(connectionProvider)); } - std::shared_ptr execute(const String::PtrWrapper& method, - const String::PtrWrapper& path, + /** + * throws RequestExecutionError + */ + std::shared_ptr execute(const String& method, + const String& path, const std::shared_ptr& headers, const std::shared_ptr& body) override; Action executeAsync(oatpp::async::AbstractCoroutine* parentCoroutine, AsyncCallback callback, - const String::PtrWrapper& method, - const String::PtrWrapper& path, + const String& method, + const String& path, const std::shared_ptr& headers, const std::shared_ptr& body) override; diff --git a/web/client/RequestExecutor.hpp b/web/client/RequestExecutor.hpp index d01876f3..590422e8 100644 --- a/web/client/RequestExecutor.hpp +++ b/web/client/RequestExecutor.hpp @@ -33,7 +33,7 @@ namespace oatpp { namespace web { namespace client { class RequestExecutor { public: - typedef oatpp::base::String String; + typedef oatpp::String String; typedef oatpp::async::Action Action; public: typedef oatpp::web::protocol::http::Protocol::Headers Headers; @@ -43,15 +43,57 @@ public: typedef Action (oatpp::async::AbstractCoroutine::*AsyncCallback)(const std::shared_ptr&); public: - virtual std::shared_ptr execute(const String::PtrWrapper& method, - const String::PtrWrapper& path, + class RequestExecutionError : public std::runtime_error { + public: + constexpr static const v_int32 ERROR_CODE_CANT_CONNECT = 1; + constexpr static const v_int32 ERROR_CODE_CANT_PARSE_STARTING_LINE = 2; + constexpr static const v_int32 ERROR_CODE_CANT_PARSE_HEADERS = 3; + constexpr static const v_int32 ERROR_CODE_CANT_READ_RESPONSE = 4; + constexpr static const v_int32 ERROR_CODE_NO_RESPONSE = 5; + private: + v_int32 m_errorCode; + const char* m_message; + v_int32 m_readErrorCode; + public: + + RequestExecutionError(v_int32 errorCode, const char* message, v_int32 readErrorCode = 0) + :std::runtime_error(message) + , m_errorCode(errorCode) + , m_message(message) + , m_readErrorCode(readErrorCode) + {} + + v_int32 getErrorCode() const { + return m_errorCode; + } + + const char* getMessage() const { + return m_message; + } + + /** + * This value is valid if errorCode == ERROR_CODE_CANT_READ_RESPONSE + * For more information about the read error you get check out: + * - oatpp::data::stream::IOStream for possible error codes + * - implementation of Connection provided by your ConnectionProvider for implementation-specific behaviour + */ + v_int32 getReadErrorCode() const { + return m_readErrorCode; + } + + }; + +public: + + virtual std::shared_ptr execute(const String& method, + const String& path, const std::shared_ptr& headers, const std::shared_ptr& body) = 0; virtual Action executeAsync(oatpp::async::AbstractCoroutine* parentCoroutine, AsyncCallback callback, - const String::PtrWrapper& method, - const String::PtrWrapper& path, + const String& method, + const String& path, const std::shared_ptr& headers, const std::shared_ptr& body) = 0; diff --git a/web/client/macro/zzz_macro_define_ApiClient_.hpp b/web/client/macro/zzz_macro_define_ApiClient_.hpp index 3237c909..ed8a0152 100644 --- a/web/client/macro/zzz_macro_define_ApiClient_.hpp +++ b/web/client/macro/zzz_macro_define_ApiClient_.hpp @@ -130,7 +130,7 @@ OATPP_MACRO_API_CLIENT_PARAM_MACRO X // API_CALL MACRO #define OATPP_API_CALL_0(NAME, METHOD, PATH, LIST) \ -static PathPattern Z_getPathPattern_##NAME(const oatpp::base::String::PtrWrapper& path) { \ +static PathPattern Z_getPathPattern_##NAME(const oatpp::String& path) { \ static PathPattern pattern = parsePathPattern(path->getData(), path->getSize()); \ return pattern; \ } \ @@ -146,7 +146,7 @@ std::shared_ptr NAME() { \ } #define OATPP_API_CALL_1(NAME, METHOD, PATH, LIST) \ -static PathPattern Z_getPathPattern_##NAME(const oatpp::base::String::PtrWrapper& path) { \ +static PathPattern Z_getPathPattern_##NAME(const oatpp::String& path) { \ static PathPattern pattern = parsePathPattern(path->getData(), path->getSize()); \ return pattern; \ } \ @@ -177,7 +177,7 @@ OATPP_API_CALL___(NAME, METHOD, PATH, (__VA_ARGS__)) // API_CALL_ASYNC MACRO #define OATPP_API_CALL_ASYNC_0(NAME, METHOD, PATH, LIST) \ -static PathPattern Z_getPathPattern_##NAME(const oatpp::base::String::PtrWrapper& path) { \ +static PathPattern Z_getPathPattern_##NAME(const oatpp::String& path) { \ static PathPattern pattern = parsePathPattern(path->getData(), path->getSize()); \ return pattern; \ } \ @@ -198,7 +198,7 @@ oatpp::async::Action NAME(\ } #define OATPP_API_CALL_ASYNC_1(NAME, METHOD, PATH, LIST) \ -static PathPattern Z_getPathPattern_##NAME(const oatpp::base::String::PtrWrapper& path) { \ +static PathPattern Z_getPathPattern_##NAME(const oatpp::String& path) { \ static PathPattern pattern = parsePathPattern(path->getData(), path->getSize()); \ return pattern; \ } \ diff --git a/web/protocol/http/Http.cpp b/web/protocol/http/Http.cpp index b090d6ff..6bc868ad 100644 --- a/web/protocol/http/Http.cpp +++ b/web/protocol/http/Http.cpp @@ -100,8 +100,8 @@ const Status Status::CODE_511(511, "Network Authentication Required"); const char* const Header::Value::CONNECTION_CLOSE = "close"; const char* const Header::Value::CONNECTION_KEEP_ALIVE = "keep-alive"; -const char* const Header::Value::SERVER = "oatpp/0.18"; -const char* const Header::Value::USER_AGENT = "oatpp/0.18"; +const char* const Header::Value::SERVER = "oatpp/" OATPP_VERSION; +const char* const Header::Value::USER_AGENT = "oatpp/" OATPP_VERSION; const char* const Header::Value::TRANSFER_ENCODING_CHUNKED = "chunked"; @@ -120,7 +120,7 @@ const char* const Header::HOST = "Host"; const char* const Header::USER_AGENT = "User-Agent"; const char* const Header::SERVER = "Server"; -oatpp::base::String::PtrWrapper Range::toString() const { +oatpp::String Range::toString() const { oatpp::data::stream::ChunkedBuffer stream; stream.write(units->getData(), units->getSize()); stream.write("=", 1); @@ -161,12 +161,12 @@ Range Range::parse(oatpp::parser::ParsingCaret& caret) { } -Range Range::parse(const std::shared_ptr& str) { +Range Range::parse(const oatpp::String& str) { oatpp::parser::ParsingCaret caret(str); return parse(caret); } -oatpp::base::String::PtrWrapper ContentRange::toString() const { +oatpp::String ContentRange::toString() const { oatpp::data::stream::ChunkedBuffer stream; stream.write(units->getData(), units->getSize()); stream.write(" ", 1); @@ -229,7 +229,7 @@ ContentRange ContentRange::parse(oatpp::parser::ParsingCaret& caret) { } -ContentRange ContentRange::parse(const std::shared_ptr& str) { +ContentRange ContentRange::parse(const oatpp::String& str) { oatpp::parser::ParsingCaret caret(str); return parse(caret); } @@ -299,7 +299,7 @@ std::shared_ptr Protocol::parseResponseStartingLine(oatpp: } -std::shared_ptr Protocol::parseHeaderName(oatpp::parser::ParsingCaret& caret) { +oatpp::String Protocol::parseHeaderName(oatpp::parser::ParsingCaret& caret) { p_char8 data = caret.getData(); oatpp::parser::ParsingCaret::Label label(caret); for(v_int32 i = caret.getPosition(); i < caret.getSize(); i++) { diff --git a/web/protocol/http/Http.hpp b/web/protocol/http/Http.hpp index e52b19c5..98326729 100644 --- a/web/protocol/http/Http.hpp +++ b/web/protocol/http/Http.hpp @@ -31,7 +31,7 @@ #include "oatpp/core/data/stream/Delegate.hpp" #include "oatpp/core/collection/ListMap.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" namespace oatpp { namespace web { namespace protocol { namespace http { @@ -157,7 +157,7 @@ private: {} public: - Range(const oatpp::base::String::PtrWrapper& pUnits, + Range(const oatpp::String& pUnits, const oatpp::os::io::Library::v_size& pStart, const oatpp::os::io::Library::v_size& pEnd) : units(pUnits) @@ -165,18 +165,18 @@ public: , end(pEnd) {} - oatpp::base::String::PtrWrapper units; + oatpp::String units; oatpp::os::io::Library::v_size start; oatpp::os::io::Library::v_size end; - oatpp::base::String::PtrWrapper toString() const; + oatpp::String toString() const; bool isValid() const { return units.get() != nullptr; } static Range parse(oatpp::parser::ParsingCaret& caret); - static Range parse(const std::shared_ptr& str); + static Range parse(const oatpp::String& str); }; @@ -189,7 +189,7 @@ private: {} public: - ContentRange(const oatpp::base::String::PtrWrapper& pUnits, + ContentRange(const oatpp::String& pUnits, const oatpp::os::io::Library::v_size& pStart, const oatpp::os::io::Library::v_size& pEnd, const oatpp::os::io::Library::v_size& pSize, @@ -201,20 +201,20 @@ public: , isSizeKnown(pIsSizeKnown) {} - oatpp::base::String::PtrWrapper units; + oatpp::String units; oatpp::os::io::Library::v_size start; oatpp::os::io::Library::v_size end; oatpp::os::io::Library::v_size size; bool isSizeKnown; - oatpp::base::String::PtrWrapper toString() const; + oatpp::String toString() const; bool isValid() const { return units.get() != nullptr; } static ContentRange parse(oatpp::parser::ParsingCaret& caret); - static ContentRange parse(const std::shared_ptr& str); + static ContentRange parse(const oatpp::String& str); }; @@ -231,9 +231,9 @@ public: return Shared_RequestStartingLine_Pool::allocateShared(); } - std::shared_ptr method; // GET, POST ... - std::shared_ptr path; - std::shared_ptr protocol; + oatpp::String method; // GET, POST ... + oatpp::String path; + oatpp::String protocol; }; @@ -250,17 +250,17 @@ public: return Shared_ResponseStartingLine_Pool::allocateShared(); } - std::shared_ptr protocol; + oatpp::String protocol; v_int32 statusCode; - std::shared_ptr description; + oatpp::String description; }; class Protocol { public: - typedef oatpp::collection::ListMap Headers; + typedef oatpp::collection::ListMap Headers; private: - static std::shared_ptr parseHeaderName(oatpp::parser::ParsingCaret& caret); + static oatpp::String parseHeaderName(oatpp::parser::ParsingCaret& caret); public: static std::shared_ptr parseRequestStartingLine(oatpp::parser::ParsingCaret& caret); diff --git a/web/protocol/http/incoming/BodyDecoder.cpp b/web/protocol/http/incoming/BodyDecoder.cpp index 6a3e8d92..b83323e3 100644 --- a/web/protocol/http/incoming/BodyDecoder.cpp +++ b/web/protocol/http/incoming/BodyDecoder.cpp @@ -88,12 +88,12 @@ void BodyDecoder::decode(const std::shared_ptr& headers, const std::shared_ptr& 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& bodyStream, const std::shared_ptr& 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; diff --git a/web/protocol/http/incoming/BodyDecoder.hpp b/web/protocol/http/incoming/BodyDecoder.hpp index 04bfe577..4d0bb410 100644 --- a/web/protocol/http/incoming/BodyDecoder.hpp +++ b/web/protocol/http/incoming/BodyDecoder.hpp @@ -34,7 +34,7 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac class BodyDecoder { private: - class ToStringDecoder : public oatpp::async::CoroutineWithResult> { + class ToStringDecoder : public oatpp::async::CoroutineWithResult { private: std::shared_ptr m_headers; std::shared_ptr m_bodyStream; @@ -58,7 +58,7 @@ private: }; template - class ToDtoDecoder : public oatpp::async::CoroutineWithResult, typename Type::PtrWrapper> { + class ToDtoDecoder : public oatpp::async::CoroutineWithResult, typename Type::ObjectWrapper> { private: std::shared_ptr m_headers; std::shared_ptr m_bodyStream; @@ -79,7 +79,12 @@ private: } oatpp::async::Action onDecoded() { - auto dto = m_objectMapper->readFromString(m_chunkedBuffer->toString()); + auto body = m_chunkedBuffer->toString(); + oatpp::parser::ParsingCaret caret(body); + auto dto = m_objectMapper->readFromCaret(caret); + if(caret.hasError()) { + return this->error(caret.getError()); + } return this->_return(dto); } @@ -104,7 +109,7 @@ public: const std::shared_ptr& bodyStream, const std::shared_ptr& toStream); - static std::shared_ptr + static oatpp::String decodeToString(const std::shared_ptr& headers, const std::shared_ptr& bodyStream) { auto chunkedBuffer = oatpp::data::stream::ChunkedBuffer::createShared(); @@ -113,7 +118,7 @@ public: } template - static typename Type::PtrWrapper decodeToDto(const std::shared_ptr& headers, + static typename Type::ObjectWrapper decodeToDto(const std::shared_ptr& headers, const std::shared_ptr& bodyStream, const std::shared_ptr& objectMapper){ return objectMapper->readFromString(decodeToString(headers, bodyStream)); @@ -130,7 +135,7 @@ public: template static oatpp::async::Action decodeToStringAsync(oatpp::async::AbstractCoroutine* parentCoroutine, - oatpp::async::Action (ParentCoroutineType::*callback)(const oatpp::base::String::PtrWrapper&), + oatpp::async::Action (ParentCoroutineType::*callback)(const oatpp::String&), const std::shared_ptr& headers, const std::shared_ptr& bodyStream) { return parentCoroutine->startCoroutineForResult(callback, headers, bodyStream); @@ -139,7 +144,7 @@ public: template 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& headers, const std::shared_ptr& bodyStream, const std::shared_ptr& objectMapper) { diff --git a/web/protocol/http/incoming/Request.hpp b/web/protocol/http/incoming/Request.hpp index 03a14227..b09656c2 100644 --- a/web/protocol/http/incoming/Request.hpp +++ b/web/protocol/http/incoming/Request.hpp @@ -60,7 +60,7 @@ public: std::shared_ptr headers; std::shared_ptr bodyStream; - base::String::PtrWrapper getHeader(const base::String::PtrWrapper& headerName) const{ + oatpp::String getHeader(const oatpp::String& headerName) const{ auto entry = headers->find(headerName); if(entry != nullptr) { return entry->getValue(); @@ -68,7 +68,7 @@ public: return nullptr; } - base::String::PtrWrapper getPathVariable(const base::String::PtrWrapper& name) const{ + oatpp::String getPathVariable(const oatpp::String& name) const{ auto entry = pathVariables->getVariable(name); if(entry != nullptr) { return entry->getValue(); @@ -76,7 +76,7 @@ public: return nullptr; } - base::String::PtrWrapper getPathTail() const{ + oatpp::String getPathTail() const{ return pathVariables->tail; } @@ -84,18 +84,18 @@ public: protocol::http::incoming::BodyDecoder::decode(headers, bodyStream, toStream); } - std::shared_ptr readBodyToString() const { + oatpp::String readBodyToString() const { return protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream); } template - typename Type::PtrWrapper readBodyToDto(const std::shared_ptr& objectMapper) const { + typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr& objectMapper) const { return objectMapper->readFromString (protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream)); } template - void readBodyToDto(oatpp::base::PtrWrapper& objectWrapper, + void readBodyToDto(oatpp::data::mapping::type::PolymorphicWrapper& objectWrapper, const std::shared_ptr& objectMapper) const { objectWrapper = objectMapper->readFromString (protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream)); @@ -111,13 +111,13 @@ public: template oatpp::async::Action readBodyToStringAsync(oatpp::async::AbstractCoroutine* parentCoroutine, - oatpp::async::Action (ParentCoroutineType::*callback)(const oatpp::base::String::PtrWrapper&)) const { + oatpp::async::Action (ParentCoroutineType::*callback)(const oatpp::String&)) const { return protocol::http::incoming::BodyDecoder::decodeToStringAsync(parentCoroutine, callback, headers, bodyStream); } template 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& objectMapper) const { return protocol::http::incoming::BodyDecoder::decodeToDtoAsync(parentCoroutine, callback, headers, bodyStream, objectMapper); } diff --git a/web/protocol/http/incoming/Response.hpp b/web/protocol/http/incoming/Response.hpp index ad8debfd..e9e4d6b0 100644 --- a/web/protocol/http/incoming/Response.hpp +++ b/web/protocol/http/incoming/Response.hpp @@ -36,7 +36,7 @@ public: SHARED_OBJECT_POOL(Shared_Incoming_Response_Pool, Response, 32) public: Response(v_int32 pStatusCode, - const oatpp::base::String::PtrWrapper& pStatusDescription, + const oatpp::String& pStatusDescription, const std::shared_ptr& pHeaders, const std::shared_ptr& pBodyStream) : statusCode(pStatusCode) @@ -47,14 +47,14 @@ public: public: static std::shared_ptr createShared(v_int32 statusCode, - const oatpp::base::String::PtrWrapper& statusDescription, + const oatpp::String& statusDescription, const std::shared_ptr& headers, const std::shared_ptr& bodyStream) { return Shared_Incoming_Response_Pool::allocateShared(statusCode, statusDescription, headers, bodyStream); } const v_int32 statusCode; - const oatpp::base::String::PtrWrapper statusDescription; + const oatpp::String statusDescription; const std::shared_ptr headers; const std::shared_ptr bodyStream; @@ -62,12 +62,12 @@ public: protocol::http::incoming::BodyDecoder::decode(headers, bodyStream, toStream); } - oatpp::base::String::PtrWrapper readBodyToString() const { + oatpp::String readBodyToString() const { return protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream); } template - typename Type::PtrWrapper readBodyToDto(const std::shared_ptr& objectMapper) const { + typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr& objectMapper) const { return objectMapper->readFromString (protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream)); } @@ -82,13 +82,13 @@ public: template oatpp::async::Action readBodyToStringAsync(oatpp::async::AbstractCoroutine* parentCoroutine, - oatpp::async::Action (ParentCoroutineType::*callback)(const oatpp::base::String::PtrWrapper&)) const { + oatpp::async::Action (ParentCoroutineType::*callback)(const oatpp::String&)) const { return protocol::http::incoming::BodyDecoder::decodeToStringAsync(parentCoroutine, callback, headers, bodyStream); } template 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& objectMapper) const { return protocol::http::incoming::BodyDecoder::decodeToDtoAsync(parentCoroutine, callback, headers, bodyStream, objectMapper); } diff --git a/web/protocol/http/outgoing/Body.hpp b/web/protocol/http/outgoing/Body.hpp index 2d025a67..7449ea23 100644 --- a/web/protocol/http/outgoing/Body.hpp +++ b/web/protocol/http/outgoing/Body.hpp @@ -35,7 +35,7 @@ class Body { protected: typedef oatpp::async::Action Action; protected: - typedef oatpp::collection::ListMap Headers; + typedef oatpp::collection::ListMap Headers; typedef oatpp::data::stream::OutputStream OutputStream; public: virtual void declareHeaders(const std::shared_ptr& headers) = 0; diff --git a/web/protocol/http/outgoing/BufferBody.hpp b/web/protocol/http/outgoing/BufferBody.hpp index 8e4f5bff..123c609e 100644 --- a/web/protocol/http/outgoing/BufferBody.hpp +++ b/web/protocol/http/outgoing/BufferBody.hpp @@ -36,14 +36,14 @@ public: OBJECT_POOL(Http_Outgoing_BufferBody_Pool, BufferBody, 32) SHARED_OBJECT_POOL(Shared_Http_Outgoing_BufferBody_Pool, BufferBody, 32) private: - oatpp::base::String::PtrWrapper m_buffer; + oatpp::String m_buffer; public: - BufferBody(const oatpp::base::String::PtrWrapper& buffer) + BufferBody(const oatpp::String& buffer) : m_buffer(buffer) {} public: - static std::shared_ptr createShared(const oatpp::base::String::PtrWrapper& buffer) { + static std::shared_ptr createShared(const oatpp::String& buffer) { return Shared_Http_Outgoing_BufferBody_Pool::allocateShared(buffer); } diff --git a/web/protocol/http/outgoing/DtoBody.hpp b/web/protocol/http/outgoing/DtoBody.hpp index 71ca8a9a..391c31a4 100644 --- a/web/protocol/http/outgoing/DtoBody.hpp +++ b/web/protocol/http/outgoing/DtoBody.hpp @@ -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 createShared(const oatpp::data::mapping::type::AbstractPtrWrapper& dto, + static std::shared_ptr 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 createShared(const oatpp::data::mapping::type::AbstractPtrWrapper& dto, + static std::shared_ptr 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) override { - if(m_dto.isNull()) { + if(!m_dto) { throw std::runtime_error("Sending null object"); } m_objectMapper->write(m_buffer, m_dto); diff --git a/web/protocol/http/outgoing/Request.hpp b/web/protocol/http/outgoing/Request.hpp index 07992f05..34af79f3 100644 --- a/web/protocol/http/outgoing/Request.hpp +++ b/web/protocol/http/outgoing/Request.hpp @@ -39,8 +39,8 @@ public: public: Request() {} - Request(const base::String::PtrWrapper& pMethod, - const base::String::PtrWrapper& pPath, + Request(const oatpp::String& pMethod, + const oatpp::String& pPath, const std::shared_ptr& pHeaders, const std::shared_ptr& pBody) : method(pMethod) @@ -51,15 +51,15 @@ public: public: - static std::shared_ptr createShared(const base::String::PtrWrapper& method, - const base::String::PtrWrapper& path, + static std::shared_ptr createShared(const oatpp::String& method, + const oatpp::String& path, const std::shared_ptr& headers, const std::shared_ptr& body) { return Shared_Outgoing_Request_Pool::allocateShared(method, path, headers, body); } - const base::String::PtrWrapper method; - const base::String::PtrWrapper path; + const oatpp::String method; + const oatpp::String path; const std::shared_ptr headers; const std::shared_ptr body; diff --git a/web/protocol/http/outgoing/Response.hpp b/web/protocol/http/outgoing/Response.hpp index 3c40eb98..a1c47cf7 100644 --- a/web/protocol/http/outgoing/Response.hpp +++ b/web/protocol/http/outgoing/Response.hpp @@ -33,7 +33,7 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac class Response : public oatpp::base::Controllable { public: - typedef oatpp::collection::ListMap Headers; + typedef oatpp::collection::ListMap Headers; public: OBJECT_POOL(Outgoing_Response_Pool, Response, 32) SHARED_OBJECT_POOL(Shared_Outgoing_Response_Pool, Response, 32) diff --git a/web/protocol/http/outgoing/ResponseFactory.cpp b/web/protocol/http/outgoing/ResponseFactory.cpp index 97b7f4dd..753b124e 100644 --- a/web/protocol/http/outgoing/ResponseFactory.cpp +++ b/web/protocol/http/outgoing/ResponseFactory.cpp @@ -31,7 +31,7 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespace outgoing { std::shared_ptr -ResponseFactory::createShared(const Status& status, const oatpp::base::String::PtrWrapper& text) { +ResponseFactory::createShared(const Status& status, const oatpp::String& text) { return Response::createShared(status, BufferBody::createShared(text)); } @@ -42,7 +42,7 @@ ResponseFactory::createShared(const Status& status, const std::shared_ptr 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)); } diff --git a/web/protocol/http/outgoing/ResponseFactory.hpp b/web/protocol/http/outgoing/ResponseFactory.hpp index 7aed6f45..39ac66f1 100644 --- a/web/protocol/http/outgoing/ResponseFactory.hpp +++ b/web/protocol/http/outgoing/ResponseFactory.hpp @@ -36,10 +36,10 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac class ResponseFactory { public: - static std::shared_ptr createShared(const Status& status, const oatpp::base::String::PtrWrapper& text); + static std::shared_ptr createShared(const Status& status, const oatpp::String& text); static std::shared_ptr createShared(const Status& status, const std::shared_ptr& segBuffer); static std::shared_ptr createShared(const Status& status, - const oatpp::data::mapping::type::AbstractPtrWrapper& dto, + const oatpp::data::mapping::type::AbstractObjectWrapper& dto, oatpp::data::mapping::ObjectMapper* objectMapper); }; diff --git a/web/server/HttpError.hpp b/web/server/HttpError.hpp index 6165a144..fc5b7db5 100644 --- a/web/server/HttpError.hpp +++ b/web/server/HttpError.hpp @@ -26,18 +26,18 @@ #define oatpp_web_server_HttpError_hpp #include "oatpp/web/protocol/http/Http.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" namespace oatpp { namespace web { namespace server { class HttpError : public std::runtime_error { private: oatpp::web::protocol::http::Status m_status; - oatpp::base::String::PtrWrapper m_message; + oatpp::String m_message; public: HttpError(const oatpp::web::protocol::http::Status& status, - const oatpp::base::String::PtrWrapper& message) + const oatpp::String& message) :std::runtime_error(status.description) , m_status(status) , m_message(message) @@ -47,7 +47,7 @@ public: return m_status; } - oatpp::base::String::PtrWrapper& getMessage(){ + oatpp::String& getMessage(){ return m_message; } diff --git a/web/server/HttpProcessor.cpp b/web/server/HttpProcessor.cpp index 71654115..07c50340 100644 --- a/web/server/HttpProcessor.cpp +++ b/web/server/HttpProcessor.cpp @@ -35,19 +35,19 @@ bool HttpProcessor::considerConnectionKeepAlive(const std::shared_ptrheaders->get(protocol::http::Header::CONNECTION, nullptr); - if(!inKeepAlive.isNull() && base::String::equalsCI_FAST(inKeepAlive, 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() && base::String::equalsCI_FAST(outKeepAlive, 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() && base::String::equalsCI_FAST(outKeepAlive, 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; @@ -77,7 +77,7 @@ HttpProcessor::processRequest(HttpRouter* router, auto route = router->getRoute(line->method, line->path); - if(!route.isNull()) { + if(route) { oatpp::web::protocol::http::Status error; auto headers = protocol::http::Protocol::parseHeaders(caret, error); @@ -143,7 +143,7 @@ HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::parseRequest(v_int32 m_currentRoute = m_router->getRoute(line->method, line->path); - if(m_currentRoute.isNull()) { + if(!m_currentRoute) { m_currentResponse = m_errorHandler->handleError(protocol::http::Status::CODE_404, "Current url has no mapping"); return yieldTo(&HttpProcessor::Coroutine::onResponseFormed); } diff --git a/web/server/HttpRouter.hpp b/web/server/HttpRouter.hpp index 1ad0c024..7fed5b74 100644 --- a/web/server/HttpRouter.hpp +++ b/web/server/HttpRouter.hpp @@ -39,12 +39,12 @@ public: std::shared_ptr > BranchRouter; typedef BranchRouter::UrlSubscriber Subscriber; - typedef oatpp::collection::ListMap> BranchMap; + typedef oatpp::collection::ListMap> BranchMap; protected: std::shared_ptr m_branchMap; protected: - const std::shared_ptr& getBranch(const oatpp::base::String::PtrWrapper& name){ + const std::shared_ptr& getBranch(const oatpp::String& name){ auto entry = m_branchMap->find(name); if(entry == nullptr){ auto branch = BranchRouter::createShared(); @@ -63,14 +63,14 @@ public: return std::shared_ptr(new HttpRouter()); } - void addSubscriber(const oatpp::base::String::PtrWrapper& method, - const oatpp::base::String::PtrWrapper& urlPattern, + void addSubscriber(const oatpp::String& method, + const oatpp::String& urlPattern, const std::shared_ptr& subscriber) { getBranch(method)->addSubscriber(urlPattern, subscriber); } - BranchRouter::Route getRoute(const oatpp::base::String::PtrWrapper& method, - const oatpp::base::String::PtrWrapper& url){ + BranchRouter::Route getRoute(const oatpp::String& method, + const oatpp::String& url){ const std::shared_ptr& branch = m_branchMap->get(method, nullptr); if(branch){ return branch->getRoute(url); diff --git a/web/server/api/ApiController.hpp b/web/server/api/ApiController.hpp index 65bc740b..cbf0e4b7 100644 --- a/web/server/api/ApiController.hpp +++ b/web/server/api/ApiController.hpp @@ -57,12 +57,12 @@ public: public: typedef oatpp::data::mapping::ObjectMapper ObjectMapper; - typedef oatpp::data::mapping::type::StringPtrWrapper String; - typedef oatpp::data::mapping::type::Int32::PtrWrapper Int32; - typedef oatpp::data::mapping::type::Int64::PtrWrapper Int64; - typedef oatpp::data::mapping::type::Float32::PtrWrapper Float32; - typedef oatpp::data::mapping::type::Float64::PtrWrapper Float64; - typedef oatpp::data::mapping::type::Boolean::PtrWrapper Boolean; + 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; + typedef oatpp::data::mapping::type::Float64 Float64; + typedef oatpp::data::mapping::type::Boolean Boolean; protected: typedef oatpp::async::Action (oatpp::async::AbstractCoroutine::*AsyncCallback)(const std::shared_ptr&); @@ -175,7 +175,7 @@ public: return m_endpointInfo[endpointName]; } - std::shared_ptr handleError(const Status& status, const base::String::PtrWrapper& message) { + std::shared_ptr handleError(const Status& status, const oatpp::String& message) { return m_errorHandler->handleError(status, message); } @@ -193,7 +193,7 @@ public: // Helper methods std::shared_ptr createResponse(const Status& status, - const oatpp::base::String::PtrWrapper& str) const { + const oatpp::String& str) const { return OutgoingResponseFactory::createShared(status, str); } @@ -203,13 +203,13 @@ public: } std::shared_ptr createDtoResponse(const Status& status, - const oatpp::data::mapping::type::AbstractPtrWrapper& dto, + const oatpp::data::mapping::type::AbstractObjectWrapper& dto, const std::shared_ptr& objectMapper) const { return OutgoingResponseFactory::createShared(status, dto, objectMapper.get()); } std::shared_ptr 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()); } diff --git a/web/server/api/Endpoint.cpp b/web/server/api/Endpoint.cpp index 735dae44..f9c81880 100644 --- a/web/server/api/Endpoint.cpp +++ b/web/server/api/Endpoint.cpp @@ -28,20 +28,20 @@ namespace oatpp { namespace web { namespace server { namespace api { -oatpp::base::PtrWrapper Endpoint::Info::toString() { +oatpp::String Endpoint::Info::toString() { auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); 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"; } diff --git a/web/server/api/Endpoint.hpp b/web/server/api/Endpoint.hpp index af19246c..000f8349 100644 --- a/web/server/api/Endpoint.hpp +++ b/web/server/api/Endpoint.hpp @@ -71,9 +71,9 @@ public: return std::shared_ptr(new Info()); } - base::String::PtrWrapper name; - base::String::PtrWrapper path; - base::String::PtrWrapper method; + oatpp::String name; + oatpp::String path; + oatpp::String method; Param body; @@ -83,7 +83,7 @@ public: std::list returnTypes; - oatpp::base::PtrWrapper toString(); + oatpp::String toString(); }; public: diff --git a/web/server/api/macro/zzz_macro_define_ApiController_.hpp b/web/server/api/macro/zzz_macro_define_ApiController_.hpp index 5c42e081..b9dffb6c 100644 --- a/web/server/api/macro/zzz_macro_define_ApiController_.hpp +++ b/web/server/api/macro/zzz_macro_define_ApiController_.hpp @@ -72,7 +72,7 @@ TYPE NAME = __request; #define OATPP_MACRO_API_CONTROLLER_HEADER_0(TYPE, NAME, PARAM_LIST) \ auto __param_str_val_##NAME = __request->getHeader(#NAME); \ -if(__param_str_val_##NAME.isNull()){ \ +if(!__param_str_val_##NAME){ \ return ApiController::handleError(Status::CODE_400, "Missing HEADER parameter '" #NAME "'"); \ } \ bool __param_validation_check_##NAME; \ @@ -83,15 +83,15 @@ if(!__param_validation_check_##NAME){ \ #define OATPP_MACRO_API_CONTROLLER_HEADER_1(TYPE, NAME, PARAM_LIST) \ auto __param_str_val_##NAME = __request->getHeader(OATPP_MACRO_FIRSTARG PARAM_LIST); \ -if(__param_str_val_##NAME.isNull()){ \ +if(!__param_str_val_##NAME){ \ return ApiController::handleError(Status::CODE_400, \ - oatpp::base::String::createShared("Missing HEADER parameter '") + OATPP_MACRO_FIRSTARG PARAM_LIST + "'"); \ + oatpp::String("Missing HEADER parameter '") + OATPP_MACRO_FIRSTARG PARAM_LIST + "'"); \ } \ bool __param_validation_check_##NAME; \ TYPE NAME = TYPE::Class::parseFromString(__param_str_val_##NAME, __param_validation_check_##NAME); \ if(!__param_validation_check_##NAME){ \ return ApiController::handleError(Status::CODE_400, \ - oatpp::base::String::createShared("Invalid HEADER parameter '") + \ + oatpp::String("Invalid HEADER parameter '") + \ OATPP_MACRO_FIRSTARG PARAM_LIST + \ "'. Expected type is '" #TYPE "'"); \ } @@ -126,7 +126,7 @@ OATPP_MACRO_API_CONTROLLER_HEADER_INFO_CHOOSER_EXP(TYPE, NAME, PARAM_LIST, OATPP #define OATPP_MACRO_API_CONTROLLER_PATH_0(TYPE, NAME, PARAM_LIST) \ auto __param_str_val_##NAME = __request->getPathVariable(#NAME); \ -if(__param_str_val_##NAME.isNull()){ \ +if(!__param_str_val_##NAME){ \ return ApiController::handleError(Status::CODE_400, "Missing PATH parameter '" #NAME "'"); \ } \ bool __param_validation_check_##NAME; \ @@ -137,15 +137,15 @@ if(!__param_validation_check_##NAME){ \ #define OATPP_MACRO_API_CONTROLLER_PATH_1(TYPE, NAME, PARAM_LIST) \ auto __param_str_val_##NAME = __request->getPathVariable(OATPP_MACRO_FIRSTARG PARAM_LIST); \ -if(__param_str_val_##NAME.isNull()){ \ +if(!__param_str_val_##NAME){ \ return ApiController::handleError(Status::CODE_400, \ - oatpp::base::String::createShared("Missing PATH parameter '") + OATPP_MACRO_FIRSTARG PARAM_LIST + "'"); \ + oatpp::String("Missing PATH parameter '") + OATPP_MACRO_FIRSTARG PARAM_LIST + "'"); \ } \ bool __param_validation_check_##NAME; \ TYPE NAME = TYPE::Class::parseFromString(__param_str_val_##NAME, __param_validation_check_##NAME); \ if(!__param_validation_check_##NAME){ \ return ApiController::handleError(Status::CODE_400, \ - oatpp::base::String::createShared("Invalid PATH parameter '") + \ + oatpp::String("Invalid PATH parameter '") + \ OATPP_MACRO_FIRSTARG PARAM_LIST + \ "'. Expected type is '" #TYPE "'"); \ } @@ -192,7 +192,7 @@ info->body.type = oatpp::data::mapping::type::__class::String::getType(); #define OATPP_MACRO_API_CONTROLLER_BODY_DTO(TYPE, NAME, PARAM_LIST) \ TYPE NAME; \ __request->readBodyToDto(NAME, getDefaultObjectMapper()); \ -if(NAME.isNull()) { \ +if(!NAME) { \ return ApiController::handleError(Status::CODE_400, "Missing valid body parameter '" #NAME "'"); \ } diff --git a/web/server/handler/ErrorHandler.cpp b/web/server/handler/ErrorHandler.cpp index 3fd5fea1..5d517f3f 100644 --- a/web/server/handler/ErrorHandler.cpp +++ b/web/server/handler/ErrorHandler.cpp @@ -30,7 +30,7 @@ namespace oatpp { namespace web { namespace server { namespace handler { std::shared_ptr -DefaultErrorHandler::handleError(const protocol::http::Status& status, const base::String::PtrWrapper& message) { +DefaultErrorHandler::handleError(const protocol::http::Status& status, const oatpp::String& message) { auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); stream << "server=" << protocol::http::Header::Value::SERVER << "\n"; diff --git a/web/server/handler/ErrorHandler.hpp b/web/server/handler/ErrorHandler.hpp index ade5ef25..c5f63424 100644 --- a/web/server/handler/ErrorHandler.hpp +++ b/web/server/handler/ErrorHandler.hpp @@ -35,7 +35,7 @@ public: virtual std::shared_ptr - handleError(const protocol::http::Status& status, const base::String::PtrWrapper& message) = 0; + handleError(const protocol::http::Status& status, const oatpp::String& message) = 0; }; @@ -50,7 +50,7 @@ public: } std::shared_ptr - handleError(const protocol::http::Status& status, const base::String::PtrWrapper& message) override; + handleError(const protocol::http::Status& status, const oatpp::String& message) override; }; diff --git a/web/url/Parser.cpp b/web/url/Parser.cpp deleted file mode 100644 index 0bad2634..00000000 --- a/web/url/Parser.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi, - * - * 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 "Parser.hpp" - -namespace oatpp { namespace web { namespace url { - -void Parser::parseQueryParamsToMap(Parameters& params, oatpp::parser::ParsingCaret& caret) { - - if(caret.findChar('?')) { - - do { - caret.inc(); - oatpp::parser::ParsingCaret::Label nameLabel(caret); - if(caret.findChar('=')) { - nameLabel.end(); - caret.inc(); - oatpp::parser::ParsingCaret::Label valueLabel(caret); - caret.findChar('&'); - params.put(nameLabel.toString(), valueLabel.toString()); - } - } while (caret.canContinueAtChar('&')); - - } - -} - -void Parser::parseQueryParamsToMap(Parameters& params, const oatpp::base::String::PtrWrapper& str) { - oatpp::parser::ParsingCaret caret(str.getPtr()); - parseQueryParamsToMap(params, caret); -} - -std::shared_ptr Parser::parseQueryParams(oatpp::parser::ParsingCaret& caret) { - auto params = Parameters::createShared(); - parseQueryParamsToMap(*params, caret); - return params; -} - -std::shared_ptr Parser::parseQueryParams(const oatpp::base::String::PtrWrapper& str) { - auto params = Parameters::createShared(); - parseQueryParamsToMap(*params, str); - return params; -} - -}}} diff --git a/web/url/Parser.hpp b/web/url/Parser.hpp deleted file mode 100644 index 82aa335e..00000000 --- a/web/url/Parser.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi, - * - * 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_web_url_Parser_hpp -#define oatpp_web_url_Parser_hpp - -#include "oatpp/core/collection/ListMap.hpp" -#include "oatpp/core/parser/ParsingCaret.hpp" - -namespace oatpp { namespace web { namespace url { - -class Parser { -public: - typedef oatpp::collection::ListMap Parameters; -public: - - /** - * parse query params in form of "?=&=..." referred by ParsingCaret - * and put that params to Parameters map - */ - static void parseQueryParamsToMap(Parameters& params, oatpp::parser::ParsingCaret& caret); - - /** - * parse query params in form of "?=&=..." referred by str - * and put that params to Parameters map - */ - static void parseQueryParamsToMap(Parameters& params, const oatpp::base::String::PtrWrapper& str); - - /** - * parse query params in form of "?=&=..." referred by ParsingCaret - */ - static std::shared_ptr parseQueryParams(oatpp::parser::ParsingCaret& caret); - - /** - * parse query params in form of "?=&=..." referred by str - */ - static std::shared_ptr parseQueryParams(const oatpp::base::String::PtrWrapper& str); - -}; - -}}} - -#endif /* oatpp_web_url_Parser_hpp */ diff --git a/web/url/mapping/Pattern.cpp b/web/url/mapping/Pattern.cpp index dd0ea4c6..58595ed5 100644 --- a/web/url/mapping/Pattern.cpp +++ b/web/url/mapping/Pattern.cpp @@ -50,7 +50,7 @@ std::shared_ptr Pattern::parse(p_char8 data, v_int32 size){ if(a == '/'){ if(i - lastPos > 0){ - auto part = Part::createShared(Part::FUNCTION_CONST, base::String::createShared(&data[lastPos], i - lastPos, true)); + auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true)); result->m_parts->pushBack(part); } @@ -59,10 +59,10 @@ std::shared_ptr Pattern::parse(p_char8 data, v_int32 size){ } else if(a == '*'){ lastPos = i + 1; if(size > lastPos){ - auto part = Part::createShared(Part::FUNCTION_ANY_END, base::String::createShared(&data[lastPos], size - lastPos, true)); + auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((const char*)&data[lastPos], size - lastPos, true)); result->m_parts->pushBack(part); }else{ - auto part = Part::createShared(Part::FUNCTION_ANY_END, base::String::createShared(0)); + auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String(0)); result->m_parts->pushBack(part); } return result; @@ -75,10 +75,10 @@ std::shared_ptr Pattern::parse(p_char8 data, v_int32 size){ } if(i > lastPos){ - auto part = Part::createShared(Part::FUNCTION_VAR, base::String::createShared(&data[lastPos], i - lastPos, true)); + auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((const char*)&data[lastPos], i - lastPos, true)); result->m_parts->pushBack(part); }else{ - auto part = Part::createShared(Part::FUNCTION_VAR, base::String::createShared(0)); + auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String(0)); result->m_parts->pushBack(part); } @@ -91,7 +91,7 @@ std::shared_ptr Pattern::parse(p_char8 data, v_int32 size){ } if(i - lastPos > 0){ - auto part = Part::createShared(Part::FUNCTION_CONST, base::String::createShared(&data[lastPos], i - lastPos, true)); + auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true)); result->m_parts->pushBack(part); } @@ -102,7 +102,7 @@ std::shared_ptr Pattern::parse(const char* data){ return parse((p_char8) data, (v_int32) std::strlen(data)); } -std::shared_ptr Pattern::parse(const base::String::PtrWrapper& data){ +std::shared_ptr Pattern::parse(const oatpp::String& data){ return parse(data->getData(), data->getSize()); } @@ -134,7 +134,7 @@ std::shared_ptr Pattern::match(p_char8 url, v_int32 size){ } auto vars = MatchMap::Variables::createShared(); - std::shared_ptr tail; + oatpp::String tail; auto curr = m_parts->getFirstNode(); @@ -151,7 +151,7 @@ std::shared_ptr Pattern::match(p_char8 url, v_int32 size){ if(caret.canContinue() && !caret.isAtChar('/')){ if(caret.isAtChar('?') && (curr == nullptr || curr->getData()->function == Part::FUNCTION_ANY_END)) { - tail = base::String::createShared(caret.getCurrData(), size - caret.getPosition(), true); + tail = oatpp::String((const char*)caret.getCurrData(), size - caret.getPosition(), true); return MatchMap::createShared(vars, tail); } return nullptr; @@ -159,7 +159,7 @@ std::shared_ptr Pattern::match(p_char8 url, v_int32 size){ }else if(part->function == Part::FUNCTION_ANY_END){ if(size > caret.getPosition()){ - tail = base::String::createShared(caret.getCurrData(), size - caret.getPosition(), true); + tail = oatpp::String((const char*)caret.getCurrData(), size - caret.getPosition(), true); } return MatchMap::createShared(vars, tail); }else if(part->function == Part::FUNCTION_VAR){ @@ -172,14 +172,14 @@ std::shared_ptr Pattern::match(p_char8 url, v_int32 size){ v_char8 a = findSysChar(caret); if(a == '?') { if(curr == nullptr || curr->getData()->function == Part::FUNCTION_ANY_END) { - vars->put(base::String::createShared(part->text.get(), true), label.toString()); - tail = base::String::createShared(caret.getCurrData(), size - caret.getPosition(), true); + vars->put(oatpp::String(part->text), label.toString()); + tail = oatpp::String((const char*)caret.getCurrData(), size - caret.getPosition(), true); return MatchMap::createShared(vars, tail); } caret.findChar('/'); } - vars->put(base::String::createShared(part->text.get(), true), label.toString()); + vars->put(oatpp::String(part->text), label.toString()); } @@ -198,11 +198,11 @@ std::shared_ptr Pattern::match(const char* url){ return match((p_char8) url, (v_int32) std::strlen(url)); } -std::shared_ptr Pattern::match(const base::String::PtrWrapper& url){ +std::shared_ptr Pattern::match(const oatpp::String& url){ return match(url->getData(), url->getSize()); } -std::shared_ptr Pattern::toString() { +oatpp::String Pattern::toString() { auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); auto curr = m_parts->getFirstNode(); while (curr != nullptr) { diff --git a/web/url/mapping/Pattern.hpp b/web/url/mapping/Pattern.hpp index 0cdd14d4..7e519f46 100644 --- a/web/url/mapping/Pattern.hpp +++ b/web/url/mapping/Pattern.hpp @@ -37,25 +37,25 @@ public: class MatchMap : public base::Controllable{ public: - typedef oatpp::collection::ListMap Variables; + typedef oatpp::collection::ListMap Variables; protected: - MatchMap(const std::shared_ptr& vars, const std::shared_ptr& urlTail) + MatchMap(const std::shared_ptr& vars, const oatpp::String& urlTail) : variables(vars) , tail(urlTail) {} public: static std::shared_ptr createShared(const std::shared_ptr& vars, - const std::shared_ptr& tail){ + const oatpp::String& tail){ return std::shared_ptr(new MatchMap(vars, tail)); } - const Variables::Entry* getVariable(const base::String::PtrWrapper& key){ + const Variables::Entry* getVariable(const oatpp::String& key){ return variables->find(key); } const std::shared_ptr variables; - const base::String::PtrWrapper tail; + const oatpp::String tail; }; @@ -63,7 +63,7 @@ private: class Part : public base::Controllable{ protected: - Part(const char* pFunction, const std::shared_ptr& pText) + Part(const char* pFunction, const oatpp::String& pText) : function(pFunction) , text(pText) {} @@ -73,12 +73,12 @@ private: static const char* FUNCTION_VAR; static const char* FUNCTION_ANY_END; - static std::shared_ptr createShared(const char* function, const std::shared_ptr& text){ + static std::shared_ptr createShared(const char* function, const oatpp::String& text){ return std::shared_ptr(new Part(function, text)); } const char* function; - const std::shared_ptr text; + const oatpp::String text; }; @@ -98,13 +98,13 @@ public: static std::shared_ptr parse(p_char8 data, v_int32 size); static std::shared_ptr parse(const char* data); - static std::shared_ptr parse(const base::String::PtrWrapper& data); + static std::shared_ptr parse(const oatpp::String& data); std::shared_ptr match(p_char8 url, v_int32 size); std::shared_ptr match(const char* url); - std::shared_ptr match(const base::String::PtrWrapper& url); + std::shared_ptr match(const oatpp::String& url); - std::shared_ptr toString(); + oatpp::String toString(); }; diff --git a/web/url/mapping/Router.hpp b/web/url/mapping/Router.hpp index bb608604..96b36e40 100644 --- a/web/url/mapping/Router.hpp +++ b/web/url/mapping/Router.hpp @@ -30,9 +30,9 @@ #include "oatpp/core/collection/LinkedList.hpp" -#include "oatpp/core/base/String.hpp" +#include "oatpp/core/Types.hpp" + -#include "oatpp/core/base/PtrWrapper.hpp" #include "oatpp/core/base/Controllable.hpp" #include "oatpp/core/base/Environment.hpp" @@ -69,8 +69,8 @@ public: return m_subscriber->processUrlAsync(parentCoroutine, callback, param); } - bool isNull() const { - return m_subscriber == nullptr; + explicit operator bool() const { + return m_subscriber != nullptr; } std::shared_ptr matchMap; @@ -108,14 +108,14 @@ public: return std::shared_ptr(new Router()); } - void addSubscriber(const base::String::PtrWrapper& urlPattern, + void addSubscriber(const oatpp::String& urlPattern, const std::shared_ptr& subscriber){ auto pattern = Pattern::parse(urlPattern); auto pair = Pair::createShared(pattern, subscriber); m_subscribers->pushBack(pair); } - Route getRoute(const base::String::PtrWrapper& url){ + Route getRoute(const oatpp::String& url){ auto curr = m_subscribers->getFirstNode(); while(curr != nullptr) { const std::shared_ptr& pair = curr->getData(); diff --git a/web/url/mapping/Subscriber.hpp b/web/url/mapping/Subscriber.hpp index 7cd7c6b2..4a1548d8 100644 --- a/web/url/mapping/Subscriber.hpp +++ b/web/url/mapping/Subscriber.hpp @@ -25,7 +25,7 @@ #ifndef oatpp_web_mapping_url_Subscriber_hpp #define oatpp_web_mapping_url_Subscriber_hpp -#include "oatpp/core/base/PtrWrapper.hpp" + #include "oatpp/core/async/Coroutine.hpp" namespace oatpp { namespace web { namespace url { namespace mapping {