20 lines
		
	
	
		
			383 B
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			20 lines
		
	
	
		
			383 B
		
	
	
	
		
			C
		
	
	
	
	
	
| 
								 | 
							
								#pragma once
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								template <typename T>
							 | 
						||
| 
								 | 
							
								class Singleton {
							 | 
						||
| 
								 | 
							
								protected:
							 | 
						||
| 
								 | 
							
								    static T* ms_Singleton;
							 | 
						||
| 
								 | 
							
								public:
							 | 
						||
| 
								 | 
							
								    explicit Singleton() {
							 | 
						||
| 
								 | 
							
								        ms_Singleton = static_cast<T*>(this);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    ~Singleton() {
							 | 
						||
| 
								 | 
							
								        ms_Singleton = nullptr;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    static T& GetSingleton(void) {
							 | 
						||
| 
								 | 
							
								        return *ms_Singleton;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    static T* GetSingletonPtr(void) {
							 | 
						||
| 
								 | 
							
								        return ms_Singleton;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								};
							 |