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 abstract Feature element.
27 
28 #ifndef KML_DOM_FEATURE_H__
29 #define KML_DOM_FEATURE_H__
30 
31 #include "kml/dom/abstractview.h"
32 #include "kml/dom/atom.h"
33 #include "kml/dom/extendeddata.h"
34 #include "kml/dom/kml22.h"
35 #include "kml/dom/kml_ptr.h"
36 #include "kml/dom/object.h"
37 #include "kml/dom/region.h"
38 #include "kml/dom/snippet.h"
39 #include "kml/dom/styleselector.h"
40 #include "kml/dom/timeprimitive.h"
41 #include "kml/dom/xal.h"
42 #include "kml/base/util.h"
43 
44 namespace kmldom {
45 
46 class VisitorDriver;
47 
48 // OGC KML 2.2 Standard: 9.1 kml:AbstractFeatureGroup
49 // OGC KML 2.2 XSD: <element name="AbstractFeatureGroup"...
50 class Feature : public Object {
51  public:
52   virtual ~Feature();
Type()53   virtual KmlDomType Type() const { return Type_Feature; }
IsA(KmlDomType type)54   virtual bool IsA(KmlDomType type) const {
55     return type == Type_Feature || Object::IsA(type);
56   }
57 
58   // <name>
get_name()59   const string& get_name() const { return name_; }
has_name()60   bool has_name() const { return has_name_; }
set_name(const string & value)61   void set_name(const string& value) {
62     name_ = value;
63     has_name_ = true;
64   }
clear_name()65   void clear_name() {
66     name_.clear();
67     has_name_ = false;
68   }
69 
70   // <visibility>
get_visibility()71   bool get_visibility() const { return visibility_; }
has_visibility()72   bool has_visibility() const { return has_visibility_; }
set_visibility(bool value)73   void set_visibility(bool value) {
74     visibility_ = value;
75     has_visibility_ = true;
76   }
clear_visibility()77   void clear_visibility() {
78     visibility_ = true;  // Default <visibility> is true.
79     has_visibility_ = false;
80   }
81 
82   // <open>
get_open()83   bool get_open() const { return open_; }
has_open()84   bool has_open() const { return has_open_; }
set_open(bool value)85   void set_open(bool value) {
86     open_ = value;
87     has_open_ = true;
88   }
clear_open()89   void clear_open() {
90     open_ = false;
91     has_open_ = false;
92   }
93 
94   // <atom:author>
get_atomauthor()95   const AtomAuthorPtr& get_atomauthor() const { return atomauthor_; }
has_atomauthor()96   bool has_atomauthor() const { return atomauthor_ != NULL; }
set_atomauthor(const AtomAuthorPtr & atomauthor)97   void set_atomauthor(const AtomAuthorPtr& atomauthor) {
98     SetComplexChild(atomauthor, &atomauthor_);
99   }
clear_atomauthor()100   void clear_atomauthor() {
101     set_atomauthor(NULL);
102   }
103 
104   // <atom:link>
get_atomlink()105   const AtomLinkPtr& get_atomlink() const { return atomlink_; }
has_atomlink()106   bool has_atomlink() const { return atomlink_ != NULL; }
set_atomlink(const AtomLinkPtr & atomlink)107   void set_atomlink(const AtomLinkPtr& atomlink) {
108     SetComplexChild(atomlink, &atomlink_);
109   }
clear_atomlink()110   void clear_atomlink() {
111     set_atomlink(NULL);
112   }
113 
114   // <address>
get_address()115   const string& get_address() const { return address_; }
has_address()116   bool has_address() const { return has_address_; }
set_address(const string & value)117   void set_address(const string& value) {
118     address_ = value;
119     has_address_ = true;
120   }
clear_address()121   void clear_address() {
122     address_.clear();
123     has_address_ = false;
124   }
125 
126   // <xal:AddressDetails>
get_xaladdressdetails()127   const XalAddressDetailsPtr& get_xaladdressdetails() const {
128     return xaladdressdetails_;
129   }
has_xaladdressdetails()130   bool has_xaladdressdetails() const { return xaladdressdetails_ != NULL; }
set_xaladdressdetails(const XalAddressDetailsPtr & xaladdressdetails)131   void set_xaladdressdetails(const XalAddressDetailsPtr& xaladdressdetails) {
132     SetComplexChild(xaladdressdetails, &xaladdressdetails_);
133   }
clear_xaladdressdetails()134   void clear_xaladdressdetails() {
135     set_xaladdressdetails(NULL);
136   }
137 
138   // <phoneNumber>
get_phonenumber()139   const string& get_phonenumber() const { return phonenumber_; }
has_phonenumber()140   bool has_phonenumber() const { return has_phonenumber_; }
set_phonenumber(const string & value)141   void set_phonenumber(const string& value) {
142     phonenumber_ = value;
143     has_phonenumber_ = true;
144   }
clear_phonenumber()145   void clear_phonenumber() {
146     phonenumber_.clear();
147     has_phonenumber_ = false;
148   }
149 
150   // TODO: "little" <snippet> (presently preserved as a misplaced child)
151   // <Snippet>
get_snippet()152   const SnippetPtr& get_snippet() const { return snippet_; }
has_snippet()153   bool has_snippet() const { return snippet_ != NULL; }
set_snippet(const SnippetPtr & snippet)154   void set_snippet(const SnippetPtr& snippet) {
155     SetComplexChild(snippet, &snippet_);
156   }
clear_snippet()157   void clear_snippet() {
158     set_snippet(NULL);
159   }
160 
161   // <description>
get_description()162   const string& get_description() const { return description_; }
has_description()163   bool has_description() const { return has_description_; }
set_description(const string & value)164   void set_description(const string& value) {
165     description_ = value;
166     has_description_ = true;
167   }
clear_description()168   void clear_description() {
169     description_.clear();
170     has_description_ = false;
171   }
172 
173   // AbstractView
get_abstractview()174   const AbstractViewPtr& get_abstractview() const { return abstractview_; }
has_abstractview()175   bool has_abstractview() const { return abstractview_ != NULL; }
set_abstractview(const AbstractViewPtr & abstractview)176   void set_abstractview(const AbstractViewPtr& abstractview) {
177     SetComplexChild(abstractview, &abstractview_);
178   }
clear_abstractview()179   void clear_abstractview() {
180     set_abstractview(NULL);
181   }
182 
183   // TimePrimitive
get_timeprimitive()184   const TimePrimitivePtr& get_timeprimitive() const { return timeprimitive_; }
has_timeprimitive()185   bool has_timeprimitive() const { return timeprimitive_ != NULL; }
set_timeprimitive(const TimePrimitivePtr & timeprimitive)186   void set_timeprimitive(const TimePrimitivePtr& timeprimitive) {
187     SetComplexChild(timeprimitive, &timeprimitive_);
188   }
clear_timeprimitive()189   void clear_timeprimitive() {
190     set_timeprimitive(NULL);
191   }
192 
193   // <styleUrl>
get_styleurl()194   const string& get_styleurl() const { return styleurl_; }
styleurl()195   string& styleurl() { return styleurl_; }
has_styleurl()196   bool has_styleurl() const { return has_styleurl_; }
set_styleurl(const string & value)197   void set_styleurl(const string& value) {
198     styleurl_ = value;
199     has_styleurl_ = true;
200   }
clear_styleurl()201   void clear_styleurl() {
202     styleurl_.clear();
203     has_styleurl_ = false;
204   }
205 
206   // StyleSelector
get_styleselector()207   const StyleSelectorPtr& get_styleselector() const { return styleselector_; }
has_styleselector()208   bool has_styleselector() const { return styleselector_ != NULL; }
set_styleselector(const StyleSelectorPtr & styleselector)209   void set_styleselector(const StyleSelectorPtr& styleselector) {
210     SetComplexChild(styleselector, &styleselector_);
211   }
clear_styleselector()212   void clear_styleselector() {
213     set_styleselector(NULL);
214   }
215 
216   // <Region>
get_region()217   const RegionPtr& get_region() const { return region_; }
has_region()218   bool has_region() const { return region_ != NULL; }
set_region(const RegionPtr & region)219   void set_region(const RegionPtr& region) {
220     SetComplexChild(region, &region_);
221   }
clear_region()222   void clear_region() {
223     set_region(NULL);
224   }
225 
226   // TODO: <Metadata> (presently preserved as a misplaced child)
227   // <ExtendedData>
get_extendeddata()228   const ExtendedDataPtr& get_extendeddata() const { return extendeddata_; }
has_extendeddata()229   bool has_extendeddata() const { return extendeddata_ != NULL; }
set_extendeddata(const ExtendedDataPtr & extendeddata)230   void set_extendeddata(const ExtendedDataPtr& extendeddata) {
231     SetComplexChild(extendeddata, &extendeddata_);
232   }
clear_extendeddata()233   void clear_extendeddata() {
234     set_extendeddata(NULL);
235   }
236 
237   // From kml:AbstractFeatureSimpleExtensionGroup.
238 
239   // <gx:balloonVisibility>
get_gx_balloonvisibility()240   bool get_gx_balloonvisibility() const { return gx_balloonvisibility_; }
has_gx_balloonvisibility()241   bool has_gx_balloonvisibility() const { return has_gx_balloonvisibility_; }
set_gx_balloonvisibility(bool value)242   void set_gx_balloonvisibility(bool value) {
243     gx_balloonvisibility_ = value;
244     has_gx_balloonvisibility_ = true;
245   }
clear_gx_balloonvisibility()246   void clear_gx_balloonvisibility() {
247     gx_balloonvisibility_ = false;
248     has_gx_balloonvisibility_ = false;
249   }
250 
251   // Visitor API methods, see visitor.h.
252   virtual void AcceptChildren(VisitorDriver* driver);
253 
254  protected:
255   // Feature is abstract.
256   Feature();
257   virtual void AddElement(const ElementPtr& element);
258   void SerializeBeforeStyleSelector(Serializer& serialize) const;
259   void SerializeAfterStyleSelector(Serializer& serialize) const;
260   virtual void Serialize(Serializer& serialize) const;
261 
262  private:
263   string name_;
264   bool has_name_;
265   bool visibility_;
266   bool has_visibility_;
267   bool open_;
268   bool has_open_;
269   AtomAuthorPtr atomauthor_;
270   AtomLinkPtr atomlink_;
271   string address_;
272   bool has_address_;
273   XalAddressDetailsPtr xaladdressdetails_;
274   string phonenumber_;
275   bool has_phonenumber_;
276   SnippetPtr snippet_;
277   string description_;
278   bool has_description_;
279   AbstractViewPtr abstractview_;
280   TimePrimitivePtr timeprimitive_;
281   string styleurl_;
282   bool has_styleurl_;
283   StyleSelectorPtr styleselector_;
284   RegionPtr region_;
285   ExtendedDataPtr extendeddata_;
286   bool gx_balloonvisibility_;
287   bool has_gx_balloonvisibility_;
288   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Feature);
289 };
290 
291 }  // namespace kmldom
292 
293 #endif  // KML_DOM_FEATURE_H__
294