1 /* 2 * file-utils.h 3 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath 4 * DIN Is Noise is released under GNU Public License 2.0 5 * For more information, please visit https://dinisnoise.org/ 6 */ 7 #ifndef __fileutils 8 #define __fileutils 9 10 #include <fstream> 11 #include <string> 12 13 extern std::string user_data_dir; 14 15 struct file_in { 16 std::ifstream f; 17 int opened; file_infile_in18 file_in (const std::string& fn) : opened (0) { 19 f.open ((user_data_dir + fn).c_str(), std::ios::in); 20 opened = !f.fail (); 21 } operatorfile_in22 ifstream& operator() () {return f;} 23 }; 24 25 struct file_out { 26 std::ofstream f; file_outfile_out27 file_out (const std::string& fn) { 28 f.open ((user_data_dir + fn).c_str(), std::ios::out); 29 } operatorfile_out30 ofstream& operator() () {return f;} 31 }; 32 #endif 33