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 Type* pContext) const {
00053   TaIndexSet<AttributeVoid> vcopy= *this;
00054   vcopy.Write(rTw, rLabel, pContext);
00055 }
00056 
00057 // DoRead(rTr, rLabel)
00058 void IndexSet::DoRead(TokenReader& rTr, const std::string& rLabel,const Type* pContext) {
00059   FD_DC("IndexSet(" << this << ")::DoRead(..): section " << rLabel);
00060   TaIndexSet<AttributeVoid> vcopy;
00061   vcopy.DoRead(rTr,rLabel, pContext);
00062   *this=vcopy;
00063 }
00064 
00065 // MaxIndex()
00066 Idx IndexSet::MaxIndex(void) const {
00067   if(Size()==0) return 0;
00068   Iterator it= End();
00069   it--;
00070   return *it;
00071 }
00072 
00073 // Insert()
00074 Idx IndexSet::Insert(void) {
00075   FD_DC("IndexSet(" << this << ")::Insert()");
00076   Idx index=MaxIndex()+1;
00077   TBaseSet<Idx>::Insert(index);
00078   return index;
00079 }
00080 
00081 //Insert(idx)
00082 bool IndexSet::Insert(Idx idx) {
00083   return TBaseSet<Idx>::Insert(idx);
00084 }
00085 
00086 
00087 //Valid(idx)
00088 bool  IndexSet::Valid(Idx idx) const {
00089   return idx!=0;
00090 }
00091 
00092 
00093 // Signature()
00094 Idx IndexSet::Signature(void) const {
00095   // prepare result
00096   Idx sig = 0;
00097   // helpers:
00098   Idx i = 1;
00099   Iterator it;
00100   // algorithm:
00101   for (it = Begin(); it != End(); ++it) {
00102     sig += *it * i;
00103     ++i;
00104   }
00105   return sig;
00106 }
00107 
00108 
00109 
00110 } // end name space

Generated on Mon Nov 10 08:13:14 2008 for libFAUDES 2.11v by  doxygen 1.4.4