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 BPose* FindPoseByFileName(const char* name, int32* _index = NULL) const; 72 }; 73 74 // iteration glue, add permutations as needed 75 76 77 template<class EachParam1> 78 void 79 EachPoseAndModel(PoseList* list, 80 void (*eachFunction)(BPose*, Model*, EachParam1), 81 EachParam1 eachParam1) 82 { 83 for (int32 index = list->CountItems() - 1; index >= 0; index--) { 84 BPose* pose = list->ItemAt(index); 85 Model* model = pose->TargetModel(); 86 if (model) 87 (eachFunction)(pose, model, eachParam1); 88 } 89 } 90 91 92 template<class EachParam1> 93 void 94 EachPoseAndModel(PoseList* list, 95 void (*eachFunction)(BPose*, Model*, int32, EachParam1), 96 EachParam1 eachParam1) 97 { 98 for (int32 index = list->CountItems() - 1; index >= 0; index--) { 99 BPose* pose = list->ItemAt(index); 100 Model* model = pose->TargetModel(); 101 if (model) 102 (eachFunction)(pose, model, index, eachParam1); 103 } 104 } 105 106 107 template<class EachParam1, class EachParam2> 108 void 109 EachPoseAndModel(PoseList* list, 110 void (*eachFunction)(BPose*, Model*, EachParam1, EachParam2), 111 EachParam1 eachParam1, EachParam2 eachParam2) 112 { 113 for (int32 index = list->CountItems() - 1; index >= 0; index--) { 114 BPose* pose = list->ItemAt(index); 115 Model* model = pose->TargetModel(); 116 if (model) 117 (eachFunction)(pose, model, eachParam1, eachParam2); 118 } 119 } 120 121 template<class EachParam1, class EachParam2> 122 void 123 EachPoseAndModel(PoseList* list, 124 void (*eachFunction)(BPose*, Model*, int32, EachParam1, EachParam2), 125 EachParam1 eachParam1, EachParam2 eachParam2) 126 { 127 for (int32 index = list->CountItems() - 1; index >= 0; index--) { 128 BPose* pose = list->ItemAt(index); 129 Model* model = pose->TargetModel(); 130 if (model) 131 (eachFunction)(pose, model, index, eachParam1, eachParam2); 132 } 133 } 134 135 template<class EachParam1> 136 void 137 EachPoseAndResolvedModel(PoseList* list, 138 void (*eachFunction)(BPose*, Model*, EachParam1), EachParam1 eachParam1) 139 { 140 for (int32 index = list->CountItems() - 1; index >= 0; index--) { 141 BPose* pose = list->ItemAt(index); 142 Model* model = pose->TargetModel()->ResolveIfLink(); 143 if (model) 144 (eachFunction)(pose, model, eachParam1); 145 } 146 } 147 148 template<class EachParam1> 149 void 150 EachPoseAndResolvedModel(PoseList* list, 151 void (*eachFunction)(BPose*, Model*, int32 , EachParam1), 152 EachParam1 eachParam1) 153 { 154 for (int32 index = list->CountItems() - 1; index >= 0; index--) { 155 BPose* pose = list->ItemAt(index); 156 Model* model = pose->TargetModel()->ResolveIfLink(); 157 if (model) 158 (eachFunction)(pose, model, index, eachParam1); 159 } 160 } 161 162 template<class EachParam1, class EachParam2> 163 void 164 EachPoseAndResolvedModel(PoseList* list, 165 void (*eachFunction)(BPose*, Model*, EachParam1, EachParam2), 166 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, eachParam1, eachParam2); 173 } 174 } 175 176 template<class EachParam1, class EachParam2> 177 void 178 EachPoseAndResolvedModel(PoseList* list, 179 void (*eachFunction)(BPose*, Model*, int32, EachParam1, EachParam2), 180 EachParam1 eachParam1, EachParam2 eachParam2) 181 { 182 for (int32 index = list->CountItems() - 1; index >= 0; index--) { 183 BPose* pose = list->ItemAt(index); 184 Model* model = pose->TargetModel()->ResolveIfLink(); 185 if (model) 186 (eachFunction)(pose, model, index, eachParam1, eachParam2); 187 } 188 } 189 190 } // namespace BPrivate 191 192 using namespace BPrivate; 193 194 #endif // _POSE_LIST_H 195