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.
37 // Programmabhaengige Includes.
38 #include <rscconst.hxx>
39 #ifndef _RSCSARRAY_HXX
40 #include <rscarray.hxx>
44 /****************** C O D E **********************************************/
45 /****************** R s c I n s t N o d e ********************************/
46 /*************************************************************************
48 |* RscInstNode::RscInstNode()
51 |* Ersterstellung MM 06.08.91
52 |* Letzte Aenderung MM 06.08.91
54 *************************************************************************/
55 RscInstNode::RscInstNode( sal_uInt32 nId
)
60 /*************************************************************************
62 |* RscInstNode::~RscInstNode()
65 |* Ersterstellung MM 06.08.91
66 |* Letzte Aenderung MM 06.08.91
68 *************************************************************************/
69 RscInstNode::~RscInstNode()
73 aInst
.pClass
->Destroy( aInst
);
74 rtl_freeMemory( aInst
.pData
);
78 /*************************************************************************
80 |* RscInstNode::GetId()
83 |* Ersterstellung MM 06.08.91
84 |* Letzte Aenderung MM 06.08.91
86 *************************************************************************/
87 sal_uInt32
RscInstNode::GetId() const
92 /****************** R s c A r r a y *************************************/
93 /*************************************************************************
95 |* RscArray::RscArray()
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()
115 |* Ersterstellung MM 25.05.91
116 |* Letzte Aenderung MM 25.05.91
118 *************************************************************************/
119 RscArray::~RscArray()
123 /*************************************************************************
125 |* RscArray::~RscArray()
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()
142 |* Ersterstellung MM 23.12.92
143 |* Letzte Aenderung MM
145 *************************************************************************/
146 RscTop
* RscArray::GetTypeClass() const
151 /*************************************************************************
153 |* RscArray::Create()
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
;
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
);
178 RSCINST
RscArray::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
182 RscArrayInst
* pClassData
;
187 aInst
.pData
= (CLASS_DATA
) rtl_allocateMemory( Size() );
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
;
200 RscArrayInst
* pDfltClassData
;
202 pDfltClassData
= (RscArrayInst
*)(rDflt
.pData
+ nOffInstData
);
204 pClassData
->pNode
= ::Create( pDfltClassData
->pNode
);
209 /*************************************************************************
211 |* RscArray::Destroy()
215 *************************************************************************/
216 static void Destroy( RscInstNode
* pNode
)
220 Destroy( pNode
->Left() );
221 Destroy( pNode
->Right() );
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()
244 *************************************************************************/
245 ERRTYPE
RscArray::GetValueEle
247 const RSCINST
& rInst
,
249 RscTop
* pCreateClass
,
253 RscArrayInst
* pClassData
;
256 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
261 if( !pTypeClass
->GetValueConst( sal_uInt32(lValue
), &nId
) )
263 return ERR_ARRAY_INVALIDINDEX
;
266 if( pClassData
->pNode
)
267 pNode
= pClassData
->pNode
->Search( sal_uInt32(lValue
) );
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 );
285 pNode
= new RscInstNode( sal_uInt32(lValue
) );
286 if( pCreateClass
&& GetSuperClass()->InHierarchy( pCreateClass
) )
287 pNode
->aInst
= pCreateClass
->Create( NULL
, rInst
);
289 pNode
->aInst
= GetSuperClass()->Create( NULL
, rInst
);
290 pNode
->aInst
.pClass
->SetToDefault( pNode
->aInst
);
291 if( pClassData
->pNode
)
292 pClassData
->pNode
->Insert( pNode
);
294 pClassData
->pNode
= pNode
;
297 *pGetInst
= pNode
->aInst
;
301 /*************************************************************************
303 |* RscArray::GetArrayEle()
307 *************************************************************************/
308 ERRTYPE
RscArray::GetArrayEle
310 const RSCINST
& rInst
,
312 RscTop
* pCreateClass
,
317 if( !pTypeClass
->GetConstValue( nId
, &lValue
) )
319 return ERR_ARRAY_INVALIDINDEX
;
322 return GetValueEle( rInst
, lValue
, pCreateClass
, pGetInst
);
325 /*************************************************************************
327 |* RscArray::IsConsistent()
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
;
340 bRet
= pNode
->aInst
.pClass
->IsConsistent( pNode
->aInst
, pList
);
341 if( !IsConsistent( pNode
->Left(), pList
) )
343 if( !IsConsistent( pNode
->Right(), pList
) )
349 sal_Bool
RscArray::IsConsistent( const RSCINST
& rInst
, RscInconsList
* pList
)
351 RscArrayInst
* pClassData
;
354 bRet
= RscTop::IsConsistent( rInst
, pList
);
356 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
357 if( !::IsConsistent( pClassData
->pNode
, pList
) )
363 /*************************************************************************
365 |* RscArray::SetToDefault()
368 |* Ersterstellung MM 25.04.91
369 |* Letzte Aenderung MM 25.04.91
371 *************************************************************************/
372 static void SetToDefault( RscInstNode
* 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()
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
;
408 bRet
= pNode
->aInst
.pClass
->IsDefault( pNode
->aInst
);
410 bRet
= IsDefault( pNode
->Left() );
412 bRet
= IsDefault( pNode
->Right() );
417 sal_Bool
RscArray::IsDefault( const RSCINST
& rInst
)
419 RscArrayInst
* pClassData
;
421 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
423 sal_Bool bRet
= ::IsDefault( pClassData
->pNode
);
426 bRet
= RscTop::IsDefault( rInst
);
430 /*************************************************************************
432 |* RscArray::IsValueDefault()
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
;
445 bRet
= pNode
->aInst
.pClass
->IsValueDefault( pNode
->aInst
, pDef
);
447 bRet
= IsValueDefault( pNode
->Left(), pDef
);
449 bRet
= IsValueDefault( pNode
->Right(), pDef
);
454 sal_Bool
RscArray::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
456 RscArrayInst
* pClassData
;
459 bRet
= RscTop::IsValueDefault( rInst
, pDef
);
463 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
465 bRet
= ::IsValueDefault( pClassData
->pNode
, pDef
);
470 /*************************************************************************
471 |* RscArray::WriteSrcHeader()
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
);
495 if( pNode
->aInst
.pClass
->IsDefault( pNode
->aInst
) )
496 fprintf( fOutput
, "Default" );
498 pNode
->aInst
.pClass
->WriteSrcHeader(
499 pNode
->aInst
, fOutput
,
500 pTC
, nTab
, aId
, pVarName
);
505 if( IsDefault( rInst
) )
506 fprintf( fOutput
, "Default" );
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()
521 *************************************************************************/
522 static void WriteSrc( RscInstNode
* pNode
, FILE * fOutput
, RscTypCont
* pTC
,
523 sal_uInt32 nTab
, const char * pVarName
,
524 CLASS_DATA pDfltData
, RscConst
* pTypeClass
)
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
);
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()
570 *************************************************************************/
571 ERRTYPE
RscArray::WriteRc( const RSCINST
& rInst
, RscWriteRc
& rMem
,
572 RscTypCont
* pTC
, sal_uInt32 nDeep
, sal_Bool bExtra
)
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 " );
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
);
593 #if OSL_DEBUG_LEVEL > 2
594 fprintf( stderr
, "\n" );
599 aError
= pNode
->aInst
.pClass
->WriteRc( pNode
->aInst
, rMem
, pTC
,
602 aError
= RscTop::WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
607 //========================================================================
608 void RscArray::WriteRcAccess
615 GetSuperClass()->WriteRcAccess( fOutput
, pTC
, pName
);
618 /*************************************************************************
620 |* RscClassArray::RscClassArray()
623 |* Ersterstellung MM 25.05.91
624 |* Letzte Aenderung MM 25.05.91
626 *************************************************************************/
627 RscClassArray::RscClassArray( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuper
,
629 : RscArray( nId
, nTypeId
, pSuper
, pTypeCl
)
633 /*************************************************************************
635 |* RscClassArray::~RscClassArray()
638 |* Ersterstellung MM 25.05.91
639 |* Letzte Aenderung MM 25.05.91
641 *************************************************************************/
642 RscClassArray::~RscClassArray()
646 /*************************************************************************
648 |* RscClassArray::WriteSrcHeader()
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()
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()
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
,
696 /*************************************************************************
698 |* RscLangArray::RscLangArray()
701 |* Ersterstellung MM 25.05.91
702 |* Letzte Aenderung MM 25.05.91
704 *************************************************************************/
705 RscLangArray::RscLangArray( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuper
,
707 : RscArray( nId
, nTypeId
, pSuper
, pTypeCl
)
711 /*************************************************************************
713 |* RscLangArray::RscLangArray()
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();
725 return RscArray::GetClassType();