r_contact.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_contact.h
00003 ///             Blackberry database record parser class for contact records.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_RECORD_CONTACT_H__
00023 #define __BARRY_RECORD_CONTACT_H__
00024 
00025 #include "dll.h"
00026 #include "record.h"
00027 #include <iosfwd>
00028 #include <string>
00029 #include <vector>
00030 #include <map>
00031 #include <stdint.h>
00032 
00033 namespace Barry {
00034 
00035 //
00036 // NOTE:  All classes here must be container-safe!  Perhaps add sorting
00037 //        operators in the future.
00038 //
00039 
00040 struct BXEXPORT ContactGroupLink
00041 {
00042         uint32_t Link;
00043         uint16_t Unknown;
00044 
00045         ContactGroupLink() : Link(0), Unknown(0) {}
00046         ContactGroupLink(uint32_t link, uint16_t unknown)
00047                 : Link(link), Unknown(unknown)
00048         {}
00049 };
00050 
00051 typedef std::vector<std::string> CategoryList;
00052 
00053 /// \addtogroup RecordParserClasses
00054 /// @{
00055 
00056 class BXEXPORT Contact
00057 {
00058 public:
00059         typedef Barry::CategoryList                     CategoryList;
00060         typedef ContactGroupLink                        GroupLink;
00061         typedef std::vector<GroupLink>                  GroupLinksType;
00062         typedef std::vector<UnknownField>               UnknownsType;
00063         typedef std::string                             EmailType;
00064         typedef std::vector<EmailType>                  EmailList;
00065 
00066         // contact specific data
00067         uint8_t RecType;
00068         uint32_t RecordId;
00069         EmailList EmailAddresses;
00070         std::string
00071                 Phone,
00072                 Fax,
00073                 WorkPhone,
00074                 HomePhone,
00075                 MobilePhone,
00076                 Pager,
00077                 PIN,
00078                 Radio,
00079                 WorkPhone2,
00080                 HomePhone2,
00081                 OtherPhone,
00082                 FirstName,
00083                 LastName,
00084                 Company,
00085                 DefaultCommunicationsMethod,
00086                 JobTitle,
00087                 PublicKey,
00088                 URL,
00089                 Prefix,
00090                 Notes,
00091                 UserDefined1,
00092                 UserDefined2,
00093                 UserDefined3,
00094                 UserDefined4,
00095                 Image;
00096 
00097         Date Birthday;
00098         Date Anniversary;
00099 
00100         PostalAddress WorkAddress;
00101         PostalAddress HomeAddress;
00102 
00103         // Categories are not allowed to have commas in them.
00104         // A category name containing a comma will be split into
00105         // two categories, not only by this library, but by the
00106         // device itself.
00107         CategoryList Categories;
00108 
00109         GroupLinksType GroupLinks;
00110         UnknownsType Unknowns;
00111 
00112 private:
00113         bool m_FirstNameSeen;
00114 
00115 //protected:
00116 public:
00117         const unsigned char* ParseField(const unsigned char *begin,
00118                 const unsigned char *end);
00119 
00120 public:
00121         Contact();
00122         ~Contact();
00123 
00124         uint32_t GetID() const { return RecordId; }
00125         std::string GetFullName() const;
00126         const std::string& GetEmail(unsigned int index = 0) const;
00127 
00128         // Parser / Builder API (see parser.h / builder.h)
00129         uint8_t GetRecType() const { return RecType; }
00130         uint32_t GetUniqueId() const { return RecordId; }
00131         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00132         void ParseHeader(const Data &data, size_t &offset);
00133         void ParseFields(const Data &data, size_t &offset);
00134         void BuildHeader(Data &data, size_t &offset) const;
00135         void BuildFields(Data &data, size_t &offset) const;
00136 
00137         void Clear();                   // erase everything
00138 
00139         void Dump(std::ostream &os) const;
00140 
00141         // sorting - put group links at the end
00142         bool operator<(const Contact &other) const {
00143                 return GroupLinks.size() == 0 && other.GroupLinks.size() > 0;
00144 //              // testing - put group links at the top
00145 //              return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
00146         }
00147 
00148         // database name
00149         static const char * GetDBName() { return "Address Book"; }
00150         static uint8_t GetDefaultRecType() { return 0; }
00151 
00152         // helpers
00153         static void SplitName(const std::string &full, std::string &first, std::string &last);
00154         static void CategoryStr2List(const std::string &str, Barry::CategoryList &list);
00155         static void CategoryList2Str(const Barry::CategoryList &list, std::string &str);
00156 };
00157 
00158 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
00159         contact.Dump(os);
00160         return os;
00161 }
00162 
00163 /// @}
00164 
00165 } // namespace Barry
00166 
00167 #endif
00168 

Generated on Wed Sep 24 21:27:32 2008 for Barry by  doxygen 1.5.1