Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dataIO_Text.h
Go to the documentation of this file.
1 
14 #ifndef DATAIO_TEXT_INCLUDED
15 #define DATAIO_TEXT_INCLUDED
16 
17 #include "dataIO.h"
18 #include <string>
19 using std::string;
20 
21 #include <fstream>
22 using std::fstream;
23 
24 enum
25 {
27 };
28 
30 
44 class DataIO_Text : public DataIO
45 {
46  public:
49 
50  virtual void read_file(double *v, const size_t n, const string& f)
51  { return read_file_base(v, n, f); }
52  virtual void write_file(const double *v, const size_t n, const string& f, const bool append = true)
53  { return write_file_base(v, n, f, append); }
54 
55  virtual void read_file(dcomplex *v, const size_t n, const string& f)
56  { return read_file_base(v, n, f); }
57  virtual void write_file(const dcomplex *v, const size_t n, const string& f, const bool append = true)
58  { return write_file_base(v, n, f, append); }
59 
60  virtual void read_file(std::vector<double>& v, const string& f)
61  { return read_file_base(&v[0], v.size(), f); }
62  virtual void write_file(const std::vector<double>& v, const string& f, const bool append = true)
63 // { return write_file_base(&v[0], v.size(), f, append); }
64  { // workaround for standard-compliant definition of operator[]
65  std::vector<double>& p = const_cast<std::vector<double>&>(v);
66 
67  return write_file_base(&p[0], v.size(), f, append);
68  }
69 
70  virtual void read_file(std::vector<dcomplex>& v, const string& f)
71  { return read_file_base(&v[0], v.size(), f); }
72  virtual void write_file(const std::vector<dcomplex>& v, const string& f, const bool append = true)
73 // { return write_file_base(&v[0], v.size(), f, append); }
74  {
75  std::vector<dcomplex>& p = const_cast<std::vector<dcomplex>&>(v);
76 
77  return write_file_base(&p[0], v.size(), f, append);
78  }
79 
80  void set_parameter(const int precision) { m_format_precision = precision; }
81 
82  private:
84 
85  template<typename T>
86  void read_file_base(T *v, const size_t n, const string&);
87 
88  template<typename T>
89  void write_file_base(const T *v, const size_t n, const string&, const bool append = true);
90 
91  template<typename T>
92  inline void fetch_data(T& v, fstream& fs);
93 
94  template<typename T>
95  inline void store_data(const T& v, fstream& fs);
96 };
97 
98 #include "dataIO_Text_impl.h"
99 #endif /* DATAIO_TEXT_INCLUDED */
void read_file_base(T *v, const size_t n, const string &)
void store_data(const T &v, fstream &fs)
int m_format_precision
Definition: dataIO_Text.h:83
virtual void write_file(const dcomplex *v, const size_t n, const string &f, const bool append=true)
Definition: dataIO_Text.h:57
DataIO_Text class for general file I/O in plain Text format.
Definition: dataIO_Text.h:44
virtual void read_file(std::vector< dcomplex > &v, const string &f)
Definition: dataIO_Text.h:70
virtual void write_file(const std::vector< double > &v, const string &f, const bool append=true)
Definition: dataIO_Text.h:62
void set_parameter(const int precision)
Definition: dataIO_Text.h:80
virtual void read_file(double *v, const size_t n, const string &f)
Definition: dataIO_Text.h:50
void write_file_base(const T *v, const size_t n, const string &, const bool append=true)
virtual void read_file(std::vector< double > &v, const string &f)
Definition: dataIO_Text.h:60
void fetch_data(T &v, fstream &fs)
virtual void write_file(const std::vector< dcomplex > &v, const string &f, const bool append=true)
Definition: dataIO_Text.h:72
virtual void write_file(const double *v, const size_t n, const string &f, const bool append=true)
Definition: dataIO_Text.h:52
DataIO class for file I/O of general collection of data.
Definition: dataIO.h:38
virtual void read_file(dcomplex *v, const size_t n, const string &f)
Definition: dataIO_Text.h:55