xref: /haiku/src/add-ons/kernel/file_systems/ramfs/Index.h (revision c237c4ce593ee823d9867fd997e51e4c447f5623)
1 /*
2  * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * All rights reserved. Distributed under the terms of the MIT license.
4  */
5 #ifndef INDEX_H
6 #define INDEX_H
7 
8 #include <SupportDefs.h>
9 
10 #include "String.h"
11 
12 class AbstractIndexEntryIterator;
13 class Entry;
14 class IndexEntryIterator;
15 class Node;
16 class Volume;
17 
18 // Index
19 class Index {
20 public:
21 	Index(Volume *volume, const char *name, uint32 type,
22 		  bool fixedKeyLength, size_t keyLength = 0);
23 	virtual ~Index();
24 
25 	status_t InitCheck() const;
26 
27 	Volume *GetVolume() const		{ return fVolume; }
28 	void GetVolume(Volume *volume)	{ fVolume = volume; }
29 
30 	const char *GetName() const		{ return fName.GetString(); }
31 	uint32 GetType() const			{ return fType; }
32 	bool HasFixedKeyLength() const	{ return fFixedKeyLength; }
33 	size_t GetKeyLength() const		{ return fKeyLength; }
34 
35 	virtual int32 CountEntries() const = 0;
36 
37 	bool GetIterator(IndexEntryIterator *iterator);
38 	bool Find(const uint8 *key, size_t length,
39 			  IndexEntryIterator *iterator);
40 
41 	// debugging
42 	void Dump();
43 
44 protected:
45 	virtual AbstractIndexEntryIterator *InternalGetIterator() = 0;
46 	virtual AbstractIndexEntryIterator *InternalFind(const uint8 *key,
47 													 size_t length) = 0;
48 
49 protected:
50 	Volume		*fVolume;
51 	status_t	fInitStatus;
52 	String		fName;
53 	uint32		fType;
54 	size_t		fKeyLength;
55 	bool		fFixedKeyLength;
56 };
57 
58 // IndexEntryIterator
59 class IndexEntryIterator {
60 public:
61 	IndexEntryIterator();
62 	IndexEntryIterator(Index *index);
63 	~IndexEntryIterator();
64 
65 	Entry *GetCurrent();
66 	Entry *GetCurrent(uint8 *buffer, size_t *keyLength);
67 	Entry *GetPrevious();
68 	Entry *GetNext();
69 	Entry *GetNext(uint8 *buffer, size_t *keyLength);
70 
71 	status_t Suspend();
72 	status_t Resume();
73 
74 private:
75 	void SetIterator(AbstractIndexEntryIterator *iterator);
76 
77 private:
78 	friend class Index;
79 
80 	AbstractIndexEntryIterator	*fIterator;
81 };
82 
83 #endif	// INDEX_H
84