From c866739c9464ec6638eac839e7a72ff2b1447377 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 7 Feb 2017 21:14:09 +0800 Subject: Set default error value to be 0 (original: 1) Also some style fixes --- misc/data_loaders.hpp | 119 +++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 64 deletions(-) diff --git a/misc/data_loaders.hpp b/misc/data_loaders.hpp index 7bbb757..2b4f869 100644 --- a/misc/data_loaders.hpp +++ b/misc/data_loaders.hpp @@ -6,7 +6,9 @@ #ifndef DATA_LOADERS_H #define DATA_LOADERS_H + #define OPT_HEADER + #include #include #include @@ -24,14 +26,11 @@ namespace opt_utilities template class dl_x_xe_y_ye; - template std::istream& operator>>(std::istream& ifs,dl_x_xe_y_ye& dl); - template class dl_x_xu_xl_y_yu_yl; - template std::istream& operator>> (std::istream& ifs,dl_x_xu_xl_y_yu_yl& dl); @@ -54,21 +53,21 @@ namespace opt_utilities void load_from(std::istream& ifs) { for(;;) - { - Tx x; - Tx x_err; - Ty y; - Ty y_err(1); - - ifs>>x>>y>>y_err; - - if(!ifs.good()) - { - break; - } - data d(x,y,y_err,y_err,x_err,x_err); - ds.add_data(d); - } + { + Tx x; + Tx x_err; + Ty y; + Ty y_err(0); + + ifs>>x>>y>>y_err; + + if(!ifs.good()) + { + break; + } + data d(x,y,y_err,y_err,x_err,x_err); + ds.add_data(d); + } //return ifs; } @@ -76,13 +75,11 @@ namespace opt_utilities { std::ifstream ifs(name); load_from(ifs); - } //friend std::istream& operator>> <>(std::istream& ifs,dl_x_y_ye& dl); }; - /** stream operator */ @@ -95,7 +92,7 @@ namespace opt_utilities /** - loading data from stream with file + loading data from stream with file [x] [x error] [y] [y error] */ @@ -113,27 +110,27 @@ namespace opt_utilities void load_from(std::istream& ifs) { for(;;) - { - Tx x; - Tx x_err; - Ty y; - Ty y_err(1); - - ifs>>x>>x_err>>y>>y_err; - - if(!ifs.good()) - { - break; - } - data d(x,y,y_err,y_err,x_err,x_err); - ds.add_data(d); - } + { + Tx x; + Tx x_err; + Ty y; + Ty y_err(0); + + ifs>>x>>x_err>>y>>y_err; + + if(!ifs.good()) + { + break; + } + data d(x,y,y_err,y_err,x_err,x_err); + ds.add_data(d); + } } void load_from(const char* name) { std::ifstream ifs(name); - load_from(ifs); + load_from(ifs); } }; @@ -150,7 +147,7 @@ namespace opt_utilities /** - loading data from stream with format + loading data from stream with format [x] [x lower error] [x upper error] [y] [y lower error] [y upper error] */ @@ -158,37 +155,35 @@ namespace opt_utilities class dl_x_xu_xl_y_yu_yl { private: - default_data_set ds; public: data_set& get_data_set() { return ds; } - void load_from(std::istream& ifs) { for(;;) - { - Tx x; - Tx xl,xu; - Ty y; - Ty yl(1),yu(1); - - ifs>>x>>xu>>xl>>y>>yu>>yl; - - xu=std::abs(xu); - xl=std::abs(xl); - yu=std::abs(yu); - yl=std::abs(yl); - - if(!ifs.good()) - { - break; - } - data d(x,y,yl,yu,xl,xu); - ds.add_data(d); - } + { + Tx x; + Tx xl,xu; + Ty y; + Ty yl(0),yu(0); + + ifs>>x>>xu>>xl>>y>>yu>>yl; + + xu=std::abs(xu); + xl=std::abs(xl); + yu=std::abs(yu); + yl=std::abs(yl); + + if(!ifs.good()) + { + break; + } + data d(x,y,yl,yu,xl,xu); + ds.add_data(d); + } } void load_from(const char* name) @@ -208,11 +203,7 @@ namespace opt_utilities dl.load_from(ifs); return ifs; } - - - } - #endif //EOF -- cgit v1.2.2