1 // Copyright (c) 2014-2020 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE
21 //
22 // @license: http://www.opensource.org/licenses/mit-license.php
23 // @author: see AUTHORS file
24 
25 #pragma once
26 
27 #include <string>
28 
29 #include <xlnt/xlnt_config.hpp>
30 #include <xlnt/packaging/uri.hpp>
31 #include <xlnt/utils/path.hpp>
32 
33 namespace xlnt {
34 
35 /// <summary>
36 /// Specifies whether the target of a relationship is inside or outside the Package.
37 /// </summary>
38 enum class XLNT_API target_mode
39 {
40     /// <summary>
41     /// The relationship references a resource that is external to the package.
42     /// </summary>
43     internal,
44     /// <summary>
45     /// The relationship references a part that is inside the package.
46     /// </summary>
47     external
48 };
49 
50 /// <summary>
51 /// All package relationships must be one of these defined types.
52 /// </summary>
53 enum class XLNT_API relationship_type
54 {
55     unknown,
56 
57     // Package parts
58     core_properties,
59     extended_properties,
60     custom_properties,
61     office_document,
62     thumbnail,
63     printer_settings,
64 
65     // SpreadsheetML parts
66     calculation_chain,
67     chartsheet,
68     comments,
69     connections,
70     custom_property,
71     custom_xml_mappings,
72     dialogsheet,
73     drawings,
74     external_workbook_references,
75     pivot_table,
76     pivot_table_cache_definition,
77     pivot_table_cache_records,
78     query_table,
79     shared_string_table,
80     shared_workbook_revision_headers,
81     shared_workbook,
82     theme,
83     revision_log,
84     shared_workbook_user_data,
85     single_cell_table_definitions,
86     stylesheet,
87     table_definition,
88     vml_drawing,
89     volatile_dependencies,
90     worksheet,
91 
92     // Worksheet parts
93     hyperlink,
94     image
95 };
96 
97 /// <summary>
98 /// Represents an association between a source Package or part, and a target object which can be a part or external
99 /// resource.
100 /// </summary>
101 class XLNT_API relationship
102 {
103 public:
104     /// <summary>
105     /// Constructs a new empty relationship.
106     /// </summary>
107     relationship();
108 
109     /// <summary>
110     /// Constructs a new relationship by specifying all of its properties.
111     /// </summary>
112     relationship(const std::string &id, relationship_type t, const uri &source,
113         const uri &target, xlnt::target_mode mode);
114 
115     /// <summary>
116     /// Returns a string of the form rId# that identifies the relationship.
117     /// </summary>
118     const std::string &id() const;
119 
120     /// <summary>
121     /// Returns the type of this relationship.
122     /// </summary>
123     relationship_type type() const;
124 
125     /// <summary>
126     /// Returns whether the target of the relationship is internal or external to the package.
127     /// </summary>
128     xlnt::target_mode target_mode() const;
129 
130     /// <summary>
131     /// Returns the URI of the package part this relationship points to.
132     /// </summary>
133     const uri &source() const;
134 
135     /// <summary>
136     /// Returns the URI of the package part this relationship points to.
137     /// </summary>
138     const uri &target() const;
139 
140     /// <summary>
141     /// Returns true if and only if rhs is equal to this relationship.
142     /// </summary>
143     bool operator==(const relationship &rhs) const;
144 
145     /// <summary>
146     /// Returns true if and only if rhs is not equal to this relationship.
147     /// </summary>
148     bool operator!=(const relationship &rhs) const;
149 
150 private:
151     /// <summary>
152     /// The id of this relationship in the format "rId#"
153     /// </summary>
154     std::string id_;
155 
156     /// <summary>
157     /// The type of this relationship.
158     /// </summary>
159     relationship_type type_;
160 
161     /// <summary>
162     /// The URI of the source of this relationship.
163     /// </summary>
164     uri source_;
165 
166     /// <summary>
167     /// The URI of the target of this relationshp.
168     /// </summary>
169     uri target_;
170 
171     /// <summary>
172     /// Whether the target of this relationship is internal or external.
173     /// </summary>
174     xlnt::target_mode mode_;
175 };
176 
177 } // namespace xlnt
178