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