field_view.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. //
  2. // Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BHO_MYSQL_FIELD_VIEW_HPP
  8. #define BHO_MYSQL_FIELD_VIEW_HPP
  9. #include <asio2/bho/mysql/blob_view.hpp>
  10. #include <asio2/bho/mysql/date.hpp>
  11. #include <asio2/bho/mysql/datetime.hpp>
  12. #include <asio2/bho/mysql/field_kind.hpp>
  13. #include <asio2/bho/mysql/string_view.hpp>
  14. #include <asio2/bho/mysql/time.hpp>
  15. #include <asio2/bho/mysql/detail/access.hpp>
  16. #include <asio2/bho/mysql/detail/config.hpp>
  17. #include <asio2/bho/mysql/detail/field_impl.hpp>
  18. #include <asio2/bho/mysql/detail/string_view_offset.hpp>
  19. #include <asio2/bho/config.hpp>
  20. #include <cstddef>
  21. #include <cstdint>
  22. #include <iosfwd>
  23. namespace bho {
  24. namespace mysql {
  25. /**
  26. * \brief Non-owning variant-like class that can represent of any of the allowed database types.
  27. * \details
  28. * This is a variant-like class, similar to \ref field, but semi-owning and read-only. Values
  29. * of this type are usually created by the library, not directly by the user. It's cheap to
  30. * construct and copy, and it's the main library interface when reading values from MySQL.
  31. * \n
  32. * Like a variant, at any point, a `field_view` always points to a value of
  33. * certain type. You can query the type using \ref field_view::kind and the `is_xxx` functions
  34. * like \ref field_view::is_int64. Use `as_xxx` and `get_xxx` for checked and unchecked value
  35. * access, respectively. As opposed to \ref field, these functions return values instead of
  36. * references.
  37. *
  38. * \par Object lifetimes
  39. * Depending on how it was constructed, `field_view` can have value or reference semantics:
  40. * \n
  41. * \li If it was created by the library, the `field_view` will have an associated \ref row,
  42. * \ref rows or \ref results object holding memory to which the `field_view` points. It will be valid as
  43. * long as the memory allocated by that object is valid.
  44. * \li If it was created from a \ref field (by calling `operator field_view`), the
  45. * `field_view` acts as a reference to that `field` object, and will be valid as long as the
  46. * `field` is.
  47. * \li If it was created from a scalar (null, integral, floating point, date, datetime or time), the
  48. * `field_view` has value semnatics and will always be valid.
  49. * \li If it was created from a string or blob type, the `field_view` acts as a `string_view` or `blob_view`,
  50. * and will be valid as long as the original string/blob is.
  51. * \n
  52. * Calling any member function on a `field_view` that has been invalidated results in undefined
  53. * behavior.
  54. */
  55. class field_view
  56. {
  57. public:
  58. /**
  59. * \brief Constructs a `field_view` holding NULL.
  60. * \par Exception safety
  61. * No-throw guarantee.
  62. *
  63. * \par Object lifetimes
  64. * Results in a `field_view` with value semantics (always valid).
  65. */
  66. BHO_CXX14_CONSTEXPR field_view() = default;
  67. /**
  68. * \brief (EXPERIMENTAL) Constructs a `field_view` holding NULL.
  69. * \details
  70. * Caution: `field_view(NULL)` will <b>not</b> match this overload. It will try to construct
  71. * a `string_view` from a NULL C string, causing undefined behavior.
  72. *
  73. * \par Exception safety
  74. * No-throw guarantee.
  75. *
  76. * \par Object lifetimes
  77. * Results in a `field_view` with value semantics (always valid).
  78. */
  79. BHO_CXX14_CONSTEXPR explicit field_view(std::nullptr_t) noexcept {}
  80. /**
  81. * \brief (EXPERIMENTAL) Constructs a `field_view` holding an `int64`.
  82. * \par Exception safety
  83. * No-throw guarantee.
  84. *
  85. * \par Object lifetimes
  86. * Results in a `field_view` with value semantics (always valid).
  87. */
  88. BHO_CXX14_CONSTEXPR explicit field_view(signed char v) noexcept : impl_{std::int64_t(v)} {}
  89. /// \copydoc field_view(signed char)
  90. BHO_CXX14_CONSTEXPR explicit field_view(short v) noexcept : impl_{std::int64_t(v)} {}
  91. /// \copydoc field_view(signed char)
  92. BHO_CXX14_CONSTEXPR explicit field_view(int v) noexcept : impl_{std::int64_t(v)} {}
  93. /// \copydoc field_view(signed char)
  94. BHO_CXX14_CONSTEXPR explicit field_view(long v) noexcept : impl_{std::int64_t(v)} {}
  95. /// \copydoc field_view(signed char)
  96. BHO_CXX14_CONSTEXPR explicit field_view(long long v) noexcept : impl_{std::int64_t(v)} {}
  97. /**
  98. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a `uint64`.
  99. * \par Exception safety
  100. * No-throw guarantee.
  101. *
  102. * \par Object lifetimes
  103. * Results in a `field_view` with value semantics (always valid).
  104. */
  105. BHO_CXX14_CONSTEXPR explicit field_view(unsigned char v) noexcept : impl_{std::uint64_t(v)} {}
  106. /// \copydoc field_view(unsigned char)
  107. BHO_CXX14_CONSTEXPR explicit field_view(unsigned short v) noexcept : impl_{std::uint64_t(v)} {}
  108. /// \copydoc field_view(unsigned char)
  109. BHO_CXX14_CONSTEXPR explicit field_view(unsigned int v) noexcept : impl_{std::uint64_t(v)} {}
  110. /// \copydoc field_view(unsigned char)
  111. BHO_CXX14_CONSTEXPR explicit field_view(unsigned long v) noexcept : impl_{std::uint64_t(v)} {}
  112. /// \copydoc field_view(unsigned char)
  113. BHO_CXX14_CONSTEXPR explicit field_view(unsigned long long v) noexcept : impl_{std::uint64_t(v)} {}
  114. /**
  115. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a string.
  116. * \par Exception safety
  117. * No-throw guarantee.
  118. *
  119. * \par Object lifetimes
  120. * Results in a `field_view` with reference semantics. It will
  121. * be valid as long as the character buffer the `string_view` points to is valid.
  122. */
  123. BHO_CXX14_CONSTEXPR explicit field_view(string_view v) noexcept : impl_{v} {}
  124. /**
  125. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a blob.
  126. * \par Exception safety
  127. * No-throw guarantee.
  128. *
  129. * \par Object lifetimes
  130. * Results in a `field_view` with reference semantics. It will
  131. * be valid as long as the character buffer the `blob_view` points to is valid.
  132. */
  133. BHO_CXX14_CONSTEXPR explicit field_view(blob_view v) noexcept : impl_{v} {}
  134. /**
  135. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a `float`.
  136. * \par Exception safety
  137. * No-throw guarantee.
  138. *
  139. * \par Object lifetimes
  140. * Results in a `field_view` with value semantics (always valid).
  141. */
  142. BHO_CXX14_CONSTEXPR explicit field_view(float v) noexcept : impl_{v} {}
  143. /**
  144. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a `double`.
  145. * \par Exception safety
  146. * No-throw guarantee.
  147. *
  148. * \par Object lifetimes
  149. * Results in a `field_view` with value semantics (always valid).
  150. */
  151. BHO_CXX14_CONSTEXPR explicit field_view(double v) noexcept : impl_{v} {}
  152. /**
  153. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a `date`.
  154. * \par Exception safety
  155. * No-throw guarantee.
  156. *
  157. * \par Object lifetimes
  158. * Results in a `field_view` with value semantics (always valid).
  159. */
  160. BHO_CXX14_CONSTEXPR explicit field_view(const date& v) noexcept : impl_{v} {}
  161. /**
  162. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a `datetime`.
  163. * \par Exception safety
  164. * No-throw guarantee.
  165. *
  166. * \par Object lifetimes
  167. * Results in a `field_view` with value semantics (always valid).
  168. */
  169. BHO_CXX14_CONSTEXPR explicit field_view(const datetime& v) noexcept : impl_{v} {}
  170. /**
  171. * \brief (EXPERIMENTAL) Constructs a `field_view` holding a `time`.
  172. * \par Exception safety
  173. * No-throw guarantee.
  174. *
  175. * \par Object lifetimes
  176. * Results in a `field_view` with value semantics (always valid).
  177. */
  178. BHO_CXX14_CONSTEXPR explicit field_view(const time& v) noexcept : impl_{v} {}
  179. /**
  180. * \brief Returns the type of the value this `field_view` is pointing to.
  181. * \par Exception safety
  182. * No-throw guarantee.
  183. */
  184. BHO_CXX14_CONSTEXPR inline field_kind kind() const noexcept;
  185. /**
  186. * \brief Returns whether this `field_view` points to a `NULL` value.
  187. * \par Exception safety
  188. * No-throw guarantee.
  189. */
  190. BHO_CXX14_CONSTEXPR bool is_null() const noexcept { return kind() == field_kind::null; }
  191. /**
  192. * \brief Returns whether this `field_view` points to a `int64` value.
  193. * \par Exception safety
  194. * No-throw guarantee.
  195. */
  196. BHO_CXX14_CONSTEXPR bool is_int64() const noexcept { return kind() == field_kind::int64; }
  197. /**
  198. * \brief Returns whether this `field_view` points to a `uint64` value.
  199. * \par Exception safety
  200. * No-throw guarantee.
  201. */
  202. BHO_CXX14_CONSTEXPR bool is_uint64() const noexcept { return kind() == field_kind::uint64; }
  203. /**
  204. * \brief Returns whether this `field_view` points to a string value.
  205. * \par Exception safety
  206. * No-throw guarantee.
  207. */
  208. BHO_CXX14_CONSTEXPR bool is_string() const noexcept { return kind() == field_kind::string; }
  209. /**
  210. * \brief Returns whether this `field_view` points to a binary blob.
  211. * \par Exception safety
  212. * No-throw guarantee.
  213. */
  214. BHO_CXX14_CONSTEXPR bool is_blob() const noexcept { return kind() == field_kind::blob; }
  215. /**
  216. * \brief Returns whether this `field_view` points to a `float` value.
  217. * \par Exception safety
  218. * No-throw guarantee.
  219. */
  220. BHO_CXX14_CONSTEXPR bool is_float() const noexcept { return kind() == field_kind::float_; }
  221. /**
  222. * \brief Returns whether this `field_view` points to a `double` value.
  223. * \par Exception safety
  224. * No-throw guarantee.
  225. */
  226. BHO_CXX14_CONSTEXPR bool is_double() const noexcept { return kind() == field_kind::double_; }
  227. /**
  228. * \brief Returns whether this `field_view` points to a `date` value.
  229. * \par Exception safety
  230. * No-throw guarantee.
  231. */
  232. BHO_CXX14_CONSTEXPR bool is_date() const noexcept { return kind() == field_kind::date; }
  233. /**
  234. * \brief Returns whether this `field_view` points to a `datetime` value.
  235. * \par Exception safety
  236. * No-throw guarantee.
  237. */
  238. BHO_CXX14_CONSTEXPR bool is_datetime() const noexcept { return kind() == field_kind::datetime; }
  239. /**
  240. * \brief Returns whether this `field_view` points to a `time` value.
  241. * \par Exception safety
  242. * No-throw guarantee.
  243. */
  244. BHO_CXX14_CONSTEXPR bool is_time() const noexcept { return kind() == field_kind::time; }
  245. /**
  246. * \brief Retrieves the underlying value as an `int64` or throws an exception.
  247. * \par Exception safety
  248. * Strong guarantee. Throws on type mismatch.
  249. * \throws bad_field_access If `!this->is_int64()`
  250. */
  251. BHO_CXX14_CONSTEXPR inline std::int64_t as_int64() const;
  252. /**
  253. * \brief Retrieves the underlying value as an `uint64` or throws an exception.
  254. * \par Exception safety
  255. * Strong guarantee. Throws on type mismatch.
  256. * \throws bad_field_access If `!this->is_uint64()`
  257. */
  258. BHO_CXX14_CONSTEXPR inline std::uint64_t as_uint64() const;
  259. /**
  260. * \brief Retrieves the underlying value as a string or throws an exception.
  261. * \par Exception safety
  262. * Strong guarantee. Throws on type mismatch.
  263. * \throws bad_field_access If `!this->is_string()`
  264. * \par Object lifetimes
  265. * The returned view has the same lifetime rules as `*this` (it's valid as long as `*this` is valid).
  266. */
  267. BHO_CXX14_CONSTEXPR inline string_view as_string() const;
  268. /**
  269. * \brief Retrieves the underlying value as a blob or throws an exception.
  270. * \par Exception safety
  271. * Strong guarantee. Throws on type mismatch.
  272. * \throws bad_field_access If `!this->is_blob()`
  273. * \par Object lifetimes
  274. * The returned view has the same lifetime rules as `*this` (it's valid as long as `*this` is valid).
  275. */
  276. BHO_CXX14_CONSTEXPR inline blob_view as_blob() const;
  277. /**
  278. * \brief Retrieves the underlying value as a `float` or throws an exception.
  279. * \par Exception safety
  280. * Strong guarantee. Throws on type mismatch.
  281. * \throws bad_field_access If `!this->is_float()`
  282. */
  283. BHO_CXX14_CONSTEXPR inline float as_float() const;
  284. /**
  285. * \brief Retrieves the underlying value as a `double` or throws an exception.
  286. * \par Exception safety
  287. * Strong guarantee. Throws on type mismatch.
  288. * \throws bad_field_access If `!this->is_double()`
  289. */
  290. BHO_CXX14_CONSTEXPR inline double as_double() const;
  291. /**
  292. * \brief Retrieves the underlying value as a `date` or throws an exception.
  293. * \par Exception safety
  294. * Strong guarantee. Throws on type mismatch.
  295. * \throws bad_field_access If `!this->is_date()`
  296. */
  297. BHO_CXX14_CONSTEXPR inline date as_date() const;
  298. /**
  299. * \brief Retrieves the underlying value as a `datetime` or throws an exception.
  300. * \par Exception safety
  301. * Strong guarantee. Throws on type mismatch.
  302. * \throws bad_field_access If `!this->is_datetime()`
  303. */
  304. BHO_CXX14_CONSTEXPR inline datetime as_datetime() const;
  305. /**
  306. * \brief Retrieves the underlying value as a `time` or throws an exception.
  307. * \par Exception safety
  308. * Strong guarantee. Throws on type mismatch.
  309. * \throws bad_field_access If `!this->is_time()`
  310. */
  311. BHO_CXX14_CONSTEXPR inline time as_time() const;
  312. /**
  313. * \brief Retrieves the underlying value as an `int64` (unchecked access).
  314. * \par Preconditions
  315. * `this->is_int64() == true` (if violated, results in undefined behavior).
  316. *
  317. * \par Exception safety
  318. * No-throw guarantee.
  319. */
  320. BHO_CXX14_CONSTEXPR inline std::int64_t get_int64() const noexcept
  321. {
  322. return is_field_ptr() ? impl_.repr.field_ptr->get<std::int64_t>() : impl_.repr.int64;
  323. }
  324. /**
  325. * \brief Retrieves the underlying value as an `uint64` (unchecked access).
  326. * \par Preconditions
  327. * `this->is_uint64() == true` (if violated, results in undefined behavior).
  328. *
  329. * \par Exception safety
  330. * No-throw guarantee.
  331. */
  332. BHO_CXX14_CONSTEXPR inline std::uint64_t get_uint64() const noexcept
  333. {
  334. return is_field_ptr() ? impl_.repr.field_ptr->get<std::uint64_t>() : impl_.repr.uint64;
  335. }
  336. /**
  337. * \brief Retrieves the underlying value as a string (unchecked access).
  338. * \par Preconditions
  339. * `this->is_string() == true` (if violated, results in undefined behavior).
  340. *
  341. * \par Exception safety
  342. * No-throw guarantee.
  343. *
  344. * \par Object lifetimes
  345. * The returned view has the same lifetime rules as `*this` (it's valid as long as `*this` is valid).
  346. */
  347. BHO_CXX14_CONSTEXPR inline string_view get_string() const noexcept
  348. {
  349. return is_field_ptr() ? string_view(impl_.repr.field_ptr->get<std::string>()) : impl_.repr.string;
  350. }
  351. /**
  352. * \brief Retrieves the underlying value as a blob (unchecked access).
  353. * \par Preconditions
  354. * `this->is_blob() == true` (if violated, results in undefined behavior).
  355. *
  356. * \par Exception safety
  357. * No-throw guarantee.
  358. *
  359. * \par Object lifetimes
  360. * The returned view has the same lifetime rules as `*this` (it's valid as long as `*this` is valid).
  361. */
  362. BHO_CXX14_CONSTEXPR inline blob_view get_blob() const noexcept
  363. {
  364. return is_field_ptr() ? impl_.repr.field_ptr->get<blob>() : impl_.repr.blob;
  365. }
  366. /**
  367. * \brief Retrieves the underlying value as a `float` (unchecked access).
  368. * \par Preconditions
  369. * `this->is_float() == true` (if violated, results in undefined behavior).
  370. *
  371. * \par Exception safety
  372. * No-throw guarantee.
  373. */
  374. BHO_CXX14_CONSTEXPR inline float get_float() const noexcept
  375. {
  376. return is_field_ptr() ? impl_.repr.field_ptr->get<float>() : impl_.repr.float_;
  377. }
  378. /**
  379. * \brief Retrieves the underlying value as a `double` (unchecked access).
  380. * \par Preconditions
  381. * `this->is_double() == true` (if violated, results in undefined behavior).
  382. *
  383. * \par Exception safety
  384. * No-throw guarantee.
  385. */
  386. BHO_CXX14_CONSTEXPR inline double get_double() const noexcept
  387. {
  388. return is_field_ptr() ? impl_.repr.field_ptr->get<double>() : impl_.repr.double_;
  389. }
  390. /**
  391. * \brief Retrieves the underlying value as a `date` (unchecked access).
  392. * \par Preconditions
  393. * `this->is_date() == true` (if violated, results in undefined behavior).
  394. *
  395. * \par Exception safety
  396. * No-throw guarantee.
  397. */
  398. BHO_CXX14_CONSTEXPR inline date get_date() const noexcept
  399. {
  400. return is_field_ptr() ? impl_.repr.field_ptr->get<date>() : impl_.repr.date_;
  401. }
  402. /**
  403. * \brief Retrieves the underlying value as a `datetime` (unchecked access).
  404. * \par Preconditions
  405. * `this->is_datetime() == true` (if violated, results in undefined behavior).
  406. *
  407. * \par Exception safety
  408. * No-throw guarantee.
  409. */
  410. BHO_CXX14_CONSTEXPR inline datetime get_datetime() const noexcept
  411. {
  412. return is_field_ptr() ? impl_.repr.field_ptr->get<datetime>() : impl_.repr.datetime_;
  413. }
  414. /**
  415. * \brief Retrieves the underlying value as a `time` (unchecked access).
  416. * \par Preconditions
  417. * `this->is_time() == true` (if violated, results in undefined behavior).
  418. *
  419. * \par Exception safety
  420. * No-throw guarantee.
  421. */
  422. BHO_CXX14_CONSTEXPR inline time get_time() const noexcept
  423. {
  424. return is_field_ptr() ? impl_.repr.field_ptr->get<time>() : impl_.repr.time_;
  425. }
  426. /**
  427. * \brief Tests for equality.
  428. * \details
  429. * If one of the operands is a `uint64` and the other a
  430. * `int64`, and the values are equal, returns `true`. Otherwise, if the types are
  431. * different, returns always `false` (`float` and `double` values are considered to be
  432. * different between them). `NULL` values are equal to other `NULL` values.
  433. *
  434. * \par Exception safety
  435. * No-throw guarantee.
  436. */
  437. BHO_CXX14_CONSTEXPR inline bool operator==(const field_view& rhs) const noexcept;
  438. /**
  439. * \brief Tests for inequality.
  440. * \par Exception safety
  441. * No-throw guarantee.
  442. */
  443. BHO_CXX14_CONSTEXPR bool operator!=(const field_view& rhs) const noexcept { return !(*this == rhs); }
  444. private:
  445. BHO_CXX14_CONSTEXPR explicit field_view(detail::string_view_offset v, bool is_blob) noexcept
  446. : impl_{v, is_blob}
  447. {
  448. }
  449. BHO_CXX14_CONSTEXPR explicit field_view(const detail::field_impl* v) noexcept : impl_{v} {}
  450. enum class internal_kind
  451. {
  452. null = 0,
  453. int64,
  454. uint64,
  455. string,
  456. blob,
  457. float_,
  458. double_,
  459. date,
  460. datetime,
  461. time,
  462. sv_offset_string,
  463. sv_offset_blob,
  464. field_ptr
  465. };
  466. union repr_t
  467. {
  468. std::int64_t int64;
  469. std::uint64_t uint64;
  470. string_view string;
  471. blob_view blob;
  472. float float_;
  473. double double_;
  474. date date_;
  475. datetime datetime_;
  476. time time_;
  477. detail::string_view_offset sv_offset_;
  478. const detail::field_impl* field_ptr;
  479. BHO_CXX14_CONSTEXPR repr_t() noexcept : int64{} {}
  480. BHO_CXX14_CONSTEXPR repr_t(std::int64_t v) noexcept : int64(v) {}
  481. BHO_CXX14_CONSTEXPR repr_t(std::uint64_t v) noexcept : uint64(v) {}
  482. BHO_CXX14_CONSTEXPR repr_t(string_view v) noexcept : string{v} {}
  483. BHO_CXX14_CONSTEXPR repr_t(blob_view v) noexcept : blob{v} {}
  484. BHO_CXX14_CONSTEXPR repr_t(float v) noexcept : float_(v) {}
  485. BHO_CXX14_CONSTEXPR repr_t(double v) noexcept : double_(v) {}
  486. BHO_CXX14_CONSTEXPR repr_t(date v) noexcept : date_(v) {}
  487. BHO_CXX14_CONSTEXPR repr_t(datetime v) noexcept : datetime_(v) {}
  488. BHO_CXX14_CONSTEXPR repr_t(time v) noexcept : time_(v) {}
  489. BHO_CXX14_CONSTEXPR repr_t(detail::string_view_offset v) noexcept : sv_offset_(v) {}
  490. BHO_CXX14_CONSTEXPR repr_t(const detail::field_impl* v) noexcept : field_ptr(v) {}
  491. };
  492. struct impl_t
  493. {
  494. internal_kind ikind{internal_kind::null};
  495. repr_t repr{};
  496. // Required by lib internal functions
  497. bool is_string_offset() const noexcept { return ikind == internal_kind::sv_offset_string; }
  498. bool is_blob_offset() const noexcept { return ikind == internal_kind::sv_offset_blob; }
  499. BHO_CXX14_CONSTEXPR impl_t() = default;
  500. BHO_CXX14_CONSTEXPR impl_t(std::int64_t v) noexcept : ikind(internal_kind::int64), repr(v) {}
  501. BHO_CXX14_CONSTEXPR impl_t(std::uint64_t v) noexcept : ikind(internal_kind::uint64), repr(v) {}
  502. BHO_CXX14_CONSTEXPR impl_t(string_view v) noexcept : ikind(internal_kind::string), repr{v} {}
  503. BHO_CXX14_CONSTEXPR impl_t(blob_view v) noexcept : ikind(internal_kind::blob), repr{v} {}
  504. BHO_CXX14_CONSTEXPR impl_t(float v) noexcept : ikind(internal_kind::float_), repr(v) {}
  505. BHO_CXX14_CONSTEXPR impl_t(double v) noexcept : ikind(internal_kind::double_), repr(v) {}
  506. BHO_CXX14_CONSTEXPR impl_t(date v) noexcept : ikind(internal_kind::date), repr(v) {}
  507. BHO_CXX14_CONSTEXPR impl_t(datetime v) noexcept : ikind(internal_kind::datetime), repr(v) {}
  508. BHO_CXX14_CONSTEXPR impl_t(time v) noexcept : ikind(internal_kind::time), repr(v) {}
  509. BHO_CXX14_CONSTEXPR impl_t(detail::string_view_offset v, bool is_blob) noexcept
  510. : ikind(is_blob ? internal_kind::sv_offset_blob : internal_kind::sv_offset_string), repr{v}
  511. {
  512. }
  513. BHO_CXX14_CONSTEXPR impl_t(const detail::field_impl* v) noexcept
  514. : ikind(internal_kind::field_ptr), repr(v)
  515. {
  516. }
  517. } impl_;
  518. BHO_CXX14_CONSTEXPR bool is_field_ptr() const noexcept
  519. {
  520. return impl_.ikind == internal_kind::field_ptr;
  521. }
  522. BHO_CXX14_CONSTEXPR inline void check_kind(internal_kind expected) const;
  523. #ifndef BHO_MYSQL_DOXYGEN
  524. friend class field;
  525. friend struct detail::access;
  526. BHO_MYSQL_DECL
  527. friend std::ostream& operator<<(std::ostream& os, const field_view& v);
  528. #endif
  529. };
  530. /**
  531. * \relates field_view
  532. * \brief Streams a `field_view`.
  533. */
  534. BHO_MYSQL_DECL
  535. std::ostream& operator<<(std::ostream& os, const field_view& v);
  536. } // namespace mysql
  537. } // namespace bho
  538. #include <asio2/bho/mysql/impl/field_view.hpp>
  539. #ifdef BHO_MYSQL_HEADER_ONLY
  540. #include <asio2/bho/mysql/impl/field_view.ipp>
  541. #endif
  542. #endif