Giter VIP home page Giter VIP logo

variadic_table's Introduction

VariadicTable

Used for "pretty-printing" a formatted table of data to the console.

It uses "variadic templates" to allow you to specify the types of data in each column.

Example Usage

#include "VariadicTable.h"

VariadicTable<std::string, double, int, std::string> vt({"Name", "Weight", "Age", "Brother"}, 10);

vt.addRow("Cody", 180.2, 40, "John");
vt.addRow("David", 175.3, 38, "Andrew");
vt.addRow("Robert", 140.3, 27, "Fande");

vt.print(std::cout);

Outputs:

------------------------------------------------
|  Name  |   Weight   |     Age    |  Brother  |
------------------------------------------------
| Cody   |      180.2 |         40 | John      |
| David  |      175.3 |         38 | Andrew    |
| Robert |      140.3 |         27 | Fande     |
------------------------------------------------

For more usage examples see main.C.

Installation

Just put VariadicTable.h somewhere and #include "VariadicTable.h"

Compilation

You don't need to compile this - but a simple make should work to build the main.C provided here so you can see the example usage.

variadic_table's People

Contributors

alessandro-gentilini avatar c3730915 avatar friedmud avatar lazzaro98 avatar permcody avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

variadic_table's Issues

Compile error compiling main.c

make all
Building file: ../src/main.C
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.C"
../src/main.C: In function ‘int main()’:
../src/main.C:11:42: error: converting to ‘std::tuple<std::basic_string<char, std::char_traits, std::allocator >, double, int, std::basic_string<char, std::char_traits, std::allocator > >’ from initializer list would use explicit constructor ‘constexpr std::tuple< >::tuple(_UElements&& ...) [with _UElements = {const char (&)[5], double, int, const char (&)[5]}; = void; _Elements = {std::basic_string<char, std::char_traits, std::allocator >, double, int, std::basic_string<char, std::char_traits, std::allocator >}]’
vt.addRow({"Cody", 180.2, 40, "John"});
^
../src/main.C:12:45: error: converting to ‘std::tuple<std::basic_string<char, std::char_traits, std::allocator >, double, int, std::basic_string<char, std::char_traits, std::allocator > >’ from initializer list would use explicit constructor ‘constexpr std::tuple< >::tuple(_UElements&& ...) [with _UElements = {const char (&)[6], double, int, const char (&)[7]}; = void; _Elements = {std::basic_string<char, std::char_traits, std::allocator >, double, int, std::basic_string<char, std::char_traits, std::allocator >}]’
vt.addRow({"David", 175.3, 38, "Andrew"});
^
../src/main.C:13:45: error: converting to ‘std::tuple<std::basic_string<char, std::char_traits, std::allocator >, double, int, std::basic_string<char, std::char_traits, std::allocator > >’ from initializer list would use explicit constructor ‘constexpr std::tuple< >::tuple(_UElements&& ...) [with _UElements = {const char (&)[7], double, int, const char (&)[6]}; = void; _Elements = {std::basic_string<char, std::char_traits, std::allocator >, double, int, std::basic_string<char, std::char_traits, std::allocator >}]’
vt.addRow({"Robert", 140.3, 27, "Fande"});
^
make: *** [src/main.o] Error 1

Errors when compiling samples

I get heaps of errors like this when attempting to compile the samples or a project where I have included your library.

src/main.C:11:42: error: converting to ‘std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’ from initializer list would use explicit constructor ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {const char (&)[5], double, int, const char (&)[5]}; <template-parameter-2-2> = void; _Elements = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]’
     vt.addRow({"Cody", 180.2, 40, "John"});

Any ideas on how to fix this?

compilation warnings

conversion from 'size_t' to '_Ty', possible loss of data at MSVC.

I replaced all unsigned int with size_t and the warnings are gone.

"this declaration has no storage type of class specifier"

When I copy the example exactly from the src file I get the above error.

#include "VariadicTable.h"

VariadicTable<std::string, double, int, std::string> vt({ "Name", "Weight", "Age", "Brother" });

vt.addRow({ "Cody", 180.2, 40, "John" });
vt.addRow({ "David", 175.3, 38, "Andrew" });
vt.addRow({ "Robert", 140.3, 27, "Fande" });

vt.print();

In my project, I get an error that says "too many initializer values". Different errors, but probably related to the same issue with the code. Anyone know why this might be? Specifically why the example code does not compile.

Documentation is wrong - examples cause compile errors

For people like me who copy the example and expect it to work, use this instead:

VariadicTable<std::string, double, int, std::string> vt({"Name", "Weight", "Age", "Brother"});

vt.addRow("Cody", 180.2, 40, "John");
vt.addRow("David", 175.3, 38, "Andrew");
vt.addRow("Robert", 140.3, 27, "Fande");

vt.print(cout);

Also, the example code from the comments in the .h file are wrong:
//VariadicTable<std::string, double, int, std::string> vt("Name", "Weight", "Age", "Brother");
this does not work.

Support string colors

I'd like to highlight some std::string cells in the VariadicTable with colors. For the lines I want to highlight, I'm doing

COLOR_YELLOW << "stuff" << COLOR_DEFAULT

and for all other lines, I'm doing

COLOR_DEFAULT << "stuff" << COLOR_DEFAULT

It seems like the logic for deciding the length of the horizontal bars is not consistent with the cell widths, because the table looks like the following.

Screen Shot 2023-02-23 at 4 57 42 PM

unicode support

right now it the column-width calculation breaks when multi-byte chars are used:

————————————————————————————————————————————————————————————————————————————————————————
|                    Section                    |     Self     |   Children   |  Total |
————————————————————————————————————————————————————————————————————————————————————————
| 根目录                                     |    4.525e-03 |        0.052 |   0.06 |
|   MooseApp::setup                             |    1.000e-05 |        0.037 |   0.04 |
|     FileMesh::init                            |    3.000e-06 |        0.002 |   0.00 |
|       FileMesh::readMesh                      |    1.548e-03 |        0.000 |   0.00 |
|     FileMesh::prepare                         |    5.100e-05 |        0.000 |   0.00 |
|     FEProblem::init                           |    6.700e-05 |        0.002 |   0.00 |
|       FEProblem::EquationSystems::Init        |    2.051e-03 |        0.000 |   0.00 |
|   MooseApp::execute                           |    0.000e+00 |        0.015 |   0.01 |
|     FEProblem::initialSetup                   |    3.760e-04 |        0.003 |   0.00 |
|       FEProblem::projectSolution              |    1.440e-04 |        0.000 |   0.00 |
|     FEProblem::solve                          |    1.181e-03 |        0.004 |   0.01 |
|       FEProblem::computeResidualSys           |    7.000e-06 |        0.003 |   0.00 |
|         FEProblem::computeResidualInternal    |    1.300e-05 |        0.003 |   0.00 |
|           FEProblem::computeResidualTags      |    4.900e-05 |        0.003 |   0.00 |
|             AuxiliarySystem::computeNodalVars |    2.090e-04 |        0.000 |   0.00 |
|       FEProblem::computeJacobianInternal      |    1.000e-06 |        0.001 |   0.00 |
|         FEProblem::computeJacobianTags        |    1.000e-05 |        0.001 |   0.00 |
|       Console::outputStep                     |    6.000e-05 |        0.000 |   0.00 |
|     FEProblem::outputStep                     |    8.700e-05 |        0.005 |   0.01 |
|       PerfGraphOutput::outputStep             |    4.300e-05 |        0.000 |   0.00 |
|       Exodus::outputStep                      |    5.395e-03 |        0.000 |   0.01 |
|       Console::outputStep                     |    5.800e-05 |        0.000 |   0.00 |
————————————————————————————————————————————————————————————————————————————————————————

Table broken

VariadicTable<std::string, int, double> vt({"Info", "#", "%"});

vt.addRow("Rounds", stats.rounds, 0);
vt.addRow("Doubles", stats.doubles, 98.333333);

vt.print(os);

| Info | # | % |

| Rounds | 5000 | 0 |
| Doubles | 4949 | 98.3333 |

offset with muti byte character

I had an issue with multi byte character (éèêë ÉÈÊË àâ ÀÂ Çç).

I fix it by replacing the line l.266 in prettyPrinter.hpp

Before:

return data.size();

Fix:

return std::count_if(data.begin(), data.end(),[](char c) { return (static_cast<unsigned char>(c) & 0xC0) != 0x80; } );

Fixed compiler errors in Visual Studio 2019

Initially I wasn't able to compile VariadicTable.h in my programm. Adding the following two include-statemnts solved my issue:

#include<limits>
#include<algorithm>

Maybe it's useful to some of you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.