1 // Copyright 2008, Google Inc. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are met: 5 // 6 // 1. Redistributions of source code must retain the above copyright notice, 7 // this list of conditions and the following disclaimer. 8 // 2. Redistributions in binary form must reproduce the above copyright notice, 9 // this list of conditions and the following disclaimer in the documentation 10 // and/or other materials provided with the distribution. 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be 12 // used to endorse or promote products derived from this software without 13 // specific prior written permission. 14 // 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26 // This file contains the declaration of the XsdElement class. 27 28 #ifndef KML_XSD_XSD_ELEMENT_H__ 29 #define KML_XSD_XSD_ELEMENT_H__ 30 31 #include "boost/intrusive_ptr.hpp" 32 #include "kml/base/referent.h" 33 #include "kml/xsd/xsd_primitive_type.h" 34 35 namespace kmlbase { 36 class Attributes; 37 } 38 39 namespace kmlxsd { 40 41 // XsdElement corresponds to <xs:element name="..." type="..." ... /> 42 // or <xs:element ref="..."/>. 43 class XsdElement : public kmlbase::Referent { 44 public: 45 // Create an XsdElement from the given attributes. 46 static XsdElement* Create(const kmlbase::Attributes& attributes); 47 48 // Get the value of the <xs:element abstract="..."> attribute. is_abstract()49 bool is_abstract() const { 50 return abstract_; 51 } 52 53 // Get the value of the <xs:element default="..."> attribute. get_default()54 const string& get_default() const { 55 return default_; 56 } 57 58 // Get the value of the <xs:element name="..."> attribute. This is the 59 // value of ref= if is_ref() is true. get_name()60 const string& get_name() const { 61 return name_; 62 } 63 64 // Get the <xs:element substitutionGroup="..."> attribute. get_substitution_group()65 const string& get_substitution_group() const { 66 return substitution_group_; 67 } 68 69 // Get the <xs:element type="..."> attribute. get_type()70 const string& get_type() const { 71 return type_; 72 } 73 74 // Return the XSD type id of the element type IF this element is of a 75 // primitive type, else return XSD_INVALID. get_type_id()76 XsdPrimitiveType::TypeId get_type_id() const { 77 return type_id_; 78 } 79 80 // This returns true if the element is of an XSD native/primitive type. 81 // Note that an element of any simpleType is _not_ considered primitive. 82 // See XsdPrimitiveType for the list of XSD primitive types. is_primitive()83 bool is_primitive() const { 84 return type_id_ != XsdPrimitiveType::XSD_INVALID; 85 } 86 87 // This returns true if this is an <xs:element ref="..."> and false if this 88 // is an <xs:element name="..." ... > is_ref()89 bool is_ref() const { 90 return ref_ == true; 91 } 92 93 private: 94 // Use static Create(). 95 XsdElement(); 96 // Set the class internals from the attributes and return true if the 97 // attributes were valid for an <xsd:element>. False is returned if there 98 // was no "name" or "ref" attribute found. 99 bool ParseAttributes(const kmlbase::Attributes& attributes); 100 bool abstract_; 101 bool ref_; 102 string default_; 103 string name_; 104 string type_; 105 XsdPrimitiveType::TypeId type_id_; 106 string substitution_group_; 107 }; 108 109 typedef boost::intrusive_ptr<XsdElement> XsdElementPtr; 110 111 } // end namespace kmlxsd 112 113 #endif // KML_XSD_XSD_ELEMENT_H__ 114