File.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
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 "base/SGObject.h"
00019 #include "lib/DynamicArray.h"
00020 #include "features/Features.h"
00021
00022 template <class ST> struct T_STRING;
00023 template <class ST> struct TSparse;
00024
00031 class CFile : public CSGObject
00032 {
00033 public:
00038 CFile(FILE* f);
00039
00051 CFile(char* fname, char rw, EFeatureType type, char fourcc[4]=NULL);
00052
00053 ~CFile();
00054
00060 int32_t parse_first_header(EFeatureType &type);
00061
00067 int32_t parse_next_header(EFeatureType &type);
00068
00069
00070
00077 int32_t* load_int_data(int32_t* target, int64_t& num);
00078
00085 float64_t* load_real_data(float64_t* target, int64_t& num);
00086
00093 float32_t* load_shortreal_data(float32_t* target, int64_t& num);
00094
00101 char* load_char_data(char* target, int64_t& num);
00102
00109 uint8_t* load_byte_data(uint8_t* target, int64_t& num);
00110
00117 uint16_t* load_word_data(uint16_t* target, int64_t& num);
00118
00125 int16_t* load_short_data(int16_t* target, int64_t& num);
00126
00133 bool save_int_data(int32_t* src, int64_t num);
00134
00141 bool save_real_data(float64_t* src, int64_t num);
00142
00149 bool save_shortreal_data(float32_t* src, int64_t num);
00150
00157 bool save_char_data(char* src, int64_t num);
00158
00165 bool save_byte_data(uint8_t* src, int64_t num);
00166
00173 bool save_word_data(uint16_t* src, int64_t num);
00174
00181 bool save_short_data(int16_t* src, int64_t num);
00182
00187 inline bool is_ok()
00188 {
00189 return status;
00190 }
00191
00192
00205 bool read_real_valued_sparse(
00206 TSparse<float64_t>*& matrix, int32_t& num_feat, int32_t& num_vec);
00207
00215 bool write_real_valued_sparse(
00216 const TSparse<float64_t>* matrix, int32_t num_feat, int32_t num_vec);
00217
00229 bool read_real_valued_dense(
00230 float64_t*& matrix, int32_t& num_feat, int32_t& num_vec);
00231
00239 bool write_real_valued_dense(
00240 const float64_t* matrix, int32_t num_feat, int32_t num_vec);
00241
00253 bool read_char_valued_strings(T_STRING<char>*& strings, int32_t& num_str, int32_t& max_string_len);
00254
00261 bool write_char_valued_strings(const T_STRING<char>* strings, int32_t num_str);
00262
00263 protected:
00268 bool read_header();
00273 bool write_header();
00274
00275 private:
00277 template <class T> void append_item(CDynamicArray<T>* items, char* ptr_data, char* ptr_item);
00278
00279 protected:
00281 FILE* file;
00283 bool status;
00285 char task;
00287 char* filename;
00289 EFeatureType expected_type;
00291 int32_t num_header;
00293 char fourcc[4];
00294 };
00295 #endif