svcore  1.9
MatrixFile.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006-2009 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _MATRIX_FILE_CACHE_H_
17 #define _MATRIX_FILE_CACHE_H_
18 
19 #include "base/ResizeableBitset.h"
20 
21 #include "FileReadThread.h"
22 
23 #include <sys/types.h>
24 #include <QString>
25 #include <QMutex>
26 #include <map>
27 
28 class MatrixFile : public QObject
29 {
30  Q_OBJECT
31 
32 public:
33  enum Mode { ReadOnly, WriteOnly };
34 
61  MatrixFile(QString fileBase, Mode mode, int cellSize,
62  int width, int height);
63  virtual ~MatrixFile();
64 
65  Mode getMode() const { return m_mode; }
66 
67  int getWidth() const { return m_width; }
68  int getHeight() const { return m_height; }
69  int getCellSize() const { return m_cellSize; }
70 
75  void setAutoClose(bool a) { m_autoClose = a; }
76 
77  void close(); // does not decrement ref count; that happens in dtor
78 
79  bool haveSetColumnAt(int x) const;
80  void getColumnAt(int x, void *data); // may throw FileReadFailed
81  void setColumnAt(int x, const void *data);
82 
83 protected:
84  int m_fd;
86  int m_flags;
87  mode_t m_fmode;
89  int m_width;
90  int m_height;
92  QString m_fileName;
93 
94  ResizeableBitset *m_setColumns; // only in writer
96 
97  // In reader: if this is >= 0, we can read that column directly
98  // without seeking (and we know that the column exists)
99  mutable int m_readyToReadColumn;
100 
101  static std::map<QString, int> m_refcount;
102  static QMutex m_createMutex;
103 
104  void initialise();
105  bool seekTo(int col) const;
106 };
107 
108 #endif
109 
void setAutoClose(bool a)
If this is set true on a write-mode MatrixFile, then the file will close() itself when all columns ha...
Definition: MatrixFile.h:75
void initialise()
Definition: MatrixFile.cpp:195
void setColumnAt(int x, const void *data)
Definition: MatrixFile.cpp:341
ResizeableBitset * m_setColumns
Definition: MatrixFile.h:94
QString m_fileName
Definition: MatrixFile.h:92
int getCellSize() const
Definition: MatrixFile.h:69
bool haveSetColumnAt(int x) const
Definition: MatrixFile.cpp:306
virtual ~MatrixFile()
Definition: MatrixFile.cpp:158
int m_flags
Definition: MatrixFile.h:86
static std::map< QString, int > m_refcount
Definition: MatrixFile.h:101
Mode m_mode
Definition: MatrixFile.h:85
int m_width
Definition: MatrixFile.h:89
void close()
Definition: MatrixFile.cpp:248
int m_cellSize
Definition: MatrixFile.h:88
bool seekTo(int col) const
Definition: MatrixFile.cpp:411
Mode getMode() const
Definition: MatrixFile.h:65
int getHeight() const
Definition: MatrixFile.h:68
bool m_autoClose
Definition: MatrixFile.h:95
int getWidth() const
Definition: MatrixFile.h:67
MatrixFile(QString fileBase, Mode mode, int cellSize, int width, int height)
Construct a MatrixFile object reading from and/or writing to the matrix file with the given base name...
Definition: MatrixFile.cpp:54
int m_readyToReadColumn
Definition: MatrixFile.h:99
int m_height
Definition: MatrixFile.h:90
static QMutex m_createMutex
Definition: MatrixFile.h:102
mode_t m_fmode
Definition: MatrixFile.h:87
void getColumnAt(int x, void *data)
Definition: MatrixFile.cpp:266
int m_headerSize
Definition: MatrixFile.h:91