Changeset e491159 for src/Common


Ignore:
Timestamp:
Aug 31, 2016, 11:20:03 AM (9 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1f75e2d
Parents:
bda58ad
Message:

Moved ScopedMap to Common folder

Location:
src/Common
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    rbda58ad re491159  
    1717#define _UTILITY_H
    1818
     19#include <cctype>
    1920#include <iostream>
     21#include <iterator>
     22#include <list>
     23#include <memory>
    2024#include <sstream>
    21 #include <iterator>
    2225#include <string>
    23 #include <cctype>
    24 #include <list>
    2526
    2627template< typename T >
     
    246247}
    247248
     249template< typename ThisType >
     250class RefCountSingleton {
     251  public:
     252        static std::shared_ptr<ThisType> get() {
     253                if( global_instance.expired() ) {
     254                        std::shared_ptr<ThisType> new_instance = std::make_shared<ThisType>();
     255                        global_instance = new_instance;
     256                        return std::move(new_instance);
     257                }
     258                return global_instance.lock();
     259        }
     260  private:
     261        static std::weak_ptr<ThisType> global_instance;
     262};
     263
    248264#endif // _UTILITY_H
    249265
Note: See TracChangeset for help on using the changeset viewer.