# HG changeset patch # User John Tsiombikas # Date 1450539627 -7200 # Node ID 95fada20c6384f9aa388b69468e6c546671a7886 # Parent c2008ba88d03c3198c334f2818ac49989524473e foo diff -r c2008ba88d03 -r 95fada20c638 src/app.cc --- a/src/app.cc Sat Dec 19 08:00:53 2015 +0200 +++ b/src/app.cc Sat Dec 19 17:40:27 2015 +0200 @@ -257,11 +257,29 @@ case 'e': case 'E': // TODO: GUI for filename at least - if(!save_curves(stdout, &curves[0], (int)curves.size())) { + if(!save_curves("test.curves", &curves[0], (int)curves.size())) { fprintf(stderr, "failed to export curves\n"); } printf("exported %d curves\n", (int)curves.size()); break; + + case 'i': + case 'I': + { + std::list clist = load_curves("test.curves"); + if(clist.empty()) { + fprintf(stderr, "failed to import curves\n"); + } + + int num = 0; + std::list::iterator it = clist.begin(); + while(it != clist.end()) { + curves.push_back(*it++); + ++num; + } + printf("imported %d curves\n", num); + } + break; } } diff -r c2008ba88d03 -r 95fada20c638 src/curvefile.cc --- a/src/curvefile.cc Sat Dec 19 08:00:53 2015 +0200 +++ b/src/curvefile.cc Sat Dec 19 17:40:27 2015 +0200 @@ -53,12 +53,13 @@ return true; } -Curve **load_curves(const char *fname, int *countret) +std::list load_curves(const char *fname) { + std::list res; FILE *fp = fopen(fname, "r"); - if(!fp) return false; + if(!fp) return res; - Curve **res = load_curves(fp, countret); + res = load_curves(fp); fclose(fp); return res; } @@ -167,33 +168,28 @@ return 0; } -Curve **load_curves(FILE *fp, int *countret) +std::list load_curves(FILE *fp) { + std::list curves; if(!expect_str(fp, "GCURVES")) { fprintf(stderr, "load_curves: failed to load, invalid file format\n"); - return 0; + return curves; } - std::vector curves; Curve *curve; - while((curve = curve_block(fp))) { curves.push_back(curve); } int ncurves = (int)curves.size(); if(!feof(fp)) { - for(int i=0; i::iterator it = curves.begin(); + while(it != curves.end()) { + delete *it++; } - return 0; + return curves; } - Curve **carr = new Curve*[ncurves]; - for(int i=0; i +#include #include "curve.h" bool save_curves(const char *fname, const Curve * const *curves, int count); bool save_curves(FILE *fp, const Curve * const *curves, int count); -Curve **load_curves(const char *fname, int *countret); -Curve **load_curves(FILE *fp, int *countret); +std::list load_curves(const char *fname); +std::list load_curves(FILE *fp); #endif // CURVEFILE_H_ \ No newline at end of file