1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10*dde7d3faSAndrew Rist * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*dde7d3faSAndrew Rist * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19*dde7d3faSAndrew Rist * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //_______________________________________________ 28cdf0e10cSrcweir // includes 29cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir //_______________________________________________ 32cdf0e10cSrcweir // namespace 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace comphelper{ 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace css = ::com::sun::star; 37cdf0e10cSrcweir 38cdf0e10cSrcweir //_______________________________________________ 39cdf0e10cSrcweir // definitions 40cdf0e10cSrcweir 41cdf0e10cSrcweir /*----------------------------------------------- 42cdf0e10cSrcweir 04.11.2003 09:29 43cdf0e10cSrcweir -----------------------------------------------*/ 44cdf0e10cSrcweir SequenceAsHashMap::SequenceAsHashMap() 45cdf0e10cSrcweir : SequenceAsHashMapBase() 46cdf0e10cSrcweir { 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir /*----------------------------------------------- 50cdf0e10cSrcweir 04.11.2003 08:30 51cdf0e10cSrcweir -----------------------------------------------*/ 52cdf0e10cSrcweir SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir (*this) << aSource; 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir //----------------------------------------------- 58cdf0e10cSrcweir SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir (*this) << lSource; 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir /*----------------------------------------------- 64cdf0e10cSrcweir 04.11.2003 08:30 65cdf0e10cSrcweir -----------------------------------------------*/ 66cdf0e10cSrcweir SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir (*this) << lSource; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir /*----------------------------------------------- 72cdf0e10cSrcweir 04.11.2003 08:30 73cdf0e10cSrcweir -----------------------------------------------*/ 74cdf0e10cSrcweir SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir (*this) << lSource; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir /*----------------------------------------------- 80cdf0e10cSrcweir 04.11.2003 09:04 81cdf0e10cSrcweir -----------------------------------------------*/ 82cdf0e10cSrcweir SequenceAsHashMap::~SequenceAsHashMap() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir /*----------------------------------------------- 87cdf0e10cSrcweir 04.11.2003 10:21 88cdf0e10cSrcweir -----------------------------------------------*/ 89cdf0e10cSrcweir void SequenceAsHashMap::operator<<(const css::uno::Any& aSource) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir // An empty Any reset this instance! 92cdf0e10cSrcweir if (!aSource.hasValue()) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir clear(); 95cdf0e10cSrcweir return; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > lN; 99cdf0e10cSrcweir if (aSource >>= lN) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir (*this) << lN; 102cdf0e10cSrcweir return; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lP; 106cdf0e10cSrcweir if (aSource >>= lP) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir (*this) << lP; 109cdf0e10cSrcweir return; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir throw css::beans::IllegalTypeException( 113cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Any contains wrong type."), 114cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir //----------------------------------------------- 118cdf0e10cSrcweir void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir sal_Int32 c = lSource.getLength(); 121cdf0e10cSrcweir sal_Int32 i = 0; 122cdf0e10cSrcweir 123cdf0e10cSrcweir for (i=0; i<c; ++i) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir css::beans::PropertyValue lP; 126cdf0e10cSrcweir if (lSource[i] >>= lP) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir if ( 129cdf0e10cSrcweir (!lP.Name.getLength()) || 130cdf0e10cSrcweir (!lP.Value.hasValue()) 131cdf0e10cSrcweir ) 132cdf0e10cSrcweir throw css::beans::IllegalTypeException( 133cdf0e10cSrcweir ::rtl::OUString::createFromAscii("PropertyValue struct contains no usefull informations."), 134cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); 135cdf0e10cSrcweir (*this)[lP.Name] = lP.Value; 136cdf0e10cSrcweir continue; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir css::beans::NamedValue lN; 140cdf0e10cSrcweir if (lSource[i] >>= lN) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir if ( 143cdf0e10cSrcweir (!lN.Name.getLength()) || 144cdf0e10cSrcweir (!lN.Value.hasValue()) 145cdf0e10cSrcweir ) 146cdf0e10cSrcweir throw css::beans::IllegalTypeException( 147cdf0e10cSrcweir ::rtl::OUString::createFromAscii("NamedValue struct contains no usefull informations."), 148cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); 149cdf0e10cSrcweir (*this)[lN.Name] = lN.Value; 150cdf0e10cSrcweir continue; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir // ignore VOID Any ... but reject wrong filled ones! 154cdf0e10cSrcweir if (lSource[i].hasValue()) 155cdf0e10cSrcweir throw css::beans::IllegalTypeException( 156cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Any contains wrong type."), 157cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir /*----------------------------------------------- 162cdf0e10cSrcweir 04.11.2003 08:30 163cdf0e10cSrcweir -----------------------------------------------*/ 164cdf0e10cSrcweir void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir clear(); 167cdf0e10cSrcweir 168cdf0e10cSrcweir sal_Int32 c = lSource.getLength(); 169cdf0e10cSrcweir const css::beans::PropertyValue* pSource = lSource.getConstArray(); 170cdf0e10cSrcweir 171cdf0e10cSrcweir for (sal_Int32 i=0; i<c; ++i) 172cdf0e10cSrcweir (*this)[pSource[i].Name] = pSource[i].Value; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir /*----------------------------------------------- 176cdf0e10cSrcweir 04.11.2003 08:30 177cdf0e10cSrcweir -----------------------------------------------*/ 178cdf0e10cSrcweir void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir clear(); 181cdf0e10cSrcweir 182cdf0e10cSrcweir sal_Int32 c = lSource.getLength(); 183cdf0e10cSrcweir const css::beans::NamedValue* pSource = lSource.getConstArray(); 184cdf0e10cSrcweir 185cdf0e10cSrcweir for (sal_Int32 i=0; i<c; ++i) 186cdf0e10cSrcweir (*this)[pSource[i].Name] = pSource[i].Value; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir /*----------------------------------------------- 190cdf0e10cSrcweir 04.11.2003 08:30 191cdf0e10cSrcweir -----------------------------------------------*/ 192cdf0e10cSrcweir void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const 193cdf0e10cSrcweir { 194cdf0e10cSrcweir sal_Int32 c = (sal_Int32)size(); 195cdf0e10cSrcweir lDestination.realloc(c); 196cdf0e10cSrcweir css::beans::PropertyValue* pDestination = lDestination.getArray(); 197cdf0e10cSrcweir 198cdf0e10cSrcweir sal_Int32 i = 0; 199cdf0e10cSrcweir for (const_iterator pThis = begin(); 200cdf0e10cSrcweir pThis != end() ; 201cdf0e10cSrcweir ++pThis ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir pDestination[i].Name = pThis->first ; 204cdf0e10cSrcweir pDestination[i].Value = pThis->second; 205cdf0e10cSrcweir ++i; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir /*----------------------------------------------- 210cdf0e10cSrcweir 04.11.2003 08:30 211cdf0e10cSrcweir -----------------------------------------------*/ 212cdf0e10cSrcweir void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const 213cdf0e10cSrcweir { 214cdf0e10cSrcweir sal_Int32 c = (sal_Int32)size(); 215cdf0e10cSrcweir lDestination.realloc(c); 216cdf0e10cSrcweir css::beans::NamedValue* pDestination = lDestination.getArray(); 217cdf0e10cSrcweir 218cdf0e10cSrcweir sal_Int32 i = 0; 219cdf0e10cSrcweir for (const_iterator pThis = begin(); 220cdf0e10cSrcweir pThis != end() ; 221cdf0e10cSrcweir ++pThis ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir pDestination[i].Name = pThis->first ; 224cdf0e10cSrcweir pDestination[i].Value = pThis->second; 225cdf0e10cSrcweir ++i; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir /*----------------------------------------------- 230cdf0e10cSrcweir 30.07.2007 14:10 231cdf0e10cSrcweir -----------------------------------------------*/ 232cdf0e10cSrcweir const css::uno::Any SequenceAsHashMap::getAsConstAny(::sal_Bool bAsPropertyValueList) const 233cdf0e10cSrcweir { 234cdf0e10cSrcweir css::uno::Any aDestination; 235cdf0e10cSrcweir if (bAsPropertyValueList) 236cdf0e10cSrcweir aDestination = css::uno::makeAny(getAsConstPropertyValueList()); 237cdf0e10cSrcweir else 238cdf0e10cSrcweir aDestination = css::uno::makeAny(getAsConstNamedValueList()); 239cdf0e10cSrcweir return aDestination; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir /*----------------------------------------------- 243cdf0e10cSrcweir 30.07.2007 14:10 244cdf0e10cSrcweir -----------------------------------------------*/ 245cdf0e10cSrcweir const css::uno::Sequence< css::uno::Any > SequenceAsHashMap::getAsConstAnyList(::sal_Bool bAsPropertyValueList) const 246cdf0e10cSrcweir { 247cdf0e10cSrcweir ::sal_Int32 i = 0; 248cdf0e10cSrcweir ::sal_Int32 c = (::sal_Int32)size(); 249cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lDestination(c); 250cdf0e10cSrcweir css::uno::Any* pDestination = lDestination.getArray(); 251cdf0e10cSrcweir 252cdf0e10cSrcweir for (const_iterator pThis = begin(); 253cdf0e10cSrcweir pThis != end() ; 254cdf0e10cSrcweir ++pThis ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir if (bAsPropertyValueList) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir css::beans::PropertyValue aProp; 259cdf0e10cSrcweir aProp.Name = pThis->first; 260cdf0e10cSrcweir aProp.Value = pThis->second; 261cdf0e10cSrcweir pDestination[i] = css::uno::makeAny(aProp); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir else 264cdf0e10cSrcweir { 265cdf0e10cSrcweir css::beans::NamedValue aProp; 266cdf0e10cSrcweir aProp.Name = pThis->first; 267cdf0e10cSrcweir aProp.Value = pThis->second; 268cdf0e10cSrcweir pDestination[i] = css::uno::makeAny(aProp); 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir ++i; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir return lDestination; 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir /*----------------------------------------------- 278cdf0e10cSrcweir 04.11.2003 08:30 279cdf0e10cSrcweir -----------------------------------------------*/ 280cdf0e10cSrcweir const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const 281cdf0e10cSrcweir { 282cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > lReturn; 283cdf0e10cSrcweir (*this) >> lReturn; 284cdf0e10cSrcweir return lReturn; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir /*----------------------------------------------- 288cdf0e10cSrcweir 04.11.2003 08:30 289cdf0e10cSrcweir -----------------------------------------------*/ 290cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const 291cdf0e10cSrcweir { 292cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lReturn; 293cdf0e10cSrcweir (*this) >> lReturn; 294cdf0e10cSrcweir return lReturn; 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir /*----------------------------------------------- 298cdf0e10cSrcweir 07.03.2007 12:45 299cdf0e10cSrcweir -----------------------------------------------*/ 300cdf0e10cSrcweir sal_Bool SequenceAsHashMap::match(const SequenceAsHashMap& rCheck) const 301cdf0e10cSrcweir { 302cdf0e10cSrcweir const_iterator pCheck; 303cdf0e10cSrcweir for ( pCheck = rCheck.begin(); 304cdf0e10cSrcweir pCheck != rCheck.end() ; 305cdf0e10cSrcweir ++pCheck ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir const ::rtl::OUString& sCheckName = pCheck->first; 308cdf0e10cSrcweir const css::uno::Any& aCheckValue = pCheck->second; 309cdf0e10cSrcweir const_iterator pFound = find(sCheckName); 310cdf0e10cSrcweir 311cdf0e10cSrcweir if (pFound == end()) 312cdf0e10cSrcweir return sal_False; 313cdf0e10cSrcweir 314cdf0e10cSrcweir const css::uno::Any& aFoundValue = pFound->second; 315cdf0e10cSrcweir if (aFoundValue != aCheckValue) 316cdf0e10cSrcweir return sal_False; 317cdf0e10cSrcweir } 318cdf0e10cSrcweir 319cdf0e10cSrcweir return sal_True; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir /*----------------------------------------------- 323cdf0e10cSrcweir 30.07.2007 14:30 324cdf0e10cSrcweir -----------------------------------------------*/ 325cdf0e10cSrcweir void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir const_iterator pUpdate; 328cdf0e10cSrcweir for ( pUpdate = rUpdate.begin(); 329cdf0e10cSrcweir pUpdate != rUpdate.end() ; 330cdf0e10cSrcweir ++pUpdate ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir const ::rtl::OUString& sName = pUpdate->first; 333cdf0e10cSrcweir const css::uno::Any& aValue = pUpdate->second; 334cdf0e10cSrcweir 335cdf0e10cSrcweir (*this)[sName] = aValue; 336cdf0e10cSrcweir } 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir /*----------------------------------------------- 340cdf0e10cSrcweir 04.11.2003 08:30 341cdf0e10cSrcweir -----------------------------------------------*/ 342cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 343cdf0e10cSrcweir void SequenceAsHashMap::dbg_dumpToFile(const char* pFileName, 344cdf0e10cSrcweir const char* pComment ) const 345cdf0e10cSrcweir { 346cdf0e10cSrcweir if (!pFileName || !pComment) 347cdf0e10cSrcweir return; 348cdf0e10cSrcweir 349cdf0e10cSrcweir FILE* pFile = fopen(pFileName, "a"); 350cdf0e10cSrcweir if (!pFile) 351cdf0e10cSrcweir return; 352cdf0e10cSrcweir 353cdf0e10cSrcweir ::rtl::OUStringBuffer sBuffer(1000); 354cdf0e10cSrcweir sBuffer.appendAscii("\n----------------------------------------\n"); 355cdf0e10cSrcweir sBuffer.appendAscii(pComment ); 356cdf0e10cSrcweir sBuffer.appendAscii("\n----------------------------------------\n"); 357cdf0e10cSrcweir sal_Int32 i = 0; 358cdf0e10cSrcweir for (const_iterator pIt = begin(); 359cdf0e10cSrcweir pIt != end() ; 360cdf0e10cSrcweir ++pIt ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir sBuffer.appendAscii("[" ); 363cdf0e10cSrcweir sBuffer.append (i++ ); 364cdf0e10cSrcweir sBuffer.appendAscii("] " ); 365cdf0e10cSrcweir sBuffer.appendAscii("\"" ); 366cdf0e10cSrcweir sBuffer.append (pIt->first); 367cdf0e10cSrcweir sBuffer.appendAscii("\" = \"" ); 368cdf0e10cSrcweir 369cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xv; 370cdf0e10cSrcweir ::rtl::OUString sv; 371cdf0e10cSrcweir sal_Int32 nv; 372cdf0e10cSrcweir sal_Bool bv; 373cdf0e10cSrcweir 374cdf0e10cSrcweir if (pIt->second >>= sv) 375cdf0e10cSrcweir sBuffer.append(sv); 376cdf0e10cSrcweir else 377cdf0e10cSrcweir if (pIt->second >>= nv) 378cdf0e10cSrcweir sBuffer.append(nv); 379cdf0e10cSrcweir else 380cdf0e10cSrcweir if (pIt->second >>= bv) 381cdf0e10cSrcweir sBuffer.appendAscii(bv ? "true" : "false"); 382cdf0e10cSrcweir else 383cdf0e10cSrcweir if (pIt->second >>= xv) 384cdf0e10cSrcweir sBuffer.appendAscii(xv.is() ? "object" : "null"); 385cdf0e10cSrcweir else 386cdf0e10cSrcweir sBuffer.appendAscii("???"); 387cdf0e10cSrcweir 388cdf0e10cSrcweir sBuffer.appendAscii("\"\n"); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir fprintf(pFile, ::rtl::OUStringToOString(sBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr()); 392cdf0e10cSrcweir fclose(pFile); 393cdf0e10cSrcweir } 394cdf0e10cSrcweir #endif // OSL_DEBUG_LEVEL > 1 395cdf0e10cSrcweir 396cdf0e10cSrcweir } // namespace comphelper 397