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 INCLUDED_CODEMAKER_SOURCE_IDLMAKER_IDLTYPE_HXX
25 #define INCLUDED_CODEMAKER_SOURCE_IDLMAKER_IDLTYPE_HXX
26 
27 #include	<codemaker/typemanager.hxx>
28 #include	<codemaker/dependency.hxx>
29 
30 enum BASETYPE
31 {
32 	BT_INVALID,
33 	BT_VOID,
34 	BT_ANY,
35 	BT_TYPE,
36 	BT_BOOLEAN,
37 	BT_CHAR,
38 	BT_STRING,
39 	BT_FLOAT,
40 	BT_DOUBLE,
41 	BT_OCTET,
42 	BT_BYTE,
43 	BT_SHORT,
44 	BT_LONG,
45 	BT_HYPER,
46 	BT_UNSIGNED_SHORT,
47 	BT_UNSIGNED_LONG,
48 	BT_UNSIGNED_HYPER
49 };
50 
51 
52 enum IdlTypeDecl
53 {
54 	CPPUTYPEDECL_ALLTYPES,
55 	CPPUTYPEDECL_NOINTERFACES,
56 	CPPUTYPEDECL_ONLYINTERFACES
57 };
58 
59 class IdlOptions;
60 class FileStream;
61 
62 class IdlType
63 {
64 public:
65 	IdlType(TypeReader& typeReader,
66 			 const ::rtl::OString& typeName,
67 			 const TypeManager& typeMgr,
68 			 const TypeDependency& typeDependencies);
69 
70 	virtual ~IdlType();
71 
72 	virtual sal_Bool dump(IdlOptions* pOptions) throw( CannotDumpException );
73 	virtual sal_Bool dumpDependedTypes(IdlOptions* pOptions)  throw( CannotDumpException );
74 	virtual sal_Bool dumpHFile(FileStream& o) throw( CannotDumpException ) = 0;
75 
76 	virtual ::rtl::OString dumpHeaderDefine(FileStream& o, sal_Char* prefix );
77 	virtual void dumpDefaultHIncludes(FileStream& o);
78 	virtual void dumpInclude(FileStream& o, const ::rtl::OString& genTypeName, const ::rtl::OString& typeName, sal_Char* prefix );
79 
80 	virtual void dumpDepIncludes(FileStream& o, const ::rtl::OString& typeName, sal_Char* prefix);
81 
82 	virtual void dumpNameSpace(FileStream& o, sal_Bool bOpen = sal_True, sal_Bool bFull = sal_False, const ::rtl::OString& type="");
83 
84 	virtual void dumpType(FileStream& o, const ::rtl::OString& type)
85 					throw( CannotDumpException );
86 	::rtl::OString	getBaseType(const ::rtl::OString& type);
87 	void	dumpIdlGetType(FileStream& o, const ::rtl::OString& type, sal_Bool bDecl=sal_False, IdlTypeDecl eDeclFlag=CPPUTYPEDECL_ALLTYPES);
88 	BASETYPE isBaseType(const ::rtl::OString& type);
89 
90 	void 	dumpConstantValue(FileStream& o, sal_uInt16 index);
91 
92 	virtual sal_uInt32  getMemberCount();
93 	virtual sal_uInt32	getInheritedMemberCount();
94 
95 	void 			inc(sal_uInt32 num=4);
96 	void 			dec(sal_uInt32 num=4);
97 	::rtl::OString 	indent();
98 	::rtl::OString	indent(sal_uInt32 num);
99 protected:
100 	virtual sal_uInt32	checkInheritedMemberCount(const TypeReader* pReader);
101 
102 	::rtl::OString	checkSpecialIdlType(const ::rtl::OString& type);
103 	::rtl::OString	checkRealBaseType(const ::rtl::OString& type, sal_Bool bResolveTypeOnly = sal_False);
104 
105 protected:
106 	sal_uInt32 			m_inheritedMemberCount;
107 
108 	sal_uInt32			m_indentLength;
109 	::rtl::OString		m_typeName;
110 	::rtl::OString		m_name;
111 	TypeReader			m_reader;
112 	TypeManager&		m_typeMgr;
113 	TypeDependency  	m_dependencies;
114 };
115 
116 class InterfaceType : public IdlType
117 {
118 public:
119 	InterfaceType(TypeReader& typeReader,
120 				 const ::rtl::OString& typeName,
121 				 const TypeManager& typeMgr,
122 				 const TypeDependency& typeDependencies);
123 
124 	virtual ~InterfaceType();
125 
126 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
127 
128 	void		dumpAttributes(FileStream& o);
129 	void		dumpMethods(FileStream& o);
130 
131 	sal_uInt32	getMemberCount();
132 	sal_uInt32	getInheritedMemberCount();
133 
134 protected:
135 	sal_uInt32	checkInheritedMemberCount(const TypeReader* pReader);
136 
137 protected:
138 	sal_uInt32 	m_inheritedMemberCount;
139 	sal_Bool 	m_hasAttributes;
140 	sal_Bool 	m_hasMethods;
141 };
142 
143 class ModuleType : public IdlType
144 {
145 public:
146 	ModuleType(TypeReader& typeReader,
147 		   	   const ::rtl::OString& typeName,
148 			   const TypeManager& typeMgr,
149 			   const TypeDependency& typeDependencies);
150 
151 	virtual ~ModuleType();
152 
153 	virtual sal_Bool 	dump(IdlOptions* pOptions) throw( CannotDumpException );
154 	sal_Bool			dumpHFile(FileStream& o) throw( CannotDumpException );
155 	sal_Bool			hasConstants();
156 };
157 
158 class ConstantsType : public ModuleType
159 {
160 public:
161 	ConstantsType(TypeReader& typeReader,
162 		   	   const ::rtl::OString& typeName,
163 			   const TypeManager& typeMgr,
164 			   const TypeDependency& typeDependencies);
165 
166 	virtual ~ConstantsType();
167 
168 	virtual sal_Bool 	dump(IdlOptions* pOptions) throw( CannotDumpException );
169 };
170 
171 class StructureType : public IdlType
172 {
173 public:
174 	StructureType(TypeReader& typeReader,
175 				  const ::rtl::OString& typeName,
176 				  const TypeManager& typeMgr,
177 				  const TypeDependency& typeDependencies);
178 
179 	virtual ~StructureType();
180 
181 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
182 
183 	void		dumpSuperMember(FileStream& o, const ::rtl::OString& super);
184 };
185 
186 class ExceptionType : public IdlType
187 {
188 public:
189 	ExceptionType(TypeReader& typeReader,
190 				  const ::rtl::OString& typeName,
191 				  const TypeManager& typeMgr,
192 				  const TypeDependency& typeDependencies);
193 
194 	virtual ~ExceptionType();
195 
196 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
197 
198 	void		dumpSuperMember(FileStream& o, const ::rtl::OString& super);
199 };
200 
201 class EnumType : public IdlType
202 {
203 public:
204 	EnumType(TypeReader& typeReader,
205 	 		 const ::rtl::OString& typeName,
206 	 		 const TypeManager& typeMgr,
207 	 		 const TypeDependency& typeDependencies);
208 
209 	virtual ~EnumType();
210 
211 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
212 };
213 
214 class TypeDefType : public IdlType
215 {
216 public:
217 	TypeDefType(TypeReader& typeReader,
218 	 		 const ::rtl::OString& typeName,
219 	 		 const TypeManager& typeMgr,
220 	 		 const TypeDependency& typeDependencies);
221 
222 	virtual ~TypeDefType();
223 
224 	sal_Bool	dumpHFile(FileStream& o) throw( CannotDumpException );
225 };
226 
227 
228 sal_Bool produceType(const ::rtl::OString& typeName,
229 					 TypeManager& typeMgr,
230 					 TypeDependency& typeDependencies,
231 					 IdlOptions* pOptions)
232 				 throw( CannotDumpException );
233 
234 /**
235  * This function returns a C++ scoped name, represents the namespace
236  * scoping of this type, e.g. com:.sun::star::uno::XInterface. If the scope of
237  * the type is equal scope, the relativ name will be used.
238  */
239 ::rtl::OString scopedName(const ::rtl::OString& scope, const ::rtl::OString& type, sal_Bool bNoNameSpace = sal_False );
240 
241 ::rtl::OString scope(const ::rtl::OString& scope, const ::rtl::OString& type );
242 
243 
244 #endif // INCLUDED_CODEMAKER_SOURCE_IDLMAKER_IDLTYPE_HXX
245 
246