desktop: CalEditDlg: fixed dialog title bar
[barry.git] / src / vbase.h
blobf2184fb83c10131bb35dbc2ebe42972cee26be04
1 ///
2 /// \file vbase.h
3 /// Base class for vformat support
4 ///
6 /*
7 Copyright (C) 2006-2012, 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__
25 #include "dll.h"
26 #include "vsmartptr.h"
27 #include "vformat.h"
28 #include "error.h"
29 #include <vector>
31 namespace Barry { namespace Sync {
34 // vTimeConverter
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.
39 ///
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.
43 ///
44 class BXEXPORT vTimeConverter
46 public:
47 virtual ~vTimeConverter() {}
49 /// Convert a time_t into an ISO timestamp string
50 /// Throws Barry::ConvertError on error, but these errors
51 /// must be rare.
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;
73 // vAttr
75 /// Class for reading a b_VFormatAttribute. Reading does not require
76 /// memory management, so none is done.
77 ///
78 class BXEXPORT vAttr
80 b_VFormatAttribute *m_attr;
82 public:
83 vAttr()
84 : m_attr(0)
88 vAttr(b_VFormatAttribute *attr)
89 : m_attr(attr)
93 vAttr& operator=(b_VFormatAttribute *attr)
95 m_attr = attr;
96 return *this;
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);
113 // vBase
115 /// Base class containing vformat helper API.
117 class BXEXPORT vBase
119 // internal data for managing the vformat
120 b_VFormat *m_format;
122 public:
123 protected:
124 vBase();
125 explicit vBase(b_VFormat *format);
126 virtual ~vBase();
128 b_VFormat* Format() { return m_format; }
129 const b_VFormat* Format() const { return m_format; }
130 void SetFormat(b_VFormat *format);
132 void Clear();
134 vAttrPtr NewAttr(const char *name);
135 vAttrPtr NewAttr(const char *name, const char *value);
136 void AddAttr(vAttrPtr attr);
137 void AddValue(vAttrPtr &attr, const char *value);
138 void AddEncodedValue(vAttrPtr &attr, b_VFormatEncoding encoding, const char *value, int len);
139 void AddParam(vAttrPtr &attr, const char *name, const char *value);
141 std::string GetAttr(const char *attrname, const char *block = 0);
142 std::vector<std::string> GetValueVector(const char *attrname, const char *block = 0);
143 vAttr GetAttrObj(const char *attrname, int nth = 0, const char *block = 0);
145 std::vector<std::string> Tokenize(const std::string &str, const char delim = ',');
146 std::string ToStringList(const std::vector<std::string> &list, const char delim = ',');
149 }} // namespace Barry::Sync
151 #endif