diff --git a/src/libsync/abstractnetworkjob.h b/src/libsync/abstractnetworkjob.h index 8a98af665..c169e5451 100644 --- a/src/libsync/abstractnetworkjob.h +++ b/src/libsync/abstractnetworkjob.h @@ -32,63 +32,6 @@ namespace OCC { class AbstractSslErrorHandler; - -/** - * A Result of type T, or an Error that contains a code and a string - **/ -template -class Result -{ - struct Error - { - QString string; - int code; - }; - union { - T _result; - Error _error; - }; - bool _isError; - -public: - Result(T value) - : _result(std::move(value)) - , _isError(false){}; - Result(int code, QString str) - : _error({ std::move(str), code }) - , _isError(true) - { - } - ~Result() - { - if (_isError) - _error.~Error(); - else - _result.~T(); - } - explicit operator bool() const { return !_isError; } - const T &operator*() const & - { - ASSERT(!_isError); - return _result; - } - T operator*() && - { - ASSERT(!_isError); - return std::move(_result); - } - QString errorMessage() const - { - ASSERT(_isError); - return _error.string; - } - int errorCode() const - { - return _isError ? _error.code : 0; - } -}; - - /** * @brief The AbstractNetworkJob class * @ingroup libsync diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h index 743b87ac5..634e792a7 100644 --- a/src/libsync/networkjobs.h +++ b/src/libsync/networkjobs.h @@ -18,6 +18,8 @@ #include "abstractnetworkjob.h" +#include "result.h" + #include #include #include diff --git a/src/libsync/result.h b/src/libsync/result.h new file mode 100644 index 000000000..58f70c4e7 --- /dev/null +++ b/src/libsync/result.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) by Olivier Goffart + * + * 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 2 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. + */ + +#pragma once + +namespace OCC { + +/** + * A Result of type T, or an Error that contains a code and a string + * + * The code is an HTTP error code. + **/ +template +class Result +{ + struct Error + { + QString string; + int code; + }; + union { + T _result; + Error _error; + }; + bool _isError; + +public: + Result(T value) + : _result(std::move(value)) + , _isError(false){}; + Result(int code, QString str) + : _error({ std::move(str), code }) + , _isError(true) + { + } + ~Result() + { + if (_isError) + _error.~Error(); + else + _result.~T(); + } + explicit operator bool() const { return !_isError; } + const T &operator*() const & + { + ASSERT(!_isError); + return _result; + } + T operator*() && + { + ASSERT(!_isError); + return std::move(_result); + } + QString errorMessage() const + { + ASSERT(_isError); + return _error.string; + } + int errorCode() const + { + return _isError ? _error.code : 0; + } +}; + +} // namespace OCC