File.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2008 Soeren Sonnenburg
00008  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef __FILE_H__
00012 #define __FILE_H__
00013 
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <stdarg.h>
00017 
00018 #include "lib/common.h"
00019 #include "lib/DynamicArray.h"
00020 #include "base/SGObject.h"
00021 
00022 template <class ST> struct T_STRING;
00023 template <class ST> struct TSparse;
00024 
00032 class CFile : public CSGObject
00033 {
00034 public:
00039     CFile(FILE* f);
00040 
00052     CFile(CHAR* fname, CHAR rw, EFeatureType type, CHAR fourcc[4]=NULL);
00053 
00054     ~CFile();
00055 
00061     INT parse_first_header(EFeatureType &type);
00062 
00068     INT parse_next_header(EFeatureType &type);
00069 
00070     // set target to NULL to get it automagically allocated
00071     // set num to 0 if whole file is to be read
00078     INT*   load_int_data(INT* target, LONG& num);
00079 
00086     DREAL*  load_real_data(DREAL* target, LONG& num);
00087 
00094     SHORTREAL*  load_shortreal_data(SHORTREAL* target, LONG& num);
00095 
00102     CHAR*  load_char_data(CHAR* target, LONG& num);
00103 
00110     BYTE*  load_byte_data(BYTE* target, LONG& num);
00111 
00118     WORD*  load_word_data(WORD* target, LONG& num);
00119 
00126     SHORT* load_short_data(SHORT* target, LONG& num);
00127 
00134     bool save_int_data(INT* src, LONG num);
00135 
00142     bool save_real_data(DREAL* src, LONG num);
00143 
00150     bool save_shortreal_data(SHORTREAL* src, LONG num);
00151 
00158     bool save_char_data(CHAR* src, LONG num);
00159 
00166     bool save_byte_data(BYTE* src, LONG num);
00167 
00174     bool save_word_data(WORD* src, LONG num);
00175 
00182     bool save_short_data(SHORT* src, LONG num);
00183 
00188     inline bool is_ok()
00189     {
00190         return status;
00191     }
00192 
00193 
00206     bool read_real_valued_sparse(TSparse<DREAL>*& matrix, INT& num_feat, INT& num_vec);
00207 
00215     bool write_real_valued_sparse(const TSparse<DREAL>* matrix, INT num_feat, INT num_vec);
00216 
00228     bool read_real_valued_dense(DREAL*& matrix, INT& num_feat, INT& num_vec);
00229 
00237     bool write_real_valued_dense(const DREAL* matrix, INT num_feat, INT num_vec);
00238 
00250     bool read_char_valued_strings(T_STRING<CHAR>*& strings, INT& num_str, INT& max_string_len);
00251 
00258     bool write_char_valued_strings(const T_STRING<CHAR>* strings, INT num_str);
00259 
00260 protected:
00265     bool read_header();
00270     bool write_header();
00271 
00272 private:
00274     template <class T> void append_item(CDynamicArray<T>* items, CHAR* ptr_data, CHAR* ptr_item);
00275 
00276 protected:
00278     FILE* file;
00280     bool status;
00282     CHAR task;
00284     CHAR* filename;
00286     EFeatureType expected_type;
00288     INT num_header;
00290     CHAR fourcc[4];
00291 };
00292 #endif

SHOGUN Machine Learning Toolbox - Documentation