r_servicebook.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_servicebook.h
00003 ///             Blackberry database record parser class for the
00004 ///             Service Book record.
00005 ///
00006 
00007 /*
00008     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #ifndef __BARRY_RECORD_SERVICEBOOK_H__
00024 #define __BARRY_RECORD_SERVICEBOOK_H__
00025 
00026 #include "dll.h"
00027 #include "record.h"
00028 #include <iosfwd>
00029 #include <string>
00030 #include <vector>
00031 #include <map>
00032 #include <stdint.h>
00033 
00034 namespace Barry {
00035 
00036 // forward declarations
00037 class IConverter;
00038 
00039 //
00040 // NOTE:  All classes here must be container-safe!  Perhaps add sorting
00041 //        operators in the future.
00042 //
00043 
00044 
00045 /// \addtogroup RecordParserClasses
00046 /// @{
00047 
00048 // This is a packed field, which is a group of fields packed in
00049 // variable length records inside one larger field of a normal record.
00050 class BXEXPORT ServiceBookConfig
00051 {
00052 public:
00053         typedef Barry::UnknownsType                     UnknownsType;
00054 
00055         uint8_t Format;
00056 
00057         UnknownsType Unknowns;
00058 
00059 public:
00060         const unsigned char* ParseField(const unsigned char *begin,
00061                 const unsigned char *end, const IConverter *ic = 0);
00062 
00063 public:
00064         ServiceBookConfig();
00065         ~ServiceBookConfig();
00066 
00067         // Parser / Builder API (see parser.h / builder.h)
00068         void Validate() const;
00069         void ParseHeader(const Data &data, size_t &offset);
00070         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00071         void BuildHeader(Data &data, size_t &offset) const;
00072         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00073 
00074         void Clear();
00075 
00076         void Dump(std::ostream &os) const;
00077 };
00078 
00079 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const ServiceBookConfig &msg) {
00080         msg.Dump(os);
00081         return os;
00082 }
00083 
00084 
00085 class ServiceBookData;
00086 
00087 class BXEXPORT ServiceBook
00088 {
00089         ServiceBookData *m_data;
00090 
00091 public:
00092         typedef std::vector<UnknownField>               UnknownsType;
00093 
00094         uint8_t RecType;
00095         uint32_t RecordId;
00096         std::string Name;
00097         std::string HiddenName;
00098         std::string Description;
00099         std::string DSID;
00100         std::string BesDomain;
00101         std::string UniqueId;
00102         std::string ContentId;
00103         ServiceBookConfig Config;
00104 
00105         UnknownsType Unknowns;
00106 
00107 public:
00108         const unsigned char* ParseField(const unsigned char *begin,
00109                 const unsigned char *end, const IConverter *ic = 0);
00110 
00111 public:
00112         ServiceBook();
00113         ~ServiceBook();
00114 
00115         // Parser / Builder API (see parser.h / builder.h)
00116         void Validate() const;
00117         uint8_t GetRecType() const { return RecType; }
00118         uint32_t GetUniqueId() const { return RecordId; }
00119         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00120         void ParseHeader(const Data &data, size_t &offset);
00121         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00122         void BuildHeader(Data &data, size_t &offset) const;
00123         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00124 
00125         // operations (common among record classes)
00126         void Clear();
00127         void Dump(std::ostream &os) const;
00128         std::string GetDescription() const;
00129 
00130         // sorting
00131         bool operator<(const ServiceBook &other) const;
00132 
00133         // database name
00134         static const char * GetDBName() { return "Service Book"; }
00135         static uint8_t GetDefaultRecType() { return 0; }
00136 
00137         // Generic Field Handle support
00138         static const FieldHandle<ServiceBook>::ListT& GetFieldHandles();
00139 };
00140 
00141 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const ServiceBook &msg) {
00142         msg.Dump(os);
00143         return os;
00144 }
00145 
00146 /// @}
00147 
00148 } // namespace Barry
00149 
00150 #endif
00151