From b6e7be78f3e13275a8f217a4e01b304d97538641 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 7 Aug 2015 18:43:03 +0200 Subject: HAWD::Formatter to print dataset --- tests/hawd/CMakeLists.txt | 1 + tests/hawd/formatter.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++ tests/hawd/formatter.h | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 tests/hawd/formatter.cpp create mode 100644 tests/hawd/formatter.h diff --git a/tests/hawd/CMakeLists.txt b/tests/hawd/CMakeLists.txt index 84c41ab..071f2ba 100644 --- a/tests/hawd/CMakeLists.txt +++ b/tests/hawd/CMakeLists.txt @@ -12,6 +12,7 @@ set(lib_SRCS dataset.cpp datasetdefinition.cpp state.cpp + formatter.cpp ) set(SRCS diff --git a/tests/hawd/formatter.cpp b/tests/hawd/formatter.cpp new file mode 100644 index 0000000..9328d44 --- /dev/null +++ b/tests/hawd/formatter.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "formatter.h" + +#include +#include + +#include + +namespace HAWD +{ + +void Formatter::print(const QString &datasetName, const QStringList &cols, State &state) +{ + QDir project(state.projectPath()); + Dataset dataset(datasetName, state); + + if (!dataset.isValid()) { + std::cout << QObject::tr("The dataset %1 could not be loaded; try checking it with the check command").arg(datasetName).toStdString() << std::endl; + return; + } + print(dataset); +} + +void Formatter::print(Dataset &dataset, const QStringList &cols) +{ + QStringList cols; + std::cout << dataset.tableHeaders(cols).toStdString() << std::endl; + dataset.eachRow( + [cols](const Dataset::Row &row) { + std::cout << row.toString(cols).toStdString() << std::endl; + }); +} + +} diff --git a/tests/hawd/formatter.h b/tests/hawd/formatter.h new file mode 100644 index 0000000..6a53bb2 --- /dev/null +++ b/tests/hawd/formatter.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include "hawd_export.h" +#include "state.h" +#include "dataset.h" + +namespace HAWD +{ + +class HAWD_EXPORT Formatter +{ +public: + static void print(const QString &datasetName, const QStringList &cols, State &state); + static void print(Dataset &dataset, const QStringList &cols = QStringList()); +}; + +} -- cgit v1.2.3