From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- gfx/ots/src/graphite.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 gfx/ots/src/graphite.h (limited to 'gfx/ots/src/graphite.h') diff --git a/gfx/ots/src/graphite.h b/gfx/ots/src/graphite.h new file mode 100644 index 0000000000..452cb26a87 --- /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 +#include + +namespace ots { + +template +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 +bool SerializeParts(const std::vector& vec, OTSStream* out) { + for (const T& part : vec) { + if (!part.SerializePart(out)) { + return false; + } + } + return true; +} + +template +bool SerializeParts(const std::vector>& vec, OTSStream* out) { + for (const std::vector& part : vec) { + if (!SerializeParts(part, out)) { + return false; + } + } + return true; +} + +inline bool SerializeParts(const std::vector& vec, OTSStream* out) { + for (uint8_t part : vec) { + if (!out->WriteU8(part)) { + return false; + } + } + return true; +} + +inline bool SerializeParts(const std::vector& vec, OTSStream* out) { + for (uint16_t part : vec) { + if (!out->WriteU16(part)) { + return false; + } + } + return true; +} + +inline bool SerializeParts(const std::vector& vec, OTSStream* out) { + for (int16_t part : vec) { + if (!out->WriteS16(part)) { + return false; + } + } + return true; +} + +inline bool SerializeParts(const std::vector& vec, OTSStream* out) { + for (uint32_t part : vec) { + if (!out->WriteU32(part)) { + return false; + } + } + return true; +} + +inline bool SerializeParts(const std::vector& vec, OTSStream* out) { + for (int32_t part : vec) { + if (!out->WriteS32(part)) { + return false; + } + } + return true; +} + +template +size_t datasize(std::vector vec) { + return sizeof(T) * vec.size(); +} + +} // namespace ots + +#endif // OTS_GRAPHITE_H_ -- cgit v1.2.3