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 _CORBAMAKER_CPPUTYPE_HXX_ 25 #define _CORBAMAKER_CPPUTYPE_HXX_ 26 27 #include <codemaker/typemanager.hxx> 28 #include <codemaker/dependency.hxx> 29 30 #include <hash_set> 31 32 enum BASETYPE 33 { 34 BT_INVALID, 35 BT_VOID, 36 BT_ANY, 37 BT_TYPE, 38 BT_BOOLEAN, 39 BT_CHAR, 40 BT_STRING, 41 BT_FLOAT, 42 BT_DOUBLE, 43 BT_OCTET, 44 BT_BYTE, 45 BT_SHORT, 46 BT_LONG, 47 BT_HYPER, 48 BT_UNSIGNED_SHORT, 49 BT_UNSIGNED_LONG, 50 BT_UNSIGNED_HYPER 51 }; 52 53 54 class CorbaOptions; 55 class FileStream; 56 57 struct OStringEqual 58 { operator ()OStringEqual59 sal_Bool operator() (const ::rtl::OString& lhs, const ::rtl::OString& rhs) const 60 { return lhs.equals( rhs );} 61 }; 62 63 struct OStringHash : public std::unary_function< const ::rtl::OString &, size_t > 64 { operator ()OStringHash65 size_t operator()( const ::rtl::OString & rStr ) const 66 { return rStr.hashCode(); } 67 }; 68 69 typedef std::hash_set< ::rtl::OString, OStringHash, OStringEqual > TypeSet; 70 71 class CorbaType 72 { 73 public: 74 CorbaType(TypeReader& typeReader, 75 const ::rtl::OString& typeName, 76 const TypeManager& typeMgr, 77 const TypeDependency& typeDependencies, 78 TypeSet* generatedConversion); 79 80 virtual ~CorbaType(); 81 82 virtual sal_Bool dump(CorbaOptions* pOptions, FileStream& o, TypeSet* allreadyDumped) throw( CannotDumpException ); 83 virtual sal_Bool dumpDependedTypes(CorbaOptions* pOptions, FileStream& o, TypeSet* allreadyDumped) throw( CannotDumpException ); 84 virtual sal_Bool dumpConversionFunctions(FileStream& o, TypeSet* allreadyDumped) throw( CannotDumpException ); 85 86 static void dumpDefaultHxxIncludes(FileStream& o); 87 88 virtual void dumpInclude(FileStream& o, TypeSet* allreadyDumped, const ::rtl::OString& typeName, sal_Char* prefix, sal_Bool bExtended=sal_False, sal_Bool bCaseSensitive=sal_False); 89 virtual void dumpDepIncludes(FileStream& o, TypeSet* allreadyDumped, const ::rtl::OString& typeName, sal_Char* prefix); 90 91 virtual void dumpNameSpace(FileStream& o, sal_Bool bOpen = sal_True, sal_Bool bFull = sal_False, const ::rtl::OString& type=""); 92 virtual void dumpFunctions(FileStream& o) = 0; 93 94 virtual ::rtl::OString printUnoType( const ::rtl::OString& type, 95 sal_Bool bConst=sal_False, 96 sal_Bool bRef=sal_False, 97 sal_Bool bNative=sal_False) 98 throw( CannotDumpException ); 99 100 virtual void dumpUnoType(FileStream& o, 101 const ::rtl::OString& type, 102 sal_Bool bConst=sal_False, 103 sal_Bool bRef=sal_False, 104 sal_Bool bNative=sal_False) 105 throw( CannotDumpException ); 106 107 virtual ::rtl::OString printCorbaType(const ::rtl::OString& type, 108 sal_Bool bConst, 109 sal_Bool bRef) 110 throw( CannotDumpException ); 111 112 virtual void dumpCorbaType(FileStream& o, 113 const ::rtl::OString& type, 114 sal_Bool bConst=sal_False, 115 sal_Bool bRef=sal_False) 116 throw( CannotDumpException ); 117 118 sal_Bool isPassedAsPointer(const ::rtl::OString& type); 119 sal_Bool isArray(const ::rtl::OString& type); 120 121 sal_Bool isDerivedFromUnknown(const ::rtl::OString& typeName); 122 123 124 ::rtl::OString printCorbaParameter(const ::rtl::OString& type, 125 sal_Bool bOut = sal_False) 126 throw( CannotDumpException ); 127 128 ::rtl::OString getTypeClass(const ::rtl::OString& type="", 129 sal_Bool bCStyle=sal_False); 130 ::rtl::OString getUnoBaseType(const ::rtl::OString& type); 131 ::rtl::OString getCorbaBaseType(const ::rtl::OString& type); 132 133 void dumpTypeInit(FileStream& o, const ::rtl::OString& type); 134 BASETYPE isBaseType(const ::rtl::OString& type); 135 136 ::rtl::OString typeToIdentifier(const ::rtl::OString& type); 137 138 virtual sal_uInt32 getMemberCount(); 139 virtual sal_uInt32 getInheritedMemberCount(); 140 141 sal_Bool isNestedTypeByName(const ::rtl::OString& type); 142 143 void inc(sal_uInt32 num=4); 144 void dec(sal_uInt32 num=4); 145 ::rtl::OString indent(); 146 ::rtl::OString indent(sal_uInt32 num); 147 protected: 148 virtual sal_uInt32 checkInheritedMemberCount(const TypeReader* pReader); 149 150 ::rtl::OString checkSpecialCorbaType(const ::rtl::OString& type); 151 ::rtl::OString checkRealBaseType(const ::rtl::OString& type, sal_Bool bResolveTypeOnly = sal_False); 152 153 protected: 154 sal_uInt32 m_inheritedMemberCount; 155 sal_uInt32 m_indentLength; 156 ::rtl::OString m_typeName; 157 ::rtl::OString m_name; 158 TypeReader m_reader; 159 TypeManager& m_typeMgr; 160 TypeDependency m_dependencies; 161 TypeSet* m_generatedConversions; 162 }; 163 164 class InterfaceType : public CorbaType 165 { 166 public: 167 InterfaceType(TypeReader& typeReader, 168 const ::rtl::OString& typeName, 169 const TypeManager& typeMgr, 170 const TypeDependency& typeDependencies, 171 TypeSet* generatedConversion); 172 173 virtual ~InterfaceType(); 174 175 void dumpFunctions(FileStream& o); 176 177 void dumpUnoMethods(FileStream& o, sal_Bool bDeclOnly, sal_Bool bDelegateToSuper); 178 void dumpCorbaMethods(FileStream& o, sal_Bool bDeclOnly); 179 180 sal_uInt32 getMemberCount(); 181 sal_uInt32 getInheritedMemberCount(); 182 183 protected: 184 sal_uInt32 checkInheritedMemberCount(const TypeReader* pReader); 185 186 protected: 187 sal_uInt32 m_inheritedMemberCount; 188 sal_Bool m_hasAttributes; 189 sal_Bool m_hasMethods; 190 }; 191 192 class ModuleType : public CorbaType 193 { 194 public: 195 ModuleType(TypeReader& typeReader, 196 const ::rtl::OString& typeName, 197 const TypeManager& typeMgr, 198 const TypeDependency& typeDependencies, 199 TypeSet* generatedConversion); 200 201 virtual ~ModuleType(); 202 203 sal_Bool dumpConversionFunctions(FileStream& o, TypeSet* allreadyDumped) throw( CannotDumpException ); 204 void dumpFunctions(FileStream& o); 205 sal_Bool hasConstants(); 206 }; 207 208 class ConstantsType : public ModuleType 209 { 210 public: 211 ConstantsType(TypeReader& typeReader, 212 const ::rtl::OString& typeName, 213 const TypeManager& typeMgr, 214 const TypeDependency& typeDependencies, 215 TypeSet* generatedConversion); 216 217 virtual ~ConstantsType(); 218 219 void dumpFunctions(FileStream& o); 220 }; 221 222 class StructureType : public CorbaType 223 { 224 public: 225 StructureType(TypeReader& typeReader, 226 const ::rtl::OString& typeName, 227 const TypeManager& typeMgr, 228 const TypeDependency& typeDependencies, 229 TypeSet* generatedConversion); 230 231 virtual ~StructureType(); 232 233 void dumpFunctions(FileStream& o); 234 235 sal_Bool dumpSuperMember(FileStream& o, const ::rtl::OString& super, sal_Bool bWithType); 236 }; 237 238 class ExceptionType : public CorbaType 239 { 240 public: 241 ExceptionType(TypeReader& typeReader, 242 const ::rtl::OString& typeName, 243 const TypeManager& typeMgr, 244 const TypeDependency& typeDependencies, 245 TypeSet* generatedConversions); 246 247 virtual ~ExceptionType(); 248 249 void dumpFunctions(FileStream& o); 250 251 sal_Bool dumpSuperMember(FileStream& o, const ::rtl::OString& super, sal_Bool bWithType); 252 }; 253 254 class EnumType : public CorbaType 255 { 256 public: 257 EnumType(TypeReader& typeReader, 258 const ::rtl::OString& typeName, 259 const TypeManager& typeMgr, 260 const TypeDependency& typeDependencies, 261 TypeSet* generatedConversion); 262 263 virtual ~EnumType(); 264 265 void dumpFunctions(FileStream& o); 266 }; 267 268 class TypeDefType : public CorbaType 269 { 270 public: 271 TypeDefType(TypeReader& typeReader, 272 const ::rtl::OString& typeName, 273 const TypeManager& typeMgr, 274 const TypeDependency& typeDependencies, 275 TypeSet* generatedConversion); 276 277 virtual ~TypeDefType(); 278 279 void dumpFunctions(FileStream& o); 280 }; 281 282 283 sal_Bool produceType(const ::rtl::OString& typeName, 284 TypeManager& typeMgr, 285 TypeDependency& typeDependencies, 286 CorbaOptions* pOptions, 287 FileStream& o, TypeSet* allreadyDumped, 288 TypeSet* generatedConversions) 289 throw( CannotDumpException ); 290 291 /** 292 * This function returns a C++ scoped name, represents the namespace 293 * scoping of this type, e.g. com:.sun::star::uno::XInterface. If the scope of 294 * the type is equal scope, the relativ name will be used. 295 */ 296 ::rtl::OString scopedName(const ::rtl::OString& scope, 297 const ::rtl::OString& type, 298 sal_Bool bNoNameSpace=sal_False); 299 300 ::rtl::OString shortScopedName(const ::rtl::OString& scope, 301 const ::rtl::OString& type, 302 sal_Bool bNoNameSpace=sal_False); 303 304 305 #endif // _CORBAMAKER_CPPUTYPE_HXX_ 306 307