// This file contains functions for manipulating a single reservation, called // a "time_slot". #include #include #include #include #include "debug.h" #include "errors.h" #include "time_slot.h" time_slot::time_slot() { #ifdef FBFC_DEBUG cerr << "\ninside default constructor time_slot\n"; #endif slot_unique_id = 0; name[0] = '\0'; start = 0; finish = 0; } time_slot::time_slot(const time_slot_info new_info) { #ifdef FBFC_DEBUG cerr << "\ninside constructor time_slot\n"; cerr << " slot_unique_id=" << new_info.slot_unique_id << endl; cerr << " name=" << new_info.name << endl; cerr << " start=" << new_info.start << endl; cerr << " finish=" << new_info.finish << endl; #endif slot_unique_id = new_info.slot_unique_id; strcpy(name, new_info.name); start = new_info.start; finish = new_info.finish; if (finish < start) { // no way to gracefully recover from an error in a constructor strcpy(fatal_err_function, "time_slot::time_slot"); sprintf(fatal_err_msg, "time_in=%d time_out=%d", start, finish); fatal_error(); } } time_slot::~time_slot() { #ifdef FBFC_DEBUG cerr << "\ninside destructor time_slot\n"; cerr << " slot_unique_id=" << slot_unique_id << endl; cerr << " name=" << name << endl; cerr << " start=" << start << endl; cerr << " finish=" << finish << endl; #endif } time_slot_info time_slot::get() { time_slot_info info; info.slot_unique_id = slot_unique_id; strcpy(info.name, name); info.start = start; info.finish = finish; return info; } int time_slot::update(const time_slot_info new_info) { int outcome = SUCCESSFUL; time_t t1, t2; // first, a little error checking if (new_info.start != 0) t1 = new_info.start; else t1 = start; if (new_info.finish != 0) t2 = new_info.finish; else t2 = finish; if (t2 < t1) { outcome = T_S_ERR_START_FINISH; } else { // load up the class with the new info values if (new_info.slot_unique_id != 0) slot_unique_id = new_info.slot_unique_id; if (new_info.name[0] != '\0') { strcpy(name, new_info.name); } if (new_info.start != 0) start = new_info.start; if (new_info.finish != 0) finish = new_info.finish; } return outcome; }