/* * (C) Copyright 2013 ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * In applying this licence, ECMWF does not waive the privileges and immunities * granted to it by virtue of its status as an intergovernmental organisation * nor does it submit to any jurisdiction. */ #pragma once #include "atlas/array.h" //------------------------------------------------------------------------------ namespace atlas { namespace array { namespace helpers { //------------------------------------------------------------------------------ /// Helper to assign a value to an array or arrayview // template struct array_writer; //------------------------------------------------------------------------------ // Recursive function to apply value to every index template struct array_writer_impl { template static void apply(const View& arr, std::ostream& out, DimIndex... idxs) { for (idx_t i = 0; i < arr.shape(Dim); ++i) { array_writer_impl::apply(arr, out, idxs..., i); if (i < arr.shape(Dim) - 1) out << " "; } } }; // End of recursion when Dim == Rank template struct array_writer_impl { template static void apply(const View& arr, std::ostream& out, DimIndex... idxs) { out << arr(idxs...); } }; //------------------------------------------------------------------------------ struct array_writer { template static void apply(const ArrayView& arr, std::ostream& out) { array_writer_impl::apply(arr, out); // Note: no need to apply variadic pack (idxs...) } template static void apply(const LocalView& arr, std::ostream& out) { array_writer_impl::apply(arr, out); // Note: no need to apply variadic pack (idxs...) } }; //------------------------------------------------------------------------------ } // namespace helpers } // namespace array } // namespace atlas