indexset.cpp

Go to the documentation of this file.
00001 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2006  Bernd Opitz
00006    Copyright (C) 2007  Thomas Moor
00007    Exclusive copyright is granted to Klaus Schmidt
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Lesser General Public
00011    License as published by the Free Software Foundation; either
00012    version 2.1 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Lesser General Public License for more details.
00018 
00019    You should have received a copy of the GNU Lesser General Public
00020    License along with this library; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00022 
00023 #include "indexset.h"
00024 
00025 
00026 namespace faudes {
00027 
00028 // IndexSet()
00029 IndexSet::IndexSet(void) : 
00030   TBaseSet<Idx>() 
00031 {
00032   FD_DC("IndexSet(" << this << ")::IndexSet()");
00033   Name("IndexSet");
00034 }
00035 
00036 // IndexSet(rOtherSet)
00037 IndexSet::IndexSet(const TBaseSet<Idx>& rOtherSet) : 
00038   TBaseSet<Idx>(rOtherSet) 
00039 {
00040   FD_DC("IndexSet(" << this << ")::IndexSet(rOtherSet " << &rOtherSet << ")");
00041 }
00042 
00043 // File constructor
00044 IndexSet::IndexSet(const std::string& rFilename, const std::string& rLabel) :
00045   TBaseSet<Idx>() 
00046 {
00047   FD_DC("IndexSet(" << this << ")::IndexSet(" << rFilename << ")");
00048   Read(rFilename, rLabel);
00049 }
00050 
00051 // DoWrite(rTw&)
00052 void IndexSet::DoWrite(TokenWriter& rTw, const std::string& rLabel) const {
00053   TaIndexSet<AttributeVoid> vcopy= *this;
00054   vcopy.Write(rTw, rLabel);
00055 }
00056 
00057 // DoRead(rTr, rLabel)
00058 void IndexSet::DoRead(TokenReader& rTr, const std::string& rLabel) {
00059   TaIndexSet<AttributeVoid> vcopy;
00060   vcopy.Read(rTr,rLabel);
00061   *this=vcopy;
00062 }
00063 
00064 // MaxIndex()
00065 Idx IndexSet::MaxIndex(void) const {
00066   if(Size()==0) return 0;
00067   Iterator it= End();
00068   it--;
00069   return *it;
00070 }
00071 
00072 // Insert()
00073 Idx IndexSet::Insert(void) {
00074   FD_DC("IndexSet(" << this << ")::Insert()");
00075   Idx index=MaxIndex()+1;
00076   TBaseSet<Idx>::Insert(index);
00077   return index;
00078 }
00079 
00080 //Insert(idx)
00081 bool IndexSet::Insert(Idx idx) {
00082   return TBaseSet<Idx>::Insert(idx);
00083 }
00084 
00085 
00086 //Valid(idx)
00087 bool  IndexSet::Valid(Idx idx) const {
00088   return idx!=0;
00089 }
00090 
00091 
00092 // Signature()
00093 Idx IndexSet::Signature(void) const {
00094   // prepare result
00095   Idx sig = 0;
00096   // helpers:
00097   Idx i = 1;
00098   Iterator it;
00099   // algorithm:
00100   for (it = Begin(); it != End(); ++it) {
00101     sig += *it * i;
00102     ++i;
00103   }
00104   return sig;
00105 }
00106 
00107 
00108 
00109 } // end name space

Generated on Fri May 9 11:26:47 2008 for libFAUDES 2.09b by  doxygen 1.4.4