Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Src/Base/AMReX_Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ box_write (std::ostream& os,
int dim)
{
os << '(';
int_vector_write(os, smallend, dim) << ' ';
int_vector_write(os, bigend, dim) << ' ';
int_vector_write(os, type, dim) << ')';
T_vector_write(os, smallend, dim) << ' ';
T_vector_write(os, bigend, dim) << ' ';
T_vector_write(os, type, dim) << ')';

if (os.fail()) {
amrex::Error("operator<<(ostream&,Box&) failed");
Expand Down Expand Up @@ -58,28 +58,28 @@ box_read (std::istream& is,

if (c == '(')
{
int_vector_read(is, smallend, dim);
int_vector_read(is, bigend, dim);
T_vector_read(is, smallend, dim);
T_vector_read(is, bigend, dim);
is >> c;
// Read an optional IndexType
is.putback(c);
if ( c == '(' )
{
int_vector_read(is, type, dim);
T_vector_read(is, type, dim);
}
is.ignore(BL_IGNORE_MAX,')');
}
else if (c == '<')
{
is.putback(c);
int_vector_read(is, smallend, dim);
int_vector_read(is, bigend, dim);
T_vector_read(is, smallend, dim);
T_vector_read(is, bigend, dim);
is >> c;
// Read an optional IndexType
is.putback(c);
if ( c == '<' )
{
int_vector_read(is, type, dim);
T_vector_read(is, type, dim);
}
//is.ignore(BL_IGNORE_MAX,'>');
}
Expand Down
113 changes: 109 additions & 4 deletions Src/Base/AMReX_IntVect.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define AMREX_INTVECT_H_
#include <AMReX_Config.H>

#include <AMReX.H>
#include <AMReX_INT.H>
#include <AMReX_SPACE.H>
#include <AMReX_Array.H>
Expand Down Expand Up @@ -41,6 +42,97 @@ int coarsen (int i) noexcept
return (i<0) ? -std::abs(i+1)/ratio-1 : i/ratio;
}

/// \cond DOXYGEN_IGNORE
namespace detail
{
template <typename T>
std::ostream& T_vector_write (std::ostream& os, const T* data, int dim)
{
os << '(' << data[0];
for (int i = 1; i < dim; ++i) {
os << ',' << data[i];
}
os << ')';
if (os.fail()) {
amrex::Error("operator<<(ostream&,[Int|Real]Vect&) failed");
}
return os;
}

template <typename T>
std::istream& T_vector_read (std::istream& is, T* data, int dim)
{
is >> std::ws;
char c;
is >> c;

for (int i = 0; i < dim; ++i) {
data[i] = T(0);
}

if (c == '(')
{
int component = 0;
bool need_comma = false;

while (true) {
is >> std::ws;
int ic = is.peek();

if (ic == std::char_traits<char>::eof()) {
if (component == 0) {
amrex::Error("operator>>(ostream&,[Int|Real]Vect&): missing first component");
} else {
amrex::Error("operator>>(ostream&,[Int|Real]Vect&): premature EOF");
}
}

if (ic == static_cast<int>(')')) {
is.get();
if (component == 0) {
amrex::Error("operator>>(ostream&,[Int|Real]Vect&): missing first component");
}
break;
}

if (need_comma) {
if (ic != static_cast<int>(',')) {
amrex::Error("operator>>(ostream&,[Int|Real]Vect&): expected ',' or ')'");
}
is.get();
is >> std::ws;
}

T value{};
if (!(is >> value)) {
if (component == 0) {
amrex::Error("operator>>(ostream&,[Int|Real]Vect&): missing first component");
} else {
amrex::Error("operator>>(ostream&,[Int|Real]Vect&): premature EOF");
}
}

if (component < dim) {
data[component] = value;
}
++component;
need_comma = true;
}
}
else
{
amrex::Error("operator>>(ostream&,[Int|Real]Vect&): expected '('");
}

if (is.fail()) {
amrex::Error("operator>>(ostream&,[Int|Real]Vect&) failed");
}

return is;
}
}
/// \endcond

/**
* \class amrex::IntVectND
* \ingroup amrex_index_space
Expand Down Expand Up @@ -1107,8 +1199,6 @@ Dim3 coarsen (Dim3 const& fine, IntVectND<dim> const& ratio) noexcept

/// \cond DOXYGEN_IGNORE
namespace detail {
std::ostream& int_vector_write (std::ostream& os, const int* iv, int dim);
std::istream& int_vector_read (std::istream& is, int* iv, int dim);

template<int dim>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
Expand Down Expand Up @@ -1143,18 +1233,33 @@ namespace detail {
}
/// \endcond

/**
* \brief Streams an IntVectND as a parenthesized, comma-separated tuple.
*
* The output format is `(v0,v1,...,v{dim-1})`.
*/
template<int dim>
std::ostream&
operator<< (std::ostream& os, const IntVectND<dim>& iv)
{
return detail::int_vector_write(os, iv.begin(), dim);
return detail::T_vector_write(os, iv.begin(), dim);
}

/**
* \brief Extracts an IntVectND from the canonical parenthesized tuple syntax.
*
* Accepts `(v0,v1,...,v{dim-1})` surrounded by optional whitespace.
* Missing trailing components are filled with zero, and any additional
* comma-separated values beyond `dim` are syntactically validated and then
* ignored so that higher-dimensional files are compatible with
* lower-dimensional readers. Any structural or numeric errors will result
* in `amrex::Error`.
*/
template<int dim>
std::istream&
operator>> (std::istream& is, IntVectND<dim>& iv)
{
return detail::int_vector_read(is, iv.begin(), dim);
return detail::T_vector_read(is, iv.begin(), dim);
}

/**
Expand Down
68 changes: 0 additions & 68 deletions Src/Base/AMReX_IntVect.cpp

This file was deleted.

20 changes: 16 additions & 4 deletions Src/Base/AMReX_RealVect.H
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,6 @@ RealVectND<dim> scale (const RealVectND<dim>& p, Real s) noexcept {

/// \cond DOXYGEN_IGNORE
namespace detail {
std::ostream& real_vector_write (std::ostream& os, const Real* p, int dim);
std::istream& real_vector_read (std::istream& is, Real* p, int dim);

template<int dim>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr
Expand Down Expand Up @@ -1170,18 +1168,32 @@ namespace detail {
}
/// \endcond

/**
* \brief Streams a RealVectND as a parenthesized list of comma-separated
* Real values.
*
* The output form is `(r0,r1,...,r{dim-1})`.
*/
template<int dim>
std::ostream&
operator<< (std::ostream& os, const RealVectND<dim>& p)
{
return detail::real_vector_write(os, p.begin(), dim);
return detail::T_vector_write(os, p.begin(), dim);
}

/**
* \brief Parses a RealVectND from the same `(r0,r1,...,r{dim-1})` tuple syntax.
*
* Whitespace around tokens is skipped, missing trailing entries are set to
* zero, and any additional comma-delimited values after the requested
* dimension are validated then discarded. Invalid tuple structure or
* values will raise `amrex::Error`.
*/
template<int dim>
std::istream&
operator>> (std::istream& is, RealVectND<dim>& p)
{
return detail::real_vector_read(is, p.begin(), dim);
return detail::T_vector_read(is, p.begin(), dim);
}

/**
Expand Down
62 changes: 0 additions & 62 deletions Src/Base/AMReX_RealVect.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions Src/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ foreach(D IN LISTS AMReX_SPACEDIM)
AMReX_BoxIterator.H
AMReX_Dim3.H
AMReX_IntVect.H
AMReX_IntVect.cpp
AMReX_IndexType.H
AMReX_IndexType.cpp
AMReX_Loop.H
Expand All @@ -123,7 +122,6 @@ foreach(D IN LISTS AMReX_SPACEDIM)
AMReX_RealBox.H
AMReX_RealBox.cpp
AMReX_RealVect.H
AMReX_RealVect.cpp
# Unions of rectangle -----------------------------------------------------
AMReX_BoxList.H
AMReX_BoxList.cpp
Expand Down
Loading
Loading