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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_svgio.hxx"
24 
25 #include <svgio/svgreader/svgdocument.hxx>
26 
27 //////////////////////////////////////////////////////////////////////////////
28 
29 namespace svgio
30 {
31     namespace svgreader
32     {
SvgDocument(const rtl::OUString & rAbsolutePath)33         SvgDocument::SvgDocument(const rtl::OUString& rAbsolutePath)
34         :   maNodes(),
35             maAbsolutePath(rAbsolutePath),
36             maIdTokenMapperList(),
37             maIdStyleTokenMapperList()
38         {
39         }
40 
~SvgDocument()41         SvgDocument::~SvgDocument()
42         {
43             while(!maNodes.empty())
44             {
45                 SvgNode* pCandidate = maNodes[maNodes.size() - 1];
46                 delete pCandidate;
47                 maNodes.pop_back();
48             }
49         }
50 
appendNode(SvgNode * pNode)51         void SvgDocument::appendNode(SvgNode* pNode)
52         {
53             OSL_ENSURE(pNode, "OOps, empty node added (!)");
54             maNodes.push_back(pNode);
55         }
56 
addSvgNodeToMapper(const rtl::OUString & rStr,const SvgNode & rNode)57         void SvgDocument::addSvgNodeToMapper(const rtl::OUString& rStr, const SvgNode& rNode)
58         {
59             if(rStr.getLength())
60             {
61                 maIdTokenMapperList.insert(IdTokenValueType(rStr, &rNode));
62             }
63         }
64 
removeSvgNodeFromMapper(const rtl::OUString & rStr)65         void SvgDocument::removeSvgNodeFromMapper(const rtl::OUString& rStr)
66         {
67             if(rStr.getLength())
68             {
69                 maIdTokenMapperList.erase(rStr);
70             }
71         }
72 
findSvgNodeById(const rtl::OUString & rStr) const73         const SvgNode* SvgDocument::findSvgNodeById(const rtl::OUString& rStr) const
74         {
75             const IdTokenMapper::const_iterator aResult(maIdTokenMapperList.find(rStr));
76 
77             if(aResult == maIdTokenMapperList.end())
78             {
79                 return 0;
80             }
81             else
82             {
83                 return aResult->second;
84             }
85         }
86 
addSvgStyleAttributesToMapper(const rtl::OUString & rStr,const SvgStyleAttributes & rSvgStyleAttributes)87         void SvgDocument::addSvgStyleAttributesToMapper(const rtl::OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes)
88         {
89             if(rStr.getLength())
90             {
91                 maIdStyleTokenMapperList.insert(IdStyleTokenValueType(rStr, &rSvgStyleAttributes));
92             }
93         }
94 
removeSvgStyleAttributesFromMapper(const rtl::OUString & rStr)95         void SvgDocument::removeSvgStyleAttributesFromMapper(const rtl::OUString& rStr)
96         {
97             if(rStr.getLength())
98             {
99                 maIdStyleTokenMapperList.erase(rStr);
100             }
101         }
102 
findSvgStyleAttributesById(const rtl::OUString & rStr) const103         const SvgStyleAttributes* SvgDocument::findSvgStyleAttributesById(const rtl::OUString& rStr) const
104         {
105             const IdStyleTokenMapper::const_iterator aResult(maIdStyleTokenMapperList.find(rStr));
106 
107             if(aResult == maIdStyleTokenMapperList.end())
108             {
109                 return 0;
110             }
111             else
112             {
113                 return aResult->second;
114             }
115         }
116 
117     } // end of namespace svgreader
118 } // end of namespace svgio
119 
120 //////////////////////////////////////////////////////////////////////////////
121 // eof
122