PTLib  Version 2.10.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vcard.h
Go to the documentation of this file.
1 /*
2  * vcard.h
3  *
4  * Class to represent and parse a vCard as per RFC2426
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 2010 Vox Lucida Pty Ltd
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Tools Library.
21  *
22  * The Initial Developer of the Original Code is Vox Lucida Pty Ltd
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 26015 $
27  * $Author: rjongbloed $
28  * $Date: 2011-06-14 02:31:10 -0500 (Tue, 14 Jun 2011) $
29  */
30 
31 #ifndef PTLIB_VCARD_H
32 #define PTLIB_VCARD_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 
39 #include <ptclib/url.h>
40 
41 
44 class PvCard : public PObject
45 {
46  PCLASSINFO(PvCard, PObject);
47 
48  public:
49  PvCard();
50 
51  bool IsValid() const;
52 
53  virtual void PrintOn(
54  ostream & strm
55  ) const;
56  virtual void ReadFrom(
57  istream & strm
58  );
59  bool Parse(
60  const PString & str
61  );
62 
70  enum Format {
75  };
77  Format fmt = e_Standard
78  );
79 
81  class Token : public PCaselessString
82  {
83  public:
84  Token(const char * str = NULL) : PCaselessString(str) { Validate(); }
85  Token(const PString & str) : PCaselessString(str) { Validate(); }
86  Token & operator=(const char * str) { PCaselessString::operator=(str); Validate(); return *this; }
87  Token & operator=(const PString & str) { PCaselessString::operator=(str); Validate(); return *this; }
88  virtual void PrintOn(ostream & strm) const;
89  virtual void ReadFrom(istream & strm);
90  private:
91  void Validate();
92  };
93 
94  class Separator : public PObject
95  {
96  public:
97  Separator(char c = '\0') : m_separator(c) { }
98  virtual void PrintOn(ostream & strm) const;
99  virtual void ReadFrom(istream & strm);
100  bool operator==(char c) const { return m_separator == c; }
101  bool operator!=(char c) const { return m_separator != c; }
103  };
104 
106  class ParamValue : public PString
107  {
108  public:
109  ParamValue(const char * str = NULL) : PString(str) { }
110  ParamValue(const PString & str) : PString(str) { }
111  virtual void PrintOn(ostream & strm) const;
112  virtual void ReadFrom(istream & strm);
113  };
115  class ParamValues : public PArray<ParamValue>
116  {
117  public:
118  virtual void PrintOn(ostream & strm) const;
119  virtual void ReadFrom(istream & strm);
120  };
121 
122  typedef std::map<Token, ParamValues> ParamMap;
123 
124  class TypeValues : public ParamValues
125  {
126  public:
128  TypeValues(const ParamValues & values) : ParamValues(values) { }
129  virtual void PrintOn(ostream & strm) const;
130  };
131 
133  class TextValue : public PString
134  {
135  public:
136  TextValue(const char * str = NULL) : PString(str) { }
137  TextValue(const PString & str) : PString(str) { }
138  virtual void PrintOn(ostream & strm) const;
139  virtual void ReadFrom(istream & strm);
140  };
141 
143  class TextValues : public PArray<TextValue>
144  {
145  public:
146  virtual void PrintOn(ostream & strm) const;
147  virtual void ReadFrom(istream & strm);
148  };
149 
150  class URIValue : public PURL
151  {
152  public:
153  URIValue(const char * str = NULL) : PURL(str) { }
154  URIValue(const PString & str) : PURL(str) { }
155  virtual void PrintOn(ostream & strm) const;
156  virtual void ReadFrom(istream & strm);
157  };
158 
160  class InlineValue : public URIValue
161  {
162  public:
163  InlineValue(const char * str = NULL) : URIValue(str), m_params(NULL) { }
164  InlineValue(const PString & str) : URIValue(str), m_params(NULL) { }
165  virtual void PrintOn(ostream & strm) const;
166  virtual void ReadFrom(istream & strm);
167  InlineValue & ReadFromParam(const ParamMap & params);
168  private:
169  const ParamMap * m_params;
170  };
171 
173  TextValue m_fullName; // Mandatory
174  TextValue m_version; // Mandatory
175 
182  TextValue m_sortString; // Form of name for sorting, e.g. family name;
183 
186  InlineValue m_photo; // Possibly embedded via data: scheme
187  InlineValue m_sound; // Possibly embedded via data: scheme
189  double m_latitude;
190  double m_longitude;
191 
194  InlineValue m_logo; // Possibly embedded via data: scheme
198 
202 
208 
209  struct MultiValue : public PObject {
211  MultiValue(const PString & type) { m_types.Append(new ParamValue(type)); }
212 
213  TypeValues m_types; // e.g. "home", "work", "pref" etc
214  void SetTypes(const ParamMap & params);
215  };
216 
217  struct Address : public MultiValue {
218  Address(bool label = false) : m_label(label) { }
219  virtual void PrintOn(ostream & strm) const;
220  virtual void ReadFrom(istream & strm);
221 
222  bool m_label;
225  TextValue m_street; // Including number "123 Main Street"
226  TextValue m_locality; // Suburb/city
227  TextValue m_region; // State/province
230  };
233 
234  struct Telephone : public MultiValue {
235  Telephone() { }
236  Telephone(const PString & number, const PString & type = PString::Empty())
237  : MultiValue(type)
238  , m_number(number)
239  { }
240  virtual void PrintOn(ostream & strm) const;
241 
243  };
245 
246  struct EMail : public MultiValue {
247  EMail() { }
248  EMail(const PString & address, const PString & type = PString::Empty())
249  : MultiValue(type)
250  , m_address(address)
251  { }
252  virtual void PrintOn(ostream & strm) const;
254  };
256 
257  struct ExtendedType {
260  };
261 
262  typedef std::map<Token, ExtendedType> ExtendedTypeMap;
264 };
265 
266 
267 #endif // PTLIB_VCARD_H
268 
269 
270 // End of File ///////////////////////////////////////////////////////////////