12#ifndef MFEM_ARRAYS_BY_NAME
13#define MFEM_ARRAYS_BY_NAME
158 if ( LHS.
Size() != RHS.
Size() ) {
return false; }
159 for (
auto it1 = LHS.
begin(), it2 = RHS.
begin();
160 it1 != LHS.
end() && it2 != RHS.
end(); it1++, it2++)
162 if (it1->first != it2->first) {
return false; }
163 if (it1->second != it2->second) {
return false; }
171 std::set<std::string> names;
172 for (
auto const &entry : data)
174 names.insert(entry.first);
182 return data.find(name) != data.end();
188 MFEM_VERIFY( data.find(name) != data.end(),
189 "Access to unknown named array \"" << name <<
"\"");
197 MFEM_VERIFY( data.find(name) != data.end(),
198 "Access to unknown named array \"" << name <<
"\"");
199 return data.at(name);
205 MFEM_VERIFY( data.find(name) == data.end(),
206 "Named array \"" << name <<
"\" already exists");
208 data.insert(std::pair<std::string,
Array<T> >(name,empty_array));
221 MFEM_VERIFY( data.find(name) != data.end(),
222 "Attempting to delete unknown named array \"" << name <<
"\"");
247 os << data.size() <<
'\n';
248 for (
auto const &it : data)
250 os <<
'"' << it.first <<
'"' <<
'\n' << it.second.Size() <<
'\n';
251 it.second.Print(os, width > 0 ? width : it.second.Size());
261 std::string ArrayLine, ArrayName;
262 for (
int i=0; i < NumArrays; i++)
265 getline(in, ArrayLine);
267 std::size_t q0 = ArrayLine.find(
'"');
268 std::size_t q1 = ArrayLine.rfind(
'"');
270 if (q0 != std::string::npos && q1 > q0)
273 ArrayName = ArrayLine.substr(q0+1,q1-q0-1);
278 q1 = ArrayLine.find(
' ');
279 ArrayName = ArrayLine.substr(0,q1-1);
283 data[ArrayName].Load(in, 0);
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...
bool operator==(const Array< T > &LHS, const Array< T > &RHS)