- applied memos and tasks patch from Brian Edginton, slightly
[barry.git] / src / r_memo.cc
blob6c0328cd53ccbaeaa3b7c50cc717b5ad4a12569f
1 ///////////////////////////////////////////////////////////////////////////////
2 // Memo Class
4 // Memo Field Codes
5 #define MEMFC_TITLE 0x01
6 #define MEMFC_BODY 0x02
7 #define MEMFC_MEMO_TYPE 0x03
8 #define MEMFC_CATEGORY 0x04
9 #define MEMFC_END 0xffff
11 FieldLink<Memos> MemosFieldLinks[] = {
12 { MEMFC_TITLE, "Title", 0, 0, &Memos::Title, 0, 0 },
13 { MEMFC_BODY, "Body", 0, 0, &Memos::Body, 0, 0 },
14 { MEMFC_CATEGORY, "Category", 0, 0, &Memos::Category, 0, 0 },
15 { MEMFC_END, "End of List", 0, 0, 0, 0, 0 }
18 Memos::Memos()
20 Clear();
23 Memos::~Memos()
27 const unsigned char* Memos::ParseField(const unsigned char *begin,
28 const unsigned char *end)
30 const CommonField *field = (const CommonField *) begin;
32 // advance and check size
33 begin += COMMON_FIELD_HEADER_SIZE + btohs(field->size);
34 if( begin > end ) // if begin==end, we are ok
35 return begin;
37 if( !btohs(field->size) ) // if field has no size, something's up
38 return begin;
40 if( field->type == MEMFC_MEMO_TYPE ) {
41 if( ( MemoType = field->u.raw[0] ) != 'm' ) {
42 throw Error( "Memos::ParseField: MemoType is not 'm'" );
44 return begin;
48 // cycle through the type table
49 for( FieldLink<Memos> *b = MemosFieldLinks;
50 b->type != MEMFC_END;
51 b++ )
53 if( b->type == field->type ) {
54 if( b->strMember ) {
55 std::string &s = this->*(b->strMember);
56 s.assign((const char *)field->u.raw, btohs(field->size)-1);
57 return begin; // done!
59 else if( b->timeMember && btohs(field->size) == 4 ) {
60 time_t &t = this->*(b->timeMember);
61 t = min2time(field->u.min1900);
62 return begin;
66 // if still not handled, add to the Unknowns list
67 UnknownField uf;
68 uf.type = field->type;
69 uf.data.assign((const char*)field->u.raw, btohs(field->size));
70 Unknowns.push_back(uf);
72 // return new pointer for next field
73 return begin;
76 void Memos::ParseHeader(const Data &data, size_t &offset)
78 // no header in Memos records
81 void Memos::ParseFields(const Data &data, size_t &offset)
83 const unsigned char *finish = ParseCommonFields(*this,
84 data.GetData() + offset, data.GetData() + data.GetSize());
85 offset += finish - (data.GetData() + offset);
89 void Memos::Dump(std::ostream &os) const
91 os << "Memos entry: 0x" << setbase(16) << RecordId
92 << " (" << (unsigned int)RecType << ")\n";
93 os << " Title: " << Title << "\n";
94 os << " Body: " << Body << "\n";
95 os << " Category: " << Category << "\n";
97 os << Unknowns;
98 os << "\n\n";
101 void Memos::Clear()
103 Title.clear();
104 Body.clear();
105 Category.clear();
107 MemoType = 0;
109 Unknowns.clear();