$darkmode
Libical API Documentation 4.0 STABLE VERSION Visit the v3.0 documentation
icalspanlist_cxx.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2001, Critical Path
3  * SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
4 */
5 
12 #include "icalspanlist_cxx.hpp"
13 #include "icalerror.h"
14 #include "vcomponent_cxx.hpp"
15 
16 #include <cstdlib> // for free()
17 #include <vector>
18 
19 using namespace LibICal;
20 
21 ICalSpanList::ICalSpanList()
22  : data(0)
23 {
24  throw icalerrno;
25 }
26 
27 ICalSpanList::ICalSpanList(const ICalSpanList &v)
28  : data(v.data)
29 {
30  if (data == NULL) {
31  throw icalerrno;
32  }
33 }
34 
40 ICalSpanList::ICalSpanList(icalset *set, const icaltimetype &start, const icaltimetype &end)
41  : data(icalspanlist_new(set, start, end))
42 {
43  if (data == NULL) {
44  throw icalerrno;
45  }
46 }
47 
52 ICalSpanList::ICalSpanList(icalcomponent *comp)
53  : data(icalspanlist_from_vfreebusy(comp))
54 {
55  if (data == NULL) {
56  throw icalerrno;
57  }
58 }
59 
63 ICalSpanList::ICalSpanList(VComponent &comp)
64  : data(icalspanlist_from_vfreebusy(static_cast<icalcomponent *>(comp)))
65 {
66  if (data == NULL) {
67  throw icalerrno;
68  }
69 }
70 
72 {
73  icalspanlist_dump(data);
74 }
75 
78 {
79  if (data == NULL) {
80  icalspanlist_free(data);
81  }
82 }
83 
90 VComponent *ICalSpanList::get_vfreebusy(const char *organizer, const char *attendee)
91 {
92  icalcomponent *comp;
93  VComponent *vcomp;
94 
95  comp = icalspanlist_as_vfreebusy(data, organizer, attendee);
96  if (comp == NULL) {
97  throw icalerrno;
98  }
99 
100  vcomp = new VComponent(comp);
101  if (vcomp == NULL) {
102  throw icalerrno;
103  }
104 
105  return vcomp;
106 }
107 
120 std::vector<int> ICalSpanList::as_vector(int delta_t)
121 {
122  int *matrix;
123  const int i = 0;
124  std::vector<int> event_vec;
125 
126  matrix = icalspanlist_as_freebusy_matrix(data, delta_t);
127 
128  if (matrix == NULL) {
129  throw icalerrno;
130  }
131 
132  while (matrix[i] != -1) {
133  event_vec.push_back(matrix[i]); // Add item at end of vector
134  }
135 
136  free(matrix);
137  return event_vec;
138 }
void icalspanlist_dump(icalspanlist *sl)
Definition: icalspanlist.c:202
icalspanlist * icalspanlist_new(icalset *set, struct icaltimetype start, struct icaltimetype end)
Definition: icalspanlist.c:81
std::vector< int > as_vector(int delta_t)
Returns a summary of events over delta_t.
VComponent * get_vfreebusy(const char *organizer, const char *attendee)
Returns a VFREEBUSY component for the object.
icalcomponent * icalspanlist_as_vfreebusy(icalspanlist *sl, const char *organizer, const char *attendee)
Definition: icalspanlist.c:343
C++ class wrapping the icalspanlist data structure.
Error handling for libical.
C++ classes for the icalcomponent wrapper (VToDo VEvent, etc..).
int * icalspanlist_as_freebusy_matrix(icalspanlist *spanlist, int delta_t)
Definition: icalspanlist.c:280
#define icalerrno
Access the current icalerrno value.
Definition: icalerror.h:133
icalspanlist * icalspanlist_from_vfreebusy(icalcomponent *comp)
Definition: icalspanlist.c:389
void icalspanlist_free(icalspanlist *sl)
Definition: icalspanlist.c:183
A class wrapping the libical icalcomponent functions.