3 /// Base class for vformat support
7 Copyright (C) 2006-2009, 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__
29 // forward declarations
30 class BarryEnvironment
;
33 // FIXME - possibly scrap this in favour of opensync's xml time routines,
34 // but this will require an overhaul of the plugin itself.
40 bool m_daylightSaving
;
42 std::string m_dtstart
;
43 std::string m_tzoffsetfrom
;
44 std::string m_tzoffsetto
;
61 /// used for comparing by TZID
62 bool operator==(const std::string
&tzid
) const;
66 // A special smart pointer for vformat pointer handling.
67 // Behaves like std::auto_ptr<> in that only one object
68 // at a time owns the pointer, and destruction frees it.
69 template <class T
, class FT
, void (*FreeFunc
)(FT
*pt
)>
75 vSmartPtr() : m_pt(0) {}
76 vSmartPtr(T
*pt
) : m_pt(pt
) {}
77 vSmartPtr(const vSmartPtr
&sp
) : m_pt(sp
.m_pt
)
87 vSmartPtr
& operator=(T
*pt
)
94 vSmartPtr
& operator=(const vSmartPtr
&sp
)
114 typedef vSmartPtr
<b_VFormatAttribute
, b_VFormatAttribute
, &b_vformat_attribute_free
> vAttrPtr
;
115 typedef vSmartPtr
<b_VFormatParam
, b_VFormatParam
, &b_vformat_attribute_param_free
> vParamPtr
;
116 typedef vSmartPtr
<char, void, &g_free
> gStringPtr
;
122 /// Class for reading a b_VFormatAttribute. Reading does not require
123 /// memory management, so none is done.
127 b_VFormatAttribute
*m_attr
;
135 vAttr(b_VFormatAttribute
*attr
)
140 vAttr
& operator=(b_VFormatAttribute
*attr
)
146 b_VFormatAttribute
* Get() { return m_attr
; }
148 // These functions do not throw an error if the value
149 // is NULL or does not exist (for example, if you ask for
150 // value #5 and there are only 4).
151 std::string
GetName();
152 std::string
GetValue(int nth
= 0);
153 std::string
GetParam(const char *name
, int nth
= 0);
154 std::string
GetAllParams(const char *name
);
161 /// Base class containing vformat helper API.
165 // internal data for managing the vformat
169 // FIXME - if you put this class in the Barry library,
170 // you'll need to change the class hierarchy
171 class ConvertError
: public std::runtime_error
174 ConvertError(const std::string
&msg
) : std::runtime_error(msg
) {}
181 b_VFormat
* Format() { return m_format
; }
182 const b_VFormat
* Format() const { return m_format
; }
183 void SetFormat(b_VFormat
*format
);
187 vAttrPtr
NewAttr(const char *name
);
188 vAttrPtr
NewAttr(const char *name
, const char *value
);
189 void AddAttr(vAttrPtr attr
);
190 void AddValue(vAttrPtr
&attr
, const char *value
);
191 void AddParam(vAttrPtr
&attr
, const char *name
, const char *value
);
193 std::string
GetAttr(const char *attrname
, const char *block
= 0);
194 vAttr
GetAttrObj(const char *attrname
, int nth
= 0, const char *block
= 0);