LibreOffice Module svgio (master) 1
svgdocument.hxx
Go to the documentation of this file.
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
27namespace svgio::svgreader
28 {
29 typedef std::vector< std::unique_ptr<SvgNode> > SvgNodeVector;
30
32 {
33 private:
36
39
41 const OUString maAbsolutePath;
42
44 typedef std::unordered_map< OUString, const SvgNode* > IdTokenMapper;
46
48 typedef std::unordered_map< OUString, const SvgStyleAttributes* > IdStyleTokenMapper;
50
51 public:
52 explicit SvgDocument(OUString aAbsolutePath);
54
55 SvgDocument(const SvgDocument&) = delete;
57
59 void appendNode(std::unique_ptr<SvgNode> pNode);
60
62 void addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode);
63 void removeSvgNodeFromMapper(const OUString& rStr);
64
66 const SvgNode* findSvgNodeById(const OUString& rStr) const;
67
69 void addSvgStyleAttributesToMapper(const OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes);
70
72 bool hasGlobalCssStyleAttributes() const { return !maIdStyleTokenMapperList.empty(); }
73 const SvgStyleAttributes* findGlobalCssStyleAttributes(const OUString& rStr) const;
74
76 const SvgNodeVector& getSvgNodeVector() const { return maNodes; }
77 const OUString& getAbsolutePath() const { return maAbsolutePath; }
78
80 void addOrphanNode(SvgNode* pOrphan) { maOrphanNodes.emplace_back(pOrphan); }
81 };
82
83} // end of namespace svgio::svgreader
84
85/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void removeSvgNodeFromMapper(const OUString &rStr)
Definition: svgdocument.cxx:48
void addSvgNodeToMapper(const OUString &rStr, const SvgNode &rNode)
add/remove nodes with Id to mapper
Definition: svgdocument.cxx:40
SvgDocument & operator=(const SvgDocument &)=delete
std::unordered_map< OUString, const SvgNode * > IdTokenMapper
hash mapper to find nodes by their id
Definition: svgdocument.hxx:44
const OUString & getAbsolutePath() const
Definition: svgdocument.hxx:77
std::unordered_map< OUString, const SvgStyleAttributes * > IdStyleTokenMapper
hash mapper to find css styles by their id
Definition: svgdocument.hxx:48
const SvgStyleAttributes * findGlobalCssStyleAttributes(const OUString &rStr) const
Definition: svgdocument.cxx:78
void appendNode(std::unique_ptr< SvgNode > pNode)
append another root node, ownership changes
Definition: svgdocument.cxx:34
SvgNodeVector maOrphanNodes
invalid nodes that have no parent
Definition: svgdocument.hxx:38
const OUString maAbsolutePath
the absolute path of the Svg file in progress (if available)
Definition: svgdocument.hxx:41
SvgDocument(OUString aAbsolutePath)
Definition: svgdocument.cxx:25
const SvgNode * findSvgNodeById(const OUString &rStr) const
find a node by its Id
Definition: svgdocument.cxx:56
void addOrphanNode(SvgNode *pOrphan)
invalid nodes that have no parent
Definition: svgdocument.hxx:80
SvgNodeVector maNodes
the document hierarchy with all root nodes
Definition: svgdocument.hxx:35
SvgDocument(const SvgDocument &)=delete
void addSvgStyleAttributesToMapper(const OUString &rStr, const SvgStyleAttributes &rSvgStyleAttributes)
add/remove styles to mapper
Definition: svgdocument.cxx:70
IdStyleTokenMapper maIdStyleTokenMapperList
Definition: svgdocument.hxx:49
bool hasGlobalCssStyleAttributes() const
find a style by its Id
Definition: svgdocument.hxx:72
const SvgNodeVector & getSvgNodeVector() const
data read access
Definition: svgdocument.hxx:76
std::vector< std::unique_ptr< SvgNode > > SvgNodeVector
Definition: svgdocument.hxx:29