From 1f4a944064bc42284c33e6b755353d191cf288e8 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Mon, 15 Dec 2008 07:26:12 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@1 ed2142bd-67ad-457f-ba7c-d818d4011675 --- misc/data_loaders.hpp | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 misc/data_loaders.hpp (limited to 'misc/data_loaders.hpp') diff --git a/misc/data_loaders.hpp b/misc/data_loaders.hpp new file mode 100644 index 0000000..6d2195d --- /dev/null +++ b/misc/data_loaders.hpp @@ -0,0 +1,180 @@ +#ifndef DATA_LOADERS_H +#define DATA_LOADERS_H +#include +#include +#include +#include +#include + +namespace opt_utilities +{ + template + class dl_x_y_ye; + + template + std::istream& operator>>(std::istream& ifs,dl_x_y_ye& dl); + + 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); + + template + class dl_x_y_ye + { + private: + default_data_set ds; + public: + data_set& get_data_set() + { + return ds; + } + + 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.push_back(d); + } + //return ifs; + } + + void load_from(const char* name) + { + std::ifstream ifs(name); + load_from(ifs); + + } + //friend std::istream& operator>> <>(std::istream& ifs,dl_x_y_ye& dl); + }; + + template + std::istream& operator>>(std::istream& ifs,dl_x_y_ye& dl) + { + dl.load_from(ifs); + return ifs; + } + + + template + class dl_x_xe_y_ye + { + private: + default_data_set ds; + public: + data_set& get_data_set() + { + return ds; + } + + 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.push_back(d); + } + } + + void load_from(const char* name) + { + std::ifstream ifs(name); + load_from(ifs); + } + }; + + template + std::istream& operator>>(std::istream& ifs,dl_x_xe_y_ye& dl) + { + dl.load_from(ifs); + return ifs; + } + + template + 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.push_back(d); + } + } + + void load_from(const char* name) + { + std::ifstream ifs(name); + load_from(ifs); + } + }; + + template + std::istream& operator>> (std::istream& ifs,dl_x_xu_xl_y_yu_yl& dl) + { + dl.load_from(ifs); + return ifs; + } + + + +} + + +#endif +//EOF -- cgit v1.2.2