38 #include <boost/core/ignore_unused.hpp>
39 #include <boost/lexical_cast.hpp>
40 #include <boost/spirit/include/qi_auto.hpp>
41 #include <boost/spirit/include/qi_core.hpp>
44 namespace qi = boost::spirit::qi;
45 namespace fusion = boost::fusion;
76 static_assert(std::is_integral<T>::value,
"Integer type required.");
77 for (T i = fusion::at_c<0>(num); i <= fusion::at_c<1>(num); ++i)
106 std::vector<unsigned int> &out)
110 auto it = str.begin();
111 bool success = qi::phrase_parse(
113 ((qi::uint_ >>
'-' >> qi::uint_)[f2] | qi::uint_[f1]) %
',',
116 return success && it == str.end();
130 template <
typename T>
133 auto it = str.begin();
135 qi::phrase_parse(it, str.end(), qi::auto_ %
',', qi::ascii::space, out);
136 return success && it == str.end();
140 const std::string &str, std::vector<int> &out);
142 const std::string &str, std::vector<long> &out);
144 const std::string &str, std::vector<unsigned int> &out);
146 const std::string &str, std::vector<double> &out);
148 const std::string &str, std::vector<float> &out);
158 const std::string &str, std::vector<std::string> &out)
160 auto it = str.begin();
161 bool success = qi::phrase_parse(it, str.end(), +~qi::char_(
",") %
',',
162 qi::ascii::space, out);
163 return success && it == str.end();
167 const std::vector<std::string> &variables,
171 std::vector<std::string> vars;
173 "Failed to interpret variable numbers or names from " + str);
174 for (std::string s : vars)
179 v = boost::lexical_cast<int>(s);
181 catch (
const boost::bad_lexical_cast &)
183 auto index =
find(variables.begin(), variables.end(), s);
184 v = index - variables.begin();
186 if (v < 0 || v >= variables.size())
188 WARNINGL0(
false,
"Warning: variable " + s +
" not found");
#define ASSERTL0(condition, msg)
#define WARNINGL0(condition, msg)
#define LIB_UTILITIES_EXPORT
static bool GenerateVariableSet(const std::string &str, const std::vector< std::string > &variables, std::set< int > &out)
Generate a set of variable locations.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
static bool GenerateSeqVector(const std::string &str, std::vector< unsigned int > &out)
Takes a comma-separated compressed string and converts it to entries in a vector.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
The above copyright notice and this permission notice shall be included.
Helper functors for holding a vector of numbers to be parsed by boost::spirit.
void operator()(T num) const
Pushes back values onto m_vec as given by num.
void operator()(fusion::vector< T, T > num) const
Pushes back values onto m_vec between the range supplied by num. Valid for only integer types.
std::vector< T > & m_vec
Storage vector that will hold parsed variables from boost::spirit.
PushBackFunctor(std::vector< T > &in)