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 _SOT_OBJECT_HXX 25 #define _SOT_OBJECT_HXX 26 27 #include <sot/sotref.hxx> 28 #ifndef _SOT_SOTDATA_HXX 29 #include <sot/sotdata.hxx> 30 #endif 31 #ifndef _TOOLS_GLOBNAME_HXX 32 #include <tools/globname.hxx> 33 #endif 34 #include "sot/sotdllapi.h" 35 36 /************************************************************************* 37 *************************************************************************/ 38 39 #define TEST_INVARIANT 40 #ifdef TEST_INVARIANT 41 #define SO2_DECL_INVARIANT() \ 42 virtual void TestObjRef( sal_Bool bFree ); \ 43 void TestMemberObjRef( sal_Bool bFree ); \ 44 virtual void TestInvariant( sal_Bool bPrint ); \ 45 void TestMemberInvariant( sal_Bool bPrint ); 46 47 #define SO2_IMPL_INVARIANT(ClassName) \ 48 void __EXPORT ClassName::TestObjRef( sal_Bool bFree ) \ 49 { \ 50 TestMemberObjRef( bFree ); \ 51 } \ 52 void __EXPORT ClassName::TestInvariant( sal_Bool bPrint ) \ 53 { \ 54 TestMemberInvariant( bPrint ); \ 55 } 56 57 #define SO2_IMPL_INVARIANT1(ClassName,Super1) \ 58 void __EXPORT ClassName::TestObjRef( sal_Bool bFree ) \ 59 { \ 60 TestMemberObjRef( bFree ); \ 61 Super1::TestObjRef( bFree ); \ 62 } \ 63 void __EXPORT ClassName::TestInvariant( sal_Bool bPrint ) \ 64 { \ 65 TestMemberInvariant( bPrint ); \ 66 Super1::TestInvariant( bPrint ); \ 67 } 68 69 #define SO2_IMPL_INVARIANT2(ClassName,Super1,Super2) \ 70 void __EXPORT ClassName::TestObjRef( sal_Bool bFree ) \ 71 { \ 72 TestMemberObjRef( bFree ); \ 73 Super1::TestObjRef( bFree ); \ 74 Super2::TestObjRef( bFree ); \ 75 } \ 76 void __EXPORT ClassName::TestInvariant( sal_Bool bPrint ) \ 77 { \ 78 TestMemberInvariant( bPrint ); \ 79 Super1::TestInvariant( bPrint ); \ 80 Super2::TestInvariant( bPrint ); \ 81 } 82 83 #define SO2_IMPL_INVARIANT3(ClassName,Super1,Super2,Super3) \ 84 void __EXPORT ClassName::TestObjRef( sal_Bool bFree ) \ 85 { \ 86 TestMemberObjRef( bFree ); \ 87 Super1::TestObjRef( bFree ); \ 88 Super2::TestObjRef( bFree ); \ 89 Super3::TestObjRef( bFree ); \ 90 } \ 91 void __EXPORT ClassName::TestInvariant( sal_Bool bPrint ) \ 92 { \ 93 TestMemberInvariant( bPrint ); \ 94 Super1::TestInvariant( bPrint ); \ 95 Super2::TestInvariant( bPrint ); \ 96 Super3::TestInvariant( bPrint ); \ 97 } 98 99 #define SO2_IMPL_INVARIANT4(ClassName,Super1,Super2,Super3,Super4) \ 100 void __EXPORT ClassName::TestObjRef( sal_Bool bFree ) \ 101 { \ 102 TestMemberObjRef( bFree ); \ 103 Super1::TestObjRef( bFree ); \ 104 Super2::TestObjRef( bFree ); \ 105 Super3::TestObjRef( bFree ); \ 106 Super4::TestObjRef( bFree ); \ 107 } \ 108 void __EXPORT ClassName::TestInvariant( sal_Bool bPrint ) \ 109 { \ 110 TestMemberInvariant( bPrint ); \ 111 Super1::TestInvariant( bPrint ); \ 112 Super2::TestInvariant( bPrint ); \ 113 Super3::TestInvariant( bPrint ); \ 114 Super4::TestInvariant( bPrint ); \ 115 } 116 117 #ifdef DBG_UTIL 118 #define CALL_TEST_INVARIANT() SotFactory::TestInvariant() 119 #else 120 #define CALL_TEST_INVARIANT() 121 #endif // DBG_UTIL 122 123 #else // TEST_INVARIANT 124 125 #define SO2_DECL_INVARIANT() 126 127 #define SO2_IMPL_INVARIANT(ClassName) 128 #define SO2_IMPL_INVARIANT1(ClassName,Super1) 129 #define SO2_IMPL_INVARIANT2(ClassName,Super1,Super2) 130 #define SO2_IMPL_INVARIANT3(ClassName,Super1,Super2,Super3) 131 #define SO2_IMPL_INVARIANT4(ClassName,Super1,Super2,Super3,Super4) 132 133 #define CALL_TEST_INVARIANT() 134 135 #endif // TEST_INVARIANT 136 137 /************************************************************************** 138 **************************************************************************/ 139 #define SO2_DECL_BASIC_CLASS_DLL(ClassName,FacName) \ 140 private: \ 141 static SotFactory ** GetFactoryAdress() \ 142 { return &(FacName->p##ClassName##Factory); } \ 143 public: \ 144 static void * CreateInstance( SotObject ** = NULL ); \ 145 static SotFactory * ClassFactory(); \ 146 virtual const SotFactory * GetSvFactory() const; \ 147 virtual void * Cast( const SotFactory * ); 148 149 #define SO2_DECL_BASIC_CLASS(ClassName) \ 150 private: \ 151 static SotFactory * pFactory; \ 152 static SotFactory ** GetFactoryAdress() { return &pFactory; } \ 153 public: \ 154 static void * CreateInstance( SotObject ** = NULL ); \ 155 static SotFactory * ClassFactory(); \ 156 virtual const SotFactory * GetSvFactory() const; \ 157 virtual void * Cast( const SotFactory * ); 158 159 /************************************************************************** 160 **************************************************************************/ 161 #define SO2_IMPL_BASIC_CLASS_DLL(ClassName,FactoryName,GlobalName) \ 162 SotFactory * ClassName::ClassFactory() \ 163 { \ 164 SotFactory **ppFactory = GetFactoryAdress(); \ 165 if( !*ppFactory ) \ 166 { \ 167 *ppFactory = new FactoryName( GlobalName, \ 168 String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( #ClassName ) ), \ 169 ClassName::CreateInstance ); \ 170 } \ 171 return *ppFactory; \ 172 } \ 173 void * __EXPORT ClassName::CreateInstance( SotObject ** ppObj ) \ 174 { \ 175 ClassName * p = new ClassName(); \ 176 if( ppObj ) \ 177 *ppObj = p; \ 178 return p; \ 179 } \ 180 const SotFactory * __EXPORT ClassName::GetSvFactory() const \ 181 { \ 182 return ClassFactory(); \ 183 } \ 184 void * __EXPORT ClassName::Cast( const SotFactory * pFact ) \ 185 { \ 186 void * pRet = NULL; \ 187 if( !pFact || pFact == ClassFactory() ) \ 188 pRet = this; \ 189 return pRet; \ 190 } 191 192 #define SO2_IMPL_BASIC_CLASS(ClassName,FactoryName,GlobalName) \ 193 SotFactory * ClassName::pFactory = NULL; \ 194 SO2_IMPL_BASIC_CLASS_DLL(ClassName,FactoryName,GlobalName) 195 196 /************************************************************************** 197 **************************************************************************/ 198 #define SO2_IMPL_BASIC_CLASS1_DLL(ClassName,FactoryName,Super1,GlobalName)\ 199 SotFactory * ClassName::ClassFactory() \ 200 { \ 201 SotFactory **ppFactory = GetFactoryAdress(); \ 202 if( !*ppFactory ) \ 203 { \ 204 *ppFactory = new FactoryName( GlobalName, \ 205 String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( #ClassName ) ), \ 206 ClassName::CreateInstance ); \ 207 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \ 208 } \ 209 return *ppFactory; \ 210 } \ 211 void * __EXPORT ClassName::CreateInstance( SotObject ** ppObj ) \ 212 { \ 213 ClassName * p = new ClassName(); \ 214 Super1* pSuper1 = p; \ 215 SotObject* pBasicObj = pSuper1; \ 216 if( ppObj ) \ 217 *ppObj = pBasicObj; \ 218 return p; \ 219 } \ 220 const SotFactory * __EXPORT ClassName::GetSvFactory() const \ 221 { \ 222 return ClassFactory(); \ 223 } \ 224 void * __EXPORT ClassName::Cast( const SotFactory * pFact ) \ 225 { \ 226 void * pRet = NULL; \ 227 if( !pFact || pFact == ClassFactory() ) \ 228 pRet = this; \ 229 if( !pRet ) \ 230 pRet = Super1::Cast( pFact ); \ 231 return pRet; \ 232 } 233 234 #define SO2_IMPL_BASIC_CLASS1(ClassName,FactoryName,Super1,GlobalName) \ 235 SotFactory * ClassName::pFactory = NULL; \ 236 SO2_IMPL_BASIC_CLASS1_DLL(ClassName,FactoryName,Super1,GlobalName) 237 238 /************************************************************************** 239 **************************************************************************/ 240 #define SO2_IMPL_BASIC_CLASS2_DLL(ClassName,FactoryName,Super1,Super2,GlobalName) \ 241 SotFactory * ClassName::ClassFactory() \ 242 { \ 243 SotFactory **ppFactory = GetFactoryAdress(); \ 244 if( !*ppFactory ) \ 245 { \ 246 *ppFactory = new FactoryName( GlobalName, \ 247 String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( #ClassName ) ), \ 248 ClassName::CreateInstance ); \ 249 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \ 250 (*ppFactory)->PutSuperClass( Super2::ClassFactory() ); \ 251 } \ 252 return *ppFactory; \ 253 } \ 254 void * __EXPORT ClassName::CreateInstance( SotObject ** ppObj ) \ 255 { \ 256 ClassName * p = new ClassName(); \ 257 if( ppObj ) \ 258 *ppObj = p; \ 259 return p; \ 260 } \ 261 const SotFactory * __EXPORT ClassName::GetSvFactory() const \ 262 { \ 263 return ClassFactory(); \ 264 } \ 265 void * __EXPORT ClassName::Cast( const SotFactory * pFact ) \ 266 { \ 267 void * pRet = NULL; \ 268 if( !pFact || pFact == ClassFactory() ) \ 269 pRet = this; \ 270 if( !pRet ) \ 271 pRet = Super1::Cast( pFact ); \ 272 if( !pRet ) \ 273 pRet = Super2::Cast( pFact ); \ 274 return pRet; \ 275 } 276 #define SO2_IMPL_BASIC_CLASS2(ClassName,FactoryName,Super1,Super2,GlobalName) \ 277 SotFactory * ClassName::pFactory = NULL; \ 278 SO2_IMPL_BASIC_CLASS2_DLL(ClassName,FactoryName,Super1,Super2,GlobalName) 279 280 /************************************************************************** 281 **************************************************************************/ 282 #define SO2_IMPL_BASIC_CLASS3_DLL(ClassName,FactoryName,Super1,Super2,Super3,GlobalName) \ 283 SotFactory * ClassName::ClassFactory() \ 284 { \ 285 SotFactory **ppFactory = GetFactoryAdress(); \ 286 if( !*ppFactory ) \ 287 { \ 288 *ppFactory = new FactoryName( GlobalName, \ 289 String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( #ClassName ) ), \ 290 ClassName::CreateInstance );\ 291 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \ 292 (*ppFactory)->PutSuperClass( Super2::ClassFactory() ); \ 293 (*ppFactory)->PutSuperClass( Super3::ClassFactory() ); \ 294 } \ 295 return *pFactory; \ 296 } \ 297 void * __EXPORT ClassName::CreateInstance( SotObject ** ppObj ) \ 298 { \ 299 ClassName * p = new ClassName(); \ 300 if( ppObj ) \ 301 *ppObj = p; \ 302 return p; \ 303 } \ 304 const SotFactory * __EXPORT ClassName::GetSvFactory() const \ 305 { \ 306 return ClassFactory(); \ 307 } \ 308 void * __EXPORT ClassName::Cast( const SotFactory * pFact ) \ 309 { \ 310 void * pRet = NULL; \ 311 if( !pFact || pFact == ClassFactory() ) \ 312 pRet = this; \ 313 if( !pRet ) \ 314 pRet = Super1::Cast( pFact ); \ 315 if( !pRet ) \ 316 pRet = Super2::Cast( pFact ); \ 317 if( !pRet ) \ 318 pRet = Super3::Cast( pFact ); \ 319 return pRet; \ 320 } 321 322 #define SO2_IMPL_BASIC_CLASS3(ClassName,FactoryName,Super1,Super2,Super3,GlobalName) \ 323 SotFactory * ClassName::pFactory = NULL; \ 324 SO2_IMPL_BASIC_CLASS3_DLL(ClassName,FactoryName,Super1,Super2,Super3,GlobalName) 325 326 /************************************************************************** 327 **************************************************************************/ 328 #define SO2_IMPL_BASIC_CLASS4_DLL(ClassName,FactoryName,Super1,Super2,Super3,Super4,GlobalName) \ 329 SotFactory * ClassName::ClassFactory() \ 330 { \ 331 SotFactory **ppFactory = GetFactoryAdress(); \ 332 if( !*ppFactory ) \ 333 { \ 334 *ppFactory = new SotFactory( GlobalName, \ 335 String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( #ClassName ) ), \ 336 ClassName::CreateInstance );\ 337 (*ppFactory)->PutSuperClass( Super1::ClassFactory() ); \ 338 (*ppFactory)->PutSuperClass( Super2::ClassFactory() ); \ 339 (*ppFactory)->PutSuperClass( Super3::ClassFactory() ); \ 340 (*ppFactory)->PutSuperClass( Super4::ClassFactory() ); \ 341 } \ 342 return *ppFactory; \ 343 } \ 344 void * __EXPORT ClassName::CreateInstance( SotObject ** ppObj ) \ 345 { \ 346 ClassName * p = new ClassName(); \ 347 if( ppObj ) \ 348 *ppObj = p; \ 349 return p; \ 350 } \ 351 const SotFactory * __EXPORT ClassName::GetSvFactory() const \ 352 { \ 353 return ClassFactory(); \ 354 } \ 355 void * __EXPORT ClassName::Cast( const SotFactory * pFact ) \ 356 { \ 357 void * pRet = NULL; \ 358 if( !pFact || pFact == ClassFactory() ) \ 359 pRet = this; \ 360 if( !pRet ) \ 361 pRet = Super1::Cast( pFact ); \ 362 if( !pRet ) \ 363 pRet = Super2::Cast( pFact ); \ 364 if( !pRet ) \ 365 pRet = Super3::Cast( pFact ); \ 366 if( !pRet ) \ 367 pRet = Super4::Cast( pFact ); \ 368 return pRet; \ 369 } 370 371 #define SO2_IMPL_BASIC_CLASS4(ClassName,FactoryName,Super1,Super2,Super3,Super4,GlobalName) \ 372 SotFactory * ClassName::pFactory = NULL; \ 373 SO2_IMPL_BASIC_CLASS4_DLL(ClassName,FactoryName,Super1,Super2,Super3,Super4,GlobalName) 374 375 //==================class SotObject======================================== 376 #ifdef _MSC_VER 377 #pragma warning(disable: 4250) 378 #endif 379 380 struct IUnknown; 381 class SOT_DLLPUBLIC SotObject : virtual public SvRefBase 382 { 383 friend class SotFactory; 384 friend class SvObject; 385 sal_uInt16 nStrongLockCount; 386 sal_uInt16 nOwnerLockCount; 387 sal_Bool bOwner:1, 388 bSVObject:1, // Ist Proxy, dann TRUE wenn andere Seite SV ist 389 bInClose:1; // TRUE, im DoClose 390 391 #if defined (GCC) && (defined (C281) || defined (C290) || defined (C291)) 392 public: 393 #else 394 protected: 395 #endif 396 virtual ~SotObject(); SetExtern()397 void SetExtern() { bOwner = sal_False; } 398 virtual sal_Bool Close(); 399 public: 400 SotObject(); 401 SO2_DECL_BASIC_CLASS_DLL(SotObject,SOTDATA()) 402 SO2_DECL_INVARIANT() 403 404 // Nur damit die Makros in So3 nicht ganz ausufern 405 virtual IUnknown * GetInterface( const SvGlobalName & ); 406 Owner() const407 sal_Bool Owner() const { return bOwner; } 408 409 void* CastAndAddRef( const SotFactory * pFact ); 410 411 sal_uInt16 Lock( sal_Bool bLock ); // affects nStrongLockCount GetOwnerLockCount() const412 sal_uInt16 GetOwnerLockCount() const { return nOwnerLockCount; } GetStrongLockCount() const413 sal_uInt16 GetStrongLockCount() const { return nStrongLockCount; } 414 415 void OwnerLock( sal_Bool bLock ); 416 void RemoveOwnerLock(); 417 sal_Bool DoClose(); IsInClose() const418 sal_Bool IsInClose() const { return bInClose; } 419 420 private: 421 // Kopieren und Zuweisen dieses Objekttyps ist nicht erlaubt 422 SOT_DLLPRIVATE SotObject & operator = ( const SotObject & ); 423 SOT_DLLPRIVATE SotObject( const SotObject & ); 424 }; 425 426 //==================class SotObjectRef====================================== 427 SV_IMPL_REF(SotObject) 428 429 //==================class SotObject*List==================================== 430 SV_DECL_REF_LIST(SotObject,SotObject*) 431 SV_IMPL_REF_LIST(SotObject,SotObject*) 432 433 #endif // _IFACE_HXX 434 435