Branch data TLA Line data Source code
1 : : // Copyright (c) 2014-2022 Thomas Fussell
2 : : // Copyright (c) 2024-2025 xlnt-community
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, ARISING 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 : : #include <xlnt/cell/cell.hpp>
26 : : #include <xlnt/worksheet/cell_iterator.hpp>
27 : : #include <xlnt/worksheet/cell_vector.hpp>
28 : :
29 : : namespace xlnt {
30 : :
31 :CBC 546 : cell_vector::cell_vector(worksheet ws, const cell_reference &cursor,
32 : 546 : const range_reference &bounds, major_order order, bool skip_null, bool wrap)
33 : 546 : : ws_(ws),
34 : 546 : cursor_(cursor),
35 : 546 : bounds_(bounds),
36 : 546 : order_(order),
37 : 546 : skip_null_(skip_null),
38 : 546 : wrap_(wrap)
39 : : {
40 : 546 : }
41 : :
42 : 221 : cell_vector::iterator cell_vector::begin()
43 : : {
44 [ + + ]: 221 : return iterator(ws_, cursor_, bounds_, order_, skip_null_, wrap_);
45 : : }
46 : :
47 : 213 : cell_vector::iterator cell_vector::end()
48 : : {
49 : 213 : auto past_end = cursor_;
50 : :
51 [ + + ]: 213 : if (order_ == major_order::row)
52 : : {
53 [ + + + + ]: 202 : past_end.column_index(bounds_.bottom_right().column_index() + 1);
54 : : }
55 : : else
56 : : {
57 [ + + + ]: 11 : past_end.row(bounds_.bottom_right().row() + 1);
58 : : }
59 : :
60 [ + + ]: 213 : return iterator(ws_, past_end, bounds_, order_, skip_null_, wrap_);
61 : : }
62 : :
63 : 292 : cell_vector::const_iterator cell_vector::cbegin() const
64 : : {
65 [ + + ]: 292 : return const_iterator(ws_, cursor_, bounds_, order_, skip_null_, wrap_);
66 : : }
67 : :
68 : 276 : cell_vector::const_iterator cell_vector::cend() const
69 : : {
70 : 276 : auto past_end = cursor_;
71 : :
72 [ + + ]: 276 : if (order_ == major_order::row)
73 : : {
74 [ + + + + ]: 212 : past_end.column_index(bounds_.bottom_right().column_index() + 1);
75 : : }
76 : : else
77 : : {
78 [ + + + ]: 64 : past_end.row(bounds_.bottom_right().row() + 1);
79 : : }
80 : :
81 [ + + ]: 276 : return const_iterator(ws_, past_end, bounds_, order_, skip_null_, wrap_);
82 : : }
83 : :
84 : 262 : bool cell_vector::empty() const
85 : : {
86 [ + + + ]: 262 : return begin() == end();
87 : : }
88 : :
89 : 2 : cell cell_vector::front()
90 : : {
91 [ + + ]: 2 : return *begin();
92 : : }
93 : :
94 : 1 : const cell cell_vector::front() const
95 : : {
96 [ + + ]: 1 : return *cbegin();
97 : : }
98 : :
99 : 6 : cell cell_vector::back()
100 : : {
101 [ + + + ]: 6 : return *(--end());
102 : : }
103 : :
104 : 1 : const cell cell_vector::back() const
105 : : {
106 [ + + + ]: 1 : return *(--cend());
107 : : }
108 : :
109 : 5 : std::size_t cell_vector::length() const
110 : : {
111 [ + + ]: 5 : return order_ == major_order::row ? bounds_.width() : bounds_.height();
112 : : }
113 : :
114 : 268 : cell_vector::const_iterator cell_vector::begin() const
115 : : {
116 : 268 : return cbegin();
117 : : }
118 : 268 : cell_vector::const_iterator cell_vector::end() const
119 : : {
120 : 268 : return cend();
121 : : }
122 : :
123 : 4 : cell_vector::reverse_iterator cell_vector::rbegin()
124 : : {
125 [ + + ]: 4 : return reverse_iterator(end());
126 : : }
127 : :
128 : 10 : cell_vector::reverse_iterator cell_vector::rend()
129 : : {
130 [ + + ]: 10 : return reverse_iterator(begin());
131 : : }
132 : :
133 : 7 : cell_vector::const_reverse_iterator cell_vector::crbegin() const
134 : : {
135 [ + + ]: 7 : return const_reverse_iterator(cend());
136 : : }
137 : :
138 : 3 : cell_vector::const_reverse_iterator cell_vector::rbegin() const
139 : : {
140 : 3 : return crbegin();
141 : : }
142 : :
143 : 19 : cell_vector::const_reverse_iterator cell_vector::crend() const
144 : : {
145 [ + + ]: 19 : return const_reverse_iterator(cbegin());
146 : : }
147 : :
148 : 9 : cell_vector::const_reverse_iterator cell_vector::rend() const
149 : : {
150 : 9 : return crend();
151 : : }
152 : :
153 : 38 : cell cell_vector::operator[](std::size_t cell_index)
154 : : {
155 [ + + ]: 38 : if (order_ == major_order::row)
156 : : {
157 [ + + ]: 33 : return ws_.cell(cursor_.make_offset(static_cast<int>(cell_index), 0));
158 : : }
159 : :
160 [ + + ]: 5 : return ws_.cell(cursor_.make_offset(0, static_cast<int>(cell_index)));
161 : : }
162 : :
163 :UBC 0 : const cell cell_vector::operator[](std::size_t cell_index) const
164 : : {
165 [ # # ]: 0 : if (order_ == major_order::row)
166 : : {
167 [ # # ]: 0 : return ws_.cell(cursor_.make_offset(static_cast<int>(cell_index), 0));
168 : : }
169 : :
170 [ # # ]: 0 : return ws_.cell(cursor_.make_offset(0, static_cast<int>(cell_index)));
171 : : }
172 : :
173 : : } // namespace xlnt
|