xref: /haiku/src/kits/tracker/PoseList.h (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
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 #ifndef _POSE_LIST_H
38 #define _POSE_LIST_H
39 
40 
41 #include <ObjectList.h>
42 
43 #include "Pose.h"
44 
45 
46 struct node_ref;
47 struct entry_ref;
48 
49 namespace BPrivate {
50 
51 class Model;
52 
53 
54 class PoseList : public BObjectList<BPose> {
55 public:
56 	PoseList(int32 itemsPerBlock = 20, bool owning = false)
57 		:
58 		BObjectList<BPose>(itemsPerBlock, owning)
59 	{
60 	}
61 
62 	PoseList(const PoseList &list)
63 		:
64 		BObjectList<BPose>(list)
65 	{
66 	}
67 
68 	BPose* FindPose(const node_ref* node, int32* index = NULL) const;
69 	BPose* FindPose(const entry_ref* entry, int32* index = NULL) const;
70 	BPose* FindPose(const Model* model, int32* index = NULL) const;
71 	BPose* DeepFindPose(const node_ref* node, int32* index = NULL) const;
72 		// same as FindPose, node can be a target of the actual
73 		// pose if the pose is a symlink
74 	PoseList* FindAllPoses(const node_ref* node) const;
75 
76 	BPose* FindPoseByFileName(const char* name, int32* _index = NULL) const;
77 };
78 
79 
80 // iteration glue, add permutations as needed
81 
82 
83 template<class EachParam1>
84 void
85 EachPoseAndModel(PoseList* list,
86 	void (*eachFunction)(BPose*, Model*, EachParam1),
87 	EachParam1 eachParam1)
88 {
89 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
90 		BPose* pose = list->ItemAt(index);
91 		Model* model = pose->TargetModel();
92 		if (model != NULL)
93 			(eachFunction)(pose, model, eachParam1);
94 	}
95 }
96 
97 
98 template<class EachParam1>
99 void
100 EachPoseAndModel(PoseList* list,
101 	void (*eachFunction)(BPose*, Model*, int32, EachParam1),
102 	EachParam1 eachParam1)
103 {
104 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
105 		BPose* pose = list->ItemAt(index);
106 		Model* model = pose->TargetModel();
107 		if (model != NULL)
108 			(eachFunction)(pose, model, index, eachParam1);
109 	}
110 }
111 
112 
113 template<class EachParam1, class EachParam2>
114 void
115 EachPoseAndModel(PoseList* list,
116 	void (*eachFunction)(BPose*, Model*, EachParam1, EachParam2),
117 	EachParam1 eachParam1, EachParam2 eachParam2)
118 {
119 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
120 		BPose* pose = list->ItemAt(index);
121 		Model* model = pose->TargetModel();
122 		if (model != NULL)
123 			(eachFunction)(pose, model, eachParam1, eachParam2);
124 	}
125 }
126 
127 
128 template<class EachParam1, class EachParam2>
129 void
130 EachPoseAndModel(PoseList* list,
131 	void (*eachFunction)(BPose*, Model*, int32, EachParam1, EachParam2),
132 	EachParam1 eachParam1, EachParam2 eachParam2)
133 {
134 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
135 		BPose* pose = list->ItemAt(index);
136 		Model* model = pose->TargetModel();
137 		if (model != NULL)
138 			(eachFunction)(pose, model, index, eachParam1, eachParam2);
139 	}
140 }
141 
142 
143 template<class EachParam1>
144 void
145 EachPoseAndResolvedModel(PoseList* list,
146 	void (*eachFunction)(BPose*, Model*, EachParam1), EachParam1 eachParam1)
147 {
148 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
149 		BPose* pose = list->ItemAt(index);
150 		Model* model = pose->TargetModel()->ResolveIfLink();
151 		if (model != NULL)
152 			(eachFunction)(pose, model, eachParam1);
153 	}
154 }
155 
156 
157 template<class EachParam1>
158 void
159 EachPoseAndResolvedModel(PoseList* list,
160 	void (*eachFunction)(BPose*, Model*, int32 , EachParam1),
161 	EachParam1 eachParam1)
162 {
163 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
164 		BPose* pose = list->ItemAt(index);
165 		Model* model = pose->TargetModel()->ResolveIfLink();
166 		if (model != NULL)
167 			(eachFunction)(pose, model, index, eachParam1);
168 	}
169 }
170 
171 
172 template<class EachParam1, class EachParam2>
173 void
174 EachPoseAndResolvedModel(PoseList* list,
175 	void (*eachFunction)(BPose*, Model*, EachParam1, EachParam2),
176 	EachParam1 eachParam1, EachParam2 eachParam2)
177 {
178 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
179 		BPose* pose = list->ItemAt(index);
180 		Model* model = pose->TargetModel()->ResolveIfLink();
181 		if (model != NULL)
182 			(eachFunction)(pose, model, eachParam1, eachParam2);
183 	}
184 }
185 
186 
187 template<class EachParam1, class EachParam2>
188 void
189 EachPoseAndResolvedModel(PoseList* list,
190 	void (*eachFunction)(BPose*, Model*, int32, EachParam1, EachParam2),
191 	EachParam1 eachParam1, EachParam2 eachParam2)
192 {
193 	for (int32 index = list->CountItems() - 1; index >= 0; index--) {
194 		BPose* pose = list->ItemAt(index);
195 		Model* model = pose->TargetModel()->ResolveIfLink();
196 		if (model != NULL)
197 			(eachFunction)(pose, model, index, eachParam1, eachParam2);
198 	}
199 }
200 
201 } // namespace BPrivate
202 
203 using namespace BPrivate;
204 
205 
206 #endif	// _POSE_LIST_H
207