summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2018-08-08 16:19:41 -0500
committerYifan Hong2018-08-08 16:38:49 -0500
commitba588bc3fbcc663bac967da7ae38c378d178e518 (patch)
treebe0dde1aa59edf0e3061de1636144250d0f9e5fb /parse_xml.cpp
parent072f12dd33706958412694714cfc17da85ea86b0 (diff)
downloadplatform-system-libvintf-ba588bc3fbcc663bac967da7ae38c378d178e518.tar.gz
platform-system-libvintf-ba588bc3fbcc663bac967da7ae38c378d178e518.tar.xz
platform-system-libvintf-ba588bc3fbcc663bac967da7ae38c378d178e518.zip
SerializeFlags is a namespace.
The SerializeFlags becomes a namespace that contains the original class definition under type SerializeFlags::Type and static constants. Consequently, all SeralizeFlags methods can now be constexpr. Also added static tests. Test: libvintf_test Test: vintf_object_test Bug: 110711640 Change-Id: I786a1f77e19defc2ab2d025de3ed7cfe48f4fbce
Diffstat (limited to 'parse_xml.cpp')
-rw-r--r--parse_xml.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/parse_xml.cpp b/parse_xml.cpp
index ff6ecc2..0cc514d 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -141,7 +141,7 @@ struct XmlNodeConverter : public XmlConverter<Object> {
141 141
142 // sub-types should implement these. 142 // sub-types should implement these.
143 virtual void mutateNode(const Object &o, NodeType *n, DocType *d) const = 0; 143 virtual void mutateNode(const Object &o, NodeType *n, DocType *d) const = 0;
144 virtual void mutateNode(const Object& o, NodeType* n, DocType* d, SerializeFlags) const { 144 virtual void mutateNode(const Object& o, NodeType* n, DocType* d, SerializeFlags::Type) const {
145 mutateNode(o, n, d); 145 mutateNode(o, n, d);
146 } 146 }
147 virtual bool buildObject(Object* o, NodeType* n, std::string* error) const = 0; 147 virtual bool buildObject(Object* o, NodeType* n, std::string* error) const = 0;
@@ -150,12 +150,12 @@ struct XmlNodeConverter : public XmlConverter<Object> {
150 // convenience methods for user 150 // convenience methods for user
151 inline const std::string& lastError() const override { return mLastError; } 151 inline const std::string& lastError() const override { return mLastError; }
152 inline NodeType* serialize(const Object& o, DocType* d, 152 inline NodeType* serialize(const Object& o, DocType* d,
153 SerializeFlags flags = SerializeFlags::EVERYTHING) const { 153 SerializeFlags::Type flags = SerializeFlags::EVERYTHING) const {
154 NodeType *root = createNode(this->elementName(), d); 154 NodeType *root = createNode(this->elementName(), d);
155 this->mutateNode(o, root, d, flags); 155 this->mutateNode(o, root, d, flags);
156 return root; 156 return root;
157 } 157 }
158 inline std::string serialize(const Object& o, SerializeFlags flags) const override { 158 inline std::string serialize(const Object& o, SerializeFlags::Type flags) const override {
159 DocType *doc = createDocument(); 159 DocType *doc = createDocument();
160 appendChild(doc, serialize(o, doc, flags)); 160 appendChild(doc, serialize(o, doc, flags));
161 std::string s = printDocument(doc); 161 std::string s = printDocument(doc);
@@ -192,7 +192,7 @@ struct XmlNodeConverter : public XmlConverter<Object> {
192 inline NodeType *operator()(const Object &o, DocType *d) const { 192 inline NodeType *operator()(const Object &o, DocType *d) const {
193 return serialize(o, d); 193 return serialize(o, d);
194 } 194 }
195 inline std::string operator()(const Object& o, SerializeFlags flags) const override { 195 inline std::string operator()(const Object& o, SerializeFlags::Type flags) const override {
196 return serialize(o, flags); 196 return serialize(o, flags);
197 } 197 }
198 inline bool operator()(Object* o, NodeType* node) { return deserialize(o, node); } 198 inline bool operator()(Object* o, NodeType* node) { return deserialize(o, node); }
@@ -234,7 +234,7 @@ struct XmlNodeConverter : public XmlConverter<Object> {
234 template <typename T, typename Array> 234 template <typename T, typename Array>
235 inline void appendChildren(NodeType* parent, const XmlNodeConverter<T>& conv, 235 inline void appendChildren(NodeType* parent, const XmlNodeConverter<T>& conv,
236 const Array& array, DocType* d, 236 const Array& array, DocType* d,
237 SerializeFlags flags = SerializeFlags::EVERYTHING) const { 237 SerializeFlags::Type flags = SerializeFlags::EVERYTHING) const {
238 for (const T &t : array) { 238 for (const T &t : array) {
239 appendChild(parent, conv.serialize(t, d, flags)); 239 appendChild(parent, conv.serialize(t, d, flags));
240 } 240 }
@@ -605,7 +605,7 @@ struct MatrixKernelConverter : public XmlNodeConverter<MatrixKernel> {
605 mutateNode(kernel, root, d, SerializeFlags::EVERYTHING); 605 mutateNode(kernel, root, d, SerializeFlags::EVERYTHING);
606 } 606 }
607 void mutateNode(const MatrixKernel& kernel, NodeType* root, DocType* d, 607 void mutateNode(const MatrixKernel& kernel, NodeType* root, DocType* d,
608 SerializeFlags flags) const override { 608 SerializeFlags::Type flags) const override {
609 KernelVersion kv = kernel.mMinLts; 609 KernelVersion kv = kernel.mMinLts;
610 if (!flags.isKernelMinorRevisionEnabled()) { 610 if (!flags.isKernelMinorRevisionEnabled()) {
611 kv.minorRev = 0u; 611 kv.minorRev = 0u;
@@ -640,7 +640,7 @@ struct ManifestHalConverter : public XmlNodeConverter<ManifestHal> {
640 mutateNode(m, root, d, SerializeFlags::EVERYTHING); 640 mutateNode(m, root, d, SerializeFlags::EVERYTHING);
641 } 641 }
642 void mutateNode(const ManifestHal& hal, NodeType* root, DocType* d, 642 void mutateNode(const ManifestHal& hal, NodeType* root, DocType* d,
643 SerializeFlags flags) const override { 643 SerializeFlags::Type flags) const override {
644 appendAttr(root, "format", hal.format); 644 appendAttr(root, "format", hal.format);
645 appendTextElement(root, "name", hal.name, d); 645 appendTextElement(root, "name", hal.name, d);
646 appendChild(root, transportArchConverter(hal.transportArch, d)); 646 appendChild(root, transportArchConverter(hal.transportArch, d));
@@ -864,7 +864,7 @@ struct HalManifestConverter : public XmlNodeConverter<HalManifest> {
864 mutateNode(m, root, d, SerializeFlags::EVERYTHING); 864 mutateNode(m, root, d, SerializeFlags::EVERYTHING);
865 } 865 }
866 void mutateNode(const HalManifest& m, NodeType* root, DocType* d, 866 void mutateNode(const HalManifest& m, NodeType* root, DocType* d,
867 SerializeFlags flags) const override { 867 SerializeFlags::Type flags) const override {
868 if (flags.isMetaVersionEnabled()) { 868 if (flags.isMetaVersionEnabled()) {
869 appendAttr(root, "version", m.getMetaVersion()); 869 appendAttr(root, "version", m.getMetaVersion());
870 } 870 }
@@ -1031,7 +1031,7 @@ struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatri
1031 mutateNode(m, root, d, SerializeFlags::EVERYTHING); 1031 mutateNode(m, root, d, SerializeFlags::EVERYTHING);
1032 } 1032 }
1033 void mutateNode(const CompatibilityMatrix& m, NodeType* root, DocType* d, 1033 void mutateNode(const CompatibilityMatrix& m, NodeType* root, DocType* d,
1034 SerializeFlags flags) const override { 1034 SerializeFlags::Type flags) const override {
1035 if (flags.isMetaVersionEnabled()) { 1035 if (flags.isMetaVersionEnabled()) {
1036 appendAttr(root, "version", m.getMinimumMetaVersion()); 1036 appendAttr(root, "version", m.getMinimumMetaVersion());
1037 } 1037 }