summaryrefslogtreecommitdiffstats
path: root/gfx/ots/src/graphite.h
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-12-06 23:39:47 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-12-06 23:39:47 +0100
commit642032029f65e9dc0d38fbb6d35ef656c73a292c (patch)
tree78a22bd12d679ab532db490d631ee69fa085aec1 /gfx/ots/src/graphite.h
parent50ef259a2df60d020ccb02d76dc5aa4835ee319e (diff)
parent2529b2edece0a0ed86553d1e73eef13c3848bf64 (diff)
downloadUXP-642032029f65e9dc0d38fbb6d35ef656c73a292c.tar
UXP-642032029f65e9dc0d38fbb6d35ef656c73a292c.tar.gz
UXP-642032029f65e9dc0d38fbb6d35ef656c73a292c.tar.lz
UXP-642032029f65e9dc0d38fbb6d35ef656c73a292c.tar.xz
UXP-642032029f65e9dc0d38fbb6d35ef656c73a292c.zip
Merge branch 'master' into release
Diffstat (limited to 'gfx/ots/src/graphite.h')
-rw-r--r--gfx/ots/src/graphite.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/gfx/ots/src/graphite.h b/gfx/ots/src/graphite.h
new file mode 100644
index 000000000..452cb26a8
--- /dev/null
+++ b/gfx/ots/src/graphite.h
@@ -0,0 +1,96 @@
+// Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef OTS_GRAPHITE_H_
+#define OTS_GRAPHITE_H_
+
+#include <vector>
+#include <type_traits>
+
+namespace ots {
+
+template<typename ParentType>
+class TablePart {
+ public:
+ TablePart(ParentType* parent) : parent(parent) { }
+ virtual ~TablePart() { }
+ virtual bool ParsePart(Buffer& table) = 0;
+ virtual bool SerializePart(OTSStream* out) const = 0;
+ protected:
+ ParentType* parent;
+};
+
+template<typename T>
+bool SerializeParts(const std::vector<T>& vec, OTSStream* out) {
+ for (const T& part : vec) {
+ if (!part.SerializePart(out)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+template<typename T>
+bool SerializeParts(const std::vector<std::vector<T>>& vec, OTSStream* out) {
+ for (const std::vector<T>& part : vec) {
+ if (!SerializeParts(part, out)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline bool SerializeParts(const std::vector<uint8_t>& vec, OTSStream* out) {
+ for (uint8_t part : vec) {
+ if (!out->WriteU8(part)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline bool SerializeParts(const std::vector<uint16_t>& vec, OTSStream* out) {
+ for (uint16_t part : vec) {
+ if (!out->WriteU16(part)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline bool SerializeParts(const std::vector<int16_t>& vec, OTSStream* out) {
+ for (int16_t part : vec) {
+ if (!out->WriteS16(part)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline bool SerializeParts(const std::vector<uint32_t>& vec, OTSStream* out) {
+ for (uint32_t part : vec) {
+ if (!out->WriteU32(part)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline bool SerializeParts(const std::vector<int32_t>& vec, OTSStream* out) {
+ for (int32_t part : vec) {
+ if (!out->WriteS32(part)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+template<typename T>
+size_t datasize(std::vector<T> vec) {
+ return sizeof(T) * vec.size();
+}
+
+} // namespace ots
+
+#endif // OTS_GRAPHITE_H_