Skip to content

Commit 886c964

Browse files
committed
Documentation
1 parent f167ddd commit 886c964

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A modern C++ wrapper for the Firebird database API.
44

55
[Documentation](https://asfernandes.github.io/fb-cpp)
6+
[Repository](https://github.com/asfernandes/fb-cpp)
67

78
## Overview
89

src/lib/types.h

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,77 @@
4444
///
4545
namespace fbcpp
4646
{
47+
///
48+
/// Represents a numeric value with an explicit decimal scale.
49+
///
4750
template <typename T>
4851
struct ScaledNumber final
4952
{
5053
bool operator==(const ScaledNumber&) const noexcept = default;
5154

55+
///
56+
/// Unscaled numeric value.
57+
///
5258
T value{};
59+
60+
///
61+
/// Decimal scale applied to `value`.
62+
///
5363
int scale = 0;
5464
};
5565

66+
///
67+
/// Signed 16-bit scaled number.
68+
///
5669
using ScaledInt16 = ScaledNumber<std::int16_t>;
70+
71+
///
72+
/// Signed 32-bit scaled number.
73+
///
5774
using ScaledInt32 = ScaledNumber<std::int32_t>;
75+
76+
///
77+
/// Signed 64-bit scaled number.
78+
///
5879
using ScaledInt64 = ScaledNumber<std::int64_t>;
5980

6081
#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
82+
///
83+
/// 128-bit integer using Boost.Multiprecision.
84+
///
6185
using BoostInt128 = boost::multiprecision::int128_t;
86+
87+
///
88+
/// Scaled 128-bit integer backed by Boost.Multiprecision.
89+
///
6290
using ScaledBoostInt128 = ScaledNumber<BoostInt128>;
6391
#endif
6492

6593
#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
94+
///
95+
/// 16-digit decimal floating point using Boost.Multiprecision.
96+
///
6697
using BoostDecFloat16 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<16>>;
98+
99+
///
100+
/// 34-digit decimal floating point using Boost.Multiprecision.
101+
///
67102
using BoostDecFloat34 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<34>>;
68103
#endif
69104

105+
///
106+
/// Firebird SQL calendar date.
107+
///
70108
using Date = std::chrono::year_month_day;
109+
110+
///
111+
/// Firebird SQL time-of-day with microsecond resolution.
112+
///
71113
using Time = std::chrono::hh_mm_ss<std::chrono::microseconds>;
72114

115+
///
116+
/// Combined date and time with microsecond precision.
117+
///
73118
struct Timestamp final
74119
{
75120
bool operator==(const Timestamp& other) const noexcept
@@ -87,6 +132,9 @@ namespace fbcpp
87132
return std::chrono::local_days{date} + time.to_duration();
88133
}
89134

135+
///
136+
/// Builds a timestamp from a local-time value.
137+
///
90138
static Timestamp fromLocalTime(std::chrono::local_time<std::chrono::microseconds> value) noexcept
91139
{
92140
const auto days = std::chrono::floor<std::chrono::days>(value);
@@ -96,48 +144,105 @@ namespace fbcpp
96144
return Timestamp{dateValue, Time{timeOfDay}};
97145
}
98146

147+
///
148+
/// Calendar date component.
149+
///
99150
Date date{};
151+
152+
///
153+
/// Time-of-day component.
154+
///
100155
Time time{std::chrono::microseconds::zero()};
101156
};
102157

158+
///
159+
/// Local time bound to a time zone.
160+
///
103161
struct TimeTz final
104162
{
105163
bool operator==(const TimeTz& other) const noexcept
106164
{
107165
return utcTime.to_duration() == other.utcTime.to_duration() && zone == other.zone;
108166
}
109167

168+
///
169+
/// UTC-normalised time-of-day.
170+
///
110171
Time utcTime;
172+
173+
///
174+
/// Time zone identifier.
175+
///
111176
std::string zone;
112177
};
113178

179+
///
180+
/// Timestamp bound to a time zone.
181+
///
114182
struct TimestampTz final
115183
{
116184
bool operator==(const TimestampTz&) const noexcept = default;
117185

186+
///
187+
/// UTC-normalised timestamp.
188+
///
118189
Timestamp utcTimestamp;
190+
191+
///
192+
/// Time zone identifier.
193+
///
119194
std::string zone;
120195
};
121196

197+
///
198+
/// Opaque 128-bit integer exposed by the Firebird API.
199+
///
122200
using OpaqueInt128 = FB_I128;
201+
202+
///
203+
/// Opaque 16-digit decimal floating point exposed by the Firebird API.
204+
///
123205
using OpaqueDecFloat16 = FB_DEC16;
206+
207+
///
208+
/// Opaque 34-digit decimal floating point exposed by the Firebird API.
209+
///
124210
using OpaqueDecFloat34 = FB_DEC34;
211+
212+
///
213+
/// Scaled Firebird opaque 128-bit integer.
214+
///
125215
using ScaledOpaqueInt128 = ScaledNumber<OpaqueInt128>;
126216

217+
///
218+
/// Wrapper for Firebird date values.
219+
///
127220
struct alignas(alignof(ISC_DATE)) OpaqueDate final
128221
{
129222
bool operator==(const OpaqueDate&) const noexcept = default;
130223

224+
///
225+
/// Raw Firebird date representation.
226+
///
131227
ISC_DATE value;
132228
};
133229

230+
///
231+
/// Wrapper for Firebird time values.
232+
///
134233
struct alignas(alignof(ISC_TIME)) OpaqueTime final
135234
{
136235
bool operator==(const OpaqueTime&) const noexcept = default;
137236

237+
///
238+
/// Raw Firebird time representation.
239+
///
138240
ISC_TIME value;
139241
};
140242

243+
///
244+
/// Wrapper for Firebird timestamp values.
245+
///
141246
struct alignas(alignof(ISC_TIMESTAMP)) OpaqueTimestamp final
142247
{
143248
bool operator==(const OpaqueTimestamp& other) const noexcept
@@ -146,24 +251,42 @@ namespace fbcpp
146251
value.timestamp_time == other.value.timestamp_time;
147252
}
148253

254+
///
255+
/// Raw Firebird timestamp representation.
256+
///
149257
ISC_TIMESTAMP value;
150258
};
151259

260+
///
261+
/// Wrapper for Firebird time-with-time-zone values.
262+
///
152263
struct alignas(alignof(ISC_TIME_TZ)) OpaqueTimeTz final
153264
{
154265
bool operator==(const OpaqueTimeTz&) const noexcept = default;
155266

267+
///
268+
/// Raw Firebird time-with-time-zone representation.
269+
///
156270
ISC_TIME_TZ value;
157271
};
158272

273+
///
274+
/// Wrapper for Firebird timestamp-with-time-zone values.
275+
///
159276
struct alignas(alignof(ISC_TIMESTAMP_TZ)) OpaqueTimestampTz final
160277
{
161278
bool operator==(const OpaqueTimestampTz&) const noexcept = default;
162279

280+
///
281+
/// Raw Firebird timestamp-with-time-zone representation.
282+
///
163283
ISC_TIMESTAMP_TZ value;
164284
};
165285

166286
// FIXME: test
287+
///
288+
/// Stream insertion helper that renders the scaled number as `value` followed by `e` and the scale.
289+
///
167290
template <typename T>
168291
std::ostream& operator<<(std::ostream& os, const fbcpp::ScaledNumber<T>& scaledNumber)
169292
{
@@ -174,14 +297,23 @@ namespace fbcpp
174297

175298

176299
// FIXME: test
300+
///
301+
/// Formatter for `fbcpp::ScaledNumber` that mirrors the stream output contract.
302+
///
177303
template <typename T>
178304
struct std::formatter<fbcpp::ScaledNumber<T>> : std::formatter<T>
179305
{
306+
///
307+
/// Parses the format specifier forwarded to the underlying formatter.
308+
///
180309
constexpr auto parse(format_parse_context& ctx)
181310
{
182311
return std::formatter<T>::parse(ctx);
183312
}
184313

314+
///
315+
/// Emits the scaled number using the native formatter for the value followed by the scale suffix.
316+
///
185317
template <typename FormatContext>
186318
auto format(const fbcpp::ScaledNumber<T>& scaledNumber, FormatContext& ctx) const
187319
{

0 commit comments

Comments
 (0)