00001 #pragma ident "$Id: TimeNamedFileStream.hpp 1161 2008-03-27 17:16:22Z ckiesch $"
00002
00008 #ifndef GPSTK_TIME_NAMED_FILE_STREAM_HPP
00009 #define GPSTK_TIME_NAMED_FILE_STREAM_HPP
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include <string>
00048
00049 #include "Exception.hpp"
00050 #include "DayTime.hpp"
00051 #include "FFStream.hpp"
00052
00053 namespace gpstk
00054 {
00057
00058 template <class BaseStream>
00059 class TimeNamedFileStream : public BaseStream
00060 {
00061 public:
00062
00063 TimeNamedFileStream()
00064 : omode(std::ios::in), debugLevel(0)
00065 {};
00066
00067 TimeNamedFileStream(
00068 const std::string fs,
00069 std::ios::openmode mode = std::ios::in)
00070 : filespec(fs), omode(mode), debugLevel(0)
00071 {};
00072
00073 virtual ~TimeNamedFileStream(void) {};
00074
00075
00078 virtual void open(const char* fs, std::ios::openmode mode = std::ios::in)
00079 {
00080 setFilespec(fs);
00081 omode = mode;
00082 };
00083
00084
00085 void setFilespec(const std::string fs)
00086 { filespec=fs; currentFilename=""; }
00087
00088
00089 std::string getFilespec(void) const
00090 { return filespec;}
00091
00092
00093
00094 std::string getCurrentFilename(void) const
00095 { return currentFilename; };
00096
00097
00098
00099 DayTime getCurrentTime(void) const
00100 { return currentTime; };
00101
00102
00103
00104 bool updateFileName(const DayTime& t=DayTime())
00105 {
00106 bool openedNewFile = false;
00107 const std::string newFilename=t.printf(filespec);
00108 if (currentFilename.size() == 0 && newFilename.size() > 0)
00109 {
00110 currentFilename = newFilename;
00111 currentTime = t;
00112 BaseStream::open(currentFilename.c_str(), omode);
00113 if (debugLevel)
00114 std::cout << "Opened " << currentFilename << std::endl;
00115 openedNewFile=true;
00116 }
00117 else if (newFilename == currentFilename)
00118 {
00119 currentTime = t;
00120 openedNewFile=false;
00121 }
00122 else
00123 {
00124 if (debugLevel)
00125 std::cout << "Closing " << currentFilename << std::endl;
00126 BaseStream::close();
00127 currentFilename = newFilename;
00128 currentTime = t;
00129 BaseStream::open(currentFilename.c_str(), omode);
00130 if (debugLevel)
00131 std::cout << "Opened " << currentFilename << std::endl;
00132 openedNewFile=true;
00133 }
00134
00135 return openedNewFile;
00136 };
00137
00138 int debugLevel;
00139
00140 private:
00142 std::string filespec;
00143
00145 std::string currentFilename;
00146
00148 DayTime currentTime;
00149
00150
00151 std::ios::openmode omode;
00152 };
00153
00155 }
00156
00157 #endif // GPSTK_TIME_NAMED_FILE_STREAM_HPP