root/trunk/src/framework/Policies/Singleton.h @ 102

Revision 102, 1.8 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef TRINITY_SINGLETON_H
22#define TRINITY_SINGLETON_H
23
24/**
25 * @brief class Singleton
26 */
27
28#include "CreationPolicy.h"
29#include "ThreadingModel.h"
30#include "ObjectLifeTime.h"
31
32namespace Trinity
33{
34    template
35        <
36        typename T,
37        class ThreadingModel = Trinity::SingleThreaded<T>,
38        class CreatePolicy = Trinity::OperatorNew<T>,
39        class LifeTimePolicy = Trinity::ObjectLifeTime<T>
40        >
41        class TRINITY_DLL_DECL Singleton
42    {
43        public:
44            static T& Instance();
45
46        protected:
47            Singleton() {};
48
49        private:
50
51            // Prohibited actions...this does not prevent hijacking.
52            Singleton(const Singleton &);
53            Singleton& operator=(const Singleton &);
54
55            // Singleton Helpers
56            static void DestroySingleton();
57
58            // data structure
59            typedef typename ThreadingModel::Lock Guard;
60            static T *si_instance;
61            static bool si_destroyed;
62    };
63}
64#endif
Note: See TracBrowser for help on using the browser.