91 lines
2.4 KiB
C++
91 lines
2.4 KiB
C++
#ifndef RJP_ARRAY_HPP
|
|
#define RJP_ARRAY_HPP
|
|
|
|
#include <rjp.h>
|
|
#include "iterator.hpp"
|
|
#include "value.hpp"
|
|
#include "integral.hpp"
|
|
#include "string_val.hpp"
|
|
#include "rjp_util.hpp"
|
|
|
|
|
|
namespace rjp{
|
|
|
|
class object;
|
|
|
|
class array_iterator : protected detail::iterator_base
|
|
{
|
|
protected:
|
|
RJP_array_iterator m_it;
|
|
|
|
public:
|
|
array_iterator(void) = default;
|
|
array_iterator(RJP_value* v);
|
|
array_iterator(const array_iterator&) = delete;
|
|
array_iterator(array_iterator&& a);
|
|
~array_iterator(void);
|
|
array_iterator& operator=(const array_iterator&) = delete;
|
|
array_iterator& operator=(array_iterator&& o);
|
|
|
|
bool operator==(const array_iterator& o)const;
|
|
bool operator!=(const array_iterator& o)const;
|
|
value operator*(void)const;
|
|
value_wrapper operator->(void)const;
|
|
|
|
array_iterator& operator++(void);
|
|
};
|
|
class array : public value
|
|
{
|
|
public:
|
|
using iterator = array_iterator;
|
|
using const_iterator = const iterator;
|
|
public:
|
|
using value::value;
|
|
array(void);
|
|
explicit array(const value& val);
|
|
explicit array(value&& val);
|
|
|
|
array(const array&) = default;
|
|
array(array&&) = default;
|
|
~array(void) = default;
|
|
array& operator=(const array&) = default;
|
|
array& operator=(array&&) = default;
|
|
|
|
template<class Val>
|
|
std::decay_t<Val> add(typename std::decay_t<Val>::underlying_type t){
|
|
RJP_value* newelem = rjp_new_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);
|
|
if constexpr(std::is_same<std::decay_t<Val>,rjp::array>::value)
|
|
rjp_set_array(newelem);
|
|
else if constexpr(std::is_same<std::decay_t<Val>,rjp::object>::value)
|
|
rjp_set_object(newelem);
|
|
else if constexpr(std::is_void<typename std::decay_t<Val>::underlying_type>::value)
|
|
rjp_set_null(newelem);
|
|
else
|
|
detail::set_to_underlying<std::decay_t<Val>>(newelem, 0);
|
|
return std::decay_t<Val>(create_unmanaged(newelem));
|
|
}
|
|
string_val add(const RJP_string&);
|
|
string_val add(RJP_string&&);
|
|
string_val add(const char*, RJP_index len = 0);
|
|
string_val add(const rexy::string_base&);
|
|
string_val add(string&&);
|
|
|
|
value& remove(value& val);
|
|
void destroy(value&& val);
|
|
|
|
iterator begin(void);
|
|
iterator end(void);
|
|
const_iterator begin(void)const;
|
|
const_iterator end(void)const;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|