Alexandria  2.18
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GridContainerToTable.icpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2021 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <boost/algorithm/string.hpp>
20 #include <type_traits>
21 #include <vector>
22 
23 namespace Euclid {
24 namespace GridContainer {
25 
31 template <size_t I, typename GridCellManager, typename... Axes>
33 
44  auto& axis = grid.template getAxis<I - 1>();
46  auto name = axis.name();
47  boost::replace_all(name, " ", "_");
48  description.emplace_back(name, typeid(typename GridAxisToTable<knot_t>::table_cell_t));
49 
51  }
52 
66  template <typename... Args>
69  auto& axis = grid.template getAxis<I - 1>();
70  for (size_t i = 0; i < axis.size(); ++i) {
71  GridToFitsHelper<I - 1, GridCellManager, Axes...>::unfold(grid, column_info, rows, std::make_pair(i, axis[i]), axes...);
72  }
73  }
74 
80  auto& axis = grid.template getAxis<I - 1>();
81  for (size_t i = 0; i < axis.size(); ++i) {
83  }
84  }
85 };
86 
90 template <typename GridCellManager, typename... Axes>
91 struct GridToFitsHelper<0, GridCellManager, Axes...> {
96 
100  template <typename... Args>
103  using GridType = GridContainer<GridCellManager, Axes...>;
104 
106  std::reverse(row_content.begin(), row_content.end());
107 
109  cell_traits.addCells(grid.at(axes.first...), row_content);
110 
111  rows.emplace_back(row_content, column_info);
112  }
113 };
114 
119 template <typename GridCellManager, typename... AxesTypes>
121  using GridType = GridContainer<GridCellManager, AxesTypes...>;
122  using Helper = GridToFitsHelper<std::tuple_size<typename GridType::AxesTuple>::value, GridCellManager, AxesTypes...>;
123 
125  Helper::addColumnDescriptions(GridContainer<GridCellManager, AxesTypes...>{grid.getAxesTuple()}, columns);
126 
128  cell_trais.addColumnDescriptions(*grid.begin(), columns);
129 
130  auto column_info = std::make_shared<Table::ColumnInfo>(std::move(columns));
131 
133  rows.reserve(grid.size());
134 
135  Helper::unfold(grid, column_info, rows);
136 
137  return Table::Table{std::move(rows)};
138 }
139 
140 } // end of namespace GridContainer
141 } // end of namespace Euclid
iterator begin()
Returns an iterator to the first cell of the grid.
size_t size() const
Returns the total number of cells of the grid.
const std::tuple< GridAxis< AxesTypes >...> & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
static void addColumnDescriptions(const GridContainer< GridCellManager, Axes...> &grid, std::vector< Table::ColumnDescription > &description)
Representation of a multi-dimensional grid which contains axis information.
Definition: GridContainer.h:97
static void addColumnDescriptions(const GridContainer< GridCellManager, Axes...> &, std::vector< Table::ColumnDescription > &)
T reverse(T...args)
static void unfold(const GridContainer< GridCellManager, Axes...> &grid, const std::shared_ptr< Table::ColumnInfo > &column_info, std::vector< Table::Row > &rows, std::pair< size_t, Args >...axes)
static void unfold(const GridContainer< GridCellManager, Axes...> &grid, const std::shared_ptr< Table::ColumnInfo > &column_info, std::vector< Table::Row > &rows, std::pair< size_t, Args >...axes)
static void addColumnDescriptions(const T &c, std::vector< Table::ColumnDescription > &columns)
T make_pair(T...args)
static void addCells(const T &c, std::vector< Table::Row::cell_type > &row)
T move(T...args)
Represents a table.
Definition: Table.h:49
static void unfold(const GridContainer< GridCellManager, Axes...> &grid, const std::shared_ptr< Table::ColumnInfo > &column_info, std::vector< Table::Row > &rows)
STL class.
Table::Table gridContainerToTable(const GridContainer< GridCellManager, AxesTypes...> &grid)
T reserve(T...args)
T emplace_back(T...args)