SpectMorph
sminfile.hh
1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #ifndef SPECTMORPH_INFILE_HH
4 #define SPECTMORPH_INFILE_HH
5 
6 #include <stdio.h>
7 #include <string>
8 #include <vector>
9 #include <set>
10 
11 #include "smstdioin.hh"
12 #include "smmmapin.hh"
13 
14 namespace SpectMorph
15 {
16 
25 class InFile
26 {
27 public:
28  enum Event {
29  NONE,
30  END_OF_FILE,
31  READ_ERROR,
32  BEGIN_SECTION,
33  END_SECTION,
34  BOOL,
35  INT,
36  STRING,
37  FLOAT,
38  FLOAT_BLOCK,
39  UINT16_BLOCK,
40  BLOB,
41  BLOB_REF
42  };
43 
44 protected:
45  GenericIn *file;
46  bool file_delete;
47  Event current_event;
48  std::string current_event_str;
49  bool current_event_bool;
50  int current_event_int;
51  std::string current_event_data;
52  float current_event_float;
53  std::vector<float> current_event_float_block;
54  std::vector<uint16_t> current_event_uint16_block;
55  size_t current_event_blob_pos;
56  size_t current_event_blob_size;
57  std::string current_event_blob_sum;
58  std::string m_file_type;
59  int m_file_version;
60 
61  std::set<std::string> skip_events;
62 
63  bool read_raw_bool (bool& b);
64  bool read_raw_string (std::string& str);
65  bool read_raw_int (int &i);
66  bool read_raw_float (float &f);
67  bool read_raw_float_block (std::vector<float>& fb);
68  bool skip_raw_float_block();
69  bool read_raw_uint16_block (std::vector<uint16_t>& ib);
70  bool skip_raw_uint16_block();
71 
72  void read_file_type_and_version();
73 
74 public:
75  InFile (const std::string& filename);
76  InFile (GenericIn *file);
77  ~InFile();
78 
84  bool
86  {
87  return file != NULL;
88  }
89  Event event();
90  std::string event_name();
91  float event_float();
92  int event_int();
93  bool event_bool();
94  std::string event_data();
95  const std::vector<float>& event_float_block();
96  const std::vector<uint16_t>& event_uint16_block();
97  std::string event_blob_sum();
98 
99  void next_event();
100  void add_skip_event (const std::string& event);
101  std::string file_type();
102  int file_version();
103 
104  GenericIn *open_blob();
105 };
106 
107 }
108 
109 #endif /* SPECTMORPH_INFILE_HH */
InFile(const std::string &filename)
Definition: sminfile.cc:17
GenericIn * open_blob()
Definition: sminfile.cc:353
bool open_ok()
Definition: sminfile.hh:85
Generic Input Stream.
Definition: smgenericin.hh:17
const std::vector< uint16_t > & event_uint16_block()
Definition: sminfile.cc:430
int event_int()
Definition: sminfile.cc:386
float event_float()
Definition: sminfile.cc:375
bool event_bool()
Definition: sminfile.cc:397
Event event()
Definition: sminfile.cc:69
const std::vector< float > & event_float_block()
Definition: sminfile.cc:419
Class to read SpectMorph binary data.
Definition: sminfile.hh:25
std::string file_type()
Definition: sminfile.cc:467
std::string event_name()
Definition: sminfile.cc:364
void next_event()
Definition: sminfile.cc:112
std::string event_data()
Definition: sminfile.cc:408
void add_skip_event(const std::string &event)
Definition: sminfile.cc:456
std::string event_blob_sum()
Definition: sminfile.cc:444
Definition: smalignedarray.cc:7
int file_version()
Definition: sminfile.cc:478