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 declarations of the Pair and StyleMap elements.
27 
28 #ifndef KML_DOM_STYLEMAP_H__
29 #define KML_DOM_STYLEMAP_H__
30 
31 #include <vector>
32 #include "kml/dom/kml22.h"
33 #include "kml/dom/kml_ptr.h"
34 #include "kml/dom/object.h"
35 #include "kml/dom/styleselector.h"
36 
37 namespace kmldom {
38 
39 class Serializer;
40 class Visitor;
41 class VisitorDriver;
42 
43 // <Pair>
44 class Pair : public Object {
45  public:
46   virtual ~Pair();
Type()47   virtual KmlDomType Type() const { return Type_Pair; }
IsA(KmlDomType type)48   virtual bool IsA(KmlDomType type) const {
49     return type == Type_Pair || Object::IsA(type);
50   }
51 
52   // <key>
get_key()53   int get_key() const {
54     return key_;
55   }
has_key()56   bool has_key() const {
57     return has_key_;
58   }
set_key(int key)59   void set_key(int key) {
60     key_ = key;
61     has_key_ = true;
62   }
clear_key()63   void clear_key() {
64     key_ = STYLESTATE_NORMAL;
65     has_key_ = false;
66   }
67 
68   // <styleUrl>
get_styleurl()69   const string& get_styleurl() const {
70     return styleurl_;
71   }
has_styleurl()72   bool has_styleurl() const {
73     return has_styleurl_;
74   }
set_styleurl(const string & styleurl)75   void set_styleurl(const string& styleurl) {
76     styleurl_ = styleurl;
77     has_styleurl_ = true;
78   }
clear_styleurl()79   void clear_styleurl() {
80     styleurl_.clear();
81     has_styleurl_ = false;
82   }
83 
84   // StyleSelector
get_styleselector()85   const StyleSelectorPtr& get_styleselector() const { return styleselector_; }
has_styleselector()86   bool has_styleselector() const { return styleselector_ != NULL; }
set_styleselector(const StyleSelectorPtr & styleselector)87   void set_styleselector(const StyleSelectorPtr& styleselector) {
88     SetComplexChild(styleselector, &styleselector_);
89   }
clear_styleselector()90   void clear_styleselector() {
91     set_styleselector(NULL);
92   }
93 
94   // Visitor API methods, see visitor.h.
95   virtual void Accept(Visitor* visitor);
96   virtual void AcceptChildren(VisitorDriver* driver);
97 
98  private:
99   friend class KmlFactory;
100   Pair();
101   friend class KmlHandler;
102   virtual void AddElement(const ElementPtr& element);
103   friend class Serializer;
104   virtual void Serialize(Serializer& serializer) const;
105   int key_;
106   bool has_key_;
107   string styleurl_;
108   bool has_styleurl_;
109   StyleSelectorPtr styleselector_;
110   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Pair);
111 };
112 
113 // <StyleMap>
114 class StyleMap : public StyleSelector {
115  public:
116   virtual ~StyleMap();
Type()117   virtual KmlDomType Type() const { return Type_StyleMap; }
IsA(KmlDomType type)118   virtual bool IsA(KmlDomType type) const {
119     return type == Type_StyleMap || StyleSelector::IsA(type);
120   }
121 
add_pair(const PairPtr & pair)122   void add_pair(const PairPtr& pair) {
123     AddComplexChild(pair, &pair_array_);
124   }
125 
get_pair_array_size()126   size_t get_pair_array_size() const {
127     return pair_array_.size();
128   }
129 
get_pair_array_at(size_t index)130   const PairPtr& get_pair_array_at(size_t index) const {
131     return pair_array_[index];
132   }
133 
134   // Visitor API methods, see visitor.h.
135   virtual void Accept(Visitor* visitor);
136   virtual void AcceptChildren(VisitorDriver* driver);
137 
138  private:
139   friend class KmlFactory;
140   StyleMap();
141   friend class KmlHandler;
142   virtual void AddElement(const ElementPtr& element);
143   friend class Serializer;
144   virtual void Serialize(Serializer& serializer) const;
145   std::vector<PairPtr> pair_array_;
146   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(StyleMap);
147 };
148 
149 }  // end namespace kmldom
150 
151 #endif  // KML_DOM_STYLEMAP_H__
152