00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SPECTMORPH_INFILE_HH
00019 #define SPECTMORPH_INFILE_HH
00020
00021 #include <stdio.h>
00022 #include <string>
00023 #include <vector>
00024 #include <set>
00025
00026 #include "smstdioin.hh"
00027 #include "smmmapin.hh"
00028
00029 namespace SpectMorph
00030 {
00031
00032 class InFile
00033 {
00034 public:
00035 enum Event {
00036 NONE,
00037 END_OF_FILE,
00038 READ_ERROR,
00039 BEGIN_SECTION,
00040 END_SECTION,
00041 INT,
00042 STRING,
00043 FLOAT,
00044 FLOAT_BLOCK,
00045 BLOB,
00046 BLOB_REF
00047 };
00048
00049 protected:
00050 GenericIn *file;
00051 Event current_event;
00052 std::string current_event_str;
00053 int current_event_int;
00054 std::string current_event_data;
00055 float current_event_float;
00056 std::vector<float> current_event_float_block;
00057 size_t current_event_blob_pos;
00058 size_t current_event_blob_size;
00059 std::string current_event_blob_sum;
00060 std::string m_file_type;
00061 int m_file_version;
00062
00063 std::set<std::string> skip_events;
00064
00065 bool read_raw_string (std::string& str);
00066 bool read_raw_int (int &i);
00067 bool read_raw_float (float &f);
00068 bool read_raw_float_block (std::vector<float>& fb);
00069 bool skip_raw_float_block();
00070
00071 void read_file_type_and_version();
00072
00073 public:
00074 InFile (const std::string& filename);
00075 InFile (GenericIn *file);
00076 bool
00077 open_ok()
00078 {
00079 return file != NULL;
00080 }
00081 Event event();
00082 std::string event_name();
00083 float event_float();
00084 int event_int();
00085 std::string event_data();
00086 const std::vector<float>& event_float_block();
00087 std::string event_blob_sum();
00088
00089 void next_event();
00090 void add_skip_event (const std::string& event);
00091 std::string file_type();
00092 int file_version();
00093
00094 GenericIn *open_blob();
00095 };
00096
00097 }
00098
00099 #endif