xref: /aoo42x/main/soltools/inc/gi_list.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SOLTOOLS_GI_LIST_HXX
29 #define SOLTOOLS_GI_LIST_HXX
30 
31 
32 #include "st_list.hxx"
33 
34 
35 class GenericInfo;
36 
37 /** Holds set of generic informations in a sorted list.
38 
39     At different places, methods of this class have a parameter,
40     whose name includes "path". Those are paths like this:
41 
42         src370/drives/o:
43 
44     which are used to access GenericInfo keys in deep search through
45     the lists and their sublists.
46 */
47 class List_GenericInfo
48 {
49   public:
50     // TYPES
51     class const_iterator
52     {
53       public:
54         const GenericInfo & operator*() const;
55         const_iterator &    operator++();
56         bool                operator==( const const_iterator & ) const;
57         bool                operator!=( const const_iterator & ) const;
58 
59                             const_iterator();
60                             const_iterator( const DynamicList< GenericInfo >::const_iterator & );
61       private: DynamicList< GenericInfo >::const_iterator it;
62     };
63     class iterator
64     { public:
65         GenericInfo &       operator*() const;
66         iterator &          operator++();
67         bool                operator==( const iterator & ) const;
68         bool                operator!=( const iterator & ) const;
69 
70                             iterator();
71                             iterator( const DynamicList< GenericInfo >::iterator & );
72       private: DynamicList< GenericInfo >::iterator it;
73     };
74 
75     typedef const char *    KeyPath;
76 
77     // LIFECYCLE
78 	                    List_GenericInfo();
79 	                    List_GenericInfo(
80                             const List_GenericInfo &
81                                                 i_rList );
82 	                    ~List_GenericInfo();
83 
84     // OPERATORS
85 	List_GenericInfo &  operator=(
86                             const List_GenericInfo &
87                                                 i_rList );
88 	const GenericInfo * operator[](
89                             KeyPath             i_sKeyPath ) const;
90 	GenericInfo *       operator[](
91                             KeyPath             i_sKeyPath );
92 
93     // OPERATIONS
94 	bool                InsertInfo(
95                             GenericInfo *       let_dpInfo,    /// Will be owned by this object.
96                             bool                i_bOverwrite = true );
97 	bool                InsertInfoByPath(
98                             GenericInfo *       let_dpInfo,    /// Will be owned by this object.
99                             KeyPath             i_sKeyPath,
100                             bool                i_bCreatePath,
101                             bool                i_bOverwrite = true );
102 
103 	GenericInfo *       ReleaseInfo(            /// Removes the GenericInfo from its parent.
104                             KeyPath             i_sKeyPath );
105 
106 	void                DeleteInfo(
107                             KeyPath             i_sKeyPath );
108 
109     // INFO
110     unsigned            Size() const;
111 
112     const_iterator      Begin() const;
113     const_iterator      End() const;
114 
115     // ACCESS
116     iterator            Begin();
117     iterator            End();
118 
119   private:
120     typedef DynamicList< GenericInfo >::iterator  sub_iterator;
121 
122     sub_iterator        lower_bound(
123                             bool &              o_bExists,
124                             const char * &      o_sNextPathSegment,
125                             KeyPath             i_sKeyPath );
126 
127     DynamicList< GenericInfo >
128                         aChildren;
129 };
130 
131 
132 // IMPLEMENTATION
133 
134 
135 inline const GenericInfo &
136 List_GenericInfo::
137 const_iterator::operator*() const
138     { return *(*it); }
139 
140 inline List_GenericInfo::const_iterator &
141 List_GenericInfo::
142 const_iterator::operator++()
143     { ++it; return *this; }
144 
145 inline bool
146 List_GenericInfo::
147 const_iterator::operator==( const const_iterator & i_rIter ) const
148     { return it == i_rIter.it; }
149 
150 inline bool
151 List_GenericInfo::
152 const_iterator::operator!=( const const_iterator & i_rIter ) const
153     { return it != i_rIter.it; }
154 
155 inline List_GenericInfo::
156 const_iterator::const_iterator()
157     :   it(0) { }
158 
159 inline List_GenericInfo::
160 const_iterator::const_iterator( const DynamicList< GenericInfo >::const_iterator & i_rDynListIter )
161     :   it(i_rDynListIter) { }
162 
163 
164 inline GenericInfo &
165 List_GenericInfo::
166 iterator::operator*() const
167     { return *(*it); }
168 
169 inline List_GenericInfo::iterator &
170 List_GenericInfo::
171 iterator::operator++()
172     { ++it; return *this; }
173 
174 inline bool
175 List_GenericInfo::
176 iterator::operator==( const iterator & i_rIter ) const
177     { return it == i_rIter.it; }
178 
179 inline bool
180 List_GenericInfo::
181 iterator::operator!=( const iterator & i_rIter ) const
182     { return it != i_rIter.it; }
183 
184 inline List_GenericInfo::
185 iterator::iterator()
186     :   it(0) { }
187 
188 inline List_GenericInfo::
189 iterator::iterator( const DynamicList< GenericInfo >::iterator & i_rDynListIter )
190     :   it(i_rDynListIter) { }
191 
192 inline unsigned
193 List_GenericInfo::Size() const
194     { return aChildren.size(); }
195 
196 inline List_GenericInfo::const_iterator
197 List_GenericInfo::Begin() const
198     { return aChildren.begin(); }
199 
200 inline List_GenericInfo::const_iterator
201 List_GenericInfo::End() const
202     { return aChildren.end(); }
203 
204 inline List_GenericInfo::iterator
205 List_GenericInfo::Begin()
206     { return aChildren.begin(); }
207 
208 inline List_GenericInfo::iterator
209 List_GenericInfo::End()
210     { return aChildren.end(); }
211 
212 
213 
214 #endif
215 
216