mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-10 09:40:53 +01:00
Simplify validate methods as suggested by Slice.
This commit is contained in:
parent
23e4b83d20
commit
e1fe2bc9bb
@ -101,8 +101,7 @@ public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( !isDefined() ) return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( LString8(ACPI.DSDT.Fixes.ACPI_DSDT_Fixe_Array[29].getNewName()) != "FixHeaders_20000000"_XS8 ) {
|
||||
log_technical_bug("ACPI_DSDT_Fixe_Array[29].getNewName() != \"FixHeaders_20000000\"");
|
||||
}
|
||||
@ -119,7 +118,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
|
||||
const decltype(DisableDrivers)::ValueType& dgetDisabledDriverArray() const { return DisableDrivers.isDefined() ? DisableDrivers.value() : DisableDrivers.nullValue; };
|
||||
|
@ -77,12 +77,9 @@ public:
|
||||
{
|
||||
using super = XmlString8AllowEmpty;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( !isDefined() ) return true;
|
||||
if ( xstring8.length() == 4 ) return true;
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Expect a string of 4 chars for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
return true; // TODO : we should return false, but currently Clover accept string that are not 4 chars long.
|
||||
// return false; // parsing can continue.
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( xstring8.length() != 4 ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("Expect a string of 4 chars for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
|
||||
} Signature = Signature_Class();
|
||||
|
@ -107,8 +107,7 @@ public:
|
||||
virtual XmlAbstractType& parseValueFromXmlLite(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, XBool generateErrors, const XmlParserPosition &keyPos, const char *keyValue, size_t keyValueLength, XBool* keyFound) override;
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( !isDefined() ) return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
// if ( LString8(ACPI_DSDT_Fixe_Array[29].getNewName()) != "FixHeaders_20000000"_XS8 ) {
|
||||
// log_technical_bug("ACPI_DSDT_Fixe_Array[29].getNewName() != \"FixHeaders_20000000\"");
|
||||
// return true; // Bug in ACPI_DSDT_Fixe_Array. We don't want to reset all the values, so return true.
|
||||
@ -117,7 +116,7 @@ public:
|
||||
// xmlLiteParser->addWarning(generateErrors, S8Printf("FixHeaders is ACPI/DSDT in deprecated. Move it to ACPI."));
|
||||
// return true; // return true because we handle this value anyway.
|
||||
// }
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
|
||||
const ACPI_DSDT_Fix& getFixHeaders() const {
|
||||
|
@ -15,11 +15,11 @@
|
||||
|
||||
|
||||
XBool ConfigPlistClass::GUI_Class::GUI_Custom_Class::GUI_Custom_Entry_Class::validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
for ( size_t idx=0 ; idx < SubEntries.size() ; ++idx ) SubEntries.ElementAt(idx).Parent = this;
|
||||
if ( Arguments.isDefined() && AddArguments.isDefined() ) {
|
||||
xmlLiteParser->addError(generateErrors, S8Printf("Arguments is ignored because AddArguments is defined. Line %d.", keyPos.getLine()));
|
||||
Arguments.reset();
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
|
@ -433,8 +433,8 @@ public:
|
||||
public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
return b;
|
||||
}
|
||||
|
||||
XBool dgetDisabled() const { return Disabled.isDefined() ? Disabled.value() : XBool(false); };
|
||||
|
@ -56,7 +56,6 @@ public:
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
XBool b = true;
|
||||
// TODO after switch to new parser : name.isEmpty()
|
||||
if ( !Find.isDefined() || Find.value().size() == 0 ) return xmlLiteParser->addWarning(generateErrors, S8Printf("Find has to be defined in dict '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
if ( !Replace.isDefined() || Replace.value().size() == 0 ) return xmlLiteParser->addWarning(generateErrors, S8Printf("One of Find or Replace has to be defined in dict '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
@ -64,7 +63,7 @@ public:
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Replace is longer (%zu) than Find (%zu) and will be truncated in dict '%s:%d'.", Replace.value().size(), Find.value().size(), xmlPath.c_str(), keyPos.getLine()));
|
||||
Replace.setSize(Find.value().size(), 0); // 0 is ignored because we know that this call will truncate
|
||||
}
|
||||
return b;
|
||||
return true;
|
||||
}
|
||||
|
||||
XBool dgetDisabled() const { return Disabled.isDefined() ? Disabled.value() : XBool(false); };
|
||||
@ -153,8 +152,7 @@ public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
XBool b = true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !Name.isDefined() ) {
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Kernel patch is ignored because 'Name' is not defined in dict '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
@ -246,11 +244,11 @@ public:
|
||||
{
|
||||
using super = XmlStringWArray;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( value().contains("\\") ) {
|
||||
return xmlLiteParser->addWarning(generateErrors, S8Printf("String cannot contains '\\' for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("String cannot contains '\\' for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -321,7 +319,7 @@ public:
|
||||
ATIConnectorsData.reset();
|
||||
ATIConnectorsPatch.reset();
|
||||
}
|
||||
return true;
|
||||
return true; // Return true to not reset the dict.
|
||||
}
|
||||
|
||||
XBool dgetKPDebug() const { return Debug.isDefined() ? Debug.value() : XBool(false); };
|
||||
|
@ -32,8 +32,7 @@ public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
XBool b = true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !Address.isDefined() || Address.value() == 0) {
|
||||
if ( Enabled.isDefined() && Enabled.value() ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("Enabled is ignored because Address is not defined or 0 in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
@ -171,8 +170,7 @@ public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
XBool b = true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
return b;
|
||||
}
|
||||
const decltype(FuzzyMatch)::ValueType& dgetFuzzyMatch() const { return FuzzyMatch.isDefined() ? FuzzyMatch.value() : FuzzyMatch.nullValue; };
|
||||
|
@ -21,10 +21,9 @@ public:
|
||||
class GuidClass : public XmlString8AllowEmpty {
|
||||
using super = XmlString8AllowEmpty;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( !isDefined() ) return true;
|
||||
if ( !IsValidGuidString(xstring8) ) return xmlLiteParser->addWarning(generateErrors, S8Printf("Invalid GUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !IsValidGuidString(xstring8) ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("Invalid GUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
};
|
||||
protected:
|
||||
@ -82,12 +81,12 @@ public:
|
||||
// return false;
|
||||
// }
|
||||
// virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
//if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
// bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
// if ( !xmlString8.isDefined() ) return true;
|
||||
// if ( xmlString8.value().isEqualIC("UseMacAddr0") ) return true;
|
||||
// if ( xmlString8.value().isEqualIC("UseMacAddr1") ) return true;
|
||||
// xmlLiteParser->addWarning(generateErrors, S8Printf("Expecting an integer or \"Detect\" or \"No\" for tag '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
// return false;
|
||||
// b = xmlLiteParser->addWarning(generateErrors, S8Printf("Expecting an integer or \"Detect\" or \"No\" for tag '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
// return b;
|
||||
// }
|
||||
public:
|
||||
// const decltype(xmlString8)::ValueType& dgetRtROMAsString() const { return xmlString8.isDefined() ? xmlString8.value() : xmlString8.nullValue; };
|
||||
@ -119,13 +118,13 @@ public:
|
||||
|
||||
// class ROMClass: public XmlData {
|
||||
// virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
//if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
// bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
// if ( "UseMacAddr0"_XS8.isEqualIC(value().CData()) ) return true;
|
||||
// if ( "UseMacAddr1"_XS8.isEqualIC(value().CData()) ) return true;
|
||||
// // TODO check length and format of ROM
|
||||
// return true;
|
||||
// xmlLiteParser->addWarning(generateErrors, S8Printf("Expecting \"UseMacAddr0\", \"UseMacAddr0\" or data tag '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
// return false;
|
||||
// b = xmlLiteParser->addWarning(generateErrors, S8Printf("Expecting \"UseMacAddr0\", \"UseMacAddr0\" or data tag '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
// return b;
|
||||
// }
|
||||
// };
|
||||
|
||||
|
@ -16,20 +16,19 @@ public:
|
||||
class InjectKextsClass: public XmlBoolOrString {
|
||||
using super = XmlBoolOrString;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( isDefined() && xmlString8.isDefined() ) {
|
||||
if ( !xmlString8.value().isEqualIC("Detect") ) return xmlLiteParser->addWarning(generateErrors, S8Printf("InjectKexts must be a boolean or \"Detect\" in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( xmlString8.isDefined() ) {
|
||||
if ( !xmlString8.value().isEqualIC("Detect") ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("InjectKexts must be a boolean or \"Detect\" in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
class CustomUUIDClass : public XmlString8AllowEmpty {
|
||||
using super = XmlString8AllowEmpty;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( !isDefined() ) return true;
|
||||
if ( !IsValidGuidString(xstring8) ) return xmlLiteParser->addWarning(generateErrors, S8Printf(" invalid CustomUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !IsValidGuidString(xstring8) ) b = xmlLiteParser->addWarning(generateErrors, S8Printf(" invalid CustomUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -65,8 +64,7 @@ public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
XBool b = true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -122,23 +122,21 @@ class MyTopLevelDictClass : public ConfigPlistAbstractClass
|
||||
|
||||
##### Validation of a single value
|
||||
|
||||
To validate and reject bad input, override the method validate. Imagine we have an integer value that is a count between 0 and 15. Example 3 :
|
||||
To validate and reject bad input, override the method validate. Imagine we have an integer value that is a count between -2 and 18. Example 3 :
|
||||
|
||||
```
|
||||
class CountClass : public XmlInt64
|
||||
{
|
||||
using super = XmlInt64;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( value() < -2 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot be negative. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot be negative. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
if ( value() > 18 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot > 18. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot > 18. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
} Count = CountClass();
|
||||
```
|
||||
@ -169,22 +167,20 @@ class MyDictClass : public XmlDict
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !type.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
}
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}else
|
||||
if ( type.value() == 1 ) {
|
||||
if ( subType.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
}else if ( type.value() == 2 ) {
|
||||
// nothing to do because subtype is optional, and if it exists, weknow that the value is correct because of th validation in MyXmlSubType
|
||||
}else{
|
||||
panic("There is a bug in MyXmlType::validate() !");
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
```
|
||||
@ -209,31 +205,30 @@ class MyDictClass : public XmlDict
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !type.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
}
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}else
|
||||
if ( type.value() == 1 ) {
|
||||
if ( subType.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
}else if ( type.value() == 2 ) {
|
||||
if ( subType.isDefined() ) {
|
||||
if ( type.value() != 11 and type.value() != 12 )
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("SubType must be 11 or 12 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
if ( subType.value() != 11 && subType.value() != 12 ) {
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("SubType must be 11 or 12 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
}else{
|
||||
// subtype is optional, so it's ok.
|
||||
}
|
||||
}else{
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be 1 or 2 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
// Let's think that we want to ignore this value but we syill want to keep the dict as the other field still has meaning.
|
||||
type.reset(); // we only reset this field. We don't return false because that'll undefine the whole dict
|
||||
subtype.reset(); // SubType means nothing without a Type.
|
||||
// Let's think that we want to ignore this value but we still want to keep the dict as the other field still has meaning.
|
||||
// That's why we don't set b to false
|
||||
type.reset(); // We only reset this field. We don't return false because that'll undefine the whole dict
|
||||
subType.reset(); // SubType means nothing without a Type.
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
@ -70,22 +70,21 @@ public:
|
||||
{
|
||||
using super = XmlUInt8;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( value() >= MAX_RAM_SLOTS ) return xmlLiteParser->addWarning(generateErrors, S8Printf("Slot cannot >= MAX_RAM_SLOTS. It must a number between 0 and %d at '%s:%d'", MAX_RAM_SLOTS-1, xmlPath.c_str(), keyPos.getLine()));
|
||||
return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( value() >= MAX_RAM_SLOTS ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("Slot cannot >= MAX_RAM_SLOTS. It must a number between 0 and %d at '%s:%d'", MAX_RAM_SLOTS-1, xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
};
|
||||
class TypeClass: public XmlString8AllowEmpty {
|
||||
using super = XmlString8AllowEmpty;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( isDefined() ) {
|
||||
if ( xstring8.isEqualIC("DDR") ) return true;
|
||||
if ( xstring8.isEqualIC("DDR2") ) return true;
|
||||
if ( xstring8.isEqualIC("DDR3") ) return true;
|
||||
if ( xstring8.isEqualIC("DDR4") ) return true;
|
||||
}
|
||||
return xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be \"DDR\", \"DDR2\", \"DDR3\" or \"DDR4\" in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( xstring8.isEqualIC("DDR") ) return b;
|
||||
if ( xstring8.isEqualIC("DDR2") ) return b;
|
||||
if ( xstring8.isEqualIC("DDR3") ) return b;
|
||||
if ( xstring8.isEqualIC("DDR4") ) return b;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be \"DDR\", \"DDR2\", \"DDR3\" or \"DDR4\" in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
public:
|
||||
};
|
||||
@ -150,7 +149,7 @@ public:
|
||||
public:
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( size() > UINT8_MAX ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("You cannot declare more then 256 memory modules in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
while ( size() > 256 ) RemoveAtIndex(size()-1);
|
||||
@ -167,7 +166,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
|
||||
decltype(ModuleDictClass::SlotIndex)::ValueType dgetCalculatedSlotCount() const {
|
||||
@ -206,8 +205,7 @@ public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
XBool b = true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( Modules.size() == 0 ) {
|
||||
// whatever if SlotCount is defined or not, and whatever value, it's ok.
|
||||
return b;
|
||||
@ -263,19 +261,18 @@ public:
|
||||
class DeviceClass: public XmlString8AllowEmpty {
|
||||
using super = XmlString8AllowEmpty;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( isDefined() ) {
|
||||
if ( xstring8.isEqualIC("ATI") ) return true;
|
||||
if ( xstring8.isEqualIC("NVidia") ) return true;
|
||||
if ( xstring8.isEqualIC("IntelGFX") ) return true;
|
||||
if ( xstring8.isEqualIC("LAN") ) return true;
|
||||
if ( xstring8.isEqualIC("WIFI") ) return true;
|
||||
if ( xstring8.isEqualIC("Firewire") ) return true;
|
||||
if ( xstring8.isEqualIC("HDMI") ) return true;
|
||||
if ( xstring8.isEqualIC("USB") ) return true;
|
||||
if ( xstring8.isEqualIC("NVME") ) return true;
|
||||
}
|
||||
return xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be \"ATI\", \"NVidia\", \"IntelGFX\", \"LAN\", \"WIFI\", \"Firewire\", \"HDMI\", \"USB\" or \"NVME\" in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( xstring8.isEqualIC("ATI") ) return b;
|
||||
if ( xstring8.isEqualIC("NVidia") ) return b;
|
||||
if ( xstring8.isEqualIC("IntelGFX") ) return b;
|
||||
if ( xstring8.isEqualIC("LAN") ) return b;
|
||||
if ( xstring8.isEqualIC("WIFI") ) return b;
|
||||
if ( xstring8.isEqualIC("Firewire") ) return b;
|
||||
if ( xstring8.isEqualIC("HDMI") ) return b;
|
||||
if ( xstring8.isEqualIC("USB") ) return b;
|
||||
if ( xstring8.isEqualIC("NVME") ) return b;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be \"ATI\", \"NVidia\", \"IntelGFX\", \"LAN\", \"WIFI\", \"Firewire\", \"HDMI\", \"USB\" or \"NVME\" in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
} Device = DeviceClass();
|
||||
XmlUInt8 ID = XmlUInt8();
|
||||
@ -292,8 +289,7 @@ public:
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
XBool b = true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
return b;
|
||||
}
|
||||
const decltype(Device)::ValueType& dgetDevice() const { return Device.isDefined() ? Device.value() : Device.nullValue; };
|
||||
@ -366,10 +362,9 @@ public:
|
||||
using super = XmlString8AllowEmpty;
|
||||
protected:
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( !isDefined() ) return true;
|
||||
if ( !IsValidGuidString(xstring8) ) return xmlLiteParser->addWarning(generateErrors, S8Printf("Invalid SmUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !IsValidGuidString(xstring8) ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("Invalid SmUUID '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -379,15 +374,11 @@ public:
|
||||
public:
|
||||
ProductNameClass() : super(true) {};
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( !isDefined() ) {
|
||||
xmlLiteParser->addError(generateErrors, S8Printf("You must define ProductName in SMBIOS dict, line %d", keyPos.getLine()));
|
||||
return true;
|
||||
}
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
MacModel Model;
|
||||
Model = GetModelFromString(xstring8);
|
||||
if ( Model == MaxMacModel ) return xmlLiteParser->addWarning(generateErrors, S8Printf("Invalid ProductName '%s' in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return true;
|
||||
if ( Model == MaxMacModel ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("Invalid ProductName '%s' in dict '%s:%d'", xstring8.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -397,16 +388,17 @@ public:
|
||||
public:
|
||||
BiosVersionClass() : super(true) {};
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !value().contains(".") ) {
|
||||
return xmlLiteParser->addWarning(generateErrors, S8Printf("BiosVersion '%s' doesn't contains a dot in dict '%s:%d'.", value().c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("BiosVersion '%s' doesn't contains a dot in dict '%s:%d'.", value().c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
}else{
|
||||
size_t rindex = value().rindexOf(".");
|
||||
if ( value().length() - rindex < 7 ) {
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Last part of BiosVersion '%s' must be at least 6 chars in dict '%s:%d'.", value().c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
// Should we check the format of these 6 last chars ?
|
||||
}
|
||||
size_t rindex = value().rindexOf(".");
|
||||
if ( value().length() - rindex < 7 ) {
|
||||
return xmlLiteParser->addWarning(generateErrors, S8Printf("Last part of BiosVersion '%s' must be at least 6 chars in dict '%s:%d'.", value().c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
// Should we check the format of these 6 last chars ?
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -416,12 +408,12 @@ public:
|
||||
public:
|
||||
BiosReleaseDateClass() : super(true) {};
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( value().length() != 8 && value().length() != 10 ) {
|
||||
return xmlLiteParser->addWarning(generateErrors, S8Printf("BiosReleaseDate '%s' must 8 or 10 chars in dict '%s:%d'.", value().c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("BiosReleaseDate '%s' must 8 or 10 chars in dict '%s:%d'.", value().c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
// Should we check the format of these 8 or 10 last chars ?
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -505,7 +497,7 @@ public:
|
||||
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !ProductName.isDefined() ) {
|
||||
// return xmlLiteParser->addWarning(generateErrors, S8Printf("ProductName is not defined, the whole SMBIOS dict is ignored at line %d.", keyPos.getLine()));
|
||||
if ( defaultMacModel < MaxMacModel ) {
|
||||
@ -515,7 +507,7 @@ public:
|
||||
if ( hasModel() ) {
|
||||
if ( BiosVersion.isDefined() ) {
|
||||
if ( !is2ndBiosVersionGreaterThan1st(ApplePlatformDataArray[getModel()].firmwareVersion, BiosVersion.value()) ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("BiosVersion '%s' is before than default ('%s') -> ignored. Dict '%s:%d'.", BiosVersion.value().c_str(), ApplePlatformDataArray[getModel()].firmwareVersion.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("BiosVersion '%s' is before than default ('%s') -> ignored. Dict '%s:%d'.", BiosVersion.value().c_str(), ApplePlatformDataArray[getModel()].firmwareVersion.c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict
|
||||
BiosVersion.reset();
|
||||
}
|
||||
}
|
||||
@ -523,20 +515,20 @@ public:
|
||||
int compareReleaseDateResult = compareReleaseDate(GetReleaseDate(getModel()), BiosReleaseDate.value());
|
||||
if ( compareReleaseDateResult == 0 ) {
|
||||
// This is just 'info'. It's useless but fine to define the same as default.
|
||||
xmlLiteParser->addInfo(generateErrors, S8Printf("BiosReleaseDate '%s' is the same as default ('%s') -> ignored. Dict '%s:%d'.", BiosReleaseDate.value().c_str(), GetReleaseDate(getModel()).c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
xmlLiteParser->addInfo(generateErrors, S8Printf("BiosReleaseDate '%s' is the same as default ('%s') -> ignored. Dict '%s:%d'.", BiosReleaseDate.value().c_str(), GetReleaseDate(getModel()).c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict
|
||||
BiosReleaseDate.reset();
|
||||
}else
|
||||
if ( compareReleaseDateResult == 1 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("BiosReleaseDate '%s' is older than default ('%s') -> ignored. Dict '%s:%d'.", BiosReleaseDate.value().c_str(), GetReleaseDate(getModel()).c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("BiosReleaseDate '%s' is older than default ('%s') -> ignored. Dict '%s:%d'.", BiosReleaseDate.value().c_str(), GetReleaseDate(getModel()).c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict
|
||||
BiosReleaseDate.reset();
|
||||
}
|
||||
}
|
||||
if ( EfiVersion.isDefined() ) {
|
||||
if ( AsciiStrVersionToUint64(ApplePlatformDataArray[dgetModel()].efiversion, 4, 5) > AsciiStrVersionToUint64(EfiVersion.value(), 4, 5)) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("EfiVersion '%s' is older than default ('%s') -> ignored. Dict '%s:%d'.", EfiVersion.value().c_str(), ApplePlatformDataArray[dgetModel()].efiversion.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("EfiVersion '%s' is older than default ('%s') -> ignored. Dict '%s:%d'.", EfiVersion.value().c_str(), ApplePlatformDataArray[dgetModel()].efiversion.c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict
|
||||
EfiVersion.reset();
|
||||
} else if (AsciiStrVersionToUint64(ApplePlatformDataArray[dgetModel()].efiversion, 4, 5) == AsciiStrVersionToUint64(EfiVersion.value(), 4, 5)) {
|
||||
xmlLiteParser->addInfo(generateErrors, S8Printf("EfiVersion '%s' is the same as default ('%s') -> ignored. Dict '%s:%d'.", EfiVersion.value().c_str(), ApplePlatformDataArray[dgetModel()].efiversion.c_str(), xmlPath.c_str(), keyPos.getLine()));
|
||||
xmlLiteParser->addInfo(generateErrors, S8Printf("EfiVersion '%s' is the same as default ('%s') -> ignored. Dict '%s:%d'.", EfiVersion.value().c_str(), ApplePlatformDataArray[dgetModel()].efiversion.c_str(), xmlPath.c_str(), keyPos.getLine())); // Do not set b to false : we don't want to invalidate the whole dict
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@ -545,7 +537,7 @@ public:
|
||||
// If ccpv, let's say nothing at the moment
|
||||
//xmlLiteParser->addInfo(generateErrors, S8Printf("Cannot check validity of BiosVersion because ProductName is not set. Dict '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true; // we don't want to invalidate the whole dict
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,7 +106,8 @@ XBool XmlArray<T>::validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPat
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// The purpose of this class is to expose a ConstXString8Array instead of a XObjArray<XString8>. That way, usual XString8Array methods can be used.
|
||||
// References of XStringW are copied by the validate method.
|
||||
class XmlString8Array : public XmlArray<XmlString8>
|
||||
{
|
||||
using super = XmlArray<XmlString8>;
|
||||
@ -130,7 +131,7 @@ class XmlString8Array : public XmlArray<XmlString8>
|
||||
// Validate can remove invalid element. So we have to regenerate 'array'. There is no object copy, so it's very quick
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override
|
||||
{
|
||||
XBool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
array.setEmpty();
|
||||
for ( size_t idx = 0 ; idx < super::size() ; idx++ ) {
|
||||
array.AddReference(&super::ElementAt(idx).value(), false);
|
||||
@ -140,10 +141,8 @@ class XmlString8Array : public XmlArray<XmlString8>
|
||||
|
||||
};
|
||||
|
||||
//class XmlString8AllowEmptyArray : public XmlArray<XmlString8AllowEmpty>
|
||||
//{
|
||||
//};
|
||||
|
||||
// The purpose of this class is to expose a ConstXStringWArray instead of a XObjArray<XStringW>. That way, usual XStringWArray methods can be used.
|
||||
// References of XStringW are copied by the validate method.
|
||||
class XmlStringWArray : public XmlArray<XmlStringW>
|
||||
{
|
||||
using super = XmlArray<XmlStringW>;
|
||||
@ -171,7 +170,7 @@ NOP;
|
||||
}
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override
|
||||
{
|
||||
XBool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
// Validate can remove invalid element. So we have to regenerate 'array'. There is no object copy, so it's very quick
|
||||
array.setEmpty();
|
||||
for ( size_t idx = 0 ; idx < super::size() ; idx++ ) {
|
||||
|
@ -167,12 +167,11 @@ if (xmlPath.containsIC("BoardSerialNumber"_XS8) ) {
|
||||
NOP;
|
||||
}
|
||||
#endif
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !canBeEmpty && xstring8.isEmpty() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("String cannot be empty for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("String cannot be empty for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
|
||||
// operator const XString8& () const { return xstring8; };
|
||||
@ -204,12 +203,11 @@ public:
|
||||
virtual XBool parseFromXmlLite(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, XBool generateErrors) override;
|
||||
// TODO validate !_canBeEmpty
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !canBeEmpty && xstringW.isEmpty() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("String cannot be empty for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("String cannot be empty for tag '%s:%d'.", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
|
||||
operator const XStringW& () const { return xstringW; };
|
||||
@ -260,9 +258,9 @@ public:
|
||||
virtual XBool parseFromXmlLite(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, XBool generateErrors) override;
|
||||
virtual XBool parseFromXmlLite(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, XBool generateErrors, const char** keyValuePtr, size_t* keyValueLengthPtr);
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( xstring8.isEmpty() ) return false;
|
||||
return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( xstring8.isEmpty() ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("String cannot be empty at tag '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
|
||||
operator const XString8& () const { return xstring8; };
|
||||
@ -298,9 +296,9 @@ public:
|
||||
|
||||
// virtual XBool parseFromXmlLite(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, XBool generateErrors) override;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
if ( xstring8.isEqual("!") ) return false; // it's an empty disabled key
|
||||
return true;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( xstring8.isEqual("!") ) b = xmlLiteParser->addWarning(generateErrors, S8Printf("Disabled key (prefix with '!') cannot be emptyString cannot be empty at tag '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return b;
|
||||
}
|
||||
|
||||
operator const XString8& () const { return xstring8; };
|
||||
|
@ -606,16 +606,14 @@ int documentation_test3()
|
||||
{
|
||||
using super = XmlInt64;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( value() < -2 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot be negative. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot be negative. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
if ( value() > 18 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot > 18. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Count cannot > 18. It must a number between -2 and 18 inclusive at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
} Count = CountClass();
|
||||
|
||||
@ -652,12 +650,11 @@ int documentation_test4()
|
||||
{
|
||||
using super = XmlUInt8;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( value() < 1 || value() > 2 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be 1 or 2 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be 1 or 2 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -665,12 +662,11 @@ int documentation_test4()
|
||||
{
|
||||
using super = XmlUInt8;
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( value() < 11 || value() > 12 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("SubType must be 11 or 22 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("SubType must be 11 or 22 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@ -689,22 +685,20 @@ int documentation_test4()
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !type.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
}
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}else
|
||||
if ( type.value() == 1 ) {
|
||||
if ( subType.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
}else if ( type.value() == 2 ) {
|
||||
// nothing to do because subtype is optional, and if it exists, weknow that the value is correct because of th validation in MyXmlSubType
|
||||
}else{
|
||||
panic("There is a bug in MyXmlType::validate() !");
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
} MyDict = MyPlist();
|
||||
|
||||
@ -748,32 +742,30 @@ int documentation_test5()
|
||||
virtual void getFields(XmlDictField** fields, size_t* nb) override { *fields = m_fields; *nb = sizeof(m_fields)/sizeof(m_fields[0]); };
|
||||
|
||||
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
|
||||
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
|
||||
bool b = super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors);
|
||||
if ( !type.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
}
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type must befined at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}else
|
||||
if ( type.value() == 1 ) {
|
||||
if ( subType.isDefined() ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("Type 1 cannot have a subtype in dict '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
}else if ( type.value() == 2 ) {
|
||||
if ( subType.isDefined() ) {
|
||||
if ( subType.value() != 11 && subType.value() != 12 ) {
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("SubType must be 11 or 12 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
return false;
|
||||
b = xmlLiteParser->addWarning(generateErrors, S8Printf("SubType must be 11 or 12 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
}
|
||||
}else{
|
||||
// subtype is optional, so it's ok.
|
||||
}
|
||||
}else{
|
||||
xmlLiteParser->addWarning(generateErrors, S8Printf("Type must be 1 or 2 at '%s:%d'", xmlPath.c_str(), keyPos.getLine()));
|
||||
// Let's think that we want to ignore this value but we syill want to keep the dict as the other field still has meaning.
|
||||
type.reset(); // we only reset this field. We don't return false because that'll undefine the whole dict
|
||||
// Let's think that we want to ignore this value but we still want to keep the dict as the other field still has meaning.
|
||||
// That's why we don't set b to false
|
||||
type.reset(); // We only reset this field. We don't return false because that'll undefine the whole dict
|
||||
subType.reset(); // SubType means nothing without a Type.
|
||||
}
|
||||
return true;
|
||||
return b;
|
||||
}
|
||||
} MyDict = MyPlist();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user