Mercurial > hg > m4-sa
comparison runner/BinaryFeatureWriter.cpp @ 66:c98f0ece3e80
added binary file verification script
author | gyorgyf |
---|---|
date | Fri, 17 Feb 2012 11:38:04 +0000 |
parents | b2f70a775ddc |
children | 5e432835d7e1 |
comparison
equal
deleted
inserted
replaced
65:b2f70a775ddc | 66:c98f0ece3e80 |
---|---|
60 const Transform *transform; | 60 const Transform *transform; |
61 OutputStream() : newtransform(true),stream(NULL),transform(NULL) { } | 61 OutputStream() : newtransform(true),stream(NULL),transform(NULL) { } |
62 ~OutputStream() { if (stream != NULL) {stream->close(); delete stream;} } | 62 ~OutputStream() { if (stream != NULL) {stream->close(); delete stream;} } |
63 | 63 |
64 struct header_t { | 64 struct header_t { |
65 int16_t BOM16; // 16-bit BOM (FEFF as in UTF-16) | 65 int16_t BOM16; // 16-bit BOM (FEFF as in UTF-16) 2 bytes |
66 int32_t BOM32; // 32-bit BOM (human readable: e.g. ABCD) | 66 int32_t BOM32; // 32-bit BOM (human readable: e.g. ABCD) 4 bytes |
67 char major_version; // check for binary compatibility | 67 char major_version; // check for binary compatibility |
68 char minor_version; // changes in txt parts only | 68 char minor_version; // changes in txt parts only |
69 char compression; // use of stream compression (e.g. gzip) | 69 char compression; // use of stream compression (e.g. gzip) |
70 char reserved1; // reserved byte | 70 char reserved1; // reserved byte |
71 char reserved2; // reserved byte | 71 char reserved2; // reserved byte |
76 | 76 |
77 bool open(string filename, bool append = true) { | 77 bool open(string filename, bool append = true) { |
78 | 78 |
79 if (stream) return true; | 79 if (stream) return true; |
80 | 80 |
81 header_t header = {(int16_t) 0xFEFF,0x41424344,MAJOR_VERSION_PY,1,0,NULL,NULL,(char)sizeof(float),(char)sizeof(int),{NULL},NULL}; | 81 header_t header = {(int16_t) 0xFEFF, (int32_t) 0x41424344,MAJOR_VERSION_PY,2,0,NULL,NULL,(char)sizeof(float),(char)sizeof(int),{NULL},NULL}; |
82 char* p_header = reinterpret_cast<char*>(&header); | 82 char* p_header = reinterpret_cast<char*>(&header); |
83 | 83 |
84 if (append) | 84 if (append) |
85 stream = new ofstream(filename.c_str(), fstream::binary | ios_base::out | ios_base::in | ofstream::ate); | 85 stream = new ofstream(filename.c_str(), fstream::binary | ios_base::out | ios_base::in | ofstream::ate); |
86 else | 86 else |
133 time_t now = time(0); | 133 time_t now = time(0); |
134 tm* gmtm = gmtime(&now); | 134 tm* gmtm = gmtime(&now); |
135 QString timestamp; | 135 QString timestamp; |
136 if (gmtm != NULL) | 136 if (gmtm != NULL) |
137 timestamp = QString("%1 %2").arg(", Created: ").arg(asctime(gmtm)).trimmed(); | 137 timestamp = QString("%1 %2").arg(", Created: ").arg(asctime(gmtm)).trimmed(); |
138 string info = QString(" SONIC ANNOTATOR v%1 PYTHON BINARY V0.1, Platform: %2-%3bit%4") | 138 string info = QString("_SONIC ANNOTATOR v%1 PYTHON BINARY V0.2, Platform: %2-%3bit%4") |
139 .arg(RUNNER_VERSION) | 139 .arg(RUNNER_VERSION) |
140 .arg(platform) | 140 .arg(platform) |
141 .arg(arch) | 141 .arg(arch) |
142 .arg(timestamp).toStdString(); | 142 .arg(timestamp).toStdString(); |
143 strncpy(reinterpret_cast<char*>(&header.info),info.c_str(), info.length() <= 160 ? info.length() : 160); | 143 strncpy(reinterpret_cast<char*>(&header.info),info.c_str(), info.length() <= 160 ? info.length() : 160); |