1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gi_list.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_soltools.hxx"
35 #include <gi_list.hxx>
38 #include <gen_info.hxx>
42 const char C_cKeySeparator
= '/';
45 List_GenericInfo::List_GenericInfo()
49 List_GenericInfo::List_GenericInfo( const List_GenericInfo
& i_rList
)
50 : aChildren(i_rList
.aChildren
)
54 List_GenericInfo::~List_GenericInfo()
59 List_GenericInfo::operator=( const List_GenericInfo
& i_rList
)
61 aChildren
= i_rList
.aChildren
;
66 List_GenericInfo::operator[]( KeyPath i_sKeyPath
) const
68 return const_cast< List_GenericInfo
& >(*this)[i_sKeyPath
];
72 List_GenericInfo::operator[]( KeyPath i_sKeyPath
)
75 const char * sNextPathSegment
= 0;
76 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
80 if ( sNextPathSegment
== 0 )
83 return (*it
)->SubList()[sNextPathSegment
];
92 List_GenericInfo::InsertInfo( GenericInfo
* let_dpInfo
,
95 if ( let_dpInfo
== 0 )
99 const char * sNextPathSegment
= 0;
100 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, let_dpInfo
->Key() );
104 aChildren
.insert( it
, let_dpInfo
);
106 else if ( i_bOverwrite
)
121 List_GenericInfo::InsertInfoByPath( GenericInfo
* let_dpInfo
,
126 if ( let_dpInfo
== 0 )
129 if ( i_sKeyPath
== 0 ? true : *i_sKeyPath
== 0 )
130 return InsertInfo(let_dpInfo
, i_bOverwrite
);
132 bool bExists
= false;
133 const char * sNextPathSegment
= 0;
134 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
138 return (*it
)->SubList().InsertInfoByPath(
144 else if ( i_bCreatePath
)
146 Simstr
aKey( i_sKeyPath
,
149 ( *sNextPathSegment
== 0 ? 0 : 1)
152 GenericInfo
* pNew
= new GenericInfo(aKey
);
153 InsertInfo(pNew
,false);
155 return pNew
->SubList().InsertInfoByPath(
169 List_GenericInfo::ReleaseInfo( KeyPath i_sKeyPath
)
171 bool bExists
= false;
172 const char * sNextPathSegment
= 0;
173 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
177 if ( *sNextPathSegment
== 0 )
180 return (*it
)->SubList().ReleaseInfo(sNextPathSegment
);
189 List_GenericInfo::DeleteInfo( KeyPath i_sKeyPath
)
191 bool bExists
= false;
192 const char * sNextPathSegment
= 0;
193 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
197 if ( *sNextPathSegment
== 0 )
199 aChildren
.remove(it
);
203 (*it
)->SubList().DeleteInfo(sNextPathSegment
);
208 List_GenericInfo::sub_iterator
209 List_GenericInfo::lower_bound( bool & o_bExists
,
210 const char * & o_sNextPathSegment
,
213 o_sNextPathSegment
= strchr(i_sKeyPath
, '/');
214 Simstr
sKey( i_sKeyPath
, (o_sNextPathSegment
== 0 ? strlen(i_sKeyPath
) : o_sNextPathSegment
++ - i_sKeyPath
) );
215 GenericInfo
aSearch(sKey
);
218 unsigned high
= aChildren
.size();
220 for ( unsigned cur
= high
/ 2; high
> low
; cur
= (low
+ high
) / 2 )
222 if ( *aChildren
[cur
] < aSearch
)
232 o_bExists
= low
< aChildren
.size()
233 ? !(aSearch
< *aChildren
[low
] )
235 return &aChildren
[low
];