NCL Composer  0.1.5
 All Classes Functions Variables Pages
Singleton.h
1 /* Copyright (c) 2011 Telemidia/PUC-Rio.
2  * All rights reserved. This program and the accompanying materials
3  * are made available under the terms of the Eclipse Public License v1.0
4  * which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors:
8  * Telemidia/PUC-Rio - initial API and implementation
9  */
10 #ifndef __SINGLETON_HPP_
11 #define __SINGLETON_HPP_
12 
13 #include <QObject>
14 #include <QDebug>
15 
16 #include <assert.h>
17 
18 
19 #define SINGLETON(T) \
20 private: static T* m_pInstance; \
21 public: \
22 static T* getInstance(){ \
23  if(m_pInstance == NULL) return m_pInstance = new T(); \
24  return m_pInstance; \
25  } \
26 static void releaseInstance(){ \
27  if(m_pInstance != NULL) delete m_pInstance; \
28  m_pInstance = NULL; \
29  }
30 
31 #define INIT_SINGLETON(T) \
32  T* T::m_pInstance = NULL;
33 
34 #endif