summaryrefslogtreecommitdiff
path: root/source/slang/slang-serialize.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-08-19 15:03:56 -0700
committerGitHub <noreply@github.com>2024-08-19 15:03:56 -0700
commit453683bf44f2112719802eaac2b332d49eebd640 (patch)
treed399db4c9cba90c11980186d3df1ffcc4d423b5a /source/slang/slang-serialize.h
parentecf85df6eee3da76ef54b14e4ab083f22da89e46 (diff)
Tuple swizzling, concat, comparison and `countof`. (#4856)
* Tuple swizzling and element access. * Update proposal status. * Cleanup. * Fix merrge error. * Address review.
Diffstat (limited to 'source/slang/slang-serialize.h')
-rw-r--r--source/slang/slang-serialize.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/slang/slang-serialize.h b/source/slang/slang-serialize.h
index a91ff21e9..e8786d561 100644
--- a/source/slang/slang-serialize.h
+++ b/source/slang/slang-serialize.h
@@ -241,6 +241,9 @@ public:
template <typename T>
void getArray(SerialIndex index, List<T>& out);
+ template <typename T, int n>
+ void getArray(SerialIndex index, ShortList<T, n>& out);
+
const void* getArray(SerialIndex index, Index& outCount);
SerialPointer getPointer(SerialIndex index);
@@ -334,6 +337,38 @@ void SerialReader::getArray(SerialIndex index, List<T>& out)
}
}
+template <typename T, int n>
+void SerialReader::getArray(SerialIndex index, ShortList<T, n>& out)
+{
+ typedef SerialTypeInfo<T> ElementTypeInfo;
+ typedef typename ElementTypeInfo::SerialType ElementSerialType;
+
+ Index count;
+ auto serialElements = (const ElementSerialType*)getArray(index, count);
+
+ if (count == 0)
+ {
+ out.clear();
+ return;
+ }
+
+ if (std::is_same<T, ElementSerialType>::value)
+ {
+ // If they are the same we can just write out
+ out.clear();
+ out.addRange((const T*)serialElements, count);
+ }
+ else
+ {
+ // Else we need to convert
+ out.setCount(count);
+ for (Index i = 0; i < count; ++i)
+ {
+ ElementTypeInfo::toNative(this, (const void*)&serialElements[i], (void*)&out[i]);
+ }
+ }
+}
+
/* This is a class used tby toSerial implementations to turn native type into the serial type */
class SerialWriter : public RefObject
{