Back to index

lightning-sunbird  0.9+nobinonly
icalspanlist_cxx.cpp
Go to the documentation of this file.
00001 #include "icalspanlist_cxx.h"
00002 #include <exception>
00003 
00010 ICalSpanList::ICalSpanList(icalset *set, icaltimetype start, icaltimetype end) throw(icalerrorenum)
00011 {
00012   data = icalspanlist_new(set, start, end);
00013   if (!data) throw icalerrno;
00014 };
00015 
00016 
00021 ICalSpanList::ICalSpanList(icalcomponent *comp) throw(icalerrorenum)
00022 {
00023   data = icalspanlist_from_vfreebusy(comp);
00024   if (!data) throw icalerrno;
00025 }
00026 
00030 ICalSpanList::ICalSpanList(VComponent &comp) throw(icalerrorenum)
00031 {
00032   data = icalspanlist_from_vfreebusy((icalcomponent*) comp);
00033   if (!data) throw icalerrno;
00034 }
00035 
00037 ICalSpanList::~ICalSpanList() {
00038   if (data)
00039     icalspanlist_free(data);
00040 }
00041 
00042 
00049 VComponent*
00050 ICalSpanList::get_vfreebusy(const char *organizer, const char *attendee) throw(icalerrorenum)
00051 {
00052   icalcomponent *comp;
00053   VComponent    *vcomp;
00054 
00055   comp = icalspanlist_as_vfreebusy(data, organizer, attendee);
00056   if (comp == 0) throw icalerrno;
00057     
00058   vcomp = new VComponent(comp);
00059   if (vcomp == 0) throw icalerrno;
00060 
00061   return vcomp;
00062 }
00063 
00064 
00077 std::vector<int> ICalSpanList::as_vector(int delta_t) throw(icalerrorenum)
00078 {
00079   int *matrix;
00080   int i = 0;
00081   std::vector<int> event_vec;
00082 
00083   matrix = icalspanlist_as_freebusy_matrix(data, delta_t);
00084 
00085   if (!matrix) throw ICAL_USAGE_ERROR;
00086 
00087   while (matrix[i] != -1) {
00088     event_vec.push_back(matrix[i]); // Add item at end of vector
00089   }
00090   
00091   return(event_vec);
00092 }