MPQC  2.3.1
identity.h
1 //
2 // identity.h --- definition of the Identity class
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _util_ref_identity_h
29 #define _util_ref_identity_h
30 
31 #ifdef __GNUG__
32 #pragma interface
33 #endif
34 
35 #include <iostream>
36 
37 #include <scconfig.h>
38 
39 namespace sc {
40 
41 class Identity;
42 
50 class Identifier {
51  private:
52  const void* id;
53  public:
55  Identifier(): id(0) {}
57  Identifier(const Identity* i): id((void*)i) {}
59  Identifier(const Identifier& i): id(i.id) {}
62 
64  void operator = (const Identifier& i) { id = i.id; }
65 
67  int operator < (const Identifier&i) const { return id < i.id; }
69  int operator > (const Identifier&i) const { return id > i.id; }
71  int operator == (const Identifier&i) const { return id == i.id; }
73  int operator <= (const Identifier&i) const { return id <= i.id; }
75  int operator >= (const Identifier&i) const { return id >= i.id; }
77  int operator != (const Identifier&i) const { return id != i.id; }
78 
79  void print(std::ostream&) const;
80 };
81 
82 std::ostream & operator << (std::ostream &o, const Identifier &i);
83 
89 class Identity {
90  public:
91  virtual ~Identity();
94  Identifier identifier() { return this; }
95 };
97 inline int lt(const Identity*i, const Identity*j) { return i < j; }
99 inline int gt(const Identity*i, const Identity*j) { return i > j; }
101 inline int le(const Identity*i, const Identity*j) { return i <= j; }
103 inline int ge(const Identity*i, const Identity*j) { return i >= j; }
105 inline int eq(const Identity*i, const Identity*j) { return i == j; }
107 inline int ne(const Identity*i, const Identity*j) { return i != j; }
110 inline int cmp(const Identity*i, const Identity*j)
111 {
112  return (i==j)?0:((i<j)?-1:1);
113 }
114 
115 }
116 
117 #endif
118 
119 // Local Variables:
120 // mode: c++
121 // c-file-style: "CLJ"
122 // End:
sc::Identity
Identity gives objects a unique identity and ordering relationship relative to all other objects.
Definition: identity.h:89
sc::Identifier::operator==
int operator==(const Identifier &i) const
Equal.
Definition: identity.h:71
sc::Identifier::Identifier
Identifier(const Identifier &i)
Create an Identifier for the given object.
Definition: identity.h:59
sc::Identifier::~Identifier
~Identifier()
The destructor does nothing.
Definition: identity.h:61
sc::Identifier::operator=
void operator=(const Identifier &i)
Assign to the given Identifier.
Definition: identity.h:64
sc::Identifier::operator>=
int operator>=(const Identifier &i) const
Greater than or equal.
Definition: identity.h:75
sc::Identifier::operator!=
int operator!=(const Identifier &i) const
Not equal.
Definition: identity.h:77
sc::Identifier::Identifier
Identifier(const Identity *i)
Create an Identifier for the given object.
Definition: identity.h:57
sc::Identifier::operator<
int operator<(const Identifier &i) const
Less than.
Definition: identity.h:67
sc::Identity::identifier
Identifier identifier()
Return the Identifier for this argument.
Definition: identity.h:94
sc::Identifier::operator<=
int operator<=(const Identifier &i) const
Less than or equal.
Definition: identity.h:73
sc::Identifier
Identifier's are used to distinguish and order objects.
Definition: identity.h:50
sc::Identifier::Identifier
Identifier()
Create an Identifier for a null object.
Definition: identity.h:55
sc::Identifier::operator>
int operator>(const Identifier &i) const
Greater than.
Definition: identity.h:69

Generated at Sun Jan 26 2020 23:33:03 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.