1 // Copyright 2009, 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 // WARNING: THE VISITOR API IMPLEMENTED IN THIS CLASS IS EXPERIMENTAL AND 27 // SUBJECT TO CHANGE WITHOUT WARNING. 28 29 #ifndef KML_DOM_VISITOR_H__ 30 #define KML_DOM_VISITOR_H__ 31 32 #include <vector> 33 #include "kml/base/util.h" 34 #include "kml/dom/kml_ptr.h" 35 36 namespace kmldom { 37 38 // A base class implementing a visitor for elements in a kml dom hierarchy. 39 // This class should be extended to implement specific visitors by overriding 40 // the approriate VisitXxx() methods. 41 // 42 // The Visitor base class will ensure that the expected visit methods are 43 // invoked even if the element being visited is a sub-type of the element for 44 // which VisitXxx() was overridden. For example, if VisitContainer() is 45 // overridden by a subclass then it will be called for any Container elements 46 // visited, such as Document or Folder. 47 // 48 // If you wish to visit an element for several types (for example Container and 49 // Feature) using a single visitor, the sub-type visit methods should invoke 50 // their parent class method: 51 // 52 // void MyVisitor::VisitContainer(const ContainerPtr& container) { 53 // // do stuff 54 // Visitor::VisitContainer(container); // calls VisitFeature() 55 // } 56 // 57 // A visitation over an element hierarchy is controlled by a VisitorDriver 58 // instance. The choice of driver can affect the order in which elements are 59 // visited and it is up to the user to select an appropriate driver for their 60 // needs. A visitor has no requirement to manage the visitation of its child 61 // elements as this is handled by the chosen driver, although a visitor is free 62 // to operate on its child elements directly if it so chooses. 63 // 64 // In typical usage processing an element hierarchy might look something like: 65 // 66 // const KmlPtr& root = GetRootElement(); 67 // MyVisitor visitor(); 68 // SimplePreorderDriver(visitor).Visit(root); 69 // ProcessResults(visitor.GetResults()); 70 // 71 class Visitor { 72 protected: 73 Visitor(); 74 75 public: 76 virtual ~Visitor(); 77 78 virtual void VisitElement(const ElementPtr& node); 79 80 virtual void VisitAbstractLatLonBox( 81 const AbstractLatLonBoxPtr& element); 82 83 virtual void VisitAbstractLink( 84 const AbstractLinkPtr& element); 85 86 virtual void VisitAbstractView( 87 const AbstractViewPtr& element); 88 89 virtual void VisitAlias( 90 const AliasPtr& element); 91 92 virtual void VisitBalloonStyle( 93 const BalloonStylePtr& element); 94 95 virtual void VisitBasicLink( 96 const BasicLinkPtr& element); 97 98 virtual void VisitCamera( 99 const CameraPtr& element); 100 101 virtual void VisitChange( 102 const ChangePtr& element); 103 104 virtual void VisitColorStyle( 105 const ColorStylePtr& element); 106 107 virtual void VisitContainer( 108 const ContainerPtr& element); 109 110 virtual void VisitCoordinates( 111 const CoordinatesPtr& element); 112 113 virtual void VisitCreate( 114 const CreatePtr& element); 115 116 virtual void VisitData( 117 const DataPtr& element); 118 119 virtual void VisitDelete( 120 const DeletePtr& element); 121 122 virtual void VisitDocument( 123 const DocumentPtr& element); 124 125 virtual void VisitExtendedData( 126 const ExtendedDataPtr& element); 127 128 virtual void VisitFeature( 129 const FeaturePtr& element); 130 131 virtual void VisitField( 132 const FieldPtr& element); 133 134 virtual void VisitFolder( 135 const FolderPtr& element); 136 137 virtual void VisitGeometry( 138 const GeometryPtr& element); 139 140 virtual void VisitGroundOverlay( 141 const GroundOverlayPtr& element); 142 143 virtual void VisitGxAnimatedUpdate( 144 const GxAnimatedUpdatePtr& element); 145 146 virtual void VisitGxFlyTo( 147 const GxFlyToPtr& element); 148 149 virtual void VisitGxLatLonQuad( 150 const GxLatLonQuadPtr& element); 151 152 virtual void VisitGxMultiTrack( 153 const GxMultiTrackPtr& element); 154 155 virtual void VisitGxPlaylist( 156 const GxPlaylistPtr& element); 157 158 virtual void VisitGxSimpleArrayData( 159 const GxSimpleArrayDataPtr& element); 160 161 virtual void VisitGxSimpleArrayField( 162 const GxSimpleArrayFieldPtr& element); 163 164 virtual void VisitGxSoundCue( 165 const GxSoundCuePtr& element); 166 167 virtual void VisitGxTimeSpan( 168 const GxTimeSpanPtr& element); 169 170 virtual void VisitGxTimeStamp( 171 const GxTimeStampPtr& element); 172 173 virtual void VisitGxTour( 174 const GxTourPtr& element); 175 176 virtual void VisitGxTourControl( 177 const GxTourControlPtr& element); 178 179 virtual void VisitGxTourPrimitive( 180 const GxTourPrimitivePtr& element); 181 182 virtual void VisitGxTrack( 183 const GxTrackPtr& element); 184 185 virtual void VisitGxWait( 186 const GxWaitPtr& element); 187 188 virtual void VisitHotSpot( 189 const HotSpotPtr& element); 190 191 virtual void VisitIcon( 192 const IconPtr& element); 193 194 virtual void VisitIconStyle( 195 const IconStylePtr& element); 196 197 virtual void VisitIconStyleIcon( 198 const IconStyleIconPtr& element); 199 200 virtual void VisitImagePyramid( 201 const ImagePyramidPtr& element); 202 203 virtual void VisitInnerBoundaryIs( 204 const InnerBoundaryIsPtr& element); 205 206 virtual void VisitItemIcon( 207 const ItemIconPtr& element); 208 209 virtual void VisitKml( 210 const KmlPtr& element); 211 212 virtual void VisitLabelStyle( 213 const LabelStylePtr& element); 214 215 virtual void VisitLatLonAltBox( 216 const LatLonAltBoxPtr& element); 217 218 virtual void VisitLatLonBox( 219 const LatLonBoxPtr& element); 220 221 virtual void VisitLineString( 222 const LineStringPtr& element); 223 224 virtual void VisitLineStyle( 225 const LineStylePtr& element); 226 227 virtual void VisitLinearRing( 228 const LinearRingPtr& element); 229 230 virtual void VisitLink( 231 const LinkPtr& element); 232 233 virtual void VisitLinkSnippet( 234 const LinkSnippetPtr& element); 235 236 virtual void VisitListStyle( 237 const ListStylePtr& element); 238 239 virtual void VisitLocation( 240 const LocationPtr& element); 241 242 virtual void VisitLod( 243 const LodPtr& element); 244 245 virtual void VisitLookAt( 246 const LookAtPtr& element); 247 248 virtual void VisitMetadata( 249 const MetadataPtr& element); 250 251 virtual void VisitModel( 252 const ModelPtr& element); 253 254 virtual void VisitMultiGeometry( 255 const MultiGeometryPtr& element); 256 257 virtual void VisitNetworkLink( 258 const NetworkLinkPtr& element); 259 260 virtual void VisitNetworkLinkControl( 261 const NetworkLinkControlPtr& element); 262 263 virtual void VisitObject( 264 const ObjectPtr& element); 265 266 virtual void VisitOrientation( 267 const OrientationPtr& element); 268 269 virtual void VisitOuterBoundaryIs( 270 const OuterBoundaryIsPtr& element); 271 272 virtual void VisitOverlay( 273 const OverlayPtr& element); 274 275 virtual void VisitOverlayXY( 276 const OverlayXYPtr& element); 277 278 virtual void VisitPair( 279 const PairPtr& element); 280 281 virtual void VisitPhotoOverlay( 282 const PhotoOverlayPtr& element); 283 284 virtual void VisitPlacemark( 285 const PlacemarkPtr& element); 286 287 virtual void VisitPoint( 288 const PointPtr& element); 289 290 virtual void VisitPolyStyle( 291 const PolyStylePtr& element); 292 293 virtual void VisitPolygon( 294 const PolygonPtr& element); 295 296 virtual void VisitRegion( 297 const RegionPtr& element); 298 299 virtual void VisitResourceMap( 300 const ResourceMapPtr& element); 301 302 virtual void VisitRotationXY( 303 const RotationXYPtr& element); 304 305 virtual void VisitScale( 306 const ScalePtr& element); 307 308 virtual void VisitSchema( 309 const SchemaPtr& element); 310 311 virtual void VisitSchemaData( 312 const SchemaDataPtr& element); 313 314 virtual void VisitScreenOverlay( 315 const ScreenOverlayPtr& element); 316 317 virtual void VisitScreenXY( 318 const ScreenXYPtr& element); 319 320 virtual void VisitSimpleData( 321 const SimpleDataPtr& element); 322 323 virtual void VisitSimpleField( 324 const SimpleFieldPtr& element); 325 326 virtual void VisitSize( 327 const SizePtr& element); 328 329 virtual void VisitSnippet( 330 const SnippetPtr& element); 331 332 virtual void VisitStyle( 333 const StylePtr& element); 334 335 virtual void VisitStyleMap( 336 const StyleMapPtr& element); 337 338 virtual void VisitStyleSelector( 339 const StyleSelectorPtr& element); 340 341 virtual void VisitSubStyle( 342 const SubStylePtr& element); 343 344 virtual void VisitTimePrimitive( 345 const TimePrimitivePtr& element); 346 347 virtual void VisitTimeSpan( 348 const TimeSpanPtr& element); 349 350 virtual void VisitTimeStamp( 351 const TimeStampPtr& element); 352 353 virtual void VisitUpdate( 354 const UpdatePtr& element); 355 356 virtual void VisitUpdateOperation( 357 const UpdateOperationPtr& element); 358 359 virtual void VisitUrl( 360 const UrlPtr& element); 361 362 virtual void VisitVec2( 363 const Vec2Ptr& element); 364 365 virtual void VisitViewVolume( 366 const ViewVolumePtr& element); 367 368 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Visitor); 369 }; 370 371 } // end namespace kmldom 372 373 #endif // KML_DOM_VISITOR_H__ 374