1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscarray.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
35 // C and C++ Includes.
40 // Programmabhaengige Includes.
41 #include <rscconst.hxx>
42 #ifndef _RSCSARRAY_HXX
43 #include <rscarray.hxx>
47 /****************** C O D E **********************************************/
48 /****************** R s c I n s t N o d e ********************************/
49 /*************************************************************************
51 |* RscInstNode::RscInstNode()
54 |* Ersterstellung MM 06.08.91
55 |* Letzte Aenderung MM 06.08.91
57 *************************************************************************/
58 RscInstNode::RscInstNode( sal_uInt32 nId
)
63 /*************************************************************************
65 |* RscInstNode::~RscInstNode()
68 |* Ersterstellung MM 06.08.91
69 |* Letzte Aenderung MM 06.08.91
71 *************************************************************************/
72 RscInstNode::~RscInstNode()
76 aInst
.pClass
->Destroy( aInst
);
77 rtl_freeMemory( aInst
.pData
);
81 /*************************************************************************
83 |* RscInstNode::GetId()
86 |* Ersterstellung MM 06.08.91
87 |* Letzte Aenderung MM 06.08.91
89 *************************************************************************/
90 sal_uInt32
RscInstNode::GetId() const
95 /****************** R s c A r r a y *************************************/
96 /*************************************************************************
98 |* RscArray::RscArray()
101 |* Ersterstellung MM 25.05.91
102 |* Letzte Aenderung MM 25.05.91
104 *************************************************************************/
105 RscArray::RscArray( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuper
, RscEnum
* pTypeCl
)
106 : RscTop( nId
, nTypeId
, pSuper
)
108 pTypeClass
= pTypeCl
;
109 nOffInstData
= RscTop::Size();
110 nSize
= nOffInstData
+ ALIGNED_SIZE( sizeof( RscArrayInst
) );
113 /*************************************************************************
115 |* RscArray::~RscArray()
118 |* Ersterstellung MM 25.05.91
119 |* Letzte Aenderung MM 25.05.91
121 *************************************************************************/
122 RscArray::~RscArray()
126 /*************************************************************************
128 |* RscArray::~RscArray()
131 |* Ersterstellung MM 25.05.91
132 |* Letzte Aenderung MM 25.05.91
134 *************************************************************************/
135 RSCCLASS_TYPE
RscArray::GetClassType() const
137 return RSCCLASS_ENUMARRAY
;
140 /*************************************************************************
142 |* RscArray::GetIndexType()
145 |* Ersterstellung MM 23.12.92
146 |* Letzte Aenderung MM
148 *************************************************************************/
149 RscTop
* RscArray::GetTypeClass() const
154 /*************************************************************************
156 |* RscArray::Create()
159 |* Ersterstellung MM 26.04.91
160 |* Letzte Aenderung MM 26.04.91
162 *************************************************************************/
163 static RscInstNode
* Create( RscInstNode
* pNode
)
165 RscInstNode
* pRetNode
= NULL
;
166 RscInstNode
* pTmpNode
;
170 pRetNode
= new RscInstNode( pNode
->GetId() );
171 pRetNode
->aInst
= pNode
->aInst
.pClass
->Create( NULL
, pNode
->aInst
);
172 if( (pTmpNode
= Create( pNode
->Left() )) != NULL
)
173 pRetNode
->Insert( pTmpNode
);
174 if( (pTmpNode
= Create( pNode
->Right() )) != NULL
)
175 pRetNode
->Insert( pTmpNode
);
181 RSCINST
RscArray::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
185 RscArrayInst
* pClassData
;
190 aInst
.pData
= (CLASS_DATA
) rtl_allocateMemory( Size() );
194 if( !bOwnClass
&& rDflt
.IsInst() )
195 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
197 RscTop::Create( &aInst
, rDflt
, bOwnClass
);
199 pClassData
= (RscArrayInst
*)(aInst
.pData
+ nOffInstData
);
200 pClassData
->pNode
= NULL
;
203 RscArrayInst
* pDfltClassData
;
205 pDfltClassData
= (RscArrayInst
*)(rDflt
.pData
+ nOffInstData
);
207 pClassData
->pNode
= ::Create( pDfltClassData
->pNode
);
212 /*************************************************************************
214 |* RscArray::Destroy()
218 *************************************************************************/
219 static void Destroy( RscInstNode
* pNode
)
223 Destroy( pNode
->Left() );
224 Destroy( pNode
->Right() );
229 void RscArray::Destroy( const RSCINST
& rInst
)
231 RscArrayInst
* pClassData
;
233 RscTop::Destroy( rInst
);
235 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
237 //Baum rekursiv loeschen
238 ::Destroy( pClassData
->pNode
);
241 /*************************************************************************
243 |* RscArray::GetValueEle()
247 *************************************************************************/
248 ERRTYPE
RscArray::GetValueEle
250 const RSCINST
& rInst
,
252 RscTop
* pCreateClass
,
256 RscArrayInst
* pClassData
;
259 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
264 if( !pTypeClass
->GetValueConst( sal_uInt32(lValue
), &nId
) )
266 return ERR_ARRAY_INVALIDINDEX
;
269 if( pClassData
->pNode
)
270 pNode
= pClassData
->pNode
->Search( sal_uInt32(lValue
) );
277 if( pNode->aInst.pClass->IsDefault( pNode->aInst ) )
279 GetSuperClass()->Destroy( pNode->aInst );
280 GetSuperClass()->Create( &pNode->aInst, rInst );
281 pNode->aInst.pClass->SetToDefault( pNode->aInst );
288 pNode
= new RscInstNode( sal_uInt32(lValue
) );
289 if( pCreateClass
&& GetSuperClass()->InHierarchy( pCreateClass
) )
290 pNode
->aInst
= pCreateClass
->Create( NULL
, rInst
);
292 pNode
->aInst
= GetSuperClass()->Create( NULL
, rInst
);
293 pNode
->aInst
.pClass
->SetToDefault( pNode
->aInst
);
294 if( pClassData
->pNode
)
295 pClassData
->pNode
->Insert( pNode
);
297 pClassData
->pNode
= pNode
;
300 *pGetInst
= pNode
->aInst
;
304 /*************************************************************************
306 |* RscArray::GetArrayEle()
310 *************************************************************************/
311 ERRTYPE
RscArray::GetArrayEle
313 const RSCINST
& rInst
,
315 RscTop
* pCreateClass
,
320 if( !pTypeClass
->GetConstValue( nId
, &lValue
) )
322 return ERR_ARRAY_INVALIDINDEX
;
325 return GetValueEle( rInst
, lValue
, pCreateClass
, pGetInst
);
328 /*************************************************************************
330 |* RscArray::IsConsistent()
333 |* Ersterstellung MM 23.09.91
334 |* Letzte Aenderung MM 23.09.91
336 *************************************************************************/
337 static BOOL
IsConsistent( RscInstNode
* pNode
, RscInconsList
* pList
)
343 bRet
= pNode
->aInst
.pClass
->IsConsistent( pNode
->aInst
, pList
);
344 if( !IsConsistent( pNode
->Left(), pList
) )
346 if( !IsConsistent( pNode
->Right(), pList
) )
352 BOOL
RscArray::IsConsistent( const RSCINST
& rInst
, RscInconsList
* pList
)
354 RscArrayInst
* pClassData
;
357 bRet
= RscTop::IsConsistent( rInst
, pList
);
359 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
360 if( !::IsConsistent( pClassData
->pNode
, pList
) )
366 /*************************************************************************
368 |* RscArray::SetToDefault()
371 |* Ersterstellung MM 25.04.91
372 |* Letzte Aenderung MM 25.04.91
374 *************************************************************************/
375 static void SetToDefault( RscInstNode
* pNode
)
379 pNode
->aInst
.pClass
->SetToDefault( pNode
->aInst
);
380 SetToDefault( pNode
->Left() );
381 SetToDefault( pNode
->Right() );
385 void RscArray::SetToDefault( const RSCINST
& rInst
)
387 RscArrayInst
* pClassData
;
389 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
391 ::SetToDefault( pClassData
->pNode
);
393 RscTop::SetToDefault( rInst
);
396 /*************************************************************************
398 |* RscArray::IsDefault()
401 |* Ersterstellung MM 25.04.91
402 |* Letzte Aenderung MM 25.04.91
404 *************************************************************************/
405 static BOOL
IsDefault( RscInstNode
* pNode
)
411 bRet
= pNode
->aInst
.pClass
->IsDefault( pNode
->aInst
);
413 bRet
= IsDefault( pNode
->Left() );
415 bRet
= IsDefault( pNode
->Right() );
420 BOOL
RscArray::IsDefault( const RSCINST
& rInst
)
422 RscArrayInst
* pClassData
;
424 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
426 BOOL bRet
= ::IsDefault( pClassData
->pNode
);
429 bRet
= RscTop::IsDefault( rInst
);
433 /*************************************************************************
435 |* RscArray::IsValueDefault()
438 |* Ersterstellung MM 25.04.91
439 |* Letzte Aenderung MM 15.01.92
441 *************************************************************************/
442 static BOOL
IsValueDefault( RscInstNode
* pNode
, CLASS_DATA pDef
)
448 bRet
= pNode
->aInst
.pClass
->IsValueDefault( pNode
->aInst
, pDef
);
450 bRet
= IsValueDefault( pNode
->Left(), pDef
);
452 bRet
= IsValueDefault( pNode
->Right(), pDef
);
457 BOOL
RscArray::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
459 RscArrayInst
* pClassData
;
462 bRet
= RscTop::IsValueDefault( rInst
, pDef
);
466 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
468 bRet
= ::IsValueDefault( pClassData
->pNode
, pDef
);
473 /*************************************************************************
474 |* RscArray::WriteSrcHeader()
477 *************************************************************************/
478 void RscArray::WriteSrcHeader( const RSCINST
& rInst
, FILE * fOutput
,
479 RscTypCont
* pTC
, sal_uInt32 nTab
,
480 const RscId
& aId
, const char * pVarName
)
482 RscArrayInst
* pClassData
;
484 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
486 if( pTC
->IsSrsDefault() )
487 { // nur einen Wert schreiben
488 RscInstNode
* pNode
= NULL
;
489 if( pClassData
->pNode
)
491 std::vector
< sal_uInt32
>::const_iterator it
;
492 for( it
= pTC
->GetFallbacks().begin(); !pNode
&& it
!= pTC
->GetFallbacks().end(); ++it
)
493 pNode
= pClassData
->pNode
->Search( *it
);
498 if( pNode
->aInst
.pClass
->IsDefault( pNode
->aInst
) )
499 fprintf( fOutput
, "Default" );
501 pNode
->aInst
.pClass
->WriteSrcHeader(
502 pNode
->aInst
, fOutput
,
503 pTC
, nTab
, aId
, pVarName
);
508 if( IsDefault( rInst
) )
509 fprintf( fOutput
, "Default" );
512 RSCINST
aSuper( GetSuperClass(), rInst
.pData
);
513 aSuper
.pClass
->WriteSrcHeader( aSuper
, fOutput
, pTC
,
514 nTab
, aId
, pVarName
);
516 if( !pTC
->IsSrsDefault() )
517 WriteSrc( rInst
, fOutput
, pTC
, nTab
, pVarName
);
520 /*************************************************************************
521 |* RscArray::WriteSrc()
524 *************************************************************************/
525 static void WriteSrc( RscInstNode
* pNode
, FILE * fOutput
, RscTypCont
* pTC
,
526 sal_uInt32 nTab
, const char * pVarName
,
527 CLASS_DATA pDfltData
, RscConst
* pTypeClass
)
531 WriteSrc( pNode
->Left(), fOutput
, pTC
, nTab
, pVarName
,
532 pDfltData
, pTypeClass
);
533 if( !pNode
->aInst
.pClass
->IsValueDefault( pNode
->aInst
, pDfltData
) )
535 fprintf( fOutput
, ";\n" );
536 for( sal_uInt32 n
= 0; n
< nTab
; n
++ )
537 fputc( '\t', fOutput
);
540 pTypeClass
->GetValueConst( pNode
->GetId(), &nIdxId
);
541 fprintf( fOutput
, "%s[ %s ] = ", pVarName
, pHS
->getString( nIdxId
).getStr() );
542 pNode
->aInst
.pClass
->WriteSrcHeader( pNode
->aInst
, fOutput
, pTC
,
543 nTab
, RscId(), pVarName
);
545 WriteSrc( pNode
->Right(), fOutput
, pTC
, nTab
, pVarName
,
546 pDfltData
, pTypeClass
);
550 void RscArray::WriteSrcArray( const RSCINST
& rInst
, FILE * fOutput
,
551 RscTypCont
* pTC
, sal_uInt32 nTab
,
552 const char * pVarName
)
554 RscArrayInst
* pClassData
;
556 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
558 ::WriteSrc( pClassData
->pNode
, fOutput
, pTC
, nTab
, pVarName
,
559 rInst
.pData
, pTypeClass
);
562 void RscArray::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
563 RscTypCont
* pTC
, sal_uInt32 nTab
,
564 const char * pVarName
)
566 WriteSrcArray( rInst
, fOutput
, pTC
, nTab
, pVarName
);
569 /*************************************************************************
570 |* RscArray::WriteRc()
573 *************************************************************************/
574 ERRTYPE
RscArray::WriteRc( const RSCINST
& rInst
, RscWriteRc
& rMem
,
575 RscTypCont
* pTC
, sal_uInt32 nDeep
, BOOL bExtra
)
578 RscArrayInst
* pClassData
;
579 RscInstNode
* pNode
= NULL
;
581 pClassData
= (RscArrayInst
*)(rInst
.pData
+ nOffInstData
);
583 if( pClassData
->pNode
)
585 #if OSL_DEBUG_LEVEL > 2
586 fprintf( stderr
, "RscArray::WriteRc: Fallback " );
588 std::vector
< sal_uInt32
>::const_iterator it
;
589 for( it
= pTC
->GetFallbacks().begin(); !pNode
&& it
!= pTC
->GetFallbacks().end(); ++it
)
591 pNode
= pClassData
->pNode
->Search( *it
);
592 #if OSL_DEBUG_LEVEL > 2
593 fprintf( stderr
, " 0x%hx", *it
);
596 #if OSL_DEBUG_LEVEL > 2
597 fprintf( stderr
, "\n" );
602 aError
= pNode
->aInst
.pClass
->WriteRc( pNode
->aInst
, rMem
, pTC
,
605 aError
= RscTop::WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
610 //========================================================================
611 void RscArray::WriteRcAccess
618 GetSuperClass()->WriteRcAccess( fOutput
, pTC
, pName
);
621 /*************************************************************************
623 |* RscClassArray::RscClassArray()
626 |* Ersterstellung MM 25.05.91
627 |* Letzte Aenderung MM 25.05.91
629 *************************************************************************/
630 RscClassArray::RscClassArray( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuper
,
632 : RscArray( nId
, nTypeId
, pSuper
, pTypeCl
)
636 /*************************************************************************
638 |* RscClassArray::~RscClassArray()
641 |* Ersterstellung MM 25.05.91
642 |* Letzte Aenderung MM 25.05.91
644 *************************************************************************/
645 RscClassArray::~RscClassArray()
649 /*************************************************************************
651 |* RscClassArray::WriteSrcHeader()
654 |* Ersterstellung MM 25.05.91
655 |* Letzte Aenderung MM 25.05.91
657 *************************************************************************/
658 void RscClassArray::WriteSrcHeader( const RSCINST
& rInst
, FILE * fOutput
,
659 RscTypCont
* pTC
, sal_uInt32 nTab
,
660 const RscId
& aId
, const char * pName
)
662 RscArray::WriteSrcHeader( rInst
, fOutput
, pTC
, nTab
, aId
, pName
);
665 /*************************************************************************
667 |* RscClassArray::WriteSrc()
670 |* Ersterstellung MM 25.05.91
671 |* Letzte Aenderung MM 25.05.91
673 *************************************************************************/
674 void RscClassArray::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
675 RscTypCont
* pTC
, sal_uInt32 nTab
,
676 const char * pVarName
)
678 RscArray::WriteSrc( rInst
, fOutput
, pTC
, nTab
, pVarName
);
681 /*************************************************************************
683 |* RscClassArray::WriteRcHeader()
686 |* Ersterstellung MM 25.05.91
687 |* Letzte Aenderung MM 25.05.91
689 *************************************************************************/
690 ERRTYPE
RscClassArray::WriteRcHeader( const RSCINST
& rInst
, RscWriteRc
& aMem
,
691 RscTypCont
* pTC
, const RscId
& aId
,
692 sal_uInt32 nDeep
, BOOL bExtra
)
694 // Eigenen Typ schreiben
695 return GetSuperClass()->WriteRcHeader( rInst
, aMem
, pTC
, aId
,
699 /*************************************************************************
701 |* RscLangArray::RscLangArray()
704 |* Ersterstellung MM 25.05.91
705 |* Letzte Aenderung MM 25.05.91
707 *************************************************************************/
708 RscLangArray::RscLangArray( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuper
,
710 : RscArray( nId
, nTypeId
, pSuper
, pTypeCl
)
714 /*************************************************************************
716 |* RscLangArray::RscLangArray()
719 |* Ersterstellung MM 25.05.91
720 |* Letzte Aenderung MM 25.05.91
722 *************************************************************************/
723 RSCCLASS_TYPE
RscLangArray::GetClassType() const
725 if( GetSuperClass() )
726 return GetSuperClass()->GetClassType();
728 return RscArray::GetClassType();