h o m e d o c u m e n t a t i o n c l a s s h i e r a r c h y

Id.h

00001 //
00002 //  Filename         : Id.h
00003 //  Author(s)        : Emmanuel Turquin
00004 //  Purpose          : Identification system
00005 //  Date of creation : 01/07/2003
00006 //
00008 
00009 
00010 //
00011 //  Copyright (C) : Please refer to the COPYRIGHT file distributed 
00012 //   with this source distribution. 
00013 //
00014 //  This program is free software; you can redistribute it and/or
00015 //  modify it under the terms of the GNU General Public License
00016 //  as published by the Free Software Foundation; either version 2
00017 //  of the License, or (at your option) any later version.
00018 //
00019 //  This program is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with this program; if not, write to the Free Software
00026 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 //
00029 
00030 #ifndef  ID_H
00031 # define ID_H
00032 
00036 class Id
00037 {
00038 public:
00039 
00040   typedef unsigned id_type;
00041 
00043   Id() {
00044     _first = 0;
00045     _second = 0;
00046   }
00047 
00051   Id(id_type id) {
00052     _first = id;
00053     _second = 0;
00054   }
00055 
00057   Id(id_type ifirst, id_type isecond) {
00058     _first = ifirst;
00059     _second = isecond;
00060   }
00061 
00063   Id(const Id& iBrother) {
00064     _first = iBrother._first;
00065     _second = iBrother._second;
00066   }
00067 
00069   Id& operator=(const Id& iBrother) {
00070    _first = iBrother._first;
00071    _second = iBrother._second;
00072     return *this;
00073   } 
00074 
00076   id_type getFirst() const {
00077     return _first;
00078   }
00079 
00081   id_type getSecond() const {
00082     return _second;
00083   }
00084 
00086   void setFirst(id_type first) {
00087     _first = first;
00088   }
00089 
00091   void setSecond(id_type second) {
00092     _second = second;
00093   }
00094   
00096   bool operator==(const Id& id) const {
00097     return ((_first == id._first) && (_second == id._second));
00098   }
00099 
00101   bool operator!=(const Id& id) const {
00102     return !((*this)==id);
00103   }
00104   
00106   bool operator<(const Id& id) const {
00107     if (_first < id._first)
00108       return true;
00109     if (_first == id._first && _second < id._second)
00110       return true;
00111     return false;
00112 }
00113 
00114 private:
00115 
00116   id_type _first;
00117   id_type _second;
00118 };
00119 
00120 // stream operator
00121 inline std::ostream& operator<<(std::ostream& s, const Id& id) {
00122   s << "[" << id.getFirst() << ", " << id.getSecond() << "]";
00123   return s;
00124 }
00125 
00126 # endif // ID_H