1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef INCLUDED_SVGIO_SVGREADER_SVGDOCUMENT_HXX
23 #define INCLUDED_SVGIO_SVGREADER_SVGDOCUMENT_HXX
24 
25 #include <svgio/svgiodllapi.h>
26 #include <boost/utility.hpp>
27 #include <svgio/svgreader/svgnode.hxx>
28 
29 //////////////////////////////////////////////////////////////////////////////
30 
31 namespace svgio
32 {
33     namespace svgreader
34     {
35         class SvgDocument : private boost::noncopyable
36         {
37         private:
38             /// the document hierarchy with all root nodes
39             SvgNodeVector           maNodes;
40 
41             /// the absolute path of the Svg file in progress (if available)
42             const rtl::OUString     maAbsolutePath;
43 
44             /// hash mapper to find nodes by their id
45             typedef std::hash_map< const rtl::OUString, const SvgNode*, rtl::OUStringHash > IdTokenMapper;
46             typedef std::pair< const rtl::OUString, const SvgNode* > IdTokenValueType;
47             IdTokenMapper           maIdTokenMapperList;
48 
49             /// hash mapper to find css styles by their id
50             typedef std::hash_map< const rtl::OUString, const SvgStyleAttributes*, rtl::OUStringHash > IdStyleTokenMapper;
51             typedef std::pair< const rtl::OUString, const SvgStyleAttributes* > IdStyleTokenValueType;
52             IdStyleTokenMapper      maIdStyleTokenMapperList;
53 
54         public:
55             SvgDocument(const rtl::OUString& rAbsolutePath);
56             ~SvgDocument();
57 
58             /// append anopther root node, ownership changes
59             void appendNode(SvgNode* pNode);
60 
61             /// add/remove nodes with Id to mapper
62             void addSvgNodeToMapper(const rtl::OUString& rStr, const SvgNode& rNode);
63             void removeSvgNodeFromMapper(const rtl::OUString& rStr);
64 
65             /// find a node by it's Id
hasSvgNodesById() const66             bool hasSvgNodesById() const { return !maIdTokenMapperList.empty(); }
67             const SvgNode* findSvgNodeById(const rtl::OUString& rStr) const;
68 
69             /// add/remove styles to mapper
70             void addSvgStyleAttributesToMapper(const rtl::OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes);
71             void removeSvgStyleAttributesFromMapper(const rtl::OUString& rStr);
72 
73             /// find a style by it's Id
hasSvgStyleAttributesById() const74             bool hasSvgStyleAttributesById() const { return !maIdStyleTokenMapperList.empty(); }
75             const SvgStyleAttributes* findSvgStyleAttributesById(const rtl::OUString& rStr) const;
76 
77             /// data read access
getSvgNodeVector() const78             const SvgNodeVector& getSvgNodeVector() const { return maNodes; }
getAbsolutePath() const79             const rtl::OUString& getAbsolutePath() const { return maAbsolutePath; }
80         };
81     } // end of namespace svgreader
82 } // end of namespace svgio
83 
84 //////////////////////////////////////////////////////////////////////////////
85 
86 #endif //INCLUDED_SVGIO_SVGREADER_SVGDOCUMENT_HXX
87 
88 // eof
89