OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PIMCalendarItem.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  */
10 #ifndef PIMCALENDARITEM_HPP_
11 #define PIMCALENDARITEM_HPP_
12 
13 #include <string>
14 #include <map>
15 #include <vector>
16 #include <set>
17 #include <PIMItem/PIMItem.hpp>
18 #include <PIMItem/PIMItemIndex.hpp>
22 namespace OpenAB {
23 
29 class ItemField
30 {
31  public:
35  ItemField();
36 
40  ItemField(const std::string& value);
41  ~ItemField();
42 
48  bool parse(std::string rawFieldString, bool forceParams = false);
49 
54  void setValue(const std::string& value);
55 
59  bool operator<(const ItemField& other) const;
60 
65  std::string toString() const;
66 
71  std::string getValue() const;
72 
77  std::map<std::string, std::set<std::string> > getParams() const;
78 
79  private:
84  void processParam (std::string paramLine);
85 
91  void addParam(std::string paramName, std::set<std::string> values);
92 
93  std::string value;
94  std::map<std::string, std::set<std::string> > params;
95 };
96 
103 {
104  public:
108  KeyValueItem();
109  virtual ~KeyValueItem();
110 
116  bool parse(const std::string& rawData);
117 
122  std::map<std::string, std::vector<ItemField> >& getFields() {return fields;}
123 
124  protected:
129  virtual bool processField();
130 
131  std::string currentLine;
132  std::string currentFieldName;
133  std::string currentFieldValue;
135  std::map<std::string, std::vector<ItemField> > fields;
136  std::map<std::string, std::vector< SmartPtr<KeyValueItem> > > subcomponents;
137 
138  private:
139  bool processSubcomponent();
140 
141  bool inSubcomponent;
142  std::string currentSubcomponentName;
143  std::string currentSubcomponentData;
144 };
145 
150 {
151  public:
154 
155  bool processField() {return true;}
156 };
157 
162 {
163  public:
166 
167  bool processField() {return true;}
168 };
169 
174 {
175  public:
177  virtual ~KeyValueItemFactory() {}
178 
184  static KeyValueItem* createItem(const std::string& componentType);
185 
191  static void registerFactory(KeyValueItemFactory* factory, const std::string& componentType);
192 
193  protected:
194  virtual KeyValueItem* createItem() = 0;
195 
196  private:
197  static std::map<std::string, KeyValueItemFactory*> factories;
198 };
199 
204 #define CREATE_KEY_VALUE_ITEM_FACTORY(KeyValueItemClass, ComponentType) \
205  class KeyValueItemClass##Factory : public KeyValueItemFactory \
206  { \
207  public: \
208  KeyValueItemClass##Factory() : KeyValueItemFactory() \
209  { \
210  KeyValueItemFactory::registerFactory(this, ComponentType); \
211  } \
212  ~KeyValueItemClass##Factory(){} \
213  protected: \
214  KeyValueItem* createItem() \
215  { \
216  return new KeyValueItemClass(); \
217  } \
218  } KeyValueItemClass##FactoryInstance;
219 
223 class PIMCalendarItem : public PIMItem, public KeyValueItem
224 {
225  public:
230 
234  virtual ~PIMCalendarItem()=0;
235 
236  bool parse(const std::string& iCalendar);
237 
239 
240  std::string getRawData() const;
241 
242  private:
243  std::string iCalendar;
244 };
245 
247 {
248  public:
253 
257  virtual ~PIMCalendarEventItem();
258 };
259 
261 {
262  public:
267 
271  virtual ~PIMCalendarTaskItem();
272 };
273 
274 } // namespace OpenAB
275 
276 #endif // PIMCALENDARITEM_HPP_
bool parse(const std::string &iCalendar)
Parses item from string. Format of string to be parsed from depends on type of item.
Definition: PIMCalendarItem.cpp:332
KeyValueItemFactory()
Definition: PIMCalendarItem.hpp:176
std::string currentLine
Definition: PIMCalendarItem.hpp:131
std::map< std::string, std::vector< ItemField > > fields
Definition: PIMCalendarItem.hpp:135
PIMCalendarTaskItem()
Constructor.
Definition: PIMCalendarItem.cpp:401
~VDayLightTimeZoneKeyValueItem()
Definition: PIMCalendarItem.hpp:153
ItemField()
default constructor
Definition: PIMCalendarItem.cpp:17
virtual ~KeyValueItemFactory()
Definition: PIMCalendarItem.hpp:177
virtual ~KeyValueItem()
Definition: PIMCalendarItem.cpp:175
bool operator<(const ItemField &other) const
comparison operator, required so fields can be stored in std::map
Definition: PIMCalendarItem.cpp:164
virtual ~PIMCalendarTaskItem()
Destructor, virtual by default.
Definition: PIMCalendarItem.cpp:406
Factory for creating KeyValueItem object.
Definition: PIMCalendarItem.hpp:173
VStandardTimeZoneKeyValueItem()
Definition: PIMCalendarItem.hpp:164
std::map< std::string, std::vector< ItemField > > & getFields()
Returns all fields of item.
Definition: PIMCalendarItem.hpp:122
~VStandardTimeZoneKeyValueItem()
Definition: PIMCalendarItem.hpp:165
bool parse(const std::string &rawData)
parses item from raw data string
Definition: PIMCalendarItem.cpp:234
Smart pointer implementation for safely passing around dynamically created data. Smart pointers are r...
Definition: SmartPtr.hpp:32
Documentation for class PIMCalendarItem.
Definition: PIMCalendarItem.hpp:223
Definition: PIMCalendarItem.hpp:260
static void registerFactory(KeyValueItemFactory *factory, const std::string &componentType)
Registers factory for given component type.
Definition: PIMCalendarItem.cpp:303
bool processField()
Handler that processed contents of given fields. Can be override in child classes.
Definition: PIMCalendarItem.hpp:167
virtual KeyValueItem * createItem()=0
bool parse(std::string rawFieldString, bool forceParams=false)
Parses given field from raw string.
Definition: PIMCalendarItem.cpp:23
Class representing item containing fields in form of key value pairs, that can contain additional par...
Definition: PIMCalendarItem.hpp:102
virtual ~PIMCalendarItem()=0
Destructor, virtual by default.
Definition: PIMCalendarItem.cpp:328
void setValue(const std::string &value)
Sets value of field.
Definition: PIMCalendarItem.cpp:60
std::map< std::string, std::vector< SmartPtr< KeyValueItem > > > subcomponents
Definition: PIMCalendarItem.hpp:136
virtual ~PIMCalendarEventItem()
Destructor, virtual by default.
Definition: PIMCalendarItem.cpp:397
std::string currentFieldValue
Definition: PIMCalendarItem.hpp:133
PIMCalendarItem(PIMItemType t)
Constructor.
Definition: PIMCalendarItem.cpp:322
std::string toString() const
Returns string representation of field.
Definition: PIMCalendarItem.cpp:112
KeyValueItem()
default constructor
Definition: PIMCalendarItem.cpp:169
Class representing single field of iCalendar object. Field can have assigned value and list of parame...
Definition: PIMCalendarItem.hpp:29
~ItemField()
Definition: PIMCalendarItem.cpp:21
bool processField()
Handler that processed contents of given fields. Can be override in child classes.
Definition: PIMCalendarItem.hpp:155
PIMItemType
Definition: PIMItemIndex.hpp:24
PIMCalendarEventItem()
Constructor.
Definition: PIMCalendarItem.cpp:392
std::string getValue() const
Returns value of field.
Definition: PIMCalendarItem.cpp:154
std::string getRawData() const
Returns raw data of item. Format of raw data depends on type of item.
Definition: PIMCalendarItem.cpp:387
virtual bool processField()
Handler that processed contents of given fields. Can be override in child classes.
Definition: PIMCalendarItem.cpp:215
std::string currentFieldValueOriginal
Definition: PIMCalendarItem.hpp:134
SmartPtr< PIMItemIndex > getIndex()
Returns index for given item.
Definition: PIMCalendarItem.cpp:339
std::map< std::string, std::set< std::string > > getParams() const
Returns all parameters of field.
Definition: PIMCalendarItem.cpp:159
std::string currentFieldName
Definition: PIMCalendarItem.hpp:132
VDayLightTimeZoneKeyValueItem()
Definition: PIMCalendarItem.hpp:152
Special implementation for VSTANDARD item of VTIMEZONE that ignores item.
Definition: PIMCalendarItem.hpp:161
Special implementation for VDAYLIGHT item of VTIMEZONE that ignores item.
Definition: PIMCalendarItem.hpp:149
Class representing PIM item.
Definition: PIMItem.hpp:22
Definition: PIMCalendarItem.hpp:246