Agora  1.2.0
Agora project
args.h
Go to the documentation of this file.
1 // Formatting library for C++ - dynamic format arguments
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 
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> const T& unwrap(const T& v) { return v; }
26 template <typename T> const T& unwrap(const std::reference_wrapper<T>& v) {
27  return static_cast<const T&>(v);
28 }
29 
31  // Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
32  // templates it doesn't complain about inability to deduce single translation
33  // unit for placing vtable. So storage_node_base is made a fake template.
34  template <typename = void> struct node {
35  virtual ~node() = default;
36  std::unique_ptr<node<>> next;
37  };
38 
39  template <typename T> struct typed_node : node<> {
41 
42  template <typename Arg>
43  FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {}
44 
45  template <typename Char>
47  : value(arg.data(), arg.size()) {}
48  };
49 
50  std::unique_ptr<node<>> head_;
51 
52  public:
53  template <typename T, typename Arg> const T& push(const Arg& arg) {
54  auto new_node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
55  auto& value = new_node->value;
56  new_node->next = std::move(head_);
57  head_ = std::move(new_node);
58  return value;
59  }
60 };
61 } // namespace detail
62 
73 template <typename Context>
76  // Workaround a GCC template argument substitution bug.
78 #endif
79 {
80  private:
81  using char_type = typename Context::char_type;
82 
83  template <typename T> struct need_copy {
84  static constexpr detail::type mapped_type =
86 
87  enum {
89  std::is_same<T, basic_string_view<char_type>>::value ||
90  std::is_same<T, detail::std_string_view<char_type>>::value ||
91  (mapped_type != detail::type::cstring_type &&
92  mapped_type != detail::type::string_type &&
93  mapped_type != detail::type::custom_type))
94  };
95  };
96 
97  template <typename T>
98  using stored_type = conditional_t<detail::is_string<T>::value &&
101  std::basic_string<char_type>, T>;
102 
103  // Storage of basic_format_arg must be contiguous.
104  std::vector<basic_format_arg<Context>> data_;
105  std::vector<detail::named_arg_info<char_type>> named_info_;
106 
107  // Storage of arguments not fitting into basic_format_arg must grow
108  // without relocation because items in data_ refer to it.
110 
111  friend class basic_format_args<Context>;
112 
113  unsigned long long get_types() const {
114  return detail::is_unpacked_bit | data_.size() |
115  (named_info_.empty()
116  ? 0ULL
117  : static_cast<unsigned long long>(detail::has_named_args_bit));
118  }
119 
121  return named_info_.empty() ? data_.data() : data_.data() + 1;
122  }
123 
124  template <typename T> void emplace_arg(const T& arg) {
125  data_.emplace_back(detail::make_arg<Context>(arg));
126  }
127 
128  template <typename T>
130  if (named_info_.empty()) {
131  constexpr const detail::named_arg_info<char_type>* zero_ptr{nullptr};
132  data_.insert(data_.begin(), {zero_ptr, 0});
133  }
134  data_.emplace_back(detail::make_arg<Context>(detail::unwrap(arg.value)));
135  auto pop_one = [](std::vector<basic_format_arg<Context>>* data) {
136  data->pop_back();
137  };
138  std::unique_ptr<std::vector<basic_format_arg<Context>>, decltype(pop_one)>
139  guard{&data_, pop_one};
140  named_info_.push_back({arg.name, static_cast<int>(data_.size() - 2u)});
141  data_[0].value_.named_args = {named_info_.data(), named_info_.size()};
142  guard.release();
143  }
144 
145  public:
146  constexpr dynamic_format_arg_store() = default;
147 
165  template <typename T> void push_back(const T& arg) {
167  emplace_arg(dynamic_args_.push<stored_type<T>>(arg));
168  else
169  emplace_arg(detail::unwrap(arg));
170  }
171 
187  template <typename T> void push_back(std::reference_wrapper<T> arg) {
188  static_assert(
190  "objects of built-in types and string views are always copied");
191  emplace_arg(arg.get());
192  }
193 
199  template <typename T>
201  const char_type* arg_name =
202  dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
204  emplace_arg(
205  fmt::arg(arg_name, dynamic_args_.push<stored_type<T>>(arg.value)));
206  } else {
207  emplace_arg(fmt::arg(arg_name, arg.value));
208  }
209  }
210 
212  void clear() {
213  data_.clear();
214  named_info_.clear();
215  dynamic_args_ = detail::dynamic_arg_list();
216  }
217 
224  void reserve(size_t new_cap, size_t new_cap_named) {
225  FMT_ASSERT(new_cap >= new_cap_named,
226  "Set of arguments includes set of named arguments");
227  data_.reserve(new_cap);
228  named_info_.reserve(new_cap_named);
229  }
230 };
231 
233 
234 #endif // FMT_ARGS_H_
fmt::v8::dynamic_format_arg_store::dynamic_args_
detail::dynamic_arg_list dynamic_args_
Definition: args.h:109
fmt::v8::dynamic_format_arg_store::char_type
typename Context::char_type char_type
Definition: args.h:81
fmt::v8::detail::dynamic_arg_list
Definition: args.h:30
size
end IFFT Reshape the symbol vector into two different spatial streams size
Definition: generate_data.m:73
fmt::v8::detail::type_constant
Definition: core.h:1156
fmt::v8::basic_format_args
Definition: core.h:702
fmt::v8::basic_format_arg
Definition: core.h:701
Catch::Generators::value
GeneratorWrapper< T > value(T &&value)
Definition: catch.hpp:3999
fmt::v8::basic_string_view
Definition: core.h:448
FMT_GCC_VERSION
#define FMT_GCC_VERSION
Definition: core.h:32
fmt::v8::dynamic_format_arg_store::push_back
void push_back(std::reference_wrapper< T > arg)
Definition: args.h:187
fmt::v8::detail::named_arg_info< char_type >
detail
Definition: fmt.cpp:13
fmt::v8::detail::value
Definition: core.h:1208
fmt::v8::dynamic_format_arg_store::get_types
unsigned long long get_types() const
Definition: args.h:113
fmt::v8::dynamic_format_arg_store::push_back
void push_back(const detail::named_arg< char_type, T > &arg)
Definition: args.h:200
fmt::v8::detail::is_unpacked_bit
@ is_unpacked_bit
Definition: core.h:1499
T
T
Definition: simulate_performance.m:4
fmt::v8::dynamic_format_arg_store::data
const basic_format_arg< Context > * data() const
Definition: args.h:120
fmt::v8::detail::named_arg
Definition: core.h:1051
fmt::v8::dynamic_format_arg_store::clear
void clear()
Definition: args.h:212
fmt::v8::detail::dynamic_arg_list::push
const T & push(const Arg &arg)
Definition: args.h:53
data_
uint8_t data_[]
Definition: radio_socket.cc:21
fmt::v8::detail::dynamic_arg_list::typed_node::typed_node
typed_node(const Arg &arg)
Definition: args.h:43
FMT_END_NAMESPACE
#define FMT_END_NAMESPACE
Definition: core.h:240
fmt::v8::dynamic_format_arg_store
Definition: args.h:74
u
Plot Rx waveform for u
Definition: inspect_single_frame.m:108
fmt::v8::detail::const_check
constexpr auto const_check(T value) -> T
Definition: core.h:365
fmt::v8::dynamic_format_arg_store::push_back
void push_back(const T &arg)
Definition: args.h:165
fmt::v8::has_formatter
std::is_constructible< typename Context::template formatter_type< T > > has_formatter
Definition: core.h:716
fmt::v8::dynamic_format_arg_store::need_copy
Definition: args.h:83
fmt::v8::arg
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1887
fmt::v8::detail::dynamic_arg_list::typed_node
Definition: args.h:39
fmt::v8::dynamic_format_arg_store::emplace_arg
void emplace_arg(const detail::named_arg< char_type, T > &arg)
Definition: args.h:129
extract_version.data
dictionary data
Definition: extract_version.py:8
fmt::v8::detail::dynamic_arg_list::typed_node::value
T value
Definition: args.h:40
if
Add CP Insert the cyclic prefix if(CP_LEN > 0) tx_cp
fmt::v8::detail::unwrap
const T & unwrap(const std::reference_wrapper< T > &v)
Definition: args.h:26
FMT_ASSERT
#define FMT_ASSERT(condition, message)
Definition: core.h:378
fmt::v8::detail::has_named_args_bit
@ has_named_args_bit
Definition: core.h:1500
fmt::v8::conditional_t
typename std::conditional< B, T, F >::type conditional_t
Definition: core.h:323
std
Definition: json.hpp:5213
fmt::v8::detail::dynamic_arg_list::node
Definition: args.h:34
fmt::v8::dynamic_format_arg_store::emplace_arg
void emplace_arg(const T &arg)
Definition: args.h:124
core.h
fmt::v8::detail::dynamic_arg_list::typed_node::typed_node
typed_node(const basic_string_view< Char > &arg)
Definition: args.h:46
FMT_BEGIN_NAMESPACE
#define FMT_BEGIN_NAMESPACE
Definition: core.h:237
fmt::v8::detail::is_reference_wrapper
Definition: args.h:21
fmt::v8::detail::value::value
constexpr value()
Definition: core.h:1231
fmt::v8::dynamic_format_arg_store::named_info_
std::vector< detail::named_arg_info< char_type > > named_info_
Definition: args.h:105
fmt::v8::dynamic_format_arg_store::data_
std::vector< basic_format_arg< Context > > data_
Definition: args.h:104
fmt::v8::detail::dynamic_arg_list::node::next
std::unique_ptr< node<> > next
Definition: args.h:36
fmt::v8::dynamic_format_arg_store::reserve
void reserve(size_t new_cap, size_t new_cap_named)
Definition: args.h:224
FMT_CONSTEXPR
#define FMT_CONSTEXPR
Definition: core.h:110
fmt::v8::detail::type
type
Definition: core.h:1131
fmt::v8::dynamic_format_arg_store::stored_type
conditional_t< detail::is_string< T >::value &&!has_formatter< T, Context >::value &&!detail::is_reference_wrapper< T >::value, std::basic_string< char_type >, T > stored_type
Definition: args.h:101
fmt::v8::detail::dynamic_arg_list::head_
std::unique_ptr< node<> > head_
Definition: args.h:50