vbase.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __BARRY_SYNC_VBASE_H__
00023 #define __BARRY_SYNC_VBASE_H__
00024
00025 #include "dll.h"
00026 #include "vsmartptr.h"
00027 #include "vformat.h"
00028 #include "error.h"
00029 #include <vector>
00030
00031 namespace Barry { namespace Sync {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class BXEXPORT vTimeConverter
00045 {
00046 public:
00047 virtual ~vTimeConverter() {}
00048
00049
00050
00051
00052 virtual std::string unix2vtime(const time_t *timestamp);
00053
00054
00055
00056
00057 virtual time_t vtime2unix(const char *vtime);
00058
00059
00060
00061
00062
00063 virtual int alarmduration2sec(const char *alarm);
00064 };
00065
00066
00067 typedef Barry::vSmartPtr<b_VFormatAttribute, b_VFormatAttribute, &b_vformat_attribute_free> vAttrPtr;
00068 typedef Barry::vSmartPtr<b_VFormatParam, b_VFormatParam, &b_vformat_attribute_param_free> vParamPtr;
00069 typedef Barry::vSmartPtr<char, void, &g_free> gStringPtr;
00070
00071
00072
00073
00074
00075
00076
00077
00078 class BXEXPORT vAttr
00079 {
00080 b_VFormatAttribute *m_attr;
00081
00082 public:
00083 vAttr()
00084 : m_attr(0)
00085 {
00086 }
00087
00088 vAttr(b_VFormatAttribute *attr)
00089 : m_attr(attr)
00090 {
00091 }
00092
00093 vAttr& operator=(b_VFormatAttribute *attr)
00094 {
00095 m_attr = attr;
00096 return *this;
00097 }
00098
00099 b_VFormatAttribute* Get() { return m_attr; }
00100
00101
00102
00103
00104 std::string GetName();
00105 std::string GetValue(int nth = 0);
00106 std::string GetDecodedValue();
00107 std::string GetParam(const char *name, int nth = 0);
00108 std::string GetAllParams(const char *name);
00109 };
00110
00111
00112
00113
00114
00115
00116
00117 class BXEXPORT vBase
00118 {
00119
00120 b_VFormat *m_format;
00121
00122 public:
00123 protected:
00124 vBase();
00125 explicit vBase(b_VFormat *format);
00126 virtual ~vBase();
00127
00128 b_VFormat* Format() { return m_format; }
00129 const b_VFormat* Format() const { return m_format; }
00130 void SetFormat(b_VFormat *format);
00131
00132 void Clear();
00133
00134 vAttrPtr NewAttr(const char *name);
00135 vAttrPtr NewAttr(const char *name, const char *value);
00136 void AddAttr(vAttrPtr attr);
00137 void AddValue(vAttrPtr &attr, const char *value);
00138 void AddEncodedValue(vAttrPtr &attr, b_VFormatEncoding encoding, const char *value, int len);
00139 void AddParam(vAttrPtr &attr, const char *name, const char *value);
00140
00141 std::string GetAttr(const char *attrname, const char *block = 0);
00142 std::vector<std::string> GetValueVector(const char *attrname, const char *block = 0);
00143 vAttr GetAttrObj(const char *attrname, int nth = 0, const char *block = 0);
00144
00145 std::vector<std::string> Tokenize(const std::string &str, const char delim = ',');
00146 std::string ToStringList(const std::vector<std::string> &list, const char delim = ',');
00147 };
00148
00149 }}
00150
00151 #endif
00152