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_cast.h"
27 #include "kml_ptr.h"
28 #include "boost/intrusive_ptr.hpp"
29 
30 namespace kmldom {
31 
AsAbstractLatLonBox(const ElementPtr element)32 const AbstractLatLonBoxPtr AsAbstractLatLonBox(const ElementPtr element) {
33   if (element && element->IsA(Type_AbstractLatLonBox)) {
34     return boost::static_pointer_cast<AbstractLatLonBox>(element);
35   }
36   return NULL;
37 }
38 
AsAbstractView(const ElementPtr element)39 const AbstractViewPtr AsAbstractView(const ElementPtr element) {
40   if (element && element->IsA(Type_AbstractView)) {
41     return boost::static_pointer_cast<AbstractView>(element);
42   }
43   return NULL;
44 }
45 
AsColorStyle(const ElementPtr element)46 const ColorStylePtr AsColorStyle(const ElementPtr element) {
47   if (element && element->IsA(Type_ColorStyle)) {
48     return boost::static_pointer_cast<ColorStyle>(element);
49   }
50   return NULL;
51 }
52 
AsContainer(const ElementPtr element)53 const ContainerPtr AsContainer(const ElementPtr element) {
54   if (element && element->IsA(Type_Container)) {
55     return boost::static_pointer_cast<Container>(element);
56   }
57   return NULL;
58 }
59 
AsFeature(const ElementPtr element)60 const FeaturePtr AsFeature(const ElementPtr element) {
61   if (element && element->IsA(Type_Feature)) {
62     return boost::static_pointer_cast<Feature>(element);
63   }
64   return NULL;
65 }
66 
AsGeometry(const ElementPtr element)67 const GeometryPtr AsGeometry(const ElementPtr element) {
68   if (element && element->IsA(Type_Geometry)) {
69     return boost::static_pointer_cast<Geometry>(element);
70   }
71   return NULL;
72 }
73 
AsObject(const ElementPtr element)74 const ObjectPtr AsObject(const ElementPtr element) {
75   if (element && element->IsA(Type_Object)) {
76     return boost::static_pointer_cast<Object>(element);
77   }
78   return NULL;
79 }
80 
AsOverlay(const ElementPtr element)81 const OverlayPtr AsOverlay(const ElementPtr element) {
82   if (element && element->IsA(Type_Overlay)) {
83     return boost::static_pointer_cast<Overlay>(element);
84   }
85   return NULL;
86 }
87 
AsStyleSelector(const ElementPtr element)88 const StyleSelectorPtr AsStyleSelector(const ElementPtr element) {
89   if (element && element->IsA(Type_StyleSelector)) {
90     return boost::static_pointer_cast<StyleSelector>(element);
91   }
92   return NULL;
93 }
94 
AsSubStyle(const ElementPtr element)95 const SubStylePtr AsSubStyle(const ElementPtr element) {
96   if (element && element->IsA(Type_SubStyle)) {
97     return boost::static_pointer_cast<SubStyle>(element);
98   }
99   return NULL;
100 }
101 
AsTimePrimitive(const ElementPtr element)102 const TimePrimitivePtr AsTimePrimitive(const ElementPtr element) {
103   if (element && element->IsA(Type_TimePrimitive)) {
104     return boost::static_pointer_cast<TimePrimitive>(element);
105   }
106   return NULL;
107 }
108 
AsAlias(const ElementPtr element)109 const AliasPtr AsAlias(const ElementPtr element) {
110   if (element && element->Type() == Type_Alias) {
111     return boost::static_pointer_cast<Alias>(element);
112   }
113   return NULL;
114 }
115 
AsBalloonStyle(const ElementPtr element)116 const BalloonStylePtr AsBalloonStyle(const ElementPtr element) {
117   if (element && element->Type() == Type_BalloonStyle) {
118     return boost::static_pointer_cast<BalloonStyle>(element);
119   }
120   return NULL;
121 }
122 
AsCamera(const ElementPtr element)123 const CameraPtr AsCamera(const ElementPtr element) {
124   if (element && element->Type() == Type_Camera) {
125     return boost::static_pointer_cast<Camera>(element);
126   }
127   return NULL;
128 }
129 
AsChange(const ElementPtr element)130 const ChangePtr AsChange(const ElementPtr element) {
131   if (element && element->Type() == Type_Change) {
132     return boost::static_pointer_cast<Change>(element);
133   }
134   return NULL;
135 }
136 
AsCreate(const ElementPtr element)137 const CreatePtr AsCreate(const ElementPtr element) {
138   if (element && element->Type() == Type_Create) {
139     return boost::static_pointer_cast<Create>(element);
140   }
141   return NULL;
142 }
143 
AsData(const ElementPtr element)144 const DataPtr AsData(const ElementPtr element) {
145   if (element && element->Type() == Type_Data) {
146     return boost::static_pointer_cast<Data>(element);
147   }
148   return NULL;
149 }
150 
AsDelete(const ElementPtr element)151 const DeletePtr AsDelete(const ElementPtr element) {
152   if (element && element->Type() == Type_Delete) {
153     return boost::static_pointer_cast<Delete>(element);
154   }
155   return NULL;
156 }
157 
AsDocument(const ElementPtr element)158 const DocumentPtr AsDocument(const ElementPtr element) {
159   if (element && element->Type() == Type_Document) {
160     return boost::static_pointer_cast<Document>(element);
161   }
162   return NULL;
163 }
164 
AsFolder(const ElementPtr element)165 const FolderPtr AsFolder(const ElementPtr element) {
166   if (element && element->Type() == Type_Folder) {
167     return boost::static_pointer_cast<Folder>(element);
168   }
169   return NULL;
170 }
171 
AsGroundOverlay(const ElementPtr element)172 const GroundOverlayPtr AsGroundOverlay(const ElementPtr element) {
173   if (element && element->Type() == Type_GroundOverlay) {
174     return boost::static_pointer_cast<GroundOverlay>(element);
175   }
176   return NULL;
177 }
178 
AsHotSpot(const ElementPtr element)179 const HotSpotPtr AsHotSpot(const ElementPtr element) {
180   if (element && element->Type() == Type_hotSpot) {
181     return boost::static_pointer_cast<HotSpot>(element);
182   }
183   return NULL;
184 }
185 
AsIcon(const ElementPtr element)186 const IconPtr AsIcon(const ElementPtr element) {
187   if (element && element->Type() == Type_Icon) {
188     return boost::static_pointer_cast<Icon>(element);
189   }
190   return NULL;
191 }
192 
AsIconStyle(const ElementPtr element)193 const IconStylePtr AsIconStyle(const ElementPtr element) {
194   if (element && element->Type() == Type_IconStyle) {
195     return boost::static_pointer_cast<IconStyle>(element);
196   }
197   return NULL;
198 }
199 
AsIconStyleIcon(const ElementPtr element)200 const IconStyleIconPtr AsIconStyleIcon(const ElementPtr element) {
201   if (element && element->Type() == Type_IconStyleIcon) {
202     return boost::static_pointer_cast<IconStyleIcon>(element);
203   }
204   return NULL;
205 }
206 
AsImagePyramid(const ElementPtr element)207 const ImagePyramidPtr AsImagePyramid(const ElementPtr element) {
208   if (element && element->Type() == Type_ImagePyramid) {
209     return boost::static_pointer_cast<ImagePyramid>(element);
210   }
211   return NULL;
212 }
213 
AsInnerBoundaryIs(const ElementPtr element)214 const InnerBoundaryIsPtr AsInnerBoundaryIs(const ElementPtr element) {
215   if (element && element->Type() == Type_innerBoundaryIs) {
216     return boost::static_pointer_cast<InnerBoundaryIs>(element);
217   }
218   return NULL;
219 }
220 
AsItemIcon(const ElementPtr element)221 const ItemIconPtr AsItemIcon(const ElementPtr element) {
222   if (element && element->Type() == Type_ItemIcon) {
223     return boost::static_pointer_cast<ItemIcon>(element);
224   }
225   return NULL;
226 }
227 
AsLabelStyle(const ElementPtr element)228 const LabelStylePtr AsLabelStyle(const ElementPtr element) {
229   if (element && element->Type() == Type_LabelStyle) {
230     return boost::static_pointer_cast<LabelStyle>(element);
231   }
232   return NULL;
233 }
234 
AsLatLonAltBox(const ElementPtr element)235 const LatLonAltBoxPtr AsLatLonAltBox(const ElementPtr element) {
236   if (element && element->Type() == Type_LatLonAltBox) {
237     return boost::static_pointer_cast<LatLonAltBox>(element);
238   }
239   return NULL;
240 }
241 
AsLatLonBox(const ElementPtr element)242 const LatLonBoxPtr AsLatLonBox(const ElementPtr element) {
243   if (element && element->Type() == Type_LatLonBox) {
244     return boost::static_pointer_cast<LatLonBox>(element);
245   }
246   return NULL;
247 }
248 
AsLineString(const ElementPtr element)249 const LineStringPtr AsLineString(const ElementPtr element) {
250   if (element && element->Type() == Type_LineString) {
251     return boost::static_pointer_cast<LineString>(element);
252   }
253   return NULL;
254 }
255 
AsLineStyle(const ElementPtr element)256 const LineStylePtr AsLineStyle(const ElementPtr element) {
257   if (element && element->Type() == Type_LineStyle) {
258     return boost::static_pointer_cast<LineStyle>(element);
259   }
260   return NULL;
261 }
262 
AsLinearRing(const ElementPtr element)263 const LinearRingPtr AsLinearRing(const ElementPtr element) {
264   if (element && element->Type() == Type_LinearRing) {
265     return boost::static_pointer_cast<LinearRing>(element);
266   }
267   return NULL;
268 }
269 
AsLink(const ElementPtr element)270 const LinkPtr AsLink(const ElementPtr element) {
271   if (element && element->Type() == Type_Link) {
272     return boost::static_pointer_cast<Link>(element);
273   }
274   return NULL;
275 }
276 
AsLinkSnippet(const ElementPtr element)277 const LinkSnippetPtr AsLinkSnippet(const ElementPtr element) {
278   if (element && element->Type() == Type_linkSnippet) {
279     return boost::static_pointer_cast<LinkSnippet>(element);
280   }
281   return NULL;
282 }
283 
AsListStyle(const ElementPtr element)284 const ListStylePtr AsListStyle(const ElementPtr element) {
285   if (element && element->Type() == Type_ListStyle) {
286     return boost::static_pointer_cast<ListStyle>(element);
287   }
288   return NULL;
289 }
290 
AsLocation(const ElementPtr element)291 const LocationPtr AsLocation(const ElementPtr element) {
292   if (element && element->Type() == Type_Location) {
293     return boost::static_pointer_cast<Location>(element);
294   }
295   return NULL;
296 }
297 
AsLod(const ElementPtr element)298 const LodPtr AsLod(const ElementPtr element) {
299   if (element && element->Type() == Type_Lod) {
300     return boost::static_pointer_cast<Lod>(element);
301   }
302   return NULL;
303 }
304 
AsLookAt(const ElementPtr element)305 const LookAtPtr AsLookAt(const ElementPtr element) {
306   if (element && element->Type() == Type_LookAt) {
307     return boost::static_pointer_cast<LookAt>(element);
308   }
309   return NULL;
310 }
311 
AsModel(const ElementPtr element)312 const ModelPtr AsModel(const ElementPtr element) {
313   if (element && element->Type() == Type_Model) {
314     return boost::static_pointer_cast<Model>(element);
315   }
316   return NULL;
317 }
318 
AsMultiGeometry(const ElementPtr element)319 const MultiGeometryPtr AsMultiGeometry(const ElementPtr element) {
320   if (element && element->Type() == Type_MultiGeometry) {
321     return boost::static_pointer_cast<MultiGeometry>(element);
322   }
323   return NULL;
324 }
325 
AsNetworkLink(const ElementPtr element)326 const NetworkLinkPtr AsNetworkLink(const ElementPtr element) {
327   if (element && element->Type() == Type_NetworkLink) {
328     return boost::static_pointer_cast<NetworkLink>(element);
329   }
330   return NULL;
331 }
332 
AsOrientation(const ElementPtr element)333 const OrientationPtr AsOrientation(const ElementPtr element) {
334   if (element && element->Type() == Type_Orientation) {
335     return boost::static_pointer_cast<Orientation>(element);
336   }
337   return NULL;
338 }
339 
AsOuterBoundaryIs(const ElementPtr element)340 const OuterBoundaryIsPtr AsOuterBoundaryIs(const ElementPtr element) {
341   if (element && element->Type() == Type_outerBoundaryIs) {
342     return boost::static_pointer_cast<OuterBoundaryIs>(element);
343   }
344   return NULL;
345 }
346 
AsOverlayXY(const ElementPtr element)347 const OverlayXYPtr AsOverlayXY(const ElementPtr element) {
348   if (element && element->Type() == Type_overlayXY) {
349     return boost::static_pointer_cast<OverlayXY>(element);
350   }
351   return NULL;
352 }
353 
AsPair(const ElementPtr element)354 const PairPtr AsPair(const ElementPtr element) {
355   if (element && element->Type() == Type_Pair) {
356     return boost::static_pointer_cast<Pair>(element);
357   }
358   return NULL;
359 }
360 
AsPhotoOverlay(const ElementPtr element)361 const PhotoOverlayPtr AsPhotoOverlay(const ElementPtr element) {
362   if (element && element->Type() == Type_PhotoOverlay) {
363     return boost::static_pointer_cast<PhotoOverlay>(element);
364   }
365   return NULL;
366 }
367 
AsPlacemark(const ElementPtr element)368 const PlacemarkPtr AsPlacemark(const ElementPtr element) {
369   if (element && element->Type() == Type_Placemark) {
370     return boost::static_pointer_cast<Placemark>(element);
371   }
372   return NULL;
373 }
374 
AsPoint(const ElementPtr element)375 const PointPtr AsPoint(const ElementPtr element) {
376   if (element && element->Type() == Type_Point) {
377     return boost::static_pointer_cast<Point>(element);
378   }
379   return NULL;
380 }
381 
AsPolyStyle(const ElementPtr element)382 const PolyStylePtr AsPolyStyle(const ElementPtr element) {
383   if (element && element->Type() == Type_PolyStyle) {
384     return boost::static_pointer_cast<PolyStyle>(element);
385   }
386   return NULL;
387 }
388 
AsPolygon(const ElementPtr element)389 const PolygonPtr AsPolygon(const ElementPtr element) {
390   if (element && element->Type() == Type_Polygon) {
391     return boost::static_pointer_cast<Polygon>(element);
392   }
393   return NULL;
394 }
395 
AsRegion(const ElementPtr element)396 const RegionPtr AsRegion(const ElementPtr element) {
397   if (element && element->Type() == Type_Region) {
398     return boost::static_pointer_cast<Region>(element);
399   }
400   return NULL;
401 }
402 
AsResourceMap(const ElementPtr element)403 const ResourceMapPtr AsResourceMap(const ElementPtr element) {
404   if (element && element->Type() == Type_ResourceMap) {
405     return boost::static_pointer_cast<ResourceMap>(element);
406   }
407   return NULL;
408 }
409 
AsRotationXY(const ElementPtr element)410 const RotationXYPtr AsRotationXY(const ElementPtr element) {
411   if (element && element->Type() == Type_rotationXY) {
412     return boost::static_pointer_cast<RotationXY>(element);
413   }
414   return NULL;
415 }
416 
AsScale(const ElementPtr element)417 const ScalePtr AsScale(const ElementPtr element) {
418   if (element && element->Type() == Type_Scale) {
419     return boost::static_pointer_cast<Scale>(element);
420   }
421   return NULL;
422 }
423 
AsSchema(const ElementPtr element)424 const SchemaPtr AsSchema(const ElementPtr element) {
425   if (element && element->Type() == Type_Schema) {
426     return boost::static_pointer_cast<Schema>(element);
427   }
428   return NULL;
429 }
430 
AsSchemaData(const ElementPtr element)431 const SchemaDataPtr AsSchemaData(const ElementPtr element) {
432   if (element && element->Type() == Type_SchemaData) {
433     return boost::static_pointer_cast<SchemaData>(element);
434   }
435   return NULL;
436 }
437 
AsScreenOverlay(const ElementPtr element)438 const ScreenOverlayPtr AsScreenOverlay(const ElementPtr element) {
439   if (element && element->Type() == Type_ScreenOverlay) {
440     return boost::static_pointer_cast<ScreenOverlay>(element);
441   }
442   return NULL;
443 }
444 
AsScreenXY(const ElementPtr element)445 const ScreenXYPtr AsScreenXY(const ElementPtr element) {
446   if (element && element->Type() == Type_screenXY) {
447     return boost::static_pointer_cast<ScreenXY>(element);
448   }
449   return NULL;
450 }
451 
AsSize(const ElementPtr element)452 const SizePtr AsSize(const ElementPtr element) {
453   if (element && element->Type() == Type_size) {
454     return boost::static_pointer_cast<Size>(element);
455   }
456   return NULL;
457 }
458 
AsSnippet(const ElementPtr element)459 const SnippetPtr AsSnippet(const ElementPtr element) {
460   if (element && element->Type() == Type_Snippet) {
461     return boost::static_pointer_cast<Snippet>(element);
462   }
463   return NULL;
464 }
465 
AsStyle(const ElementPtr element)466 const StylePtr AsStyle(const ElementPtr element) {
467   if (element && element->Type() == Type_Style) {
468     return boost::static_pointer_cast<Style>(element);
469   }
470   return NULL;
471 }
472 
AsStyleMap(const ElementPtr element)473 const StyleMapPtr AsStyleMap(const ElementPtr element) {
474   if (element && element->Type() == Type_StyleMap) {
475     return boost::static_pointer_cast<StyleMap>(element);
476   }
477   return NULL;
478 }
479 
AsTimeSpan(const ElementPtr element)480 const TimeSpanPtr AsTimeSpan(const ElementPtr element) {
481   if (element && element->Type() == Type_TimeSpan) {
482     return boost::static_pointer_cast<TimeSpan>(element);
483   }
484   return NULL;
485 }
486 
AsTimeStamp(const ElementPtr element)487 const TimeStampPtr AsTimeStamp(const ElementPtr element) {
488   if (element && element->Type() == Type_TimeStamp) {
489     return boost::static_pointer_cast<TimeStamp>(element);
490   }
491   return NULL;
492 }
493 
AsUpdate(const ElementPtr element)494 const UpdatePtr AsUpdate(const ElementPtr element) {
495   if (element && element->Type() == Type_Update) {
496     return boost::static_pointer_cast<Update>(element);
497   }
498   return NULL;
499 }
500 
AsViewVolume(const ElementPtr element)501 const ViewVolumePtr AsViewVolume(const ElementPtr element) {
502   if (element && element->Type() == Type_ViewVolume) {
503     return boost::static_pointer_cast<ViewVolume>(element);
504   }
505   return NULL;
506 }
507 
508 }  // end namespace kmldom
509