/* * ConfigPlist.h * * Created on: Oct 9, 2020 * Author: jief */ #ifndef _CONFIGPLISTCLASS_DEVICES_PROPERTIES_H_ #define _CONFIGPLISTCLASS_DEVICES_PROPERTIES_H_ //Properties could be a string containing an EFIString to inject, or a dict of key-dict pair. The dict in the key-dict pair is a key-value pair class PropertiesUnion: public XmlUnion { public: class Properties4DeviceClass; class Property : public XmlAddKey { using super = XmlAddKey; const Properties4DeviceClass& parent; private: public: // XmlPropertyValue xmlValue = XmlPropertyValue(); public: // XmlCompositeField m_fields[1] = { xmlValue }; // virtual void getFields(XmlCompositeField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); }; Property() : parent(*new Properties4DeviceClass) { panic("BUG. define getNewInstance()"); } Property(const Properties4DeviceClass& _parent) : parent(_parent) {} uint8_t dgetBValue() const { if ( !parent.dgetEnabled() ) return false; return xmlKey().isDefined() ? xmlKey().isEnabled() : XBool(false); } const keyType::ValueType& dgetKey() const { return xmlKey().isDefined() ? xmlKey().value() : xmlKey().nullValue; }; XBuffer dgetValue() const { return isDefined() ? value() : XBuffer::NullXBuffer; }; TAG_TYPE dgetValueType() const { return isDefined() ? valueType() : kTagTypeNone; }; }; // class PropertiesClass; // // Dict for Devices/Properties/each key. // // A repeating key + dict // // Key could be like "AAPL,GfxYTile" or "AAPL,ig-platform-id" class Properties4DeviceClass : public XmlAddKey> { using super = XmlAddKey>; public: virtual Property* getNewInstance() override { return new Property(*this); } public: const keyType::ValueType& dgetLabel() const { return super::xmlKey().isDefined() ? xmlKey().value() : xmlKey().nullValue; }; const keyType::ValueType& dgetDevicePathAsString() const { return xmlKey().isDefined() ? xmlKey().value() : xmlKey().nullValue; }; XBool dgetEnabled() const { return xmlKey().isDefined() ? xmlKey().isEnabled() : XBool(false); }; }; protected: XmlString8AllowEmpty PropertiesAsString = XmlString8AllowEmpty(); public: XmlRepeatingDict PropertiesAsDict = XmlRepeatingDict(); XmlUnionField m_fields[2] = { PropertiesAsString, PropertiesAsDict }; virtual void getFields(XmlUnionField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); }; public: const decltype(PropertiesAsString)::ValueType& dgetpropertiesAsString() const { return PropertiesAsString.isDefined() ? PropertiesAsString.value() : PropertiesAsString.nullValue; }; }; #endif /* _CONFIGPLISTCLASS_DEVICES_PROPERTIES_H_ */