icalset.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. @file icalset.h
  3. @author eric 28 November 1999
  4. Icalset is the "base class" for representations of a collection of
  5. iCal components. Derived classes (actually delegatees) include:
  6. icalfileset Store components in a single file
  7. icaldirset Store components in multiple files in a directory
  8. icalbdbset Store components in a Berkeley DB File
  9. icalheapset Store components on the heap
  10. icalmysqlset Store components in a mysql database.
  11. **/
  12. /*
  13. (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of either:
  16. The LGPL as published by the Free Software Foundation, version
  17. 2.1, available at: http://www.gnu.org/licenses/lgpl-2.1.html
  18. Or:
  19. The Mozilla Public License Version 1.0. You may obtain a copy of
  20. the License at http://www.mozilla.org/MPL/
  21. The Original Code is eric. The Initial Developer of the Original
  22. Code is Eric Busboom
  23. ======================================================================*/
  24. #ifndef ICALSET_H
  25. #define ICALSET_H
  26. #include "libical_icalss_export.h"
  27. #include "icalgauge.h"
  28. #include "icalcomponent.h"
  29. #include "icalerror.h"
  30. typedef struct icalset_impl icalset;
  31. typedef enum icalset_kind
  32. {
  33. ICAL_FILE_SET,
  34. ICAL_DIR_SET,
  35. ICAL_BDB_SET
  36. } icalset_kind;
  37. typedef struct icalsetiter
  38. {
  39. icalcompiter iter; /* icalcomponent_kind, pvl_elem iter */
  40. icalgauge *gauge;
  41. icalrecur_iterator *ritr; /*the last iterator */
  42. icalcomponent *last_component; /*the pending recurring component to be processed */
  43. const char *tzid; /* the calendar's timezone id */
  44. } icalsetiter;
  45. struct icalset_impl
  46. {
  47. icalset_kind kind;
  48. size_t size;
  49. char *dsn;
  50. icalset *(*init) (icalset *set, const char *dsn, void *options);
  51. void (*free) (icalset *set);
  52. const char *(*path) (icalset *set);
  53. void (*mark) (icalset *set);
  54. icalerrorenum(*commit) (icalset *set);
  55. icalerrorenum(*add_component) (icalset *set, icalcomponent *comp);
  56. icalerrorenum(*remove_component) (icalset *set, icalcomponent *comp);
  57. int (*count_components) (icalset *set, icalcomponent_kind kind);
  58. icalerrorenum(*select) (icalset *set, icalgauge *gauge);
  59. void (*clear) (icalset *set);
  60. icalcomponent *(*fetch) (icalset *set, icalcomponent_kind kind, const char *uid);
  61. icalcomponent *(*fetch_match) (icalset *set, icalcomponent *comp);
  62. int (*has_uid) (icalset *set, const char *uid);
  63. icalerrorenum(*modify) (icalset *set, icalcomponent *old, icalcomponent *newc);
  64. icalcomponent *(*get_current_component) (icalset *set);
  65. icalcomponent *(*get_first_component) (icalset *set);
  66. icalcomponent *(*get_next_component) (icalset *set);
  67. icalsetiter(*icalset_begin_component) (icalset *set,
  68. icalcomponent_kind kind, icalgauge *gauge,
  69. const char *tzid);
  70. icalcomponent *(*icalsetiter_to_next) (icalset *set, icalsetiter *i);
  71. icalcomponent *(*icalsetiter_to_prior) (icalset *set, icalsetiter *i);
  72. };
  73. /** @brief Register a new derived class */
  74. LIBICAL_ICALSS_EXPORT int icalset_register_class(icalset *set);
  75. /** @brief Generic icalset constructor
  76. *
  77. * @param kind The type of icalset to create
  78. * @param dsn Data Source Name - usually a pathname or DB handle
  79. * @param options Any implementation specific options
  80. *
  81. * @return A valid icalset reference or NULL if error.
  82. *
  83. * This creates any of the icalset types available.
  84. */
  85. LIBICAL_ICALSS_EXPORT icalset *icalset_new(icalset_kind kind, const char *dsn, void *options);
  86. LIBICAL_ICALSS_EXPORT icalset *icalset_new_file(const char *path);
  87. LIBICAL_ICALSS_EXPORT icalset *icalset_new_file_reader(const char *path);
  88. LIBICAL_ICALSS_EXPORT icalset *icalset_new_file_writer(const char *path);
  89. LIBICAL_ICALSS_EXPORT icalset *icalset_new_dir(const char *path);
  90. LIBICAL_ICALSS_EXPORT void icalset_free(icalset *set);
  91. LIBICAL_ICALSS_EXPORT const char *icalset_path(icalset *set);
  92. /** Mark the cluster as changed, so it will be written to disk when it
  93. is freed. **/
  94. LIBICAL_ICALSS_EXPORT void icalset_mark(icalset *set);
  95. /** Write changes to disk immediately */
  96. LIBICAL_ICALSS_EXPORT icalerrorenum icalset_commit(icalset *set);
  97. LIBICAL_ICALSS_EXPORT icalerrorenum icalset_add_component(icalset *set, icalcomponent *comp);
  98. LIBICAL_ICALSS_EXPORT icalerrorenum icalset_remove_component(icalset *set, icalcomponent *comp);
  99. LIBICAL_ICALSS_EXPORT int icalset_count_components(icalset *set, icalcomponent_kind kind);
  100. /** Restrict the component returned by icalset_first, _next to those
  101. that pass the gauge. */
  102. LIBICAL_ICALSS_EXPORT icalerrorenum icalset_select(icalset *set, icalgauge *gauge);
  103. /** Clears the gauge defined by icalset_select() */
  104. LIBICAL_ICALSS_EXPORT void icalset_clear_select(icalset *set);
  105. /** Get a component by uid */
  106. LIBICAL_ICALSS_EXPORT icalcomponent *icalset_fetch(icalset *set, const char *uid);
  107. LIBICAL_ICALSS_EXPORT int icalset_has_uid(icalset *set, const char *uid);
  108. LIBICAL_ICALSS_EXPORT icalcomponent *icalset_fetch_match(icalset *set, icalcomponent *c);
  109. /** Modify components according to the MODIFY method of CAP. Works on
  110. the currently selected components. */
  111. LIBICAL_ICALSS_EXPORT icalerrorenum icalset_modify(icalset *set,
  112. icalcomponent *oldc, icalcomponent *newc);
  113. /** Iterate through the components. If a guage has been defined, these
  114. will skip over components that do not pass the gauge */
  115. LIBICAL_ICALSS_EXPORT icalcomponent *icalset_get_current_component(icalset *set);
  116. LIBICAL_ICALSS_EXPORT icalcomponent *icalset_get_first_component(icalset *set);
  117. LIBICAL_ICALSS_EXPORT icalcomponent *icalset_get_next_component(icalset *set);
  118. /** External Iterator with gauge - for thread safety */
  119. LIBICAL_ICALSS_EXPORT extern icalsetiter icalsetiter_null;
  120. LIBICAL_ICALSS_EXPORT icalsetiter icalset_begin_component(icalset *set,
  121. icalcomponent_kind kind,
  122. icalgauge *gauge, const char *tzid);
  123. /** Default _next, _prior, _deref for subclasses that use single cluster */
  124. LIBICAL_ICALSS_EXPORT icalcomponent *icalsetiter_next(icalsetiter *i);
  125. LIBICAL_ICALSS_EXPORT icalcomponent *icalsetiter_prior(icalsetiter *i);
  126. LIBICAL_ICALSS_EXPORT icalcomponent *icalsetiter_deref(icalsetiter *i);
  127. /** for subclasses that use multiple clusters that require specialized cluster traversal */
  128. LIBICAL_ICALSS_EXPORT icalcomponent *icalsetiter_to_next(icalset *set, icalsetiter *i);
  129. LIBICAL_ICALSS_EXPORT icalcomponent *icalsetiter_to_prior(icalset *set, icalsetiter *i);
  130. #endif /* !ICALSET_H */