kwave  18.07.70
SwapFile.h
Go to the documentation of this file.
1 /***************************************************************************
2  SwapFile.h - Provides virtual memory in a swap file
3  -------------------
4  begin : Fri Aug 17 2001
5  copyright : (C) 2000 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SWAP_FILE_H
19 #define SWAP_FILE_H
20 
21 #include "config.h"
22 #include <sys/types.h> // for size_t
23 
24 #include <QFile>
25 #include <QTemporaryFile>
26 
27 class QString;
28 
29 namespace Kwave
30 {
31 
32  class SwapFile
33  {
34  public:
40  explicit SwapFile(const QString &name);
41 
43  virtual ~SwapFile();
44 
52  bool allocate(size_t size);
53 
58  inline void *address() const { return m_address; }
59 
64  inline size_t size() const { return m_size; }
65 
67  inline int mapCount() const { return m_map_count; }
68 
72  inline size_t pagesize() const { return m_pagesize; }
73 
79  bool resize(size_t size);
80 
86  void *map();
87 
93  int unmap();
94 
103  int read(unsigned int offset, void *buffer, unsigned int length);
104 
113  int write(unsigned int offset, const void *buffer, unsigned int length);
114 
115  private:
116 
121  void close();
122 
123  private:
124 
126  QTemporaryFile m_file;
127 
129  void *m_address;
130 
132  size_t m_size;
133 
135  size_t m_pagesize;
136 
139 
140  };
141 }
142 
143 #endif /* SWAP_FILE_H */
144 
145 //***************************************************************************
146 //***************************************************************************
void * map()
Definition: SwapFile.cpp:206
Definition: App.h:33
void * address() const
Definition: SwapFile.h:58
int write(unsigned int offset, const void *buffer, unsigned int length)
Definition: SwapFile.cpp:274
const char name[16]
Definition: memcpy.c:510
size_t m_pagesize
Definition: SwapFile.h:135
int read(unsigned int offset, void *buffer, unsigned int length)
Definition: SwapFile.cpp:258
size_t pagesize() const
Definition: SwapFile.h:72
bool allocate(size_t size)
Definition: SwapFile.cpp:65
size_t size() const
Definition: SwapFile.h:64
size_t m_size
Definition: SwapFile.h:132
SwapFile(const QString &name)
Definition: SwapFile.cpp:37
virtual ~SwapFile()
Definition: SwapFile.cpp:58
bool resize(size_t size)
Definition: SwapFile.cpp:122
int mapCount() const
Definition: SwapFile.h:67
void * m_address
Definition: SwapFile.h:129
QTemporaryFile m_file
Definition: SwapFile.h:126