3 /// Base class for vformat support
7 Copyright (C) 2006-2007, 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
<VFormatAttribute
, VFormatAttribute
, &vformat_attribute_free
> vAttrPtr
;
115 typedef vSmartPtr
<VFormatParam
, VFormatParam
, &vformat_attribute_param_free
> vParamPtr
;
116 typedef vSmartPtr
<char, void, &g_free
> gStringPtr
;
122 /// Class for reading a VFormatAttribute. Reading does not require
123 /// memory management, so none is done.
127 VFormatAttribute
*m_attr
;
135 vAttr(VFormatAttribute
*attr
)
140 vAttr
& operator=(VFormatAttribute
*attr
)
146 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);
160 /// Base class containing vformat helper API.
164 // internal data for managing the vformat
168 // FIXME - if you put this class in the Barry library,
169 // you'll need to change the class hierarchy
170 class ConvertError
: public std::runtime_error
173 ConvertError(const std::string
&msg
) : std::runtime_error(msg
) {}
180 VFormat
* Format() { return m_format
; }
181 const VFormat
* Format() const { return m_format
; }
182 void SetFormat(VFormat
*format
);
186 vAttrPtr
NewAttr(const char *name
);
187 vAttrPtr
NewAttr(const char *name
, const char *value
);
188 void AddAttr(vAttrPtr attr
);
189 void AddValue(vAttrPtr
&attr
, const char *value
);
190 void AddParam(vAttrPtr
&attr
, const char *name
, const char *value
);
192 std::string
GetAttr(const char *attrname
, const char *block
= 0);
193 vAttr
GetAttrObj(const char *attrname
, int nth
= 0, const char *block
= 0);