btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / tracker / NodeWalker.h
blob7c5eafc8997bf94441b23265e9703ffc36c07b88
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
34 #ifndef _NODE_WALKER_H
35 #define _NODE_WALKER_H
38 #ifndef _BE_BUILD_H
39 # include <BeBuild.h>
40 #endif
41 #include <Directory.h>
42 #include <Entry.h>
43 #include <EntryList.h>
44 #include <List.h>
45 #include <ObjectList.h>
46 #include <Query.h>
47 #include <Volume.h>
48 #include <VolumeRoster.h>
51 namespace BTrackerPrivate {
53 class TWalker : public BEntryList {
54 // adds a virtual destructor that is severely missing in BEntryList
55 // BEntryList should never be used polymorphically because of that
56 public:
57 virtual ~TWalker();
59 virtual status_t GetNextEntry(BEntry*, bool traverse = false) = 0;
60 virtual status_t GetNextRef(entry_ref*) = 0;
61 virtual int32 GetNextDirents(struct dirent*, size_t,
62 int32 count = INT_MAX) = 0;
63 virtual status_t Rewind() = 0;
64 virtual int32 CountEntries() = 0;
68 class TNodeWalker : public TWalker {
69 // TNodeWalker supports iterating a single volume, starting from a specified
70 // entry; if passed a non-directory entry it returns just that one entry
71 public:
72 TNodeWalker(bool includeTopDirectory);
73 TNodeWalker(const char* path, bool includeTopDirectory);
74 TNodeWalker(const entry_ref* ref, bool includeTopDirectory);
75 TNodeWalker(const BDirectory* dir, bool includeTopDirectory);
76 virtual ~TNodeWalker();
78 // Backwards compatibility with Tracker compiled for R5 (remove when this
79 // gets integrated into the official release).
80 TNodeWalker();
81 TNodeWalker(const char* path);
82 TNodeWalker(const entry_ref* ref);
83 TNodeWalker(const BDirectory* dir);
85 virtual status_t GetNextEntry(BEntry*, bool traverse = false);
86 virtual status_t GetNextRef(entry_ref*);
87 virtual int32 GetNextDirents(struct dirent*, size_t,
88 int32 count = INT_MAX);
89 virtual status_t Rewind();
91 protected:
92 status_t PopDirCommon();
93 void PushDirCommon(const entry_ref*);
95 private:
96 virtual int32 CountEntries();
97 // don't know how to do that, have just a fake stub here
99 protected:
100 BObjectList<BDirectory> fDirs;
101 int32 fTopIndex;
102 BDirectory* fTopDir;
103 bool fIncludeTopDir;
104 bool fOriginalIncludeTopDir;
106 private:
107 BEntry* fJustFile;
108 BDirectory fOriginalDirCopy;
109 BEntry* fOriginalJustFile;
110 // keep around to support Rewind
114 class TVolWalker : public TNodeWalker {
115 // TNodeWalker supports iterating over all the mounted volumes;
116 // non-attribute and read-only volumes may optionaly be filtered out
117 public:
118 TVolWalker(bool knows_attr = true, bool writable = true,
119 bool includeTopDirectory = true);
120 virtual ~TVolWalker();
122 virtual status_t GetNextEntry(BEntry*, bool traverse = false);
123 virtual status_t GetNextRef(entry_ref*);
124 virtual int32 GetNextDirents(struct dirent*, size_t,
125 int32 count = INT_MAX);
126 virtual status_t Rewind();
128 virtual status_t NextVolume();
129 // skips to the next volume
130 // Note: it would be cool to return const BVolume*
131 // that way a subclass could implement a volume filter -
132 // it would just override, call inherited for as long as there
133 // are volumes and it does not like them
134 // we would have to give up the status_t then, which might be
135 // ok
137 private:
138 BVolumeRoster fVolRoster;
139 BVolume fVol;
140 bool fKnowsAttr;
141 bool fWritable;
143 typedef TNodeWalker _inherited;
147 class TQueryWalker : public TWalker {
148 public:
149 TQueryWalker(const char* predicate);
150 virtual ~TQueryWalker();
152 // Does an in-fix walk of all entries
153 virtual status_t GetNextEntry(BEntry*, bool traverse = false);
154 virtual status_t GetNextRef(entry_ref*);
155 virtual int32 GetNextDirents(struct dirent*, size_t,
156 int32 count = INT_MAX);
158 virtual status_t NextVolume();
159 // skips to the next volume
160 virtual status_t Rewind();
162 private:
163 virtual int32 CountEntries();
164 // can't count
166 BQuery fQuery;
167 BVolumeRoster fVolRoster;
168 BVolume fVol;
169 bigtime_t fTime;
170 const char* fPredicate;
172 typedef TQueryWalker _inherited;
175 } // namespace BTrackerPrivate
177 using namespace BTrackerPrivate;
180 #endif // _NODE_WALKER_H