00001 // -*- c++ -*- 00002 00003 // This file is part of the Collective Variables module (Colvars). 00004 // The original version of Colvars and its updates are located at: 00005 // https://github.com/Colvars/colvars 00006 // Please update all Colvars source files before making any changes. 00007 // If you wish to distribute your changes, please submit them to the 00008 // Colvars repository at GitHub. 00009 00010 #ifndef COLVARPROXY_IO_H 00011 #define COLVARPROXY_IO_H 00012 00013 #include <map> 00014 #include <string> 00015 #include <iosfwd> 00016 00017 00019 class colvarproxy_io { 00020 00021 public: 00022 00024 colvarproxy_io(); 00025 00027 virtual ~colvarproxy_io(); 00028 00030 virtual bool io_available(); 00031 00033 // Returns error code 00034 virtual int get_frame(long int &); 00035 00037 // Returns error code 00038 virtual int set_frame(long int); 00039 00041 virtual int backup_file(char const *filename); 00042 00044 inline int backup_file(std::string const &filename) 00045 { 00046 return backup_file(filename.c_str()); 00047 } 00048 00050 virtual int remove_file(char const *filename); 00051 00053 inline int remove_file(std::string const &filename) 00054 { 00055 return remove_file(filename.c_str()); 00056 } 00057 00059 virtual int rename_file(char const *filename, char const *newfilename); 00060 00062 inline int rename_file(std::string const &filename, 00063 std::string const &newfilename) 00064 { 00065 return rename_file(filename.c_str(), newfilename.c_str()); 00066 } 00067 00069 inline std::string & input_prefix() 00070 { 00071 return input_prefix_str; 00072 } 00073 00075 inline std::string & output_prefix() 00076 { 00077 return output_prefix_str; 00078 } 00079 00081 inline std::string & restart_output_prefix() 00082 { 00083 return restart_output_prefix_str; 00084 } 00085 00087 inline int default_restart_frequency() const 00088 { 00089 return restart_frequency_engine; 00090 } 00091 00093 inline char const * & input_buffer() 00094 { 00095 return input_buffer_; 00096 } 00097 00102 virtual std::istream &input_stream(std::string const &input_name, 00103 std::string const description = "file/channel", 00104 bool error_on_fail = true); 00105 00107 virtual bool input_stream_exists(std::string const &input_name); 00108 00110 virtual int close_input_stream(std::string const &input_name); 00111 00113 virtual int close_input_streams(); 00114 00118 virtual std::ostream &output_stream(std::string const &output_name, 00119 std::string const description = "file/channel"); 00120 00122 virtual bool output_stream_exists(std::string const &output_name); 00123 00125 virtual int flush_output_stream(std::string const &output_name); 00126 00128 virtual int flush_output_streams(); 00129 00131 virtual int close_output_stream(std::string const &output_name); 00132 00134 virtual int close_output_streams(); 00135 00136 protected: 00137 00139 std::string input_prefix_str; 00140 00142 std::string output_prefix_str; 00143 00145 std::string restart_output_prefix_str; 00146 00148 int restart_frequency_engine; 00149 00151 std::map<std::string, std::istream *> input_streams_; 00152 00154 std::istream *input_stream_error_; 00155 00157 std::map<std::string, std::ostream *> output_streams_; 00158 00160 std::ostream *output_stream_error_; 00161 00163 char const *input_buffer_; 00164 }; 00165 00166 00167 #endif