btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / tracker / PoseList.cpp
blobedaba3d696c814afae1609ff0715b3b605499dd7
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
35 // Icon cache is used for drawing node icons; it caches icons
36 // and reuses them for successive draws
38 #include <Debug.h>
40 #include "PoseList.h"
43 BPose*
44 PoseList::FindPose(const node_ref* node, int32* resultingIndex) const
46 int32 count = CountItems();
47 for (int32 index = 0; index < count; index++) {
48 BPose* pose = ItemAt(index);
49 ASSERT(pose->TargetModel());
50 if (*pose->TargetModel()->NodeRef() == *node) {
51 if (resultingIndex != NULL)
52 *resultingIndex = index;
54 return pose;
58 return NULL;
62 BPose*
63 PoseList::FindPose(const entry_ref* entry, int32* resultingIndex) const
65 int32 count = CountItems();
66 for (int32 index = 0; index < count; index++) {
67 BPose* pose = ItemAt(index);
68 ASSERT(pose->TargetModel());
69 if (*pose->TargetModel()->EntryRef() == *entry) {
70 if (resultingIndex != NULL)
71 *resultingIndex = index;
73 return pose;
76 return NULL;
80 BPose*
81 PoseList::FindPose(const Model* model, int32* resultingIndex) const
83 return FindPose(model->NodeRef(), resultingIndex);
87 BPose*
88 PoseList::DeepFindPose(const node_ref* node, int32* resultingIndex) const
90 int32 count = CountItems();
91 for (int32 index = 0; index < count; index++) {
92 BPose* pose = ItemAt(index);
93 Model* model = pose->TargetModel();
94 if (*model->NodeRef() == *node) {
95 if (resultingIndex != NULL)
96 *resultingIndex = index;
98 return pose;
100 // if model is a symlink, try matching node with the target
101 // of the link
102 if (model->IsSymLink()) {
103 model = model->LinkTo();
104 if (model != NULL && *model->NodeRef() == *node) {
105 if (resultingIndex != NULL)
106 *resultingIndex = index;
108 return pose;
113 return NULL;
117 PoseList*
118 PoseList::FindAllPoses(const node_ref* node) const
120 int32 count = CountItems();
121 PoseList *result = new PoseList(5, false);
122 for (int32 index = 0; index < count; index++) {
123 BPose *pose = ItemAt(index);
124 Model *model = pose->TargetModel();
125 if (*model->NodeRef() == *node) {
126 result->AddItem(pose, 0);
127 continue;
130 if (!model->IsSymLink())
131 continue;
133 model = model->LinkTo();
134 if (model != NULL && *model->NodeRef() == *node) {
135 result->AddItem(pose);
136 continue;
139 if (model == NULL) {
140 Model model(pose->TargetModel()->EntryRef(), true);
141 if (*model.NodeRef() == *node)
142 result->AddItem(pose);
146 return result;
150 BPose*
151 PoseList::FindPoseByFileName(const char* name, int32* _index) const
153 int32 count = CountItems();
154 for (int32 index = 0; index < count; index++) {
155 BPose* pose = ItemAt(index);
156 ASSERT(pose->TargetModel());
157 if (strcmp(pose->TargetModel()->EntryRef()->name, name) == 0) {
158 if (_index != NULL)
159 *_index = index;
161 return pose;
165 return NULL;