CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / rsc / source / res / rscarray.cxx
blobcda959ebb79c2b90ac89226b43d623d49ebdc552
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
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 **************************************/
32 // C and C++ Includes.
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
37 // Programmabhaengige Includes.
38 #include <rscconst.hxx>
39 #ifndef _RSCSARRAY_HXX
40 #include <rscarray.hxx>
41 #endif
42 #include <rscdb.hxx>
44 /****************** C O D E **********************************************/
45 /****************** R s c I n s t N o d e ********************************/
46 /*************************************************************************
48 |* RscInstNode::RscInstNode()
50 |* Beschreibung
51 |* Ersterstellung MM 06.08.91
52 |* Letzte Aenderung MM 06.08.91
54 *************************************************************************/
55 RscInstNode::RscInstNode( sal_uInt32 nId )
57 nTypeId = nId;
60 /*************************************************************************
62 |* RscInstNode::~RscInstNode()
64 |* Beschreibung
65 |* Ersterstellung MM 06.08.91
66 |* Letzte Aenderung MM 06.08.91
68 *************************************************************************/
69 RscInstNode::~RscInstNode()
71 if( aInst.IsInst() )
73 aInst.pClass->Destroy( aInst );
74 rtl_freeMemory( aInst.pData );
78 /*************************************************************************
80 |* RscInstNode::GetId()
82 |* Beschreibung
83 |* Ersterstellung MM 06.08.91
84 |* Letzte Aenderung MM 06.08.91
86 *************************************************************************/
87 sal_uInt32 RscInstNode::GetId() const
89 return nTypeId;
92 /****************** R s c A r r a y *************************************/
93 /*************************************************************************
95 |* RscArray::RscArray()
97 |* Beschreibung
98 |* Ersterstellung MM 25.05.91
99 |* Letzte Aenderung MM 25.05.91
101 *************************************************************************/
102 RscArray::RscArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper, RscEnum * pTypeCl )
103 : RscTop( nId, nTypeId, pSuper )
105 pTypeClass = pTypeCl;
106 nOffInstData = RscTop::Size();
107 nSize = nOffInstData + ALIGNED_SIZE( sizeof( RscArrayInst ) );
110 /*************************************************************************
112 |* RscArray::~RscArray()
114 |* Beschreibung
115 |* Ersterstellung MM 25.05.91
116 |* Letzte Aenderung MM 25.05.91
118 *************************************************************************/
119 RscArray::~RscArray()
123 /*************************************************************************
125 |* RscArray::~RscArray()
127 |* Beschreibung
128 |* Ersterstellung MM 25.05.91
129 |* Letzte Aenderung MM 25.05.91
131 *************************************************************************/
132 RSCCLASS_TYPE RscArray::GetClassType() const
134 return RSCCLASS_ENUMARRAY;
137 /*************************************************************************
139 |* RscArray::GetIndexType()
141 |* Beschreibung
142 |* Ersterstellung MM 23.12.92
143 |* Letzte Aenderung MM
145 *************************************************************************/
146 RscTop * RscArray::GetTypeClass() const
148 return pTypeClass;
151 /*************************************************************************
153 |* RscArray::Create()
155 |* Beschreibung
156 |* Ersterstellung MM 26.04.91
157 |* Letzte Aenderung MM 26.04.91
159 *************************************************************************/
160 static RscInstNode * Create( RscInstNode * pNode )
162 RscInstNode * pRetNode = NULL;
163 RscInstNode * pTmpNode;
165 if( pNode )
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 );
175 return pRetNode;
178 RSCINST RscArray::Create( RSCINST * pInst, const RSCINST & rDflt,
179 sal_Bool bOwnClass )
181 RSCINST aInst;
182 RscArrayInst * pClassData;
184 if( !pInst )
186 aInst.pClass = this;
187 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
189 else
190 aInst = *pInst;
191 if( !bOwnClass && rDflt.IsInst() )
192 bOwnClass = rDflt.pClass->InHierarchy( this );
194 RscTop::Create( &aInst, rDflt, bOwnClass );
196 pClassData = (RscArrayInst *)(aInst.pData + nOffInstData);
197 pClassData->pNode = NULL;
198 if( bOwnClass )
200 RscArrayInst * pDfltClassData;
202 pDfltClassData = (RscArrayInst *)(rDflt.pData + nOffInstData);
204 pClassData->pNode = ::Create( pDfltClassData->pNode );
206 return( aInst );
209 /*************************************************************************
211 |* RscArray::Destroy()
213 |* Beschreibung
215 *************************************************************************/
216 static void Destroy( RscInstNode * pNode )
218 if( pNode )
220 Destroy( pNode->Left() );
221 Destroy( pNode->Right() );
222 delete pNode;
226 void RscArray::Destroy( const RSCINST & rInst )
228 RscArrayInst * pClassData;
230 RscTop::Destroy( rInst );
232 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
234 //Baum rekursiv loeschen
235 ::Destroy( pClassData->pNode );
238 /*************************************************************************
240 |* RscArray::GetValueEle()
242 |* Beschreibung
244 *************************************************************************/
245 ERRTYPE RscArray::GetValueEle
247 const RSCINST & rInst,
248 sal_Int32 lValue,
249 RscTop * pCreateClass,
250 RSCINST * pGetInst
253 RscArrayInst * pClassData;
254 RscInstNode * pNode;
256 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
258 ERRTYPE aError;
260 Atom nId;
261 if( !pTypeClass->GetValueConst( sal_uInt32(lValue), &nId ) )
262 { // nicht gefunden
263 return ERR_ARRAY_INVALIDINDEX;
266 if( pClassData->pNode )
267 pNode = pClassData->pNode->Search( sal_uInt32(lValue) );
268 else
269 pNode = NULL;
272 if( pNode )
274 if( pNode->aInst.pClass->IsDefault( pNode->aInst ) )
276 GetSuperClass()->Destroy( pNode->aInst );
277 GetSuperClass()->Create( &pNode->aInst, rInst );
278 pNode->aInst.pClass->SetToDefault( pNode->aInst );
281 else
283 if( !pNode )
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;
297 *pGetInst = pNode->aInst;
298 return aError;
301 /*************************************************************************
303 |* RscArray::GetArrayEle()
305 |* Beschreibung
307 *************************************************************************/
308 ERRTYPE RscArray::GetArrayEle
310 const RSCINST & rInst,
311 Atom nId,
312 RscTop * pCreateClass,
313 RSCINST * pGetInst
316 sal_Int32 lValue;
317 if( !pTypeClass->GetConstValue( nId, &lValue ) )
318 { // nicht gefunden
319 return ERR_ARRAY_INVALIDINDEX;
322 return GetValueEle( rInst, lValue, pCreateClass, pGetInst );
325 /*************************************************************************
327 |* RscArray::IsConsistent()
329 |* Beschreibung
330 |* Ersterstellung MM 23.09.91
331 |* Letzte Aenderung MM 23.09.91
333 *************************************************************************/
334 static sal_Bool IsConsistent( RscInstNode * pNode, RscInconsList * pList )
336 sal_Bool bRet = sal_True;
338 if( pNode )
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;
346 return bRet;
349 sal_Bool RscArray::IsConsistent( const RSCINST & rInst, RscInconsList * pList )
351 RscArrayInst * pClassData;
352 sal_Bool bRet;
354 bRet = RscTop::IsConsistent( rInst, pList );
356 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
357 if( !::IsConsistent( pClassData->pNode, pList ) )
358 bRet = sal_False;
360 return( bRet );
363 /*************************************************************************
365 |* RscArray::SetToDefault()
367 |* Beschreibung
368 |* Ersterstellung MM 25.04.91
369 |* Letzte Aenderung MM 25.04.91
371 *************************************************************************/
372 static void SetToDefault( RscInstNode * pNode )
374 if( pNode )
376 pNode->aInst.pClass->SetToDefault( pNode->aInst );
377 SetToDefault( pNode->Left() );
378 SetToDefault( pNode->Right() );
382 void RscArray::SetToDefault( const RSCINST & rInst )
384 RscArrayInst * pClassData;
386 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
388 ::SetToDefault( pClassData->pNode );
390 RscTop::SetToDefault( rInst );
393 /*************************************************************************
395 |* RscArray::IsDefault()
397 |* Beschreibung
398 |* Ersterstellung MM 25.04.91
399 |* Letzte Aenderung MM 25.04.91
401 *************************************************************************/
402 static sal_Bool IsDefault( RscInstNode * pNode )
404 sal_Bool bRet = sal_True;
406 if( pNode )
408 bRet = pNode->aInst.pClass->IsDefault( pNode->aInst );
409 if( bRet )
410 bRet = IsDefault( pNode->Left() );
411 if( bRet )
412 bRet = IsDefault( pNode->Right() );
414 return bRet;
417 sal_Bool RscArray::IsDefault( const RSCINST & rInst )
419 RscArrayInst * pClassData;
421 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
423 sal_Bool bRet = ::IsDefault( pClassData->pNode );
425 if( bRet )
426 bRet = RscTop::IsDefault( rInst );
427 return bRet;
430 /*************************************************************************
432 |* RscArray::IsValueDefault()
434 |* Beschreibung
435 |* Ersterstellung MM 25.04.91
436 |* Letzte Aenderung MM 15.01.92
438 *************************************************************************/
439 static sal_Bool IsValueDefault( RscInstNode * pNode, CLASS_DATA pDef )
441 sal_Bool bRet = sal_True;
443 if( pNode )
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 );
451 return bRet;
454 sal_Bool RscArray::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
456 RscArrayInst * pClassData;
457 sal_Bool bRet;
459 bRet = RscTop::IsValueDefault( rInst, pDef );
461 if( bRet )
463 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
465 bRet = ::IsValueDefault( pClassData->pNode, pDef );
467 return bRet;
470 /*************************************************************************
471 |* RscArray::WriteSrcHeader()
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 )
479 RscArrayInst * pClassData;
481 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
483 if( pTC->IsSrsDefault() )
484 { // nur einen Wert schreiben
485 RscInstNode * pNode = NULL;
486 if( pClassData->pNode )
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 );
493 if( pNode )
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;
505 if( IsDefault( rInst ) )
506 fprintf( fOutput, "Default" );
507 else
509 RSCINST aSuper( GetSuperClass(), rInst.pData );
510 aSuper.pClass->WriteSrcHeader( aSuper, fOutput, pTC,
511 nTab, aId, pVarName );
513 if( !pTC->IsSrsDefault() )
514 WriteSrc( rInst, fOutput, pTC, nTab, pVarName );
517 /*************************************************************************
518 |* RscArray::WriteSrc()
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 )
526 if( pNode )
528 WriteSrc( pNode->Left(), fOutput, pTC, nTab, pVarName,
529 pDfltData, pTypeClass );
530 if( !pNode->aInst.pClass->IsValueDefault( pNode->aInst, pDfltData ) )
532 fprintf( fOutput, ";\n" );
533 for( sal_uInt32 n = 0; n < nTab; n++ )
534 fputc( '\t', fOutput );
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 );
542 WriteSrc( pNode->Right(), fOutput, pTC, nTab, pVarName,
543 pDfltData, pTypeClass );
547 void RscArray::WriteSrcArray( const RSCINST & rInst, FILE * fOutput,
548 RscTypCont * pTC, sal_uInt32 nTab,
549 const char * pVarName )
551 RscArrayInst * pClassData;
553 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
555 ::WriteSrc( pClassData->pNode, fOutput, pTC, nTab, pVarName,
556 rInst.pData, pTypeClass );
559 void RscArray::WriteSrc( const RSCINST & rInst, FILE * fOutput,
560 RscTypCont * pTC, sal_uInt32 nTab,
561 const char * pVarName )
563 WriteSrcArray( rInst, fOutput, pTC, nTab, pVarName );
566 /*************************************************************************
567 |* RscArray::WriteRc()
569 |* Beschreibung
570 *************************************************************************/
571 ERRTYPE RscArray::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
572 RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra )
574 ERRTYPE aError;
575 RscArrayInst * pClassData;
576 RscInstNode * pNode = NULL;
578 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
580 if( pClassData->pNode )
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 )
588 pNode = pClassData->pNode->Search( *it );
589 #if OSL_DEBUG_LEVEL > 2
590 fprintf( stderr, " 0x%hx", *it );
591 #endif
593 #if OSL_DEBUG_LEVEL > 2
594 fprintf( stderr, "\n" );
595 #endif
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 );
604 return aError;
607 //========================================================================
608 void RscArray::WriteRcAccess
610 FILE * fOutput,
611 RscTypCont * pTC,
612 const char * pName
615 GetSuperClass()->WriteRcAccess( fOutput, pTC, pName );
618 /*************************************************************************
620 |* RscClassArray::RscClassArray()
622 |* Beschreibung
623 |* Ersterstellung MM 25.05.91
624 |* Letzte Aenderung MM 25.05.91
626 *************************************************************************/
627 RscClassArray::RscClassArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper,
628 RscEnum * pTypeCl )
629 : RscArray( nId, nTypeId, pSuper, pTypeCl )
633 /*************************************************************************
635 |* RscClassArray::~RscClassArray()
637 |* Beschreibung
638 |* Ersterstellung MM 25.05.91
639 |* Letzte Aenderung MM 25.05.91
641 *************************************************************************/
642 RscClassArray::~RscClassArray()
646 /*************************************************************************
648 |* RscClassArray::WriteSrcHeader()
650 |* Beschreibung
651 |* Ersterstellung MM 25.05.91
652 |* Letzte Aenderung MM 25.05.91
654 *************************************************************************/
655 void RscClassArray::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput,
656 RscTypCont * pTC, sal_uInt32 nTab,
657 const RscId & aId, const char * pName )
659 RscArray::WriteSrcHeader( rInst, fOutput, pTC, nTab, aId, pName );
662 /*************************************************************************
664 |* RscClassArray::WriteSrc()
666 |* Beschreibung
667 |* Ersterstellung MM 25.05.91
668 |* Letzte Aenderung MM 25.05.91
670 *************************************************************************/
671 void RscClassArray::WriteSrc( const RSCINST & rInst, FILE * fOutput,
672 RscTypCont * pTC, sal_uInt32 nTab,
673 const char * pVarName )
675 RscArray::WriteSrc( rInst, fOutput, pTC, nTab, pVarName );
678 /*************************************************************************
680 |* RscClassArray::WriteRcHeader()
682 |* Beschreibung
683 |* Ersterstellung MM 25.05.91
684 |* Letzte Aenderung MM 25.05.91
686 *************************************************************************/
687 ERRTYPE RscClassArray::WriteRcHeader( const RSCINST & rInst, RscWriteRc & aMem,
688 RscTypCont * pTC, const RscId & aId,
689 sal_uInt32 nDeep, sal_Bool bExtra )
691 // Eigenen Typ schreiben
692 return GetSuperClass()->WriteRcHeader( rInst, aMem, pTC, aId,
693 nDeep, bExtra );
696 /*************************************************************************
698 |* RscLangArray::RscLangArray()
700 |* Beschreibung
701 |* Ersterstellung MM 25.05.91
702 |* Letzte Aenderung MM 25.05.91
704 *************************************************************************/
705 RscLangArray::RscLangArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper,
706 RscEnum * pTypeCl )
707 : RscArray( nId, nTypeId, pSuper, pTypeCl )
711 /*************************************************************************
713 |* RscLangArray::RscLangArray()
715 |* Beschreibung
716 |* Ersterstellung MM 25.05.91
717 |* Letzte Aenderung MM 25.05.91
719 *************************************************************************/
720 RSCCLASS_TYPE RscLangArray::GetClassType() const
722 if( GetSuperClass() )
723 return GetSuperClass()->GetClassType();
724 else
725 return RscArray::GetClassType();