1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/common/include/villas/table.hpp
Steffen Vogel 7d10544d79 Apply clang-format changes
Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
2024-02-29 18:58:07 +01:00

69 lines
1.4 KiB
C++

/* Print fancy tables.
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <string>
#include <vector>
#include <villas/log.hpp>
namespace villas {
class Table;
class TableColumn {
friend Table;
public:
enum class Alignment { LEFT, RIGHT };
protected:
int _width; // The real width of this column. Calculated by Table::resize().
int width; // Width of the column.
public:
TableColumn(int w, enum Alignment a, const std::string &t,
const std::string &f, const std::string &u = "")
: _width(0), width(w), title(t), format(f), unit(u), align(a) {}
std::string title; // The title as shown in the table header.
std::string format; // The format which is used to print the table rows.
std::string unit; // An optional unit which will be shown in the table header.
enum Alignment align;
int getWidth() const { return _width; }
};
class Table {
protected:
int resize(int w);
int width;
std::vector<TableColumn> columns;
Logger logger;
public:
Table(Logger log, const std::vector<TableColumn> &cols)
: width(-1), columns(cols), logger(log) {}
// Print a table header consisting of \p n columns.
void header();
// Print table rows.
void row(int count, ...);
int getWidth() const { return width; }
};
} // namespace villas