Skip to content

Commit fd787d8

Browse files
committed
Rework Row class. Remove its default constructor.
1 parent 72873eb commit fd787d8

5 files changed

Lines changed: 102 additions & 123 deletions

File tree

src/fb-cpp/Row.h

Lines changed: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,20 @@ namespace fbcpp
6464
class Row final
6565
{
6666
public:
67-
Row() = default;
68-
6967
///
7068
/// @brief Constructs a Row view over the given message buffer.
7169
///
72-
/// @param message Pointer to the raw row data.
70+
/// @param client Client used to build conversion helpers.
7371
/// @param descriptors Column descriptors.
74-
/// @param statusWrapper Status wrapper used for Firebird conversions.
75-
/// @param numericConverter Numeric converter.
76-
/// @param calendarConverter Calendar converter.
72+
/// @param message Pointer to the raw row data.
7773
///
78-
Row(const std::byte* message, const std::vector<Descriptor>& descriptors, impl::StatusWrapper& statusWrapper,
79-
impl::NumericConverter& numericConverter, impl::CalendarConverter& calendarConverter)
74+
Row(Client& client, const std::vector<Descriptor>& descriptors, const std::byte* message)
8075
: message{message},
8176
descriptors{&descriptors},
82-
statusWrapper{&statusWrapper},
83-
numericConverter{&numericConverter},
84-
calendarConverter{&calendarConverter}
77+
client{&client},
78+
statusWrapper{client},
79+
numericConverter{client},
80+
calendarConverter{client}
8581
{
8682
}
8783

@@ -313,7 +309,7 @@ namespace fbcpp
313309
switch (descriptor.adjustedType)
314310
{
315311
case DescriptorAdjustedType::DATE:
316-
return getCalendarConverter().opaqueDateToDate(
312+
return calendarConverter.opaqueDateToDate(
317313
*reinterpret_cast<const OpaqueDate*>(&message[descriptor.offset]));
318314

319315
default:
@@ -354,7 +350,7 @@ namespace fbcpp
354350
switch (descriptor.adjustedType)
355351
{
356352
case DescriptorAdjustedType::TIME:
357-
return getCalendarConverter().opaqueTimeToTime(
353+
return calendarConverter.opaqueTimeToTime(
358354
*reinterpret_cast<const OpaqueTime*>(&message[descriptor.offset]));
359355

360356
default:
@@ -395,7 +391,7 @@ namespace fbcpp
395391
switch (descriptor.adjustedType)
396392
{
397393
case DescriptorAdjustedType::TIMESTAMP:
398-
return getCalendarConverter().opaqueTimestampToTimestamp(
394+
return calendarConverter.opaqueTimestampToTimestamp(
399395
*reinterpret_cast<const OpaqueTimestamp*>(&message[descriptor.offset]));
400396

401397
default:
@@ -436,8 +432,8 @@ namespace fbcpp
436432
switch (descriptor.adjustedType)
437433
{
438434
case DescriptorAdjustedType::TIME_TZ:
439-
return getCalendarConverter().opaqueTimeTzToTimeTz(
440-
getStatusWrapper(), *reinterpret_cast<const OpaqueTimeTz*>(&message[descriptor.offset]));
435+
return calendarConverter.opaqueTimeTzToTimeTz(
436+
&statusWrapper, *reinterpret_cast<const OpaqueTimeTz*>(&message[descriptor.offset]));
441437

442438
default:
443439
throwInvalidType("TimeTz", descriptor.adjustedType);
@@ -477,8 +473,8 @@ namespace fbcpp
477473
switch (descriptor.adjustedType)
478474
{
479475
case DescriptorAdjustedType::TIMESTAMP_TZ:
480-
return getCalendarConverter().opaqueTimestampTzToTimestampTz(
481-
getStatusWrapper(), *reinterpret_cast<const OpaqueTimestampTz*>(&message[descriptor.offset]));
476+
return calendarConverter.opaqueTimestampTzToTimestampTz(
477+
&statusWrapper, *reinterpret_cast<const OpaqueTimestampTz*>(&message[descriptor.offset]));
482478

483479
default:
484480
throwInvalidType("TimestampTz", descriptor.adjustedType);
@@ -547,52 +543,51 @@ namespace fbcpp
547543
return (message[descriptor.offset] != std::byte{0}) ? std::string{"true"} : std::string{"false"};
548544

549545
case DescriptorAdjustedType::INT16:
550-
return getNumericConverter().numberToString(
546+
return numericConverter.numberToString(
551547
ScaledInt16{*reinterpret_cast<const std::int16_t*>(data), descriptor.scale});
552548

553549
case DescriptorAdjustedType::INT32:
554-
return getNumericConverter().numberToString(
550+
return numericConverter.numberToString(
555551
ScaledInt32{*reinterpret_cast<const std::int32_t*>(data), descriptor.scale});
556552

557553
case DescriptorAdjustedType::INT64:
558-
return getNumericConverter().numberToString(
554+
return numericConverter.numberToString(
559555
ScaledInt64{*reinterpret_cast<const std::int64_t*>(data), descriptor.scale});
560556

561557
case DescriptorAdjustedType::INT128:
562-
return getNumericConverter().opaqueInt128ToString(
563-
getStatusWrapper(), *reinterpret_cast<const OpaqueInt128*>(data), descriptor.scale);
558+
return numericConverter.opaqueInt128ToString(
559+
&statusWrapper, *reinterpret_cast<const OpaqueInt128*>(data), descriptor.scale);
564560

565561
case DescriptorAdjustedType::FLOAT:
566-
return getNumericConverter().numberToString(*reinterpret_cast<const float*>(data));
562+
return numericConverter.numberToString(*reinterpret_cast<const float*>(data));
567563

568564
case DescriptorAdjustedType::DOUBLE:
569-
return getNumericConverter().numberToString(*reinterpret_cast<const double*>(data));
565+
return numericConverter.numberToString(*reinterpret_cast<const double*>(data));
570566

571567
case DescriptorAdjustedType::DATE:
572-
return getCalendarConverter().opaqueDateToString(*reinterpret_cast<const OpaqueDate*>(data));
568+
return calendarConverter.opaqueDateToString(*reinterpret_cast<const OpaqueDate*>(data));
573569

574570
case DescriptorAdjustedType::TIME:
575-
return getCalendarConverter().opaqueTimeToString(*reinterpret_cast<const OpaqueTime*>(data));
571+
return calendarConverter.opaqueTimeToString(*reinterpret_cast<const OpaqueTime*>(data));
576572

577573
case DescriptorAdjustedType::TIMESTAMP:
578-
return getCalendarConverter().opaqueTimestampToString(
579-
*reinterpret_cast<const OpaqueTimestamp*>(data));
574+
return calendarConverter.opaqueTimestampToString(*reinterpret_cast<const OpaqueTimestamp*>(data));
580575

581576
case DescriptorAdjustedType::TIME_TZ:
582-
return getCalendarConverter().opaqueTimeTzToString(
583-
getStatusWrapper(), *reinterpret_cast<const OpaqueTimeTz*>(data));
577+
return calendarConverter.opaqueTimeTzToString(
578+
&statusWrapper, *reinterpret_cast<const OpaqueTimeTz*>(data));
584579

585580
case DescriptorAdjustedType::TIMESTAMP_TZ:
586-
return getCalendarConverter().opaqueTimestampTzToString(
587-
getStatusWrapper(), *reinterpret_cast<const OpaqueTimestampTz*>(data));
581+
return calendarConverter.opaqueTimestampTzToString(
582+
&statusWrapper, *reinterpret_cast<const OpaqueTimestampTz*>(data));
588583

589584
case DescriptorAdjustedType::DECFLOAT16:
590-
return getNumericConverter().opaqueDecFloat16ToString(
591-
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat16*>(data));
585+
return numericConverter.opaqueDecFloat16ToString(
586+
&statusWrapper, *reinterpret_cast<const OpaqueDecFloat16*>(data));
592587

593588
case DescriptorAdjustedType::DECFLOAT34:
594-
return getNumericConverter().opaqueDecFloat34ToString(
595-
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat34*>(data));
589+
return numericConverter.opaqueDecFloat34ToString(
590+
&statusWrapper, *reinterpret_cast<const OpaqueDecFloat34*>(data));
596591

597592
case DescriptorAdjustedType::STRING:
598593
return std::string{reinterpret_cast<const char*>(data + sizeof(std::uint16_t)),
@@ -623,10 +618,10 @@ namespace fbcpp
623618

624619
constexpr std::size_t N = fieldCountV<T>;
625620

626-
if (N != getDescriptors().size())
621+
if (N != descriptors->size())
627622
{
628623
throw FbCppException("Struct field count (" + std::to_string(N) +
629-
") does not match output column count (" + std::to_string(getDescriptors().size()) + ")");
624+
") does not match output column count (" + std::to_string(descriptors->size()) + ")");
630625
}
631626

632627
return getStruct<T>(std::make_index_sequence<N>{});
@@ -642,10 +637,10 @@ namespace fbcpp
642637

643638
constexpr std::size_t N = std::tuple_size_v<T>;
644639

645-
if (N != getDescriptors().size())
640+
if (N != descriptors->size())
646641
{
647642
throw FbCppException("Tuple element count (" + std::to_string(N) +
648-
") does not match output column count (" + std::to_string(getDescriptors().size()) + ")");
643+
") does not match output column count (" + std::to_string(descriptors->size()) + ")");
649644
}
650645

651646
return getTuple<T>(std::make_index_sequence<N>{});
@@ -684,12 +679,10 @@ namespace fbcpp
684679
private:
685680
const Descriptor& getDescriptor(unsigned index)
686681
{
687-
const auto& descs = getDescriptors();
688-
689-
if (index >= descs.size())
682+
if (index >= descriptors->size())
690683
throw std::out_of_range("index out of range");
691684

692-
return descs[index];
685+
return (*descriptors)[index];
693686
}
694687

695688
template <typename T, std::size_t... Is>
@@ -931,19 +924,19 @@ namespace fbcpp
931924
#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
932925
case DescriptorAdjustedType::INT128:
933926
boostInt128.emplace(
934-
getNumericConverter().opaqueInt128ToBoostInt128(*reinterpret_cast<const OpaqueInt128*>(data)));
927+
numericConverter.opaqueInt128ToBoostInt128(*reinterpret_cast<const OpaqueInt128*>(data)));
935928
data = reinterpret_cast<const std::byte*>(&boostInt128.value());
936929
break;
937930

938931
case DescriptorAdjustedType::DECFLOAT16:
939-
boostDecFloat16.emplace(getNumericConverter().opaqueDecFloat16ToBoostDecFloat16(
940-
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat16*>(data)));
932+
boostDecFloat16.emplace(numericConverter.opaqueDecFloat16ToBoostDecFloat16(
933+
&statusWrapper, *reinterpret_cast<const OpaqueDecFloat16*>(data)));
941934
data = reinterpret_cast<const std::byte*>(&boostDecFloat16.value());
942935
break;
943936

944937
case DescriptorAdjustedType::DECFLOAT34:
945-
boostDecFloat34.emplace(getNumericConverter().opaqueDecFloat34ToBoostDecFloat34(
946-
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat34*>(data)));
938+
boostDecFloat34.emplace(numericConverter.opaqueDecFloat34ToBoostDecFloat34(
939+
&statusWrapper, *reinterpret_cast<const OpaqueDecFloat34*>(data)));
947940
data = reinterpret_cast<const std::byte*>(&boostDecFloat34.value());
948941
break;
949942
#endif
@@ -985,39 +978,37 @@ namespace fbcpp
985978
switch (descriptor.adjustedType)
986979
{
987980
case DescriptorAdjustedType::INT16:
988-
return getNumericConverter().numberToNumber<T>(
981+
return numericConverter.numberToNumber<T>(
989982
ScaledInt16{*reinterpret_cast<const std::int16_t*>(data), descriptor.scale}, toScale.value());
990983

991984
case DescriptorAdjustedType::INT32:
992-
return getNumericConverter().numberToNumber<T>(
985+
return numericConverter.numberToNumber<T>(
993986
ScaledInt32{*reinterpret_cast<const std::int32_t*>(data), descriptor.scale}, toScale.value());
994987

995988
case DescriptorAdjustedType::INT64:
996-
return getNumericConverter().numberToNumber<T>(
989+
return numericConverter.numberToNumber<T>(
997990
ScaledInt64{*reinterpret_cast<const std::int64_t*>(data), descriptor.scale}, toScale.value());
998991

999992
#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
1000993
case DescriptorAdjustedType::INT128:
1001-
return getNumericConverter().numberToNumber<T>(
994+
return numericConverter.numberToNumber<T>(
1002995
ScaledBoostInt128{*reinterpret_cast<const BoostInt128*>(data), descriptor.scale},
1003996
toScale.value());
1004997

1005998
case DescriptorAdjustedType::DECFLOAT16:
1006-
return getNumericConverter().numberToNumber<T>(
999+
return numericConverter.numberToNumber<T>(
10071000
*reinterpret_cast<const BoostDecFloat16*>(data), toScale.value());
10081001

10091002
case DescriptorAdjustedType::DECFLOAT34:
1010-
return getNumericConverter().numberToNumber<T>(
1003+
return numericConverter.numberToNumber<T>(
10111004
*reinterpret_cast<const BoostDecFloat34*>(data), toScale.value());
10121005
#endif
10131006

10141007
case DescriptorAdjustedType::FLOAT:
1015-
return getNumericConverter().numberToNumber<T>(
1016-
*reinterpret_cast<const float*>(data), toScale.value());
1008+
return numericConverter.numberToNumber<T>(*reinterpret_cast<const float*>(data), toScale.value());
10171009

10181010
case DescriptorAdjustedType::DOUBLE:
1019-
return getNumericConverter().numberToNumber<T>(
1020-
*reinterpret_cast<const double*>(data), toScale.value());
1011+
return numericConverter.numberToNumber<T>(*reinterpret_cast<const double*>(data), toScale.value());
10211012

10221013
default:
10231014
throwInvalidType(toTypeName, descriptor.adjustedType);
@@ -1027,29 +1018,10 @@ namespace fbcpp
10271018
private:
10281019
const std::byte* message = nullptr;
10291020
const std::vector<Descriptor>* descriptors = nullptr;
1030-
impl::StatusWrapper* statusWrapper = nullptr;
1031-
impl::NumericConverter* numericConverter = nullptr;
1032-
impl::CalendarConverter* calendarConverter = nullptr;
1033-
1034-
impl::StatusWrapper* getStatusWrapper() const
1035-
{
1036-
return statusWrapper;
1037-
}
1038-
1039-
const std::vector<Descriptor>& getDescriptors() const
1040-
{
1041-
return *descriptors;
1042-
}
1043-
1044-
impl::NumericConverter& getNumericConverter() const
1045-
{
1046-
return *numericConverter;
1047-
}
1048-
1049-
impl::CalendarConverter& getCalendarConverter() const
1050-
{
1051-
return *calendarConverter;
1052-
}
1021+
Client* client = nullptr;
1022+
impl::StatusWrapper statusWrapper;
1023+
impl::NumericConverter numericConverter;
1024+
impl::CalendarConverter calendarConverter;
10531025
};
10541026

10551027
///

src/fb-cpp/RowSet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ using namespace fbcpp::impl;
3131

3232

3333
RowSet::RowSet(Statement& statement, unsigned maxRows)
34-
: statusWrapper{statement.getAttachment().getClient()},
34+
: client{&statement.getAttachment().getClient()},
35+
statusWrapper{statement.getAttachment().getClient()},
3536
numericConverter{statement.getAttachment().getClient()},
3637
calendarConverter{statement.getAttachment().getClient()}
3738
{

src/fb-cpp/RowSet.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ namespace fbcpp
7070
explicit RowSet(Statement& statement, unsigned maxRows);
7171

7272
RowSet(RowSet&& o) noexcept
73-
: count{o.count},
73+
: client{o.client},
74+
count{o.count},
7475
messageLength{o.messageLength},
7576
buffer{std::move(o.buffer)},
7677
descriptors{std::move(o.descriptors)},
@@ -86,6 +87,7 @@ namespace fbcpp
8687
{
8788
if (this != &o)
8889
{
90+
client = o.client;
8991
count = o.count;
9092
messageLength = o.messageLength;
9193
buffer = std::move(o.buffer);
@@ -128,7 +130,7 @@ namespace fbcpp
128130
{
129131
assert(index < count);
130132
const auto* data = buffer.data() + static_cast<std::size_t>(index) * messageLength;
131-
return Row{data, descriptors, statusWrapper, numericConverter, calendarConverter};
133+
return Row{*client, descriptors, data};
132134
}
133135

134136
///
@@ -151,6 +153,7 @@ namespace fbcpp
151153
}
152154

153155
private:
156+
Client* client = nullptr;
154157
unsigned count = 0;
155158
unsigned messageLength = 0;
156159
std::vector<std::byte> buffer;

src/fb-cpp/Statement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Statement::Statement(
178178
outMetadata.reset(statementHandle->getOutputMetadata(&statusWrapper));
179179
processMetadata(outMetadata, outDescriptors, outMessage);
180180

181-
outRow = Row(outMessage.data(), outDescriptors, statusWrapper, numericConverter, calendarConverter);
181+
outRow = std::make_unique<Row>(attachment.getClient(), outDescriptors, outMessage.data());
182182
}
183183

184184
void Statement::free()

0 commit comments

Comments
 (0)