svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006-2009 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _MATRIX_FILE_CACHE_H_ 00017 #define _MATRIX_FILE_CACHE_H_ 00018 00019 #include "base/ResizeableBitset.h" 00020 00021 #include "FileReadThread.h" 00022 00023 #include <sys/types.h> 00024 #include <QString> 00025 #include <QMutex> 00026 #include <map> 00027 00028 class MatrixFile : public QObject 00029 { 00030 Q_OBJECT 00031 00032 public: 00033 enum Mode { ReadOnly, WriteOnly }; 00034 00061 MatrixFile(QString fileBase, Mode mode, int cellSize, 00062 int width, int height); 00063 virtual ~MatrixFile(); 00064 00065 Mode getMode() const { return m_mode; } 00066 00067 int getWidth() const { return m_width; } 00068 int getHeight() const { return m_height; } 00069 int getCellSize() const { return m_cellSize; } 00070 00075 void setAutoClose(bool a) { m_autoClose = a; } 00076 00077 void close(); // does not decrement ref count; that happens in dtor 00078 00079 bool haveSetColumnAt(int x) const; 00080 void getColumnAt(int x, void *data); // may throw FileReadFailed 00081 void setColumnAt(int x, const void *data); 00082 00083 protected: 00084 int m_fd; 00085 Mode m_mode; 00086 int m_flags; 00087 mode_t m_fmode; 00088 int m_cellSize; 00089 int m_width; 00090 int m_height; 00091 int m_headerSize; 00092 QString m_fileName; 00093 00094 ResizeableBitset *m_setColumns; // only in writer 00095 bool m_autoClose; 00096 00097 // In reader: if this is >= 0, we can read that column directly 00098 // without seeking (and we know that the column exists) 00099 mutable int m_readyToReadColumn; 00100 00101 static std::map<QString, int> m_refcount; 00102 static QMutex m_createMutex; 00103 00104 void initialise(); 00105 bool seekTo(int col) const; 00106 }; 00107 00108 #endif 00109