20 #ifndef STAR_TOKEN_HPP
21 #define STAR_TOKEN_HPP
27 #include <boost/lexical_cast.hpp>
31 std::string& countString,
32 std::string& valueString);
37 return boost::lexical_cast<T>(valueString);
39 catch (boost::bad_lexical_cast&) {
40 throw std::invalid_argument(
"Unable to convert string '" + valueString +
"' to typeid: " +
typeid(T).name());
47 return boost::lexical_cast<
double>(valueString);
49 catch (boost::bad_lexical_cast&) {
55 std::string vs(valueString);
56 std::replace(vs.begin(), vs.end(),
'D',
'E');
57 std::replace(vs.begin(), vs.end(),
'd',
'e');
59 try {
return boost::lexical_cast<
double>(vs); }
60 catch (boost::bad_lexical_cast&) {
61 throw std::invalid_argument(
"Unable to convert string '" + valueString +
"' to double");
72 inline std::string readValueToken<std::string>(
const std::string& valueString) {
73 if (valueString.size() > 0 && valueString[0] ==
'\'') {
74 if (valueString.size() < 2 || valueString[valueString.size() - 1] !=
'\'')
75 throw std::invalid_argument(
"Unable to parse string '" + valueString +
"' as a string token");
76 return valueString.substr(1, valueString.size() - 2);
87 if (!
isStarToken(token, m_countString, m_valueString))
88 throw std::invalid_argument(
"Token \""+token+
"\" is not a repetition specifier");
92 StarToken(
const std::string& token,
const std::string& countStr,
const std::string& valueStr)
93 : m_countString(countStr)
94 , m_valueString(valueStr)
104 return !m_valueString.empty();
111 return m_countString;
120 return m_valueString;
126 void init_(
const std::string& token) {
129 if (m_countString ==
"") {
130 if (m_valueString !=
"")
132 throw std::invalid_argument(
"Not specifying a count also implies not specifying a value. Token: \'" + token +
"\'.");
139 m_count = boost::lexical_cast<
int>(m_countString);
143 throw std::invalid_argument(
"Specifing zero repetitions is not allowed. Token: \'" + token +
"\'.");
148 std::string m_countString;
149 std::string m_valueString;
const std::string & valueString() const
Definition: StarToken.hpp:119
StarToken(const std::string &token, const std::string &countStr, const std::string &valueStr)
Definition: StarToken.hpp:92
Definition: StarToken.hpp:83
size_t count() const
Definition: StarToken.hpp:99
T readValueToken(const std::string &valueString)
Definition: StarToken.hpp:35
bool isStarToken(const std::string &token, std::string &countString, std::string &valueString)
bool hasValue() const
Definition: StarToken.hpp:103
StarToken(const std::string &token)
Definition: StarToken.hpp:85
const std::string & countString() const
Definition: StarToken.hpp:110
float readValueToken< float >(const std::string &valueString)
Definition: StarToken.hpp:67
double readValueToken< double >(const std::string &valueString)
Definition: StarToken.hpp:45