LRAUV  revA
FileLogWriter.h
Go to the documentation of this file.
1 
10 #ifndef FILELOGWRITER_H_
11 #define FILELOGWRITER_H_
12 
13 #include "io/FileOutStream.h"
14 #include "logger/HasFilename.h"
15 #include "logger/LogWriter.h"
16 
17 class FileEncoder;
18 
28 class FileLogWriter: public LogWriter, public HasFilename
29 {
30 public:
31  enum FlushFreq
32  {
34  };
35 
43  FileLogWriter( const Str &filename, LogWriter* logWriter, const bool append =
44  false, FileEncoder* fileEncoder = NULL );
45 
51  FileLogWriter( FILE* file, LogWriter* logWriter );
52 
54  virtual ~FileLogWriter();
55 
57  virtual void resetInputs();
58 
60  virtual bool valid( void )
61  {
62  return isWritable();
63  }
64  ;
65 
67  virtual unsigned int write( const LogEntry *entry, const Unit* unit = NULL );
68 
70  virtual void endCycle();
71 
73  unsigned int getBytesInFile( void )
74  {
75  return bytesInFile_;
76  }
77  ;
78 
79  unsigned int getEntriesWritten( void )
80  {
81  return entriesWritten_;
82  }
83  ;
84 
85  virtual const Str& getFilename()
86  {
87  return filename_;
88  }
89 
90  void resetFilename( const Str& filename );
91 
93  bool isWritable( void )
94  {
95  return fileStream_.isWritable();
96  }
97  ;
98 
99  /*virtual void config( Logger& logger );*/
100 
101 protected:
102 
104  bool open( const char *filename, const bool append );
105 
107  void close( void );
108 
109  void setFlushFreq( const FlushFreq flushFreq )
110  {
111  flushFreq_ = flushFreq;
112  }
113 
115  {
116  return fileEncoder_;
117  }
118 
119  void setFilename( const Str& filename )
120  {
121  filename_ = filename;
122  }
123 
126 
127 private:
128  // Note that the copy constructor below is private and not given a body.
129  // Any attempt to call it will return a compiler error.
130  FileLogWriter( const FileLogWriter& old ); // disallow copy constructor
131 
134 
136  unsigned int entriesWritten_;
137 
139  unsigned int bytesInFile_;
140 
143 
146 
148 
150 
152 
153 };
154 
155 #endif /*FILELOGWRITER_H_*/
FileOutStream fileStream_
The output file stream.
Definition: FileLogWriter.h:133
unsigned int bytesInFile_
Total bytes written.
Definition: FileLogWriter.h:139
Wraps around another LogWriter to write LogEntries to a file.
Definition: FileLogWriter.h:28
FileLogWriter(const Str &filename, LogWriter *logWriter, const bool append=false, FileEncoder *fileEncoder=NULL)
Constructor with filename & specified flushFreq.
Definition: FileLogWriter.cpp:28
Definition: FileLogWriter.h:33
Base class for a generalized set of "log data destinations," including to files (text or binary)...
Definition: LogWriter.h:25
Contains the LogWriter class definition.
void resetFilename(const Str &filename)
Definition: FileLogWriter.cpp:208
FileEncoder * getFileEncoder()
Definition: FileLogWriter.h:114
Definition: FileLogWriter.h:33
Str filename_
Name of the current file.
Definition: FileLogWriter.h:145
unsigned int getBytesInFile(void)
Accessors.
Definition: FileLogWriter.h:73
FlushFreq
Definition: FileLogWriter.h:31
virtual const Str & getFilename()
Definition: FileLogWriter.h:85
FileEncoder * fileEncoder_
Definition: FileLogWriter.h:151
Wraps a c FILE* handle with an OutStream class.
Definition: FileOutStream.h:26
Definition: FileLogWriter.h:33
bool isWritable(void)
Keep track of whether the stream is open.
Definition: FileLogWriter.h:93
One "entry" in a LogQueue.
Definition: LogEntry.h:33
unsigned int entriesWritten_
Total entries written.
Definition: FileLogWriter.h:136
Replacement for standard template class string.
Definition: Str.h:12
FlushFreq flushFreq_
Definition: FileLogWriter.h:147
virtual ~FileLogWriter()
Destructor, closes file if open.
Definition: FileLogWriter.cpp:70
bool writtenInCycle_
Definition: FileLogWriter.h:149
bool isWritable()
indicates whether the stream can actually be written to.
Definition: FileOutStream.h:63
Simple Interface that contains getFilename() function.
virtual void endCycle()
If flushFreq_ is FLUSH_PER_CYCLE, this causes an output flush.
Definition: FileLogWriter.cpp:185
void setFlushFreq(const FlushFreq flushFreq)
Definition: FileLogWriter.h:109
bool initFilename_
True if a file name is specified in constructor.
Definition: FileLogWriter.h:142
void setFilename(const Str &filename)
Definition: FileLogWriter.h:119
virtual bool valid(void)
Is the LogWriter valid?
Definition: FileLogWriter.h:60
virtual unsigned int write(const LogEntry *entry, const Unit *unit=NULL)
Write.
Definition: FileLogWriter.cpp:159
Simple Interface that contains getFilename() function.
Definition: HasFilename.h:20
virtual void resetInputs()
Reset cached input settings.
Definition: FileLogWriter.cpp:88
This is a rather abstract class that can be implemented by classes that encode a (closed) file...
Definition: FileEncoder.h:20
unsigned int getEntriesWritten(void)
Definition: FileLogWriter.h:79
Code that represents an engineering unit.
Definition: Unit.h:24
LogWriter * logWriter_
The LogWriter that does the actual writing.
Definition: FileLogWriter.h:125
void close(void)
Close the currently open file.
Definition: FileLogWriter.cpp:140
Contains the FileOutStream class declaration.
bool open(const char *filename, const bool append)
Open the stream to the named file.
Definition: FileLogWriter.cpp:100