GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/tree/LeafBuffer.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 106 115 92.2%
Functions: 319 453 70.4%
Branches: 361 1045 34.5%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #ifndef OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED
5 #define OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED
6
7 #include <openvdb/Types.h>
8 #include <openvdb/io/Compression.h> // for io::readCompressedValues(), etc
9 #include <openvdb/util/NodeMasks.h>
10 #include <tbb/spin_mutex.h>
11 #include <algorithm> // for std::swap
12 #include <atomic>
13 #include <cstddef> // for offsetof()
14 #include <iostream>
15 #include <memory>
16 #include <type_traits>
17
18
19 class TestLeaf;
20
21 namespace openvdb {
22 OPENVDB_USE_VERSION_NAMESPACE
23 namespace OPENVDB_VERSION_NAME {
24 namespace tree {
25
26
27 /// @brief Array of fixed size 2<SUP>3<I>Log2Dim</I></SUP> that stores
28 /// the voxel values of a LeafNode
29 template<typename T, Index Log2Dim>
30 class LeafBuffer
31 {
32 public:
33 using ValueType = T;
34 using StorageType = ValueType;
35 using NodeMaskType = util::NodeMask<Log2Dim>;
36 static const Index SIZE = 1 << 3 * Log2Dim;
37
38 struct FileInfo
39 {
40 22761 FileInfo(): bufpos(0) , maskpos(0) {}
41 std::streamoff bufpos;
42 std::streamoff maskpos;
43 io::MappedFile::Ptr mapping;
44 SharedPtr<io::StreamMetadata> meta;
45 };
46
47 /// Default constructor
48
2/2
✓ Branch 1 taken 39447040 times.
✓ Branch 2 taken 77031 times.
79096451 inline LeafBuffer(): mData(new ValueType[SIZE]) { mOutOfCore = 0; }
49 /// Construct a buffer populated with the specified value.
50 explicit inline LeafBuffer(const ValueType&);
51 /// Copy constructor
52 inline LeafBuffer(const LeafBuffer&);
53 /// Construct a buffer but don't allocate memory for the full array of values.
54
3/42
✓ Branch 0 taken 20924 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1780 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 370 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
30375 LeafBuffer(PartialCreate, const ValueType&): mData(nullptr) { mOutOfCore = 0; }
55 /// Destructor
56 inline ~LeafBuffer();
57
58 /// Return @c true if this buffer's values have not yet been read from disk.
59
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
4 bool isOutOfCore() const { return bool(mOutOfCore); }
60 /// Return @c true if memory for this buffer has not yet been allocated.
61
44/112
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 463 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 454 times.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 512 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 512 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 82370 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 82369 times.
✓ Branch 23 taken 1 times.
✓ Branch 24 taken 432 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 432 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 432 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 432 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 3 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 1 times.
✓ Branch 43 taken 2 times.
✓ Branch 44 taken 9 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 8 times.
✓ Branch 47 taken 1 times.
✓ Branch 48 taken 2415 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 9 times.
✓ Branch 51 taken 2406 times.
✓ Branch 52 taken 12670 times.
✓ Branch 53 taken 4 times.
✗ Branch 54 not taken.
✓ Branch 55 taken 12670 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 5 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 5 times.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 12168396 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 12168396 times.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✓ Branch 80 taken 5 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 5 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 520028182 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 520028182 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 7603100 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 7603100 times.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
539899023 bool empty() const { return !mData || this->isOutOfCore(); }
62 /// Allocate memory for this buffer if it has not already been allocated.
63
105/423
✓ Branch 0 taken 50153 times.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11115008 times.
✓ Branch 4 taken 21708 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1034 times.
✓ Branch 7 taken 306 times.
✓ Branch 8 taken 512 times.
✓ Branch 9 taken 262157 times.
✓ Branch 10 taken 512 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 19713 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 266463 times.
✓ Branch 16 taken 559 times.
✓ Branch 17 taken 2055 times.
✓ Branch 18 taken 1122 times.
✓ Branch 19 taken 512 times.
✓ Branch 20 taken 3584 times.
✓ Branch 21 taken 7 times.
✓ Branch 22 taken 587738 times.
✓ Branch 23 taken 91054 times.
✓ Branch 24 taken 512 times.
✓ Branch 25 taken 3595 times.
✓ Branch 26 taken 2130 times.
✓ Branch 27 taken 281874 times.
✓ Branch 28 taken 936 times.
✓ Branch 29 taken 513 times.
✓ Branch 30 taken 380 times.
✓ Branch 31 taken 2 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 5126 times.
✓ Branch 34 taken 523 times.
✓ Branch 35 taken 509 times.
✓ Branch 36 taken 6 times.
✓ Branch 37 taken 58 times.
✓ Branch 38 taken 5120 times.
✓ Branch 39 taken 5388 times.
✓ Branch 40 taken 310 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✓ Branch 43 taken 5120 times.
✓ Branch 44 taken 10 times.
✓ Branch 45 taken 7 times.
✓ Branch 46 taken 27778 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 3584 times.
✓ Branch 49 taken 7 times.
✓ Branch 50 taken 3095 times.
✓ Branch 51 taken 10 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 3590 times.
✓ Branch 54 taken 7 times.
✓ Branch 55 taken 520 times.
✓ Branch 56 taken 2030 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 3584 times.
✓ Branch 59 taken 1845 times.
✓ Branch 60 taken 14 times.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✓ Branch 63 taken 7168 times.
✓ Branch 64 taken 14 times.
✓ Branch 65 taken 8 times.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✓ Branch 68 taken 4096 times.
✓ Branch 69 taken 8 times.
✓ Branch 70 taken 8 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 2 times.
✓ Branch 73 taken 4096 times.
✓ Branch 74 taken 8 times.
✓ Branch 75 taken 8 times.
✓ Branch 76 taken 6684 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 4096 times.
✓ Branch 79 taken 8 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✓ Branch 84 taken 422 times.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✓ Branch 101 taken 99 times.
✗ Branch 102 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✓ Branch 111 taken 4 times.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✓ Branch 118 taken 1 times.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✓ Branch 133 taken 1 times.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✓ Branch 148 taken 1 times.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✓ Branch 157 taken 2 times.
✗ Branch 158 not taken.
✓ Branch 159 taken 512 times.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✓ Branch 163 taken 512 times.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✓ Branch 169 taken 513 times.
✓ Branch 170 taken 512 times.
✗ Branch 171 not taken.
✓ Branch 172 taken 2 times.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✓ Branch 179 taken 1 times.
✗ Branch 180 not taken.
✓ Branch 181 taken 1 times.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✓ Branch 188 taken 1 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 12 times.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✓ Branch 195 taken 16 times.
✗ Branch 196 not taken.
✓ Branch 197 taken 39677 times.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✓ Branch 200 taken 1 times.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✓ Branch 205 taken 45 times.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✓ Branch 214 taken 1 times.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✓ Branch 217 taken 700 times.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 237 not taken.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 252 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 255 not taken.
✗ Branch 256 not taken.
✗ Branch 257 not taken.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 261 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✗ Branch 264 not taken.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✗ Branch 267 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 270 not taken.
✗ Branch 271 not taken.
✗ Branch 272 not taken.
✗ Branch 273 not taken.
✗ Branch 274 not taken.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 291 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 297 not taken.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 306 not taken.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✓ Branch 310 taken 852 times.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 315 not taken.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 327 not taken.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 330 not taken.
✗ Branch 331 not taken.
✗ Branch 332 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 336 not taken.
✗ Branch 337 not taken.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✗ Branch 342 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 345 not taken.
✗ Branch 346 not taken.
✗ Branch 347 not taken.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✓ Branch 357 taken 96 times.
✗ Branch 359 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✓ Branch 362 taken 102 times.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✗ Branch 366 not taken.
✓ Branch 367 taken 100 times.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✓ Branch 372 taken 102 times.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✓ Branch 377 taken 114 times.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✓ Branch 382 taken 112 times.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✓ Branch 387 taken 114 times.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✓ Branch 392 taken 130 times.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✓ Branch 397 taken 188 times.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✓ Branch 402 taken 160 times.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✓ Branch 407 taken 98 times.
✗ Branch 409 not taken.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✓ Branch 412 taken 98 times.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✓ Branch 417 taken 98 times.
✗ Branch 418 not taken.
✗ Branch 419 not taken.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✓ Branch 422 taken 68 times.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✓ Branch 425 taken 352 times.
✗ Branch 427 not taken.
✓ Branch 428 taken 178 times.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 433 not taken.
✓ Branch 434 taken 356 times.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
23967297 bool allocate() { if (mData == nullptr) mData = new ValueType[SIZE]; return true; }
64
65 /// Populate this buffer with a constant value.
66 inline void fill(const ValueType&);
67
68 /// Return a const reference to the i'th element of this buffer.
69 2048 const ValueType& getValue(Index i) const { return this->at(i); }
70 /// Return a const reference to the i'th element of this buffer.
71
57/108
✓ Branch 1 taken 15834112 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1024 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1382400 times.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 6 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 4 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 1 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 3 times.
✓ Branch 32 taken 1 times.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
✓ Branch 36 taken 4 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 1 times.
✓ Branch 39 taken 1 times.
✓ Branch 40 taken 3 times.
✓ Branch 41 taken 1 times.
✓ Branch 42 taken 1 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✓ Branch 50 taken 1 times.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✓ Branch 53 taken 1 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 1 times.
✗ Branch 57 not taken.
✓ Branch 59 taken 1 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✓ Branch 62 taken 1 times.
✓ Branch 63 taken 1 times.
✗ Branch 64 not taken.
✓ Branch 65 taken 1 times.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 1 times.
✗ Branch 69 not taken.
✓ Branch 71 taken 1 times.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✓ Branch 74 taken 1 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 2303 times.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 4 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✓ Branch 84 taken 3 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 3 times.
✓ Branch 89 taken 1 times.
✗ Branch 90 not taken.
✓ Branch 92 taken 1 times.
✗ Branch 93 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✓ Branch 101 taken 1 times.
✗ Branch 102 not taken.
✓ Branch 104 taken 1 times.
✗ Branch 105 not taken.
✓ Branch 107 taken 1 times.
✗ Branch 108 not taken.
✓ Branch 110 taken 1 times.
✗ Branch 111 not taken.
✓ Branch 113 taken 1 times.
✗ Branch 114 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
✓ Branch 119 taken 1 times.
✗ Branch 120 not taken.
✓ Branch 122 taken 1 times.
✗ Branch 123 not taken.
✓ Branch 125 taken 1 times.
✗ Branch 126 not taken.
2273620028 const ValueType& operator[](Index i) const { return this->at(i); }
72 /// Set the i'th value of this buffer to the specified value.
73 inline void setValue(Index i, const ValueType&);
74
75 /// Copy the other buffer's values into this buffer.
76 inline LeafBuffer& operator=(const LeafBuffer&);
77
78 /// @brief Return @c true if the contents of the other buffer
79 /// exactly equal the contents of this buffer.
80 inline bool operator==(const LeafBuffer&) const;
81 /// @brief Return @c true if the contents of the other buffer
82 /// are not exactly equal to the contents of this buffer.
83
16/32
✓ Branch 1 taken 205 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 205 times.
✓ Branch 6 taken 205 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 205 times.
✓ Branch 11 taken 205 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 205 times.
✓ Branch 16 taken 205 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 205 times.
✓ Branch 21 taken 205 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 205 times.
✓ Branch 26 taken 205 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 205 times.
✓ Branch 31 taken 205 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 205 times.
✓ Branch 36 taken 205 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 205 times.
1640 inline bool operator!=(const LeafBuffer& other) const { return !(other == *this); }
84
85 /// Exchange this buffer's values with the other buffer's values.
86 inline void swap(LeafBuffer&);
87
88 /// Return the memory footprint of this buffer in bytes.
89 inline Index memUsage() const;
90 inline Index memUsageIfLoaded() const;
91 /// Return the number of values contained in this buffer.
92 static Index size() { return SIZE; }
93
94 /// @brief Return a const pointer to the array of voxel values.
95 /// @details This method guarantees that the buffer is allocated and loaded.
96 /// @warning This method should only be used by experts seeking low-level optimizations.
97 const ValueType* data() const;
98 /// @brief Return a pointer to the array of voxel values.
99 /// @details This method guarantees that the buffer is allocated and loaded.
100 /// @warning This method should only be used by experts seeking low-level optimizations.
101 ValueType* data();
102
103 private:
104 /// If this buffer is empty, return zero, otherwise return the value at index @ i.
105 inline const ValueType& at(Index i) const;
106
107 /// @brief Return a non-const reference to the value at index @a i.
108 /// @details This method is private since it makes assumptions about the
109 /// buffer's memory layout. LeafBuffers associated with custom leaf node types
110 /// (e.g., a bool buffer implemented as a bitmask) might not be able to
111 /// return non-const references to their values.
112
11/22
✓ Branch 1 taken 17217536 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2560 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 512 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 512 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 512 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 512 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 512 times.
✗ Branch 27 not taken.
586048164 ValueType& operator[](Index i) { return const_cast<ValueType&>(this->at(i)); }
113
114 bool deallocate();
115
116 295 inline void setOutOfCore(bool b) { mOutOfCore = b; }
117 // To facilitate inlining in the common case in which the buffer is in-core,
118 // the loading logic is split into a separate function, doLoad().
119
2/2
✓ Branch 0 taken 18978 times.
✓ Branch 1 taken 3596249828 times.
7126013534 inline void loadValues() const { if (this->isOutOfCore()) this->doLoad(); }
120 inline void doLoad() const;
121 inline bool detachFromFile();
122
123 using FlagsType = std::atomic<Index32>;
124
125 union {
126 ValueType* mData;
127 FileInfo* mFileInfo;
128 };
129 FlagsType mOutOfCore; // interpreted as bool; extra bits reserved for future use
130 tbb::spin_mutex mMutex; // 1 byte
131 //int8_t mReserved[3]; // padding for alignment
132
133 static const ValueType sZero;
134
135 friend class ::TestLeaf;
136 // Allow the parent LeafNode to access this buffer's data pointer.
137 template<typename, Index> friend class LeafNode;
138 }; // class LeafBuffer
139
140
141 ////////////////////////////////////////
142
143
144 template<typename T, Index Log2Dim>
145 const T LeafBuffer<T, Log2Dim>::sZero = zeroVal<T>();
146
147
148 template<typename T, Index Log2Dim>
149 inline
150 11951628 LeafBuffer<T, Log2Dim>::LeafBuffer(const ValueType& val)
151
2/2
✓ Branch 1 taken 67480576 times.
✓ Branch 2 taken 131798 times.
146590732 : mData(new ValueType[SIZE])
152 {
153 mOutOfCore = 0;
154 262967 this->fill(val);
155 11951628 }
156
157
158 template<typename T, Index Log2Dim>
159 inline
160
2/2
✓ Branch 0 taken 9114 times.
✓ Branch 1 taken 6144340 times.
12290081 LeafBuffer<T, Log2Dim>::~LeafBuffer()
161 {
162
2/2
✓ Branch 0 taken 9114 times.
✓ Branch 1 taken 6144340 times.
12290081 if (this->isOutOfCore()) {
163 18228 this->detachFromFile();
164 } else {
165 12271853 this->deallocate();
166 }
167 12290081 }
168
169
170 template<typename T, Index Log2Dim>
171 inline
172 87898 LeafBuffer<T, Log2Dim>::LeafBuffer(const LeafBuffer& other)
173 : mData(nullptr)
174
2/2
✓ Branch 0 taken 5331 times.
✓ Branch 1 taken 38619 times.
87898 , mOutOfCore(other.mOutOfCore.load())
175 {
176
2/2
✓ Branch 0 taken 5331 times.
✓ Branch 1 taken 38619 times.
87898 if (other.isOutOfCore()) {
177 10662 mFileInfo = new FileInfo(*other.mFileInfo);
178
1/2
✓ Branch 0 taken 38619 times.
✗ Branch 1 not taken.
77236 } else if (other.mData != nullptr) {
179 12556 this->allocate();
180 77236 ValueType* target = mData;
181 77236 const ValueType* source = other.mData;
182 Index n = SIZE;
183
2/2
✓ Branch 0 taken 19772928 times.
✓ Branch 1 taken 38619 times.
39622068 while (n--) *target++ = *source++;
184 }
185 87898 }
186
187
188 template<typename T, Index Log2Dim>
189 inline void
190 372765867 LeafBuffer<T, Log2Dim>::setValue(Index i, const ValueType& val)
191 {
192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 188122014 times.
372765867 assert(i < SIZE);
193
2/4
✓ Branch 2 taken 205 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 205 times.
✗ Branch 6 not taken.
372766277 this->loadValues();
194
4/6
✓ Branch 0 taken 188121510 times.
✓ Branch 1 taken 504 times.
✓ Branch 2 taken 205 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 205 times.
✗ Branch 5 not taken.
372766277 if (mData) mData[i] = val;
195 372765867 }
196
197
198 template<typename T, Index Log2Dim>
199 inline LeafBuffer<T, Log2Dim>&
200 48120 LeafBuffer<T, Log2Dim>::operator=(const LeafBuffer& other)
201 {
202
1/2
✓ Branch 0 taken 24060 times.
✗ Branch 1 not taken.
48120 if (&other != this) {
203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24060 times.
48120 if (this->isOutOfCore()) {
204 this->detachFromFile();
205 } else {
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24060 times.
48120 if (other.isOutOfCore()) this->deallocate();
207 }
208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24060 times.
48120 if (other.isOutOfCore()) {
209 mOutOfCore.store(other.mOutOfCore.load(std::memory_order_acquire),
210 std::memory_order_release);
211 mFileInfo = new FileInfo(*other.mFileInfo);
212
1/2
✓ Branch 0 taken 24060 times.
✗ Branch 1 not taken.
48120 } else if (other.mData != nullptr) {
213 this->allocate();
214 48120 ValueType* target = mData;
215 48120 const ValueType* source = other.mData;
216 Index n = SIZE;
217
2/2
✓ Branch 0 taken 12318720 times.
✓ Branch 1 taken 24060 times.
24685560 while (n--) *target++ = *source++;
218 }
219 }
220 48120 return *this;
221 }
222
223
224 template<typename T, Index Log2Dim>
225 inline void
226 187468 LeafBuffer<T, Log2Dim>::fill(const ValueType& val)
227 {
228 6042700 this->detachFromFile();
229
11/28
✓ Branch 0 taken 58541 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 163751 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 192274 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1001208 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 21151 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12905 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2259 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 4462996 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 52843 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
6042700 if (mData != nullptr) {
230 ValueType* target = mData;
231 Index n = SIZE;
232
22/28
✓ Branch 0 taken 29972992 times.
✓ Branch 1 taken 58541 times.
✓ Branch 2 taken 9782784 times.
✓ Branch 3 taken 19107 times.
✓ Branch 4 taken 79793024 times.
✓ Branch 5 taken 165795 times.
✓ Branch 6 taken 98444292 times.
✓ Branch 7 taken 192274 times.
✓ Branch 8 taken 512618496 times.
✓ Branch 9 taken 1001208 times.
✓ Branch 10 taken 10829312 times.
✓ Branch 11 taken 21151 times.
✓ Branch 12 taken 6607360 times.
✓ Branch 13 taken 12905 times.
✓ Branch 14 taken 1156608 times.
✓ Branch 15 taken 2259 times.
✓ Branch 16 taken 2285053952 times.
✓ Branch 17 taken 4462996 times.
✓ Branch 18 taken 5552064 times.
✓ Branch 19 taken 52843 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 512 times.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
3074356108 while (n--) *target++ = val;
233 }
234 187468 }
235
236
237 template<typename T, Index Log2Dim>
238 inline bool
239 5750 LeafBuffer<T, Log2Dim>::operator==(const LeafBuffer& other) const
240 {
241 5750 this->loadValues();
242 5750 other.loadValues();
243 5750 const ValueType *target = mData, *source = other.mData;
244
1/2
✓ Branch 0 taken 5750 times.
✗ Branch 1 not taken.
5750 if (!target && !source) return true;
245
1/2
✓ Branch 0 taken 5750 times.
✗ Branch 1 not taken.
5750 if (!target || !source) return false;
246 Index n = SIZE;
247
6/6
✓ Branch 0 taken 2112009 times.
✓ Branch 1 taken 4109 times.
✓ Branch 2 taken 1641 times.
✓ Branch 3 taken 2110368 times.
✓ Branch 4 taken 2110368 times.
✓ Branch 5 taken 5750 times.
2117759 while (n && math::isExactlyEqual(*target++, *source++)) --n;
248 5750 return n == 0;
249 }
250
251
252 template<typename T, Index Log2Dim>
253 inline void
254 41625 LeafBuffer<T, Log2Dim>::swap(LeafBuffer& other)
255 {
256 std::swap(mData, other.mData);
257
258 // Two atomics can't be swapped because it would require hardware support:
259 // https://en.wikipedia.org/wiki/Double_compare-and-swap
260 // Note that there's a window in which other.mOutOfCore could be written
261 // between our load from it and our store to it.
262 auto tmp = other.mOutOfCore.load(std::memory_order_acquire);
263 tmp = mOutOfCore.exchange(std::move(tmp));
264 other.mOutOfCore.store(std::move(tmp), std::memory_order_release);
265 41625 }
266
267
268 template<typename T, Index Log2Dim>
269 inline Index
270 LeafBuffer<T, Log2Dim>::memUsage() const
271 {
272 size_t n = sizeof(*this);
273
6/42
✓ Branch 0 taken 51509 times.
✓ Branch 1 taken 11607 times.
✓ Branch 2 taken 1768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 370 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3263 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
68521 if (this->isOutOfCore()) n += sizeof(FileInfo);
274
6/42
✓ Branch 0 taken 49423 times.
✓ Branch 1 taken 2086 times.
✓ Branch 2 taken 1768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 370 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3263 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
56914 else if (mData) n += SIZE * sizeof(ValueType);
275 return static_cast<Index>(n);
276 }
277
278
279 template<typename T, Index Log2Dim>
280 inline Index
281 LeafBuffer<T, Log2Dim>::memUsageIfLoaded() const
282 {
283 size_t n = sizeof(*this);
284 n += SIZE * sizeof(ValueType);
285 return static_cast<Index>(n);
286 }
287
288
289 template<typename T, Index Log2Dim>
290 inline const typename LeafBuffer<T, Log2Dim>::ValueType*
291 1007779 LeafBuffer<T, Log2Dim>::data() const
292 {
293 1007779 this->loadValues();
294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 581204 times.
1007779 if (mData == nullptr) {
295 LeafBuffer* self = const_cast<LeafBuffer*>(this);
296 // This lock will be contended at most once.
297 tbb::spin_mutex::scoped_lock lock(self->mMutex);
298 if (mData == nullptr) self->mData = new ValueType[SIZE];
299 }
300 1007779 return mData;
301 }
302
303 template<typename T, Index Log2Dim>
304 inline typename LeafBuffer<T, Log2Dim>::ValueType*
305 15552756 LeafBuffer<T, Log2Dim>::data()
306 {
307 15552756 this->loadValues();
308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7783199 times.
15552756 if (mData == nullptr) {
309 // This lock will be contended at most once.
310 tbb::spin_mutex::scoped_lock lock(mMutex);
311 if (mData == nullptr) mData = new ValueType[SIZE];
312 }
313 15552756 return mData;
314 }
315
316
317 template<typename T, Index Log2Dim>
318 inline const typename LeafBuffer<T, Log2Dim>::ValueType&
319 5655749200 LeafBuffer<T, Log2Dim>::at(Index i) const
320 {
321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2859844345 times.
5655749200 assert(i < SIZE);
322 5655749200 this->loadValues();
323 // We can't use the ternary operator here, otherwise Visual C++ returns
324 // a reference to a temporary.
325
1/2
✓ Branch 0 taken 2859844345 times.
✗ Branch 1 not taken.
5655749200 if (mData) return mData[i]; else return sZero;
326 }
327
328
329 template<typename T, Index Log2Dim>
330 inline bool
331 12271853 LeafBuffer<T, Log2Dim>::deallocate()
332 {
333
3/4
✓ Branch 0 taken 6136738 times.
✓ Branch 1 taken 7602 times.
✓ Branch 2 taken 6136738 times.
✗ Branch 3 not taken.
12271853 if (mData != nullptr && !this->isOutOfCore()) {
334
3/4
✓ Branch 0 taken 6136738 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 180224 times.
✓ Branch 3 taken 352 times.
12617097 delete[] mData;
335 12256649 mData = nullptr;
336 12256649 return true;
337 }
338 return false;
339 }
340
341
342 template<typename T, Index Log2Dim>
343 inline void
344
1/2
✓ Branch 0 taken 18978 times.
✗ Branch 1 not taken.
37956 LeafBuffer<T, Log2Dim>::doLoad() const
345 {
346
1/2
✓ Branch 0 taken 18978 times.
✗ Branch 1 not taken.
37956 if (!this->isOutOfCore()) return;
347
348 LeafBuffer<T, Log2Dim>* self = const_cast<LeafBuffer<T, Log2Dim>*>(this);
349
350 // This lock will be contended at most once, after which this buffer
351 // will no longer be out-of-core.
352 37956 tbb::spin_mutex::scoped_lock lock(self->mMutex);
353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18978 times.
37956 if (!this->isOutOfCore()) return;
354
355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18978 times.
75912 std::unique_ptr<FileInfo> info(self->mFileInfo);
356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18978 times.
37956 assert(info.get() != nullptr);
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18978 times.
37956 assert(info->mapping.get() != nullptr);
358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18978 times.
37956 assert(info->meta.get() != nullptr);
359
360 /// @todo For now, we have to clear the mData pointer in order for allocate() to take effect.
361
1/2
✓ Branch 1 taken 3544 times.
✗ Branch 2 not taken.
37956 self->mData = nullptr;
362
1/2
✓ Branch 1 taken 15434 times.
✗ Branch 2 not taken.
30868 self->allocate();
363
364
1/2
✓ Branch 1 taken 18978 times.
✗ Branch 2 not taken.
37956 SharedPtr<std::streambuf> buf = info->mapping->createBuffer();
365
1/2
✓ Branch 1 taken 18978 times.
✗ Branch 2 not taken.
37956 std::istream is(buf.get());
366
367
1/2
✓ Branch 1 taken 18978 times.
✗ Branch 2 not taken.
37956 io::setStreamMetadataPtr(is, info->meta, /*transfer=*/true);
368
369 NodeMaskType mask;
370
2/4
✓ Branch 1 taken 18978 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18978 times.
✗ Branch 5 not taken.
37956 is.seekg(info->maskpos);
371 mask.load(is);
372
373
1/2
✓ Branch 1 taken 18978 times.
✗ Branch 2 not taken.
37956 is.seekg(info->bufpos);
374
2/4
✓ Branch 1 taken 18978 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18978 times.
✗ Branch 5 not taken.
37956 io::readCompressedValues(is, self->mData, SIZE, mask, io::getHalfFloat(is));
375
376 self->setOutOfCore(false);
377 }
378
379
380 template<typename T, Index Log2Dim>
381 inline bool
382
2/2
✓ Branch 0 taken 9114 times.
✓ Branch 1 taken 5823596 times.
11816263 LeafBuffer<T, Log2Dim>::detachFromFile()
383 {
384
2/2
✓ Branch 0 taken 9114 times.
✓ Branch 1 taken 5823596 times.
11816263 if (this->isOutOfCore()) {
385
1/2
✓ Branch 0 taken 9114 times.
✗ Branch 1 not taken.
18228 delete mFileInfo;
386 18228 mFileInfo = nullptr;
387 this->setOutOfCore(false);
388 18228 return true;
389 }
390 return false;
391 }
392
393
394 ////////////////////////////////////////
395
396
397 // Partial specialization for bool ValueType
398 template<Index Log2Dim>
399 class LeafBuffer<bool, Log2Dim>
400 {
401 public:
402 using NodeMaskType = util::NodeMask<Log2Dim>;
403 using WordType = typename NodeMaskType::Word;
404 using ValueType = bool;
405 using StorageType = WordType;
406
407 static const Index WORD_COUNT = NodeMaskType::WORD_COUNT;
408 static const Index SIZE = 1 << 3 * Log2Dim;
409
410 // These static declarations must be on separate lines to avoid VC9 compiler errors.
411 static const bool sOn;
412 static const bool sOff;
413
414 LeafBuffer() {}
415 LeafBuffer(bool on): mData(on) {}
416 LeafBuffer(const NodeMaskType& other): mData(other) {}
417 LeafBuffer(const LeafBuffer& other): mData(other.mData) {}
418 ~LeafBuffer() {}
419 void fill(bool val) { mData.set(val); }
420 LeafBuffer& operator=(const LeafBuffer& b) { if (&b != this) { mData=b.mData; } return *this; }
421
422 1410 const bool& getValue(Index i) const
423 {
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1410 times.
1410 assert(i < SIZE);
425 // We can't use the ternary operator here, otherwise Visual C++ returns
426 // a reference to a temporary.
427
2/2
✓ Branch 1 taken 940 times.
✓ Branch 2 taken 470 times.
1410 if (mData.isOn(i)) return sOn; else return sOff;
428 }
429 961 const bool& operator[](Index i) const { return this->getValue(i); }
430
431 bool operator==(const LeafBuffer& other) const { return mData == other.mData; }
432 bool operator!=(const LeafBuffer& other) const { return mData != other.mData; }
433
434
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1023310 times.
✓ Branch 3 taken 115948 times.
✓ Branch 4 taken 907362 times.
1023310 void setValue(Index i, bool val) { assert(i < SIZE); mData.set(i, val); }
435
436 void swap(LeafBuffer& other) { if (&other != this) std::swap(mData, other.mData); }
437
438 Index memUsage() const { return sizeof(*this); }
439 Index memUsageIfLoaded() const { return sizeof(*this); }
440 static Index size() { return SIZE; }
441
442 /// @brief Return a pointer to the C-style array of words encoding the bits.
443 /// @warning This method should only be used by experts seeking low-level optimizations.
444 WordType* data() { return &(mData.template getWord<WordType>(0)); }
445 /// @brief Return a const pointer to the C-style array of words encoding the bits.
446 /// @warning This method should only be used by experts seeking low-level optimizations.
447 const WordType* data() const { return const_cast<LeafBuffer*>(this)->data(); }
448
449 private:
450 // Allow the parent LeafNode to access this buffer's data.
451 template<typename, Index> friend class LeafNode;
452
453 NodeMaskType mData;
454 }; // class LeafBuffer
455
456
457 /// @internal For consistency with other nodes and with iterators, methods like
458 /// LeafNode::getValue() return a reference to a value. Since it's not possible
459 /// to return a reference to a bit in a node mask, we return a reference to one
460 /// of the following static values instead.
461 ///
462 /// @todo Make these static inline with C++17
463 template<Index Log2Dim> const bool LeafBuffer<bool, Log2Dim>::sOn = true;
464 template<Index Log2Dim> const bool LeafBuffer<bool, Log2Dim>::sOff = false;
465
466 } // namespace tree
467 } // namespace OPENVDB_VERSION_NAME
468 } // namespace openvdb
469
470 #endif // OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED
471