Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

resource.cc

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2000 Alan McIvor <alan@mcivor.gen.nz>
00003 **  
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 ** 
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 ** 
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software 
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include <cstdio>
00020 #include <stdarg.h>
00021 
00022 using namespace std;
00023 
00024 #include "resource.h"
00025 #include "projectExceptions.h"
00026 
00027 RESOURCE::RESOURCE( char * id, char * name ):
00028   NAMED_ID(id, name)
00029 {
00030     mEfficiency = 1.0;
00031     mRate = -1.0;
00032 
00033     is_group = 0;
00034 }
00035 
00036 
00037 void RESOURCE::Error(char *fmt, ...) 
00038 {
00039     char buf[1024];
00040     va_list args;
00041 
00042     va_start(args, fmt);
00043     vsprintf(buf, fmt, args);
00044     va_end(args);
00045 
00046     string sid = id();
00047     throw RESOURCEException( sid, buf );
00048 }
00049 
00050 
00051 void RESOURCE::setEfficiency(double e)
00052 {
00053     if ( e <= 0.0 )
00054         Error("Invalid value (%f) for efficiency", e );
00055 
00056     mEfficiency = e;
00057 }
00058 
00059 
00060 
00061 void RESOURCE::setRate(double r)
00062 { 
00063     if ( r < 0.0 )
00064         Error("Invalid value (%f) for rate", r );
00065 
00066     if ( mRate != -1.0 )
00067         Error("Setting rate to %f after already set to %f", r, mRate);
00068 
00069     mRate = r; 
00070 }
00071 
00072 
00073 
00074 bool RESOURCE::IsAvailable( int start, int finish )
00075 {
00076     for ( ResourceTimeBlockIterator tb = mBooked.begin(); 
00077           tb != mBooked.end(); tb++ )
00078     {
00079         if ( tb->overlap( start, finish ) )
00080         {
00081             return false;
00082         }
00083     }
00084 
00085     return true;
00086 }
00087 
00088 bool RESOURCE::IsUsed( int dayNo )
00089 {
00090     return ! IsAvailable( dayNo, dayNo );
00091 }
00092 
00093 
00094 bool RESOURCE::reverseIsAvailable( int start, int finish )
00095 {
00096     for ( ResourceTimeBlockIterator tb = mRbooked.begin(); 
00097           tb != mRbooked.end(); tb++ )
00098     {
00099         if ( tb->overlap( start, finish ) )
00100         {
00101             return false;
00102         }
00103     }
00104 
00105     return true;
00106 }
00107 
00108 
00109 void RESOURCE::AddNote(const string & note)
00110 {
00111     mNotes.push_back(note);
00112 }
00113 
00114 void RESOURCE::addTimeBlock(TASK *t, int start, int finish, TimeBlock::Type type)
00115 {
00116     mBooked.push_back(ResourceTimeBlock(t, start, finish, type));
00117 }
00118 
00119 
00120 void RESOURCE::addReverseTimeBlock(TASK *t, int start, int finish, TimeBlock::Type type)
00121 {
00122     mRbooked.push_back(ResourceTimeBlock(t, start, finish, type));
00123 }
00124 
00125 
00126 double RESOURCE::sDefaultRate = -1.0;
00127 
00128 void RESOURCE::setDefaultRate(double rate)
00129 {
00130     sDefaultRate = rate;
00131 }
00132 
00133 double RESOURCE::rate()
00134 {
00135     if ( mRate != -1.0 )
00136         return mRate;
00137     if ( sDefaultRate != -1 )
00138         return sDefaultRate;
00139     Error("Neither resource rate nor default rate set");
00140     /*NOTREACHED*/
00141     return 0.0;
00142 }

Generated on Wed Feb 18 22:23:54 2004 for Opensched by doxygen1.2.15