/**
This file is a part of r0nk, atlas_moon, and rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
#ifndef RAII_RJP_STRING_HPP
#define RAII_RJP_STRING_HPP
#include
#include "raii/string_base.hpp"
#include //exchange
#include //memcpy
namespace raii{
namespace detail{
class rjp_allocator
{
public:
static void free(void* data);
static void* allocate(size_t size);
static void* copy(const void* data, size_t len);
};
}
//rjp allocated string
struct rjp_string : public string_intermediary
{
rjp_string(const rjp_string&) = default;
rjp_string(rjp_string&&) = default;
rjp_string& operator=(const rjp_string&) = default;
rjp_string& operator=(rjp_string&&) = default;
using string_intermediary::string_intermediary;
rjp_string(RJP_value* r):
string_intermediary(r ? std::exchange(r->string.value, nullptr) : nullptr, r ? r->string.length : 0){}
using string_intermediary::operator=;
rjp_string& operator=(RJP_value* r){
if(!r)
return *this;
reset();
m_data = std::exchange(r->string.value, nullptr);
m_length = r->string.length;
return *this;
}
};
rjp_string rjp_string_from_key(RJP_value* val);
}
#endif