7#ifndef ARCANE_SERVICE_OPTIONS_H
8#define ARCANE_SERVICE_OPTIONS_H
19namespace StrongOptions
21template <
typename T, std::
size_t N>
22std::ostream&
operator<<(std::ostream& o,
const std::array<T, N>& a)
30std::ostream&
operator<<(std::ostream& o,
const std::vector<T>& a)
39template <std::size_t... Is>
struct seq
41template <std::size_t N, std::size_t... Is>
44template <std::size_t... Is>
48template <
typename T, std::size_t N1, std::size_t... I1, std::size_t N2, std::size_t... I2>
53 return std::array<T, N1 + N2>{ { a1[I1] }..., { a2[I2] }... };
56template <
typename T, std::
size_t N1, std::
size_t N2>
59concat(
const std::array<T, N1>& a1,
const std::array<T, N2>& a2)
61 return concat(a1, a2, gen_seq<N1>{}, gen_seq<N2>{});
64template <
typename T, std::
size_t N1>
67concat(
const std::array<T, N1>& a1,
const T& x)
69 return concat(a1, std::array<T, 1>{ { x } }, gen_seq<N1>{}, gen_seq<1>{});
78 template <
typename T,
int N,
typename... Args>
79 static std::array<typename T::type, N>
80 requiredFixedArray(Args&&... args)
85 template <
typename T,
int N,
int CurN,
typename... Args>
89 template <
typename T,
int N,
int CurN,
typename Head,
typename... Tail>
92 static std::array<typename T::type, N>
93 requiredFixedArray(
const std::array<typename T::type, CurN>& r, Head&&, Tail&&... args)
99 template <
typename T,
int N,
int CurN,
typename... Tail>
102 static std::array<typename T::type, N>
103 requiredFixedArray(
const std::array<typename T::type, CurN>& r, T&& t, Tail&&... args)
109 template <
typename T,
int N,
int CurN>
112 static std::array<typename T::type, N>
113 requiredFixedArray(
const std::array<typename T::type, CurN>& r)
115 static_assert(CurN == N,
"Invalid required parameter count");
164 template <
typename T,
int Nmin,
int Nmax,
typename... Args>
166 requiredVariableArray(Args&&... args)
171 template <
typename T,
int Nmin,
int Nmax,
int CurN,
typename... Args>
175 template <
typename T,
int Nmin,
int Nmax,
int CurN,
typename Head,
typename... Tail>
186 template <
typename T,
int Nmin,
int Nmax,
int CurN,
typename... Tail>
197 template <
typename T,
int Nmin,
int Nmax,
int CurN>
203 static_assert(CurN >= Nmin && (Nmax == -1 || CurN <= Nmax),
"Invalid required parameter count");
209 template <
typename T,
typename... Args>
211 optionalSimple(
typename T::type& r, Args&&... args)
216 template <
typename T,
int CurN,
typename... Args>
220 template <
typename T,
int CurN,
typename Head,
typename... Tail>
224 optionalSimple(
typename T::type& r, Head&&, Tail&&... args)
230 template <
typename T,
int CurN,
typename... Tail>
234 optionalSimple(
typename T::type& r, T&& t, Tail&&... args)
241 template <
typename T,
int CurN>
245 optionalSimple([[maybe_unused]]
typename T::type& r)
247 static_assert(CurN <= 1,
"Invalid required parameter count");
253 template <
typename AllowedTypes,
typename... Args>
255 checkRestriction(
const Args&... args)
260 template <
typename AllowedTypes,
typename... Args>
264 template <
typename... AllowedTypes,
typename Head,
typename... Tail>
265 struct Internal4<std::tuple<AllowedTypes...>, Head, Tail...>
268 checkRestriction([[maybe_unused]]
const Head& h,
const Tail&... tail)
270 static_assert(
Internal44<Head, AllowedTypes...>::checkType,
"Illegal option");
271 return Internal4<std::tuple<AllowedTypes...>, Tail...>::checkRestriction(tail...);
275 template <
typename... AllowedTypes>
285 template <
typename Arg,
typename... AllowedTypes>
289 template <
typename Arg,
typename Head,
typename... Tail>
295 template <
typename Arg,
typename Head>
298 static const bool checkType = std::is_same<Arg, Head>::value;
301 template <
typename Arg>
304 static const bool checkType =
false;
310template <
typename Name,
typename Type>
321template <
typename Name,
typename Type>
334#define DECLARE_OPTION_EXTERN(name, type) \
339 typedef OptionValue<tag::name##_t, type> name##_; \
340 ARCANE_CORE_EXPORT extern OptionProxy<tag::name##_t, type> _##name;
342#define DECLARE_OPTION(name, type) \
347 typedef OptionValue<tag::name##_t, type> name##_; \
348 OptionProxy<tag::name##_t, type> _##name;
352#if !defined(ARCANE_JOIN_HELPER2)
353#define ARCANE_JOIN_HELPER2(a, b) a##b
356#if !defined(ARCANE_JOIN_HELPER)
357#define ARCANE_JOIN_HELPER(a, b) ARCANE_JOIN_HELPER2(a, b)
360#if !defined(ARCANE_JOIN_WITH_LINE)
361#define ARCANE_JOIN_WITH_LINE(a) ARCANE_JOIN_HELPER(a, __LINE__)
367template <
typename Interface>
372 static std::unique_ptr<Interface>
373 create(
const std::string& name)
375 const std::map<std::string, ctor_functor>& ctor_functors = instance()->m_ctor_functors;
376 auto finder = ctor_functors.find(name);
379 return std::unique_ptr<Interface>(finder->second());
384 typedef std::function<Interface*()> ctor_functor;
387 registerImplementation(
const std::string& name,
const ctor_functor& ctor)
389 instance()->m_ctor_functors[name] = ctor;
394 static std::unique_ptr<InstanceBuilder> m_instance;
400 return m_instance.get();
405 std::map<std::string, ctor_functor> m_ctor_functors;
411template <
typename Interface,
typename Class,
typename SrongOptionClass>
417 return new Class(std::move(std::unique_ptr<SrongOptionClass>(
new SrongOptionClass{})));
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Vecteur 1D de données avec sémantique par valeur (style STL).
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Opérateur de sortie sur un flot.