2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-12-09 11:57:37 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-01-17 15:55:32 +00:00
|
|
|
#include <stratosphere/sf/sf_common.hpp>
|
|
|
|
#include <stratosphere/sf/cmif/sf_cmif_pointer_and_size.hpp>
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
namespace ams::sf {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
struct OutBaseTag{};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename>
|
|
|
|
struct IsOutForceEnabled : public std::false_type{};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct IsOutForceEnabled<::ams::Result> : public std::true_type{};
|
|
|
|
|
|
|
|
template<typename T>
|
2020-05-11 22:02:10 +00:00
|
|
|
concept OutEnabled = (std::is_trivial<T>::value || IsOutForceEnabled<T>::value) && !std::is_pointer<T>::value;
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2021-01-17 15:55:32 +00:00
|
|
|
template<typename T>
|
2019-12-09 11:57:37 +00:00
|
|
|
class Out : public impl::OutBaseTag {
|
2021-01-17 15:55:32 +00:00
|
|
|
static_assert(OutEnabled<T>);
|
2019-12-09 11:57:37 +00:00
|
|
|
public:
|
|
|
|
static constexpr size_t TypeSize = sizeof(T);
|
|
|
|
private:
|
2021-10-10 07:14:06 +00:00
|
|
|
T *m_ptr;
|
2019-12-09 11:57:37 +00:00
|
|
|
public:
|
2021-10-10 07:14:06 +00:00
|
|
|
constexpr Out(uintptr_t p) : m_ptr(reinterpret_cast<T *>(p)) { /* ... */ }
|
|
|
|
constexpr Out(T *p) : m_ptr(p) { /* ... */ }
|
|
|
|
constexpr Out(const cmif::PointerAndSize &pas) : m_ptr(reinterpret_cast<T *>(pas.GetAddress())) { /* TODO: Is AMS_ABORT_UNLESS(pas.GetSize() >= sizeof(T)); necessary? */ }
|
2019-12-09 11:57:37 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
template<typename U> requires (std::integral<T> && std::is_enum<U>::value && std::same_as<typename std::underlying_type<U>::type, T>)
|
|
|
|
constexpr Out(U *p) : m_ptr(reinterpret_cast<T *>(p)) { static_assert(sizeof(U) == sizeof(T)); static_assert(alignof(U) == alignof(T)); }
|
|
|
|
|
2019-12-09 11:57:37 +00:00
|
|
|
void SetValue(const T& value) const {
|
2021-10-10 07:14:06 +00:00
|
|
|
*m_ptr = value;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const T &GetValue() const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return *m_ptr;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
T *GetPointer() const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_ptr;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convenience operators. */
|
|
|
|
T &operator*() const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return *m_ptr;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
T *operator->() const {
|
2021-10-10 07:14:06 +00:00
|
|
|
return m_ptr;
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Out<T *> {
|
|
|
|
static_assert(!std::is_same<T, T>::value, "Invalid sf::Out<T> (Raw Pointer)");
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|