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