/** This file is a part of 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 MATRIX_NETRETURN_HPP #define MATRIX_NETRETURN_HPP #include "raii/rjp_string.hpp" #include //std::forward namespace matrix{ class netreturn_base { protected: raii::rjp_string m_error = {}; raii::rjp_string m_errorcode = {}; int m_http_error = 200; public: constexpr netreturn_base(void) = default; netreturn_base(const raii::rjp_string& error, const raii::rjp_string& errorcode, int httpstatus); netreturn_base(const raii::rjp_string& error, raii::rjp_string&& errorcode, int httpstatus); netreturn_base(raii::rjp_string&& error, const raii::rjp_string& errorcode, int httpstatus); netreturn_base(raii::rjp_string&& error, raii::rjp_string&& errorcode, int httpstatus); bool ok(void)const; const raii::rjp_string& mxerror(void)const; const raii::rjp_string& mxerrorcode(void)const; raii::rjp_string& mxerror(void); raii::rjp_string& mxerrorcode(void); int httpstatus(void)const; bool has_httperror(void)const; }; template class netreturn : public netreturn_base { public: using value_type = Retval; private: Retval m_ret = {}; public: constexpr netreturn(void) = default; template netreturn(Str1&& error, Str2&& errorcode, int httpcode, Val&& val = Val()): netreturn_base(std::forward(error), std::forward(errorcode), httpcode), m_ret(std::forward(val)){} netreturn(netreturn_base&& n): netreturn_base(std::move(n)){} netreturn(const netreturn_base& n): netreturn_base(n){} Retval& value(void)&{ return m_ret; } const Retval& value(void)const&{ return m_ret; } Retval&& value(void)&&{ return std::move(m_ret); } }; template<> class netreturn : public netreturn_base { public: using value_type = void; public: template netreturn(Str1&& error, Str2&& errorcode, int httpcode): netreturn_base(std::forward(error), std::forward(errorcode), httpcode){} netreturn(netreturn_base&& n): netreturn_base(std::move(n)){} netreturn(const netreturn_base& n): netreturn_base(n){} }; } #endif