1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-26 12:16:04 +00:00
Atmosphere/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_out.hpp
2018-10-31 05:04:00 +09:00

75 lines
No EOL
1.8 KiB
C++

/*
* Copyright (c) 2018 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
#include <type_traits>
/* Declare false allowed struct. */
template <typename>
struct AllowedOut : std::false_type {};
struct OutDataTag{};
struct OutHandleTag{};
struct OutSessionTag{};
/* Define out struct, so that we can get errors on enable_if */
template <typename T, typename Allowed = void>
class Out {
static_assert(std::is_pod<T>::value && !std::is_pod<T>::value, "Invalid IPC Out Type!");
};
template <typename T>
class Out<T, typename std::enable_if<std::is_trivial<T>::value || AllowedOut<T>::value>::type> : public OutDataTag {
private:
T *obj;
public:
Out(T *o) : obj(o) { }
void SetValue(const T& t) {
*obj = t;
}
const T& GetValue() {
return *obj;
}
T *GetPointer() {
return obj;
}
/* Convenience operators. */
T& operator*() {
return *obj;
}
T* operator->() {
return obj;
}
};
template <typename T>
class Out<T*> {
static_assert(std::is_pod<T>::value && !std::is_pod<T>::value, "Invalid IPC Out Type (Raw Pointer)!");
};
template <typename T>
struct OutHelper;
template <typename T>
struct OutHelper<Out<T>> {
using type = T;
};