/** rjp++ Copyright (C) 2020 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef RJP_ARRAY_HPP #define RJP_ARRAY_HPP #include #include //size_t #include "iterator.hpp" #include "value.hpp" #include "integral.hpp" #include "string_val.hpp" #include "rjp_util.hpp" #include "container.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, private container { public: using iterator = array_iterator; using const_iterator = const iterator; using size_type = size_t; public: using value::value; array(void); array(const value& val); 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 = create_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 = create_element(m_value); if constexpr(std::is_same,rjp::array>::value) set_array_value(newelem); else if constexpr(std::is_same,rjp::object>::value) set_object_value(newelem); else if constexpr(std::is_void::underlying_type>::value) set_null_value(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; size_type size(void)const; private: static RJP_value* create_element(RJP_value* arr); }; } #endif