CFEL - ASG Software Suite  2.5.0
CASS
file_parser.h
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file file_parser.h contains base class for all file parsers
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _FILEPARSER_H_
10 #define _FILEPARSER_H_
11 
12 #include <QtCore/QObject>
13 #include <QtCore/QThread>
14 #include <QtCore/QReadWriteLock>
15 
16 #include <tr1/memory>
17 #include <fstream>
18 #include <string>
19 
20 #include "cass.h"
21 #include "pausablethread.h"
22 
23 namespace cass
24 {
25 /** base class for all file parsers
26  *
27  * @author Lutz Foucar
28  */
30 {
31  Q_OBJECT
32 public:
33  /** constructor
34  *
35  * @param readerpointerpair the filereader the will read the event from files
36  * @param event2posreader reference to container that maps events to the
37  * position in file, reader pair vector
38  * @param lock reference to the protector of the eventlist map
39  */
40  FileParser(const filereaderpointerpair_t readerpointerpair,
41  event2positionreaders_t &event2posreader,
42  QReadWriteLock &lock);
43 
44  /** typedef the shared pointer of this */
45  typedef std::tr1::shared_ptr<FileParser> shared_pointer;
46 
47  /** virtual destructor */
48  virtual ~FileParser();
49 
50  /** create an instance of the requested type
51  *
52  * returns an instance of the right fileparser. To figure out the right
53  * fileparser the filname is inspected and depending on the extension the
54  * right file parser is created.
55  *
56  * @return a shared pointer to the requested type
57  * @param type the type of the parser requested
58  * @param readerpointerpair the filereader the will read the event from files
59  * @param event2posreader reference to container that maps events to the
60  * position in file, reader pair vector
61  * @param lock reference to the protector of the eventlist map
62  */
63  static shared_pointer instance(const std::string type,
64  const filereaderpointerpair_t readerpointerpair,
65  event2positionreaders_t &event2posreader,
66  QReadWriteLock &lock);
67 
68  /** @return the type of file parser */
69  virtual const std::string type() {return "Unknown";}
70 
71 protected:
72  /** put current file position in the eventmap
73  *
74  * save the current position of the filestream in the filepointer and put
75  * a copy of the file pointer in the eventmap.
76  *
77  * @param eventStartPos the position in the file where the event starts
78  * @param eventId the event id that should be associated with this position
79  */
80  void savePos(const std::streampos& eventStartPos, const uint64_t eventId);
81 
82 protected:
83  /** the file pointer */
85 
86  /** reference to the map containing the beginnings of the event */
88 
89  /** Lock that protects the map */
91 
92 };
93 }//end namespace cass
94 #endif
event2positionreaders_t & _event2posreader
reference to the map containing the beginnings of the event
Definition: file_parser.h:87
declaration of a pausable QThread
static shared_pointer instance(const std::string type, const filereaderpointerpair_t readerpointerpair, event2positionreaders_t &event2posreader, QReadWriteLock &lock)
create an instance of the requested type
Definition: file_parser.cpp:42
filereaderpointerpair_t _readerpointerpair
the file pointer
Definition: file_parser.h:84
std::tr1::shared_ptr< FileParser > shared_pointer
typedef the shared pointer of this
Definition: file_parser.h:45
QReadWriteLock & _lock
Lock that protects the map.
Definition: file_parser.h:90
file contains global definitions for project cass
void savePos(const std::streampos &eventStartPos, const uint64_t eventId)
put current file position in the eventmap
Definition: file_parser.cpp:62
std::pair< std::tr1::shared_ptr< FileReader >, FilePointer > filereaderpointerpair_t
pair of a file pointer with the associated file reader
Definition: cass.h:276
FileParser(const filereaderpointerpair_t readerpointerpair, event2positionreaders_t &event2posreader, QReadWriteLock &lock)
constructor
Definition: file_parser.cpp:30
virtual ~FileParser()
virtual destructor
Definition: file_parser.cpp:39
base class for all file parsers
Definition: file_parser.h:29
std::map< uint64_t, positionreaders_t > event2positionreaders_t
the list of events contained in a file with the associated position and reader
Definition: cass.h:282
virtual const std::string type()
Definition: file_parser.h:69
A QThread that has the ability to be paused and resumed.