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