Backed out 3 changesets (bug 1889130) for causing xpcshell failures in test_dooh...
[gecko.git] / gfx / ots / src / graphite.h
blob452cb26a87b1e89e080d21b7757808244649690b
1 // Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef OTS_GRAPHITE_H_
6 #define OTS_GRAPHITE_H_
8 #include <vector>
9 #include <type_traits>
11 namespace ots {
13 template<typename ParentType>
14 class TablePart {
15 public:
16 TablePart(ParentType* parent) : parent(parent) { }
17 virtual ~TablePart() { }
18 virtual bool ParsePart(Buffer& table) = 0;
19 virtual bool SerializePart(OTSStream* out) const = 0;
20 protected:
21 ParentType* parent;
24 template<typename T>
25 bool SerializeParts(const std::vector<T>& vec, OTSStream* out) {
26 for (const T& part : vec) {
27 if (!part.SerializePart(out)) {
28 return false;
31 return true;
34 template<typename T>
35 bool SerializeParts(const std::vector<std::vector<T>>& vec, OTSStream* out) {
36 for (const std::vector<T>& part : vec) {
37 if (!SerializeParts(part, out)) {
38 return false;
41 return true;
44 inline bool SerializeParts(const std::vector<uint8_t>& vec, OTSStream* out) {
45 for (uint8_t part : vec) {
46 if (!out->WriteU8(part)) {
47 return false;
50 return true;
53 inline bool SerializeParts(const std::vector<uint16_t>& vec, OTSStream* out) {
54 for (uint16_t part : vec) {
55 if (!out->WriteU16(part)) {
56 return false;
59 return true;
62 inline bool SerializeParts(const std::vector<int16_t>& vec, OTSStream* out) {
63 for (int16_t part : vec) {
64 if (!out->WriteS16(part)) {
65 return false;
68 return true;
71 inline bool SerializeParts(const std::vector<uint32_t>& vec, OTSStream* out) {
72 for (uint32_t part : vec) {
73 if (!out->WriteU32(part)) {
74 return false;
77 return true;
80 inline bool SerializeParts(const std::vector<int32_t>& vec, OTSStream* out) {
81 for (int32_t part : vec) {
82 if (!out->WriteS32(part)) {
83 return false;
86 return true;
89 template<typename T>
90 size_t datasize(std::vector<T> vec) {
91 return sizeof(T) * vec.size();
94 } // namespace ots
96 #endif // OTS_GRAPHITE_H_