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 #include "kml/dom/style.h"
27 #include "kml/base/attributes.h"
28 #include "kml/dom/kml22.h"
29 #include "kml/dom/kml_cast.h"
30 #include "kml/dom/serializer.h"
31 
32 using kmlbase::Attributes;
33 
34 namespace kmldom {
35 
Style()36 Style::Style() {}
37 
~Style()38 Style::~Style() {}
39 
AddElement(const ElementPtr & element)40 void Style::AddElement(const ElementPtr& element) {
41   if (!element) {
42     return;
43   }
44   switch (element->Type()) {
45     case Type_IconStyle:
46       set_iconstyle(AsIconStyle(element));
47       break;
48     case Type_LabelStyle:
49       set_labelstyle(AsLabelStyle(element));
50       break;
51     case Type_LineStyle:
52       set_linestyle(AsLineStyle(element));
53       break;
54     case Type_PolyStyle:
55       set_polystyle(AsPolyStyle(element));
56       break;
57     case Type_BalloonStyle:
58       set_balloonstyle(AsBalloonStyle(element));
59       break;
60     case Type_ListStyle:
61       set_liststyle(AsListStyle(element));
62       break;
63     default:
64       StyleSelector::AddElement(element);
65       break;
66   }
67 }
68 
Serialize(Serializer & serializer) const69 void Style::Serialize(Serializer& serializer) const {
70   ElementSerializer element_serializer(*this, serializer);
71   StyleSelector::Serialize(serializer);
72   if (has_iconstyle()) {
73     serializer.SaveElement(get_iconstyle());
74   }
75   if (has_labelstyle()) {
76     serializer.SaveElement(get_labelstyle());
77   }
78   if (has_linestyle()) {
79     serializer.SaveElement(get_linestyle());
80   }
81   if (has_polystyle()) {
82     serializer.SaveElement(get_polystyle());
83   }
84   if (has_balloonstyle()) {
85     serializer.SaveElement(get_balloonstyle());
86   }
87   if (has_liststyle()) {
88     serializer.SaveElement(get_liststyle());
89   }
90 }
91 
Accept(Visitor * visitor)92 void Style::Accept(Visitor* visitor) {
93   visitor->VisitStyle(StylePtr(this));
94 }
95 
AcceptChildren(VisitorDriver * driver)96 void Style::AcceptChildren(VisitorDriver* driver) {
97   StyleSelector::AcceptChildren(driver);
98   if (has_iconstyle()) {
99     driver->Visit(get_iconstyle());
100   }
101   if (has_labelstyle()) {
102     driver->Visit(get_labelstyle());
103   }
104   if (has_linestyle()) {
105     driver->Visit(get_linestyle());
106   }
107   if (has_polystyle()) {
108     driver->Visit(get_polystyle());
109   }
110   if (has_balloonstyle()) {
111     driver->Visit(get_balloonstyle());
112   }
113   if (has_liststyle()) {
114     driver->Visit(get_liststyle());
115   }
116 }
117 
118 }  // end namespace kmldom
119