xref: /haiku/src/add-ons/kernel/file_systems/netfs/client/QueryIterator.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 // QueryIterator.cpp
2 
3 #include "QueryIterator.h"
4 
5 // constructor
6 QueryIterator::QueryIterator(Volume* volume)
7 	:
8 	BReferenceable(),
9 	fVolume(volume),
10 	fParentIterator(NULL),
11 	fVolumeLink()
12 {
13 }
14 
15 // destructor
16 QueryIterator::~QueryIterator()
17 {
18 }
19 
20 // GetVolume
21 Volume*
22 QueryIterator::GetVolume() const
23 {
24 	return fVolume;
25 }
26 
27 // SetParentIterator
28 void
29 QueryIterator::SetParentIterator(HierarchicalQueryIterator* parent)
30 {
31 	fParentIterator = parent;
32 }
33 
34 // GetParentIterator
35 HierarchicalQueryIterator*
36 QueryIterator::GetParentIterator() const
37 {
38 	return fParentIterator;
39 }
40 
41 // ReadQuery
42 status_t
43 QueryIterator::ReadQuery(struct dirent* buffer, size_t bufferSize, int32 count,
44 	int32* countRead, bool* done)
45 {
46 	*countRead = 0;
47 	*done = true;
48 	return B_OK;
49 }
50 
51 
52 void
53 QueryIterator::LastReferenceReleased()
54 {
55 	// don't delete
56 }
57 
58 
59 // #pragma mark -
60 
61 // constructor
62 HierarchicalQueryIterator::HierarchicalQueryIterator(Volume* volume)
63 	: QueryIterator(volume),
64 	  fSubIterators(),
65 	  fCurrentSubIterator(NULL)
66 {
67 }
68 
69 // destructor
70 HierarchicalQueryIterator::~HierarchicalQueryIterator()
71 {
72 }
73 
74 // GetCurrentSubIterator
75 QueryIterator*
76 HierarchicalQueryIterator::GetCurrentSubIterator() const
77 {
78 	return fCurrentSubIterator;
79 }
80 
81 // NextSubIterator
82 QueryIterator*
83 HierarchicalQueryIterator::NextSubIterator()
84 {
85 	if (fCurrentSubIterator)
86 		fCurrentSubIterator = fSubIterators.GetNext(fCurrentSubIterator);
87 	return fCurrentSubIterator;
88 }
89 
90 // RewindSubIterator
91 void
92 HierarchicalQueryIterator::RewindSubIterator()
93 {
94 	fCurrentSubIterator = fSubIterators.First();
95 }
96 
97 // AddSubIterator
98 void
99 HierarchicalQueryIterator::AddSubIterator(QueryIterator* subIterator)
100 {
101 	if (!subIterator)
102 		return;
103 
104 	fSubIterators.Insert(subIterator);
105 	subIterator->SetParentIterator(this);
106 	if (!fCurrentSubIterator)
107 		fCurrentSubIterator = subIterator;
108 }
109 
110 // RemoveSubIterator
111 void
112 HierarchicalQueryIterator::RemoveSubIterator(QueryIterator* subIterator)
113 {
114 	if (!subIterator)
115 		return;
116 
117 	if (fCurrentSubIterator == subIterator)
118 		NextSubIterator();
119 	subIterator->SetParentIterator(NULL);
120 	fSubIterators.Remove(subIterator);
121 }
122 
123 // RemoveAllSubIterators
124 void
125 HierarchicalQueryIterator::RemoveAllSubIterators(
126 	DoublyLinkedList<QueryIterator>& subIterators)
127 {
128 	while (QueryIterator* iterator = fSubIterators.First()) {
129 		RemoveSubIterator(iterator);
130 		subIterators.Insert(iterator);
131 	}
132 }
133 
134