Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svgio/inc/svgdocument.hxx
Line
Count
Source
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
#pragma once
21
22
#include "svgnode.hxx"
23
#include <memory>
24
#include <unordered_map>
25
#include <vector>
26
27
namespace svgio::svgreader
28
    {
29
        typedef std::vector< std::unique_ptr<SvgNode> > SvgNodeVector;
30
31
        class SvgDocument
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* > IdTokenMapper;
42
            IdTokenMapper           maIdTokenMapperList;
43
44
            /// hash mapper to find css styles by their id
45
            typedef std::unordered_map< OUString, const SvgStyleAttributes* > IdStyleTokenMapper;
46
            IdStyleTokenMapper      maIdStyleTokenMapperList;
47
48
        public:
49
            explicit SvgDocument(OUString aAbsolutePath);
50
            ~SvgDocument();
51
52
            SvgDocument(const SvgDocument&) = delete;
53
            SvgDocument& operator=(const SvgDocument&) = delete;
54
55
            /// append another root node, ownership changes
56
            void appendNode(std::unique_ptr<SvgNode> pNode);
57
58
            /// add/remove nodes with Id to mapper
59
            void addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode);
60
            void removeSvgNodeFromMapper(const OUString& rStr);
61
62
            /// find a node by its Id
63
            const SvgNode* findSvgNodeById(const OUString& rStr) const;
64
65
            /// add/remove styles to mapper
66
            void addSvgStyleAttributesToMapper(const OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes);
67
68
            /// find a style by its Id
69
198
            bool hasGlobalCssStyleAttributes() const { return !maIdStyleTokenMapperList.empty(); }
70
            const SvgStyleAttributes* findGlobalCssStyleAttributes(const OUString& rStr) const;
71
72
            /// data read access
73
23.8k
            const SvgNodeVector& getSvgNodeVector() const { return maNodes; }
74
0
            const OUString& getAbsolutePath() const { return maAbsolutePath; }
75
        };
76
77
} // end of namespace svgio::svgreader
78
79
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */