3 /// Base class for vformat support
7 Copyright (C) 2006-2010, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_SYNC_VBASE_H__
23 #define __BARRY_SYNC_VBASE_H__
26 #include "vsmartptr.h"
31 namespace Barry
{ namespace Sync
{
36 /// A virtual base class that the plugins may override, to do
37 /// time related conversions. Default implementations for these
38 /// functions are provided, but may be overrided depending on need.
40 /// We do this in a "callback" style, so that it doesn't matter what
41 /// version of the opensync library we link against, in case the
42 /// user wishes to use the opensync time functions.
44 class BXEXPORT vTimeConverter
47 virtual ~vTimeConverter() {}
49 /// Convert a time_t into an ISO timestamp string
50 /// Throws Barry::ConvertError on error, but these errors
52 virtual std::string
unix2vtime(const time_t *timestamp
);
54 /// Convert an ISO timestamp string into a time_t, using
55 /// the current system timezone if vtime is not in UTC.
56 /// Returns (time_t)-1 on error.
57 virtual time_t vtime2unix(const char *vtime
);
59 /// Convert a VEVENT alarm duration string in the format
60 /// of "[+-]P.W.DT.H.M.S" where the periods represent numbers
61 /// and each letter besides P and T represent Week, Day,
62 /// Hour, Minute, and Second respectively.
63 virtual int alarmduration2sec(const char *alarm
);
67 typedef Barry::vSmartPtr
<b_VFormatAttribute
, b_VFormatAttribute
, &b_vformat_attribute_free
> vAttrPtr
;
68 typedef Barry::vSmartPtr
<b_VFormatParam
, b_VFormatParam
, &b_vformat_attribute_param_free
> vParamPtr
;
69 typedef Barry::vSmartPtr
<char, void, &g_free
> gStringPtr
;
75 /// Class for reading a b_VFormatAttribute. Reading does not require
76 /// memory management, so none is done.
80 b_VFormatAttribute
*m_attr
;
88 vAttr(b_VFormatAttribute
*attr
)
93 vAttr
& operator=(b_VFormatAttribute
*attr
)
99 b_VFormatAttribute
* Get() { return m_attr
; }
101 // These functions do not throw an error if the value
102 // is NULL or does not exist (for example, if you ask for
103 // value #5 and there are only 4).
104 std::string
GetName();
105 std::string
GetValue(int nth
= 0);
106 std::string
GetDecodedValue();
107 std::string
GetParam(const char *name
, int nth
= 0);
108 std::string
GetAllParams(const char *name
);
115 /// Base class containing vformat helper API.
119 // internal data for managing the vformat
127 b_VFormat
* Format() { return m_format
; }
128 const b_VFormat
* Format() const { return m_format
; }
129 void SetFormat(b_VFormat
*format
);
133 vAttrPtr
NewAttr(const char *name
);
134 vAttrPtr
NewAttr(const char *name
, const char *value
);
135 void AddAttr(vAttrPtr attr
);
136 void AddValue(vAttrPtr
&attr
, const char *value
);
137 void AddEncodedValue(vAttrPtr
&attr
, b_VFormatEncoding encoding
, const char *value
, int len
);
138 void AddParam(vAttrPtr
&attr
, const char *name
, const char *value
);
140 std::string
GetAttr(const char *attrname
, const char *block
= 0);
141 std::vector
<std::string
> GetValueVector(const char *attrname
, const char *block
= 0);
142 vAttr
GetAttrObj(const char *attrname
, int nth
= 0, const char *block
= 0);
144 std::vector
<std::string
> Tokenize(const std::string
&str
, const char delim
= ',');
145 std::string
ToStringList(const std::vector
<std::string
> &list
, const char delim
= ',');
148 }} // namespace Barry::Sync