25#include "bitpit_operators.hpp"
40 std::ios::fmtflags streamFlags(str.flags());
42 str << std::setprecision(8) << std::scientific;
45 str.flags(streamFlags);
55void flushASCII(std::fstream &str,
const std::vector<data_T> &data)
68void flushASCII(std::fstream &str,
int elements_per_line,
const std::vector<data_T> &data)
78 lines = (nr - 1) /elements_per_line + 1;
80 std::ios::fmtflags streamFlags(str.flags());
82 str << std::setprecision(8) << std::scientific;
85 this_line = std::min(elements_per_line, nr - k);
87 for (j=0; j<this_line; j++) {
100 str.flags(streamFlags);
110template<
class data_T,
size_t d >
111void flushASCII(std::fstream &str,
const std::array<data_T,d> &data)
124template<
class data_T,
size_t d >
125void flushASCII(std::fstream &str,
int elements_per_line,
const std::array<data_T,d> &data)
127 int i(0), j(0), k(0);
130 int lines, this_line;
135 lines = nr /elements_per_line;
137 std::ios::fmtflags streamFlags(str.flags());
139 str << std::setprecision(8) << std::scientific;
142 this_line = std::min(elements_per_line, nr - k);
143 for (j=0; j<this_line; j++) {
156 str.flags(streamFlags);
167template<
class data_T>
168void flushASCII(std::fstream &str,
int elements_per_line,
const data_T *data,
int nr)
170 int i(0), j(0), k(0);
172 int lines, this_line;
176 lines = nr /elements_per_line;
178 std::ios::fmtflags streamFlags(str.flags());
180 str << std::setprecision(8) << std::scientific;
183 this_line = std::min(elements_per_line, nr - k);
184 for (j = 0; j < this_line; j++) {
197 str.flags(streamFlags);
209template<
class data_T>
214 int i(0), j(0), k(0);
217 int lines, this_line;
222 lines = (nr-1) /elements_per_line + 1;
224 std::ios::fmtflags streamFlags(str.flags());
226 str << std::setprecision(8) << std::scientific;
230 this_line = std::min(elements_per_line, nr - k);
232 for (j=0; j<this_line; j++) {
249 str.flags(streamFlags);
259template<
class data_T>
263 nbytes =
sizeof(data_T);
265 str.write(
reinterpret_cast<const char*
>(&data), nbytes);
275template<
class data_T>
276void flushBINARY(std::fstream &str,
const std::vector<data_T> &data)
280 nbytes =
sizeof(data_T) * nr;
282 str.write(
reinterpret_cast<const char*
>(&data[0]), nbytes);
291template<
class data_T>
292void flushBINARY(std::fstream &str,
const std::vector<std::vector<data_T>> &data)
294 for (
const auto &item : data) {
307template<
class data_T,
size_t d >
308void flushBINARY(std::fstream &str,
const std::vector<std::array<data_T,d> > &data)
312 nbytes =
sizeof(data_T) * nr * d;
314 str.write(
reinterpret_cast<const char*
>(&data[0]), nbytes);
324template<
class data_T,
size_t d >
325void flushBINARY(std::fstream &str,
const std::array<data_T,d> &data)
328 nbytes =
sizeof(data_T)*d;
330 str.write(
reinterpret_cast<const char*
>(&data[0]), nbytes);
340template<
class data_T>
344 nbytes =
sizeof(data_T) *nr;
346 str.write(
reinterpret_cast<const char*
>(data), nbytes);
357template<
class data_T>
363 for (dataItr = data.
begin(); dataItr != dataEnd; ++dataItr) {
368 for (dataItr = data.
begin(); dataItr != dataEnd; ++dataItr) {
382template<
class data_T>
385 std::vector<data_T> temp;
388 int expected, read(0);
395 std::stringstream ss(line);
403 if (read != expected) {
404 log::cout() <<
" Not expected nr of element in line" << std::endl;
405 log::cout() <<
" Expected number: "<< expected << std::endl;
406 log::cout() <<
" Actual number: "<< read << std::endl;
422template<
class data_T>
426 int expected(data.size());
431 std::stringstream ss(line);
441 while (ss.good() && read<expected) {
446 if (expected != read) {
447 log::cout() <<
" Not expected nr of element in line" << std::endl;
448 log::cout() <<
" Expected number: "<< expected << std::endl;
449 log::cout() <<
" Actual number: "<< read << std::endl;
464template<
class data_T,
size_t d >
465void lineStream(std::fstream &str, std::array<data_T,d> &data)
467 std::vector<data_T> temp;
470 int expected, read(0), i;
477 std::stringstream ss(line);
485 if (expected == read) {
486 for (i=0; i<read; i++) data[i] = temp[i];
488 log::cout() <<
" Not expected nr of element in line" << std::endl;
489 log::cout() <<
" Expected number: "<< expected << std::endl;
490 log::cout() <<
" Actual number: "<< read << std::endl;
504template<
class data_T>
507 std::vector<data_T> temp;
510 int expected, read(0), i;
517 std::stringstream ss(line);
525 if (expected == read) {
526 for (i=0; i<read; i++) data[i] = temp[i];
528 log::cout() <<
" Not expected nr of element in line" << std::endl;
529 log::cout() <<
" Expected number: "<< expected << std::endl;
530 log::cout() <<
" Actual number: "<< read << std::endl;
541template<
class data_T>
556template<
class data_T>
559 std::vector<data_T> temp;
561 typename std::vector<data_T>::iterator itrData, begData, endData;
562 typename std::vector<data_T>::iterator itrTemp, begTemp, endTemp;
564 begData = data.begin();
565 endData = data.end();
569 while (str.good() && itrData!=endData) {
573 begTemp = temp.begin();
574 endTemp = temp.end();
576 for (itrTemp=begTemp; (itrTemp!=endTemp && itrData!=endData);) {
584 if (itrData != endData) {
585 log::cout() <<
"Not enough elements found to fill vector" << std::endl;
595template<
class data_T>
596void absorbASCII(std::fstream &str, std::vector<std::vector<data_T>> &data)
599 size_t dim1= data.size();
606 typename std::vector<data_T>::iterator itrRow = data[row].begin();
607 typename std::vector<data_T>::iterator endRow = data[row].end();
609 std::vector<data_T> temp;
610 typename std::vector<data_T>::iterator itrTemp;
612 while(itrRow==endRow){
616 log::cout() <<
"all internal vectors have 0 size in absorbASCII " << std::endl;
620 itrRow = data[row].begin();
621 endRow = data[row].end();
629 for (itrTemp=temp.begin(); itrTemp!=temp.end(); ++itrTemp) {
633 while(itrRow==endRow){
640 itrRow = data[row].begin();
641 endRow = data[row].end();
646 log::cout() <<
"Not enough elements found to fill vector" << std::endl;
656template<
class data_T,
size_t d >
657void absorbASCII(std::fstream &str, std::vector<std::array<data_T,d> > &data)
663 size_t nArrays = data.size();
681template<
class data_T,
size_t d >
684 std::vector<data_T> temp;
686 typename std::array<data_T,d>::iterator itrData, begData, endData;
687 typename std::vector<data_T>::iterator itrTemp, begTemp, endTemp;
689 begData = data.begin();
690 endData = data.end();
694 while (str.good() && itrData!=endData) {
698 begTemp = temp.begin();
699 endTemp = temp.end();
701 for (itrTemp = begTemp; (itrTemp!=endTemp && itrData!=endData);) {
709 if (itrData != endData) {
710 log::cout() <<
"Not enough elements found to fill array" << std::endl;
724template<
class data_T>
727 std::vector<data_T> temp;
729 data_T *itrData, *begData, *endData;
730 typename std::vector<data_T>::iterator itrTemp, begTemp, endTemp;
737 while (str.good() && itrData!=endData) {
741 begTemp = temp.begin();
742 endTemp = temp.end();
744 for (itrTemp=begTemp; (itrTemp!=endTemp && itrData!=endData);) {
752 if (itrData != endData) {
753 log::cout() <<
"Not enough elements found to fill array" << std::endl;
763template<
class data_T>
771 while (str.good() && read) {
775 std::stringstream ss(line);
777 while (ss.good() && read) {
781 read = dataItr != dataEnd;
794template<
class data_T>
802 while (str.good() && read) {
806 std::stringstream ss(line);
808 while (ss.good() && read) {
824template<
class data_T>
828 nbytes =
sizeof(data_T);
830 str.read(
reinterpret_cast<char*
>(&data), nbytes);
839template<
class data_T>
844 nbytes =
sizeof(data_T) *nr;
846 str.read(
reinterpret_cast<char*
>(&data[0]), nbytes);
855template<
class data_T>
856void absorbBINARY(std::fstream &str, std::vector<std::vector<data_T>> &data)
858 for (
auto &item: data) {
870template<
class data_T,
size_t d >
871void absorbBINARY(std::fstream &str, std::vector<std::array<data_T,d> > &data)
875 nbytes =
sizeof(data_T) *nr *d;
877 str.read(
reinterpret_cast<char*
>(&data[0]), nbytes);
887template<
class data_T,
size_t d >
891 nbytes =
sizeof(data_T) *d;
893 str.read(
reinterpret_cast<char*
>(&data[0]), nbytes);
903template<
class data_T>
907 nbytes =
sizeof(data_T) *nr;
909 str.read(
reinterpret_cast<char*
>(data), nbytes);
920template<
class data_T>
925 for (dataItr = data.
begin(); dataItr != dataEnd; ++dataItr) {
939template<
class data_T>
947 for (n=0; n<nElements; ++n) {
id_t getId(const id_t &fallback=-1) const noexcept
const_iterator begin() const noexcept
const_iterator end() const noexcept
Iterator for the class PiercedStorage.
Metafunction for generating a pierced vector.
iterator insert(id_t id, const value_t &value)
void reserve(std::size_t n)
std::string & trim(std::string &s)
void flushASCII(std::fstream &str, const uint8_t &data)
void absorbBINARY(std::fstream &str, data_T &data)
void absorbASCII(std::fstream &str, data_T &data)
void lineStream(std::fstream &str, data_T &data)
void flushBINARY(std::fstream &str, const data_T &data)
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)