00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "Core/precomp.h"
00015 #include "API/Core/IOData/file_outputprovider.h"
00016 #include "API/Core/System/cl_assert.h"
00017 #include "API/Core/System/error.h"
00018
00019 CL_OutputSource_File::CL_OutputSource_File(const char *_filename)
00020 {
00021 filename=_filename;
00022 m_pos = 0;
00023 file=NULL;
00024 open();
00025 }
00026 CL_OutputSource_File::CL_OutputSource_File()
00027 {
00028 m_pos = 0;
00029 file=NULL;
00030 }
00031
00032 CL_OutputSource_File::~CL_OutputSource_File()
00033 {
00034 close();
00035 }
00036
00037 std::string CL_OutputSource_File::get_data() const
00038 {
00039 cl_assert(false);
00040 return NULL;
00041 }
00042
00043 void CL_OutputSource_File::set_system_mode()
00044 {
00045 cl_assert(false);
00046 }
00047
00048 void CL_OutputSource_File::set_big_endian_mode()
00049 {
00050 cl_assert(false);
00051 }
00052
00053 void CL_OutputSource_File::set_little_endian_mode()
00054 {
00055 cl_assert(false);
00056 }
00057
00058 void CL_OutputSource_File::write_int32(int data)
00059 {
00060 write(&data, sizeof(int));
00061 }
00062
00063 void CL_OutputSource_File::write_uint32(unsigned int data)
00064 {
00065 write(&data, sizeof(unsigned int));
00066 }
00067
00068 void CL_OutputSource_File::write_short16(short data)
00069 {
00070 write(&data, sizeof(short));
00071 }
00072
00073 void CL_OutputSource_File::write_ushort16(unsigned short data)
00074 {
00075 write(&data, sizeof(unsigned short));
00076 }
00077
00078 void CL_OutputSource_File::write_char8(char data)
00079 {
00080 write(&data, sizeof(char));
00081 }
00082
00083 void CL_OutputSource_File::write_uchar8(unsigned char data)
00084 {
00085 write(&data, sizeof(unsigned char));
00086 }
00087
00088 void CL_OutputSource_File::write_float32(float data)
00089 {
00090 write(&data, sizeof(float));
00091 }
00092
00093 void CL_OutputSource_File::write_bool(bool data)
00094 {
00095 write(&data, sizeof(bool));
00096 }
00097
00098 int CL_OutputSource_File::write(const void *data, int size)
00099 {
00100 cl_assert(file!=NULL);
00101 fwrite( data, size,1,file);
00102 m_pos+=size;
00103 return size;
00104 }
00105
00106 void CL_OutputSource_File::open()
00107 {
00108 if(file!=NULL) return;
00109 file=fopen(filename,"w+b");
00110 if(file==NULL)
00111 {
00112 throw CL_Error("could not create file");
00113 }
00114 }
00115
00116 void CL_OutputSource_File::close()
00117 {
00118 if(file==NULL) return;
00119 fclose(file);
00120 file=NULL;
00121 }
00122
00123 CL_OutputSource *CL_OutputSource_File::clone()
00124 {
00125 cl_assert(false);
00126 return NULL;
00127 }
00128
00129 int CL_OutputSource_File::tell()
00130 {
00131 return m_pos;
00132 }
00133
00134 int CL_OutputSource_File::size()
00135 {
00136 return m_pos;
00137 }
00138
00139 void CL_OutputSource_File::write_string(const char *string)
00140 {
00141 int len = strlen(string)+1;
00142 write_int32(len);
00143 write((char*) string, len);
00144 }
00145
00146 void CL_OutputSource_File::write_string(CL_String & string)
00147 {
00148 write_int32((int)string.get_length());
00149 write(string.get_string(),string.get_length());
00150 }