diff --git a/src/lib/stat/data.hpp b/src/lib/stat/data.hpp index 65dcfbf13..1478116d9 100644 --- a/src/lib/stat/data.hpp +++ b/src/lib/stat/data.hpp @@ -71,6 +71,8 @@ ** ** std::vector& counters = daz.n.data; ** \endcode + ** + ** @see DataCSV_test ** */ @@ -240,7 +242,7 @@ namespace stat{ fs::path filename_; public: - DataFile(fs::path csvFile) + DataFile(fs::path csvFile ="") : filename_{fs::consolidated (csvFile)} { loadData(); @@ -334,6 +336,9 @@ namespace stat{ save (size_t lineLimit =std::numeric_limits::max() ,bool backupOld =false) { + if (filename_.empty()) + throw error::Logic{"Unable to save DataFile without filename given."}; + fs::path newFilename{filename_}; newFilename += ".tmp"; @@ -355,6 +360,22 @@ namespace stat{ } // lock onto absolute path + void + saveAs (fs::path newStorage + ,size_t lineLimit =std::numeric_limits::max()) + { + newStorage = fs::consolidated (newStorage); + if (fs::exists(newStorage)) + throw error::Invalid{_Fmt{"Storing DataFile rejected: target %s exists already"} + % newStorage}; + if (not (newStorage.parent_path().empty() + or fs::exists(newStorage.parent_path()))) + throw error::Invalid{_Fmt{"DataFile(%s) placed into nonexistent directory %s"} + % newStorage.filename() % newStorage.parent_path()}; + filename_ = newStorage; + save (lineLimit); + } + private: /* === Implementation === */ diff --git a/tests/library/stat/data-csv-test.cpp b/tests/library/stat/data-csv-test.cpp index e04135bbd..a72c54cec 100644 --- a/tests/library/stat/data-csv-test.cpp +++ b/tests/library/stat/data-csv-test.cpp @@ -31,11 +31,13 @@ //#include "lib/time/timevalue.hpp" //#include "lib/error.hpp" //#include "lib/util-foreach.hpp" +#include "lib/util.hpp" #include "lib/format-cout.hpp" ///////////////////////TODO #include "lib/test/diagnostic-output.hpp" ///////////////////////TODO //#include -//#include +#include +#include //using lumiera::Error; //using lumiera::LUMIERA_ERROR_EXCEPTION; @@ -45,21 +47,37 @@ //using boost::algorithm::is_lower; //using boost::algorithm::is_digit; +using util::isnil; //using std::function; -//using std::string; +using std::string; +using std::vector; namespace lib { namespace stat{ namespace test{ - template - class Wrmrmpft + namespace {//Setup for test + + /** Define the layout of a data row */ + struct TableForm { - T tt_; + Column id{"ID"}; + Column val{"Value"}; + Column off{"Offset"}; + + auto allColumns() + { return std::tie(id + ,val + ,off + ); + } }; + + using TestTab = DataFile; + + }//(End)Test setup - struct Murpf { }; /***********************************************************//** @@ -74,17 +92,43 @@ namespace test{ void run (Arg) { + simpleUsage(); checkGarbageStr(); - checkTypeDisplay(); checkThrowChecker(); checkLocalManipulation(); } - /** @test prints "sizeof()" including some type name. */ + /** @test add rows and data to a table without filename. */ void - checkTypeDisplay () + simpleUsage () { + TestTab tab; + CHECK (isnil (tab)); + tab.newRow(); + CHECK (not isnil (tab)); + CHECK (1 == tab.size()); + CHECK ( "" == string{tab.id}); + CHECK (0.0 == tab.val); + CHECK ( 0 == tab.off); + tab.id = "one"; + tab.val = 1.0; + + tab.dupRow(); + CHECK (2 == tab.size()); + CHECK ("one" == string{tab.id}); + CHECK ( 1.0 == tab.val); + CHECK ( 0 == tab.off); + + tab.id = "two"; + tab.val = 5.0; + tab.off = -23; + CHECK ("two" == string{tab.id}); + CHECK ( 5.0 == tab.val); + CHECK ( -23 == tab.off); + + CHECK (tab.off.header == "Offset"); + CHECK (tab.off.data == vector({0,-23})); } @@ -93,6 +137,7 @@ namespace test{ void checkGarbageStr() { + UNIMPLEMENTED("Rabäääääh"); } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 2518782c3..0d2ab6ca6 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -112041,6 +112041,29 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + +

+ Das ist naheliegend und kompromittiert das Design nicht wesentlich; File-Operationen können ohnehin immer Fehler auslösen, und da ein Pfad invalid sein kann, ist auch das Original-Design der Tabelle in dieser Hinsicht inhärent stateful. +

+ + +
+ + + + + + @@ -112077,6 +112100,13 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + +