00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00141 return 0.0;
00142 }