MPQC  3.0.0-alpha
src/lib/util/ref/identity.h
00001 //
00002 // identity.h --- definition of the Identity class
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _util_ref_identity_h
00029 #define _util_ref_identity_h
00030 
00031 #include <iostream>
00032 
00033 #include <scconfig.h>
00034 
00035 namespace sc {
00036 
00037 class Identity;
00038 
00046 class Identifier {
00047   private:
00048     const void* id;
00049   public:
00051     Identifier(): id(0) {}
00053     Identifier(const Identity* i): id((void*)i) {}
00055     Identifier(const Identifier& i): id(i.id) {}
00057     ~Identifier() {}
00058 
00060     void operator = (const Identifier& i) { id = i.id; }
00061 
00063     int operator < (const Identifier&i) const { return id < i.id; }
00065     int operator > (const Identifier&i) const { return id > i.id; }
00067     int operator == (const Identifier&i) const { return id == i.id; }
00069     int operator <= (const Identifier&i) const { return id <= i.id; }
00071     int operator >= (const Identifier&i) const { return id >= i.id; }
00073     int operator != (const Identifier&i) const { return id != i.id; }
00074 
00075     void print(std::ostream&) const;
00076 };
00077 
00078 std::ostream & operator << (std::ostream &o, const Identifier &i);
00079 
00085 class Identity {
00086   public:
00087     virtual ~Identity();
00090     Identifier identifier() { return this; }
00091 };
00093 inline int lt(const Identity*i, const Identity*j) { return i < j; }
00095 inline int gt(const Identity*i, const Identity*j) { return i > j; }
00097 inline int le(const Identity*i, const Identity*j) { return i <= j; }
00099 inline int ge(const Identity*i, const Identity*j) { return i >= j; }
00101 inline int eq(const Identity*i, const Identity*j) { return i == j; }
00103 inline int ne(const Identity*i, const Identity*j) { return i != j; }
00106 inline int cmp(const Identity*i, const Identity*j)
00107 {
00108   return (i==j)?0:((i<j)?-1:1);
00109 }
00110 
00111 }
00112 
00113 #endif
00114 
00115 // Local Variables:
00116 // mode: c++
00117 // c-file-style: "CLJ"
00118 // End:

Generated at Sat Jul 7 2012 11:52:48 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.0.