Ignore:
Timestamp:
Jul 30, 2015, 8:47:36 PM (10 years ago)
Author:
Frederik Heber <heber@…>
Children:
1b5188
Parents:
73ab25
git-author:
Frederik Heber <heber@…> (06/01/15 08:23:04)
git-committer:
Frederik Heber <heber@…> (07/30/15 20:47:36)
Message:

Added Singleton:getConstInstance() and ..Pointer() functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodePatterns/Singleton_impl.hpp

    r73ab25 r163eec  
    3838
    3939template <class T,bool _may_create>
     40const T& Singleton<T,_may_create>::getConstInstance(){
     41  // boost supports RAII-Style locking, so we don't need to unlock
     42  boost::recursive_mutex::scoped_lock guard(instanceLock);
     43  if(!theInstance.get()) {
     44    theInstance.reset(creator::make());
     45  }
     46  return *theInstance;
     47}
     48
     49template <class T,bool _may_create>
    4050T* Singleton<T,_may_create>::getPointer(){
     51  // boost supports RAII-Style locking, so we don't need to unlock
     52  boost::recursive_mutex::scoped_lock guard(instanceLock);
     53  if(!theInstance.get()) {
     54    theInstance.reset(creator::make());
     55  }
     56  return theInstance.get();
     57
     58}
     59
     60template <class T,bool _may_create>
     61const T* Singleton<T,_may_create>::getConstPointer(){
    4162  // boost supports RAII-Style locking, so we don't need to unlock
    4263  boost::recursive_mutex::scoped_lock guard(instanceLock);
     
    98119#define CONSTRUCT_SINGLETON(name) \
    99120    template name& Singleton< name , name::may_create >::getInstance(); \
     121    template const name& Singleton< name , name::may_create >::getConstInstance(); \
    100122    template name* Singleton< name , name::may_create >::getPointer();  \
     123    template const name* Singleton< name , name::may_create >::getConstPointer();  \
    101124    template void  Singleton< name , name::may_create >::purgeInstance(); \
    102125    template name& Singleton< name , name::may_create >::resetInstance(); \
Note: See TracChangeset for help on using the changeset viewer.