SpectMorph
|
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_OUT_FILE_HH 00019 #define SPECTMORPH_OUT_FILE_HH 00020 00021 #include <stdio.h> 00022 #include <string> 00023 #include <vector> 00024 #include <set> 00025 #include "smgenericout.hh" 00026 00027 namespace SpectMorph 00028 { 00029 00030 class OutFile 00031 { 00032 GenericOut *file; 00033 bool delete_file; 00034 std::set<std::string> stored_blobs; 00035 00036 protected: 00037 void write_raw_string (const std::string& s); 00038 void write_raw_int (int i); 00039 void write_file_type_and_version (const std::string& file_type, int file_version); 00040 00041 public: 00042 OutFile (const std::string& filename, const std::string& file_type, int file_version); 00043 OutFile (GenericOut *outfile, const std::string& file_type, int file_version); 00044 00045 bool 00046 open_ok() 00047 { 00048 return file != NULL; 00049 } 00050 ~OutFile(); 00051 00052 void begin_section (const std::string& s); 00053 void end_section(); 00054 00055 void write_bool (const std::string& s, bool b); 00056 void write_int (const std::string& s, int i); 00057 void write_string (const std::string& s, const std::string& data); 00058 void write_float (const std::string& s, double f); 00059 void write_float_block (const std::string& s, const std::vector<float>& fb); 00060 void write_blob (const std::string& s, const void *data, size_t size); 00061 }; 00062 00063 } 00064 00065 #endif /* SPECTMORPH_OUT_FILE_HH */