From 7e6e3d20f334547d8cea78e8e0b37106efebe028 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 8 Nov 2011 13:48:38 -0800 Subject: added Lazy modifier to params to support recursion ChoiceBlock can now derive from another param block Params with name/value support can be assigned directly in C++ code using param = "named_value" --- indra/llxuixml/llxuiparser.cpp | 258 +++++++++++++++++++++++++++++++---------- 1 file changed, 197 insertions(+), 61 deletions(-) (limited to 'indra/llxuixml/llxuiparser.cpp') diff --git a/indra/llxuixml/llxuiparser.cpp b/indra/llxuixml/llxuiparser.cpp index 878f992178..cdf578113a 100644 --- a/indra/llxuixml/llxuiparser.cpp +++ b/indra/llxuixml/llxuiparser.cpp @@ -59,28 +59,26 @@ const char* NO_VALUE_MARKER = "no_value"; const S32 LINE_NUMBER_HERE = 0; -struct MaxOccur : public LLInitParam::ChoiceBlock +struct MaxOccursValues : public LLInitParam::TypeValuesHelper { - Alternative count; - Alternative unbounded; - - MaxOccur() - : unbounded("", "unbounded") - {} + using TypeValuesHelper::operator =; + typedef std::string name_t; + static void declareValues() + { + declare("unbounded", U32_MAX); + } }; struct Occurs : public LLInitParam::Block { - Optional minOccurs; - Optional maxOccurs; + Optional minOccurs; + Optional maxOccurs; + Multiple foo; Occurs() - : minOccurs("minOccurs"), - maxOccurs("maxOccurs") - { - minOccurs = 0; - maxOccurs.unbounded.choose(); - } + : minOccurs("minOccurs", 0), + maxOccurs("maxOccurs", U32_MAX) + {} }; @@ -103,18 +101,15 @@ namespace LLInitParam }; } -struct Name : public LLInitParam::Block -{ - Mandatory name; - - Name() - : name("name") - {} -}; +struct Element; +struct Group; +struct Choice; +struct Sequence; +struct Any; struct Attribute : public LLInitParam::Block { - Mandatory name; + Mandatory name; Mandatory type; Mandatory use; @@ -122,41 +117,170 @@ struct Attribute : public LLInitParam::Block : name("name"), type("type"), use("use") + {} +}; + +struct Any : public LLInitParam::Block +{ + Optional _namespace; + + Any() + : _namespace("namespace") + {} +}; + +struct All : public LLInitParam::Block +{ + Multiple> elements; + + All() + : elements("element") { + maxOccurs = 1; } }; -struct ComplexType : public LLInitParam::Block +struct Choice : public LLInitParam::ChoiceBlock +{ + Alternative> element; + Alternative> group; + Alternative> choice; + Alternative> sequence; + Alternative> any; + + Choice() + : element("element"), + group("group"), + choice("choice"), + sequence("sequence"), + any("any") + {} + +}; + +struct Sequence : public LLInitParam::ChoiceBlock +{ + Alternative> element; + Alternative> group; + Alternative> choice; + Alternative> sequence; + Alternative> any; +}; + +struct GroupContents : public LLInitParam::ChoiceBlock { - Multiple attribute; - //Multiple elements; - Optional mixed; + Alternative all; + Alternative choice; + Alternative sequence; + + GroupContents() + : all("all"), + choice("choice"), + sequence("sequence") + {} +}; + +struct Group : public LLInitParam::Block +{ + Optional name, + ref; + + Group() + : name("name"), + ref("ref") + {} +}; + +struct Restriction : public LLInitParam::Block +{ +}; + +struct Extension : public LLInitParam::Block +{ +}; + +struct SimpleContent : public LLInitParam::ChoiceBlock +{ + Alternative restriction; + Alternative extension; + + SimpleContent() + : restriction("restriction"), + extension("extension") + {} +}; + +struct SimpleType : public LLInitParam::Block +{ + // TODO +}; + +struct ComplexContent : public LLInitParam::Block +{ + Optional mixed; + + ComplexContent() + : mixed("mixed", true) + {} +}; + +struct ComplexTypeContents : public LLInitParam::ChoiceBlock +{ + Alternative simple_content; + Alternative complex_content; + Alternative group; + Alternative all; + Alternative choice; + Alternative sequence; + + ComplexTypeContents() + : simple_content("simpleContent"), + complex_content("complexContent"), + group("group"), + all("all"), + choice("choice"), + sequence("sequence") + {} +}; + +struct ComplexType : public LLInitParam::Block +{ + Optional name; + Optional mixed; + + Multiple attribute; + Multiple> elements; ComplexType() - : attribute("xs:attribute"), - //elements("xs:element"), + : name("name"), + attribute("xs:attribute"), + elements("xs:element"), mixed("mixed") { - mixed = true; } }; -struct Element : public LLInitParam::Block +struct ElementContents : public LLInitParam::ChoiceBlock { - Mandatory complexType; - Mandatory name; + Alternative simpleType; + Alternative complexType; - Element() - : complexType("xs:complexType") + ElementContents() + : simpleType("simpleType"), + complexType("complexType") {} }; -struct Elements : public LLInitParam::Block +struct Element : public LLInitParam::Block { - Multiple elements; + Optional name, + ref, + type; - Elements() - : elements("xs:element") + Element() + : name("xs:name"), + ref("xs:ref"), + type("xs:type") {} }; @@ -164,28 +288,32 @@ struct Schema : public LLInitParam::Block { private: Mandatory targetNamespace, - xmlns; + xmlns, + xs; public: Optional attributeFormDefault, - elementFormDefault, - xs; + elementFormDefault; - Optional elements; + Mandatory root_element; void setNameSpace(const std::string& ns) {targetNamespace = ns; xmlns = ns;} - Schema() + Schema(const std::string& ns = LLStringUtil::null) : attributeFormDefault("attributeFormDefault"), elementFormDefault("elementFormDefault"), xs("xmlns:xs"), targetNamespace("targetNamespace"), xmlns("xmlns"), - elements("xs:choice") + root_element("xs:element") { attributeFormDefault = "unqualified"; elementFormDefault = "qualified"; xs = "http://www.w3.org/2001/XMLSchema"; + if (!ns.empty()) + { + setNameSpace(ns); + }; } }; @@ -214,22 +342,30 @@ LLXSDWriter::LLXSDWriter() void LLXSDWriter::writeXSD(const std::string& type_name, LLXMLNodePtr node, const LLInitParam::BaseBlock& block, const std::string& xml_namespace) { + Schema schema(xml_namespace); + + schema.root_element.name = type_name; + Choice& choice = schema.root_element.complexType.choice; + + choice.minOccurs = 0; + choice.maxOccurs = "unbounded"; + mSchemaNode = node; - node->setName("xs:schema"); - node->createChild("attributeFormDefault", true)->setStringValue("unqualified"); - node->createChild("elementFormDefault", true)->setStringValue("qualified"); - node->createChild("targetNamespace", true)->setStringValue(xml_namespace); - node->createChild("xmlns:xs", true)->setStringValue("http://www.w3.org/2001/XMLSchema"); - node->createChild("xmlns", true)->setStringValue(xml_namespace); - - node = node->createChild("xs:complexType", false); - node->createChild("name", true)->setStringValue(type_name); - node->createChild("mixed", true)->setStringValue("true"); - - mAttributeNode = node; - mElementNode = node->createChild("xs:choice", false); - mElementNode->createChild("minOccurs", true)->setStringValue("0"); - mElementNode->createChild("maxOccurs", true)->setStringValue("unbounded"); + //node->setName("xs:schema"); + //node->createChild("attributeFormDefault", true)->setStringValue("unqualified"); + //node->createChild("elementFormDefault", true)->setStringValue("qualified"); + //node->createChild("targetNamespace", true)->setStringValue(xml_namespace); + //node->createChild("xmlns:xs", true)->setStringValue("http://www.w3.org/2001/XMLSchema"); + //node->createChild("xmlns", true)->setStringValue(xml_namespace); + + //node = node->createChild("xs:complexType", false); + //node->createChild("name", true)->setStringValue(type_name); + //node->createChild("mixed", true)->setStringValue("true"); + + //mAttributeNode = node; + //mElementNode = node->createChild("xs:choice", false); + //mElementNode->createChild("minOccurs", true)->setStringValue("0"); + //mElementNode->createChild("maxOccurs", true)->setStringValue("unbounded"); block.inspectBlock(*this); // duplicate element choices -- cgit v1.2.3