r_memo.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_memo.h
00003 ///             Record parsing class for the memo database.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008     Copyright (C) 2007, Brian Edginton
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_MEMO_H__
00024 #define __BARRY_RECORD_MEMO_H__
00025 
00026 #include "dll.h"
00027 #include "record.h"
00028 #include <vector>
00029 #include <string>
00030 #include <stdint.h>
00031 
00032 namespace Barry {
00033 
00034 // forward declarations
00035 class IConverter;
00036 
00037 class BXEXPORT Memo
00038 {
00039 public:
00040         typedef Barry::UnknownsType                     UnknownsType;
00041 
00042         uint8_t RecType;
00043         uint32_t RecordId;
00044 
00045         std::string Title;
00046         std::string Body;
00047         CategoryList Categories;
00048 
00049         UnknownsType Unknowns;
00050 
00051 public:
00052         const unsigned char* ParseField(const unsigned char *begin,
00053                 const unsigned char *end, const IConverter *ic = 0);
00054 
00055 public:
00056         Memo();
00057         ~Memo();
00058 
00059         // Parser / Builder API (see parser.h / builder.h)
00060         void Validate() const;
00061         uint8_t GetRecType() const { return RecType; }
00062         uint32_t GetUniqueId() const { return RecordId; }
00063         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00064         void ParseHeader(const Data &data, size_t &offset);
00065         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00066         void BuildHeader(Data &data, size_t &offset) const;
00067         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00068 
00069         // operations (common among record classes)
00070         void Clear();
00071         void Dump(std::ostream &os) const;
00072         std::string GetDescription() const;
00073 
00074         bool operator<(const Memo &other) const;
00075 
00076         // database name
00077         static const char * GetDBName() { return "Memos"; }
00078         static uint8_t GetDefaultRecType() { return 0; }    // or 0?
00079 
00080         // Generic Field Handle support
00081         static const FieldHandle<Memo>::ListT& GetFieldHandles();
00082 };
00083 
00084 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const Memo &msg) {
00085         msg.Dump(os);
00086         return os;
00087 }
00088 
00089 } // namespace Barry
00090 
00091 #endif
00092