/**
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_OBJECT_HPP
#define RJP_OBJECT_HPP
#include
#include
#include "value.hpp"
#include "iterator.hpp"
#include "member.hpp"
#include "integral.hpp"
#include "string_val.hpp"
#include "rjp_util.hpp"
#include "container.hpp"
namespace rjp{
class array;
class object_iterator : protected detail::iterator_base
{
protected:
RJP_object_iterator m_it;
public:
object_iterator(void);
object_iterator(RJP_value* v);
object_iterator(const object_iterator&) = delete;
object_iterator(object_iterator&& o);
~object_iterator(void);
object_iterator& operator=(const object_iterator&) = delete;
object_iterator& operator=(object_iterator&& o);
bool operator==(const object_iterator& o)const;
bool operator!=(const object_iterator& o)const;
member operator*(void)const;
value_wrapper operator->(void)const;
object_iterator& operator++(void);
};
class object : public value, private container
{
public:
using iterator = object_iterator;
using const_iterator = const iterator;
public:
using value::value;
object(void);
object(const value& val);
object(value&& val);
object(const object&) = default;
object(object&&) = default;
~object(void) = default;
object& operator=(const object&) = default;
object& operator=(object&&) = default;
template
member> add(const rexy::string_base& key, typename std::decay_t::underlying_type t){
RJP_value* newmem = add_member_impl(key);
detail::set_to_underlying>(newmem, t);
return create_unmanaged(newmem);
}
template
member> add(const rexy::string_base& key){
RJP_value* newmem = add_member_impl(key);
if constexpr(std::is_same,rjp::array>::value)
set_array_value(newmem);
else if constexpr(std::is_same,rjp::object>::value)
set_object_value(newmem);
else if constexpr(std::is_void::underlying_type>::value)
set_null_value(newmem);
else
detail::set_to_underlying>(newmem, 0);
return create_unmanaged(newmem);
}
member add(const rexy::string_base& key, const RJP_string&);
member add(const rexy::string_base& key, RJP_string&&);
member add(const rexy::string_base& key, const char*, RJP_index len = 0);
member add(const rexy::string_base& key, const rexy::string_base&);
member add(const rexy::string_base& key, string&&);
template
member> add(string&& key, typename std::decay_t::underlying_type t){
RJP_value* newmem = add_member_impl(std::move(key));
detail::set_to_underlying>(newmem, t);
return create_unmanaged(newmem);
}
template
member> add(string&& key){
RJP_value* newmem = add_member_impl(std::move(key));
if constexpr(std::is_same,rjp::array>::value)
set_array_value(newmem);
else if constexpr(std::is_same,rjp::object>::value)
set_object_value(newmem);
else if constexpr(std::is_void::underlying_type>::value)
set_null_value(newmem);
else
detail::set_to_underlying>(newmem, 0);
return create_unmanaged(newmem);
}
member add(string&& key, const RJP_string&);
member add(string&& key, RJP_string&&);
member add(string&& key, const char*, RJP_index len = 0);
member add(string&& key, const rexy::string_base&);
member add(string&& key, string&&);
value remove(const rexy::string_base& key);
value& remove(value& val);
void destroy(const rexy::string_base& key);
void destroy(value&& val);
bool has_child(const value&);
iterator begin(void);
const_iterator begin(void)const;
iterator end(void)const;
value search(const rexy::string_base& key)const;
private:
RJP_value* add_member_impl(const rexy::string_base& key);
RJP_value* add_member_impl(string&& key);
};
}
#endif