xref: /aoo41x/main/idl/inc/database.hxx (revision f3ea6674)
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 #ifndef _DATABASE_HXX
25 #define _DATABASE_HXX
26 
27 #include <module.hxx>
28 #include <hash.hxx>
29 #include <lex.hxx>
30 #include <tools/pstm.hxx>
31 
32 /*************************************************************************
33 *************************************************************************/
34 
35 class SvCommand;
36 
37 #ifdef IDL_COMPILER
38 /******************** class SvIdlError ***********************************/
39 class SvIdlError
40 {
41     ByteString  aText;
42 public:
43     sal_uInt32  nLine, nColumn;
44 
45             SvIdlError() : nLine(0), nColumn(0) {}
46             SvIdlError( sal_uInt32 nL, sal_uInt32 nC )
47                 : nLine(nL), nColumn(nC) {}
48 
49     const ByteString &  GetText() const { return aText; }
50     void            SetText( const ByteString & rT ) { aText = rT; }
51     sal_Bool            IsError() const { return nLine != 0; }
52     void            Clear() { nLine = nColumn = 0; }
53 	SvIdlError &	operator = ( const SvIdlError & rRef )
54 	{ aText   = rRef.aText;
55 	  nLine   = rRef.nLine;
56 	  nColumn = rRef.nColumn;
57 	  return *this;
58 	}
59 };
60 #endif
61 
62 /******************** class SvIdlDataBase ********************************/
63 class SvIdlDataBase
64 {
65 	sal_Bool  						bExport;
66     String                      aExportFile;
67 	sal_uInt32					nUniqueId;
68     sal_uInt32                  nVerbosity;
69     String                      aDataBaseFile;
70     SvFileStream *              pStm;
71     sal_Bool                        bIsModified;
72     SvPersistStream             aPersStream;
73     StringList                  aIdFileList;
74     SvStringHashTable *         pIdTable;
75 
76     SvMetaTypeMemberList        aTypeList;
77     SvMetaClassMemberList       aClassList;
78     SvMetaModuleMemberList      aModuleList;
79 	SvMetaAttributeMemberList	aAttrList;
80     SvMetaTypeMemberList        aTmpTypeList; // nicht Persistent
81 
82 protected:
83 #ifdef IDL_COMPILER
84 	ByteString						aModulePrefix;
85     SvMetaObjectMemberStack     aContextStack;
86     String                      aPath;
87     SvIdlError                  aError;
88 	void						WriteReset()
89 								{
90 									aUsedTypes.Clear();
91 									aIFaceName.Erase();
92 								}
93 #endif
94 public:
95                 explicit SvIdlDataBase( const SvCommand& rCmd );
96                 ~SvIdlDataBase();
97     static sal_Bool IsBinaryFormat( SvStream & rInStm );
98 
99     void        Load( SvStream & rInStm );
100     void        Save( SvStream & rInStm, sal_uInt32 nContextFlags );
101 
102     SvMetaAttributeMemberList&  GetAttrList() { return aAttrList; }
103     SvStringHashTable *       GetIdTable() { return pIdTable; }
104     SvMetaTypeMemberList &    GetTypeList();
105     SvMetaClassMemberList &   GetClassList()  { return aClassList; }
106     SvMetaModuleMemberList &  GetModuleList() { return aModuleList; }
107     SvMetaModule *            GetModule( const ByteString & rName );
108 
109 	// Liste der benutzten Typen beim Schreiben
110     SvMetaTypeMemberList	aUsedTypes;
111 	ByteString					aIFaceName;
112 	SvNumberIdentifier		aStructSlotId;
113 
114 #ifdef IDL_COMPILER
115     void                    StartNewFile( const String& rName );
116     void                    SetExportFile( const String& rName )
117 							{ aExportFile = rName; }
118 	void					AppendAttr( SvMetaAttribute *pSlot );
119 	const ByteString&			GetActModulePrefix() const { return aModulePrefix; }
120 	const SvIdlError &		GetError() const { return aError; }
121 	void					SetError( const SvIdlError & r )
122 							{ aError = r; }
123 
124     const String &            GetPath() const { return aPath; }
125     SvMetaObjectMemberStack & GetStack()      { return aContextStack; }
126 
127 	void					Write( const ByteString & rText );
128 	void 					WriteError( const ByteString & rErrWrn,
129 									const ByteString & rFileName,
130 									const ByteString & rErrorText,
131 									sal_uLong nRow = 0, sal_uLong nColumn = 0 ) const;
132     void                    WriteError( SvTokenStream & rInStm );
133     void                    SetError( const ByteString & rError, SvToken * pTok );
134     void                    Push( SvMetaObject * pObj );
135     sal_Bool                    Pop( sal_Bool bOk, SvTokenStream & rInStm, sal_uInt32 nTokPos )
136                             {
137                                 GetStack().Pop();
138                                 if( bOk )
139                                     aError.Clear();
140                                 else
141                                     rInStm.Seek( nTokPos );
142                                 return bOk;
143                             }
144 	sal_uInt32				GetUniqueId() { return ++nUniqueId; }
145     sal_Bool                    FindId( const ByteString & rIdName, sal_uLong * pVal );
146     sal_Bool                    InsertId( const ByteString & rIdName, sal_uLong nVal );
147     sal_Bool                    ReadIdFile( const String & rFileName );
148 
149 	SvMetaType *			FindType( const ByteString & rName );
150 	static SvMetaType *		FindType( const SvMetaType *, SvMetaTypeMemberList & );
151 
152     SvMetaType *            ReadKnownType( SvTokenStream & rInStm );
153     SvMetaAttribute *       ReadKnownAttr( SvTokenStream & rInStm,
154 											SvMetaType * pType = NULL );
155     SvMetaAttribute *       SearchKnownAttr( const SvNumberIdentifier& );
156     SvMetaClass *           ReadKnownClass( SvTokenStream & rInStm );
157 #endif
158 };
159 
160 #ifdef IDL_COMPILER
161 class SvIdlWorkingBase : public SvIdlDataBase
162 {
163 public:
164                 explicit SvIdlWorkingBase( const SvCommand& rCmd );
165 
166     sal_Bool        ReadSvIdl( SvTokenStream &, sal_Bool bImported, const String & rPath );
167     sal_Bool        WriteSvIdl( SvStream & );
168 
169     sal_Bool        WriteSfx( SvStream & );
170 	sal_Bool		WriteHelpIds( SvStream & );
171     sal_Bool        WriteSfxItem( SvStream & );
172 	sal_Bool 		WriteCSV( SvStream& );
173 	sal_Bool		WriteDocumentation( SvStream& );
174 };
175 #endif
176 
177 #endif // _DATABASE_HXX
178 
179