GEOS
BufferOps.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 
17 
18 #ifndef GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
19 #define GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
20 
21 #include "common/DataTypes.hpp"
22 #include "common/logger/Logger.hpp"
23 #include "codingUtilities/Utilities.hpp"
24 #include "codingUtilities/traits.hpp"
25 #include "LvArray/src/limits.hpp"
26 
27 #include <type_traits>
28 
29 namespace geos
30 {
31 
32 template< typename T >
33 class InterObjectRelation;
34 
35 namespace bufferOps
36 {
37 
38 template< typename T >
39 struct is_packable_helper;
40 
41 template< typename T >
42 constexpr bool is_noncontainer_type_packable = std::is_trivial< T >::value ||
43  std::is_arithmetic< T >::value ||
44  traits::is_tensorT< T > ||
45  traits::is_string< T >;
46 
47 template< typename T >
48 constexpr bool is_container = !is_noncontainer_type_packable< T >;
49 
50 template< typename >
51 constexpr bool is_packable_array = false;
52 
53 template< typename T, int NDIM, typename PERMUTATION >
54 constexpr bool is_packable_array< Array< T, NDIM, PERMUTATION > > = is_packable_helper< T >::value;
55 
56 template< typename T, int NDIM, int USD >
57 constexpr bool is_packable_array< ArrayView< T, NDIM, USD > > = is_packable_helper< T >::value;
58 
59 template< typename T, int NDIM, int USD >
60 constexpr bool is_packable_array< ArraySlice< T, NDIM, USD > > = is_packable_helper< T >::value;
61 
62 template< typename T >
63 constexpr bool is_packable_array< ArrayOfArrays< T > > = is_packable_helper< T >::value;
64 
65 template< typename >
66 constexpr bool is_packable_set = false;
67 
68 template< typename T >
69 constexpr bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
70 
71 
72 template< typename >
73 constexpr bool is_packable_map = false;
74 
75 template< typename T_KEY, typename T_VAL, typename SORTED >
76 constexpr bool is_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_packable_helper< T_KEY >::value &&
77  is_packable_helper< T_VAL >::value;
78 
79 
80 template< typename T >
81 struct is_packable_helper
82 {
83  static constexpr bool value = is_noncontainer_type_packable< T > ||
84  is_packable_array< T > ||
85  is_packable_map< T > ||
86  is_packable_set< T >;
87 };
88 
89 template< typename T >
90 constexpr bool is_packable = is_packable_helper< T >::value;
91 
92 template< typename T >
93 constexpr bool is_packable_by_index = is_packable_array< T >;
94 
95 template< typename >
96 constexpr bool is_map_packable_by_index = false;
97 
98 template< typename T_KEY, typename T_VAL, typename SORTED >
99 constexpr bool is_map_packable_by_index< mapBase< T_KEY, T_VAL, SORTED > > = is_packable< T_KEY > &&
100  is_packable_by_index< T_VAL >;
101 
102 template< typename T >
103 constexpr bool can_memcpy_helper = std::is_arithmetic< T >::value ||
104  std::is_enum< T >::value ||
105  traits::is_tensorT< T >;
106 
107 template< typename T >
108 constexpr bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
109 
110 //------------------------------------------------------------------------------
111 // Pack(buffer,var)
112 //------------------------------------------------------------------------------
113 template< bool DO_PACKING, typename T >
114 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
115 Pack( buffer_unit_type * & buffer,
116  T const & var );
117 
118 //------------------------------------------------------------------------------
119 template< bool DO_PACKING >
121 Pack( buffer_unit_type * & buffer,
122  const string & var );
123 
124 //------------------------------------------------------------------------------
125 template< bool DO_PACKING, typename T >
127 Pack( buffer_unit_type * & buffer,
128  SortedArray< T > const & var );
129 
130 //------------------------------------------------------------------------------
131 template< bool DO_PACKING, typename T >
132 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
133 Pack( buffer_unit_type * & buffer,
134  T const & var );
135 
136 //------------------------------------------------------------------------------
137 template< bool DO_PACKING, typename T, int NDIM, int USD >
138 typename std::enable_if< is_packable< T >, localIndex >::type
139 Pack( buffer_unit_type * & buffer,
140  ArrayView< T, NDIM, USD > const & var );
141 
142 //------------------------------------------------------------------------------
143 template< bool DO_PACKING, typename T >
145 Pack( buffer_unit_type * & buffer,
146  ArrayOfArrays< T > const & var );
147 
148 //------------------------------------------------------------------------------
149 template< bool DO_PACKING, typename T >
151 Pack( buffer_unit_type * & buffer,
152  ArrayOfSets< T > const & var );
153 
154 //------------------------------------------------------------------------------
155 template< bool DO_PACKING, typename MAP_TYPE >
156 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
157 Pack( buffer_unit_type * & buffer,
158  MAP_TYPE const & var );
159 
160 //------------------------------------------------------------------------------
161 template< bool DO_PACKING, typename T_FIRST, typename T_SECOND >
163 Pack( buffer_unit_type * & buffer,
164  std::pair< T_FIRST, T_SECOND > const & var );
165 
166 //------------------------------------------------------------------------------
167 template< bool DO_PACKING, typename T >
169 Pack( buffer_unit_type * & buffer,
170  InterObjectRelation< T > const & var );
171 
172 //------------------------------------------------------------------------------
173 // fallthrough-implementation
174 template< bool DO_PACKING, typename T >
175 typename std::enable_if< !is_packable< T >, localIndex >::type
176 Pack( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
177  T const & GEOS_UNUSED_PARAM( var ) )
178 {
179  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable." );
180  return 0;
181 }
182 
183 //------------------------------------------------------------------------------
184 // PackArray(buffer,var,length)
185 //------------------------------------------------------------------------------
186 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
187 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
188 PackPointer( buffer_unit_type * & buffer,
189  T const * const GEOS_RESTRICT var,
190  INDEX_TYPE const length );
191 
192 //------------------------------------------------------------------------------
193 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
194 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
195 PackPointer( buffer_unit_type * & buffer,
196  T const * const GEOS_RESTRICT var,
197  INDEX_TYPE const length );
198 
199 //------------------------------------------------------------------------------
200 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
201 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
202 PackArray( buffer_unit_type * & buffer,
203  arraySlice1d< T, USD > const & var,
204  INDEX_TYPE const length );
205 
206 //------------------------------------------------------------------------------
207 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
208 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
209 PackArray( buffer_unit_type * & buffer,
210  arraySlice1d< T, USD > const & var,
211  INDEX_TYPE const length );
212 
213 //------------------------------------------------------------------------------
214 // PackByIndex(buffer,var,indices)
215 //------------------------------------------------------------------------------
216 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices >
217 typename std::enable_if< is_packable< T >, localIndex >::type
218 PackByIndex( buffer_unit_type * & buffer,
219  ArrayView< T, NDIM, USD > const & var,
220  const T_indices & indices );
221 
222 //------------------------------------------------------------------------------
223 template< bool DO_PACKING, typename T, typename T_indices >
224 localIndex PackByIndex( buffer_unit_type * & buffer,
225  ArrayOfArrays< T > const & var,
226  T_indices const & indices );
227 
228 //------------------------------------------------------------------------------
229 template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES >
230 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
231 PackByIndex( buffer_unit_type * & buffer,
232  MAP_TYPE const & var,
233  T_INDICES const & indices );
234 
235 //------------------------------------------------------------------------------
236 template< bool DO_PACKING, typename T, typename T_INDICES >
237 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >, localIndex >::type
238 PackByIndex( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
239  T const & GEOS_UNUSED_PARAM( var ),
240  T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
241 {
242  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
243  return 0;
244 }
245 
246 //------------------------------------------------------------------------------
247 // Unpack(buffer,var)
248 //------------------------------------------------------------------------------
249 template< typename T >
250 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
251 Unpack( buffer_unit_type const * & buffer,
252  T & var );
253 
254 //------------------------------------------------------------------------------
255 inline
257 Unpack( buffer_unit_type const * & buffer,
258  string & var );
259 
260 //------------------------------------------------------------------------------
261 template< typename T >
262 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
263 Unpack( buffer_unit_type const * & buffer,
264  T & var );
265 
266 //------------------------------------------------------------------------------
267 template< typename T >
269 Unpack( buffer_unit_type const * & buffer,
270  SortedArray< T > & var );
271 
272 //------------------------------------------------------------------------------
273 template< typename T, int NDIM, typename PERMUTATION >
274 typename std::enable_if< is_packable< T >, localIndex >::type
275 Unpack( buffer_unit_type const * & buffer,
276  Array< T, NDIM, PERMUTATION > & var );
277 
278 //------------------------------------------------------------------------------
279 template< typename T >
280 localIndex Unpack( buffer_unit_type const * & buffer,
281  ArrayOfArrays< T > & var );
282 
283 //------------------------------------------------------------------------------
284 inline
286 Unpack( buffer_unit_type const * & buffer,
287  ArrayOfArrays< array1d< globalIndex > > & var,
288  localIndex const subArrayIndex );
289 
290 //------------------------------------------------------------------------------
291 template< typename T >
292 localIndex Unpack( buffer_unit_type const * & buffer,
293  ArrayOfSets< T > & var );
294 
295 //------------------------------------------------------------------------------
296 template< typename MAP_TYPE >
297 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
298 Unpack( buffer_unit_type const * & buffer,
299  MAP_TYPE & map );
300 
301 //------------------------------------------------------------------------------
302 template< typename T_FIRST, typename T_SECOND >
304 Unpack( buffer_unit_type const * & buffer,
305  std::pair< T_FIRST, T_SECOND > & var );
306 
307 //------------------------------------------------------------------------------
308 template< typename T >
310 Unpack( buffer_unit_type const * & buffer,
311  InterObjectRelation< T > & var );
312 
313 //------------------------------------------------------------------------------
314 template< typename T >
315 typename std::enable_if< !is_packable< T >, localIndex >::type
316 Unpack( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
317  T & GEOS_UNUSED_PARAM( var ) )
318 {
319  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable." );
320  return 0;
321 }
322 
323 //------------------------------------------------------------------------------
324 // UnpackArray(buffer,var,expectedLength)
325 //------------------------------------------------------------------------------
326 template< typename T, typename INDEX_TYPE >
327 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
328 UnpackPointer( buffer_unit_type const * & buffer,
329  T * const GEOS_RESTRICT var,
330  INDEX_TYPE const expectedLength );
331 
332 //------------------------------------------------------------------------------
333 template< typename T, typename INDEX_TYPE >
334 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
335 UnpackPointer( buffer_unit_type const * & buffer,
336  T * const GEOS_RESTRICT var,
337  INDEX_TYPE const expectedLength );
338 
339 //------------------------------------------------------------------------------
340 template< typename T, typename INDEX_TYPE, int USD >
341 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
342 UnpackArray( buffer_unit_type const * & buffer,
343  arraySlice1d< T, USD > const & var,
344  INDEX_TYPE const length );
345 
346 //------------------------------------------------------------------------------
347 template< typename T, typename INDEX_TYPE, int USD >
348 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
349 UnpackArray( buffer_unit_type const * & buffer,
350  arraySlice1d< T, USD > const & var,
351  INDEX_TYPE const length );
352 
353 //------------------------------------------------------------------------------
354 // UnpackByIndex(buffer,var,indices)
355 //------------------------------------------------------------------------------
356 template< typename T, int NDIM, int USD, typename T_indices >
358 UnpackByIndex( buffer_unit_type const * & buffer,
359  ArrayView< T, NDIM, USD > const & var,
360  const T_indices & indices );
361 
362 //------------------------------------------------------------------------------
363 template< typename T, typename T_indices >
365 UnpackByIndex( buffer_unit_type const * & buffer,
366  ArrayOfArrays< T > & var,
367  T_indices const & indices );
368 
369 //------------------------------------------------------------------------------
370 template< typename MAP_TYPE, typename T_INDICES >
371 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
372 UnpackByIndex( buffer_unit_type const * & buffer,
373  MAP_TYPE & map,
374  T_INDICES const & indices );
375 
376 //------------------------------------------------------------------------------
377 template< typename T, typename T_INDICES >
378 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >, localIndex >::type
379 UnpackByIndex( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
380  T & GEOS_UNUSED_PARAM( var ),
381  T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
382 {
383  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
384  return 0;
385 }
386 
387 //------------------------------------------------------------------------------
388 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
389 localIndex Pack( buffer_unit_type * & buffer,
390  T const * const GEOS_RESTRICT var,
391  arraySlice1d< INDEX_TYPE const > const & indices,
392  INDEX_TYPE const length );
393 
394 //------------------------------------------------------------------------------
395 template< typename T, typename INDEX_TYPE >
396 localIndex Unpack( buffer_unit_type const * & buffer,
397  T * const GEOS_RESTRICT var,
398  arraySlice1d< INDEX_TYPE const > const & indices,
399  INDEX_TYPE & length );
400 
401 //------------------------------------------------------------------------------
402 template< bool DO_PACKING, int USD >
403 localIndex Pack( buffer_unit_type * & buffer,
404  SortedArray< localIndex > const & var,
405  SortedArray< globalIndex > const & unmappedGlobalIndices,
406  arraySlice1d< globalIndex const, USD > const & localToGlobal );
407 
408 //------------------------------------------------------------------------------
409 template< typename SORTED >
410 inline localIndex Unpack( buffer_unit_type const * & buffer,
411  SortedArray< localIndex > & var,
412  SortedArray< globalIndex > & unmappedGlobalIndices,
413  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap,
414  bool const clearExistingSet );
415 
416 //------------------------------------------------------------------------------
417 template< typename T >
419 Pack( buffer_unit_type * & buffer,
420  ArrayOfSets< T > const & var );
421 
422 //------------------------------------------------------------------------------
423 template< typename T >
425 Unpack( buffer_unit_type const * & buffer,
426  ArrayOfSets< T > & var );
427 
428 
429 //------------------------------------------------------------------------------
430 template< bool DO_PACKING, int USD >
432 Pack( buffer_unit_type * & buffer,
433  arraySlice1d< localIndex const, USD > const & var,
434  globalIndex const * const unmappedGlobalIndices,
435  localIndex const length,
436  arraySlice1d< globalIndex const > const & localToGlobalMap );
437 
438 //------------------------------------------------------------------------------
439 template< typename SORTED >
440 inline localIndex Unpack( buffer_unit_type const * & buffer,
441  localIndex_array & var,
442  array1d< globalIndex > & unmappedGlobalIndices,
443  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
444 
445 //------------------------------------------------------------------------------
446 inline localIndex UnpackSyncList( buffer_unit_type const * & buffer,
447  localIndex_array & var,
448  std::unordered_map< globalIndex, localIndex > const & globalToLocalMap );
449 
450 //------------------------------------------------------------------------------
451 template< typename SORTED, int USD >
452 inline
454 Unpack( buffer_unit_type const * & buffer,
455  arraySlice1d< localIndex, USD > & var,
456  array1d< globalIndex > & unmappedGlobalIndices,
457  localIndex const expectedLength,
458  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
459 
460 //------------------------------------------------------------------------------
461 template< bool DO_PACKING >
463 Pack( buffer_unit_type * & buffer,
464  arrayView1d< localIndex const > const & var,
465  arrayView1d< localIndex const > const & indices,
466  arrayView1d< globalIndex const > const & localToGlobalMap,
467  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
468 
469 //------------------------------------------------------------------------------
470 template< bool DO_PACKING >
472 Pack( buffer_unit_type * & buffer,
473  ArrayOfArraysView< array1d< globalIndex > const > const & var,
474  arrayView1d< localIndex const > const & indices,
475  arrayView1d< globalIndex const > const & localToGlobalMap );
476 
477 //------------------------------------------------------------------------------
478 template< typename SORTED0, typename SORTED1 >
479 inline
481 Unpack( buffer_unit_type const * & buffer,
482  arrayView1d< localIndex > const & var,
483  array1d< localIndex > const & indices,
484  mapBase< globalIndex, localIndex, SORTED0 > const & globalToLocalMap,
485  mapBase< globalIndex, localIndex, SORTED1 > const & relatedObjectGlobalToLocalMap );
486 
487 
488 //------------------------------------------------------------------------------
489 template< bool DO_PACKING, typename SORTED >
491 Pack( buffer_unit_type * & buffer,
492  arrayView1d< arrayView1d< localIndex const > const > const & var,
493  mapBase< localIndex, array1d< globalIndex >, SORTED > const & unmappedGlobalIndices,
494  arrayView1d< localIndex const > const & indices,
495  arrayView1d< globalIndex const > const & localToGlobalMap,
496  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
497 
498 //------------------------------------------------------------------------------
499 template< typename SORTED0, typename SORTED1, typename SORTED2 >
500 inline
502 Unpack( buffer_unit_type const * & buffer,
503  arrayView1d< localIndex_array > & var,
504  array1d< localIndex > & indices,
505  mapBase< localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
506  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
507  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap );
508 
509 //------------------------------------------------------------------------------
510 template< typename SORTED0 >
511 inline
513 Unpack( buffer_unit_type const * & buffer,
514  ArrayOfArrays< array1d< globalIndex > > & var,
515  array1d< localIndex > & indices,
516  mapBase< globalIndex, localIndex, SORTED0 > const & globalToLocalMap );
517 
518 //------------------------------------------------------------------------------
519 template< bool DO_PACKING, typename SORTED >
521 Pack( buffer_unit_type * & buffer,
522  arrayView1d< SortedArray< localIndex > const > const & var,
523  mapBase< localIndex, SortedArray< globalIndex >, SORTED > const & unmappedGlobalIndices,
524  arrayView1d< localIndex const > const & indices,
525  arrayView1d< globalIndex const > const & localToGlobalMap,
526  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
527 
528 //------------------------------------------------------------------------------
529 template< typename SORTED0, typename SORTED1, typename SORTED2 >
530 inline
532 Unpack( buffer_unit_type const * & buffer,
533  arrayView1d< SortedArray< localIndex > > & var,
534  localIndex_array & indices,
535  mapBase< localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
536  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
537  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap,
538  bool const clearFlag );
539 
540 //------------------------------------------------------------------------------
541 template< bool DO_PACKING, int USD0, int USD1 >
543 Pack( buffer_unit_type * & buffer,
544  arrayView2d< localIndex const, USD0 > const & var,
545  arrayView1d< localIndex > const & indices,
546  arraySlice1d< globalIndex const, USD1 > const & localToGlobalMap );
547 
548 //------------------------------------------------------------------------------
549 template< typename SORTED, int USD >
550 inline
552 Unpack( buffer_unit_type const * & buffer,
553  arrayView2d< localIndex, USD > const & var,
554  array1d< localIndex > & indices,
555  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
556 
557 //------------------------------------------------------------------------------
558 template< bool DO_PACKING, typename SORTED, int USD0 >
560 Pack( buffer_unit_type * & buffer,
561  arrayView2d< localIndex const, USD0 > const & var,
562  mapBase< localIndex, array1d< globalIndex >, SORTED > const & unmappedGlobalIndices,
563  arrayView1d< localIndex const > const & indices,
564  arraySlice1d< globalIndex const > const & localToGlobalMap,
565  arraySlice1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
566 
567 //------------------------------------------------------------------------------
568 template< typename SORTED0, typename SORTED1, typename SORTED2, int USD >
569 inline
571 Unpack( buffer_unit_type const * & buffer,
572  arrayView2d< localIndex, USD > const & var,
573  localIndex_array & indices,
574  mapBase< localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
575  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
576  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap );
577 
578 //------------------------------------------------------------------------------
579 template< bool DO_PACKING, typename MAP_TYPE >
580 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
581 Pack( buffer_unit_type * & buffer, MAP_TYPE const & var );
582 
583 //------------------------------------------------------------------------------
584 template< typename MAP_TYPE >
585 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
586 Unpack( buffer_unit_type const * & buffer, MAP_TYPE & map );
587 
588 //------------------------------------------------------------------------------
589 template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES >
590 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
591 Pack( buffer_unit_type * & buffer, MAP_TYPE const & var, T_INDICES const & packIndices );
592 
593 //------------------------------------------------------------------------------
594 template< typename MAP_TYPE, typename T_INDICES >
595 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
596 Unpack( buffer_unit_type const * & buffer, MAP_TYPE & map, T_INDICES const & unpackIndices );
597 
598 //------------------------------------------------------------------------------
599 template< bool DO_PACKING, typename T_FIRST, typename T_SECOND >
601 Pack( buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND > const & var );
602 
603 //------------------------------------------------------------------------------
604 template< typename T_FIRST, typename T_SECOND >
606 Unpack( buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
607 
608 //------------------------------------------------------------------------------
609 template< bool DO_PACKING, typename T >
611 Pack( buffer_unit_type * & buffer,
612  InterObjectRelation< T > const & var );
613 
614 template< typename ... VARPACK >
616 PackSize( VARPACK const && ... pack )
617 {
618  buffer_unit_type * junk = nullptr;
619  return Pack< false >( junk, pack ... );
620 }
621 
622 template< typename ... VARPACK >
624 PackSize( VARPACK && ... pack )
625 {
626  buffer_unit_type * junk = nullptr;
627  return Pack< false >( junk, pack ... );
628 }
629 
630 #ifdef GEOS_USE_ARRAY_BOUNDS_CHECK
631 //------------------------------------------------------------------------------
632 template< bool DO_PACKING, typename T, typename T_INDICES >
633 typename std::enable_if< !is_packable_by_index< T > &&
634  !is_map_packable_by_index< T >, localIndex >::type
635 Pack( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ), T const & GEOS_UNUSED_PARAM( var ), T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
636 {
637  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
638  return 0;
639 }
640 
641 //------------------------------------------------------------------------------
642 template< typename T, typename T_INDICES >
643 typename std::enable_if< !is_packable_by_index< T > &&
644  !is_map_packable_by_index< T >, localIndex >::type
645 Unpack( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ), T & GEOS_UNUSED_PARAM( var ), T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
646 {
647  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
648  return 0;
649 }
650 
651 //------------------------------------------------------------------------------
652 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
654 Pack( buffer_unit_type * & buffer,
655  arraySlice1d< T > const & var,
656  arraySlice1d< INDEX_TYPE > const & indices,
657  INDEX_TYPE const length );
658 
659 //------------------------------------------------------------------------------
660 template< typename T, typename INDEX_TYPE >
662 Unpack( buffer_unit_type const * & buffer,
663  arraySlice1d< T > & var,
664  arraySlice1d< INDEX_TYPE > const & indices,
665  INDEX_TYPE & length );
666 
667 #endif /* GEOS_USE_ARRAY_BOUNDS_CHECK */
668 
669 } /* namespace bufferOps */
670 } /* namespace geos */
671 
672 #include "BufferOps_inline.hpp"
673 
674 #endif /* GEOS_DATAREPOSITORY_BUFFEROPS_HPP_ */
#define GEOS_RESTRICT
preprocessor variable for the C99 restrict keyword for use with pointers
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:72
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
array1d< localIndex > localIndex_array
A 1-dimensional array of geos::localIndex types.
Definition: DataTypes.hpp:398
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
Definition: DataTypes.hpp:286
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
Definition: DataTypes.hpp:369
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:109
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
Definition: DataTypes.hpp:282