casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDMDataObjectReader.h
Go to the documentation of this file.
1 #ifndef SDMDataObjectReader_CLASS
2 #define SDMDataObjectReader_CLASS
3 
4 #include <string>
5 #include <map>
6 #include <set>
7 #include <vector>
8 #include <bitset>
9 
10 #ifdef REG_BASIC
11 #undef REG_BASIC
12 #endif
13 
14 #ifdef REG_EXTENDED
15 #undef REG_EXTENDED
16 #endif
17 
18 #ifdef REG_ICASE
19 #undef REG_ICASE
20 #endif
21 
22 #ifdef REG_NOSUB
23 #undef REG_NOSUB
24 #endif
25 
26 #ifdef REG_NEWLINE
27 #undef REG_NEWLINE
28 #endif
29 
30 #ifdef REG_NOTBOL
31 #undef REG_NOTBOL
32 #endif
33 
34 #ifdef REG_NOTEOL
35 #undef REG_NOTEOL
36 #endif
37 
38 #ifdef REG_STARTEND
39 #undef REG_STARTEND
40 #endif
41 
42 #ifndef WITHOUT_BOOST
43 #include <boost/regex.hpp>
44 #else
45 #include <regex>
46 #endif
47 
50 
51 /*
52 typedef long long ACTUALDURATIONSTYPE;
53 typedef long long ACTUALTIMESTYPE;
54 typedef float AUTODATATYPE;
55 typedef int LONGCROSSDATATYPE; // mcaillat
56 typedef short int SHORTCROSSDATATYPE;
57 typedef float FLOATCROSSDATATYPE;
58 typedef unsigned int FLAGSTYPE; // mcaillat
59 typedef float ZEROLAGSTYPE;
60 */
61 
62 namespace asdmbinaries {
67 
68  public:
73 
78  SDMDataObjectReaderException(std::string m);
79 
84 
89  std::string getMessage() const;
90 
91  protected:
92  std::string message;
93 
94  };
95 
96  inline SDMDataObjectReaderException::SDMDataObjectReaderException() : message ("SDMDataObjectReaderException") {}
97  inline SDMDataObjectReaderException::SDMDataObjectReaderException(std::string m) : message(m) {}
99  inline std::string SDMDataObjectReaderException::getMessage() const {
100  return "SDMDataObjectReaderException : " + message;
101  }
102 
112  public:
117 
121  virtual ~SDMDataObjectReader();
122 
130  const SDMDataObject & read(std::string filename);
131 
140  const SDMDataObject & read(const char * buffer, unsigned long int size, bool fromFile=false);
141 
142 
149  const SDMDataObject & ref() const;
150 
157  const SDMDataObject * ptr() const;
158 
163  void done();
164 
165  private:
168 
169  int filedes_;
170  unsigned int dataSize_;
171  char* data_;
172  std::string::size_type position_;
173  std::string::size_type lastPosition_;
174  std::string::size_type endPosition_;
175 
176  unsigned int integrationNum_;
177 
178  static const bool initClass_;
179  static bool initClass();
180  void init() ;
181  std::string::size_type find(const std::string& s);
182  bool compare(const std::string& s);
183  bool EOD();
184 
185  // Two strings used as MIME boundaries
186  static const std::string MIMEBOUNDARY_1;
187  static const std::string MIMEBOUNDARY_2;
188 
189  // Regular expressions used to identify a Content-ID field in a MIME header
190 #ifndef WITHOUT_BOOST
196 #else
198  static const std::regex CONTENTIDSUBSETREGEXP;
199  static const std::regex CONTENTIDBINREGEXP;
200  static const std::regex CONTENTIDBINREGEXP1;
201  static const std::regex CONTENTIDBINREGEXP2;
202 #endif
203  // Set of valid binary attachment names
204  static std::set<std::string> BINATTACHNAMES;
206  static std::map<std::string, BINATTACHCODES> name2code;
207 
208  std::string extractXMLHeader(const std::string& boundary);
209  void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters);
210  void getFields(const std::string& header, std::map<std::string, std::string>& fields);
211  std::string getContentID();
212  std::string getContentLocation();
213 
214  void processMIME();
216  void processMIMESDMDataSubsetHeader(SDMDataSubset& sdmDataSubset);
218  void processMIMEIntegration();
219  void processMIMESubscan();
220  void processBinaryAttachment(const std::string& boundary, const SDMDataSubset& sdmDataSubset);
221 
222 
223  // SDMDataObject related stuff
226  const SDMDataObject& sdmDataObject();
227 
228  std::bitset<6> attachmentFlags;
229 
231  unsigned long int nActualTimes_;
233  unsigned long int nActualDurations_;
235  unsigned long int nZeroLags_;
236  const FLAGSTYPE * flags_;
237  unsigned long int nFlags_;
241  unsigned long int nCrossData_;
243  unsigned long int nAutoData_;
244 
245  };
246 } // namespace asdmbinaries
247 #endif // SDMDataObjectReader_CLASS
SDMDataObject:: declarations.
void processBinaryAttachment(const std::string &boundary, const SDMDataSubset &sdmDataSubset)
static const boost::regex CONTENTIDDATASTRUCTUREREGEXP
Regular expressions used to identify a Content-ID field in a MIME header.
const ACTUALDURATIONSTYPE * actualDurations_
float FLOATCROSSDATATYPE
Type of cross data when those are encoded as 32bits float.
static const boost::regex CONTENTIDBINREGEXP1
int16_t SHORTCROSSDATATYPE
Type of cross data when those are encoded as 16bits unsigned integers.
const SDMDataObject & ref() const
This method returns a reference to the SDMDataObject instance built during the execution of the read ...
static const boost::regex CONTENTIDBINREGEXP2
void getFields(const std::string &header, std::map< std::string, std::string > &fields)
SDMDataObjectParser parser_
SDMDataObject related stuff.
const ACTUALTIMESTYPE * actualTimes_
static std::set< std::string > BINATTACHNAMES
Set of valid binary attachment names.
static std::map< std::string, BINATTACHCODES > name2code
const SDMDataObject * ptr() const
This method returns a pointer to the SDMDataObject instance built during the execution of the read me...
float AUTODATATYPE
Type of auto data.
const SHORTCROSSDATATYPE * shortCrossData_
size_t size() const
int64_t ACTUALTIMESTYPE
Type of actual times.
const INTCROSSDATATYPE * longCrossData_
const SDMDataObject & sdmDataObject()
int32_t INTCROSSDATATYPE
Type of cross data when those are encoded as 32bits unsigned integers.
std::string getMessage() const
Returns the message associated to this exception.
static const std::string MIMEBOUNDARY_2
virtual ~SDMDataObjectReader()
The destructor.
static const boost::regex CONTENTIDBINREGEXP
static const boost::regex CONTENTIDSUBSETREGEXP
uint32_t FLAGSTYPE
Type of flags.
void done()
A method to release the resources allocated by the read operation.
SDMDataObjectReader()
An empty constructor.
virtual ~SDMDataObjectReaderException()
The destructor.
A class to represent an exception thrown while reading a MIME message containing ALMA binary data...
bool compare(const std::string &s)
const SDMDataObject & read(std::string filename)
This method reads a MIME message contained in a disk file and returns a reference to an SDMDataObject...
std::string::size_type find(const std::string &s)
A class to read a MIME message containing ALMA binary data and provide a view on these binary data th...
TableExprNode regex(const TableExprNode &node)
Functions for regular expression matching and pattern matching.
Definition: ExprNode.h:1440
std::string extractXMLHeader(const std::string &boundary)
float ZEROLAGSTYPE
Type of zero lags.
const FLOATCROSSDATATYPE * floatCrossData_
void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters)
void processMIMESDMDataSubsetHeader(SDMDataSubset &sdmDataSubset)
static const std::string MIMEBOUNDARY_1
Two strings used as MIME boundaries.
int64_t ACTUALDURATIONSTYPE
Type of actual durations.