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 // This file contains the declaration of the internal StyleInliner class.
27 
28 #ifndef KML_ENGINE_STYLE_INLINER_INTERNAL_H__
29 #define KML_ENGINE_STYLE_INLINER_INTERNAL_H__
30 
31 #include "kml/base/string_util.h"
32 #include "kml/dom.h"
33 #include "kml/engine/engine_types.h"
34 
35 namespace kmlengine {
36 
37 // This class inlines _most_ shared StyleSelectors into each Feature.
38 // NOTE: Direct use of this class in production code is not recommended.
39 // Use the InlineStyles function declared above.
40 class StyleInliner : public kmldom::ParserObserver {
41  public:
42   StyleInliner();
43 
~StyleInliner()44   virtual ~StyleInliner() {}
45 
46   // ParserObserver::NewElement()
47   virtual bool NewElement(const kmldom::ElementPtr& element);
48 
49   // Like AsFeature(), but not if the feature is a <Document>.
50   static kmldom::FeaturePtr AsNonDocumentFeature(
51       const kmldom::ElementPtr& element);
52 
53   // ParserObserver::EndElement()
54   virtual bool EndElement(const kmldom::ElementPtr& parent,
55                           const kmldom::ElementPtr& child);
56 
57   // ParserObserver::AddChild()
58   virtual bool AddChild(const kmldom::ElementPtr& parent,
59                         const kmldom::ElementPtr& child);
60 
61   // Mostly for debugging, but no reason to hide these.
get_document()62   const kmldom::DocumentPtr& get_document() const {
63     return document_;
64   }
65 
in_update()66   bool in_update() const {
67     return in_update_;
68   }
69 
70   // All shared styles are added to this map _instead_ of their <Document>
71   // parent.  Any duplicate id's are handled in a "last one wins" fashion.
get_shared_styles()72   const kmlengine::SharedStyleMap& get_shared_styles() const {
73     return shared_styles_;
74   }
75 
76  private:
77   kmlengine::SharedStyleMap shared_styles_;
78   kmldom::DocumentPtr document_;
79   bool in_update_;
80 };
81 
82 }  // end namespace kmlengine
83 
84 #endif  // KML_ENGINE_STYLE_INLINER_INTERNAL_H__
85