Lightweight 0.20250904.0
Loading...
Searching...
No Matches
StdString.hpp
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "../SqlColumnTypeDefinitions.hpp"
6#include "Core.hpp"
7#include "UnicodeConverter.hpp"
8
9#include <concepts>
10#include <cstdlib>
11#include <string>
12#include <type_traits>
13
14namespace Lightweight
15{
16
17// Specialized traits for std::basic_string<> as output string parameter
18template <typename CharT>
19struct SqlBasicStringOperations<std::basic_string<CharT>>
20{
21 using CharType = CharT;
22 using StringType = std::basic_string<CharT>;
23
24 static constexpr auto ColumnType = SqlColumnTypeDefinitions::Varchar { 255 };
25
26 static LIGHTWEIGHT_FORCE_INLINE CharType const* Data(StringType const* str) noexcept
27 {
28 return str->data();
29 }
30
31 static LIGHTWEIGHT_FORCE_INLINE CharType* Data(StringType* str) noexcept
32 {
33 return str->data();
34 }
35
36 static LIGHTWEIGHT_FORCE_INLINE SQLULEN Size(StringType const* str) noexcept
37 {
38 return str->size();
39 }
40
41 static LIGHTWEIGHT_FORCE_INLINE void Clear(StringType* str) noexcept
42 {
43 str->clear();
44 }
45
46 static LIGHTWEIGHT_FORCE_INLINE void Reserve(StringType* str, size_t capacity) noexcept
47 {
48 // std::basic_string<> tries to defer the allocation as long as possible.
49 // So we first tell StringType how much to reserve and then resize it to the *actually* reserved
50 // size.
51 str->reserve(capacity);
52 str->resize(str->capacity());
53 }
54
55 static LIGHTWEIGHT_FORCE_INLINE void Resize(StringType* str, SQLLEN indicator) noexcept
56 {
57 if (indicator > 0)
58 str->resize(indicator);
59 }
60};
61
62} // namespace Lightweight