Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/fb-cpp/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace fbcpp::impl;


Attachment::Attachment(Client& client, const std::string& uri, const AttachmentOptions& options)
: client{client}
: client{&client}
{
const auto master = client.getMaster();

Expand Down Expand Up @@ -68,8 +68,8 @@ void Attachment::disconnectOrDrop(bool drop)
{
assert(isValid());

const auto status = client.newStatus();
StatusWrapper statusWrapper{client, status.get()};
const auto status = client->newStatus();
StatusWrapper statusWrapper{*client, status.get()};

if (drop)
handle->dropDatabase(&statusWrapper);
Expand Down
21 changes: 18 additions & 3 deletions src/fb-cpp/Attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,22 @@ namespace fbcpp
{
}

Attachment& operator=(Attachment&&) = delete;
///
/// @brief Transfers ownership of another Attachment into this one.
///
/// The old handle is released via `FbRef::operator=(FbRef&&)`.
/// After the assignment, `this` is valid (with `o`'s handle) and `o` is invalid.
///
Attachment& operator=(Attachment&& o) noexcept
{
if (this != &o)
{
client = o.client;
handle = std::move(o.handle);
}

return *this;
}

Attachment(const Attachment&) = delete;
Attachment& operator=(const Attachment&) = delete;
Expand Down Expand Up @@ -229,7 +244,7 @@ namespace fbcpp
///
Client& getClient() noexcept
{
return client;
return *client;
}

///
Expand All @@ -254,7 +269,7 @@ namespace fbcpp
void disconnectOrDrop(bool drop);

private:
Client& client;
Client* client;
FbRef<fb::IAttachment> handle;
};
} // namespace fbcpp
Expand Down
40 changes: 20 additions & 20 deletions src/fb-cpp/CalendarConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace fbcpp::impl
{
public:
explicit CalendarConverter(Client& client, StatusWrapper* statusWrapper)
: client{client},
: client{&client},
statusWrapper{statusWrapper}
{
}
Expand All @@ -67,7 +67,7 @@ namespace fbcpp::impl
if (yearValue <= 0)
throwInvalidDateValue();

return OpaqueDate{client.getUtil()->encodeDate(static_cast<unsigned>(yearValue), monthValue, dayValue)};
return OpaqueDate{client->getUtil()->encodeDate(static_cast<unsigned>(yearValue), monthValue, dayValue)};
}

Date opaqueDateToDate(OpaqueDate date)
Expand All @@ -76,7 +76,7 @@ namespace fbcpp::impl
unsigned month;
unsigned day;

client.getUtil()->decodeDate(date.value, &year, &month, &day);
client->getUtil()->decodeDate(date.value, &year, &month, &day);

return Date{std::chrono::year{static_cast<int>(year)}, std::chrono::month{month}, std::chrono::day{day}};
}
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace fbcpp::impl
const auto subseconds = static_cast<unsigned>(time.subseconds().count() / 100);

OpaqueTime opaqueTime;
opaqueTime.value = client.getUtil()->encodeTime(hours, minutes, seconds, subseconds);
opaqueTime.value = client->getUtil()->encodeTime(hours, minutes, seconds, subseconds);

return opaqueTime;
}
Expand All @@ -152,7 +152,7 @@ namespace fbcpp::impl
unsigned seconds;
unsigned subseconds;

const auto util = client.getUtil();
const auto util = client->getUtil();
util->decodeTime(time.value, &hours, &minutes, &seconds, &subseconds);

const auto timeOfDay = std::chrono::hours{hours} + std::chrono::minutes{minutes} +
Expand Down Expand Up @@ -252,7 +252,7 @@ namespace fbcpp::impl

OpaqueTimeTz opaque{};

client.getUtil()->encodeTimeTz(statusWrapper, &opaque.value, 0u, 0u, 0u, 0u, timeTz.zone.c_str());
client->getUtil()->encodeTimeTz(statusWrapper, &opaque.value, 0u, 0u, 0u, 0u, timeTz.zone.c_str());

opaque.value.utc_time = static_cast<ISC_TIME>(duration.count() / 100);

Expand All @@ -269,7 +269,7 @@ namespace fbcpp::impl
unsigned fractions;
std::array<char, 128> timeZoneBuffer;

client.getUtil()->decodeTimeTz(statusWrapper, &opaqueTime.value, &hours, &minutes, &seconds, &fractions,
client->getUtil()->decodeTimeTz(statusWrapper, &opaqueTime.value, &hours, &minutes, &seconds, &fractions,
static_cast<unsigned>(timeZoneBuffer.size()), timeZoneBuffer.data());

TimeTz timeTz;
Expand All @@ -295,7 +295,7 @@ namespace fbcpp::impl
unsigned fractions;
std::array<char, 128> timeZoneBuffer;

client.getUtil()->decodeTimeTz(statusWrapper, &time.value, &hours, &minutes, &seconds, &fractions,
client->getUtil()->decodeTimeTz(statusWrapper, &time.value, &hours, &minutes, &seconds, &fractions,
static_cast<unsigned>(timeZoneBuffer.size()), timeZoneBuffer.data());

return std::format("{:02}:{:02}:{:02}.{:04} {}", hours, minutes, seconds, fractions, timeZoneBuffer.data());
Expand Down Expand Up @@ -360,7 +360,7 @@ namespace fbcpp::impl

OpaqueTimeTz encoded;
const std::string timeZoneString{makeComponentView(5)};
client.getUtil()->encodeTimeTz(
client->getUtil()->encodeTimeTz(
statusWrapper, &encoded.value, hours, minutes, seconds, fractions, timeZoneString.c_str());

return opaqueTimeTzToTimeTz(encoded);
Expand Down Expand Up @@ -389,7 +389,7 @@ namespace fbcpp::impl
OpaqueTimestamp opaqueTimestamp;
opaqueTimestamp.value.timestamp_date = opaqueDate.value;
opaqueTimestamp.value.timestamp_time =
client.getUtil()->encodeTime(static_cast<unsigned>(timestamp.time.hours().count()),
client->getUtil()->encodeTime(static_cast<unsigned>(timestamp.time.hours().count()),
static_cast<unsigned>(timestamp.time.minutes().count()),
static_cast<unsigned>(timestamp.time.seconds().count()), static_cast<unsigned>(subseconds / 100));

Expand All @@ -406,7 +406,7 @@ namespace fbcpp::impl
unsigned seconds;
unsigned subseconds;

const auto util = client.getUtil();
const auto util = client->getUtil();
util->decodeDate(timestamp.value.timestamp_date, &year, &month, &day);
util->decodeTime(timestamp.value.timestamp_time, &hours, &minutes, &seconds, &subseconds);

Expand Down Expand Up @@ -513,7 +513,7 @@ namespace fbcpp::impl
{
OpaqueTimestampTz opaque;

client.getUtil()->encodeTimeStampTz(
client->getUtil()->encodeTimeStampTz(
statusWrapper, &opaque.value, 1u, 1u, 1u, 0u, 0u, 0u, 0u, timestampTz.zone.c_str());

const auto utcOpaque = timestampToOpaqueTimestamp(timestampTz.utcTimestamp);
Expand All @@ -539,7 +539,7 @@ namespace fbcpp::impl
unsigned subseconds;
std::array<char, 128> timeZoneBuffer;

client.getUtil()->decodeTimeStampTz(statusWrapper, &opaqueTimestamp.value, &year, &month, &day, &hours,
client->getUtil()->decodeTimeStampTz(statusWrapper, &opaqueTimestamp.value, &year, &month, &day, &hours,
&minutes, &seconds, &subseconds, static_cast<unsigned>(timeZoneBuffer.size()), timeZoneBuffer.data());

TimestampTz timestampTz;
Expand Down Expand Up @@ -569,7 +569,7 @@ namespace fbcpp::impl
unsigned subseconds;
std::array<char, 128> timeZoneBuffer;

client.getUtil()->decodeTimeStampTz(statusWrapper, &timestamp.value, &year, &month, &day, &hours, &minutes,
client->getUtil()->decodeTimeStampTz(statusWrapper, &timestamp.value, &year, &month, &day, &hours, &minutes,
&seconds, &subseconds, static_cast<unsigned>(timeZoneBuffer.size()), timeZoneBuffer.data());

return std::format("{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:04} {}", year, month, day, hours, minutes,
Expand Down Expand Up @@ -648,7 +648,7 @@ namespace fbcpp::impl

OpaqueTimestampTz encoded;
const std::string timeZoneString{makeComponentView(8)};
client.getUtil()->encodeTimeStampTz(statusWrapper, &encoded.value,
client->getUtil()->encodeTimeStampTz(statusWrapper, &encoded.value,
static_cast<unsigned>(static_cast<int>(date.year())), monthValue, dayValue, hours, minutes, seconds,
fractions, timeZoneString.c_str());

Expand All @@ -674,7 +674,7 @@ namespace fbcpp::impl
isc_arg_end,
};

throw DatabaseException(client, STATUS_CONVERSION_ERROR_FROM_STRING);
throw DatabaseException(*client, STATUS_CONVERSION_ERROR_FROM_STRING);
}

[[noreturn]] void throwInvalidDateValue()
Expand All @@ -684,7 +684,7 @@ namespace fbcpp::impl
isc_arg_end,
};

throw DatabaseException(client, STATUS_INVALID_DATE_VALUE);
throw DatabaseException(*client, STATUS_INVALID_DATE_VALUE);
}

[[noreturn]] void throwInvalidTimeValue()
Expand All @@ -694,7 +694,7 @@ namespace fbcpp::impl
isc_arg_end,
};

throw DatabaseException(client, STATUS_INVALID_TIME_VALUE);
throw DatabaseException(*client, STATUS_INVALID_TIME_VALUE);
}

[[noreturn]] void throwInvalidTimestampValue()
Expand All @@ -704,15 +704,15 @@ namespace fbcpp::impl
isc_arg_end,
};

throw DatabaseException(client, STATUS_INVALID_TIMESTAMP_VALUE);
throw DatabaseException(*client, STATUS_INVALID_TIMESTAMP_VALUE);
}

private:
static constexpr auto TICKS_PER_DAY = std::int64_t{24} * 60 * 60 * 10000;
static constexpr auto BASE_EPOCH = std::chrono::local_days{
std::chrono::year{1858} / std::chrono::November / 17,
};
Client& client;
Client* client;
StatusWrapper* statusWrapper;
};
} // namespace fbcpp::impl
Expand Down
2 changes: 1 addition & 1 deletion src/fb-cpp/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using namespace fbcpp::impl;
void StatusWrapper::checkException(StatusWrapper* status)
{
if (status->dirty && (status->getState() & fb::IStatus::STATE_ERRORS))
throw DatabaseException{status->client, status->getErrors()};
throw DatabaseException{*status->client, status->getErrors()};
}

void StatusWrapper::catchException(fb::IStatus* status) noexcept
Expand Down
4 changes: 2 additions & 2 deletions src/fb-cpp/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace fbcpp::impl
{
public:
explicit StatusWrapper(Client& client, IStatus* status)
: client{client},
: client{&client},
status{status}
{
}
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace fbcpp::impl
}

protected:
Client& client;
Client* client;
IStatus* status;
bool dirty = false;

Expand Down
18 changes: 9 additions & 9 deletions src/fb-cpp/NumericConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace fbcpp::impl
{
public:
explicit NumericConverter(Client& client, StatusWrapper* statusWrapper)
: client{client},
: client{&client},
statusWrapper{statusWrapper}
{
}
Expand All @@ -161,7 +161,7 @@ namespace fbcpp::impl
isc_arg_end,
};

throw DatabaseException(client, STATUS_NUMERIC_OUT_OF_RANGE);
throw DatabaseException(*client, STATUS_NUMERIC_OUT_OF_RANGE);
}

[[noreturn]] void throwConversionErrorFromString(const std::string& str)
Expand All @@ -172,7 +172,7 @@ namespace fbcpp::impl
isc_arg_end,
};

throw DatabaseException(client, STATUS_CONVERSION_ERROR_FROM_STRING);
throw DatabaseException(*client, STATUS_CONVERSION_ERROR_FROM_STRING);
}

public:
Expand Down Expand Up @@ -356,23 +356,23 @@ namespace fbcpp::impl

std::string opaqueInt128ToString(const OpaqueInt128& opaqueInt128, int scale)
{
const auto int128Util = client.getUtil()->getInt128(statusWrapper);
const auto int128Util = client->getUtil()->getInt128(statusWrapper);
char buffer[fb::IInt128::STRING_SIZE + 1];
int128Util->toString(statusWrapper, &opaqueInt128, scale, static_cast<unsigned>(sizeof(buffer)), buffer);
return buffer;
}

std::string opaqueDecFloat16ToString(const OpaqueDecFloat16& opaqueDecFloat16)
{
const auto decFloat16Util = client.getDecFloat16Util(statusWrapper);
const auto decFloat16Util = client->getDecFloat16Util(statusWrapper);
char buffer[fb::IDecFloat16::STRING_SIZE + 1];
decFloat16Util->toString(statusWrapper, &opaqueDecFloat16, static_cast<unsigned>(sizeof(buffer)), buffer);
return buffer;
}

std::string opaqueDecFloat34ToString(const OpaqueDecFloat34& opaqueDecFloat34)
{
const auto decFloat34Util = client.getDecFloat34Util(statusWrapper);
const auto decFloat34Util = client->getDecFloat34Util(statusWrapper);
char buffer[fb::IDecFloat34::STRING_SIZE + 1];
decFloat34Util->toString(statusWrapper, &opaqueDecFloat34, static_cast<unsigned>(sizeof(buffer)), buffer);
return buffer;
Expand Down Expand Up @@ -401,7 +401,7 @@ namespace fbcpp::impl

OpaqueDecFloat16 boostDecFloat16ToOpaqueDecFloat16(const BoostDecFloat16& boostDecFloat16)
{
const auto decFloat16Util = client.getDecFloat16Util(statusWrapper);
const auto decFloat16Util = client->getDecFloat16Util(statusWrapper);
OpaqueDecFloat16 opaqueDecFloat16;
decFloat16Util->fromString(statusWrapper, boostDecFloat16.str().c_str(), &opaqueDecFloat16);
return opaqueDecFloat16;
Expand All @@ -414,7 +414,7 @@ namespace fbcpp::impl

OpaqueDecFloat34 boostDecFloat34ToOpaqueDecFloat34(const BoostDecFloat34& boostDecFloat34)
{
const auto decFloat34Util = client.getDecFloat34Util(statusWrapper);
const auto decFloat34Util = client->getDecFloat34Util(statusWrapper);
OpaqueDecFloat34 opaqueDecFloat34;
decFloat34Util->fromString(statusWrapper, boostDecFloat34.str().c_str(), &opaqueDecFloat34);
return opaqueDecFloat34;
Expand Down Expand Up @@ -573,7 +573,7 @@ namespace fbcpp::impl
}

private:
Client& client;
Client* client;
StatusWrapper* statusWrapper;
};
} // namespace fbcpp::impl
Expand Down
2 changes: 1 addition & 1 deletion src/fb-cpp/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using namespace fbcpp::impl;

Statement::Statement(
Attachment& attachment, Transaction& transaction, std::string_view sql, const StatementOptions& options)
: attachment{attachment},
: attachment{&attachment},
status{attachment.getClient().newStatus()},
statusWrapper{attachment.getClient(), status.get()},
calendarConverter{attachment.getClient(), &statusWrapper},
Expand Down
Loading