1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "svgnode.hxx"
24 #include <unordered_map>
27 namespace svgio::svgreader
29 typedef std::vector
< std::unique_ptr
<SvgNode
> > SvgNodeVector
;
34 /// the document hierarchy with all root nodes
35 SvgNodeVector maNodes
;
37 /// the absolute path of the Svg file in progress (if available)
38 const OUString maAbsolutePath
;
40 /// hash mapper to find nodes by their id
41 typedef std::unordered_map
< OUString
, const SvgNode
* > IdTokenMapper
;
42 IdTokenMapper maIdTokenMapperList
;
44 /// hash mapper to find css styles by their id
45 typedef std::unordered_map
< OUString
, const SvgStyleAttributes
* > IdStyleTokenMapper
;
46 IdStyleTokenMapper maIdStyleTokenMapperList
;
49 explicit SvgDocument(OUString aAbsolutePath
);
52 SvgDocument(const SvgDocument
&) = delete;
53 SvgDocument
& operator=(const SvgDocument
&) = delete;
55 /// append another root node, ownership changes
56 void appendNode(std::unique_ptr
<SvgNode
> pNode
);
58 /// add/remove nodes with Id to mapper
59 void addSvgNodeToMapper(const OUString
& rStr
, const SvgNode
& rNode
);
60 void removeSvgNodeFromMapper(const OUString
& rStr
);
62 /// find a node by its Id
63 const SvgNode
* findSvgNodeById(const OUString
& rStr
) const;
65 /// add/remove styles to mapper
66 void addSvgStyleAttributesToMapper(const OUString
& rStr
, const SvgStyleAttributes
& rSvgStyleAttributes
);
68 /// find a style by its Id
69 bool hasGlobalCssStyleAttributes() const { return !maIdStyleTokenMapperList
.empty(); }
70 const SvgStyleAttributes
* findGlobalCssStyleAttributes(const OUString
& rStr
) const;
73 const SvgNodeVector
& getSvgNodeVector() const { return maNodes
; }
74 const OUString
& getAbsolutePath() const { return maAbsolutePath
; }
77 } // end of namespace svgio::svgreader
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */