@@ -44,48 +44,47 @@ namespace m_bmqstoragetool {
44
44
45
45
class CompositeSequenceNumber {
46
46
private:
47
- // DATA
48
- unsigned int d_leaseId;
49
- // Primary Lease Id
50
- bsls::Types::Uint64 d_seqNumber;
51
- // Sequence Number
52
- bool d_isSet;
53
- // Set to `true` if the value of this object is set
47
+ // PRIVATE DATA
48
+
49
+ // / Pair of primary lease Id and sequence number
50
+ bsl::pair<unsigned int , bsls::Types::Uint64> d_compositeSequenceNumber;
54
51
55
52
public:
56
53
// CREATORS
57
54
58
- // / Create an un-initialized CompositeSequenceNumber. Note that
59
- // / `isSet()` would return false.
55
+ // / Create CompositeSequenceNumber with zero initialized values.
60
56
CompositeSequenceNumber ();
61
57
62
58
// / Create CompositeSequenceNumber from the specified `leaseId` and
63
59
// / `sequenceNumber`
64
- CompositeSequenceNumber (const unsigned int leaseId,
65
- const bsls::Types::Uint64 sequenceNumber);
60
+ CompositeSequenceNumber (unsigned int leaseId,
61
+ bsls::Types::Uint64 sequenceNumber);
66
62
67
63
// MANIPULATORS
68
64
69
65
// / Initialize this CompositeSequenceNumber from the specified
70
66
// / `seqNumString` representation in format `<leaseId>-<sequenceNumber>`.
71
67
// / Return a reference offering modifiable access to this object. If
72
- // / convertion is successfull, `isSet()` would return `true`. Otherwise,
73
- // / `isSet()` would return `false` and specified `errorDescription` is
68
+ // / convertion is successfull, `success` value is set to `true`. Otherwise,
69
+ // / `success` value is set to `false` and specified `errorDescription` is
74
70
// / filled with error description.
75
- CompositeSequenceNumber& fromString (bsl::ostream& errorDescription,
71
+ CompositeSequenceNumber& fromString (bool * success,
72
+ bsl::ostream& errorDescription,
76
73
const bsl::string& seqNumString);
77
74
78
75
// ACCESSORS
79
76
80
- // / Return `true` if the value of this object is not set.
81
- bool isSet () const ;
82
-
83
- // / Return Primary Lease Id value.
77
+ // / Return primary Lease Id value.
84
78
unsigned int leaseId () const ;
85
79
86
- // / Return Sequence Number value.
80
+ // / Return sequence number value.
87
81
bsls::Types::Uint64 sequenceNumber () const ;
88
82
83
+ // / Return the const reference to composite sequence number as a pair of
84
+ // / primary lease Id and sequence number.
85
+ const bsl::pair<unsigned int , bsls::Types::Uint64>&
86
+ compositeSequenceNumber () const ;
87
+
89
88
// / Write the value of this object to the specified output `stream` in a
90
89
// / human-readable format, and return a reference to `stream`.
91
90
// / Optionally specify an initial indentation `level`. If `level` is
@@ -139,19 +138,20 @@ bool operator<=(const CompositeSequenceNumber& lhs,
139
138
140
139
// ACCESSORS
141
140
142
- inline bool CompositeSequenceNumber::isSet () const
141
+ inline unsigned int CompositeSequenceNumber::leaseId () const
143
142
{
144
- return d_isSet ;
143
+ return d_compositeSequenceNumber. first ;
145
144
}
146
145
147
- inline unsigned int CompositeSequenceNumber::leaseId () const
146
+ inline bsls::Types::Uint64 CompositeSequenceNumber::sequenceNumber () const
148
147
{
149
- return d_leaseId ;
148
+ return d_compositeSequenceNumber. second ;
150
149
}
151
150
152
- inline bsls::Types::Uint64 CompositeSequenceNumber::sequenceNumber () const
151
+ inline const bsl::pair<unsigned int , bsls::Types::Uint64>&
152
+ CompositeSequenceNumber::compositeSequenceNumber () const
153
153
{
154
- return d_seqNumber ;
154
+ return d_compositeSequenceNumber ;
155
155
}
156
156
157
157
} // close package namespace
@@ -166,51 +166,28 @@ inline bsl::ostream& m_bmqstoragetool::operator<<(
166
166
bsl::ostream& stream,
167
167
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
168
168
{
169
- // PRECONDITIONS
170
- BSLS_ASSERT (rhs.isSet ());
171
-
172
169
return rhs.print (stream, 0 , -1 );
173
170
}
174
171
175
172
inline bool m_bmqstoragetool::operator ==(
176
173
const m_bmqstoragetool::CompositeSequenceNumber& lhs,
177
174
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
178
175
{
179
- // PRECONDITIONS
180
- BSLS_ASSERT (lhs.isSet () && rhs.isSet ());
181
-
182
- return (lhs.leaseId () == rhs.leaseId () &&
183
- lhs.sequenceNumber () == rhs.sequenceNumber ());
176
+ return lhs.compositeSequenceNumber () == rhs.compositeSequenceNumber ();
184
177
}
185
178
186
179
inline bool m_bmqstoragetool::operator <(
187
180
const m_bmqstoragetool::CompositeSequenceNumber& lhs,
188
181
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
189
182
{
190
- // PRECONDITIONS
191
- BSLS_ASSERT (lhs.isSet () && rhs.isSet ());
192
-
193
- // Check leaseId first
194
- if (lhs.leaseId () < rhs.leaseId ()) {
195
- return true ; // RETURN
196
- }
197
- else if (lhs.leaseId () == rhs.leaseId ()) {
198
- if (lhs.sequenceNumber () < rhs.sequenceNumber ()) {
199
- return true ; // RETURN
200
- }
201
- }
202
-
203
- return false ;
183
+ return lhs.compositeSequenceNumber () < rhs.compositeSequenceNumber ();
204
184
}
205
185
206
186
inline bool m_bmqstoragetool::operator <=(
207
187
const m_bmqstoragetool::CompositeSequenceNumber& lhs,
208
188
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
209
189
{
210
- // PRECONDITIONS
211
- BSLS_ASSERT (lhs.isSet () && rhs.isSet ());
212
-
213
- return (lhs < rhs || lhs == rhs);
190
+ return lhs.compositeSequenceNumber () <= rhs.compositeSequenceNumber ();
214
191
}
215
192
216
193
} // close enterprise namespace
0 commit comments