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 #ifndef KML_DOM_DOCUMENT_H__
27 #define KML_DOM_DOCUMENT_H__
28 
29 #include <vector>
30 #include "kml/dom/container.h"
31 #include "kml/dom/kml22.h"
32 #include "kml/dom/kml_ptr.h"
33 #include "kml/dom/schema.h"
34 #include "kml/dom/styleselector.h"
35 
36 namespace kmldom {
37 
38 class Visitor;
39 class VisitorDriver;
40 
41 class Document : public Container {
42  public:
43   virtual ~Document();
Type()44   virtual KmlDomType Type() const { return Type_Document; }
IsA(KmlDomType type)45   virtual bool IsA(KmlDomType type) const {
46     return type == Type_Document || Container::IsA(type);
47   }
48 
49   // <Schema>
add_schema(const SchemaPtr & schema)50   void add_schema(const SchemaPtr& schema) {
51     AddComplexChild(schema, &schema_array_);
52   }
53 
get_schema_array_size()54   size_t get_schema_array_size() const {
55     return schema_array_.size();
56   }
57 
get_schema_array_at(size_t index)58   const SchemaPtr& get_schema_array_at(size_t index) const {
59     return schema_array_[index];
60   }
61 
DeleteSchemaAt(size_t index)62   SchemaPtr DeleteSchemaAt(size_t index) {
63     return Element::DeleteFromArrayAt(&schema_array_, index);
64   }
65 
66   // <Style> and <StyleMap>
add_styleselector(const StyleSelectorPtr & styleselector)67   void add_styleselector(const StyleSelectorPtr& styleselector) {
68     AddComplexChild(styleselector, &styleselector_array_);
69   }
70 
get_styleselector_array_size()71   size_t get_styleselector_array_size() const {
72     return styleselector_array_.size();
73   }
74 
get_styleselector_array_at(size_t index)75   const StyleSelectorPtr& get_styleselector_array_at(size_t index) const {
76     return styleselector_array_[index];
77   }
78 
DeleteStyleSelectorAt(size_t index)79   StyleSelectorPtr DeleteStyleSelectorAt(size_t index) {
80     return Element::DeleteFromArrayAt(&styleselector_array_, index);
81   }
82 
83   // Note: If Document contains a StyleSelector, it is appended to Document's
84   // array of StyleSelectors and is NOT handed up to Feature. The current
85   // KML Spec/XSD is incorrect in that it gives any Feature this array
86   // behaviour. Any Feature other than Document may have only ONE StyleSelector.
87 
88   // Visitor API methods, see visitor.h.
89   virtual void Accept(Visitor* visitor);
90   virtual void AcceptChildren(VisitorDriver* driver);
91 
92  private:
93   friend class KmlFactory;
94   Document();
95   friend class KmlHandler;
96   virtual void AddElement(const ElementPtr& element);
97   friend class Serializer;
98   virtual void Serialize(Serializer& serializer) const;
99   std::vector<SchemaPtr> schema_array_;
100   std::vector<StyleSelectorPtr> styleselector_array_;
101   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Document);
102 };
103 
104 }  // end namespace kmldom
105 
106 #endif  // KML_DOM_DOCUMENT_H__
107