30 #ifndef INCLUDED_MiniArgsHandling_h_GUID_51E5C000_C9EC_438C_FF9C_2FE43886985C 31 #define INCLUDED_MiniArgsHandling_h_GUID_51E5C000_C9EC_438C_FF9C_2FE43886985C 37 #if defined(OSVR_HAVE_BOOST) || defined(BOOST_VERSION) 38 #include <boost/algorithm/string/predicate.hpp> 44 #include <initializer_list> 53 using ArgList = std::vector<std::string>;
57 return std::vector<std::string>(argv + 1, argv + argc);
61 template <
typename F>
inline std::size_t
handle_arg(ArgList &c, F &&f) {
62 auto origSize = c.size();
63 auto origEnd = end(c);
64 auto newEnd =
std::remove_if(begin(c), end(c), std::forward<F>(f));
65 if (newEnd != origEnd) {
66 std::size_t newSize = std::distance(begin(c), newEnd);
68 return origSize - newSize;
75 static bool apply(
T &&a, std::string
const &b) {
76 return (std::forward<T>(a) == b);
79 #ifdef OSVR_HAVE_BOOST 80 struct CaseInsensitiveComparisonPolicy {
82 static bool apply(
T &&a, std::string
const &b) {
83 return boost::iequals(b, std::forward<T>(a));
86 #endif // OSVR_HAVE_BOOST 88 template <
typename ComparisonPolicy,
typename SequenceType>
89 inline bool generic_handle_has_switch(ArgList &c,
90 SequenceType &&argSwitch) {
91 return 0 <
handle_arg(c, [&argSwitch](std::string
const &arg) {
97 #ifdef OSVR_HAVE_BOOST 98 template <
typename SequenceType>
105 inline bool handle_has_iswitch(ArgList &c, SequenceType &&argSwitch) {
106 return detail::generic_handle_has_switch<
107 detail::CaseInsensitiveComparisonPolicy>(
108 c, std::forward<SequenceType>(argSwitch));
110 #endif // OSVR_HAVE_BOOST 118 template <
typename SequenceType>
120 return detail::generic_handle_has_switch<
122 c, std::forward<SequenceType>(argSwitch));
129 template <
typename F,
typename G>
137 auto origEnd = end(c);
138 auto origSize = c.size();
139 std::vector<bool> isCandidate(origSize,
false);
142 [&](std::string
const &arg) {
143 return std::forward<F>(predicate)(arg);
146 ArgList remainingArgs;
147 auto beforeEnd = end(c);
150 std::size_t count = 0;
153 bool lastAccepted =
false;
154 for (
auto it = begin(c), e = end(c); it != beforeEnd && it != e;
156 if (std::forward<F>(predicate)(*it)) {
160 std::forward<G>(action)(*it);
164 remainingArgs.emplace_back(std::move(*it));
165 lastAccepted =
false;
173 remainingArgs.emplace_back(std::move(c.back()));
177 c.swap(remainingArgs);
182 template <
typename ComparisonPolicy,
typename SequenceType>
183 inline bool generic_handle_has_any_switch_of(
185 std::initializer_list<SequenceType>
const &argSwitches) {
187 handle_arg(c, [&argSwitches](std::string
const &arg) {
188 for (
const auto &sw : argSwitches) {
203 template <
typename SequenceType>
206 std::initializer_list<SequenceType>
const &argSwitches) {
207 return detail::generic_handle_has_any_switch_of<
211 #ifdef OSVR_HAVE_BOOST 212 template <
typename SequenceType>
221 inline bool handle_has_any_iswitch_of(
222 ArgList &c, std::initializer_list<SequenceType> argSwitches) {
223 return detail::generic_handle_has_any_switch_of<
224 detail::CaseInsensitiveComparisonPolicy>(c, argSwitches);
226 #endif // OSVR_HAVE_BOOST 230 #endif // INCLUDED_MiniArgsHandling_h_GUID_51E5C000_C9EC_438C_FF9C_2FE43886985C Definition: RunLoopManager.h:42
std::size_t handle_arg(ArgList &c, F &&f)
Takes a predicate to find arguments.
Definition: MiniArgsHandling.h:61
ArgList makeArgList(int argc, char *argv[])
Constructs a vector containing the arguments excluding argv[0].
Definition: MiniArgsHandling.h:56
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
typename F::template apply< Args... > apply
Apply an alias class.
Definition: Apply.h:44
Definition: newuoa.h:1888
t_< detail::transform_< List, Fun >> transform
Given a list and an alias class, apply the alias class to each element in the list and return the res...
Definition: Transform.h:54
bool handle_has_switch(ArgList &c, SequenceType &&argSwitch)
Takes a "sequence" (something with operator== with std::string) to compare (case-sensitive) with ever...
Definition: MiniArgsHandling.h:119
Definition: MiniArgsHandling.h:73
bool handle_has_any_switch_of(ArgList &c, std::initializer_list< SequenceType > const &argSwitches)
Takes a list of "sequences" (something with operator== with std::string) to compare (case-sensitive) ...
Definition: MiniArgsHandling.h:204
std::size_t handle_value_arg(ArgList &c, F &&predicate, G &&action)
Takes a predicate to find arguments.
Definition: MiniArgsHandling.h:130
void remove_if(GeneralizedTransform &transform, UnaryPredicate pred)
Remove levels from a generalized transform as dictated by an arbitrary predicate. ...
Definition: GeneralizedTransform.h:111