xref: /trunk/main/idl/inc/basobj.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 #ifndef _BASOBJ_HXX
29 #define _BASOBJ_HXX
30 
31 #include <tools/ref.hxx>
32 #include <bastype.hxx>
33 #include <tools/pstm.hxx>
34 
35 class SvTokenStream;
36 class SvMetaObject;
37 class SvAttributeList;
38 class SvIdlDataBase;
39 
40 typedef SvMetaObject * (*CreateMetaObjectType)();
41 #define IDL_WRITE_COMPILER  0x8000
42 #define IDL_WRITE_BROWSER   0x4000
43 #define IDL_WRITE_CALLING   0x2000
44 #define IDL_WRITE_MASK      0xE000
45 
46 #define C_PREF  "C_"
47 
48 enum WriteType
49 {
50     WRITE_IDL, WRITE_ODL, WRITE_SLOTMAP, WRITE_C_HEADER, WRITE_C_SOURCE,
51     WRITE_CXX_HEADER, WRITE_CXX_SOURCE, WRITE_DOCU
52 };
53 
54 enum
55 {
56     WA_METHOD = 0x1,    WA_VARIABLE = 0x2,  WA_ARGUMENT = 0x4,
57     WA_STRUCT = 0x8,    WA_READONLY = 0x10
58 };
59 typedef int WriteAttribute;
60 
61 /******************** Meta Factory **************************************/
62 #ifdef IDL_COMPILER
63 
64 #define PRV_SV_DECL_META_FACTORY( Class )                               \
65     static SvAttributeList * pAttribList;                               \
66     static SvMetaObject * Create() { return new Class; }                \
67     static const char *   GetClassName() { return #Class; }
68 
69 #define PRV_SV_IMPL_META_FACTORY( Class )                               \
70     SvAttributeList * Class::pAttribList = NULL;
71 
72 #else
73 
74 #define PRV_SV_DECL_META_FACTORY( Class )
75 
76 #define PRV_SV_IMPL_META_FACTORY( Class )
77 
78 #endif // IDL_COMPILER
79 
80 #define SV_DECL_META_FACTORY( Class, CLASS_ID )                         \
81     SV_DECL_PERSIST( Class, CLASS_ID )                                  \
82     PRV_SV_DECL_META_FACTORY( Class )
83 
84 
85 #define SV_DECL_META_FACTORY1( Class, Super1, CLASS_ID )                \
86     SV_DECL_PERSIST1( Class, Super1, CLASS_ID )                         \
87     PRV_SV_DECL_META_FACTORY( Class )
88 
89 #define SV_IMPL_META_FACTORY( Class )                                   \
90     PRV_SV_IMPL_META_FACTORY( Class )                                   \
91     SV_IMPL_PERSIST( Class )
92 
93 
94 #define SV_IMPL_META_FACTORY1( Class, Super1 )                          \
95     PRV_SV_IMPL_META_FACTORY( Class )                                   \
96     SV_IMPL_PERSIST1( Class, Super1 )
97 
98 
99 /******************** class SvMetaObject ********************************/
100 class SvMetaObject : public SvPersistBase
101 {
102 public:
103             SV_DECL_META_FACTORY1( SvMetaObject, SvPersistBase, 14 )
104             SvMetaObject();
105 
106 #ifdef IDL_COMPILER
107     static void         WriteTab( SvStream & rOutStm, sal_uInt16 nTab );
108     static sal_Bool         TestAndSeekSpaceOnly( SvStream &, sal_uLong nBegPos );
109     static void         Back2Delemitter( SvStream & );
110     static void         WriteStars( SvStream & );
111 
112     virtual sal_Bool        ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm );
113     virtual void        WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab );
114 
115     virtual void        Write( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab,
116                                WriteType, WriteAttribute = 0 );
117 
118     virtual void        WriteCxx( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab );
119     virtual void        WriteHxx( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab );
120 #endif
121 };
122 SV_DECL_IMPL_REF(SvMetaObject)
123 //SV_DECL_IMPL_PERSIST_LIST(SvMetaObject,SvMetaObject *)
124 SV_DECL_PERSIST_LIST(SvMetaObject,SvMetaObject *)
125 SV_IMPL_PERSIST_LIST(SvMetaObject,SvMetaObject *)
126 
127 
128 class SvMetaObjectMemberStack
129 {
130     SvMetaObjectMemberList aList;
131 public:
132             SvMetaObjectMemberStack() {;}
133 
134     void            Push( SvMetaObject * pObj )
135                     { aList.Insert( pObj, LIST_APPEND ); }
136     SvMetaObject *  Pop() { return aList.Remove( aList.Count() -1 ); }
137     SvMetaObject *  Top() const { return aList.GetObject( aList.Count() -1 ); }
138     void            Clear() { aList.Clear(); }
139     sal_uLong     Count() const { return aList.Count(); }
140 
141     SvMetaObject *  Get( TypeId nType )
142                     {
143                         SvMetaObject * pObj = aList.Last();
144                         while( pObj )
145                         {
146                             if( pObj->IsA( nType ) )
147                                 return pObj;
148                             pObj = aList.Prev();
149                         }
150                         return NULL;
151                     }
152 };
153 
154 /******************** class SvMetaName **********************************/
155 class SvMetaName : public SvMetaObject
156 {
157     SvString      aName;
158     SvHelpContext aHelpContext;
159     SvHelpText    aHelpText;
160     SvString      aConfigName;
161     SvString      aDescription;
162 
163 protected:
164 #ifdef IDL_COMPILER
165     virtual sal_Bool ReadNameSvIdl( SvIdlDataBase &, SvTokenStream & rInStm );
166             void DoReadContextSvIdl( SvIdlDataBase &, SvTokenStream & rInStm,
167                                      char c = '\0' );
168     virtual void ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & rInStm );
169     virtual void WriteContextSvIdl( SvIdlDataBase & rBase,
170                                     SvStream & rOutStm, sal_uInt16 nTab );
171     virtual void ReadAttributesSvIdl( SvIdlDataBase & rBase,
172                                       SvTokenStream & rInStm );
173     virtual void WriteAttributesSvIdl( SvIdlDataBase & rBase,
174                                        SvStream & rOutStm, sal_uInt16 nTab );
175     virtual void WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab,
176                                     WriteType, WriteAttribute = 0);
177     virtual void WriteContext( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab,
178                                     WriteType, WriteAttribute = 0);
179 #endif
180 public:
181             SV_DECL_META_FACTORY1( SvMetaName, SvMetaObject, 15 )
182             SvMetaName();
183 
184     virtual sal_Bool                SetName( const ByteString & rName, SvIdlDataBase * = NULL  );
185     void                        SetDescription( const ByteString& rText )
186                                 { aDescription = rText; }
187     const SvHelpContext&        GetHelpContext() const { return aHelpContext; }
188     virtual const SvString &    GetName() const { return aName; }
189     virtual const SvString &    GetHelpText() const { return aHelpText; }
190     virtual const SvString &    GetConfigName() const{ return aConfigName; }
191     virtual const SvString&     GetDescription() const{ return aDescription; }
192 
193 #ifdef IDL_COMPILER
194     virtual sal_Bool        Test( SvIdlDataBase &, SvTokenStream & rInStm );
195     virtual sal_Bool        ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm );
196     virtual void        WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab );
197     virtual void        Write( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab,
198                                     WriteType, WriteAttribute = 0);
199     void                WriteDescription( SvStream& rOutStm );
200 #endif
201 };
202 SV_DECL_IMPL_REF(SvMetaName)
203 SV_DECL_IMPL_PERSIST_LIST(SvMetaName,SvMetaName *)
204 
205 
206 /******************** class SvMetaReference *****************************/
207 SV_DECL_REF(SvMetaReference)
208 class SvMetaReference : public SvMetaName
209 {
210 protected:
211     SvMetaReferenceRef  aRef;
212 public:
213             SV_DECL_META_FACTORY1( SvMetaReference, SvMetaName, 17 )
214             SvMetaReference();
215 
216     const SvString &    GetName() const
217                         {
218                             return ( !aRef.Is()
219                                     || SvMetaName::GetName().Len() )
220                                 ? SvMetaName::GetName()
221                                 : aRef->GetName();
222                         }
223 
224     const SvString &    GetHelpText() const
225                         {
226                             return ( !aRef.Is()
227                                     || SvMetaName::GetHelpText().Len() )
228                                 ? SvMetaName::GetHelpText()
229                                 : aRef->GetHelpText();
230                         }
231 
232     const SvString &    GetConfigName() const
233                         {
234                             return ( !aRef.Is()
235                                     || SvMetaName::GetConfigName().Len() )
236                                 ? SvMetaName::GetConfigName()
237                                 : aRef->GetConfigName();
238                         }
239 
240     const SvString &    GetDescription() const
241                         {
242                             return ( !aRef.Is()
243                                     || SvMetaName::GetDescription().Len() )
244                                 ? SvMetaName::GetDescription()
245                                 : aRef->GetDescription();
246                         }
247     SvMetaReference *   GetRef() const { return aRef; }
248     void                SetRef( SvMetaReference * pRef  )
249                         { aRef = pRef; }
250 };
251 SV_IMPL_REF(SvMetaReference)
252 SV_DECL_IMPL_PERSIST_LIST(SvMetaReference,SvMetaReference *)
253 
254 
255 /******************** class SvMetaExtern *********************************/
256 class SvMetaModule;
257 class SvMetaExtern : public SvMetaReference
258 {
259     SvMetaModule *          pModule;    // in welchem Modul enthalten
260 
261     SvUUId                  aUUId;
262     SvVersion               aVersion;
263     sal_Bool                    bReadUUId;
264     sal_Bool                    bReadVersion;
265 public:
266                         SV_DECL_META_FACTORY1( SvMetaExtern, SvMetaName, 16 )
267                         SvMetaExtern();
268 
269     SvMetaModule *      GetModule() const;
270 
271     const SvGlobalName &GetUUId() const;
272     const SvVersion &   GetVersion() const { return aVersion; }
273 #ifdef IDL_COMPILER
274     void                SetModule( SvIdlDataBase & rBase );
275     virtual sal_Bool        ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm );
276     virtual void        WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab );
277 
278     virtual void        Write( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab,
279                                 WriteType, WriteAttribute = 0);
280 protected:
281     virtual void        ReadAttributesSvIdl( SvIdlDataBase &, SvTokenStream & rInStm );
282     virtual void        WriteAttributesSvIdl( SvIdlDataBase & rBase,
283                                               SvStream & rOutStm, sal_uInt16 nTab );
284     virtual void        WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm, sal_uInt16 nTab,
285                                         WriteType, WriteAttribute = 0);
286 #endif
287 };
288 SV_DECL_IMPL_REF(SvMetaExtern)
289 SV_DECL_IMPL_PERSIST_LIST(SvMetaExtern,SvMetaExtern *)
290 
291 
292 #endif // _BASOBJ_HXX
293 
294 
295