xref: /haiku/src/kits/tracker/PoseList.h (revision fef6144999c2fa611f59ee6ffe6dd7999501385c)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
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:
14 
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.
17 
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.
24 
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.
28 
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.
33 */
34 
35 //	PoseList is a commonly used instance of BObjectList<BPose>
36 //	Defines convenience find and iteration calls
37 
38 #ifndef	_POSE_LIST_H
39 #define _POSE_LIST_H
40 
41 #include "ObjectList.h"
42 
43 struct node_ref;
44 struct entry_ref;
45 
46 namespace BPrivate {
47 
48 class BPose;
49 class Model;
50 
51 class PoseList : public BObjectList<BPose> {
52 public:
53 	PoseList(int32 itemsPerBlock = 20, bool owning = false)
54 		:	BObjectList<BPose>(itemsPerBlock, owning)
55 		{}
56 
57 	PoseList(const PoseList &list)
58 		:	BObjectList<BPose>(list)
59 		{}
60 
61 	BPose *FindPose(const node_ref *node, int32 *index = NULL) const;
62 	BPose *FindPose(const entry_ref *entry, int32 *index = NULL) const;
63 	BPose *FindPose(const Model *model, int32 *index = NULL) const;
64 	BPose *DeepFindPose(const node_ref *node, int32 *index = NULL) const;
65 		// same as FindPose, node can be a target of the actual
66 		// pose if the pose is a symlink
67 	BPose *FindVolumePose(const dev_t device, int32 *index = NULL) const;
68 };
69 
70 // iteration glue, add permutations as needed
71 
72 template<class EachParam1>
73 void
74 EachPoseAndModel(PoseList *list, void (*eachFunction)(BPose *, Model *, EachParam1),
75 	EachParam1 eachParam1)
76 {
77 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
78 		BPose *pose = list->ItemAt(index);
79 		Model *model = pose->TargetModel();
80 		if (model)
81 			(eachFunction)(pose, model, eachParam1);
82 	}
83 }
84 
85 template<class EachParam1>
86 void
87 EachPoseAndModel(PoseList *list, void (*eachFunction)(BPose *, Model *, int32 ,
88 	EachParam1), EachParam1 eachParam1)
89 {
90 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
91 		BPose *pose = list->ItemAt(index);
92 		Model *model = pose->TargetModel();
93 		if (model)
94 			(eachFunction)(pose, model, index, eachParam1);
95 	}
96 }
97 
98 template<class EachParam1, class EachParam2>
99 void
100 EachPoseAndModel(PoseList *list, void (*eachFunction)(BPose *, Model *, EachParam1,
101 	EachParam2), EachParam1 eachParam1, EachParam2 eachParam2)
102 {
103 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
104 		BPose *pose = list->ItemAt(index);
105 		Model *model = pose->TargetModel();
106 		if (model)
107 			(eachFunction)(pose, model, eachParam1, eachParam2);
108 	}
109 }
110 
111 template<class EachParam1, class EachParam2>
112 void
113 EachPoseAndModel(PoseList *list, void (*eachFunction)(BPose *, Model *, int32,
114 	EachParam1, EachParam2), EachParam1 eachParam1, EachParam2 eachParam2)
115 {
116 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
117 		BPose *pose = list->ItemAt(index);
118 		Model *model = pose->TargetModel();
119 		if (model)
120 			(eachFunction)(pose, model, index, eachParam1, eachParam2);
121 	}
122 }
123 
124 template<class EachParam1>
125 void
126 EachPoseAndResolvedModel(PoseList *list, void (*eachFunction)(BPose *, Model *, EachParam1),
127 	EachParam1 eachParam1)
128 {
129 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
130 		BPose *pose = list->ItemAt(index);
131 		Model *model = pose->TargetModel()->ResolveIfLink();
132 		if (model)
133 			(eachFunction)(pose, model, eachParam1);
134 	}
135 }
136 
137 template<class EachParam1>
138 void
139 EachPoseAndResolvedModel(PoseList *list, void (*eachFunction)(BPose *, Model *, int32 ,
140 	EachParam1), EachParam1 eachParam1)
141 {
142 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
143 		BPose *pose = list->ItemAt(index);
144 		Model *model = pose->TargetModel()->ResolveIfLink();
145 		if (model)
146 			(eachFunction)(pose, model, index, eachParam1);
147 	}
148 }
149 
150 template<class EachParam1, class EachParam2>
151 void
152 EachPoseAndResolvedModel(PoseList *list, void (*eachFunction)(BPose *, Model *, EachParam1,
153 	EachParam2), EachParam1 eachParam1, EachParam2 eachParam2)
154 {
155 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
156 		BPose *pose = list->ItemAt(index);
157 		Model *model = pose->TargetModel()->ResolveIfLink();
158 		if (model)
159 			(eachFunction)(pose, model, eachParam1, eachParam2);
160 	}
161 }
162 
163 template<class EachParam1, class EachParam2>
164 void
165 EachPoseAndResolvedModel(PoseList *list, void (*eachFunction)(BPose *, Model *, int32,
166 	EachParam1, EachParam2), EachParam1 eachParam1, EachParam2 eachParam2)
167 {
168 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
169 		BPose *pose = list->ItemAt(index);
170 		Model *model = pose->TargetModel()->ResolveIfLink();
171 		if (model)
172 			(eachFunction)(pose, model, index, eachParam1, eachParam2);
173 	}
174 }
175 
176 } // namespace BPrivate
177 
178 using namespace BPrivate;
179 
180 #endif
181