CFEL - ASG Software Suite  2.5.0
CASS
file_reader.h
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file file_reader.h contains base class for all file readers
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _FILEREADER_H_
10 #define _FILEREADER_H_
11 
12 #include <tr1/memory>
13 #include <fstream>
14 #include <string>
15 
16 namespace cass
17 {
18 class CASSEvent;
19 
20 /** base class for all file readers
21  *
22  * @author Lutz Foucar
23  */
25 {
26 public:
27  /** typedef the shared pointer of this */
28  typedef std::tr1::shared_ptr<FileReader> shared_pointer;
29 
30  /** virtual destructor */
31  virtual ~FileReader() {}
32 
33  /** create an instance of the requested type
34  *
35  * The type is determined from the filename
36  *
37  * @return a shared pointer to the requested type
38  * @param filename the filename of the file that this reader is working on
39  */
40  static shared_pointer instance(const std::string &filename);
41 
42  /** read the file contents
43  *
44  * should read the file contents and convert them so that they can be put
45  * into the cassevent
46  *
47  * @return true when the workers should work on the filled cassevent,
48  * false if not.
49  * @param file the file that contains the data to be put into the cassevent
50  * @param event the CASSEvent where the data will be put into
51  */
52  virtual bool operator()(std::ifstream &file, CASSEvent& event)=0;
53 
54  /** load the settings of the reader */
55  virtual void loadSettings()=0;
56 
57  /** read the file header
58  *
59  * @param file the filestream to the header information of the file
60  */
61  virtual void readHeaderInfo(std::ifstream &/*file*/) {}
62 
63  /** set the filename of the instance
64  *
65  * @param filename the filename of the file that this reader is working on
66  */
67  void filename(const std::string &filename) {_filename = filename;}
68 
69  /** retrieve the filename that this instance is working on
70  *
71  * @return filename the filename of the file that this reader is working on
72  */
73  const std::string& filename()const {return _filename;}
74 
75  /** return the type of file that this is for
76  *
77  * @return the type of reader
78  */
79  std::string type()const {return _type;}
80 
81 protected:
82  /** only inheritants can create this */
84 
85  /** set the readers type
86  *
87  * @param type The type of the reader
88  */
89  FileReader(const std::string &type) :_type(type) {}
90 
91  /** the name of the file that we read the values from */
92  std::string _filename;
93 
94  /** the reader type as string */
95  std::string _type;
96 };
97 } //end namespace cass
98 #endif
Event to store all LCLS Data.
Definition: cass_event.h:32
std::string type() const
return the type of file that this is for
Definition: file_reader.h:79
const std::string & filename() const
retrieve the filename that this instance is working on
Definition: file_reader.h:73
void filename(const std::string &filename)
set the filename of the instance
Definition: file_reader.h:67
std::string _type
the reader type as string
Definition: file_reader.h:95
virtual void readHeaderInfo(std::ifstream &)
read the file header
Definition: file_reader.h:61
base class for all file readers
Definition: file_reader.h:24
virtual void loadSettings()=0
load the settings of the reader
FileReader()
only inheritants can create this
Definition: file_reader.h:83
virtual ~FileReader()
virtual destructor
Definition: file_reader.h:31
std::string _filename
the name of the file that we read the values from
Definition: file_reader.h:92
static shared_pointer instance(const std::string &filename)
create an instance of the requested type
Definition: file_reader.cpp:29
virtual bool operator()(std::ifstream &file, CASSEvent &event)=0
read the file contents
std::tr1::shared_ptr< FileReader > shared_pointer
typedef the shared pointer of this
Definition: file_reader.h:28
FileReader(const std::string &type)
set the readers type
Definition: file_reader.h:89