HPCToolkit
Unique.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 // **************************************************************************
48 //
49 // File:
50 // Unique.h
51 //
52 // Purpose:
53 // Defines the Unique class (see below).
54 //
55 // Description:
56 // Mixin for non-copyable objects or singleton objects.
57 // All class definitions should contain copy constructors and assignment
58 // operators. Many class's objects, however, should never be copied.
59 // If this is the case, the class should multiply inherit from the
60 // Unique mixin class, which inhibits these operations. The Unique
61 // class additionally provides a mechanism for classes that should only
62 // have single objects (a stronger form of a non-copyable object).
63 // In this later case, the second constructor should be used and the
64 // class name specified as a (const char*) string.
65 //
66 // Note that for Unique objects, object equality amounts to pointer
67 // equality, so equality and inequality operators can be easily defined.
68 //
69 // **************************************************************************
70 
71 #ifndef support_Unique_h
72 #define support_Unique_h
73 
74 
75 // ************************* System Include Files ***************************
76 
77 #include <set>
78 #include <string>
79 
80 // ************************** User Include Files ****************************
81 
82 #include <include/uint.h>
83 
84 // ************************* Variable Definitions ***************************
85 
86 // *************************** Class Definitions ****************************
87 
88 // **************************************************************************
89 //
90 // Class:
91 // Unique
92 //
93 // Class Data Members:
94 // std::string className private -- the name of the class, if singleton.
95 //
96 // Purpose:
97 // 1) Mixin for a class with objects that shouldn't be copied.
98 // 2) Mixin for a class which should have only a single object.
99 //
100 // History:
101 // 09/24/96 - dbaker - Creation (adapted from Memento).
102 //
103 // **************************************************************************
104 class Unique
105 {
106  protected:
107 
108  // Special Class Members
109 
110  Unique();
111  // Default constructor.
112 
113  Unique(const char* theClassName);
114  // Constructor for singleton object.
115 
116  virtual ~Unique();
117  // Destructor.
118 
119 
120  private:
121 
122  static std::set<std::string> classNameSet;
123  // Where the set of class names are stored.
124 
125  Unique(const Unique& mo);
126  // Copy constructor (explicitly not allowed).
127  // has not implemetationm since compiler should complain
128  // about inaccessability
129  Unique& operator=(const Unique& mo);
130  // Assignment operator (explicitly not allowed).
131  // has not implemetationm, ...
132 
133  std::string className;
134  // Saved class name or ""
135 
136 };
137 
138 // ********************** Extern Function Prototypes ************************
139 
140 // Unique object equality.
141 inline bool operator==(const Unique& u1, const Unique& u2)
142 {
143  return (&u1 == &u2);
144 }
145 
146 
147 // Unique object inequality.
148 inline bool operator!=(const Unique& u1, const Unique& u2)
149 {
150  return !(u1 == u2);
151 }
152 
153 
154 #endif /* support_Unique_h */
bool operator!=(const Unique &u1, const Unique &u2)
Definition: Unique.hpp:148
Unique & operator=(const Unique &mo)
Unique()
Definition: Unique.cpp:85
virtual ~Unique()
Definition: Unique.cpp:132
static std::set< std::string > classNameSet
Definition: Unique.hpp:122
bool operator==(const Unique &u1, const Unique &u2)
Definition: Unique.hpp:141
std::string className
Definition: Unique.hpp:133