comparison data/fileio/MatrixFile.cpp @ 936:0c1d6de8f44b

Merge from branch warnfix_no_size_t
author Chris Cannam
date Wed, 18 Jun 2014 13:51:16 +0100
parents 59e7fe1b1003
children ce82bcdc95d0
comparison
equal deleted inserted replaced
917:49618f39ff09 936:0c1d6de8f44b
50 static size_t totalStorage = 0; 50 static size_t totalStorage = 0;
51 static size_t totalCount = 0; 51 static size_t totalCount = 0;
52 static size_t openCount = 0; 52 static size_t openCount = 0;
53 53
54 MatrixFile::MatrixFile(QString fileBase, Mode mode, 54 MatrixFile::MatrixFile(QString fileBase, Mode mode,
55 size_t cellSize, size_t width, size_t height) : 55 int cellSize, int width, int height) :
56 m_fd(-1), 56 m_fd(-1),
57 m_mode(mode), 57 m_mode(mode),
58 m_flags(0), 58 m_flags(0),
59 m_fmode(0), 59 m_fmode(0),
60 m_cellSize(cellSize), 60 m_cellSize(cellSize),
61 m_width(width), 61 m_width(width),
62 m_height(height), 62 m_height(height),
63 m_headerSize(2 * sizeof(size_t)), 63 m_headerSize(2 * sizeof(int)),
64 m_setColumns(0), 64 m_setColumns(0),
65 m_autoClose(false), 65 m_autoClose(false),
66 m_readyToReadColumn(-1) 66 m_readyToReadColumn(-1)
67 { 67 {
68 Profiler profiler("MatrixFile::MatrixFile", true); 68 Profiler profiler("MatrixFile::MatrixFile", true);
123 #endif 123 #endif
124 124
125 if (newFile) { 125 if (newFile) {
126 initialise(); // write header and "unwritten" column tags 126 initialise(); // write header and "unwritten" column tags
127 } else { 127 } else {
128 size_t header[2]; 128 int header[2];
129 if (::read(m_fd, header, 2 * sizeof(size_t)) < 0) { 129 if (::read(m_fd, header, 2 * sizeof(int)) < 0) {
130 ::perror("MatrixFile::MatrixFile: read failed"); 130 ::perror("MatrixFile::MatrixFile: read failed");
131 cerr << "ERROR: MatrixFile::MatrixFile: " 131 cerr << "ERROR: MatrixFile::MatrixFile: "
132 << "Failed to read header (fd " << m_fd << ", file \"" 132 << "Failed to read header (fd " << m_fd << ", file \""
133 << fileName << "\")" << endl; 133 << fileName << "\")" << endl;
134 throw FileReadFailed(fileName); 134 throw FileReadFailed(fileName);
220 if (::lseek(m_fd, 0, SEEK_SET) < 0) { 220 if (::lseek(m_fd, 0, SEEK_SET) < 0) {
221 ::perror("ERROR: MatrixFile::initialise: Seek to write header failed"); 221 ::perror("ERROR: MatrixFile::initialise: Seek to write header failed");
222 throw FileOperationFailed(m_fileName, "lseek"); 222 throw FileOperationFailed(m_fileName, "lseek");
223 } 223 }
224 224
225 size_t header[2]; 225 int header[2];
226 header[0] = m_width; 226 header[0] = m_width;
227 header[1] = m_height; 227 header[1] = m_height;
228 if (::write(m_fd, header, 2 * sizeof(size_t)) != 2 * sizeof(size_t)) { 228 if (::write(m_fd, header, 2 * sizeof(int)) != 2 * sizeof(int)) {
229 ::perror("ERROR: MatrixFile::initialise: Failed to write header"); 229 ::perror("ERROR: MatrixFile::initialise: Failed to write header");
230 throw FileOperationFailed(m_fileName, "write"); 230 throw FileOperationFailed(m_fileName, "write");
231 } 231 }
232 232
233 if (m_mode == WriteOnly) { 233 if (m_mode == WriteOnly) {
261 #endif 261 #endif
262 } 262 }
263 } 263 }
264 264
265 void 265 void
266 MatrixFile::getColumnAt(size_t x, void *data) 266 MatrixFile::getColumnAt(int x, void *data)
267 { 267 {
268 assert(m_mode == ReadOnly); 268 assert(m_mode == ReadOnly);
269 269
270 #ifdef DEBUG_MATRIX_FILE_READ_SET 270 #ifdef DEBUG_MATRIX_FILE_READ_SET
271 cerr << "MatrixFile[" << m_fd << "]::getColumnAt(" << x << ")" << endl; 271 cerr << "MatrixFile[" << m_fd << "]::getColumnAt(" << x << ")" << endl;
274 Profiler profiler("MatrixFile::getColumnAt"); 274 Profiler profiler("MatrixFile::getColumnAt");
275 275
276 ssize_t r = -1; 276 ssize_t r = -1;
277 277
278 if (m_readyToReadColumn < 0 || 278 if (m_readyToReadColumn < 0 ||
279 size_t(m_readyToReadColumn) != x) { 279 m_readyToReadColumn != x) {
280 280
281 unsigned char set = 0; 281 unsigned char set = 0;
282 if (!seekTo(x)) { 282 if (!seekTo(x)) {
283 cerr << "ERROR: MatrixFile::getColumnAt(" << x << "): Seek failed" << endl; 283 cerr << "ERROR: MatrixFile::getColumnAt(" << x << "): Seek failed" << endl;
284 throw FileOperationFailed(m_fileName, "seek"); 284 throw FileOperationFailed(m_fileName, "seek");
301 throw FileReadFailed(m_fileName); 301 throw FileReadFailed(m_fileName);
302 } 302 }
303 } 303 }
304 304
305 bool 305 bool
306 MatrixFile::haveSetColumnAt(size_t x) const 306 MatrixFile::haveSetColumnAt(int x) const
307 { 307 {
308 if (m_mode == WriteOnly) { 308 if (m_mode == WriteOnly) {
309 return m_setColumns->get(x); 309 return m_setColumns->get(x);
310 } 310 }
311 311
312 if (m_readyToReadColumn >= 0 && 312 if (m_readyToReadColumn >= 0 &&
313 size_t(m_readyToReadColumn) == x) return true; 313 int(m_readyToReadColumn) == x) return true;
314 314
315 Profiler profiler("MatrixFile::haveSetColumnAt"); 315 Profiler profiler("MatrixFile::haveSetColumnAt");
316 316
317 #ifdef DEBUG_MATRIX_FILE_READ_SET 317 #ifdef DEBUG_MATRIX_FILE_READ_SET
318 cerr << "MatrixFile[" << m_fd << "]::haveSetColumnAt(" << x << ")" << endl; 318 cerr << "MatrixFile[" << m_fd << "]::haveSetColumnAt(" << x << ")" << endl;
336 336
337 return set; 337 return set;
338 } 338 }
339 339
340 void 340 void
341 MatrixFile::setColumnAt(size_t x, const void *data) 341 MatrixFile::setColumnAt(int x, const void *data)
342 { 342 {
343 assert(m_mode == WriteOnly); 343 assert(m_mode == WriteOnly);
344 if (m_fd < 0) return; // closed 344 if (m_fd < 0) return; // closed
345 345
346 #ifdef DEBUG_MATRIX_FILE_READ_SET 346 #ifdef DEBUG_MATRIX_FILE_READ_SET
406 } 406 }
407 } 407 }
408 } 408 }
409 409
410 bool 410 bool
411 MatrixFile::seekTo(size_t x) const 411 MatrixFile::seekTo(int x) const
412 { 412 {
413 if (m_fd < 0) { 413 if (m_fd < 0) {
414 cerr << "ERROR: MatrixFile::seekTo: File not open" << endl; 414 cerr << "ERROR: MatrixFile::seekTo: File not open" << endl;
415 return false; 415 return false;
416 } 416 }