1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* palm-db-tools: Raw PalmOS Records
* Copyright (C) 2000 by Tom Dyas (tdyas@users.sourceforge.net)
*/
#ifndef __PALMLIB_RECORD_H__
#define __PALMLIB_RECORD_H__
#include "Block.h"
namespace PalmLib {
class Record : public Block {
public:
#ifdef __GNUG__
static const pi_char_t FLAG_ATTR_DELETED = 0x80;
static const pi_char_t FLAG_ATTR_DIRTY = 0x40;
static const pi_char_t FLAG_ATTR_BUSY = 0x20;
static const pi_char_t FLAG_ATTR_SECRET = 0x10;
#else
static const pi_char_t FLAG_ATTR_DELETED;
static const pi_char_t FLAG_ATTR_DIRTY;
static const pi_char_t FLAG_ATTR_BUSY;
static const pi_char_t FLAG_ATTR_SECRET;
#endif
/**
* Default constructor.
*/
Record() : Block(), m_attrs(0), m_unique_id(0) { }
/**
* Copy constructor.
*/
Record(const Record& rhs) : Block(rhs.data(), rhs.size()) {
m_attrs = rhs.attrs();
m_unique_id = rhs.unique_id();
}
/**
* Destructor.
*/
virtual ~Record() { }
/**
* Constructor which lets the caller specify all the
* parameters.
*
* @param attrs Attribute byte (flags + category).
* @param unique_id Unique ID for this record.
* @param data Start of buffer to copy (or 0 for empty).
* @param size Size of the buffer to copy.
*/
Record(pi_char_t attrs, pi_uint32_t unique_id,
Block::const_pointer data, const Block::size_type size)
: Block(data, size), m_attrs(attrs), m_unique_id(unique_id) { }
/**
* Constructor which lets the caller use the default fill
* constructor.
* @param attrs Attribute byte (flags + category).
* @param unique_id Unique ID for this record.
* @param size Size of buffer to generate.
* @param value Value to fill buffer with.
*/
Record(pi_char_t attrs, pi_uint32_t unique_id,
const size_type size, const value_type value = 0)
: Block(size, value), m_attrs(attrs), m_unique_id(unique_id) { }
/**
* Assignment operator.
*
* @param rhs The PalmLib::Record we should become. */
Record& operator = (const Record& rhs) {
Block::operator = (rhs);
m_attrs = rhs.attrs();
m_unique_id = rhs.unique_id();
return *this;
}
/**
* Return the attributes byte which contains the category and
* flags.
*/
pi_char_t attrs() const { return m_attrs; }
/**
* Return the state of the record's "deleted" flag.
*/
bool deleted() const { return (m_attrs & FLAG_ATTR_DELETED) != 0; }
/**
* Set the state of the record's "deleted" flag.
*
* @param state New state of the "deleted" flag.
*/
void deleted(bool state) {
if (state)
m_attrs |= FLAG_ATTR_DELETED;
else
m_attrs &= ~(FLAG_ATTR_DELETED);
}
/**
* Return the state of the record's "dirty" flag.
*/
bool dirty() const { return (m_attrs & FLAG_ATTR_DIRTY) != 0; }
/**
* Set the state of the record's "dirty" flag.
*
* @param state New state of the "dirty" flag.
*/
void dirty(bool state) {
if (state)
m_attrs |= FLAG_ATTR_DIRTY;
else
m_attrs &= ~(FLAG_ATTR_DIRTY);
}
/**
* Return the state of the record's "secret" flag.
*/
bool secret() const { return (m_attrs & FLAG_ATTR_SECRET) != 0; }
/**
* Set the state of the record's "secret" flag.
*
* @param state New state of the "secret" flag.
*/
void secret(bool state) {
if (state)
m_attrs |= FLAG_ATTR_SECRET;
else
m_attrs &= ~(FLAG_ATTR_SECRET);
}
/**
* Return the category of this record.
*/
pi_char_t category() const { return (m_attrs & 0x0F); }
/**
* Set the category of this record.
*/
void category(pi_char_t cat)
{ m_attrs &= ~(0x0F); m_attrs |= (cat & 0x0F); }
/**
* Return the unique ID of this record.
*/
pi_uint32_t unique_id() const { return m_unique_id; }
/**
* Set the unique ID of this record to uid.
*
* @param uid New unique ID for this record.
*/
void unique_id(pi_uint32_t uid) { m_unique_id = uid; }
private:
pi_char_t m_attrs;
pi_uint32_t m_unique_id;
};
}
#endif
|