Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <string.h>
00015
00016 #include "lib/File.h"
00017
00018 #include "features/StringFeatures.h"
00019 #include "features/SparseFeatures.h"
00020
00021 using namespace shogun;
00022
00023 CFile::CFile() : CSGObject()
00024 {
00025 file=NULL;
00026 filename=NULL;
00027 variable_name=NULL;
00028 }
00029
00030 CFile::CFile(FILE* f, const char* name) : CSGObject()
00031 {
00032 file=f;
00033 filename=NULL;
00034 variable_name=NULL;
00035
00036 if (name)
00037 set_variable_name(name);
00038 }
00039
00040 CFile::CFile(char* fname, char rw, const char* name) : CSGObject()
00041 {
00042 variable_name=NULL;
00043 task=rw;
00044 filename=strdup(fname);
00045 char mode[2];
00046 mode[0]=rw;
00047 mode[1]='\0';
00048
00049 if (rw=='r' || rw == 'w')
00050 {
00051 if (filename)
00052 {
00053 if (!(file=fopen((const char*) filename, (const char*) mode)))
00054 SG_ERROR("Error opening file '%s'\n", filename);
00055 }
00056 }
00057 else
00058 SG_ERROR("unknown mode '%c'\n", mode[0]);
00059
00060 if (name)
00061 set_variable_name(name);
00062 }
00063
00064 void CFile::get_bool_vector(bool*& vector, int32_t& len)
00065 {
00066 int32_t* int_vector;
00067 get_int_vector(int_vector, len);
00068
00069 ASSERT(len>0);
00070 vector= new bool[len];
00071
00072 for (int32_t i=0; i<len; i++)
00073 vector[i]= (int_vector[i]!=0);
00074
00075 delete[] int_vector;
00076 }
00077
00078 void CFile::set_bool_vector(const bool* vector, int32_t len)
00079 {
00080 int32_t* int_vector = new int32_t[len];
00081 for (int32_t i=0;i<len;i++)
00082 {
00083 if (vector[i])
00084 int_vector[i]=1;
00085 else
00086 int_vector[i]=0;
00087 }
00088 set_int_vector(int_vector,len);
00089 delete[] int_vector;
00090 }
00091
00092 void CFile::get_bool_matrix(bool*& matrix, int32_t& num_feat, int32_t& num_vec)
00093 {
00094 SG_NOTIMPLEMENTED;
00095 }
00096
00097 void CFile::set_bool_matrix(const bool* matrix, int32_t num_feat, int32_t num_vec)
00098 {
00099 SG_NOTIMPLEMENTED;
00100 }
00101
00102 void CFile::get_bool_string_list(
00103 TString<bool>*& strings, int32_t& num_str,
00104 int32_t& max_string_len)
00105 {
00106 TString<int32_t>* strs;
00107 get_int_string_list(strs, num_str, max_string_len);
00108
00109 ASSERT(num_str>0 && max_string_len>0);
00110 strings=new TString<bool>[num_str];
00111
00112 SG_NOTIMPLEMENTED;
00113
00114 }
00115
00116 void CFile::set_bool_string_list(const TString<bool>* strings, int32_t num_str)
00117 {
00118 SG_NOTIMPLEMENTED;
00119
00120 }
00121
00122 CFile::~CFile()
00123 {
00124 close();
00125 }
00126
00127 void CFile::set_variable_name(const char* name)
00128 {
00129 free(variable_name);
00130 variable_name=strdup(name);
00131 }
00132
00133 char* CFile::get_variable_name()
00134 {
00135 return strdup(variable_name);
00136 }