qupled 1.3.3__cp313-cp313-macosx_13_0_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qupled/.dylibs/libSQLiteCpp.0.dylib +0 -0
- qupled/.dylibs/libgsl.28.dylib +0 -0
- qupled/.dylibs/libgslcblas.0.dylib +0 -0
- qupled/.dylibs/libomp.dylib +0 -0
- qupled/.dylibs/libsqlite3.3.50.1.dylib +0 -0
- qupled/__init__.py +1 -0
- qupled/database.py +640 -0
- qupled/esa.py +27 -0
- qupled/hf.py +263 -0
- qupled/include/fmt/args.h +235 -0
- qupled/include/fmt/chrono.h +2240 -0
- qupled/include/fmt/color.h +643 -0
- qupled/include/fmt/compile.h +535 -0
- qupled/include/fmt/core.h +2969 -0
- qupled/include/fmt/format-inl.h +1678 -0
- qupled/include/fmt/format.h +4535 -0
- qupled/include/fmt/os.h +455 -0
- qupled/include/fmt/ostream.h +245 -0
- qupled/include/fmt/printf.h +675 -0
- qupled/include/fmt/ranges.h +738 -0
- qupled/include/fmt/std.h +537 -0
- qupled/include/fmt/xchar.h +259 -0
- qupled/lib/cmake/fmt/fmt-config-version.cmake +43 -0
- qupled/lib/cmake/fmt/fmt-config.cmake +31 -0
- qupled/lib/cmake/fmt/fmt-targets-release.cmake +19 -0
- qupled/lib/cmake/fmt/fmt-targets.cmake +116 -0
- qupled/lib/libfmt.a +0 -0
- qupled/lib/pkgconfig/fmt.pc +11 -0
- qupled/mpi.py +69 -0
- qupled/native.cpython-313-darwin.so +0 -0
- qupled/output.py +92 -0
- qupled/qstls.py +68 -0
- qupled/qstlsiet.py +37 -0
- qupled/qvsstls.py +59 -0
- qupled/rpa.py +27 -0
- qupled/stls.py +94 -0
- qupled/stlsiet.py +97 -0
- qupled/vsstls.py +203 -0
- qupled-1.3.3.dist-info/METADATA +81 -0
- qupled-1.3.3.dist-info/RECORD +43 -0
- qupled-1.3.3.dist-info/WHEEL +6 -0
- qupled-1.3.3.dist-info/licenses/LICENSE +674 -0
- qupled-1.3.3.dist-info/top_level.txt +1 -0
qupled/hf.py
ADDED
@@ -0,0 +1,263 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import numpy as np
|
4
|
+
|
5
|
+
from . import database
|
6
|
+
from . import mpi
|
7
|
+
from . import native
|
8
|
+
|
9
|
+
|
10
|
+
class HF:
|
11
|
+
"""
|
12
|
+
Class used to solve the HF scheme.
|
13
|
+
"""
|
14
|
+
|
15
|
+
def __init__(self):
|
16
|
+
self.inputs: Input = None
|
17
|
+
"""The inputs used to solve the scheme. Default = ``None``"""
|
18
|
+
self.results: Result = Result()
|
19
|
+
"""The results obtained by solving the scheme"""
|
20
|
+
# Undocumented properties
|
21
|
+
self.db_handler = database.DataBaseHandler()
|
22
|
+
self.native_scheme_cls = native.HF
|
23
|
+
self.native_inputs_cls = native.Input
|
24
|
+
self.native_scheme_status = None
|
25
|
+
|
26
|
+
@property
|
27
|
+
def run_id(self):
|
28
|
+
"""
|
29
|
+
Property that retrieves the run ID from the database handler.
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
str: The run ID associated with the current database handler.
|
33
|
+
"""
|
34
|
+
return self.db_handler.run_id
|
35
|
+
|
36
|
+
@mpi.MPI.record_time
|
37
|
+
@mpi.MPI.synchronize_ranks
|
38
|
+
def compute(self, inputs: Input):
|
39
|
+
"""
|
40
|
+
Solves the scheme and saves the results.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
inputs: Input parameters.
|
44
|
+
"""
|
45
|
+
self.inputs = inputs
|
46
|
+
self._add_run_to_database()
|
47
|
+
self._compute_native()
|
48
|
+
self._save()
|
49
|
+
|
50
|
+
@mpi.MPI.run_only_on_root
|
51
|
+
def compute_rdf(self, rdf_grid: np.ndarray = None):
|
52
|
+
"""
|
53
|
+
Computes the radial distribution function (RDF) using the provided RDF grid.
|
54
|
+
If results are available, this method computes the RDF and stores the results
|
55
|
+
in the database.
|
56
|
+
|
57
|
+
Args:
|
58
|
+
rdf_grid: A numpy array representing the RDF grid.
|
59
|
+
If not provided, a default grid will be used.
|
60
|
+
"""
|
61
|
+
if self.results is not None:
|
62
|
+
self.results.compute_rdf(rdf_grid)
|
63
|
+
self.db_handler.insert_results(
|
64
|
+
{"rdf": self.results.rdf, "rdf_grid": self.results.rdf_grid}
|
65
|
+
)
|
66
|
+
|
67
|
+
def _add_run_to_database(self):
|
68
|
+
"""
|
69
|
+
Adds the current run information to the database.
|
70
|
+
|
71
|
+
This method inserts the run details stored in `self.inputs` into the database
|
72
|
+
using the `db_handler`. It also updates the `database_info` attribute of
|
73
|
+
`self.inputs` with the current `run_id`.
|
74
|
+
"""
|
75
|
+
self.db_handler.insert_run(self.inputs)
|
76
|
+
self.inputs.database_info.run_id = self.run_id
|
77
|
+
|
78
|
+
def _compute_native(self):
|
79
|
+
"""
|
80
|
+
Computes the native representation of the inputs and processes the results.
|
81
|
+
|
82
|
+
This method performs the following steps:
|
83
|
+
1. Converts the current inputs to their native representation.
|
84
|
+
2. Initializes a native scheme object using the native inputs.
|
85
|
+
3. Computes the native scheme and stores its status.
|
86
|
+
4. Converts the results from the native scheme back to the desired format.
|
87
|
+
"""
|
88
|
+
native_inputs = self.native_inputs_cls()
|
89
|
+
self.inputs.to_native(native_inputs)
|
90
|
+
scheme = self.native_scheme_cls(native_inputs)
|
91
|
+
self.native_scheme_status = scheme.compute()
|
92
|
+
self.results.from_native(scheme)
|
93
|
+
|
94
|
+
@mpi.MPI.run_only_on_root
|
95
|
+
def _save(self):
|
96
|
+
"""
|
97
|
+
Saves the current state and results to the database.
|
98
|
+
|
99
|
+
This method updates the run status in the database using the current
|
100
|
+
native scheme status and inserts the results into the database.
|
101
|
+
"""
|
102
|
+
self.db_handler.update_run_status(self.native_scheme_status)
|
103
|
+
self.db_handler.insert_results(self.results.__dict__)
|
104
|
+
|
105
|
+
|
106
|
+
class Input:
|
107
|
+
"""
|
108
|
+
Class used to store the inputs for the :obj:`qupled.hf.HF` class.
|
109
|
+
"""
|
110
|
+
|
111
|
+
def __init__(self, coupling: float, degeneracy: float):
|
112
|
+
"""
|
113
|
+
Initialize the base class with the given parameters.
|
114
|
+
|
115
|
+
Parameters:
|
116
|
+
coupling (float): Coupling parameter.
|
117
|
+
degeneracy (float): Degeneracy parameter.
|
118
|
+
"""
|
119
|
+
self.chemical_potential: list[float] = [-10.0, 10.0]
|
120
|
+
"""Initial guess for the chemical potential. Default = ``[-10, 10]``"""
|
121
|
+
self.coupling: float = coupling
|
122
|
+
"""Coupling parameter."""
|
123
|
+
self.cutoff: float = 10.0
|
124
|
+
"""Cutoff for the wave-vector grid. Default = ``10.0``"""
|
125
|
+
self.degeneracy: float = degeneracy
|
126
|
+
"""Degeneracy parameter."""
|
127
|
+
self.frequency_cutoff: float = 10.0
|
128
|
+
"""Cutoff for the frequency (applies only in the ground state). Default = ``10.0``"""
|
129
|
+
self.integral_error: float = 1.0e-5
|
130
|
+
"""Accuracy (relative error) in the computation of integrals. Default = ``1.0e-5``"""
|
131
|
+
self.integral_strategy: str = "full"
|
132
|
+
"""
|
133
|
+
Scheme used to solve two-dimensional integrals
|
134
|
+
allowed options include:
|
135
|
+
|
136
|
+
- full: the inner integral is evaluated at arbitrary points selected automatically by the quadrature rule
|
137
|
+
|
138
|
+
- segregated: the inner integral is evaluated on a fixed grid that depends on the integrand that is being processed
|
139
|
+
|
140
|
+
Segregated is usually faster than full but it could become
|
141
|
+
less accurate if the fixed points are not chosen correctly. Default = ``'full'``
|
142
|
+
"""
|
143
|
+
self.matsubara: int = 128
|
144
|
+
"""Number of Matsubara frequencies. Default = ``128``"""
|
145
|
+
self.resolution: float = 0.1
|
146
|
+
"""Resolution of the wave-vector grid. Default = ``0.1``"""
|
147
|
+
self.threads: int = 1
|
148
|
+
"""Number of OMP threads for parallel calculations. Default = ``1``"""
|
149
|
+
# Undocumented default values
|
150
|
+
self.theory: str = "HF"
|
151
|
+
self.database_info: DatabaseInfo = DatabaseInfo()
|
152
|
+
|
153
|
+
def to_native(self, native_input: any):
|
154
|
+
"""
|
155
|
+
Converts the attributes of the current object to their native representations
|
156
|
+
and sets them on the provided `native_input` object.
|
157
|
+
|
158
|
+
This method iterates through the attributes of the current object and checks
|
159
|
+
if the `native_input` object has a corresponding attribute. If it does, the
|
160
|
+
method attempts to convert the attribute's value to its native representation
|
161
|
+
using a `to_native` method, if available. Otherwise, it directly assigns the
|
162
|
+
attribute's value to the `native_input` object.
|
163
|
+
|
164
|
+
Args:
|
165
|
+
native_input (any): The object to which the native representations of the
|
166
|
+
current object's attributes will be assigned.
|
167
|
+
"""
|
168
|
+
name = Input.to_native.__name__
|
169
|
+
for attr, value in self.__dict__.items():
|
170
|
+
if hasattr(native_input, attr) and value is not None:
|
171
|
+
value_to_set = (
|
172
|
+
tonative()
|
173
|
+
if callable(tonative := getattr(value, name, None))
|
174
|
+
else value
|
175
|
+
)
|
176
|
+
setattr(native_input, attr, value_to_set)
|
177
|
+
|
178
|
+
|
179
|
+
class Result:
|
180
|
+
"""
|
181
|
+
Class used to store the results for the :obj:`qupled.hf.HF` class.
|
182
|
+
"""
|
183
|
+
|
184
|
+
def __init__(self):
|
185
|
+
self.idr: np.ndarray = None
|
186
|
+
"""Ideal density response"""
|
187
|
+
self.lfc: np.ndarray = None
|
188
|
+
"""Local field correction"""
|
189
|
+
self.rdf: np.ndarray = None
|
190
|
+
"""Radial distribution function"""
|
191
|
+
self.rdf_grid: np.ndarray = None
|
192
|
+
"""Radial distribution function grid"""
|
193
|
+
self.sdr: np.ndarray = None
|
194
|
+
"""Static density response"""
|
195
|
+
self.ssf: np.ndarray = None
|
196
|
+
"""Static structure factor"""
|
197
|
+
self.uint: float = None
|
198
|
+
"""Internal energy"""
|
199
|
+
self.wvg: np.ndarray = None
|
200
|
+
"""Wave-vector grid"""
|
201
|
+
|
202
|
+
def from_native(self, native_scheme: any):
|
203
|
+
"""
|
204
|
+
Updates the attributes of the current object based on the attributes of a given native scheme object.
|
205
|
+
|
206
|
+
Args:
|
207
|
+
native_scheme (any): An object containing attributes to update the current object with.
|
208
|
+
|
209
|
+
Notes:
|
210
|
+
- Only attributes that exist in both the current object and the native_scheme object will be updated.
|
211
|
+
- Attributes with a value of `None` in the native_scheme object will not overwrite the current object's attributes.
|
212
|
+
"""
|
213
|
+
for attr in self.__dict__.keys():
|
214
|
+
if hasattr(native_scheme, attr):
|
215
|
+
value = getattr(native_scheme, attr)
|
216
|
+
setattr(self, attr, value) if value is not None else None
|
217
|
+
|
218
|
+
def compute_rdf(self, rdf_grid: np.ndarray | None = None):
|
219
|
+
"""
|
220
|
+
Compute the radial distribution function (RDF) for the system.
|
221
|
+
|
222
|
+
Args:
|
223
|
+
rdf_grid (np.ndarray | None, optional): A 1D array specifying the grid points
|
224
|
+
at which the RDF is computed. If None, a default grid ranging from 0.0
|
225
|
+
to 10.0 with a step size of 0.01 is used.
|
226
|
+
|
227
|
+
Returns:
|
228
|
+
None: The computed RDF is stored in the `self.rdf` attribute.
|
229
|
+
"""
|
230
|
+
if self.wvg is not None and self.ssf is not None:
|
231
|
+
self.rdf_grid = (
|
232
|
+
rdf_grid if rdf_grid is not None else np.arange(0.0, 10.0, 0.01)
|
233
|
+
)
|
234
|
+
self.rdf = native.compute_rdf(self.rdf_grid, self.wvg, self.ssf)
|
235
|
+
|
236
|
+
|
237
|
+
class DatabaseInfo:
|
238
|
+
"""
|
239
|
+
Class used to store the database information passed to the native code.
|
240
|
+
"""
|
241
|
+
|
242
|
+
def __init__(self):
|
243
|
+
self.name: str = database.DataBaseHandler.DEFAULT_DATABASE_NAME
|
244
|
+
"""Database name"""
|
245
|
+
self.run_id: int = None
|
246
|
+
"""ID of the run in the database"""
|
247
|
+
self.run_table_name: str = database.DataBaseHandler.RUN_TABLE_NAME
|
248
|
+
"""Name of the table used to store the runs in the database"""
|
249
|
+
|
250
|
+
def to_native(self) -> native.DatabaseInfo:
|
251
|
+
"""
|
252
|
+
Converts the current object to a native `DatabaseInfo` instance.
|
253
|
+
This method creates a new instance of `native.DatabaseInfo` and copies
|
254
|
+
all non-None attributes from the current object to the new instance.
|
255
|
+
Returns:
|
256
|
+
native.DatabaseInfo: A new instance of `native.DatabaseInfo` with
|
257
|
+
attributes copied from the current object.
|
258
|
+
"""
|
259
|
+
native_database_info = native.DatabaseInfo()
|
260
|
+
for attr, value in self.__dict__.items():
|
261
|
+
if value is not None:
|
262
|
+
setattr(native_database_info, attr, value)
|
263
|
+
return native_database_info
|
@@ -0,0 +1,235 @@
|
|
1
|
+
// Formatting library for C++ - dynamic argument lists
|
2
|
+
//
|
3
|
+
// Copyright (c) 2012 - present, Victor Zverovich
|
4
|
+
// All rights reserved.
|
5
|
+
//
|
6
|
+
// For the license information refer to format.h.
|
7
|
+
|
8
|
+
#ifndef FMT_ARGS_H_
|
9
|
+
#define FMT_ARGS_H_
|
10
|
+
|
11
|
+
#include <functional> // std::reference_wrapper
|
12
|
+
#include <memory> // std::unique_ptr
|
13
|
+
#include <vector>
|
14
|
+
|
15
|
+
#include "core.h"
|
16
|
+
|
17
|
+
FMT_BEGIN_NAMESPACE
|
18
|
+
|
19
|
+
namespace detail {
|
20
|
+
|
21
|
+
template <typename T> struct is_reference_wrapper : std::false_type {};
|
22
|
+
template <typename T>
|
23
|
+
struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};
|
24
|
+
|
25
|
+
template <typename T> auto unwrap(const T& v) -> const T& { return v; }
|
26
|
+
template <typename T>
|
27
|
+
auto unwrap(const std::reference_wrapper<T>& v) -> const T& {
|
28
|
+
return static_cast<const T&>(v);
|
29
|
+
}
|
30
|
+
|
31
|
+
class dynamic_arg_list {
|
32
|
+
// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
|
33
|
+
// templates it doesn't complain about inability to deduce single translation
|
34
|
+
// unit for placing vtable. So storage_node_base is made a fake template.
|
35
|
+
template <typename = void> struct node {
|
36
|
+
virtual ~node() = default;
|
37
|
+
std::unique_ptr<node<>> next;
|
38
|
+
};
|
39
|
+
|
40
|
+
template <typename T> struct typed_node : node<> {
|
41
|
+
T value;
|
42
|
+
|
43
|
+
template <typename Arg>
|
44
|
+
FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {}
|
45
|
+
|
46
|
+
template <typename Char>
|
47
|
+
FMT_CONSTEXPR typed_node(const basic_string_view<Char>& arg)
|
48
|
+
: value(arg.data(), arg.size()) {}
|
49
|
+
};
|
50
|
+
|
51
|
+
std::unique_ptr<node<>> head_;
|
52
|
+
|
53
|
+
public:
|
54
|
+
template <typename T, typename Arg> auto push(const Arg& arg) -> const T& {
|
55
|
+
auto new_node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
|
56
|
+
auto& value = new_node->value;
|
57
|
+
new_node->next = std::move(head_);
|
58
|
+
head_ = std::move(new_node);
|
59
|
+
return value;
|
60
|
+
}
|
61
|
+
};
|
62
|
+
} // namespace detail
|
63
|
+
|
64
|
+
/**
|
65
|
+
\rst
|
66
|
+
A dynamic version of `fmt::format_arg_store`.
|
67
|
+
It's equipped with a storage to potentially temporary objects which lifetimes
|
68
|
+
could be shorter than the format arguments object.
|
69
|
+
|
70
|
+
It can be implicitly converted into `~fmt::basic_format_args` for passing
|
71
|
+
into type-erased formatting functions such as `~fmt::vformat`.
|
72
|
+
\endrst
|
73
|
+
*/
|
74
|
+
template <typename Context>
|
75
|
+
class dynamic_format_arg_store
|
76
|
+
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
|
77
|
+
// Workaround a GCC template argument substitution bug.
|
78
|
+
: public basic_format_args<Context>
|
79
|
+
#endif
|
80
|
+
{
|
81
|
+
private:
|
82
|
+
using char_type = typename Context::char_type;
|
83
|
+
|
84
|
+
template <typename T> struct need_copy {
|
85
|
+
static constexpr detail::type mapped_type =
|
86
|
+
detail::mapped_type_constant<T, Context>::value;
|
87
|
+
|
88
|
+
enum {
|
89
|
+
value = !(detail::is_reference_wrapper<T>::value ||
|
90
|
+
std::is_same<T, basic_string_view<char_type>>::value ||
|
91
|
+
std::is_same<T, detail::std_string_view<char_type>>::value ||
|
92
|
+
(mapped_type != detail::type::cstring_type &&
|
93
|
+
mapped_type != detail::type::string_type &&
|
94
|
+
mapped_type != detail::type::custom_type))
|
95
|
+
};
|
96
|
+
};
|
97
|
+
|
98
|
+
template <typename T>
|
99
|
+
using stored_type = conditional_t<
|
100
|
+
std::is_convertible<T, std::basic_string<char_type>>::value &&
|
101
|
+
!detail::is_reference_wrapper<T>::value,
|
102
|
+
std::basic_string<char_type>, T>;
|
103
|
+
|
104
|
+
// Storage of basic_format_arg must be contiguous.
|
105
|
+
std::vector<basic_format_arg<Context>> data_;
|
106
|
+
std::vector<detail::named_arg_info<char_type>> named_info_;
|
107
|
+
|
108
|
+
// Storage of arguments not fitting into basic_format_arg must grow
|
109
|
+
// without relocation because items in data_ refer to it.
|
110
|
+
detail::dynamic_arg_list dynamic_args_;
|
111
|
+
|
112
|
+
friend class basic_format_args<Context>;
|
113
|
+
|
114
|
+
auto get_types() const -> unsigned long long {
|
115
|
+
return detail::is_unpacked_bit | data_.size() |
|
116
|
+
(named_info_.empty()
|
117
|
+
? 0ULL
|
118
|
+
: static_cast<unsigned long long>(detail::has_named_args_bit));
|
119
|
+
}
|
120
|
+
|
121
|
+
auto data() const -> const basic_format_arg<Context>* {
|
122
|
+
return named_info_.empty() ? data_.data() : data_.data() + 1;
|
123
|
+
}
|
124
|
+
|
125
|
+
template <typename T> void emplace_arg(const T& arg) {
|
126
|
+
data_.emplace_back(detail::make_arg<Context>(arg));
|
127
|
+
}
|
128
|
+
|
129
|
+
template <typename T>
|
130
|
+
void emplace_arg(const detail::named_arg<char_type, T>& arg) {
|
131
|
+
if (named_info_.empty()) {
|
132
|
+
constexpr const detail::named_arg_info<char_type>* zero_ptr{nullptr};
|
133
|
+
data_.insert(data_.begin(), {zero_ptr, 0});
|
134
|
+
}
|
135
|
+
data_.emplace_back(detail::make_arg<Context>(detail::unwrap(arg.value)));
|
136
|
+
auto pop_one = [](std::vector<basic_format_arg<Context>>* data) {
|
137
|
+
data->pop_back();
|
138
|
+
};
|
139
|
+
std::unique_ptr<std::vector<basic_format_arg<Context>>, decltype(pop_one)>
|
140
|
+
guard{&data_, pop_one};
|
141
|
+
named_info_.push_back({arg.name, static_cast<int>(data_.size() - 2u)});
|
142
|
+
data_[0].value_.named_args = {named_info_.data(), named_info_.size()};
|
143
|
+
guard.release();
|
144
|
+
}
|
145
|
+
|
146
|
+
public:
|
147
|
+
constexpr dynamic_format_arg_store() = default;
|
148
|
+
|
149
|
+
/**
|
150
|
+
\rst
|
151
|
+
Adds an argument into the dynamic store for later passing to a formatting
|
152
|
+
function.
|
153
|
+
|
154
|
+
Note that custom types and string types (but not string views) are copied
|
155
|
+
into the store dynamically allocating memory if necessary.
|
156
|
+
|
157
|
+
**Example**::
|
158
|
+
|
159
|
+
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
160
|
+
store.push_back(42);
|
161
|
+
store.push_back("abc");
|
162
|
+
store.push_back(1.5f);
|
163
|
+
std::string result = fmt::vformat("{} and {} and {}", store);
|
164
|
+
\endrst
|
165
|
+
*/
|
166
|
+
template <typename T> void push_back(const T& arg) {
|
167
|
+
if (detail::const_check(need_copy<T>::value))
|
168
|
+
emplace_arg(dynamic_args_.push<stored_type<T>>(arg));
|
169
|
+
else
|
170
|
+
emplace_arg(detail::unwrap(arg));
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
\rst
|
175
|
+
Adds a reference to the argument into the dynamic store for later passing to
|
176
|
+
a formatting function.
|
177
|
+
|
178
|
+
**Example**::
|
179
|
+
|
180
|
+
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
181
|
+
char band[] = "Rolling Stones";
|
182
|
+
store.push_back(std::cref(band));
|
183
|
+
band[9] = 'c'; // Changing str affects the output.
|
184
|
+
std::string result = fmt::vformat("{}", store);
|
185
|
+
// result == "Rolling Scones"
|
186
|
+
\endrst
|
187
|
+
*/
|
188
|
+
template <typename T> void push_back(std::reference_wrapper<T> arg) {
|
189
|
+
static_assert(
|
190
|
+
need_copy<T>::value,
|
191
|
+
"objects of built-in types and string views are always copied");
|
192
|
+
emplace_arg(arg.get());
|
193
|
+
}
|
194
|
+
|
195
|
+
/**
|
196
|
+
Adds named argument into the dynamic store for later passing to a formatting
|
197
|
+
function. ``std::reference_wrapper`` is supported to avoid copying of the
|
198
|
+
argument. The name is always copied into the store.
|
199
|
+
*/
|
200
|
+
template <typename T>
|
201
|
+
void push_back(const detail::named_arg<char_type, T>& arg) {
|
202
|
+
const char_type* arg_name =
|
203
|
+
dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
|
204
|
+
if (detail::const_check(need_copy<T>::value)) {
|
205
|
+
emplace_arg(
|
206
|
+
fmt::arg(arg_name, dynamic_args_.push<stored_type<T>>(arg.value)));
|
207
|
+
} else {
|
208
|
+
emplace_arg(fmt::arg(arg_name, arg.value));
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
/** Erase all elements from the store */
|
213
|
+
void clear() {
|
214
|
+
data_.clear();
|
215
|
+
named_info_.clear();
|
216
|
+
dynamic_args_ = detail::dynamic_arg_list();
|
217
|
+
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
\rst
|
221
|
+
Reserves space to store at least *new_cap* arguments including
|
222
|
+
*new_cap_named* named arguments.
|
223
|
+
\endrst
|
224
|
+
*/
|
225
|
+
void reserve(size_t new_cap, size_t new_cap_named) {
|
226
|
+
FMT_ASSERT(new_cap >= new_cap_named,
|
227
|
+
"Set of arguments includes set of named arguments");
|
228
|
+
data_.reserve(new_cap);
|
229
|
+
named_info_.reserve(new_cap_named);
|
230
|
+
}
|
231
|
+
};
|
232
|
+
|
233
|
+
FMT_END_NAMESPACE
|
234
|
+
|
235
|
+
#endif // FMT_ARGS_H_
|