Merge pull request #5 from oatpp/big_string_refactoring

Big string refactoring
This commit is contained in:
Leonid Stryzhevskyi 2018-06-28 00:31:07 +03:00 committed by GitHub
commit bb1a4db399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
84 changed files with 1430 additions and 1312 deletions

View File

@ -22,4 +22,4 @@
*
***************************************************************************/
#include "PtrWrapper.hpp"
#include "Types.hpp"

42
core/Types.hpp Normal file
View File

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

View File

@ -32,6 +32,7 @@
#include <unordered_map>
#include <stdexcept>
#define OATPP_VERSION "0.18.6"
#define OATPP_ASSERT(EXP) \
if(!(EXP)) { \

View File

@ -1,105 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_base_PtrWrapper
#define oatpp_base_PtrWrapper
#include "Controllable.hpp"
namespace oatpp { namespace base {
template<class T>
class PtrWrapper {
protected:
std::shared_ptr<T> m_ptr;
public:
PtrWrapper() {}
PtrWrapper(const std::shared_ptr<T>& ptr)
: m_ptr(ptr)
{}
PtrWrapper(std::shared_ptr<T>&& 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<T> 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<class T, class F>
inline PtrWrapper<T> static_wrapper_cast(const F& from){
return PtrWrapper<T>(std::static_pointer_cast<T>(from.getPtr()));
}
}}
#endif /* oatpp_base_PtrWrapper */

View File

@ -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> String::allocShared(const void* data, v_int32 size, bool copyAsOwnData) {
std::shared_ptr<StrBuffer> StrBuffer::allocShared(const void* data, v_int32 size, bool copyAsOwnData) {
if(copyAsOwnData) {
memory::AllocationExtras extras(size + 1);
const auto& ptr = memory::allocateSharedWithExtras<String>(extras);
const auto& ptr = memory::allocateSharedWithExtras<StrBuffer>(extras);
ptr->setAndCopy(extras.extraPtr, data, size);
return ptr;
}
return std::make_shared<String>(data, size, copyAsOwnData);
return std::make_shared<StrBuffer>(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> String::createShared(const void* data, v_int32 size, bool copyAsOwnData) {
std::shared_ptr<StrBuffer> StrBuffer::createShared(const void* data, v_int32 size, bool copyAsOwnData) {
return allocShared(data, size, copyAsOwnData);
}
std::shared_ptr<String> String::createShared(const char* data, bool copyAsOwnData) {
std::shared_ptr<StrBuffer> StrBuffer::createShared(const char* data, bool copyAsOwnData) {
return allocShared(data, (v_int32) std::strlen(data), copyAsOwnData);
}
std::shared_ptr<String> String::createShared(String* other, bool copyAsOwnData) {
std::shared_ptr<StrBuffer> StrBuffer::createShared(StrBuffer* other, bool copyAsOwnData) {
return allocShared(other->getData(), other->getSize(), copyAsOwnData);
}
std::shared_ptr<String> String::createShared(v_int32 size) {
std::shared_ptr<StrBuffer> StrBuffer::createShared(v_int32 size) {
return allocShared(nullptr, size, true);
}
std::shared_ptr<String> String::createSharedConcatenated(const void* data1, v_int32 size1, const void* data2, v_int32 size2) {
std::shared_ptr<StrBuffer> 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> String::toLowerCase() const {
std::shared_ptr<StrBuffer> 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> String::toUpperCase() const {
std::shared_ptr<StrBuffer> 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<String>& 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<String> operator + (const char* a, const oatpp::base::PtrWrapper<String>& b){
return String::createSharedConcatenated(a, (v_int32) std::strlen(a), b->getData(), b->getSize());
}
oatpp::base::PtrWrapper<String> operator + (const oatpp::base::PtrWrapper<String>& b, const char* a){
return String::createSharedConcatenated(b->getData(), b->getSize(), a, (v_int32) std::strlen(a));
}
oatpp::base::PtrWrapper<String> operator + (const oatpp::base::PtrWrapper<String>& a, const oatpp::base::PtrWrapper<String>& b) {
return String::createSharedConcatenated(a->getData(), a->getSize(), b->getData(), b->getSize());
}
std::shared_ptr<String> operator + (const char* a, const std::shared_ptr<String>& b){
return String::createSharedConcatenated(a, (v_int32) std::strlen(a), b->getData(), b->getSize());
}
std::shared_ptr<String> operator + (const std::shared_ptr<String>& b, const char* a){
return String::createSharedConcatenated(b->getData(), b->getSize(), a, (v_int32) std::strlen(a));
}
}}

146
core/base/StrBuffer.hpp Normal file
View File

@ -0,0 +1,146 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_base_StrBuffer_hpp
#define oatpp_base_StrBuffer_hpp
#include "memory/ObjectPool.hpp"
#include "./Controllable.hpp"
#include <cstring> // 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<StrBuffer> 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)"[<nullptr>]")
, 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<StrBuffer> createShared(v_int32 size);
static std::shared_ptr<StrBuffer> createShared(const void* data, v_int32 size, bool copyAsOwnData = true);
static std::shared_ptr<StrBuffer> createShared(const char* data, bool copyAsOwnData = true);
static std::shared_ptr<StrBuffer> createShared(StrBuffer* other, bool copyAsOwnData = true);
static std::shared_ptr<StrBuffer> createSharedConcatenated(const void* data1, v_int32 size1, const void* data2, v_int32 size2);
static std::shared_ptr<StrBuffer> 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<StrBuffer> toLowerCase() const;
/**
* (correct for ACII only)
*/
std::shared_ptr<StrBuffer> 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 */

View File

@ -1,213 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_base_String_hpp
#define oatpp_base_String_hpp
#include "memory/ObjectPool.hpp"
#include "./Controllable.hpp"
#include "./PtrWrapper.hpp"
#include <cstring> // c
namespace oatpp { namespace base {
class String : public oatpp::base::Controllable {
public:
class PtrWrapper : public oatpp::base::PtrWrapper<String> {
public:
PtrWrapper() {}
PtrWrapper(const std::shared_ptr<String>& ptr)
: oatpp::base::PtrWrapper<String>(ptr)
{}
PtrWrapper(std::shared_ptr<String>&& ptr)
: oatpp::base::PtrWrapper<String>(std::move(ptr))
{}
PtrWrapper(const char* str)
: oatpp::base::PtrWrapper<String>(createFromCString(str))
{}
PtrWrapper(const oatpp::base::PtrWrapper<String>& other)
: oatpp::base::PtrWrapper<String>(other)
{}
PtrWrapper(oatpp::base::PtrWrapper<String>&& other)
: oatpp::base::PtrWrapper<String>(std::move(other))
{}
PtrWrapper& operator = (const char* str) {
m_ptr = String::createFromCString(str);
return *this;
}
PtrWrapper& operator = (const oatpp::base::PtrWrapper<String>& other){
oatpp::base::PtrWrapper<String>::operator=(other);
return *this;
}
PtrWrapper& operator = (oatpp::base::PtrWrapper<String>&& other){
oatpp::base::PtrWrapper<String>::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<String>& 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<String> 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)"[<nullptr>]")
, 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<String> createShared(v_int32 size);
static std::shared_ptr<String> createShared(const void* data, v_int32 size, bool copyAsOwnData = true);
static std::shared_ptr<String> createShared(const char* data, bool copyAsOwnData = true);
static std::shared_ptr<String> createShared(String* other, bool copyAsOwnData = true);
static std::shared_ptr<String> createSharedConcatenated(const void* data1, v_int32 size1, const void* data2, v_int32 size2);
static std::shared_ptr<String> 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<String> toLowerCase() const;
/**
* (correct for ACII only)
*/
std::shared_ptr<String> 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<String>& 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<String> operator + (const char* a, const oatpp::base::PtrWrapper<String>& b);
oatpp::base::PtrWrapper<String> operator + (const oatpp::base::PtrWrapper<String>& b, const char* a);
oatpp::base::PtrWrapper<String> operator + (const oatpp::base::PtrWrapper<String>& a, const oatpp::base::PtrWrapper<String>& b);
std::shared_ptr<String> operator + (const char* a, const std::shared_ptr<String>& b);
std::shared_ptr<String> operator + (const std::shared_ptr<String>& b, const char* a);
}}
#endif /* oatpp_base_String_hpp */

View File

@ -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"

View File

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

View File

@ -25,7 +25,7 @@
#ifndef concurrency_Runnable_hpp
#define concurrency_Runnable_hpp
#include "oatpp/core/base/PtrWrapper.hpp"
namespace oatpp { namespace concurrency {

View File

@ -30,7 +30,7 @@
#include "oatpp/core/base/memory/ObjectPool.hpp"
#include "oatpp/core/base/Controllable.hpp"
#include "oatpp/core/base/PtrWrapper.hpp"
#include <thread>
#include <atomic>

View File

@ -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 {

View File

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

View File

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

View File

@ -32,8 +32,6 @@
#include "oatpp/core/base/memory/ObjectPool.hpp"
#include "oatpp/core/base/Controllable.hpp"
#include "oatpp/core/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 <class T>
using List = oatpp::data::mapping::type::List<T>;
protected:

View File

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

View File

@ -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<oatpp::base::String, __class::String> {
class String : public oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String> {
public:
StringPtrWrapper(const std::shared_ptr<oatpp::base::String>& ptr, const type::Type* const valueType);
String(const std::shared_ptr<oatpp::base::StrBuffer>& ptr, const type::Type* const valueType);
public:
StringPtrWrapper() {}
String() {}
StringPtrWrapper(const std::shared_ptr<oatpp::base::String>& ptr)
: type::PtrWrapper<oatpp::base::String, __class::String>(ptr)
String(v_int32 size)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createShared(size))
{}
StringPtrWrapper(std::shared_ptr<oatpp::base::String>&& ptr)
: type::PtrWrapper<oatpp::base::String, __class::String>(std::move(ptr))
String(const char* data, v_int32 size, bool copyAsOwnData = true)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createShared(data, size, copyAsOwnData))
{}
StringPtrWrapper(const char* str)
: type::PtrWrapper<oatpp::base::String, __class::String>(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, __class::String>(oatpp::base::StrBuffer::createSharedConcatenated(data1, size1, data2, size2))
{}
StringPtrWrapper(const std::string& str)
: type::PtrWrapper<oatpp::base::String, __class::String>
(oatpp::base::String::createShared(str.data(), str.size()))
String(const char* data, bool copyAsOwnData = true)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(oatpp::base::StrBuffer::createFromCString(data, copyAsOwnData))
{}
StringPtrWrapper(const oatpp::base::PtrWrapper<oatpp::base::String>& other)
: type::PtrWrapper<oatpp::base::String, __class::String>(other)
String(const std::shared_ptr<oatpp::base::StrBuffer>& ptr)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(ptr)
{}
StringPtrWrapper(oatpp::base::PtrWrapper<oatpp::base::String>&& other)
: type::PtrWrapper<oatpp::base::String, __class::String>(std::move(other))
String(std::shared_ptr<oatpp::base::StrBuffer>&& ptr)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(std::forward<std::shared_ptr<oatpp::base::StrBuffer>>(ptr))
{}
StringPtrWrapper& operator = (const char* str) {
m_ptr = oatpp::base::String::createFromCString(str);
String(const String& other)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(other)
{}
String(String&& other)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(std::forward<String>(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<oatpp::base::String>& other){
oatpp::base::PtrWrapper<oatpp::base::String>::operator=(other);
String& operator = (String&& other){
m_ptr = std::forward<std::shared_ptr<oatpp::base::StrBuffer>>(other.m_ptr);
return *this;
}
StringPtrWrapper& operator = (oatpp::base::PtrWrapper<oatpp::base::String>&& other){
oatpp::base::PtrWrapper<oatpp::base::String>::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<oatpp::base::String>& 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<typename ValueType, class Clazz>
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<Primitive, Clazz> {
class ObjectWrapper : public oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz> {
public:
PtrWrapper(const std::shared_ptr<Primitive>& ptr, const type::Type* const valueType)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(ptr)
ObjectWrapper(const std::shared_ptr<Primitive>& ptr, const type::Type* const valueType)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(ptr)
{
if(Clazz::getType() != valueType){
throw std::runtime_error("Value type does not match");
@ -135,32 +141,32 @@ public:
}
public:
PtrWrapper()
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>()
ObjectWrapper()
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>()
{}
PtrWrapper(const std::shared_ptr<Primitive>& ptr)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(ptr)
ObjectWrapper(const std::shared_ptr<Primitive>& ptr)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(ptr)
{}
PtrWrapper(std::shared_ptr<Primitive>&& ptr)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(std::move(ptr))
ObjectWrapper(std::shared_ptr<Primitive>&& ptr)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(std::move(ptr))
{}
PtrWrapper(const PtrWrapper& other)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(other)
ObjectWrapper(const ObjectWrapper& other)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(other)
{}
PtrWrapper(PtrWrapper&& other)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(std::move(other))
ObjectWrapper(ObjectWrapper&& other)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(std::move(other))
{}
PtrWrapper(const ValueType& value)
: oatpp::data::mapping::type::PtrWrapper<Primitive, Clazz>(Primitive::createShared(value))
ObjectWrapper(const ValueType& value)
: oatpp::data::mapping::type::ObjectWrapper<Primitive, Clazz>(Primitive::createShared(value))
{}
PtrWrapper& operator = (const ValueType& value){
if(this->isNull()){
ObjectWrapper& operator = (const ValueType& value){
if(!this->m_ptr){
this->m_ptr = Primitive::createShared(value);
} else {
this->m_ptr.get()->setValue(value);
@ -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<v_int32, __class::Int32> Int32;
typedef Primitive<v_int64, __class::Int64> Int64;
typedef Primitive<v_float32, __class::Float32> Float32;
typedef Primitive<v_float64, __class::Float64> Float64;
typedef Primitive<bool, __class::Boolean> Boolean;
typedef Primitive<v_int32, __class::Int32>::ObjectWrapper Int32;
typedef Primitive<v_int64, __class::Int64>::ObjectWrapper Int64;
typedef Primitive<v_float32, __class::Float32>::ObjectWrapper Float32;
typedef Primitive<v_float64, __class::Float64>::ObjectWrapper Float64;
typedef Primitive<bool, __class::Boolean>::ObjectWrapper Boolean;
namespace __class {
@ -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<class T>
base::PtrWrapper<base::String>
primitiveToStr(const oatpp::data::mapping::type::PolymorphicWrapper<T>& primitive) {
auto type = primitive.valueType;
if(type == oatpp::data::mapping::type::__class::String::getType()) {
return std::static_pointer_cast<base::String>(primitive.getPtr());
} else if(type == oatpp::data::mapping::type::__class::Int32::getType()) {
return utils::conversion::int32ToStr(static_cast<oatpp::data::mapping::type::Int32*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Int64::getType()) {
return utils::conversion::int64ToStr(static_cast<oatpp::data::mapping::type::Int64*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Float32::getType()) {
return utils::conversion::float32ToStr(static_cast<oatpp::data::mapping::type::Float32*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Float64::getType()) {
return utils::conversion::float64ToStr(static_cast<oatpp::data::mapping::type::Float64*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Boolean::getType()) {
return utils::conversion::boolToStr(static_cast<oatpp::data::mapping::type::Boolean*>(primitive.get())->getValue());
}
throw std::runtime_error("[oatpp::data::mapping::type::primitiveToStr]: Invalid primitive type");
}
}}}}
namespace std {
template<>
struct hash<oatpp::data::mapping::type::String> {
typedef oatpp::data::mapping::type::String argument_type;
typedef v_word32 result_type;
result_type operator()(oatpp::data::mapping::type::String const& s) const noexcept {
p_char8 data = s->getData();
v_int32 size4 = s->getSize() >> 2;
result_type result = 0;
for(v_int32 i = 0; i < size4; i++) {
result ^= *((p_word32) data);
data += 4;
}
for(v_int32 i = 0; i < s->getSize() - (size4 << 2); i++ ) {
((p_char8) &result)[i] ^= data[i];
}
return result;
}
};
}
#endif /* oatpp_base_controllable_PrimitiveDataTypes_hpp */

View File

@ -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 <list>
#include <unordered_map>
@ -44,45 +44,47 @@ namespace __class {
}
template <class T>
class PolymorphicWrapper : public oatpp::base::PtrWrapper<T> {
class PolymorphicWrapper {
protected:
std::shared_ptr<T> m_ptr;
public:
typedef T ObjectType;
public:
typedef __class::Void Class;
public:
PolymorphicWrapper(const oatpp::base::PtrWrapper<T>& other, const Type* const type)
: oatpp::base::PtrWrapper<T>(other)
, valueType(type)
{}
PolymorphicWrapper(oatpp::base::PtrWrapper<T>&& other, const Type* const type)
: oatpp::base::PtrWrapper<T>(std::move(other))
, valueType(type)
{}
public:
PolymorphicWrapper()
: oatpp::base::PtrWrapper<T>()
PolymorphicWrapper(const std::shared_ptr<T>& ptr)
: m_ptr(ptr)
, valueType(Class::getType())
{}
PolymorphicWrapper(const Type* const type)
: oatpp::base::PtrWrapper<T>()
PolymorphicWrapper(const std::shared_ptr<T>& ptr, const Type* const type)
: m_ptr(ptr)
, valueType(type)
{}
PolymorphicWrapper(const std::shared_ptr<T>& ptr, const Type* const type)
: oatpp::base::PtrWrapper<T>(ptr)
PolymorphicWrapper(std::shared_ptr<T>&& 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<T>(other)
: m_ptr(other.m_ptr)
, valueType(other.valueType)
{}
PolymorphicWrapper(PolymorphicWrapper&& other)
: oatpp::base::PtrWrapper<T>(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<T>& other){
oatpp::base::PtrWrapper<T>::operator = (other);
return *this;
}
PolymorphicWrapper& operator=(const oatpp::base::PtrWrapper<T>&& other){
oatpp::base::PtrWrapper<T>::operator = (std::move(other));
return *this;
}
PolymorphicWrapper& operator=(const PolymorphicWrapper<T>& other){
oatpp::base::PtrWrapper<T>::operator = (other);
m_ptr = other.m_ptr;
return *this;
}
PolymorphicWrapper& operator=(const PolymorphicWrapper<T>&& other){
oatpp::base::PtrWrapper<T>::operator = (std::move(other));
m_ptr = std::move(other.m_ptr);
return *this;
}
@ -114,18 +106,47 @@ public:
return PolymorphicWrapper<oatpp::base::Controllable>(this->m_ptr, valueType);
}
T* operator->() const {
return m_ptr.operator->();
}
T* get() const {
return m_ptr.get();
}
std::shared_ptr<T> 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<class T, class F>
inline PolymorphicWrapper<T> static_wrapper_cast(const F& from){
return PolymorphicWrapper<T>(std::static_pointer_cast<T>(from.getPtr()));
}
template <class T, class Clazz>
class PtrWrapper : public PolymorphicWrapper<T>{
class ObjectWrapper : public PolymorphicWrapper<T>{
public:
typedef T ObjectType;
public:
typedef Clazz Class;
public:
PtrWrapper(const std::shared_ptr<T>& ptr, const type::Type* const valueType)
ObjectWrapper(const std::shared_ptr<T>& ptr, const type::Type* const valueType)
: PolymorphicWrapper<T>(ptr, Class::getType())
{
if(Class::getType() != valueType){
@ -134,51 +155,51 @@ public:
}
public:
PtrWrapper()
ObjectWrapper()
: PolymorphicWrapper<T>(Class::getType())
{}
PtrWrapper(const std::shared_ptr<T>& ptr)
ObjectWrapper(const std::shared_ptr<T>& ptr)
: PolymorphicWrapper<T>(ptr, Class::getType())
{}
PtrWrapper(const oatpp::base::PtrWrapper<T>& other)
: PolymorphicWrapper<T>(other, Class::getType())
ObjectWrapper(const PolymorphicWrapper<T>& other)
: PolymorphicWrapper<T>(other.m_ptr, Class::getType())
{}
PtrWrapper(oatpp::base::PtrWrapper<T>&& other)
: PolymorphicWrapper<T>(std::move(other), Class::getType())
ObjectWrapper(PolymorphicWrapper<T>&& other)
: PolymorphicWrapper<T>(std::move(other.getPtr()), Class::getType())
{}
static PtrWrapper empty(){
return PtrWrapper();
static ObjectWrapper empty(){
return ObjectWrapper();
}
PtrWrapper& operator=(const oatpp::base::PtrWrapper<T>& other){
ObjectWrapper& operator=(const PolymorphicWrapper<T>& other){
if(this->valueType != other.valueType){
OATPP_LOGE("PtrWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::PtrWrapper]: Invalid class cast");
OATPP_LOGE("ObjectWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::ObjectWrapper]: Invalid class cast");
}
PolymorphicWrapper<T>::operator = (other);
return *this;
}
PtrWrapper& operator=(const oatpp::base::PtrWrapper<T>&& other){
ObjectWrapper& operator=(const PolymorphicWrapper<T>&& other){
if(this->valueType != other.valueType){
OATPP_LOGE("PtrWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::PtrWrapper]: Invalid class cast");
OATPP_LOGE("ObjectWrapper", "Invalid class cast");
throw std::runtime_error("[oatpp::data::mapping::type::ObjectWrapper]: Invalid class cast");
}
PolymorphicWrapper<T>::operator = (std::move(other));
PolymorphicWrapper<T>::operator = (std::forward<PolymorphicWrapper<T>>(other));
return *this;
}
};
typedef PolymorphicWrapper<oatpp::base::Controllable> AbstractPtrWrapper;
typedef PolymorphicWrapper<oatpp::base::Controllable> AbstractObjectWrapper;
class Type {
public:
typedef AbstractPtrWrapper (*Creator)();
typedef AbstractObjectWrapper (*Creator)();
public:
class Property; // FWD
typedef std::unordered_map<std::string, Property*> Properties;
@ -203,15 +224,13 @@ public:
const char* const name;
const Type* const type;
void set(void* object, const oatpp::base::PtrWrapper<oatpp::base::Controllable>& value) {
oatpp::base::PtrWrapper<oatpp::base::Controllable>* property =
(oatpp::base::PtrWrapper<oatpp::base::Controllable>*)(((v_int64) object) + offset);
void set(void* object, const AbstractObjectWrapper& value) {
AbstractObjectWrapper* property = (AbstractObjectWrapper*)(((v_int64) object) + offset);
*property = value;
}
oatpp::base::PtrWrapper<oatpp::base::Controllable> get(void* object) {
oatpp::base::PtrWrapper<oatpp::base::Controllable>* property =
(oatpp::base::PtrWrapper<oatpp::base::Controllable>*)(((v_int64) object) + offset);
AbstractObjectWrapper get(void* object) {
AbstractObjectWrapper* property = (AbstractObjectWrapper*)(((v_int64) object) + offset);
return *property;
}

View File

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

View File

@ -181,9 +181,9 @@ os::io::Library::v_size ChunkedBuffer::readSubstring(void *buffer,
}
std::shared_ptr<oatpp::base::String> 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;
}

View File

@ -149,10 +149,10 @@ public:
os::io::Library::v_size pos,
os::io::Library::v_size count);
std::shared_ptr<oatpp::base::String> 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<oatpp::base::String> toString() {
oatpp::String toString() {
return getSubstring(0, m_size);
}

View File

@ -137,7 +137,7 @@ oatpp::async::Action IOStream::readExactSizeDataAsyncInline(oatpp::data::stream:
// Functions
const std::shared_ptr<OutputStream>& operator <<
(const std::shared_ptr<OutputStream>& s, const base::String::PtrWrapper& str) {
(const std::shared_ptr<OutputStream>& s, const oatpp::String& str) {
s->write(str);
return s;
}

View File

@ -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<oatpp::base::String>& 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<OutputStream>& operator <<
(const std::shared_ptr<OutputStream>& s, const base::String::PtrWrapper& str);
(const std::shared_ptr<OutputStream>& s, const oatpp::String& str);
const std::shared_ptr<OutputStream>& operator <<
(const std::shared_ptr<OutputStream>& s, const char* str);

View File

@ -26,6 +26,7 @@
#include <stdlib.h>
#include <cstdlib>
#include <algorithm>
namespace oatpp { namespace parser {
@ -50,7 +51,7 @@ namespace oatpp { namespace parser {
, m_error(nullptr)
{}
ParsingCaret::ParsingCaret(const std::shared_ptr<base::String>& 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<ParsingCaret>(new ParsingCaret(parseData, dataSize));
}
std::shared_ptr<ParsingCaret> ParsingCaret::createShared(const std::shared_ptr<base::String>& str){
std::shared_ptr<ParsingCaret> ParsingCaret::createShared(const oatpp::String& str){
return std::shared_ptr<ParsingCaret>(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<base::String> 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<base::String> 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<base::String> 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<oatpp::base::String> ParsingCaret::findTextFromList(const std::shared_ptr<oatpp::collection::LinkedList<std::shared_ptr<oatpp::base::String>>>& 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<oatpp::collection::LinkedList<oatpp::String>>& list){
while(m_pos < m_size){

View File

@ -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<oatpp::base::String> 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<oatpp::base::String> 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<base::String>& str);
ParsingCaret(const oatpp::String& str);
public:
static std::shared_ptr<ParsingCaret> createShared(const char* text);
static std::shared_ptr<ParsingCaret> createShared(p_char8 parseData, v_int32 dataSize);
static std::shared_ptr<ParsingCaret> createShared(const std::shared_ptr<base::String>& str);
static std::shared_ptr<ParsingCaret> 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<base::String> parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData);
std::shared_ptr<base::String> parseName(bool saveAsOwnData);
oatpp::String parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData);
oatpp::String parseName(bool saveAsOwnData);
std::shared_ptr<base::String> findTextFromList(const std::shared_ptr<oatpp::collection::LinkedList<std::shared_ptr<base::String>>>& list);
bool findText(p_char8 text, v_int32 textSize);
oatpp::String findTextFromList(const std::shared_ptr<oatpp::collection::LinkedList<oatpp::String>>& list);
bool notAtCharFromSet(const char* set) const;
bool notAtCharFromSet(p_char8 set, v_int32 setSize) const;

View File

@ -33,7 +33,7 @@ namespace oatpp { namespace utils { namespace conversion {
return (v_int32) std::strtol(str, &end, 10);
}
v_int32 strToInt32(const base::PtrWrapper<base::String>& 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<base::String>& 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<base::String> 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<base::String>::empty();
return oatpp::String::empty();
}
base::PtrWrapper<base::String> 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<base::String>::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<base::String>& 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<base::String>& 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<base::String> 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<base::String>::empty();
return oatpp::String::empty();
}
base::PtrWrapper<base::String> 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<base::String>::empty();
return oatpp::String::empty();
}
base::PtrWrapper<base::String> 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<base::String>& str, bool& success) {
bool strToBool(const oatpp::String& str, bool& success) {
if(str->equals((p_char8)"true", 4)){
success = true;
return true;

View File

@ -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<base::String>& str, bool& success);
v_int32 strToInt32(const oatpp::String& str, bool& success);
v_int64 strToInt64(const char* str);
v_int64 strToInt64(const base::PtrWrapper<base::String>& 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<base::String> int32ToStr(v_int32 value);
base::PtrWrapper<base::String> 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<typename T>
base::PtrWrapper<base::String> 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<base::String>::empty();
return oatpp::String::empty();
}
v_float32 strToFloat32(const char* str);
v_float32 strToFloat32(const base::PtrWrapper<base::String>& str, bool& success);
v_float32 strToFloat32(const oatpp::String& str, bool& success);
v_float64 strToFloat64(const char* str);
v_float64 strToFloat64(const base::PtrWrapper<base::String>& 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<base::String> float32ToStr(v_float32 value);
base::PtrWrapper<base::String> float64ToStr(v_float64 value);
oatpp::String float32ToStr(v_float32 value);
oatpp::String float64ToStr(v_float64 value);
base::PtrWrapper<base::String> boolToStr(bool value);
bool strToBool(const base::PtrWrapper<base::String>& str, bool& success);
oatpp::String boolToStr(bool value);
bool strToBool(const oatpp::String& str, bool& success);
template<class T>
oatpp::String
primitiveToStr(const oatpp::data::mapping::type::PolymorphicWrapper<T>& primitive) {
auto type = primitive.valueType;
if(type == oatpp::data::mapping::type::__class::String::getType()) {
return std::static_pointer_cast<oatpp::base::StrBuffer>(primitive.getPtr());
} else if(type == oatpp::data::mapping::type::__class::Int32::getType()) {
return utils::conversion::int32ToStr(static_cast<oatpp::data::mapping::type::Int32::ObjectType*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Int64::getType()) {
return utils::conversion::int64ToStr(static_cast<oatpp::data::mapping::type::Int64::ObjectType*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Float32::getType()) {
return utils::conversion::float32ToStr(static_cast<oatpp::data::mapping::type::Float32::ObjectType*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Float64::getType()) {
return utils::conversion::float64ToStr(static_cast<oatpp::data::mapping::type::Float64::ObjectType*>(primitive.get())->getValue());
} else if(type == oatpp::data::mapping::type::__class::Boolean::getType()) {
return utils::conversion::boolToStr(static_cast<oatpp::data::mapping::type::Boolean::ObjectType*>(primitive.get())->getValue());
}
throw std::runtime_error("[oatpp::utils::conversion::primitiveToStr]: Invalid primitive type");
}
}}}

View File

@ -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 {

View File

@ -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);

View File

@ -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;
}

160
network/Url.cpp Normal file
View File

@ -0,0 +1,160 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "Url.hpp"
#include <cstdlib>
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::Parameters> Url::Parser::parseQueryParams(oatpp::parser::ParsingCaret& caret) {
auto params = Url::Parameters::createShared();
parseQueryParamsToMap(*params, caret);
return params;
}
std::shared_ptr<Url::Parameters> 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;
}
}}

113
network/Url.hpp Normal file
View File

@ -0,0 +1,113 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_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<oatpp::String, oatpp::String> Parameters;
public:
struct Authority {
oatpp::String userInfo;
oatpp::String host;
v_int32 port = -1;
};
public:
class Parser {
public:
/**
* parse "<scheme>:"
* 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 "?<paramName>=<paramValue>&<paramName>=<paramValue>..." 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 "?<paramName>=<paramValue>&<paramName>=<paramValue>..." 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 "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by ParsingCaret
*/
static std::shared_ptr<Url::Parameters> parseQueryParams(oatpp::parser::ParsingCaret& caret);
/**
* parse query params in form of "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by str
*/
static std::shared_ptr<Url::Parameters> 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<Parameters> queryParams;
};
}}
#endif /* oatpp_network_url_Url_hpp */

View File

@ -81,13 +81,13 @@ oatpp::async::Action SimpleTCPConnectionProvider::getConnectionAsync(oatpp::asyn
class ConnectCoroutine : public oatpp::async::CoroutineWithResult<ConnectCoroutine, std::shared_ptr<oatpp::data::stream::IOStream>> {
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)
{}

View File

@ -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<SimpleTCPConnectionProvider>
createShared(const oatpp::base::String::PtrWrapper& host, v_int32 port){
createShared(const oatpp::String& host, v_int32 port){
return std::shared_ptr<SimpleTCPConnectionProvider>(new SimpleTCPConnectionProvider(host, port));
}

View File

@ -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 {

View File

@ -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<v_int32> m_status;
std::shared_ptr<base::String> m_port;
oatpp::String m_port;
std::shared_ptr<ServerConnectionProvider> m_connectionProvider;
std::shared_ptr<ConnectionHandler> m_connectionHandler;

View File

@ -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 {

View File

@ -200,13 +200,13 @@ v_int32 Utils::escapeUtf8Char(p_char8 sequence, p_char8 buffer){
}
}
std::shared_ptr<Utils::String> 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::String> 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<ParsingCaret>& 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<ParsingCaret>& 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::String> Utils::parseString(const std::shared_ptr<ParsingCaret>& 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::String> Utils::parseString(const std::shared_ptr<ParsingC
}
std::string Utils::parseStringToStdString(const std::shared_ptr<ParsingCaret>& 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;

View File

@ -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 <string>
@ -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<ParsingCaret>& caret, v_int32& size);
static p_char8 preparseString(ParsingCaret& caret, v_int32& size);
public:
static std::shared_ptr<String> escapeString(p_char8 data, v_int32 size);
static std::shared_ptr<String> 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<String> parseString(const std::shared_ptr<ParsingCaret>& caret);
static std::string parseStringToStdString(const std::shared_ptr<ParsingCaret>& caret);
static String parseString(ParsingCaret& caret);
static std::string parseStringToStdString(ParsingCaret& caret);
};

View File

@ -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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>&
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<oatpp::parser::ParsingCaret>&
}
}
void Deserializer::skipString(const std::shared_ptr<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>
}
}
void Deserializer::skipToken(const std::shared_ptr<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& caret,
Deserializer::AbstractObjectWrapper Deserializer::readObjectValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& 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<oatpp::parser::ParsingCaret>& caret,
Deserializer::AbstractObjectWrapper Deserializer::readListValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& 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<oatpp::parser::ParsingCaret>& caret,
Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& 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<oatpp::parser::ParsingCaret>& caret,
Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& config){
if(caret->canContinueAtChar('[', 1)) {
if(caret.canContinueAtChar('[', 1)) {
auto listWrapper = type->creator();
oatpp::data::mapping::type::PolymorphicWrapper<AbstractList>
@ -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<oatpp::parser::ParsingCaret>& caret,
Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& 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();
}

View File

@ -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<AbstractPtrWrapper> AbstractList;
typedef oatpp::data::mapping::type::List<AbstractObjectWrapper> AbstractList;
public:
@ -81,39 +81,39 @@ public:
static const char* const ERROR_PARSER_ARRAY_SCOPE_CLOSE;
private:
static void skipScope(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret, v_char8 charOpen, v_char8 charClose);
static void skipString(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static void skipToken(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static void skipValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& 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<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readInt32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readInt64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readFloat32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readFloat64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readBooleanValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
static AbstractPtrWrapper readObjectValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& 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>& config);
static AbstractPtrWrapper readListValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
static AbstractObjectWrapper readListValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& config);
static AbstractPtrWrapper readValue(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
static AbstractObjectWrapper readValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& config);
static AbstractPtrWrapper readList(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
static AbstractObjectWrapper readList(const Type* const type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& config);
static AbstractPtrWrapper readObject(const Type* const type,
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
static AbstractObjectWrapper readObject(const Type* const type,
oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& config);
public:
static AbstractPtrWrapper deserialize(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
static AbstractObjectWrapper deserialize(oatpp::parser::ParsingCaret& caret,
const std::shared_ptr<Config>& config,
const Type* const type) {
if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME){
@ -121,7 +121,7 @@ public:
} else if(type->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME){
return readList(type, caret, config);
}
return AbstractPtrWrapper::empty();
return AbstractObjectWrapper::empty();
}
};

View File

@ -54,12 +54,12 @@ public:
}
void write(const std::shared_ptr<oatpp::data::stream::OutputStream>& stream,
const oatpp::data::mapping::type::AbstractPtrWrapper& variant) const override {
const oatpp::data::mapping::type::AbstractObjectWrapper& variant) const override {
Serializer::serialize(stream, variant);
}
oatpp::data::mapping::type::AbstractPtrWrapper
read(const std::shared_ptr<oatpp::parser::ParsingCaret>& 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);
}

View File

@ -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<String>(field->get(object));
auto value = oatpp::data::mapping::type::static_wrapper_cast<oatpp::base::StrBuffer>(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<Object>(field->get(object));
auto value = oatpp::data::mapping::type::static_wrapper_cast<Object>(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<String>(curr->getData());
auto value = oatpp::data::mapping::type::static_wrapper_cast<oatpp::base::StrBuffer>(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<Object>(curr->getData());
auto value = oatpp::data::mapping::type::static_wrapper_cast<Object>(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<AbstractList>(curr->getData());
auto value = oatpp::data::mapping::type::static_wrapper_cast<AbstractList>(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<oatpp::data::mapping::type::Int32>(stream, list);
writeListOfSimpleData<oatpp::data::mapping::type::Int32::ObjectType>(stream, list);
} else if(itemTypeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) {
writeListOfSimpleData<oatpp::data::mapping::type::Int64>(stream, list);
writeListOfSimpleData<oatpp::data::mapping::type::Int64::ObjectType>(stream, list);
} else if(itemTypeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) {
writeListOfSimpleData<oatpp::data::mapping::type::Float32>(stream, list);
writeListOfSimpleData<oatpp::data::mapping::type::Float32::ObjectType>(stream, list);
} else if(itemTypeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) {
writeListOfSimpleData<oatpp::data::mapping::type::Float64>(stream, list);
writeListOfSimpleData<oatpp::data::mapping::type::Float64::ObjectType>(stream, list);
} else if(itemTypeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) {
writeListOfSimpleData<oatpp::data::mapping::type::Boolean>(stream, list);
writeListOfSimpleData<oatpp::data::mapping::type::Boolean::ObjectType>(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<AbstractList>(field->get(object));
auto value = oatpp::data::mapping::type::static_wrapper_cast<AbstractList>(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<oatpp::data::mapping::type::Int32>(stream, object, field);
writeSimpleData<oatpp::data::mapping::type::Int32::ObjectType>(stream, object, field);
} else if(typeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) {
writeSimpleData<oatpp::data::mapping::type::Int64>(stream, object, field);
writeSimpleData<oatpp::data::mapping::type::Int64::ObjectType>(stream, object, field);
} else if(typeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) {
writeSimpleData<oatpp::data::mapping::type::Float32>(stream, object, field);
writeSimpleData<oatpp::data::mapping::type::Float32::ObjectType>(stream, object, field);
} else if(typeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) {
writeSimpleData<oatpp::data::mapping::type::Float64>(stream, object, field);
writeSimpleData<oatpp::data::mapping::type::Float64::ObjectType>(stream, object, field);
} else if(typeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) {
writeSimpleData<oatpp::data::mapping::type::Boolean>(stream, object, field);
writeSimpleData<oatpp::data::mapping::type::Boolean::ObjectType>(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) {

View File

@ -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<T>(field->get(object));
auto value = oatpp::data::mapping::type::static_wrapper_cast<T>(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<T>(curr->getData());
auto value = oatpp::data::mapping::type::static_wrapper_cast<T>(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<oatpp::data::stream::OutputStream>& stream,
const oatpp::data::mapping::type::AbstractPtrWrapper& object){
const oatpp::data::mapping::type::AbstractObjectWrapper& object){
auto type = object.valueType;
if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) {
writeObject(stream.get(), type, static_cast<Object*>(object.get()));

View File

@ -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 <unordered_map>
namespace oatpp { namespace test { namespace base {
@ -61,18 +63,17 @@ namespace {
};
typedef oatpp::base::String String;
typedef oatpp::String String;
template<typename T>
using PtrWrapper = oatpp::base::PtrWrapper<T>;
using ObjectWrapper = oatpp::data::mapping::type::PolymorphicWrapper<T>;
template<typename T>
using PolymorphicWrapper = oatpp::data::mapping::type::PolymorphicWrapper<T>;
template<typename T>
using TypePtrWrapper = oatpp::data::mapping::type::PtrWrapper<T, oatpp::data::mapping::type::__class::Void>;
using TypeObjectWrapper = oatpp::data::mapping::type::ObjectWrapper<T, oatpp::data::mapping::type::__class::Void>;
typedef oatpp::data::mapping::type::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<String> reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
base::PtrWrapper<String> reg3(std::move(reg1));
OATPP_ASSERT(reg1.isNull());
base::PtrWrapper<String> 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<String> 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<String> 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<String> reg2(reg1);
OATPP_ASSERT(!reg1.isNull());
base::PtrWrapper<String> 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<String, String> map;
map["str_1"] = "val_1";
map["str_2"] = "val_2";
map["str_3"] = "val_3";
OATPP_ASSERT(map.find("str_1")->second == "val_1");
OATPP_ASSERT(map.find("str_2")->second == "val_2");
OATPP_ASSERT(map.find("str_3")->second == "val_3");
return true;
}

View File

@ -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 <list>

View File

@ -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 <list>

View File

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

View File

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

View File

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

View File

@ -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::StringToStringMap> 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();
}

View File

@ -43,7 +43,7 @@
#include "oatpp/core/utils/ConversionUtils.hpp"
#include "oatpp/core/base/Controllable.hpp"
#include "oatpp/core/base/PtrWrapper.hpp"
#include <string>
#include <list>
@ -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<std::string, std::shared_ptr<oatpp::base::String>> PathVariablesMap;
typedef std::unordered_map<std::string, oatpp::String> 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<StringToParamMap>& pathParams,
const std::shared_ptr<StringToParamMap>& queryParams) {
oatpp::data::stream::ChunkedBuffer stream;
@ -144,7 +144,7 @@ protected:
return stream.toString();
}
virtual std::shared_ptr<Response> executeRequest(const oatpp::base::String::PtrWrapper& method,
virtual std::shared_ptr<Response> executeRequest(const oatpp::String& method,
const PathPattern& pathPattern,
const std::shared_ptr<StringToParamMap>& headers,
const std::shared_ptr<StringToParamMap>& 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<StringToParamMap>& headers,
const std::shared_ptr<StringToParamMap>& pathParams,

View File

@ -41,19 +41,16 @@
namespace oatpp { namespace web { namespace client {
std::shared_ptr<HttpRequestExecutor::Response>
HttpRequestExecutor::execute(const String::PtrWrapper& method,
const String::PtrWrapper& path,
HttpRequestExecutor::execute(const String& method,
const String& path,
const std::shared_ptr<Headers>& headers,
const std::shared_ptr<Body>& 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>& headers,
const std::shared_ptr<Body>& body) {
class ExecutorCoroutine : public oatpp::async::CoroutineWithResult<ExecutorCoroutine, std::shared_ptr<HttpRequestExecutor::Response>> {
private:
std::shared_ptr<oatpp::network::ClientConnectionProvider> m_connectionProvider;
String::PtrWrapper m_method;
String::PtrWrapper m_path;
String m_method;
String m_path;
std::shared_ptr<Headers> m_headers;
std::shared_ptr<Body> m_body;
private:
@ -125,8 +118,8 @@ oatpp::async::Action HttpRequestExecutor::executeAsync(oatpp::async::AbstractCor
public:
ExecutorCoroutine(const std::shared_ptr<oatpp::network::ClientConnectionProvider>& connectionProvider,
const String::PtrWrapper& method,
const String::PtrWrapper& path,
const String& method,
const String& path,
const std::shared_ptr<Headers>& headers,
const std::shared_ptr<Body>& body)
: m_connectionProvider(connectionProvider)

View File

@ -44,15 +44,18 @@ public:
return std::shared_ptr<HttpRequestExecutor>(new HttpRequestExecutor(connectionProvider));
}
std::shared_ptr<Response> execute(const String::PtrWrapper& method,
const String::PtrWrapper& path,
/**
* throws RequestExecutionError
*/
std::shared_ptr<Response> execute(const String& method,
const String& path,
const std::shared_ptr<Headers>& headers,
const std::shared_ptr<Body>& 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>& headers,
const std::shared_ptr<Body>& body) override;

View File

@ -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<Response>&);
public:
virtual std::shared_ptr<Response> 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<Response> execute(const String& method,
const String& path,
const std::shared_ptr<Headers>& headers,
const std::shared_ptr<Body>& 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>& headers,
const std::shared_ptr<Body>& body) = 0;

View File

@ -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<oatpp::web::protocol::http::incoming::Response> 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; \
} \

View File

@ -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<oatpp::base::String>& 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<oatpp::base::String>& str) {
ContentRange ContentRange::parse(const oatpp::String& str) {
oatpp::parser::ParsingCaret caret(str);
return parse(caret);
}
@ -299,7 +299,7 @@ std::shared_ptr<ResponseStartingLine> Protocol::parseResponseStartingLine(oatpp:
}
std::shared_ptr<oatpp::base::String> 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++) {

View File

@ -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<oatpp::base::String>& 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<oatpp::base::String>& str);
static ContentRange parse(const oatpp::String& str);
};
@ -231,9 +231,9 @@ public:
return Shared_RequestStartingLine_Pool::allocateShared();
}
std::shared_ptr<base::String> method; // GET, POST ...
std::shared_ptr<base::String> path;
std::shared_ptr<base::String> 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<base::String> protocol;
oatpp::String protocol;
v_int32 statusCode;
std::shared_ptr<base::String> description;
oatpp::String description;
};
class Protocol {
public:
typedef oatpp::collection::ListMap<base::String::PtrWrapper, base::String::PtrWrapper> Headers;
typedef oatpp::collection::ListMap<oatpp::String, oatpp::String> Headers;
private:
static std::shared_ptr<oatpp::base::String> parseHeaderName(oatpp::parser::ParsingCaret& caret);
static oatpp::String parseHeaderName(oatpp::parser::ParsingCaret& caret);
public:
static std::shared_ptr<RequestStartingLine> parseRequestStartingLine(oatpp::parser::ParsingCaret& caret);

View File

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

View File

@ -34,7 +34,7 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac
class BodyDecoder {
private:
class ToStringDecoder : public oatpp::async::CoroutineWithResult<ToStringDecoder, std::shared_ptr<oatpp::base::String>> {
class ToStringDecoder : public oatpp::async::CoroutineWithResult<ToStringDecoder, oatpp::String> {
private:
std::shared_ptr<Protocol::Headers> m_headers;
std::shared_ptr<oatpp::data::stream::InputStream> m_bodyStream;
@ -58,7 +58,7 @@ private:
};
template<class Type>
class ToDtoDecoder : public oatpp::async::CoroutineWithResult<ToDtoDecoder<Type>, typename Type::PtrWrapper> {
class ToDtoDecoder : public oatpp::async::CoroutineWithResult<ToDtoDecoder<Type>, typename Type::ObjectWrapper> {
private:
std::shared_ptr<Protocol::Headers> m_headers;
std::shared_ptr<oatpp::data::stream::InputStream> m_bodyStream;
@ -79,7 +79,12 @@ private:
}
oatpp::async::Action onDecoded() {
auto dto = m_objectMapper->readFromString<Type>(m_chunkedBuffer->toString());
auto body = m_chunkedBuffer->toString();
oatpp::parser::ParsingCaret caret(body);
auto dto = m_objectMapper->readFromCaret<Type>(caret);
if(caret.hasError()) {
return this->error(caret.getError());
}
return this->_return(dto);
}
@ -104,7 +109,7 @@ public:
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<oatpp::data::stream::OutputStream>& toStream);
static std::shared_ptr<oatpp::base::String>
static oatpp::String
decodeToString(const std::shared_ptr<Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream) {
auto chunkedBuffer = oatpp::data::stream::ChunkedBuffer::createShared();
@ -113,7 +118,7 @@ public:
}
template<class Type>
static typename Type::PtrWrapper decodeToDto(const std::shared_ptr<Protocol::Headers>& headers,
static typename Type::ObjectWrapper decodeToDto(const std::shared_ptr<Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper){
return objectMapper->readFromString<Type>(decodeToString(headers, bodyStream));
@ -130,7 +135,7 @@ public:
template<typename ParentCoroutineType>
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<Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream) {
return parentCoroutine->startCoroutineForResult<ToStringDecoder>(callback, headers, bodyStream);
@ -139,7 +144,7 @@ public:
template<class DtoType, typename ParentCoroutineType>
static oatpp::async::Action
decodeToDtoAsync(oatpp::async::AbstractCoroutine* parentCoroutine,
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::PtrWrapper&),
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::ObjectWrapper&),
const std::shared_ptr<Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) {

View File

@ -60,7 +60,7 @@ public:
std::shared_ptr<http::Protocol::Headers> headers;
std::shared_ptr<oatpp::data::stream::InputStream> 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<oatpp::base::String> readBodyToString() const {
oatpp::String readBodyToString() const {
return protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream);
}
template<class Type>
typename Type::PtrWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return objectMapper->readFromString<Type>
(protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream));
}
template<class Type>
void readBodyToDto(oatpp::base::PtrWrapper<Type>& objectWrapper,
void readBodyToDto(oatpp::data::mapping::type::PolymorphicWrapper<Type>& objectWrapper,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
objectWrapper = objectMapper->readFromString<Type>
(protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream));
@ -111,13 +111,13 @@ public:
template<typename ParentCoroutineType>
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<class DtoType, typename ParentCoroutineType>
oatpp::async::Action readBodyToDtoAsync(oatpp::async::AbstractCoroutine* parentCoroutine,
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::PtrWrapper&),
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::ObjectWrapper&),
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return protocol::http::incoming::BodyDecoder::decodeToDtoAsync<DtoType>(parentCoroutine, callback, headers, bodyStream, objectMapper);
}

View File

@ -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<http::Protocol::Headers>& pHeaders,
const std::shared_ptr<oatpp::data::stream::InputStream>& pBodyStream)
: statusCode(pStatusCode)
@ -47,14 +47,14 @@ public:
public:
static std::shared_ptr<Response> createShared(v_int32 statusCode,
const oatpp::base::String::PtrWrapper& statusDescription,
const oatpp::String& statusDescription,
const std::shared_ptr<http::Protocol::Headers>& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& 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<http::Protocol::Headers> headers;
const std::shared_ptr<oatpp::data::stream::InputStream> 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<class Type>
typename Type::PtrWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return objectMapper->readFromString<Type>
(protocol::http::incoming::BodyDecoder::decodeToString(headers, bodyStream));
}
@ -82,13 +82,13 @@ public:
template<typename ParentCoroutineType>
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<class DtoType, typename ParentCoroutineType>
oatpp::async::Action readBodyToDtoAsync(oatpp::async::AbstractCoroutine* parentCoroutine,
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::PtrWrapper&),
oatpp::async::Action (ParentCoroutineType::*callback)(const typename DtoType::ObjectWrapper&),
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return protocol::http::incoming::BodyDecoder::decodeToDtoAsync<DtoType>(parentCoroutine, callback, headers, bodyStream, objectMapper);
}

View File

@ -35,7 +35,7 @@ class Body {
protected:
typedef oatpp::async::Action Action;
protected:
typedef oatpp::collection::ListMap<base::String::PtrWrapper, base::String::PtrWrapper> Headers;
typedef oatpp::collection::ListMap<oatpp::String, oatpp::String> Headers;
typedef oatpp::data::stream::OutputStream OutputStream;
public:
virtual void declareHeaders(const std::shared_ptr<Headers>& headers) = 0;

View File

@ -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<BufferBody> createShared(const oatpp::base::String::PtrWrapper& buffer) {
static std::shared_ptr<BufferBody> createShared(const oatpp::String& buffer) {
return Shared_Http_Outgoing_BufferBody_Pool::allocateShared(buffer);
}

View File

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

View File

@ -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<Headers>& pHeaders,
const std::shared_ptr<Body>& pBody)
: method(pMethod)
@ -51,15 +51,15 @@ public:
public:
static std::shared_ptr<Request> createShared(const base::String::PtrWrapper& method,
const base::String::PtrWrapper& path,
static std::shared_ptr<Request> createShared(const oatpp::String& method,
const oatpp::String& path,
const std::shared_ptr<Headers>& headers,
const std::shared_ptr<Body>& 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> headers;
const std::shared_ptr<Body> body;

View File

@ -33,7 +33,7 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac
class Response : public oatpp::base::Controllable {
public:
typedef oatpp::collection::ListMap<base::String::PtrWrapper, base::String::PtrWrapper> Headers;
typedef oatpp::collection::ListMap<oatpp::String, oatpp::String> Headers;
public:
OBJECT_POOL(Outgoing_Response_Pool, Response, 32)
SHARED_OBJECT_POOL(Shared_Outgoing_Response_Pool, Response, 32)

View File

@ -31,7 +31,7 @@
namespace oatpp { namespace web { namespace protocol { namespace http { namespace outgoing {
std::shared_ptr<Response>
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<oatpp:
std::shared_ptr<Response>
ResponseFactory::createShared(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
oatpp::data::mapping::ObjectMapper* objectMapper) {
return Response::createShared(status, DtoBody::createShared(dto, objectMapper));
}

View File

@ -36,10 +36,10 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac
class ResponseFactory {
public:
static std::shared_ptr<Response> createShared(const Status& status, const oatpp::base::String::PtrWrapper& text);
static std::shared_ptr<Response> createShared(const Status& status, const oatpp::String& text);
static std::shared_ptr<Response> createShared(const Status& status, const std::shared_ptr<oatpp::data::stream::ChunkedBuffer>& segBuffer);
static std::shared_ptr<Response> createShared(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
oatpp::data::mapping::ObjectMapper* objectMapper);
};

View File

@ -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;
}

View File

@ -35,19 +35,19 @@ bool HttpProcessor::considerConnectionKeepAlive(const std::shared_ptr<protocol::
if(request) {
auto& inKeepAlive = request->headers->get(protocol::http::Header::CONNECTION, nullptr);
if(!inKeepAlive.isNull() && 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);
}

View File

@ -39,12 +39,12 @@ public:
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
> BranchRouter;
typedef BranchRouter::UrlSubscriber Subscriber;
typedef oatpp::collection::ListMap<oatpp::base::String::PtrWrapper, std::shared_ptr<BranchRouter>> BranchMap;
typedef oatpp::collection::ListMap<oatpp::String, std::shared_ptr<BranchRouter>> BranchMap;
protected:
std::shared_ptr<BranchMap> m_branchMap;
protected:
const std::shared_ptr<BranchRouter>& getBranch(const oatpp::base::String::PtrWrapper& name){
const std::shared_ptr<BranchRouter>& 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<HttpRouter>(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>& 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<BranchRouter>& branch = m_branchMap->get(method, nullptr);
if(branch){
return branch->getRoute(url);

View File

@ -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<OutgoingResponse>&);
@ -175,7 +175,7 @@ public:
return m_endpointInfo[endpointName];
}
std::shared_ptr<OutgoingResponse> handleError(const Status& status, const base::String::PtrWrapper& message) {
std::shared_ptr<OutgoingResponse> handleError(const Status& status, const oatpp::String& message) {
return m_errorHandler->handleError(status, message);
}
@ -193,7 +193,7 @@ public:
// Helper methods
std::shared_ptr<OutgoingResponse> 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<OutgoingResponse> createDtoResponse(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto,
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return OutgoingResponseFactory::createShared(status, dto, objectMapper.get());
}
std::shared_ptr<OutgoingResponse> createDtoResponse(const Status& status,
const oatpp::data::mapping::type::AbstractPtrWrapper& dto) const {
const oatpp::data::mapping::type::AbstractObjectWrapper& dto) const {
return OutgoingResponseFactory::createShared(status, dto, m_defaultObjectMapper.get());
}

View File

@ -28,20 +28,20 @@
namespace oatpp { namespace web { namespace server { namespace api {
oatpp::base::PtrWrapper<oatpp::base::String> 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";
}

View File

@ -71,9 +71,9 @@ public:
return std::shared_ptr<Info>(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<Param> returnTypes;
oatpp::base::PtrWrapper<oatpp::base::String> toString();
oatpp::String toString();
};
public:

View File

@ -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 "'"); \
}

View File

@ -30,7 +30,7 @@
namespace oatpp { namespace web { namespace server { namespace handler {
std::shared_ptr<protocol::http::outgoing::Response>
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";

View File

@ -35,7 +35,7 @@ public:
virtual
std::shared_ptr<protocol::http::outgoing::Response>
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<protocol::http::outgoing::Response>
handleError(const protocol::http::Status& status, const base::String::PtrWrapper& message) override;
handleError(const protocol::http::Status& status, const oatpp::String& message) override;
};

View File

@ -1,66 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "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::Parameters> Parser::parseQueryParams(oatpp::parser::ParsingCaret& caret) {
auto params = Parameters::createShared();
parseQueryParamsToMap(*params, caret);
return params;
}
std::shared_ptr<Parser::Parameters> Parser::parseQueryParams(const oatpp::base::String::PtrWrapper& str) {
auto params = Parameters::createShared();
parseQueryParamsToMap(*params, str);
return params;
}
}}}

View File

@ -1,64 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_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<oatpp::base::String::PtrWrapper, oatpp::base::String::PtrWrapper> Parameters;
public:
/**
* parse query params in form of "?<paramName>=<paramValue>&<paramName>=<paramValue>..." 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 "?<paramName>=<paramValue>&<paramName>=<paramValue>..." 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 "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by ParsingCaret
*/
static std::shared_ptr<Parameters> parseQueryParams(oatpp::parser::ParsingCaret& caret);
/**
* parse query params in form of "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by str
*/
static std::shared_ptr<Parameters> parseQueryParams(const oatpp::base::String::PtrWrapper& str);
};
}}}
#endif /* oatpp_web_url_Parser_hpp */

View File

@ -50,7 +50,7 @@ std::shared_ptr<Pattern> 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> 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> 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> 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> Pattern::parse(const char* data){
return parse((p_char8) data, (v_int32) std::strlen(data));
}
std::shared_ptr<Pattern> Pattern::parse(const base::String::PtrWrapper& data){
std::shared_ptr<Pattern> Pattern::parse(const oatpp::String& data){
return parse(data->getData(), data->getSize());
}
@ -134,7 +134,7 @@ std::shared_ptr<Pattern::MatchMap> Pattern::match(p_char8 url, v_int32 size){
}
auto vars = MatchMap::Variables::createShared();
std::shared_ptr<base::String> tail;
oatpp::String tail;
auto curr = m_parts->getFirstNode();
@ -151,7 +151,7 @@ std::shared_ptr<Pattern::MatchMap> 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::MatchMap> 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::MatchMap> 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::MatchMap> Pattern::match(const char* url){
return match((p_char8) url, (v_int32) std::strlen(url));
}
std::shared_ptr<Pattern::MatchMap> Pattern::match(const base::String::PtrWrapper& url){
std::shared_ptr<Pattern::MatchMap> Pattern::match(const oatpp::String& url){
return match(url->getData(), url->getSize());
}
std::shared_ptr<oatpp::base::String> Pattern::toString() {
oatpp::String Pattern::toString() {
auto stream = oatpp::data::stream::ChunkedBuffer::createShared();
auto curr = m_parts->getFirstNode();
while (curr != nullptr) {

View File

@ -37,25 +37,25 @@ public:
class MatchMap : public base::Controllable{
public:
typedef oatpp::collection::ListMap<base::String::PtrWrapper, base::String::PtrWrapper> Variables;
typedef oatpp::collection::ListMap<oatpp::String, oatpp::String> Variables;
protected:
MatchMap(const std::shared_ptr<Variables>& vars, const std::shared_ptr<base::String>& urlTail)
MatchMap(const std::shared_ptr<Variables>& vars, const oatpp::String& urlTail)
: variables(vars)
, tail(urlTail)
{}
public:
static std::shared_ptr<MatchMap> createShared(const std::shared_ptr<Variables>& vars,
const std::shared_ptr<base::String>& tail){
const oatpp::String& tail){
return std::shared_ptr<MatchMap>(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> 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<base::String>& 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<Part> createShared(const char* function, const std::shared_ptr<base::String>& text){
static std::shared_ptr<Part> createShared(const char* function, const oatpp::String& text){
return std::shared_ptr<Part>(new Part(function, text));
}
const char* function;
const std::shared_ptr<base::String> text;
const oatpp::String text;
};
@ -98,13 +98,13 @@ public:
static std::shared_ptr<Pattern> parse(p_char8 data, v_int32 size);
static std::shared_ptr<Pattern> parse(const char* data);
static std::shared_ptr<Pattern> parse(const base::String::PtrWrapper& data);
static std::shared_ptr<Pattern> parse(const oatpp::String& data);
std::shared_ptr<MatchMap> match(p_char8 url, v_int32 size);
std::shared_ptr<MatchMap> match(const char* url);
std::shared_ptr<MatchMap> match(const base::String::PtrWrapper& url);
std::shared_ptr<MatchMap> match(const oatpp::String& url);
std::shared_ptr<oatpp::base::String> toString();
oatpp::String toString();
};

View File

@ -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<Pattern::MatchMap> matchMap;
@ -108,14 +108,14 @@ public:
return std::shared_ptr<Router>(new Router());
}
void addSubscriber(const base::String::PtrWrapper& urlPattern,
void addSubscriber(const oatpp::String& urlPattern,
const std::shared_ptr<UrlSubscriber>& 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>& pair = curr->getData();

View File

@ -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 {