Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGDOCUMENT_HXX
21 : #define INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGDOCUMENT_HXX
22 :
23 : #include <boost/utility.hpp>
24 : #include <svgio/svgreader/svgnode.hxx>
25 : #include <unordered_map>
26 :
27 : namespace svgio
28 : {
29 : namespace svgreader
30 : {
31 : class SvgDocument : private boost::noncopyable
32 : {
33 : private:
34 : /// the document hierarchy with all root nodes
35 : SvgNodeVector maNodes;
36 :
37 : /// the absolute path of the Svg file in progress (if available)
38 : const OUString maAbsolutePath;
39 :
40 : /// hash mapper to find nodes by their id
41 : typedef std::unordered_map< OUString, const SvgNode*,
42 : OUStringHash,
43 : ::std::equal_to< OUString > > IdTokenMapper;
44 : typedef std::pair< const OUString, const SvgNode* > IdTokenValueType;
45 : IdTokenMapper maIdTokenMapperList;
46 :
47 : /// hash mapper to find css styles by their id
48 : typedef std::unordered_map< OUString, const SvgStyleAttributes*, OUStringHash, ::std::equal_to< OUString > > IdStyleTokenMapper;
49 : typedef std::pair< const OUString, const SvgStyleAttributes* > IdStyleTokenValueType;
50 : IdStyleTokenMapper maIdStyleTokenMapperList;
51 :
52 : public:
53 : SvgDocument(const OUString& rAbsolutePath);
54 : ~SvgDocument();
55 :
56 : /// append another root node, ownership changes
57 : void appendNode(SvgNode* pNode);
58 :
59 : /// add/remove nodes with Id to mapper
60 : void addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode);
61 : void removeSvgNodeFromMapper(const OUString& rStr);
62 :
63 : /// find a node by its Id
64 : bool hasSvgNodesById() const { return !maIdTokenMapperList.empty(); }
65 : const SvgNode* findSvgNodeById(const OUString& rStr) const;
66 :
67 : /// add/remove styles to mapper
68 : void addSvgStyleAttributesToMapper(const OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes);
69 :
70 : /// find a style by its Id
71 10060 : bool hasGlobalCssStyleAttributes() const { return !maIdStyleTokenMapperList.empty(); }
72 : const SvgStyleAttributes* findGlobalCssStyleAttributes(const OUString& rStr) const;
73 :
74 : /// data read access
75 299 : const SvgNodeVector& getSvgNodeVector() const { return maNodes; }
76 0 : const OUString& getAbsolutePath() const { return maAbsolutePath; }
77 : };
78 : } // end of namespace svgreader
79 : } // end of namespace svgio
80 :
81 : #endif // INCLUDED_SVGIO_INC_SVGIO_SVGREADER_SVGDOCUMENT_HXX
82 :
83 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|