Changeset 1687
- Timestamp:
- Aug 31, 2008, 5:37:56 PM (16 years ago)
- Location:
- code/branches/core3/src/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/core/Identifier.h
r1685 r1687 319 319 ClassIdentifier() 320 320 { 321 #define SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE 322 #include "Super.h" 321 SuperFunctionInitialization<0, T>::initialize(this); 323 322 } 324 323 ~ClassIdentifier() 325 324 { 326 #define SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE 327 #include "Super.h" 325 SuperFunctionDestruction<0, T>::destroy(this); 328 326 } 329 327 -
code/branches/core3/src/core/Super.h
r1685 r1687 39 39 classes that have an Identifier. Arguments however are supported. 40 40 41 To add a new super-function, you have process 6steps:41 To add a new super-function, you have process 4 steps: 42 42 43 43 1) Add a new SUPER macro 44 44 This allows you to call the super-function in your code. 45 Location: This file (Super.h), marked with --> HERE <-- comments (1/ 5)45 Location: This file (Super.h), marked with --> HERE <-- comments (1/3) 46 46 47 47 2) Call the SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros. 48 48 This defines some global classes and templates, needed to create and call the super-functions. 49 Location: This file (Super.h), marked with --> HERE <-- comments (2/ 5)49 Location: This file (Super.h), marked with --> HERE <-- comments (2/3) 50 50 51 51 3) Call the SUPER_INTRUSIVE_DECLARATION macro. 52 52 This will be included into the declaration of ClassIdentifier<T>. 53 Location: This file (Super.h), marked with --> HERE <-- comments (3/5) 54 55 4) Call the SUPER_INTRUSIVE_CONSTRUCTOR macro. 56 This will be included into the constructor of ClassIdentifier<T>. 57 Location: This file (Super.h), marked with --> HERE <-- comments (4/5) 58 59 5) Call the SUPER_INTRUSIVE_DESTRUCTOR macro. 60 This will be included into the destructor of ClassIdentifier<T>. 61 Location: This file (Super.h), marked with --> HERE <-- comments (5/5) 62 63 6) Call the SUPER_FUNCTION macro. 53 Location: This file (Super.h), marked with --> HERE <-- comments (3/3) 54 55 4) Call the SUPER_FUNCTION macro. 64 56 This defines a partially specialized template that will decide if a class is "super" to another class. 65 57 If the check returns true, a SuperFunctionCaller gets created, which will be used by the SUPER macro. … … 225 217 */ 226 218 227 // (1/ 5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--219 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 228 220 #define SUPER_testfunction(classname, functionname, ...) \ 229 221 SUPER_NOARGS(classname, functionname) … … 240 232 #define SUPER_changedVisibility(classname, functionname, ...) \ 241 233 SUPER_NOARGS(classname, functionname) 242 // (1/ 5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--234 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 243 235 244 236 … … 251 243 //// Common code //// 252 244 253 // Base template 245 // Base templates 246 /** 247 @brief Creates the SuperFunctionCaller if T is a child of the super-functions baseclass. 248 */ 254 249 template <int functionnumber, class T, int templatehack1, int templatehack2> 255 250 struct SuperFunctionCondition 256 251 { 257 252 static void check() {} 253 }; 254 255 /** 256 @brief Initializes the SuperFunctionCaller-pointer with zero. 257 */ 258 template <int functionnumber, class T> 259 struct SuperFunctionInitialization 260 { 261 static void initialize(ClassIdentifier<T>* identifier) {} 262 }; 263 264 /** 265 @brief Deletes the SuperFunctionCaller. 266 */ 267 template <int functionnumber, class T> 268 struct SuperFunctionDestruction 269 { 270 static void destroy(ClassIdentifier<T>* identifier) {} 258 271 }; 259 272 … … 275 288 { \ 276 289 SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); \ 290 } \ 291 }; \ 292 \ 293 template <class T> \ 294 struct SuperFunctionInitialization<functionnumber, T> \ 295 { \ 296 static void initialize(ClassIdentifier<T>* identifier) \ 297 { \ 298 identifier->superFunctionCaller_##functionname##_ = 0; \ 299 SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \ 300 } \ 301 }; \ 302 \ 303 template <class T> \ 304 struct SuperFunctionDestruction<functionnumber, T> \ 305 { \ 306 static void destroy(ClassIdentifier<T>* identifier) \ 307 { \ 308 if (identifier->superFunctionCaller_##functionname##_) \ 309 delete identifier->superFunctionCaller_##functionname##_; \ 310 SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); \ 277 311 } \ 278 312 }; \ … … 328 362 // Calls the condition-check of the next super-function (functionnumber + 1) 329 363 SuperFunctionCondition<functionnumber + 1, T, templatehack1, templatehack2>::check(); 364 } 365 }; 366 367 // Initializes the SuperFunctionCaller-pointer with zero. 368 template <class T> 369 struct SuperFunctionInitialization<functionnumber, T> 370 { 371 static void initialize(ClassIdentifier<T>* identifier) 372 { 373 identifier->superFunctionCaller_##functionname##_ = 0; 374 375 // Calls the initialization of the next super-function (functionnumber + 1) 376 SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); 377 } 378 }; 379 380 // Deletes the SuperFunctionCaller. 381 template <class T> 382 struct SuperFunctionDestruction<functionnumber, T> 383 { 384 static void destroy(ClassIdentifier<T>* identifier) 385 { 386 if (identifier->superFunctionCaller_##functionname##_) 387 delete identifier->superFunctionCaller_##functionname##_; 388 389 // Calls the destruction of the next super-function (functionnumber + 1) 390 SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); 330 391 } 331 392 }; … … 356 417 */ 357 418 419 358 420 //// Execute the code for each super-function //// 359 // (2/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 421 422 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 360 423 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(0, testfunction, false) 361 424 () … … 377 440 () 378 441 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 379 // (2/ 5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--442 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 380 443 381 444 } … … 391 454 392 455 private: 456 393 457 template <int functionnumber, class TT, int templatehack1, int templatehack2> 394 458 friend struct SuperFunctionCondition; … … 416 480 417 481 //// Execute the code for each super-function //// 418 // (3/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 482 483 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 419 484 SUPER_INTRUSIVE_DECLARATION(testfunction); 420 485 SUPER_INTRUSIVE_DECLARATION(XMLPort); … … 422 487 SUPER_INTRUSIVE_DECLARATION(changedActivity); 423 488 SUPER_INTRUSIVE_DECLARATION(changedVisibility); 424 // (3/ 5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--489 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 425 490 426 491 427 492 #undef SUPER_INTRUSIVE_DECLARATION_INCLUDE 428 493 #endif /* SUPER_INTRUSIVE_DECLARATION_INCLUDE */ 429 430 #ifdef SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE431 432 //////////////////////////////////////////////////////////////////////////433 // This code gets included inside the constructor of ClassIdentifier<T> //434 //////////////////////////////////////////////////////////////////////////435 436 // Function-specific code //437 438 /**439 @brief Initializes the SuperFunctionCaller pointer with zero.440 @param functionname The name of the super-function441 */442 #ifndef SUPER_INTRUSIVE_CONSTRUCTOR443 #define SUPER_INTRUSIVE_CONSTRUCTOR(functionname) \444 this->superFunctionCaller_##functionname##_ = 0445 #endif446 447 448 //// Execute the code for each super-function ////449 // (4/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--450 SUPER_INTRUSIVE_CONSTRUCTOR(testfunction);451 SUPER_INTRUSIVE_CONSTRUCTOR(XMLPort);452 SUPER_INTRUSIVE_CONSTRUCTOR(tick);453 SUPER_INTRUSIVE_CONSTRUCTOR(changedActivity);454 SUPER_INTRUSIVE_CONSTRUCTOR(changedVisibility);455 // (4/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--456 457 #undef SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE458 #endif /* SUPER_INTRUSIVE_CONSTRUCTOR_INCLUDE */459 460 #ifdef SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE461 462 /////////////////////////////////////////////////////////////////////////463 // This code gets included inside the destructor of ClassIdentifier<T> //464 /////////////////////////////////////////////////////////////////////////465 466 // Function-specific code //467 468 /**469 @brief Deletes the SuperFunctionCaller.470 @param functionname The name of the super-function471 */472 #ifndef SUPER_INTRUSIVE_DESTRUCTOR473 #define SUPER_INTRUSIVE_DESTRUCTOR(functionname) \474 if (this->superFunctionCaller_##functionname##_) \475 delete this->superFunctionCaller_##functionname##_476 #endif477 478 479 //// Execute the code for each super-function ////480 // (5/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--481 SUPER_INTRUSIVE_DESTRUCTOR(testfunction);482 SUPER_INTRUSIVE_DESTRUCTOR(XMLPort);483 SUPER_INTRUSIVE_DESTRUCTOR(tick);484 SUPER_INTRUSIVE_DESTRUCTOR(changedActivity);485 SUPER_INTRUSIVE_DESTRUCTOR(changedVisibility);486 // (5/5) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--487 488 #undef SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE489 #endif /* SUPER_INTRUSIVE_DESTRUCTOR_INCLUDE */490 494 #endif /* _Super_H__ */
Note: See TracChangeset
for help on using the changeset viewer.