1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_soltools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <gi_list.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <gen_info.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir const char C_cKeySeparator = '/'; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir List_GenericInfo::List_GenericInfo() 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir } 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir List_GenericInfo::List_GenericInfo( const List_GenericInfo & i_rList ) 47*cdf0e10cSrcweir : aChildren(i_rList.aChildren) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir List_GenericInfo::~List_GenericInfo() 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir List_GenericInfo & 56*cdf0e10cSrcweir List_GenericInfo::operator=( const List_GenericInfo & i_rList ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir aChildren = i_rList.aChildren; 59*cdf0e10cSrcweir return *this; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir const GenericInfo * 63*cdf0e10cSrcweir List_GenericInfo::operator[]( KeyPath i_sKeyPath ) const 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir return const_cast< List_GenericInfo& >(*this)[i_sKeyPath]; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir GenericInfo * 69*cdf0e10cSrcweir List_GenericInfo::operator[]( KeyPath i_sKeyPath ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir bool bExists = false; 72*cdf0e10cSrcweir const char * sNextPathSegment = 0; 73*cdf0e10cSrcweir sub_iterator it = lower_bound(bExists, sNextPathSegment, i_sKeyPath); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir if ( bExists ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir if ( sNextPathSegment == 0 ) 78*cdf0e10cSrcweir return (*it); 79*cdf0e10cSrcweir else 80*cdf0e10cSrcweir return (*it)->SubList()[sNextPathSegment]; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir else 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir return 0; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir bool 89*cdf0e10cSrcweir List_GenericInfo::InsertInfo( GenericInfo * let_dpInfo, 90*cdf0e10cSrcweir bool i_bOverwrite ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir if ( let_dpInfo == 0 ) 93*cdf0e10cSrcweir return false; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir bool bExists = false; 96*cdf0e10cSrcweir const char * sNextPathSegment = 0; 97*cdf0e10cSrcweir sub_iterator it = lower_bound(bExists, sNextPathSegment, let_dpInfo->Key() ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir if ( ! bExists ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir aChildren.insert( it, let_dpInfo ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir else if ( i_bOverwrite ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir delete (*it); 106*cdf0e10cSrcweir (*it) = let_dpInfo; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir else 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir delete let_dpInfo; 111*cdf0e10cSrcweir return false; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir return true; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir bool 118*cdf0e10cSrcweir List_GenericInfo::InsertInfoByPath( GenericInfo * let_dpInfo, 119*cdf0e10cSrcweir KeyPath i_sKeyPath, 120*cdf0e10cSrcweir bool i_bCreatePath, 121*cdf0e10cSrcweir bool i_bOverwrite ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir if ( let_dpInfo == 0 ) 124*cdf0e10cSrcweir return false; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir if ( i_sKeyPath == 0 ? true : *i_sKeyPath == 0 ) 127*cdf0e10cSrcweir return InsertInfo(let_dpInfo, i_bOverwrite); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir bool bExists = false; 130*cdf0e10cSrcweir const char * sNextPathSegment = 0; 131*cdf0e10cSrcweir sub_iterator it = lower_bound(bExists, sNextPathSegment, i_sKeyPath); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if ( bExists ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir return (*it)->SubList().InsertInfoByPath( 136*cdf0e10cSrcweir let_dpInfo, 137*cdf0e10cSrcweir sNextPathSegment, 138*cdf0e10cSrcweir i_bCreatePath, 139*cdf0e10cSrcweir i_bOverwrite ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir else if ( i_bCreatePath ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir Simstr aKey( i_sKeyPath, 144*cdf0e10cSrcweir 0, 145*cdf0e10cSrcweir sNextPathSegment - 146*cdf0e10cSrcweir ( *sNextPathSegment == 0 ? 0 : 1) 147*cdf0e10cSrcweir - i_sKeyPath ); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir GenericInfo * pNew = new GenericInfo(aKey); 150*cdf0e10cSrcweir InsertInfo(pNew,false); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir return pNew->SubList().InsertInfoByPath( 153*cdf0e10cSrcweir let_dpInfo, 154*cdf0e10cSrcweir sNextPathSegment, 155*cdf0e10cSrcweir i_bCreatePath, 156*cdf0e10cSrcweir i_bOverwrite ); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir else 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir delete let_dpInfo; 161*cdf0e10cSrcweir return false; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir GenericInfo * 166*cdf0e10cSrcweir List_GenericInfo::ReleaseInfo( KeyPath i_sKeyPath ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir bool bExists = false; 169*cdf0e10cSrcweir const char * sNextPathSegment = 0; 170*cdf0e10cSrcweir sub_iterator it = lower_bound(bExists, sNextPathSegment, i_sKeyPath ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir if ( bExists ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir if ( *sNextPathSegment == 0 ) 175*cdf0e10cSrcweir return (*it); 176*cdf0e10cSrcweir else 177*cdf0e10cSrcweir return (*it)->SubList().ReleaseInfo(sNextPathSegment); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir else 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir return 0; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void 186*cdf0e10cSrcweir List_GenericInfo::DeleteInfo( KeyPath i_sKeyPath ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir bool bExists = false; 189*cdf0e10cSrcweir const char * sNextPathSegment = 0; 190*cdf0e10cSrcweir sub_iterator it = lower_bound(bExists, sNextPathSegment, i_sKeyPath ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if ( bExists ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir if ( *sNextPathSegment == 0 ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir aChildren.remove(it); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir else 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir (*it)->SubList().DeleteInfo(sNextPathSegment); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir List_GenericInfo::sub_iterator 206*cdf0e10cSrcweir List_GenericInfo::lower_bound( bool & o_bExists, 207*cdf0e10cSrcweir const char * & o_sNextPathSegment, 208*cdf0e10cSrcweir KeyPath i_sKeyPath ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir o_sNextPathSegment = strchr(i_sKeyPath, '/'); 211*cdf0e10cSrcweir Simstr sKey( i_sKeyPath, (o_sNextPathSegment == 0 ? strlen(i_sKeyPath) : o_sNextPathSegment++ - i_sKeyPath) ); 212*cdf0e10cSrcweir GenericInfo aSearch(sKey); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir unsigned low = 0; 215*cdf0e10cSrcweir unsigned high = aChildren.size(); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir for ( unsigned cur = high / 2; high > low; cur = (low + high) / 2 ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir if ( *aChildren[cur] < aSearch ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir low = cur+1; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir else 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir high = cur; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } // end for 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir o_bExists = low < aChildren.size() 230*cdf0e10cSrcweir ? !(aSearch < *aChildren[low] ) 231*cdf0e10cSrcweir : false; 232*cdf0e10cSrcweir return &aChildren[low]; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235