1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include <gi_list.hxx>
34 #include <gen_info.hxx>
38 const char C_cKeySeparator
= '/';
41 List_GenericInfo::List_GenericInfo()
45 List_GenericInfo::List_GenericInfo( const List_GenericInfo
& i_rList
)
46 : aChildren(i_rList
.aChildren
)
50 List_GenericInfo::~List_GenericInfo()
55 List_GenericInfo::operator=( const List_GenericInfo
& i_rList
)
57 aChildren
= i_rList
.aChildren
;
62 List_GenericInfo::operator[]( KeyPath i_sKeyPath
) const
64 return const_cast< List_GenericInfo
& >(*this)[i_sKeyPath
];
68 List_GenericInfo::operator[]( KeyPath i_sKeyPath
)
71 const char * sNextPathSegment
= 0;
72 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
76 if ( sNextPathSegment
== 0 )
79 return (*it
)->SubList()[sNextPathSegment
];
88 List_GenericInfo::InsertInfo( GenericInfo
* let_dpInfo
,
91 if ( let_dpInfo
== 0 )
95 const char * sNextPathSegment
= 0;
96 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, let_dpInfo
->Key() );
100 aChildren
.insert( it
, let_dpInfo
);
102 else if ( i_bOverwrite
)
117 List_GenericInfo::InsertInfoByPath( GenericInfo
* let_dpInfo
,
122 if ( let_dpInfo
== 0 )
125 if ( i_sKeyPath
== 0 ? true : *i_sKeyPath
== 0 )
126 return InsertInfo(let_dpInfo
, i_bOverwrite
);
128 bool bExists
= false;
129 const char * sNextPathSegment
= 0;
130 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
134 return (*it
)->SubList().InsertInfoByPath(
140 else if ( i_bCreatePath
)
142 Simstr
aKey( i_sKeyPath
,
144 (int)(sNextPathSegment
-
145 ( *sNextPathSegment
== 0 ? 0 : 1)
148 GenericInfo
* pNew
= new GenericInfo(aKey
);
149 InsertInfo(pNew
,false);
151 return pNew
->SubList().InsertInfoByPath(
165 List_GenericInfo::ReleaseInfo( KeyPath i_sKeyPath
)
167 bool bExists
= false;
168 const char * sNextPathSegment
= 0;
169 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
173 if ( *sNextPathSegment
== 0 )
176 return (*it
)->SubList().ReleaseInfo(sNextPathSegment
);
185 List_GenericInfo::DeleteInfo( KeyPath i_sKeyPath
)
187 bool bExists
= false;
188 const char * sNextPathSegment
= 0;
189 sub_iterator it
= lower_bound(bExists
, sNextPathSegment
, i_sKeyPath
);
193 if ( *sNextPathSegment
== 0 )
195 aChildren
.remove(it
);
199 (*it
)->SubList().DeleteInfo(sNextPathSegment
);
204 List_GenericInfo::sub_iterator
205 List_GenericInfo::lower_bound( bool & o_bExists
,
206 const char * & o_sNextPathSegment
,
209 o_sNextPathSegment
= strchr(i_sKeyPath
, '/');
210 Simstr
sKey( i_sKeyPath
, (int)(o_sNextPathSegment
== 0 ? strlen(i_sKeyPath
) : o_sNextPathSegment
++ - i_sKeyPath
) );
211 GenericInfo
aSearch(sKey
);
214 unsigned high
= aChildren
.size();
216 for ( unsigned cur
= high
/ 2; high
> low
; cur
= (low
+ high
) / 2 )
218 if ( *aChildren
[cur
] < aSearch
)
228 o_bExists
= low
< aChildren
.size()
229 ? !(aSearch
< *aChildren
[low
] )
231 return &aChildren
[low
];
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */