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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_rsc.hxx" 30 /****************** I N C L U D E S **************************************/ 31 32 // C and C++ Includes. 33 #include <stdlib.h> 34 #include <stdio.h> 35 #include <string.h> 36 37 // Programmabhaengige Includes. 38 #include <rscconst.hxx> 39 #ifndef _RSCSARRAY_HXX 40 #include <rscarray.hxx> 41 #endif 42 #include <rscdb.hxx> 43 44 /****************** C O D E **********************************************/ 45 /****************** R s c I n s t N o d e ********************************/ 46 /************************************************************************* 47 |* 48 |* RscInstNode::RscInstNode() 49 |* 50 |* Beschreibung 51 |* Ersterstellung MM 06.08.91 52 |* Letzte Aenderung MM 06.08.91 53 |* 54 *************************************************************************/ 55 RscInstNode::RscInstNode( sal_uInt32 nId ) 56 { 57 nTypeId = nId; 58 } 59 60 /************************************************************************* 61 |* 62 |* RscInstNode::~RscInstNode() 63 |* 64 |* Beschreibung 65 |* Ersterstellung MM 06.08.91 66 |* Letzte Aenderung MM 06.08.91 67 |* 68 *************************************************************************/ 69 RscInstNode::~RscInstNode() 70 { 71 if( aInst.IsInst() ) 72 { 73 aInst.pClass->Destroy( aInst ); 74 rtl_freeMemory( aInst.pData ); 75 } 76 } 77 78 /************************************************************************* 79 |* 80 |* RscInstNode::GetId() 81 |* 82 |* Beschreibung 83 |* Ersterstellung MM 06.08.91 84 |* Letzte Aenderung MM 06.08.91 85 |* 86 *************************************************************************/ 87 sal_uInt32 RscInstNode::GetId() const 88 { 89 return nTypeId; 90 } 91 92 /****************** R s c A r r a y *************************************/ 93 /************************************************************************* 94 |* 95 |* RscArray::RscArray() 96 |* 97 |* Beschreibung 98 |* Ersterstellung MM 25.05.91 99 |* Letzte Aenderung MM 25.05.91 100 |* 101 *************************************************************************/ 102 RscArray::RscArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper, RscEnum * pTypeCl ) 103 : RscTop( nId, nTypeId, pSuper ) 104 { 105 pTypeClass = pTypeCl; 106 nOffInstData = RscTop::Size(); 107 nSize = nOffInstData + ALIGNED_SIZE( sizeof( RscArrayInst ) ); 108 } 109 110 /************************************************************************* 111 |* 112 |* RscArray::~RscArray() 113 |* 114 |* Beschreibung 115 |* Ersterstellung MM 25.05.91 116 |* Letzte Aenderung MM 25.05.91 117 |* 118 *************************************************************************/ 119 RscArray::~RscArray() 120 { 121 } 122 123 /************************************************************************* 124 |* 125 |* RscArray::~RscArray() 126 |* 127 |* Beschreibung 128 |* Ersterstellung MM 25.05.91 129 |* Letzte Aenderung MM 25.05.91 130 |* 131 *************************************************************************/ 132 RSCCLASS_TYPE RscArray::GetClassType() const 133 { 134 return RSCCLASS_ENUMARRAY; 135 } 136 137 /************************************************************************* 138 |* 139 |* RscArray::GetIndexType() 140 |* 141 |* Beschreibung 142 |* Ersterstellung MM 23.12.92 143 |* Letzte Aenderung MM 144 |* 145 *************************************************************************/ 146 RscTop * RscArray::GetTypeClass() const 147 { 148 return pTypeClass; 149 } 150 151 /************************************************************************* 152 |* 153 |* RscArray::Create() 154 |* 155 |* Beschreibung 156 |* Ersterstellung MM 26.04.91 157 |* Letzte Aenderung MM 26.04.91 158 |* 159 *************************************************************************/ 160 static RscInstNode * Create( RscInstNode * pNode ) 161 { 162 RscInstNode * pRetNode = NULL; 163 RscInstNode * pTmpNode; 164 165 if( pNode ) 166 { 167 pRetNode = new RscInstNode( pNode->GetId() ); 168 pRetNode->aInst = pNode->aInst.pClass->Create( NULL, pNode->aInst ); 169 if( (pTmpNode = Create( pNode->Left() )) != NULL ) 170 pRetNode->Insert( pTmpNode ); 171 if( (pTmpNode = Create( pNode->Right() )) != NULL ) 172 pRetNode->Insert( pTmpNode ); 173 } 174 175 return pRetNode; 176 } 177 178 RSCINST RscArray::Create( RSCINST * pInst, const RSCINST & rDflt, 179 sal_Bool bOwnClass ) 180 { 181 RSCINST aInst; 182 RscArrayInst * pClassData; 183 184 if( !pInst ) 185 { 186 aInst.pClass = this; 187 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() ); 188 } 189 else 190 aInst = *pInst; 191 if( !bOwnClass && rDflt.IsInst() ) 192 bOwnClass = rDflt.pClass->InHierarchy( this ); 193 194 RscTop::Create( &aInst, rDflt, bOwnClass ); 195 196 pClassData = (RscArrayInst *)(aInst.pData + nOffInstData); 197 pClassData->pNode = NULL; 198 if( bOwnClass ) 199 { 200 RscArrayInst * pDfltClassData; 201 202 pDfltClassData = (RscArrayInst *)(rDflt.pData + nOffInstData); 203 204 pClassData->pNode = ::Create( pDfltClassData->pNode ); 205 } 206 return( aInst ); 207 } 208 209 /************************************************************************* 210 |* 211 |* RscArray::Destroy() 212 |* 213 |* Beschreibung 214 |* 215 *************************************************************************/ 216 static void Destroy( RscInstNode * pNode ) 217 { 218 if( pNode ) 219 { 220 Destroy( pNode->Left() ); 221 Destroy( pNode->Right() ); 222 delete pNode; 223 } 224 } 225 226 void RscArray::Destroy( const RSCINST & rInst ) 227 { 228 RscArrayInst * pClassData; 229 230 RscTop::Destroy( rInst ); 231 232 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 233 234 //Baum rekursiv loeschen 235 ::Destroy( pClassData->pNode ); 236 } 237 238 /************************************************************************* 239 |* 240 |* RscArray::GetValueEle() 241 |* 242 |* Beschreibung 243 |* 244 *************************************************************************/ 245 ERRTYPE RscArray::GetValueEle 246 ( 247 const RSCINST & rInst, 248 sal_Int32 lValue, 249 RscTop * pCreateClass, 250 RSCINST * pGetInst 251 ) 252 { 253 RscArrayInst * pClassData; 254 RscInstNode * pNode; 255 256 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 257 258 ERRTYPE aError; 259 260 Atom nId; 261 if( !pTypeClass->GetValueConst( sal_uInt32(lValue), &nId ) ) 262 { // nicht gefunden 263 return ERR_ARRAY_INVALIDINDEX; 264 } 265 266 if( pClassData->pNode ) 267 pNode = pClassData->pNode->Search( sal_uInt32(lValue) ); 268 else 269 pNode = NULL; 270 271 /* 272 if( pNode ) 273 { 274 if( pNode->aInst.pClass->IsDefault( pNode->aInst ) ) 275 { 276 GetSuperClass()->Destroy( pNode->aInst ); 277 GetSuperClass()->Create( &pNode->aInst, rInst ); 278 pNode->aInst.pClass->SetToDefault( pNode->aInst ); 279 } 280 } 281 else 282 */ 283 if( !pNode ) 284 { 285 pNode = new RscInstNode( sal_uInt32(lValue) ); 286 if( pCreateClass && GetSuperClass()->InHierarchy( pCreateClass ) ) 287 pNode->aInst = pCreateClass->Create( NULL, rInst ); 288 else 289 pNode->aInst = GetSuperClass()->Create( NULL, rInst ); 290 pNode->aInst.pClass->SetToDefault( pNode->aInst ); 291 if( pClassData->pNode ) 292 pClassData->pNode->Insert( pNode ); 293 else 294 pClassData->pNode = pNode; 295 } 296 297 *pGetInst = pNode->aInst; 298 return aError; 299 } 300 301 /************************************************************************* 302 |* 303 |* RscArray::GetArrayEle() 304 |* 305 |* Beschreibung 306 |* 307 *************************************************************************/ 308 ERRTYPE RscArray::GetArrayEle 309 ( 310 const RSCINST & rInst, 311 Atom nId, 312 RscTop * pCreateClass, 313 RSCINST * pGetInst 314 ) 315 { 316 sal_Int32 lValue; 317 if( !pTypeClass->GetConstValue( nId, &lValue ) ) 318 { // nicht gefunden 319 return ERR_ARRAY_INVALIDINDEX; 320 } 321 322 return GetValueEle( rInst, lValue, pCreateClass, pGetInst ); 323 } 324 325 /************************************************************************* 326 |* 327 |* RscArray::IsConsistent() 328 |* 329 |* Beschreibung 330 |* Ersterstellung MM 23.09.91 331 |* Letzte Aenderung MM 23.09.91 332 |* 333 *************************************************************************/ 334 static sal_Bool IsConsistent( RscInstNode * pNode, RscInconsList * pList ) 335 { 336 sal_Bool bRet = sal_True; 337 338 if( pNode ) 339 { 340 bRet = pNode->aInst.pClass->IsConsistent( pNode->aInst, pList ); 341 if( !IsConsistent( pNode->Left(), pList ) ) 342 bRet = sal_False; 343 if( !IsConsistent( pNode->Right(), pList ) ) 344 bRet = sal_False; 345 } 346 return bRet; 347 } 348 349 sal_Bool RscArray::IsConsistent( const RSCINST & rInst, RscInconsList * pList ) 350 { 351 RscArrayInst * pClassData; 352 sal_Bool bRet; 353 354 bRet = RscTop::IsConsistent( rInst, pList ); 355 356 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 357 if( !::IsConsistent( pClassData->pNode, pList ) ) 358 bRet = sal_False; 359 360 return( bRet ); 361 } 362 363 /************************************************************************* 364 |* 365 |* RscArray::SetToDefault() 366 |* 367 |* Beschreibung 368 |* Ersterstellung MM 25.04.91 369 |* Letzte Aenderung MM 25.04.91 370 |* 371 *************************************************************************/ 372 static void SetToDefault( RscInstNode * pNode ) 373 { 374 if( pNode ) 375 { 376 pNode->aInst.pClass->SetToDefault( pNode->aInst ); 377 SetToDefault( pNode->Left() ); 378 SetToDefault( pNode->Right() ); 379 } 380 } 381 382 void RscArray::SetToDefault( const RSCINST & rInst ) 383 { 384 RscArrayInst * pClassData; 385 386 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 387 388 ::SetToDefault( pClassData->pNode ); 389 390 RscTop::SetToDefault( rInst ); 391 } 392 393 /************************************************************************* 394 |* 395 |* RscArray::IsDefault() 396 |* 397 |* Beschreibung 398 |* Ersterstellung MM 25.04.91 399 |* Letzte Aenderung MM 25.04.91 400 |* 401 *************************************************************************/ 402 static sal_Bool IsDefault( RscInstNode * pNode ) 403 { 404 sal_Bool bRet = sal_True; 405 406 if( pNode ) 407 { 408 bRet = pNode->aInst.pClass->IsDefault( pNode->aInst ); 409 if( bRet ) 410 bRet = IsDefault( pNode->Left() ); 411 if( bRet ) 412 bRet = IsDefault( pNode->Right() ); 413 } 414 return bRet; 415 } 416 417 sal_Bool RscArray::IsDefault( const RSCINST & rInst ) 418 { 419 RscArrayInst * pClassData; 420 421 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 422 423 sal_Bool bRet = ::IsDefault( pClassData->pNode ); 424 425 if( bRet ) 426 bRet = RscTop::IsDefault( rInst ); 427 return bRet; 428 } 429 430 /************************************************************************* 431 |* 432 |* RscArray::IsValueDefault() 433 |* 434 |* Beschreibung 435 |* Ersterstellung MM 25.04.91 436 |* Letzte Aenderung MM 15.01.92 437 |* 438 *************************************************************************/ 439 static sal_Bool IsValueDefault( RscInstNode * pNode, CLASS_DATA pDef ) 440 { 441 sal_Bool bRet = sal_True; 442 443 if( pNode ) 444 { 445 bRet = pNode->aInst.pClass->IsValueDefault( pNode->aInst, pDef ); 446 if( bRet ) 447 bRet = IsValueDefault( pNode->Left(), pDef ); 448 if( bRet ) 449 bRet = IsValueDefault( pNode->Right(), pDef ); 450 } 451 return bRet; 452 } 453 454 sal_Bool RscArray::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) 455 { 456 RscArrayInst * pClassData; 457 sal_Bool bRet; 458 459 bRet = RscTop::IsValueDefault( rInst, pDef ); 460 461 if( bRet ) 462 { 463 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 464 465 bRet = ::IsValueDefault( pClassData->pNode, pDef ); 466 } 467 return bRet; 468 } 469 470 /************************************************************************* 471 |* RscArray::WriteSrcHeader() 472 |* 473 |* Beschreibung 474 *************************************************************************/ 475 void RscArray::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput, 476 RscTypCont * pTC, sal_uInt32 nTab, 477 const RscId & aId, const char * pVarName ) 478 { 479 RscArrayInst * pClassData; 480 481 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 482 483 if( pTC->IsSrsDefault() ) 484 { // nur einen Wert schreiben 485 RscInstNode * pNode = NULL; 486 if( pClassData->pNode ) 487 { 488 std::vector< sal_uInt32 >::const_iterator it; 489 for( it = pTC->GetFallbacks().begin(); !pNode && it != pTC->GetFallbacks().end(); ++it ) 490 pNode = pClassData->pNode->Search( *it ); 491 } 492 493 if( pNode ) 494 { 495 if( pNode->aInst.pClass->IsDefault( pNode->aInst ) ) 496 fprintf( fOutput, "Default" ); 497 else 498 pNode->aInst.pClass->WriteSrcHeader( 499 pNode->aInst, fOutput, 500 pTC, nTab, aId, pVarName ); 501 return; 502 } 503 } 504 505 if( IsDefault( rInst ) ) 506 fprintf( fOutput, "Default" ); 507 else 508 { 509 RSCINST aSuper( GetSuperClass(), rInst.pData ); 510 aSuper.pClass->WriteSrcHeader( aSuper, fOutput, pTC, 511 nTab, aId, pVarName ); 512 } 513 if( !pTC->IsSrsDefault() ) 514 WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); 515 } 516 517 /************************************************************************* 518 |* RscArray::WriteSrc() 519 |* 520 |* Beschreibung 521 *************************************************************************/ 522 static void WriteSrc( RscInstNode * pNode, FILE * fOutput, RscTypCont * pTC, 523 sal_uInt32 nTab, const char * pVarName, 524 CLASS_DATA pDfltData, RscConst * pTypeClass ) 525 { 526 if( pNode ) 527 { 528 WriteSrc( pNode->Left(), fOutput, pTC, nTab, pVarName, 529 pDfltData, pTypeClass ); 530 if( !pNode->aInst.pClass->IsValueDefault( pNode->aInst, pDfltData ) ) 531 { 532 fprintf( fOutput, ";\n" ); 533 for( sal_uInt32 n = 0; n < nTab; n++ ) 534 fputc( '\t', fOutput ); 535 536 Atom nIdxId; 537 pTypeClass->GetValueConst( pNode->GetId(), &nIdxId ); 538 fprintf( fOutput, "%s[ %s ] = ", pVarName, pHS->getString( nIdxId ).getStr() ); 539 pNode->aInst.pClass->WriteSrcHeader( pNode->aInst, fOutput, pTC, 540 nTab, RscId(), pVarName ); 541 } 542 WriteSrc( pNode->Right(), fOutput, pTC, nTab, pVarName, 543 pDfltData, pTypeClass ); 544 } 545 } 546 547 void RscArray::WriteSrcArray( const RSCINST & rInst, FILE * fOutput, 548 RscTypCont * pTC, sal_uInt32 nTab, 549 const char * pVarName ) 550 { 551 RscArrayInst * pClassData; 552 553 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 554 555 ::WriteSrc( pClassData->pNode, fOutput, pTC, nTab, pVarName, 556 rInst.pData, pTypeClass ); 557 }; 558 559 void RscArray::WriteSrc( const RSCINST & rInst, FILE * fOutput, 560 RscTypCont * pTC, sal_uInt32 nTab, 561 const char * pVarName ) 562 { 563 WriteSrcArray( rInst, fOutput, pTC, nTab, pVarName ); 564 } 565 566 /************************************************************************* 567 |* RscArray::WriteRc() 568 |* 569 |* Beschreibung 570 *************************************************************************/ 571 ERRTYPE RscArray::WriteRc( const RSCINST & rInst, RscWriteRc & rMem, 572 RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra ) 573 { 574 ERRTYPE aError; 575 RscArrayInst * pClassData; 576 RscInstNode * pNode = NULL; 577 578 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData); 579 580 if( pClassData->pNode ) 581 { 582 #if OSL_DEBUG_LEVEL > 2 583 fprintf( stderr, "RscArray::WriteRc: Fallback " ); 584 #endif 585 std::vector< sal_uInt32 >::const_iterator it; 586 for( it = pTC->GetFallbacks().begin(); !pNode && it != pTC->GetFallbacks().end(); ++it ) 587 { 588 pNode = pClassData->pNode->Search( *it ); 589 #if OSL_DEBUG_LEVEL > 2 590 fprintf( stderr, " 0x%hx", *it ); 591 #endif 592 } 593 #if OSL_DEBUG_LEVEL > 2 594 fprintf( stderr, "\n" ); 595 #endif 596 } 597 598 if( pNode ) 599 aError = pNode->aInst.pClass->WriteRc( pNode->aInst, rMem, pTC, 600 nDeep, bExtra ); 601 else 602 aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep, bExtra ); 603 604 return aError; 605 } 606 607 //======================================================================== 608 void RscArray::WriteRcAccess 609 ( 610 FILE * fOutput, 611 RscTypCont * pTC, 612 const char * pName 613 ) 614 { 615 GetSuperClass()->WriteRcAccess( fOutput, pTC, pName ); 616 } 617 618 /************************************************************************* 619 |* 620 |* RscClassArray::RscClassArray() 621 |* 622 |* Beschreibung 623 |* Ersterstellung MM 25.05.91 624 |* Letzte Aenderung MM 25.05.91 625 |* 626 *************************************************************************/ 627 RscClassArray::RscClassArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper, 628 RscEnum * pTypeCl ) 629 : RscArray( nId, nTypeId, pSuper, pTypeCl ) 630 { 631 } 632 633 /************************************************************************* 634 |* 635 |* RscClassArray::~RscClassArray() 636 |* 637 |* Beschreibung 638 |* Ersterstellung MM 25.05.91 639 |* Letzte Aenderung MM 25.05.91 640 |* 641 *************************************************************************/ 642 RscClassArray::~RscClassArray() 643 { 644 } 645 646 /************************************************************************* 647 |* 648 |* RscClassArray::WriteSrcHeader() 649 |* 650 |* Beschreibung 651 |* Ersterstellung MM 25.05.91 652 |* Letzte Aenderung MM 25.05.91 653 |* 654 *************************************************************************/ 655 void RscClassArray::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput, 656 RscTypCont * pTC, sal_uInt32 nTab, 657 const RscId & aId, const char * pName ) 658 { 659 RscArray::WriteSrcHeader( rInst, fOutput, pTC, nTab, aId, pName ); 660 } 661 662 /************************************************************************* 663 |* 664 |* RscClassArray::WriteSrc() 665 |* 666 |* Beschreibung 667 |* Ersterstellung MM 25.05.91 668 |* Letzte Aenderung MM 25.05.91 669 |* 670 *************************************************************************/ 671 void RscClassArray::WriteSrc( const RSCINST & rInst, FILE * fOutput, 672 RscTypCont * pTC, sal_uInt32 nTab, 673 const char * pVarName ) 674 { 675 RscArray::WriteSrc( rInst, fOutput, pTC, nTab, pVarName ); 676 } 677 678 /************************************************************************* 679 |* 680 |* RscClassArray::WriteRcHeader() 681 |* 682 |* Beschreibung 683 |* Ersterstellung MM 25.05.91 684 |* Letzte Aenderung MM 25.05.91 685 |* 686 *************************************************************************/ 687 ERRTYPE RscClassArray::WriteRcHeader( const RSCINST & rInst, RscWriteRc & aMem, 688 RscTypCont * pTC, const RscId & aId, 689 sal_uInt32 nDeep, sal_Bool bExtra ) 690 { 691 // Eigenen Typ schreiben 692 return GetSuperClass()->WriteRcHeader( rInst, aMem, pTC, aId, 693 nDeep, bExtra ); 694 } 695 696 /************************************************************************* 697 |* 698 |* RscLangArray::RscLangArray() 699 |* 700 |* Beschreibung 701 |* Ersterstellung MM 25.05.91 702 |* Letzte Aenderung MM 25.05.91 703 |* 704 *************************************************************************/ 705 RscLangArray::RscLangArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper, 706 RscEnum * pTypeCl ) 707 : RscArray( nId, nTypeId, pSuper, pTypeCl ) 708 { 709 } 710 711 /************************************************************************* 712 |* 713 |* RscLangArray::RscLangArray() 714 |* 715 |* Beschreibung 716 |* Ersterstellung MM 25.05.91 717 |* Letzte Aenderung MM 25.05.91 718 |* 719 *************************************************************************/ 720 RSCCLASS_TYPE RscLangArray::GetClassType() const 721 { 722 if( GetSuperClass() ) 723 return GetSuperClass()->GetClassType(); 724 else 725 return RscArray::GetClassType(); 726 727 } 728 729