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