Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94213495
aka_array_printer.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Dec 4, 19:30
Size
2 KB
Mime Type
text/x-c++
Expires
Fri, Dec 6, 19:30 (1 d, 16 h)
Engine
blob
Format
Raw Data
Handle
22715840
Attached To
rAKA akantu
aka_array_printer.hh
View Options
/**
* Copyright (©) 2019-2023 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This file is part of Akantu
*
* Akantu is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Akantu is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Akantu. If not, see <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
#include "aka_array.hh"
/* -------------------------------------------------------------------------- */
#ifndef AKANTU_AKA_ARRAY_PRINTER_HH_
#define AKANTU_AKA_ARRAY_PRINTER_HH_
namespace akantu {
/* -------------------------------------------------------------------------- */
template <class container, bool no_explicit = true> class ArrayPrinter {
public:
ArrayPrinter(const container & cont) : cont(cont) {}
void printself(std::ostream & stream, int indent = 0) const {
std::string space(indent, AKANTU_INDENT);
stream << space << "{";
for (Int i = 0; i < this->cont.size(); ++i) {
stream << this->cont[i];
if (i != this->cont.size() - 1)
stream << ", ";
}
stream << "}";
}
private:
const container & cont;
};
/* -------------------------------------------------------------------------- */
template <class T> class ArrayPrinter<Array<T>> {
public:
ArrayPrinter(const Array<T> & cont) : cont(cont) {}
void printself(std::ostream & stream, int indent = 0) const {
std::string space(indent, AKANTU_INDENT);
stream << space << "{";
for (Int i = 0; i < this->cont.size(); ++i) {
stream << "{";
for (Int j = 0; j < this->cont.getNbComponent(); ++j) {
stream << this->cont(i, j);
if (j != this->cont.getNbComponent() - 1)
stream << ", ";
}
stream << "}";
if (i != this->cont.size() - 1)
stream << ", ";
}
stream << "}";
}
private:
const Array<T> & cont;
};
template <class container>
decltype(auto) make_printer(const container & array) {
return ArrayPrinter<container>(array);
}
/* -------------------------------------------------------------------------- */
template <class T>
inline std::ostream & operator<<(std::ostream & stream,
const ArrayPrinter<T> & _this) {
_this.printself(stream);
return stream;
}
} // namespace akantu
#endif /* AKANTU_AKA_ARRAY_PRINTER_HH_ */
Event Timeline
Log In to Comment