Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Ivanov <[email protected]>
  • Loading branch information
alexander-e1off committed Nov 11, 2024
1 parent c4e6d13 commit 149c396
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 240 deletions.
6 changes: 4 additions & 2 deletions src/applications/bmqstoragetool/bmqstoragetool.m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
using namespace BloombergLP;
using namespace m_bmqstoragetool;

static bool
parseArgs(CommandLineArguments& arguments, int argc, const char* argv[], bslma::Allocator* allocator)
static bool parseArgs(CommandLineArguments& arguments,
int argc,
const char* argv[],
bslma::Allocator* allocator)
{
bool showHelp = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ CompositeSequenceNumber::CompositeSequenceNumber()
// NOTHING
}

CompositeSequenceNumber::CompositeSequenceNumber(const unsigned int leaseId, const bsls::Types::Uint64 sequenceNumber)
CompositeSequenceNumber::CompositeSequenceNumber(
const unsigned int leaseId,
const bsls::Types::Uint64 sequenceNumber)
: d_leaseId(leaseId)
, d_seqNumber(sequenceNumber)
{
BSLS_ASSERT(d_leaseId > 0 && d_seqNumber > 0);
d_isUnset = !(d_leaseId > 0 && d_seqNumber > 0);
}

CompositeSequenceNumber& CompositeSequenceNumber::fromString(bsl::ostream& errorDescription, const bsl::string& seqNumString)
CompositeSequenceNumber&
CompositeSequenceNumber::fromString(bsl::ostream& errorDescription,
const bsl::string& seqNumString)
{
d_isUnset = true;

Expand All @@ -57,19 +61,19 @@ CompositeSequenceNumber& CompositeSequenceNumber::fromString(bsl::ostream& error
if (separatorPos == bsl::string::npos) {
errorDescription << "Invalid format: no '-' separator found.";
return *this; // RETURN
}
}

// Extract parts
// TODO: use allocator!
bsl::string firstPart = seqNumString.substr(0, separatorPos);
bsl::string firstPart = seqNumString.substr(0, separatorPos);
bsl::string secondPart = seqNumString.substr(separatorPos + 1);

// Convert parts to numbers
try {
size_t posFirst, posSecond;

unsigned long uLong = bsl::stoul(firstPart, &posFirst);
d_seqNumber = bsl::stoul(secondPart, &posSecond);
d_seqNumber = bsl::stoul(secondPart, &posSecond);

if (posFirst != firstPart.size() || posSecond != secondPart.size()) {
throw bsl::invalid_argument("");
Expand All @@ -86,18 +90,20 @@ CompositeSequenceNumber& CompositeSequenceNumber::fromString(bsl::ostream& error
}

d_isUnset = false;

} catch (const bsl::invalid_argument& e) {
}
catch (const bsl::invalid_argument& e) {
errorDescription << "Invalid input: non-numeric values encountered.";
} catch (const bsl::out_of_range& e) {
}
catch (const bsl::out_of_range& e) {
errorDescription << "Invalid input: number out of range.";
}

return *this;
}

bsl::ostream&
CompositeSequenceNumber::print(bsl::ostream& stream, int level, int spacesPerLevel) const
bsl::ostream& CompositeSequenceNumber::print(bsl::ostream& stream,
int level,
int spacesPerLevel) const
{
if (stream.bad()) {
return stream; // RETURN
Expand All @@ -109,7 +115,8 @@ CompositeSequenceNumber::print(bsl::ostream& stream, int level, int spacesPerLev
stream << "** UNSET **";
}
else {
stream << "leaseId: " << leaseId() << ", sequenceNumber: " << sequenceNumber();
stream << "leaseId: " << leaseId()
<< ", sequenceNumber: " << sequenceNumber();
}

if (spacesPerLevel >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
#ifndef INCLUDED_M_BMQSTORAGETOOL_COMPOSITESEQUENCENUMBER
#define INCLUDED_M_BMQSTORAGETOOL_COMPOSITESEQUENCENUMBER

//@PURPOSE: Provide value-semantic type to represent composite sequence number, which is used for message filtering.
//@PURPOSE: Provide value-semantic type to represent composite sequence number,
//which is used for message filtering.
//
//@CLASSES:
// m_bmqstoragetool::CompositeSequenceNumber: Value-semantic type to represent composite sequence number.
// m_bmqstoragetool::CompositeSequenceNumber: Value-semantic type to represent
// composite sequence number.
//
//@DESCRIPTION: 'CompositeSequenceNumber' provides value-semantic type to represent sequence number.
// There could be sequence numbers collision inside journal file for different lease Ids,
// so need to handle composite sequence number taking into account Primary Lease Id too.
//@DESCRIPTION: 'CompositeSequenceNumber' provides value-semantic type to
//represent sequence number.
// There could be sequence numbers collision inside journal file for different
// lease Ids, so need to handle composite sequence number taking into account
// Primary Lease Id too.

// BDE
#include <bsl_ostream.h>
Expand All @@ -49,19 +53,25 @@ class CompositeSequenceNumber {
public:
// CREATORS

/// Create an un-initialized CompositeSequenceNumber. Note that `isUnset()` would
/// return true.
/// Create an un-initialized CompositeSequenceNumber. Note that
/// `isUnset()` would return true.
CompositeSequenceNumber();

/// Create CompositeSequenceNumber from the specified `leaseId` and `sequenceNumber`
CompositeSequenceNumber(const unsigned int leaseId, const bsls::Types::Uint64 sequenceNumber);
/// Create CompositeSequenceNumber from the specified `leaseId` and
/// `sequenceNumber`
CompositeSequenceNumber(const unsigned int leaseId,
const bsls::Types::Uint64 sequenceNumber);

// MANIPULATORS

/// Initialize this CompositeSequenceNumber from the specified `seqNumString` representation in format `<leaseId>-<sequenceNumber>`.
/// Return a reference offering modifiable access to this object. If convertion is successfull, `isUnset()` would return `true`.
/// Otherwise, `isUnset()` would return `false` and specified `errorDescription` is filled with error description.
CompositeSequenceNumber& fromString(bsl::ostream& errorDescription, const bsl::string& seqNumString);
/// Initialize this CompositeSequenceNumber from the specified
/// `seqNumString` representation in format `<leaseId>-<sequenceNumber>`.
/// Return a reference offering modifiable access to this object. If
/// convertion is successfull, `isUnset()` would return `true`. Otherwise,
/// `isUnset()` would return `false` and specified `errorDescription` is
/// filled with error description.
CompositeSequenceNumber& fromString(bsl::ostream& errorDescription,
const bsl::string& seqNumString);

// ACCESSORS

Expand Down Expand Up @@ -99,15 +109,18 @@ class CompositeSequenceNumber {
/// `stream` in a human-readable format, and return a reference to `stream`.
/// Note that this human-readable format is not fully specified, and can
/// change without notice.
bsl::ostream& operator<<(bsl::ostream& stream, const CompositeSequenceNumber& rhs);
bsl::ostream& operator<<(bsl::ostream& stream,
const CompositeSequenceNumber& rhs);

/// Return true if the specified `lhs` instance is less than the
/// specified `rhs` instance, false otherwise.
bool operator<(const CompositeSequenceNumber& lhs, const CompositeSequenceNumber& rhs);
bool operator<(const CompositeSequenceNumber& lhs,
const CompositeSequenceNumber& rhs);

/// Return true if the specified `lhs` instance is less or equal to the
/// specified `rhs` instance, false otherwise.
bool operator<=(const CompositeSequenceNumber& lhs, const CompositeSequenceNumber& rhs);
bool operator<=(const CompositeSequenceNumber& lhs,
const CompositeSequenceNumber& rhs);

// ============================================================================
// INLINE DEFINITIONS
Expand Down Expand Up @@ -142,25 +155,28 @@ inline bsls::Types::Uint64 CompositeSequenceNumber::sequenceNumber() const

// FREE OPERATORS

inline bsl::ostream& m_bmqstoragetool::operator<<(bsl::ostream& stream,
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
inline bsl::ostream& m_bmqstoragetool::operator<<(
bsl::ostream& stream,
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
{
// PRECONDITIONS
BSLS_ASSERT(!rhs.isUnset());

return rhs.print(stream, 0, -1);
}

inline bool m_bmqstoragetool::operator<(const m_bmqstoragetool::CompositeSequenceNumber& lhs,
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
inline bool m_bmqstoragetool::operator<(
const m_bmqstoragetool::CompositeSequenceNumber& lhs,
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
{
// PRECONDITIONS
BSLS_ASSERT(!lhs.isUnset() && !rhs.isUnset());

// Check leaseId first
if (lhs.leaseId() < rhs.leaseId()) {
return true; // RETURN
} else if (lhs.leaseId() == rhs.leaseId()) {
}
else if (lhs.leaseId() == rhs.leaseId()) {
if (lhs.sequenceNumber() < rhs.sequenceNumber()) {
return true; // RETURN
}
Expand All @@ -169,13 +185,15 @@ inline bool m_bmqstoragetool::operator<(const m_bmqstoragetool::CompositeSequenc
return false;
}

inline bool m_bmqstoragetool::operator<=(const m_bmqstoragetool::CompositeSequenceNumber& lhs,
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
inline bool m_bmqstoragetool::operator<=(
const m_bmqstoragetool::CompositeSequenceNumber& lhs,
const m_bmqstoragetool::CompositeSequenceNumber& rhs)
{
// PRECONDITIONS
BSLS_ASSERT(!lhs.isUnset() && !rhs.isUnset());

if (lhs.leaseId() == rhs.leaseId() && lhs.sequenceNumber() == rhs.sequenceNumber()) {
if (lhs.leaseId() == rhs.leaseId() &&
lhs.sequenceNumber() == rhs.sequenceNumber()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ static void test2_fromStringTest()
// FROM STRING TEST
//
// Concerns:
// Exercise the functionality to initialize component from string representation.
// Exercise the functionality to initialize component from string
// representation.
//
// Testing:
// fromString method
Expand Down Expand Up @@ -123,7 +124,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid format: no '-' separator found.");
ASSERT_EQ(errorDescription.str(),
"Invalid format: no '-' separator found.");
}

// Invalid string with wrong separator
Expand All @@ -136,7 +138,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid format: no '-' separator found.");
ASSERT_EQ(errorDescription.str(),
"Invalid format: no '-' separator found.");
}

// Invalid string with non-numeric value in first part
Expand All @@ -149,7 +152,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid input: non-numeric values encountered.");
ASSERT_EQ(errorDescription.str(),
"Invalid input: non-numeric values encountered.");
}

// Invalid string with non-numeric value in second part
Expand All @@ -162,7 +166,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid input: non-numeric values encountered.");
ASSERT_EQ(errorDescription.str(),
"Invalid input: non-numeric values encountered.");
}

// Invalid string with zero value in first part
Expand All @@ -175,7 +180,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid input: zero values encountered.");
ASSERT_EQ(errorDescription.str(),
"Invalid input: zero values encountered.");
}

// Invalid string with zero value in second part
Expand All @@ -188,7 +194,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid input: zero values encountered.");
ASSERT_EQ(errorDescription.str(),
"Invalid input: zero values encountered.");
}

// Invalid string with out of range value in first part
Expand All @@ -202,7 +209,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid input: number out of range.");
ASSERT_EQ(errorDescription.str(),
"Invalid input: number out of range.");
}

// Invalid string with out of range value in second part
Expand All @@ -216,7 +224,8 @@ static void test2_fromStringTest()
compositeSeqNum.fromString(errorDescription, inputString);
ASSERT_EQ(compositeSeqNum.isUnset(), true);
ASSERT(!errorDescription.str().empty());
ASSERT_EQ(errorDescription.str(), "Invalid input: number out of range.");
ASSERT_EQ(errorDescription.str(),
"Invalid input: number out of range.");
}
}

Expand Down
55 changes: 25 additions & 30 deletions src/applications/bmqstoragetool/m_bmqstoragetool_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ namespace m_bmqstoragetool {
// class Filters
// =============

Filters::Filters(const bsl::vector<bsl::string>& queueKeys,
const bsl::vector<bsl::string>& queueUris,
const QueueMap& queueMap,
Filters::Filters(const bsl::vector<bsl::string>& queueKeys,
const bsl::vector<bsl::string>& queueUris,
const QueueMap& queueMap,
const Parameters::SearchValueType valueType,
const bsls::Types::Uint64 valueGt,
const bsls::Types::Uint64 valueLt,
const CompositeSequenceNumber seqNumGt,
const CompositeSequenceNumber seqNumLt,
bslma::Allocator* allocator)
const bsls::Types::Uint64 valueGt,
const bsls::Types::Uint64 valueLt,
const CompositeSequenceNumber seqNumGt,
const CompositeSequenceNumber seqNumLt,
bslma::Allocator* allocator)
: d_queueKeys(allocator)
, d_valueType(valueType)
, d_valueGt(valueGt)
Expand Down Expand Up @@ -59,7 +59,8 @@ Filters::Filters(const bsl::vector<bsl::string>& queueKeys,
}
}

bool Filters::apply(const mqbs::MessageRecord& record, bsls::Types::Uint64 offset) const
bool Filters::apply(const mqbs::MessageRecord& record,
bsls::Types::Uint64 offset) const
{
// Apply `queue key` filter
if (!d_queueKeys.empty()) {
Expand All @@ -76,27 +77,21 @@ bool Filters::apply(const mqbs::MessageRecord& record, bsls::Types::Uint64 offse

// Apply `range` filter
bsls::Types::Uint64 value;
switch(d_valueType) {
case Parameters::e_TIMESTAMP:
value = record.header().timestamp();
break;
case Parameters::e_SEQUENCE_NUM:
{
CompositeSequenceNumber seqNum(record.header().primaryLeaseId(), record.header().sequenceNumber());
if ((!d_seqNumGt.isUnset() && seqNum <= d_seqNumGt) ||
(!d_seqNumLt.isUnset() && d_seqNumLt <= seqNum)) {
// Not inside range
return false; // RETURN
}
}
break;
case Parameters::e_OFFSET:
value = offset;
break;
default:
// No range filter defined
return true; // RETURN

switch (d_valueType) {
case Parameters::e_TIMESTAMP: value = record.header().timestamp(); break;
case Parameters::e_SEQUENCE_NUM: {
CompositeSequenceNumber seqNum(record.header().primaryLeaseId(),
record.header().sequenceNumber());
if ((!d_seqNumGt.isUnset() && seqNum <= d_seqNumGt) ||
(!d_seqNumLt.isUnset() && d_seqNumLt <= seqNum)) {
// Not inside range
return false; // RETURN
}
} break;
case Parameters::e_OFFSET: value = offset; break;
default:
// No range filter defined
return true; // RETURN
}
if ((d_valueGt > 0 && value <= d_valueGt) ||
(d_valueLt > 0 && value >= d_valueLt)) {
Expand Down
Loading

0 comments on commit 149c396

Please sign in to comment.