SpectMorph

lib/sminfile.hh

00001 /* 
00002  * Copyright (C) 2009-2010 Stefan Westerfeld
00003  *
00004  * This library is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License as published by the
00006  * Free Software Foundation; either version 3 of the License, or (at your
00007  * option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
00012  * for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 
00040 class InFile
00041 {
00042 public:
00043   enum Event {
00044     NONE,
00045     END_OF_FILE,
00046     READ_ERROR,
00047     BEGIN_SECTION,
00048     END_SECTION,
00049     BOOL,
00050     INT,
00051     STRING,
00052     FLOAT,
00053     FLOAT_BLOCK,
00054     BLOB,
00055     BLOB_REF
00056   };
00057 
00058 protected:
00059   GenericIn         *file;
00060   bool               file_delete;
00061   Event              current_event;
00062   std::string        current_event_str;
00063   bool               current_event_bool;
00064   int                current_event_int;
00065   std::string        current_event_data;
00066   float              current_event_float;
00067   std::vector<float> current_event_float_block;
00068   size_t             current_event_blob_pos;
00069   size_t             current_event_blob_size;
00070   std::string        current_event_blob_sum;
00071   std::string        m_file_type;
00072   int                m_file_version;
00073 
00074   std::set<std::string> skip_events;
00075 
00076   bool        read_raw_bool (bool& b);
00077   bool        read_raw_string (std::string& str);
00078   bool        read_raw_int (int &i);
00079   bool        read_raw_float (float &f);
00080   bool        read_raw_float_block (std::vector<float>& fb);
00081   bool        skip_raw_float_block();
00082 
00083   void        read_file_type_and_version();
00084 
00085 public:
00086   InFile (const std::string& filename);
00087   InFile (GenericIn *file);
00088   ~InFile();
00089 
00095   bool
00096   open_ok()
00097   {
00098     return file != NULL;
00099   }
00100   Event        event();
00101   std::string  event_name();
00102   float        event_float();
00103   int          event_int();
00104   bool         event_bool();
00105   std::string  event_data();
00106   const std::vector<float>& event_float_block();
00107   std::string  event_blob_sum();
00108 
00109   void         next_event();
00110   void         add_skip_event (const std::string& event);
00111   std::string  file_type();
00112   int          file_version();
00113 
00114   GenericIn   *open_blob();
00115 };
00116 
00117 }
00118 
00119 #endif /* SPECTMORPH_INFILE_HH */
 All Classes Functions Variables Enumerations Enumerator