summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar bunnei2018-07-19 16:18:38 -0700
committerGravatar GitHub2018-07-19 16:18:38 -0700
commitd3cfaf95c883512691df01e90d8ab7e8873c2c3d (patch)
tree0a9ca7761857f6855ed30f8ef2f99674cd7d119c /src/core/hle/kernel
parentMerge pull request #725 from lioncash/bytes (diff)
parenthle_ipc: Introduce generic WriteBuffer overload for multiple container types (diff)
downloadyuzu-d3cfaf95c883512691df01e90d8ab7e8873c2c3d.tar.gz
yuzu-d3cfaf95c883512691df01e90d8ab7e8873c2c3d.tar.xz
yuzu-d3cfaf95c883512691df01e90d8ab7e8873c2c3d.zip
Merge pull request #726 from lioncash/overload
hle_ipc: Introduce generic WriteBuffer overload for multiple container types
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp4
-rw-r--r--src/core/hle/kernel/hle_ipc.h23
2 files changed, 21 insertions, 6 deletions
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 911e6fbc1..8f40bdd5a 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -301,10 +301,6 @@ size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size, int buffe
301 return size; 301 return size;
302} 302}
303 303
304size_t HLERequestContext::WriteBuffer(const std::vector<u8>& buffer, int buffer_index) const {
305 return WriteBuffer(buffer.data(), buffer.size(), buffer_index);
306}
307
308size_t HLERequestContext::GetReadBufferSize(int buffer_index) const { 304size_t HLERequestContext::GetReadBufferSize(int buffer_index) const {
309 const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; 305 const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()};
310 return is_buffer_a ? BufferDescriptorA()[buffer_index].Size() 306 return is_buffer_a ? BufferDescriptorA()[buffer_index].Size()
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index 88f93ad22..01b805df8 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -5,8 +5,10 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <iterator>
8#include <memory> 9#include <memory>
9#include <string> 10#include <string>
11#include <type_traits>
10#include <vector> 12#include <vector>
11#include <boost/container/small_vector.hpp> 13#include <boost/container/small_vector.hpp>
12#include "common/common_types.h" 14#include "common/common_types.h"
@@ -171,8 +173,25 @@ public:
171 /// Helper function to write a buffer using the appropriate buffer descriptor 173 /// Helper function to write a buffer using the appropriate buffer descriptor
172 size_t WriteBuffer(const void* buffer, size_t size, int buffer_index = 0) const; 174 size_t WriteBuffer(const void* buffer, size_t size, int buffer_index = 0) const;
173 175
174 /// Helper function to write a buffer using the appropriate buffer descriptor 176 /* Helper function to write a buffer using the appropriate buffer descriptor
175 size_t WriteBuffer(const std::vector<u8>& buffer, int buffer_index = 0) const; 177 *
178 * @tparam ContiguousContainer an arbitrary container that satisfies the
179 * ContiguousContainer concept in the C++ standard library.
180 *
181 * @param container The container to write the data of into a buffer.
182 * @param buffer_index The buffer in particular to write to.
183 */
184 template <typename ContiguousContainer,
185 typename = std::enable_if_t<!std::is_pointer_v<ContiguousContainer>>>
186 size_t WriteBuffer(const ContiguousContainer& container, int buffer_index = 0) const {
187 using ContiguousType = typename ContiguousContainer::value_type;
188
189 static_assert(std::is_trivially_copyable_v<ContiguousType>,
190 "Container to WriteBuffer must contain trivially copyable objects");
191
192 return WriteBuffer(std::data(container), std::size(container) * sizeof(ContiguousType),
193 buffer_index);
194 }
176 195
177 /// Helper function to get the size of the input buffer 196 /// Helper function to get the size of the input buffer
178 size_t GetReadBufferSize(int buffer_index = 0) const; 197 size_t GetReadBufferSize(int buffer_index = 0) const;