Table.hpp
Go to the documentation of this file.
1 /****
2  * Table.hpp - Additional definitions to assist with table creation using an Array
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the FlashString Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  * @author: 2018 - Mikee47 <mike@sillyhouse.net>
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "ArrayPrinter.hpp"
25 
32 namespace FSTR
33 {
42 template <typename ElementType, size_t Columns> class TableRow
43 {
44 public:
50  ElementType operator[](size_t index) const
51  {
52  return values[index];
53  }
54 
59  size_t length() const
60  {
61  return Columns;
62  }
63 
67  size_t printTo(Print& p) const
68  {
69  return FSTR::ArrayPrinter<TableRow>(*this).printTo(p);
70  }
71 
75  static TableRow empty()
76  {
77  return TableRow{};
78  }
79 
80  /* Private data */
81 
82  ElementType values[Columns];
83 };
84 
85 } // namespace FSTR
86 
Class template to provide a simple way to print the contents of an array.
Definition: ArrayPrinter.hpp:40
size_t printTo(Print &p) const
Definition: ArrayPrinter.hpp:46
Class template to define the row of a table.
Definition: Table.hpp:43
static TableRow empty()
Return a TableRow instance to be used for invalid or empty values.
Definition: Table.hpp:75
ElementType operator[](size_t index) const
Array operator.
Definition: Table.hpp:50
ElementType values[Columns]
Definition: Table.hpp:82
size_t length() const
Get number of columns.
Definition: Table.hpp:59
size_t printTo(Print &p) const
Print a row using Array Printer.
Definition: Table.hpp:67
Provides formatted output to stream.
Definition: Print.h:37
Definition: Array.hpp:108