Add middleman functions to prevent needing to also link rjp when linking against rjp++
This commit is contained in:
parent
662f24ef9a
commit
44b4bd8b19
@ -13,9 +13,9 @@ option(BUILD_TESTS "Build test programs" OFF)
|
||||
option(ENABLE_PROFILING "Enable asan" OFF)
|
||||
mark_as_advanced(ENABLE_PROFILING)
|
||||
|
||||
set(SOURCE_LIST "src/allocator.cpp" "src/array.cpp" "src/integral.cpp" "src/object.cpp" "src/rjp.cpp" "src/string.cpp" "src/string_val.cpp" "src/value.cpp" "src/vget_proxy.cpp")
|
||||
set(SOURCE_LIST "src/allocator.cpp" "src/array.cpp" "src/integral.cpp" "src/object.cpp" "src/rjp.cpp" "src/string.cpp" "src/string_val.cpp" "src/value.cpp" "src/vget_proxy.cpp" "src/container.cpp")
|
||||
if(ENABLE_SHARED)
|
||||
set(RJP++_LIBFLAGS "-lrjp++ -lrjp")
|
||||
set(RJP++_LIBFLAGS "-lrjp++ -lrexy")
|
||||
add_library(rjp++ SHARED ${SOURCE_LIST})
|
||||
set_target_properties(rjp++ PROPERTIES SOVERSION "${rjp_VERSION_MAJOR}.${rjp_VERSION_MINOR}.${rjp_VERSION_REVISION}")
|
||||
else()
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include "integral.hpp"
|
||||
#include "string_val.hpp"
|
||||
#include "rjp_util.hpp"
|
||||
|
||||
#include "container.hpp"
|
||||
|
||||
namespace rjp{
|
||||
|
||||
@ -34,7 +34,7 @@ namespace rjp{
|
||||
|
||||
array_iterator& operator++(void);
|
||||
};
|
||||
class array : public value
|
||||
class array : public value, private container
|
||||
{
|
||||
public:
|
||||
using iterator = array_iterator;
|
||||
@ -53,19 +53,19 @@ namespace rjp{
|
||||
|
||||
template<class Val>
|
||||
std::decay_t<Val> add(typename std::decay_t<Val>::underlying_type t){
|
||||
RJP_value* newelem = rjp_new_element(m_value);
|
||||
RJP_value* newelem = create_element(m_value);
|
||||
detail::set_to_underlying<std::decay_t<Val>>(newelem, t);
|
||||
return std::decay_t<Val>(create_unmanaged(newelem));
|
||||
}
|
||||
template<class Val = null>
|
||||
std::decay_t<Val> add(void){
|
||||
RJP_value* newelem = rjp_new_element(m_value);
|
||||
RJP_value* newelem = create_element(m_value);
|
||||
if constexpr(std::is_same<std::decay_t<Val>,rjp::array>::value)
|
||||
rjp_set_array(newelem);
|
||||
set_array_value(newelem);
|
||||
else if constexpr(std::is_same<std::decay_t<Val>,rjp::object>::value)
|
||||
rjp_set_object(newelem);
|
||||
set_object_value(newelem);
|
||||
else if constexpr(std::is_void<typename std::decay_t<Val>::underlying_type>::value)
|
||||
rjp_set_null(newelem);
|
||||
set_null_value(newelem);
|
||||
else
|
||||
detail::set_to_underlying<std::decay_t<Val>>(newelem, 0);
|
||||
return std::decay_t<Val>(create_unmanaged(newelem));
|
||||
@ -83,6 +83,9 @@ namespace rjp{
|
||||
iterator end(void);
|
||||
const_iterator begin(void)const;
|
||||
const_iterator end(void)const;
|
||||
|
||||
private:
|
||||
static RJP_value* create_element(RJP_value* arr);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
17
rjp++/include/container.hpp
Normal file
17
rjp++/include/container.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef RJP_CONTAINER_HPP
|
||||
#define RJP_CONTAINER_HPP
|
||||
|
||||
#include <rjp.h>
|
||||
|
||||
namespace rjp{
|
||||
|
||||
struct container
|
||||
{
|
||||
static void set_array_value(RJP_value* v);
|
||||
static void set_object_value(RJP_value* v);
|
||||
static void set_null_value(RJP_value* v);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -9,8 +9,12 @@
|
||||
|
||||
namespace rjp{
|
||||
|
||||
struct member_base
|
||||
{
|
||||
static const RJP_string* member_key(RJP_value* v);
|
||||
};
|
||||
template<class Type>
|
||||
class member : public Type
|
||||
class member : public Type, private member_base
|
||||
{
|
||||
public:
|
||||
member(void) = default;
|
||||
@ -31,14 +35,14 @@ namespace rjp{
|
||||
member& operator=(member&&) = default;
|
||||
|
||||
rexy::static_string key(void)const{
|
||||
return rexy::static_string(rjp_member_key(this->m_value)->value, rjp_member_key(this->m_value)->length);
|
||||
return rexy::static_string(member_key(this->m_value)->value, member_key(this->m_value)->length);
|
||||
}
|
||||
string steal_key(void){
|
||||
return string(this->m_value);
|
||||
}
|
||||
};
|
||||
template<>
|
||||
class member<void> : public value
|
||||
class member<void> : public value, private member_base
|
||||
{
|
||||
public:
|
||||
member(void) = default;
|
||||
@ -55,7 +59,7 @@ namespace rjp{
|
||||
member& operator=(member&&) = default;
|
||||
|
||||
rexy::static_string key(void)const{
|
||||
return rexy::static_string(rjp_member_key(m_value)->value, rjp_member_key(m_value)->length);
|
||||
return rexy::static_string(member_key(m_value)->value, member_key(m_value)->length);
|
||||
}
|
||||
string steal_key(void){
|
||||
return string(m_value);
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include "integral.hpp"
|
||||
#include "string_val.hpp"
|
||||
#include "rjp_util.hpp"
|
||||
#include "container.hpp"
|
||||
|
||||
namespace rjp{
|
||||
|
||||
@ -36,7 +37,7 @@ namespace rjp{
|
||||
object_iterator& operator++(void);
|
||||
};
|
||||
|
||||
class object : public value
|
||||
class object : public value, private container
|
||||
{
|
||||
public:
|
||||
using iterator = object_iterator;
|
||||
@ -55,19 +56,19 @@ namespace rjp{
|
||||
|
||||
template<class Val>
|
||||
member<std::decay_t<Val>> add(const rexy::string_base& key, typename std::decay_t<Val>::underlying_type t){
|
||||
RJP_value* newmem = rjp_new_member(m_value, key.get(), key.length());
|
||||
RJP_value* newmem = add_member_impl(key);
|
||||
detail::set_to_underlying<std::decay_t<Val>>(newmem, t);
|
||||
return create_unmanaged(newmem);
|
||||
}
|
||||
template<class Val = null>
|
||||
member<std::decay_t<Val>> add(const rexy::string_base& key){
|
||||
RJP_value* newmem = rjp_new_member(m_value, key.get(), key.length());
|
||||
RJP_value* newmem = add_member_impl(key);
|
||||
if constexpr(std::is_same<std::decay_t<Val>,rjp::array>::value)
|
||||
rjp_set_array(newmem);
|
||||
set_array_value(newmem);
|
||||
else if constexpr(std::is_same<std::decay_t<Val>,rjp::object>::value)
|
||||
rjp_set_object(newmem);
|
||||
set_object_value(newmem);
|
||||
else if constexpr(std::is_void<typename std::decay_t<Val>::underlying_type>::value)
|
||||
rjp_set_null(newmem);
|
||||
set_null_value(newmem);
|
||||
else
|
||||
detail::set_to_underlying<std::decay_t<Val>>(newmem, 0);
|
||||
return create_unmanaged(newmem);
|
||||
@ -80,21 +81,19 @@ namespace rjp{
|
||||
|
||||
template<class Val>
|
||||
member<std::decay_t<Val>> add(string&& key, typename std::decay_t<Val>::underlying_type t){
|
||||
auto len = key.length();
|
||||
RJP_value* newmem = rjp_new_member_steal_key(m_value, key.release(), len);
|
||||
RJP_value* newmem = add_member_impl(std::move(key));
|
||||
detail::set_to_underlying<std::decay_t<Val>>(newmem, t);
|
||||
return create_unmanaged(newmem);
|
||||
}
|
||||
template<class Val = null>
|
||||
member<std::decay_t<Val>> add(string&& key){
|
||||
auto len = key.length();
|
||||
RJP_value* newmem = rjp_new_member_steal_key(m_value, key.release(), len);
|
||||
RJP_value* newmem = add_member_impl(std::move(key));
|
||||
if constexpr(std::is_same<std::decay_t<Val>,rjp::array>::value)
|
||||
rjp_set_array(newmem);
|
||||
set_array_value(newmem);
|
||||
else if constexpr(std::is_same<std::decay_t<Val>,rjp::object>::value)
|
||||
rjp_set_object(newmem);
|
||||
set_object_value(newmem);
|
||||
else if constexpr(std::is_void<typename std::decay_t<Val>::underlying_type>::value)
|
||||
rjp_set_null(newmem);
|
||||
set_null_value(newmem);
|
||||
else
|
||||
detail::set_to_underlying<std::decay_t<Val>>(newmem, 0);
|
||||
return create_unmanaged(newmem);
|
||||
@ -119,6 +118,9 @@ namespace rjp{
|
||||
|
||||
value search(const rexy::string_base& key);
|
||||
|
||||
private:
|
||||
RJP_value* add_member_impl(const rexy::string_base& key);
|
||||
RJP_value* add_member_impl(rexy::string_base&& key);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ namespace rjp{
|
||||
return ph(c, size, typename sequence_gen<sizeof...(Args)>::type{});
|
||||
}
|
||||
};
|
||||
|
||||
RJP_value* parse_cback(RJP_parse_flag f, RJP_parse_callback* cb);
|
||||
int irjp_parse_callback(char* dest, int size, void* userdata);
|
||||
}
|
||||
template<class Func, class... Args>
|
||||
@ -57,7 +57,7 @@ namespace rjp{
|
||||
detail::invoker_impl<Func,Args...> inv(std::forward<Func>(func), std::forward<Args>(args)...);
|
||||
cb.data = static_cast<void*>(&inv);
|
||||
cb.read = detail::irjp_parse_callback;
|
||||
return value(rjp_parse_cback(f, &cb), true);
|
||||
return value(detail::parse_cback(f, &cb), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -78,7 +78,9 @@ namespace rjp{
|
||||
array::iterator array::end(void){
|
||||
return iterator();
|
||||
}
|
||||
|
||||
RJP_value* array::create_element(RJP_value* arr){
|
||||
return rjp_new_element(arr);
|
||||
}
|
||||
|
||||
|
||||
array_iterator::array_iterator(RJP_value* v){
|
||||
@ -115,4 +117,5 @@ namespace rjp{
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
16
rjp++/src/container.cpp
Normal file
16
rjp++/src/container.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "container.hpp"
|
||||
#include <rjp.h>
|
||||
|
||||
namespace rjp{
|
||||
|
||||
void container::set_array_value(RJP_value* v){
|
||||
rjp_set_array(v);
|
||||
}
|
||||
void container::set_object_value(RJP_value* v){
|
||||
rjp_set_object(v);
|
||||
}
|
||||
void container::set_null_value(RJP_value* v){
|
||||
rjp_set_null(v);
|
||||
}
|
||||
|
||||
}
|
||||
@ -118,12 +118,19 @@ namespace rjp{
|
||||
object::iterator object::end(void)const{
|
||||
return iterator();
|
||||
}
|
||||
|
||||
value object::search(const rexy::string_base& key){
|
||||
RJP_value* result = rjp_search_member(m_value, key.get());
|
||||
return create_unmanaged(result);
|
||||
}
|
||||
|
||||
RJP_value* object::add_member_impl(const rexy::string_base& key){
|
||||
return rjp_new_member(m_value, key.get(), key.length());
|
||||
}
|
||||
RJP_value* object::add_member_impl(rexy::string_base&& key){
|
||||
auto length = key.length();
|
||||
return rjp_new_member_steal_key(m_value, key.release(), length);
|
||||
}
|
||||
|
||||
|
||||
object_iterator::object_iterator(void):
|
||||
m_it(){}
|
||||
|
||||
@ -43,6 +43,9 @@ namespace rjp{
|
||||
invoker* inv = static_cast<invoker*>(userdata);
|
||||
return inv->run(dest, size);
|
||||
}
|
||||
RJP_value* parse_cback(RJP_parse_flag f, RJP_parse_callback* cb){
|
||||
return rjp_parse_cback(f, cb);
|
||||
}
|
||||
|
||||
template<>
|
||||
void set_to_underlying<rjp::integer>(RJP_value* val, RJP_int i){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user