JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
Singleton.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18// This file has been modified / imported from the Neuromorphic Robotics Toolkit (NRT). Original copyright is:
19
20/* author Randolph Voorhies
21 copyright GNU Public License (GPL v3)
22 // ////////////////////////////////////////////////////////////////////////
23 // The iLab Neuromorphic Robotics Toolkit (NRT) //
24 // Copyright 2010-2012 by the University of Southern California (USC) //
25 // and the iLab at USC. //
26 // //
27 // iLab - University of Southern California //
28 // Hedco Neurociences Building, Room HNB-10 //
29 // Los Angeles, Ca 90089-2520 - USA //
30 // //
31 // See http://ilab.usc.edu for information about this project. //
32 // ////////////////////////////////////////////////////////////////////////
33 // This file is part of The iLab Neuromorphic Robotics Toolkit. //
34 // //
35 // The iLab Neuromorphic Robotics Toolkit is free software: you can //
36 // redistribute it and/or modify it under the terms of the GNU General //
37 // Public License as published by the Free Software Foundation, either //
38 // version 3 of the License, or (at your option) any later version. //
39 // //
40 // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
41 // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
42 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
43 // PURPOSE. See the GNU General Public License for more details. //
44 // //
45 // You should have received a copy of the GNU General Public License //
46 // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
47 // <http://www.gnu.org/licenses/>. //
48 // ////////////////////////////////////////////////////////////////////////
49*/
50
51#pragma once
52
53namespace jevois
54{
55 //! A generic singleton class to enforce a single instance of an object
56 /*! The Singleton class should be inherited by any class which needs:
57 -# To have only one instance
58 -# To be globally accessible
59
60 Note that there are currently no guarantees on the order of destruction of Singletons, so care should be taken to
61 never reference another Singleton in the destructor of a Singleton.
62
63 This particular implementation is from:
64 http://stackoverflow.com/questions/1008019/c-singleton-design-pattern
65
66 The following is an example use of the Singleton:
67
68 @code
69 class MyClass : public Singleton<MyClass>
70 {
71 public:
72 void doIt() {...}
73
74 private:
75 MyClass();
76 };
77
78 int main()
79 {
80 ...
81 MyClass::instance().doIt();
82 ...
83 }
84 @endcode
85
86 @tparam T The class that is being made the singleton.
87
88 This class was first designed by Rand Voorhies in the Neuromorphic Robotics Toolkit.
89 \ingroup types */
90 template <class T>
92 {
93 public:
94 //! Get the global, unique instance of the class T
95 /*! If the global, unique instance of class T has not yet been created, then this method will create it in a
96 thread-safe manner. */
97 static T & instance();
98
99 protected:
100 //! Only classes that inherit from Singleton can construct it via its protected default constructor
102
103 private:
104 // Prevent copy-construction and copy, only allow default construction
105 Singleton(Singleton const &) = delete;
106 void operator=(Singleton const &) = delete;
107 };
108}
109
110// Include implementation details:
111#include <jevois/Types/details/SingletonImpl.H>
A generic singleton class to enforce a single instance of an object.
Definition Singleton.H:92
static T & instance()
Get the global, unique instance of the class T.
Singleton()
Only classes that inherit from Singleton can construct it via its protected default constructor.
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2