1 //------------------------------------------------------------------------------
2 // Copyright (c) 2001-2002, OpenBeOS
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
22 // File Name: AppInfoList.h
23 // Author: Ingo Weinhold (bonefish@users.sf.net)
24 // Description: A helper class for TRoster. A list of RosterAppInfos.
25 //------------------------------------------------------------------------------
27 #ifndef APP_INFO_LIST_H
28 #define APP_INFO_LIST_H
44 virtual ~AppInfoList();
46 bool AddInfo(RosterAppInfo
*info
);
47 bool RemoveInfo(RosterAppInfo
*info
);
48 void MakeEmpty(bool deleteInfos
= false);
50 RosterAppInfo
*InfoFor(const char *signature
) const;
51 RosterAppInfo
*InfoFor(team_id team
) const;
52 RosterAppInfo
*InfoFor(const entry_ref
*ref
) const;
53 RosterAppInfo
*InfoForToken(uint32 token
) const;
55 bool IsEmpty() const { return (CountInfos() == 0); };
56 int32
CountInfos() const;
60 void Sort(bool (*lessFunc
)(const RosterAppInfo
*, const RosterAppInfo
*));
63 RosterAppInfo
*RemoveInfo(int32 index
);
65 RosterAppInfo
*InfoAt(int32 index
) const;
67 int32
IndexOf(RosterAppInfo
*info
) const;
68 int32
IndexOf(const char *signature
) const;
69 int32
IndexOf(team_id team
) const;
70 int32
IndexOf(const entry_ref
*ref
) const;
71 int32
IndexOfToken(uint32 token
) const;
74 friend class Iterator
;
80 // AppInfoList::Iterator
81 class AppInfoList::Iterator
{
83 inline Iterator(const Iterator
&it
)
92 inline bool IsValid() const
94 return (fIndex
>= 0 && fIndex
< fCount
);
97 inline RosterAppInfo
*Remove()
99 RosterAppInfo
*info
= fList
->RemoveInfo(fIndex
);
105 inline Iterator
&operator=(const Iterator
&it
)
113 inline Iterator
&operator++()
119 inline Iterator
operator++(int)
121 return Iterator(fList
, fIndex
+ 1);
124 inline Iterator
&operator--()
130 inline Iterator
operator--(int)
132 return Iterator(fList
, fIndex
- 1);
135 inline bool operator==(const Iterator
&it
) const
137 return (fList
== it
.fList
&& fIndex
== it
.fIndex
);
140 inline bool operator!=(const Iterator
&it
) const
142 return !(*this == it
);
145 inline RosterAppInfo
*operator*() const
147 return fList
->InfoAt(fIndex
);
151 friend class AppInfoList
;
154 inline Iterator(AppInfoList
*list
, int32 index
= 0)
157 fCount(list
->CountInfos())
167 #endif // APP_INFO_LIST_H