37 template<
typename T,
typename INDEX_TYPE >
38 struct StringToArrayHelper
45 static void skipDelimiters( std::istringstream & inputStream )
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() ) ) );
76 template<
int NDIM,
int USD >
79 INDEX_TYPE
const *
const dims,
80 std::istringstream & inputStream )
82 LVARRAY_ERROR_IF( inputStream.peek() !=
'{',
"opening { not found for input array: "<<inputStream.str() );
85 for(
int i=0; i<(*dims); ++i )
87 skipDelimiters( inputStream );
88 Read< NDIM-1 >( arraySlice[i], dims+1, inputStream );
91 skipDelimiters( inputStream );
92 LVARRAY_ERROR_IF( inputStream.peek() !=
'}',
"closing } not found for input array: "<<inputStream.str() );
116 template<
typename T,
118 typename PERMUTATION,
120 template<
typename >
class BUFFER_TYPE >
130 bool valueOnLeft =
false;
131 bool spaceOnLeft =
false;
133 for(
char const c : valueString )
135 if( c !=
'{' && c !=
',' && c !=
'}' && c!=
' ' )
137 if( valueOnLeft && spaceOnLeft )
139 LVARRAY_ERROR(
"Array value sequence specified without ',' delimiter: "<<valueString );
145 if( c ==
'{' || c ==
',' || c ==
'}' )
167 valueString.erase(
std::remove( valueString.begin(), valueString.end(),
' ' ), valueString.end());
170 if( valueString==
"{}" )
178 "Sub arrays not separated by ',' delimiter: "<<valueString );
181 "First non-space character of input string for an array must be {. Given string is: \n"<<valueString );
183 size_t const numOpen = std::count( valueString.begin(), valueString.end(),
'{' );
184 size_t const numClose = std::count( valueString.begin(), valueString.end(),
'}' );
187 "Number of opening { not equal to number of } in processing of string for filling" 188 " an Array. Given string is: \n"<<valueString );
193 "Cannot have an empty sub-dimension of an array, i.e. { { 0, 1}, {} }. " 194 "The input is"<<valueString );
197 int const ndims = LvArray::integerConversion< int >( valueString.find_first_not_of(
'{' ));
199 "number of dimensions in string ("<<ndims<<
200 ") does not match dimensions of array("<<NDIM<<
201 "). String is:/n"<<valueString );
210 INDEX_TYPE dims[NDIM] = {0};
213 INDEX_TYPE currentDims[NDIM] = {0};
216 bool dimSet[NDIM] = {
false};
218 for(
int i=0; i<NDIM; ++i )
225 for(
size_t charCount = 0; charCount<valueString.size(); ++charCount )
227 char const c = valueString[charCount];
237 dimSet[dimLevel] =
true;
239 "Dimension "<<dimLevel<<
" is inconsistent across the expression. " 240 "The first set value of the dimension is "<<dims[dimLevel]<<
241 " while the current value of the dimension is"<<currentDims[dimLevel]<<
242 ". The values that have been parsed prior to the error are:\n"<<
243 valueString.substr( 0, charCount+1 ) );
246 currentDims[dimLevel] = 1;
249 "In parsing the input string, the current dimension of the array has dropped " 250 "below 0. This means that there are more '}' than '{' at some point in the" 251 " parsing. The values that have been parsed prior to the error are:\n"<<
252 valueString.substr( 0, charCount+1 ) );
258 "character of ',' follows '"<<lastChar<<
"'. Comma must follow an array value." );
259 if( dimSet[dimLevel]==
false )
263 ++(currentDims[dimLevel]);
268 "Expression fails to close all '{' with a corresponding '}'. Check your input:"<<
271 array.
resize( NDIM, dims );
276 std::replace( valueString.begin(), valueString.end(),
',',
' ' );
280 for( std::string::size_type a=0; a<valueString.size(); ++a )
282 if( valueString[a] ==
'}' )
284 valueString.insert( a,
" " );
288 std::istringstream strstream( valueString );
290 internal::StringToArrayHelper< T, INDEX_TYPE >::Read( array.
toSlice(), array.
dims(), strstream );
void clear()
Sets the size of the Array to zero and destroys all the values.
#define LVARRAY_ERROR_IF(EXP, MSG)
Abort execution if EXP is true.
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
constexpr ArraySlice< T, NDIM, USD, INDEX_TYPE > toSlice() const &noexcept
Contains the implementation of LvArray::Array.
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.
constexpr INDEX_TYPE const * dims() const noexcept
#define LVARRAY_ERROR(MSG)
Abort execution.
void resize(int const numDims, DIMS_TYPE const *const dims)
Resize the dimensions of the Array to match the given dimensions.
std::string string
String type.
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...