#ifndef RJP_ARRAY_HPP #define RJP_ARRAY_HPP #include #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 std::decay_t add(typename std::decay_t::underlying_type t){ RJP_value* newelem = rjp_new_element(m_value); detail::set_to_underlying>(newelem, t); return std::decay_t(create_unmanaged(newelem)); } template std::decay_t add(void){ RJP_value* newelem = rjp_new_element(m_value); if constexpr(std::is_same,rjp::array>::value) rjp_set_array(newelem); else if constexpr(std::is_same,rjp::object>::value) rjp_set_object(newelem); else if constexpr(std::is_void::underlying_type>::value) rjp_set_null(newelem); else detail::set_to_underlying>(newelem, 0); return std::decay_t(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