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>;
56 inline ArgList makeArgList(
int argc,
char *argv[]) {
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;
73 struct StringEqualityComparisonPolicy {
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>
119 inline bool handle_has_switch(ArgList &c, SequenceType &&argSwitch) {
120 return detail::generic_handle_has_switch<
121 detail::StringEqualityComparisonPolicy>(
122 c, std::forward<SequenceType>(argSwitch));
129 template <
typename F,
typename G>
130 inline std::size_t handle_value_arg(ArgList &c, F &&predicate,
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>
204 inline bool handle_has_any_switch_of(
206 std::initializer_list<SequenceType>
const &argSwitches) {
207 return detail::generic_handle_has_any_switch_of<
208 detail::StringEqualityComparisonPolicy>(c, argSwitches);
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
The main namespace for all C++ elements of the framework, internal and external.
typename F::template apply< Args...> apply
Apply an alias class.
t_< detail::transform_< List, Fun >> transform