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 "lib/SimpleFile.h"
00021 #include "features/Features.h"
00022
00023 template <class ST> struct T_STRING;
00024 template <class ST> struct TSparse;
00025
00033 class CFile : public CSGObject
00034 {
00035 public:
00040 CFile(FILE* f);
00041
00053 CFile(char* fname, char rw, EFeatureType type, char fourcc[4]=NULL);
00054
00055 virtual ~CFile();
00056
00062 int32_t parse_first_header(EFeatureType &type);
00063
00069 int32_t parse_next_header(EFeatureType &type);
00070
00071
00072
00079 int32_t* load_int_data(int32_t* target, int64_t& num);
00080
00087 float64_t* load_real_data(float64_t* target, int64_t& num);
00088
00095 float32_t* load_shortreal_data(float32_t* target, int64_t& num);
00096
00103 char* load_char_data(char* target, int64_t& num);
00104
00111 uint8_t* load_byte_data(uint8_t* target, int64_t& num);
00112
00119 uint16_t* load_word_data(uint16_t* target, int64_t& num);
00120
00127 int16_t* load_short_data(int16_t* target, int64_t& num);
00128
00135 template <class DT> DT* load_data(DT* target, int64_t& num)
00136 {
00137 CSimpleFile<DT> f(filename, file);
00138 target=f.load(target, num);
00139 status=(target!=NULL);
00140 return target;
00141 }
00142
00149 template <class DT> bool save_data(DT* src, int64_t num)
00150 {
00151 CSimpleFile<DT> f(filename, file);
00152 status=f.save(src, num);
00153 return status;
00154 }
00155
00162 bool save_int_data(int32_t* src, int64_t num);
00163
00170 bool save_real_data(float64_t* src, int64_t num);
00171
00178 bool save_shortreal_data(float32_t* src, int64_t num);
00179
00186 bool save_char_data(char* src, int64_t num);
00187
00194 bool save_byte_data(uint8_t* src, int64_t num);
00195
00202 bool save_word_data(uint16_t* src, int64_t num);
00203
00210 bool save_short_data(int16_t* src, int64_t num);
00211
00216 inline bool is_ok()
00217 {
00218 return status;
00219 }
00220
00221
00234 bool read_real_valued_sparse(
00235 TSparse<float64_t>*& matrix, int32_t& num_feat, int32_t& num_vec);
00236
00244 bool write_real_valued_sparse(
00245 const TSparse<float64_t>* matrix, int32_t num_feat, int32_t num_vec);
00246
00258 bool read_real_valued_dense(
00259 float64_t*& matrix, int32_t& num_feat, int32_t& num_vec);
00260
00268 bool write_real_valued_dense(
00269 const float64_t* matrix, int32_t num_feat, int32_t num_vec);
00270
00282 bool read_char_valued_strings(T_STRING<char>*& strings, int32_t& num_str, int32_t& max_string_len);
00283
00290 bool write_char_valued_strings(const T_STRING<char>* strings, int32_t num_str);
00291
00293 inline virtual const char* get_name() const { return "File"; }
00294
00295 protected:
00300 bool read_header();
00305 bool write_header();
00306
00307 private:
00309 template <class T> void append_item(CDynamicArray<T>* items, char* ptr_data, char* ptr_item);
00310
00311 protected:
00313 FILE* file;
00315 bool status;
00317 char task;
00319 char* filename;
00321 EFeatureType expected_type;
00323 int32_t num_header;
00325 char fourcc[4];
00326 };
00327 #endif