20 #ifndef GEOS_COMMON_FORMAT_TABLE_TABLEDATA_HPP
21 #define GEOS_COMMON_FORMAT_TABLE_TABLEDATA_HPP
25 #include "common/format/Format.hpp"
26 #include "TableTypes.hpp"
106 template<
typename ... Args >
107 void addRow( Args
const & ... args );
130 { m_errors->clear(); }
155 {
return *m_errors; }
162 {
return *m_errors; }
169 template<
typename SortingFunc >
170 void sort( SortingFunc sortingFunctor )
172 std::sort( m_rows.begin(), m_rows.end(), sortingFunctor );
180 std::unique_ptr< geos::TableErrorListing > m_errors;
214 template<
typename T >
227 bool columnMajorValues );
244 bool columnMajorValues,
265 m_columnValues.clear();
274 std::set< real64 > m_columnValues;
276 std::unique_ptr< geos::TableErrorListing > m_errors = std::make_unique< geos::TableErrorListing >();
283 template<
typename T >
286 template<
typename ... Args >
291 static_assert( has_formatter_v< decltype(args) > ||
isCellType< std::decay_t< decltype(args) > >,
"Argument passed in addRow cannot be converted to string nor a CellType" );
292 if constexpr (std::is_same_v< Args, CellType >) {
293 cells.push_back( { args,
string() } );
295 else if constexpr (std::is_floating_point_v< std::decay_t< decltype(args) > >) {
296 if( !
getErrorsList().hasErrors() && (std::isnan( args ) || std::isinf( args )))
298 m_errors->addError(
"Warning : Invalid values detected (nan/inf)." );
300 cells.push_back( {CellType::Value, GEOS_FMT(
"{}", args )} );
304 cells.push_back( {CellType::Value, GEOS_FMT(
"{}", args )} );
318 template<
typename T >
321 static_assert( has_formatter_v< decltype(value) >,
"Argument passed in addCell cannot be converted to string" );
322 m_columnValues.insert( columnValue );
323 m_data.get_inserted( rowValue ).get_inserted( columnValue ) = GEOS_FMT(
"{}", value );
327 namespace basicSerialization
334 template<
typename T >
336 {
return sizeof(T); }
344 {
return sizeof(string::size_type) + str.size(); }
352 template<
typename T,
353 std::enable_if_t< std::is_trivially_copyable_v< T >,
bool > =
true >
370 template<
typename T,
371 std::enable_if_t< std::is_trivially_copyable_v< T >,
bool > =
true >
384 namespace tableDataSorting
400 template<
typename T,
401 std::enable_if_t< std::is_trivially_copyable_v< T >,
bool > >
402 void basicSerialization::serializePrimitive( T
const data,
407 out.insert( out.end(), begin, end );
410 template<
typename T,
411 std::enable_if_t< std::is_trivially_copyable_v< T >,
bool > >
412 void basicSerialization::deserializePrimitive( T & data,
416 if( ptr +
sizeof(T)> end )
417 throw std::runtime_error(
"Buffer overflow" );
419 data = *
reinterpret_cast< T
const *
>(ptr);
bool positiveNumberStringComp(string_view a, string_view b)
Compare two string number string by in ascending numerical order.
unsigned long sizeOfPrimitive(T)
void serializeString(string const &data, stdVector< buffer_unit_type > &out)
Write a string value to the buffer.
void deserializeString(string &str, buffer_unit_type const *&ptr, buffer_unit_type const *end)
Reads a string value from the buffer and advances the pointer.
void deserializePrimitive(T &data, buffer_unit_type const *&ptr, buffer_unit_type const *end)
Reads the data from the buffer and advances the pointer.
unsigned long sizeOfString(string const &str)
Returns the size of a string (header size + content).
Enumerates the Units that are in use in GEOS and regroups useful conversion and formatting functions.
Class for managing 2D table m_data.
real64 RowType
Type real64 for a row.
void collectTableValues(arrayView1d< real64 const > dim0AxisCoordinates, arrayView1d< real64 const > dim1AxisCoordinates, arrayView1d< real64 const > values, bool columnMajorValues)
Collects all the values needed to build the table.
void clear()
Clear all data stored in TableData.
void addCell(RowType rowValue, ColumnType columnValue, T const &value)
Add a cell to the table. If necessary, create automatically the containing column & row.
TableData2D::TableDataHolder convertTable2D(arrayView1d< real64 const > coordX, arrayView1d< real64 const > coordY, string_view rowAxisDescription, string_view columnAxisDescription, arrayView1d< real64 const > const values, bool columnMajorValues, string_view valueDescription)
Convert from 2D axis/values a structure the information needed to build a TableFormatter.
TableDataHolder buildTableData(string_view dataDescription, string_view rowFmt="{}", string_view columnFmt="{}") const
real64 ColumnType
Type real64 for a column.
Class for managing table data.
DataRows const & getCellsData() const
size_t getSerializedSize() const
Returns the total serialized byte size of all rows in the table.
stdVector< string > const & getErrorMsgs() const
Get all error messages.
void clear()
Reset data in the table.
void addRow(stdVector< CellData > const &row)
Add a row to the table.
void clearErrors()
Remove all errors.
TableErrorListing & getErrorsList()
Get all error messages.
void serialize(stdVector< buffer_unit_type > &serializedTableData) const
Serializes the tableData into the output buffer.
void addRow(Args const &... args)
Add a row to the table. The values passed to addRow (can be any type).
DataRows & getCellsData()
void sort(SortingFunc sortingFunctor)
Sorts the rows using a custom comparator functor.
bool operator<(TableData const &other) const
Lexicographic comparison operator, can be used for ordering in containers.
bool operator==(TableData const &other) const
Equality comparison of all cells.
void addSeparator()
Add a line separator to the table You must have filled values in TableData before using it.
stdVector< stdVector< CellData > > DataRows
Alias for table data rows with cells values.
TableErrorListing const & getErrorsList() const
Get all error messages.
Class for retrieving errors in the table classes.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
std::string string
String type.
double real64
64-bit floating point type.
constexpr bool isCellType
Trait to check is the args is a special type of cell.
internal::StdMapWrapper< std::map< Key, T, Compare, Allocator >, USE_STD_CONTAINER_BOUNDS_CHECKING > stdMap
signed char buffer_unit_type
Type stored in communication buffers.
CellType
The different type a cell can handle.
std::string_view string_view
String type.
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
Struct containing conversion informations.
stdVector< string > headerNames
TableData tableData
TableData to be built.
Representing a single cell's data within a TableData row.
void serialize(stdVector< buffer_unit_type > &out) const
Serializes the cell type and value into the output buffer.
string value
The cell value.
size_t getSerializedSize() const
CellType type
The cell type.