#include "CLucene/StdHeader.h"
#ifndef _lucene_store_RAMDirectory_
#define _lucene_store_RAMDirectory_
#include "Lock.h"
#include "Directory.h"
#include "CLucene/util/VoidMap.h"
#include "CLucene/util/Arrays.h"
namespace
lucene{
namespace
store{
class
RAMDirectory;
class
RAMFile {
public
:
lucene::util::VoidList<l_byte_t*> buffers;
long_t length;
long_t lastModified;
#ifdef _DEBUG
char_t* filename;
#endif
RAMFile();
~RAMFile();
};
#ifndef CLUCENE_LITE
class
RAMLock:
public
virtual
LuceneLock{
private
:
RAMDirectory* directory;
const
char_t* fname;
public
:
RAMLock(
const
char_t* name, RAMDirectory* dir);
~RAMLock();
bool
obtain();
void
release();
};
#endif
#ifndef CLUCENE_LITE
class
RAMOutputStream:
public
OutputStream {
protected
:
RAMOutputStream(RAMOutputStream& clone);
public
:
RAMFile& file;
int_t pointer;
RAMOutputStream(RAMFile& f);
~RAMOutputStream();
OutputStream& clone();
void
flushBuffer(
const
l_byte_t* src,
const
int_t len);
virtual
void
close();
virtual
void
seek(
const
long_t pos);
long_t Length();
};
#endif
class
RAMInputStream:
public
InputStream {
private
:
RAMFile& file;
int_t pointer;
public
:
RAMInputStream(RAMFile& f);
RAMInputStream(RAMInputStream& clone);
~RAMInputStream();
InputStream& clone();
void
readInternal(l_byte_t *dest,
const
int_t idestOffset,
const
int_t len);
void
close();
void
seekInternal(
const
long_t pos);
RAMInputStream& operator=(
const
RAMInputStream& str )
{
throw
"CAN'T ASSIGN THIS OBJECT"
;
}
};
class
RAMDirectory:
public
Directory{
protected
:
lucene::util::VoidMap<
const
char_t*,RAMFile*> files;
public
:
DEFINE_MUTEX(files_mutex);
void
list(char_t**& list, int_t& size);
RAMDirectory();
~RAMDirectory();
bool
fileExists(
const
char_t* name)
const
;
long_t fileModified(
const
char_t* name)
const
;
long_t fileLength(
const
char_t* name)
const
;
#ifndef CLUCENE_LITE
virtual
void
renameFile(
const
char_t* from,
const
char_t* to);
virtual
void
deleteFile(
const
char_t* name,
const
bool
throwError =
true
);
virtual
OutputStream& createFile(
const
char_t* name);
LuceneLock* makeLock(
const
char_t* name);
#endif
InputStream& openFile(
const
char_t* name);
virtual
void
close();
};
}}
#endif