aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/IO/Helper.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-30 21:38:53 -0700
committerrtk0c <[email protected]>2022-06-30 21:38:53 -0700
commit7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch)
treee95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Utils/IO/Helper.hpp
parent2cf952088d375ac8b2f45b144462af0953436cff (diff)
Restructure project
Diffstat (limited to 'app/source/Cplt/Utils/IO/Helper.hpp')
-rw-r--r--app/source/Cplt/Utils/IO/Helper.hpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/source/Cplt/Utils/IO/Helper.hpp b/app/source/Cplt/Utils/IO/Helper.hpp
new file mode 100644
index 0000000..7a84103
--- /dev/null
+++ b/app/source/Cplt/Utils/IO/Helper.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <Cplt/Utils/IO/DataStream.hpp>
+
+namespace DataStreamAdapters {
+
+/// Helper to invoke either Read() or ReadObject().
+/// This is intended for writing IO adapters, users that's writing IO logic shouldn't using this - it increases compile time while reducing readability.
+template <class TAdapter, class T>
+void ReadHelper(InputDataStream& stream, T& t)
+{
+ if constexpr (!std::is_same_v<TAdapter, void>) {
+ stream.ReadObjectAdapted<TAdapter>(t);
+ } else if constexpr (requires(T tt, InputDataStream ss) { ss.Read(tt); }) {
+ stream.Read(t);
+ } else if constexpr (requires(T tt, InputDataStream ss) { ss.ReadEnum(tt); }) {
+ stream.ReadEnum(t);
+ } else if constexpr (requires(T tt, InputDataStream ss) { ss.ReadObject(tt); }) {
+ stream.ReadObject(t);
+ } else {
+ static_assert(false && sizeof(T), "This type is neither a 'value' nor an 'object'.");
+ }
+}
+
+/// Helper to invoke either Write() or WriteObject().
+/// This is intended for writing IO adapters, users that's writing IO logic shouldn't using this - it increases compile time while reducing readability.
+template <class TAdapter, class T>
+void WriteHelper(OutputDataStream& stream, T& t)
+{
+ if constexpr (!std::is_same_v<TAdapter, void>) {
+ stream.WriteObjectAdapted<TAdapter>(t);
+ } else if constexpr (requires(T tt, OutputDataStream ss) { ss.Write(tt); }) {
+ stream.Write(t);
+ } else if constexpr (requires(T tt, OutputDataStream ss) { ss.WriteEnum(tt); }) {
+ stream.WriteEnum(t);
+ } else if constexpr (requires(T tt, OutputDataStream ss) { ss.WriteObject(tt); }) {
+ stream.WriteObject(t);
+ } else {
+ static_assert(false && sizeof(T), "This type is neither a 'value' nor an 'object'.");
+ }
+}
+
+} // namespace DataStreamAdapters