xref: /aoo41x/main/soltools/inc/gi_list.hxx (revision 38268e38)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SOLTOOLS_GI_LIST_HXX
25 #define SOLTOOLS_GI_LIST_HXX
26 
27 
28 #include "st_list.hxx"
29 
30 
31 class GenericInfo;
32 
33 /** Holds set of generic informations in a sorted list.
34 
35     At different places, methods of this class have a parameter,
36     whose name includes "path". Those are paths like this:
37 
38         src370/drives/o:
39 
40     which are used to access GenericInfo keys in deep search through
41     the lists and their sublists.
42 */
43 class List_GenericInfo
44 {
45   public:
46     // TYPES
47     class const_iterator
48     {
49       public:
50         const GenericInfo & operator*() const;
51         const_iterator &    operator++();
52         bool                operator==( const const_iterator & ) const;
53         bool                operator!=( const const_iterator & ) const;
54 
55                             const_iterator();
56                             const_iterator( const DynamicList< GenericInfo >::const_iterator & );
57       private: DynamicList< GenericInfo >::const_iterator it;
58     };
59     class iterator
60     { public:
61         GenericInfo &       operator*() const;
62         iterator &          operator++();
63         bool                operator==( const iterator & ) const;
64         bool                operator!=( const iterator & ) const;
65 
66                             iterator();
67                             iterator( const DynamicList< GenericInfo >::iterator & );
68       private: DynamicList< GenericInfo >::iterator it;
69     };
70 
71     typedef const char *    KeyPath;
72 
73     // LIFECYCLE
74 	                    List_GenericInfo();
75 	                    List_GenericInfo(
76                             const List_GenericInfo &
77                                                 i_rList );
78 	                    ~List_GenericInfo();
79 
80     // OPERATORS
81 	List_GenericInfo &  operator=(
82                             const List_GenericInfo &
83                                                 i_rList );
84 	const GenericInfo * operator[](
85                             KeyPath             i_sKeyPath ) const;
86 	GenericInfo *       operator[](
87                             KeyPath             i_sKeyPath );
88 
89     // OPERATIONS
90 	bool                InsertInfo(
91                             GenericInfo *       let_dpInfo,    /// Will be owned by this object.
92                             bool                i_bOverwrite = true );
93 	bool                InsertInfoByPath(
94                             GenericInfo *       let_dpInfo,    /// Will be owned by this object.
95                             KeyPath             i_sKeyPath,
96                             bool                i_bCreatePath,
97                             bool                i_bOverwrite = true );
98 
99 	GenericInfo *       ReleaseInfo(            /// Removes the GenericInfo from its parent.
100                             KeyPath             i_sKeyPath );
101 
102 	void                DeleteInfo(
103                             KeyPath             i_sKeyPath );
104 
105     // INFO
106     unsigned            Size() const;
107 
108     const_iterator      Begin() const;
109     const_iterator      End() const;
110 
111     // ACCESS
112     iterator            Begin();
113     iterator            End();
114 
115   private:
116     typedef DynamicList< GenericInfo >::iterator  sub_iterator;
117 
118     sub_iterator        lower_bound(
119                             bool &              o_bExists,
120                             const char * &      o_sNextPathSegment,
121                             KeyPath             i_sKeyPath );
122 
123     DynamicList< GenericInfo >
124                         aChildren;
125 };
126 
127 
128 // IMPLEMENTATION
129 
130 
131 inline const GenericInfo &
132 List_GenericInfo::
operator *() const133 const_iterator::operator*() const
134     { return *(*it); }
135 
136 inline List_GenericInfo::const_iterator &
137 List_GenericInfo::
operator ++()138 const_iterator::operator++()
139     { ++it; return *this; }
140 
141 inline bool
142 List_GenericInfo::
operator ==(const const_iterator & i_rIter) const143 const_iterator::operator==( const const_iterator & i_rIter ) const
144     { return it == i_rIter.it; }
145 
146 inline bool
147 List_GenericInfo::
operator !=(const const_iterator & i_rIter) const148 const_iterator::operator!=( const const_iterator & i_rIter ) const
149     { return it != i_rIter.it; }
150 
151 inline List_GenericInfo::
const_iterator()152 const_iterator::const_iterator()
153     :   it(0) { }
154 
155 inline List_GenericInfo::
const_iterator(const DynamicList<GenericInfo>::const_iterator & i_rDynListIter)156 const_iterator::const_iterator( const DynamicList< GenericInfo >::const_iterator & i_rDynListIter )
157     :   it(i_rDynListIter) { }
158 
159 
160 inline GenericInfo &
161 List_GenericInfo::
operator *() const162 iterator::operator*() const
163     { return *(*it); }
164 
165 inline List_GenericInfo::iterator &
166 List_GenericInfo::
operator ++()167 iterator::operator++()
168     { ++it; return *this; }
169 
170 inline bool
171 List_GenericInfo::
operator ==(const iterator & i_rIter) const172 iterator::operator==( const iterator & i_rIter ) const
173     { return it == i_rIter.it; }
174 
175 inline bool
176 List_GenericInfo::
operator !=(const iterator & i_rIter) const177 iterator::operator!=( const iterator & i_rIter ) const
178     { return it != i_rIter.it; }
179 
180 inline List_GenericInfo::
iterator()181 iterator::iterator()
182     :   it(0) { }
183 
184 inline List_GenericInfo::
iterator(const DynamicList<GenericInfo>::iterator & i_rDynListIter)185 iterator::iterator( const DynamicList< GenericInfo >::iterator & i_rDynListIter )
186     :   it(i_rDynListIter) { }
187 
188 inline unsigned
Size() const189 List_GenericInfo::Size() const
190     { return aChildren.size(); }
191 
192 inline List_GenericInfo::const_iterator
Begin() const193 List_GenericInfo::Begin() const
194     { return aChildren.begin(); }
195 
196 inline List_GenericInfo::const_iterator
End() const197 List_GenericInfo::End() const
198     { return aChildren.end(); }
199 
200 inline List_GenericInfo::iterator
Begin()201 List_GenericInfo::Begin()
202     { return aChildren.begin(); }
203 
204 inline List_GenericInfo::iterator
End()205 List_GenericInfo::End()
206     { return aChildren.end(); }
207 
208 
209 
210 #endif
211 
212