curvedraw
diff src/curvefile.cc @ 10:95fada20c638
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 19 Dec 2015 17:40:27 +0200 |
parents | 8bf96e11ed1f |
children | 099fd7adb900 |
line diff
1.1 --- a/src/curvefile.cc Sat Dec 19 08:00:53 2015 +0200 1.2 +++ b/src/curvefile.cc Sat Dec 19 17:40:27 2015 +0200 1.3 @@ -53,12 +53,13 @@ 1.4 return true; 1.5 } 1.6 1.7 -Curve **load_curves(const char *fname, int *countret) 1.8 +std::list<Curve*> load_curves(const char *fname) 1.9 { 1.10 + std::list<Curve*> res; 1.11 FILE *fp = fopen(fname, "r"); 1.12 - if(!fp) return false; 1.13 + if(!fp) return res; 1.14 1.15 - Curve **res = load_curves(fp, countret); 1.16 + res = load_curves(fp); 1.17 fclose(fp); 1.18 return res; 1.19 } 1.20 @@ -167,33 +168,28 @@ 1.21 return 0; 1.22 } 1.23 1.24 -Curve **load_curves(FILE *fp, int *countret) 1.25 +std::list<Curve*> load_curves(FILE *fp) 1.26 { 1.27 + std::list<Curve*> curves; 1.28 if(!expect_str(fp, "GCURVES")) { 1.29 fprintf(stderr, "load_curves: failed to load, invalid file format\n"); 1.30 - return 0; 1.31 + return curves; 1.32 } 1.33 1.34 - std::vector<Curve*> curves; 1.35 Curve *curve; 1.36 - 1.37 while((curve = curve_block(fp))) { 1.38 curves.push_back(curve); 1.39 } 1.40 1.41 int ncurves = (int)curves.size(); 1.42 if(!feof(fp)) { 1.43 - for(int i=0; i<ncurves; i++) { 1.44 - delete curves[i]; 1.45 + std::list<Curve*>::iterator it = curves.begin(); 1.46 + while(it != curves.end()) { 1.47 + delete *it++; 1.48 } 1.49 - return 0; 1.50 + return curves; 1.51 } 1.52 1.53 - Curve **carr = new Curve*[ncurves]; 1.54 - for(int i=0; i<ncurves; i++) { 1.55 - carr[i] = curves[i]; 1.56 - } 1.57 - *countret = ncurves; 1.58 - return carr; 1.59 + return curves; 1.60 } 1.61