Skip to content

Commit c33de34

Browse files
committed
improve coding style
1 parent 110fe88 commit c33de34

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

include/osmium/builder/osm_object_builder.hpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ namespace osmium {
324324

325325
class ChangesetDiscussionBuilder : public Builder {
326326

327-
std::size_t m_comment_offset = SIZE_MAX;
327+
std::size_t m_comment_offset = std::numeric_limits<std::size_t>::max();
328328

329329
void add_user(osmium::ChangesetComment& comment, const char* user, const std::size_t length) {
330330
if (length > osmium::max_osm_string_length) {
@@ -343,9 +343,13 @@ namespace osmium {
343343
add_padding(true);
344344
}
345345

346+
bool has_open_comment() const noexcept {
347+
return m_comment_offset != std::numeric_limits<std::size_t>::max();
348+
}
349+
346350
// Get current comment pointer (recalculated each time to handle buffer reallocation)
347351
osmium::ChangesetComment* get_comment_ptr() {
348-
if (m_comment_offset == SIZE_MAX) {
352+
if (!has_open_comment()) {
349353
return nullptr;
350354
}
351355
return reinterpret_cast<osmium::ChangesetComment*>(
@@ -372,12 +376,12 @@ namespace osmium {
372376
ChangesetDiscussionBuilder& operator=(ChangesetDiscussionBuilder&&) = delete;
373377

374378
~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!");
376380
add_padding();
377381
}
378382

379383
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!");
381385

382386
// Store offset instead of pointer to handle buffer reallocation
383387
m_comment_offset = buffer().written() - buffer().committed();
@@ -386,38 +390,31 @@ namespace osmium {
386390
new (comment) osmium::ChangesetComment{date, uid};
387391
add_size(sizeof(ChangesetComment));
388392

389-
auto* comment_ptr = get_comment_ptr();
390-
add_user(*comment_ptr, user, std::strlen(user));
393+
add_user(*comment, user, std::strlen(user));
391394
}
392395

393396
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!");
395398

396399
// 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();
399401

400402
// Invalidate offset to ensure right adding order
401-
m_comment_offset = SIZE_MAX;
403+
m_comment_offset = std::numeric_limits<std::size_t>::max();
402404

403-
add_text(comment, text, std::strlen(text));
405+
add_text(*comment, text, std::strlen(text));
404406
}
405407

406408
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!");
408410

409411
// 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();
412413

413414
// Invalidate offset to ensure right adding order
414-
m_comment_offset = SIZE_MAX;
415+
m_comment_offset = std::numeric_limits<std::size_t>::max();
415416

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());
421418
}
422419
}; // class ChangesetDiscussionBuilder
423420

0 commit comments

Comments
 (0)