Libbarrett
1.2.4
|
00001 00033 #include <fstream> 00034 00035 00036 namespace barrett { 00037 namespace log { 00038 00039 00040 template<typename T, typename Traits> 00041 Writer<T, Traits>::Writer(const char* fileName) : 00042 file(fileName, std::ios_base::binary), recordLength(Traits::serializedLength()) 00043 { 00044 if (recordLength == 0) { 00045 throw(std::logic_error("(log::Writer::Writer): The record length " 00046 "(Traits::serializedLength()) cannot be zero.")); 00047 } 00048 00049 buffer = new char[recordLength]; 00050 } 00051 00052 template<typename T, typename Traits> 00053 Writer<T, Traits>::~Writer() 00054 { 00055 if (file.is_open()) { 00056 close(); 00057 } 00058 00059 delete[] buffer; 00060 buffer = NULL; 00061 } 00062 00063 template<typename T, typename Traits> 00064 inline void Writer<T, Traits>::putRecord(parameter_type data) 00065 { 00066 Traits::serialize(data, buffer); 00067 file.write(buffer, recordLength); 00068 } 00069 00070 template<typename T, typename Traits> 00071 inline void Writer<T, Traits>::close() 00072 { 00073 file.close(); 00074 } 00075 00076 00077 } 00078 }