12#ifndef MFEM_ARRAYS_BY_NAME
13#define MFEM_ARRAYS_BY_NAME
68 int Size()
const {
return static_cast<int>(
data.size()); }
159 if ( LHS.
Size() != RHS.
Size() ) {
return false; }
160 for (
auto it1 = LHS.
begin(), it2 = RHS.
begin();
161 it1 != LHS.
end() && it2 != RHS.
end(); it1++, it2++)
163 if (it1->first != it2->first) {
return false; }
164 if (it1->second != it2->second) {
return false; }
172 std::set<std::string> names;
173 for (
auto const &entry : data)
175 names.insert(entry.first);
183 return data.find(name) != data.end();
189 MFEM_VERIFY( data.find(name) != data.end(),
190 "Access to unknown named array \"" << name <<
"\"");
198 MFEM_VERIFY( data.find(name) != data.end(),
199 "Access to unknown named array \"" << name <<
"\"");
200 return data.at(name);
206 MFEM_VERIFY( data.find(name) == data.end(),
207 "Named array \"" << name <<
"\" already exists");
209 data.insert(std::pair<std::string,
Array<T> >(name,empty_array));
222 MFEM_VERIFY( data.find(name) != data.end(),
223 "Attempting to delete unknown named array \"" << name <<
"\"");
248 os << data.size() <<
'\n';
249 for (
auto const &it : data)
252 os << std::quoted(it.first) <<
'\n' << it.second.Size() <<
'\n';
253 it.second.Print(os, width > 0 ? width : it.second.Size());
263 for (
int i = 0; i < NumArrays; i++)
276 std::string ArrayName;
277 if (in.peek() ==
'"')
281 MFEM_ABORT(
"error parsing input!");
287 MFEM_VERIFY(in.good(),
"error parsing input!");
291 data[ArrayName].Load(in);
void Print(std::ostream &out=mfem::out, int width=-1) const
Print the contents of the container to an output stream.
void SortAll()
Sort each named array in the container.
ArraysByName()=default
Default constructor.
iterator end()
STL-like end. Returns pointer after the last entry of the container.
ArraysByName(ArraysByName &&src) noexcept=default
Move constructor.
Array< T > & operator[](const std::string &name)
Reference access to the named entry.
void UniqueAll()
Remove duplicates from each, previously sorted, named array.
const Array< T > & operator[](const std::string &name) const
Const reference access to the named entry.
typename container::const_iterator const_iterator
ArraysByName< T > & operator=(ArraysByName< T > &&src) noexcept=default
Move assignment operator.
std::set< std::string > GetNames() const
Return an STL set of strings giving the names of the arrays.
iterator begin()
STL-like begin. Returns pointer to the first entry of the container.
container data
Map containing the data sorted alphabetically by name.
ArraysByName(const ArraysByName &src)=default
Copy constructor: deep copy from src.
void DeleteAll()
Delete all named arrays from the container.
std::map< std::string, Array< T > > container
Reusing STL map iterators.
void DeleteArray(const std::string &name)
Delete the named array from the container.
int Size() const
Return the number of named arrays in the container.
bool EntryExists(const std::string &name) const
Return true if an array with the given name is present in the container.
const_iterator end() const
STL-like end. Returns const pointer after the last entry of the container.
typename container::iterator iterator
void Load(std::istream &in)
Load the contents of the container from an input stream.
const_iterator begin() const
STL-like begin. Returns const pointer to the first entry of the container.
ArraysByName< T > & operator=(const ArraysByName< T > &src)=default
Copy assignment operator: deep copy from 'src'.
Array< T > & CreateArray(const std::string &name)
Create a new empty array with the given name.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
int parse_quoted_string(std::string &result, std::istream &in, char delim='"', char escape = '\\')
Read a string formatted using std::quoted. Return nonzero on error.
bool operator==(const Array< T > &LHS, const Array< T > &RHS)