@@ -324,7 +324,7 @@ namespace osmium {
324
324
325
325
class ChangesetDiscussionBuilder : public Builder {
326
326
327
- std::size_t m_comment_offset = SIZE_MAX ;
327
+ std::size_t m_comment_offset = std::numeric_limits<std:: size_t >::max() ;
328
328
329
329
void add_user (osmium::ChangesetComment& comment, const char * user, const std::size_t length) {
330
330
if (length > osmium::max_osm_string_length) {
@@ -343,9 +343,13 @@ namespace osmium {
343
343
add_padding (true );
344
344
}
345
345
346
+ bool has_open_comment () const noexcept {
347
+ return m_comment_offset != std::numeric_limits<std::size_t >::max ();
348
+ }
349
+
346
350
// Get current comment pointer (recalculated each time to handle buffer reallocation)
347
351
osmium::ChangesetComment* get_comment_ptr () {
348
- if (m_comment_offset == SIZE_MAX ) {
352
+ if (! has_open_comment () ) {
349
353
return nullptr ;
350
354
}
351
355
return reinterpret_cast <osmium::ChangesetComment*>(
@@ -372,12 +376,12 @@ namespace osmium {
372
376
ChangesetDiscussionBuilder& operator =(ChangesetDiscussionBuilder&&) = delete ;
373
377
374
378
~ChangesetDiscussionBuilder () {
375
- assert (m_comment_offset == SIZE_MAX && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
379
+ assert (! has_open_comment () && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
376
380
add_padding ();
377
381
}
378
382
379
383
void add_comment (osmium::Timestamp date, osmium::user_id_type uid, const char * user) {
380
- assert (m_comment_offset == SIZE_MAX && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
384
+ assert (! has_open_comment () && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
381
385
382
386
// Store offset instead of pointer to handle buffer reallocation
383
387
m_comment_offset = buffer ().written () - buffer ().committed ();
@@ -386,38 +390,31 @@ namespace osmium {
386
390
new (comment) osmium::ChangesetComment{date, uid};
387
391
add_size (sizeof (ChangesetComment));
388
392
389
- auto * comment_ptr = get_comment_ptr ();
390
- add_user (*comment_ptr, user, std::strlen (user));
393
+ add_user (*comment, user, std::strlen (user));
391
394
}
392
395
393
396
void add_comment_text (const char * text) {
394
- assert (m_comment_offset != SIZE_MAX && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
397
+ assert (has_open_comment () && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
395
398
396
399
// Get fresh pointer each time to handle buffer reallocation
397
- auto * comment_ptr = get_comment_ptr ();
398
- osmium::ChangesetComment& comment = *comment_ptr;
400
+ auto * comment = get_comment_ptr ();
399
401
400
402
// Invalidate offset to ensure right adding order
401
- m_comment_offset = SIZE_MAX ;
403
+ m_comment_offset = std::numeric_limits<std:: size_t >:: max () ;
402
404
403
- add_text (comment, text, std::strlen (text));
405
+ add_text (* comment, text, std::strlen (text));
404
406
}
405
407
406
408
void add_comment_text (const std::string& text) {
407
- assert (m_comment_offset != SIZE_MAX && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
409
+ assert (has_open_comment () && " You have to always call both add_comment() and then add_comment_text() in that order for each comment!" );
408
410
409
411
// Get fresh pointer each time to handle buffer reallocation
410
- auto * comment_ptr = get_comment_ptr ();
411
- osmium::ChangesetComment& comment = *comment_ptr;
412
+ auto * comment = get_comment_ptr ();
412
413
413
414
// Invalidate offset to ensure right adding order
414
- m_comment_offset = SIZE_MAX ;
415
+ m_comment_offset = std::numeric_limits<std:: size_t >:: max () ;
415
416
416
- add_text (comment, text.c_str (), text.size ());
417
- }
418
-
419
- bool has_open_comment () const noexcept {
420
- return m_comment_offset != SIZE_MAX;
417
+ add_text (*comment, text.c_str (), text.size ());
421
418
}
422
419
}; // class ChangesetDiscussionBuilder
423
420
0 commit comments