/** This file is a part of rexy's matrix client Copyright (C) 2019-2020 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 #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 rexy::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 rexy::string_intermediary::string_intermediary; rjp_string(RJP_value* r): rexy::string_intermediary(r ? rjp_get_string(r)->value : nullptr, r ? rjp_get_string(r)->length : 0, r ? rjp_get_string(r)->length : 0) { if(r){ RJP_string* str = rjp_get_string(r); str->value = nullptr; str->length = 0; rjp_set_null(r); } } using rexy::string_intermediary::operator=; rjp_string& operator=(RJP_value* r){ if(!r) return *this; reset(); RJP_string* str = rjp_get_string(r); m_data = std::exchange(str->value, nullptr); m_length = str->length; m_cap = str->length; str->length = 0; return *this; } }; } #endif