37 template<
typename T,
typename INDEX_TYPE >
47 while( inputStream.peek() ==
' ' )
59 static void Read( T & arrayValue,
61 std::istringstream & inputStream )
63 inputStream >> arrayValue;
66 "Invalid value of type " <<
typeid(T).name() <<
" in: " <<
67 ( inputStream.eof() ?
"" : inputStream.str().substr( inputStream.tellg() ) ),
68 std::invalid_argument );
77 template<
int NDIM,
int USD >
80 INDEX_TYPE
const *
const dims,
81 std::istringstream & inputStream )
83 LVARRAY_THROW_IF( inputStream.peek() !=
'{',
"Opening '{' not found for input array: "<<inputStream.str(),
84 std::invalid_argument );
87 for(
int i=0; i<(*dims); ++i )
90 Read< NDIM-1 >( arraySlice[i], dims+1, inputStream );
94 LVARRAY_THROW_IF( inputStream.peek() !=
'}',
"Closing '}' not found for input array: "<<inputStream.str(),
95 std::invalid_argument );
119 template<
typename T,
121 typename PERMUTATION,
123 template<
typename >
class BUFFER_TYPE >
125 std::string valueString )
133 bool valueOnLeft =
false;
134 bool spaceOnLeft =
false;
136 for(
char const c : valueString )
138 if( c !=
'{' && c !=
',' && c !=
'}' && c!=
' ' )
140 if( valueOnLeft && spaceOnLeft )
142 LVARRAY_THROW(
"Array value sequence specified without ',' delimiter: "<<valueString,
143 std::invalid_argument );
149 if( c ==
'{' || c ==
',' || c ==
'}' )
171 valueString.erase(
std::remove( valueString.begin(), valueString.end(),
' ' ), valueString.end());
174 if( valueString==
"{}" )
182 "Sub arrays not separated by ',' delimiter: "<<valueString,
183 std::invalid_argument );
186 "First non-space character of input string for an array must be '{'. Given string is: \n"<<valueString,
187 std::invalid_argument );
189 size_t const numOpen = std::count( valueString.begin(), valueString.end(),
'{' );
190 size_t const numClose = std::count( valueString.begin(), valueString.end(),
'}' );
193 "Number of opening '{' not equal to number of '}' in processing of string for filling" 194 " an Array. Given string is: \n"<<valueString,
195 std::invalid_argument );
200 "Cannot have an empty sub-dimension of an array, i.e. { { 0, 1}, {} }. " 201 "The input is"<<valueString,
202 std::invalid_argument );
205 int const ndims = LvArray::integerConversion< int >( valueString.find_first_not_of(
'{' ));
207 "number of dimensions in string ("<<ndims<<
208 ") does not match dimensions of array("<<NDIM<<
209 "). String is:/n"<<valueString,
210 std::invalid_argument );
219 INDEX_TYPE dims[NDIM] = {0};
222 INDEX_TYPE currentDims[NDIM] = {0};
225 bool dimSet[NDIM] = {
false};
227 for(
int i=0; i<NDIM; ++i )
234 for(
size_t charCount = 0; charCount<valueString.size(); ++charCount )
236 char const c = valueString[charCount];
246 "character '}' follows '"<<lastChar<<
"'. Closing brace must follow an array value.",
247 std::invalid_argument );
250 dimSet[dimLevel] =
true;
252 "Dimension "<<dimLevel<<
" is inconsistent across the expression. " 253 "The first set value of the dimension is "<<dims[dimLevel]<<
254 " while the current value of the dimension is"<<currentDims[dimLevel]<<
255 ". The values that have been parsed prior to the error are:\n"<<
256 valueString.substr( 0, charCount+1 ),
257 std::invalid_argument );
260 currentDims[dimLevel] = 1;
263 "In parsing the input string, the current dimension of the array has dropped " 264 "below 0. This means that there are more '}' than '{' at some point in the" 265 " parsing. The values that have been parsed prior to the error are:\n"<<
266 valueString.substr( 0, charCount+1 ),
267 std::invalid_argument );
273 "character of ',' follows '"<<lastChar<<
"'. Comma must follow an array value.",
274 std::invalid_argument );
275 if( dimSet[dimLevel]==
false )
279 ++(currentDims[dimLevel]);
284 "Expression fails to close all '{' with a corresponding '}'. Check your input:"<<
286 std::invalid_argument );
288 array.
resize( NDIM, dims );
293 std::replace( valueString.begin(), valueString.end(),
',',
' ' );
297 for( std::string::size_type a=0; a<valueString.size(); ++a )
299 if( valueString[a] ==
'}' )
301 valueString.insert( a,
" " );
305 std::istringstream strstream( valueString );
void clear()
Sets the size of the Array to zero and destroys all the values.
Definition: Array.hpp:466
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool remove(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, T const &value, CALLBACKS &&callBacks)
Remove the given value from the array if it exists.
Definition: sortedArrayManipulation.hpp:473
LVARRAY_HOST_DEVICE constexpr ArraySlice< T, NDIM, USD, INDEX_TYPE > toSlice() const &noexcept
Definition: ArrayView.hpp:308
#define LVARRAY_THROW_IF(EXP, MSG, TYPE)
Conditionally throw an exception.
Definition: Macros.hpp:201
Contains the implementation of LvArray::Array.
#define LVARRAY_THROW(MSG, TYPE)
Throw an exception.
Definition: Macros.hpp:220
The top level namespace.
Definition: Array.hpp:24
LVARRAY_HOST_DEVICE void resize(int const numDims, DIMS_TYPE const *const dims)
Resize the dimensions of the Array to match the given dimensions.
Definition: Array.hpp:320
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE const * dims() const noexcept
Definition: ArrayView.hpp:470
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55