GEOSX
output.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 // Source includes
16 #include "Array.hpp"
17 #include "SortedArray.hpp"
18 #include "ArrayOfArrays.hpp"
19 #include "CRSMatrix.hpp"
20 
21 // System includes
22 #include <string>
23 #include <iostream>
24 
25 namespace LvArray
26 {
27 
38 // Sphinx start after Array stream IO
39 template< typename T, int NDIM, int USD, typename INDEX_TYPE >
40 std::ostream & operator<<( std::ostream & stream,
42 {
43  stream << "{ ";
44 
45  if( slice.size( 0 ) > 0 )
46  {
47  stream << slice[ 0 ];
48  }
49 
50  for( INDEX_TYPE i = 1; i < slice.size( 0 ); ++i )
51  {
52  stream << ", " << slice[ i ];
53  }
54 
55  stream << " }";
56  return stream;
57 }
58 // Sphinx end before Array stream IO
59 
60 
72 template< typename T,
73  int NDIM,
74  int USD,
75  typename INDEX_TYPE,
76  template< typename > class BUFFER_TYPE >
77 std::ostream & operator<<( std::ostream & stream,
79 { return stream << view.toSliceConst(); }
80 
89 template< typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE >
90 std::ostream & operator<< ( std::ostream & stream,
92 {
93  if( view.size() == 0 )
94  {
95  stream << "{}";
96  return stream;
97  }
98 
99  stream << "{ " << view[ 0 ];
100 
101  if( view.size() > 0 )
102  stream << view[ 0 ];
103 
104  for( INDEX_TYPE i = 1; i < view.size(); ++i )
105  {
106  stream << ", " << view[ i ];
107  }
108 
109  stream << " }";
110  return stream;
111 }
112 
121 template< typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE >
122 std::ostream & operator<< ( std::ostream & stream,
124 { return stream << array.toViewConst(); }
125 
134 template< typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE >
135 std::ostream & operator<< ( std::ostream & stream,
137 {
138  stream << "{" << std::endl;
139 
140  for( INDEX_TYPE i = 0; i < view.size(); ++i )
141  {
142  stream << i << "\t{";
143  for( INDEX_TYPE j = 0; j < view.sizeOfArray( i ); ++j )
144  {
145  stream << view( i, j ) << ", ";
146  }
147 
148  stream << "}" << std::endl;
149  }
150 
151  stream << "}" << std::endl;
152  return stream;
153 }
154 
163 template< typename T, typename INDEX_TYPE, template< typename > class BUFFER_TYPE >
164 std::ostream & operator<< ( std::ostream & stream,
166 { return stream << array.toViewConst(); }
167 
176 template< typename T, typename COL_TYPE, typename INDEX_TYPE, template< typename > class BUFFER_TYPE >
177 std::ostream & operator<< ( std::ostream & stream, CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > const & view )
178 {
179  stream << "{" << std::endl;
180 
181  for( INDEX_TYPE row = 0; row < view.numRows(); ++row )
182  {
183  stream << "row " << row << std::endl;
184  stream << "\tcolumns: " << view.getColumns( row ) << std::endl;
185  stream << "\tvalues: " << view.getEntries( row ) << std::endl;
186  }
187 
188  stream << "}" << std::endl;
189  return stream;
190 }
191 
200 template< typename T, int N >
201 std::enable_if_t< !std::is_same< T, char >::value, std::ostream & >
202 operator<< ( std::ostream & stream, T const ( &array )[ N ] )
203 {
204  stream << "{ " << array[ 0 ];
205  for( int i = 1; i < N; ++i )
206  {
207  stream << ", " << array[ i ];
208  }
209  stream << " }";
210  return stream;
211 }
212 
222 template< typename T, int M, int N >
223 std::ostream & operator<< ( std::ostream & stream, T const ( &array )[ M ][ N ] )
224 {
225  stream << "{ " << array[ 0 ];
226  for( int i = 1; i < M; ++i )
227  {
228  stream << ", " << array[ i ];
229  }
230  stream << " }";
231  return stream;
232 }
233 
234 } // namespace LvArray
Contains the implementation of LvArray::ArrayOfArrays.
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
constexpr INDEX_TYPE_NC size() const
This class provides an interface similar to an std::set.
Definition: SortedArray.hpp:35
This class implements an array of arrays like object with contiguous storage.
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
SortedArrayView< T const, INDEX_TYPE, BUFFER_TYPE > toViewConst() const &
Contains the implementation of LvArray::Array.
This class provides a view into an array of arrays like object.
Contains the implementation of LvArray::SortedArray.
constexpr INDEX_TYPE size() const
constexpr INDEX_TYPE size() const noexcept
Definition: ArraySlice.hpp:171
constexpr INDEX_TYPE_NC sizeOfArray(INDEX_TYPE const i) const
constexpr ArraySlice< T const, NDIM, USD, INDEX_TYPE > toSliceConst() const &noexcept
Definition: ArrayView.hpp:288
Contains the implementation of LvArray::CRSMatrix.
The top level namespace.
Definition: Array.hpp:24
std::ostream & operator<<(std::ostream &os, MemorySpace const space)
Output a MemorySpace enum to a stream.
This class provides a view into a SortedArray.
constexpr ArrayOfArraysView< T const, INDEX_TYPE const, true, BUFFER_TYPE > toViewConst() const &