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