Changeset 44:b8711bbdd13e in rrlib_util


Ignore:
Timestamp:
24.01.2012 03:06:28 (8 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Added lifetime policy Longevity for ordered destruction of singletons

Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • make.xml

    r36 r44  
    2727    <sources> 
    2828      patterns/* 
    29       patterns/command/* 
    30       patterns/factory/* 
    31       patterns/singleton/* 
     29      patterns/command/** 
     30      patterns/factory/** 
     31      patterns/singleton/** 
    3232    </sources> 
    3333  </rrlib> 
  • patterns/singleton.h

    r34 r44  
    4242// Internal includes with "" 
    4343//---------------------------------------------------------------------- 
     44 
     45// default policies 
     46#include "rrlib/util/patterns/singleton/policies/creation/CreateUsingNew.h" 
     47#include "rrlib/util/patterns/singleton/policies/lifetime/DefaultLifetime.h" 
     48 
     49#include "rrlib/util/patterns/singleton/tSingletonHolder.h" 
     50 
     51// creation policies 
    4452#include "rrlib/util/patterns/singleton/policies/creation/CreateStatic.h" 
    45 #include "rrlib/util/patterns/singleton/policies/creation/CreateUsingNew.h" 
    4653#include "rrlib/util/patterns/singleton/policies/creation/CreateUsingMalloc.h" 
    4754 
    48 #include "rrlib/util/patterns/singleton/policies/lifetime/DefaultLifetime.h" 
     55// lifetime policies 
    4956#include "rrlib/util/patterns/singleton/policies/lifetime/PhoenixSingleton.h" 
    5057#include "rrlib/util/patterns/singleton/policies/lifetime/NoDestruction.h" 
    51  
    52 #include "rrlib/util/patterns/singleton/tSingletonHolder.h" 
     58#include "rrlib/util/patterns/singleton/policies/lifetime/Longevity.h" 
    5359 
    5460//---------------------------------------------------------------------- 
  • patterns/singleton/policies/lifetime/DefaultLifetime.h

    r37 r44  
    7474struct DefaultLifetime 
    7575{ 
    76   static void ScheduleDestruction(void (*function)()) 
     76  static void ScheduleDestruction(T *, void (*function)()) 
    7777  { 
    78     atexit(function); 
     78    std::atexit(function); 
    7979  } 
    8080  static void OnDeadReference() 
  • patterns/singleton/policies/lifetime/NoDestruction.h

    r34 r44  
    7373struct NoDestruction 
    7474{ 
    75   static void ScheduleDestruction(void (*function)()) 
     75  static void ScheduleDestruction(T *, void (*function)()) 
    7676  {} 
    7777  static void OnDeadReference() 
  • patterns/singleton/policies/lifetime/PhoenixSingleton.h

    r37 r44  
    7373struct PhoenixSingleton 
    7474{ 
    75   static void ScheduleDestruction(void (*function)()) 
     75  static void ScheduleDestruction(T *, void (*function)()) 
    7676  { 
    77     atexit(function); 
     77    std::atexit(function); 
    7878  } 
    7979  static void OnDeadReference() 
  • patterns/singleton/tSingletonHolder.h

    r43 r44  
    111111      } 
    112112      tSingletonHolder::InstancePointer() = TCreationPolicy<T>::Create(); 
    113       TLifetimePolicy<T>::ScheduleDestruction(&tSingletonHolder::DestroyInstance); 
     113      TLifetimePolicy<T>::ScheduleDestruction(tSingletonHolder::InstancePointer(), &tSingletonHolder::DestroyInstance); 
    114114    } 
    115115  } 
  • test/test_singleton_pattern.cpp

    r39 r44  
    7979  } 
    8080}; 
    81 typedef tSingletonHolder<tLogImplementation, singleton::PhoenixSingleton> tLog; 
     81//typedef tSingletonHolder<tLogImplementation, singleton::PhoenixSingleton> tLog; 
    8282//typedef tSingletonHolder<tLogImplementation, singleton::NoDestruction> tLog; 
     83typedef tSingletonHolder<tLogImplementation, singleton::Longevity> tLog; 
     84unsigned int GetLongevity(tLogImplementation *) 
     85{ 
     86  return 2; 
     87} 
    8388 
    8489struct tKeyboardImplementation 
     
    99104  }; 
    100105}; 
    101 typedef rrlib::util::tSingletonHolder<tKeyboardImplementation> tKeyboard; 
     106//typedef rrlib::util::tSingletonHolder<tKeyboardImplementation> tKeyboard; 
     107typedef rrlib::util::tSingletonHolder<tKeyboardImplementation, singleton::Longevity> tKeyboard; 
     108unsigned int GetLongevity(tKeyboardImplementation *) 
     109{ 
     110  return 1; 
     111} 
    102112 
    103113struct tDisplayImplementation 
     
    118128  }; 
    119129}; 
    120 typedef rrlib::util::tSingletonHolder<tDisplayImplementation> tDisplay; 
     130//typedef rrlib::util::tSingletonHolder<tDisplayImplementation> tDisplay; 
     131typedef rrlib::util::tSingletonHolder<tDisplayImplementation, singleton::Longevity> tDisplay; 
     132unsigned int GetLongevity(tDisplayImplementation *) 
     133{ 
     134  return 1; 
     135} 
    121136 
    122137int main(int argc, char **argv) 
Note: See TracChangeset for help on using the changeset viewer.