1 /* 2 * cDataFileManager.h 3 * Avida 4 * 5 * Called "data_file_manager.hh" prior to 10/18/05. 6 * Copyright 1999-2011 Michigan State University. All rights reserved. 7 * Copyright 1993-2005 California Institute of Technology 8 * 9 */ 10 11 #ifndef cDataFileManager_h 12 #define cDataFileManager_h 13 14 #include <fstream> 15 16 #ifndef cDataFile_h 17 #include "cDataFile.h" 18 #endif 19 #ifndef tDictionary_h 20 #include "tDictionary.h" 21 #endif 22 23 24 /** 25 * This class helps to manage a collection of data files. It is possible 26 * to add files, to remove files, and to access existing files by name. 27 **/ 28 29 class cDataFile; 30 class cString; 31 template <class T> class tList; // aggregate 32 33 class cDataFileManager 34 { 35 private: 36 cString m_target_dir; 37 tDictionary<cDataFile*> m_datafiles; 38 39 cDataFileManager(const cDataFileManager&); // @not_implemented 40 cDataFileManager& operator=(const cDataFileManager&); // @not_implemented 41 42 public: 43 cDataFileManager(const cString& target_dir = "", bool verbose = false); 44 ~cDataFileManager(); 45 46 /** 47 * Looks up the @ref cDataFile corresponding to the given name. If that 48 * file hasn't been created previously, it is created now. 49 * 50 * @return The @ref cDataFile. 51 * @param name The name of the file to look up/create. 52 **/ 53 cDataFile& Get(const cString & name); GetOFStream(const cString & name)54 std::ofstream& GetOFStream(const cString& name) { return Get(name).GetOFStream(); } 55 56 inline bool IsOpen(const cString& name); 57 58 void FlushAll(); 59 60 /** Removes the given file, thereby closing it. 61 * 62 * @return true if file existed, otherwise false. 63 **/ 64 bool Remove(const cString& name); 65 GetTargetDir()66 const cString& GetTargetDir() const { return m_target_dir; } 67 }; 68 69 IsOpen(const cString & name)70inline bool cDataFileManager::IsOpen(const cString & name) 71 { 72 cDataFile* found; 73 if (m_datafiles.Find(name, found)) return false; 74 return true; 75 } 76 77 78 #endif 79