10#include <boost/lexical_cast.hpp>
26template <
typename T> std::string
toString(
const T &
value) {
return boost::lexical_cast<std::string>(
value); }
29template <
typename T> std::string
toString(
const std::shared_ptr<T> &) {
throw boost::bad_lexical_cast(); }
32template <
typename T> std::string
toString(
const std::vector<T> &
value,
const std::string &delimiter =
",") {
33 std::stringstream result;
34 std::size_t vsize =
value.size();
35 for (std::size_t i = 0; i < vsize; ++i) {
45std::string
toString(
const std::vector<std::vector<T>> &
value,
const std::string &outerDelimiter =
",",
46 const std::string &innerDelimiter =
"+") {
47 std::stringstream result;
48 std::size_t vsize =
value.size();
49 for (std::size_t i = 0; i < vsize; ++i) {
50 std::size_t innervsize =
value[i].size();
51 for (std::size_t j = 0; j < innervsize; ++j) {
52 result <<
value[i][j];
53 if (j + 1 != innervsize)
54 result << innerDelimiter;
58 result << outerDelimiter;
65template <
typename T> std::string
toPrettyString(
const T &
value,
size_t maxLength = 0,
bool collapseLists =
true) {
72std::string
toPrettyString(
const std::shared_ptr<T> &
value,
size_t maxLength = 0,
bool collapseLists =
true) {
76 throw boost::bad_lexical_cast();
85 const std::vector<T> &
value,
size_t maxLength = 0,
bool collapseLists =
true,
const std::string &delimiter =
",",
86 const std::string &unusedDelimiter =
"+",
87 typename std::enable_if<!(std::is_integral<T>::value && std::is_arithmetic<T>::value)>::type * =
nullptr) {
103 const std::string &delimiter =
",",
const std::string &listDelimiter =
"-",
104 typename std::enable_if<std::is_integral<T>::value && std::is_arithmetic<T>::value>::type * =
nullptr) {
122 const std::string &delimiter,
const std::string &unusedDelimiter,
123 typename std::enable_if<std::is_same<bool, bool>::value>::type *) {
131std::string
toPrettyString(
const std::vector<std::vector<T>> &
value,
size_t maxLength = 0,
bool collapseLists =
true,
132 const std::string &outerDelimiter =
",",
const std::string &innerDelimiter =
"+") {
139template <
typename T>
int findSize(
const T &) {
return 1; }
142template <
typename T>
int findSize(
const std::vector<T> &
value) {
return static_cast<int>(
value.size()); }
145template <
typename T>
inline void appendValue(
const std::string &strvalue, std::vector<T> &
value) {
147 std::size_t pos = strvalue.find(
':');
148 std::size_t numChar = std::string::npos;
150 bool dashSeparator =
false;
151 if (pos == std::string::npos) {
152 pos = strvalue.find(
'-', 1);
153 if (pos != std::string::npos)
154 dashSeparator =
true;
156 const auto posStep = strvalue.find(
':', pos + 1);
157 if (posStep != std::string::npos) {
158 step = boost::lexical_cast<T>(strvalue.substr(posStep + 1));
159 numChar = posStep - pos - 1;
164 if (pos == std::string::npos) {
165 value.emplace_back(boost::lexical_cast<T>(strvalue));
169 if (step ==
static_cast<T
>(0))
170 throw std::logic_error(
"Step size must be non-zero");
173 auto start = boost::lexical_cast<T>(strvalue.substr(0, pos));
174 auto stop = boost::lexical_cast<T>(strvalue.substr(pos + 1, numChar));
176 if ((start > stop) && (dashSeparator)) {
177 std::swap(start, stop);
181 if (start + step < start)
182 throw std::logic_error(
"Step size is negative with increasing limits");
183 for (
auto i = start; i <= stop;) {
184 value.emplace_back(i);
187 i =
static_cast<T
>(i + step);
190 if (start + step >= start)
191 throw std::logic_error(
"Step size is positive with decreasing limits");
192 for (
auto i = start; i >= stop;) {
193 value.emplace_back(i);
196 i =
static_cast<T
>(i + step);
201template <
typename T>
inline void toValue(
const std::string &strvalue, T &
value) {
202 value = boost::lexical_cast<T>(strvalue);
205template <
typename T>
inline void toValue(
const std::string &, std::shared_ptr<T> &) {
206 throw boost::bad_lexical_cast();
214template <
typename T>
void toValue(
const std::string &strvalue, std::vector<T> &
value, std::true_type) {
219 for (
const auto &token : values) {
224template <
typename T>
void toValue(
const std::string &strvalue, std::vector<T> &
value, std::false_type) {
231 std::transform(values.
cbegin(), values.
cend(), std::back_inserter(
value),
232 [](
const std::string &str) { return boost::lexical_cast<T>(str); });
245template <>
struct is_range_type<unsigned long long> :
public std::true_type {};
252template <
typename T>
void toValue(
const std::string &strvalue, std::vector<T> &
value) {
257void toValue(
const std::string &strvalue, std::vector<std::vector<T>> &
value,
const std::string &outerDelimiter =
",",
258 const std::string &innerDelimiter =
"+") {
265 for (
const auto &token : tokens) {
268 vect.reserve(values.
count());
269 std::transform(values.
begin(), values.
end(), std::back_inserter(vect),
270 [](
const std::string &str) { return boost::lexical_cast<T>(str); });
271 value.emplace_back(std::move(vect));
293 lhs =
static_cast<T
>(lhs +
rhs);
296template <
typename T>
inline void addingOperator(std::vector<T> &lhs,
const std::vector<T> &
rhs) {
299 lhs.insert(lhs.end(),
rhs.begin(),
rhs.end());
301 std::vector<T> rhs_copy(
rhs);
302 lhs.insert(lhs.end(), rhs_copy.begin(), rhs_copy.end());
314template <
typename T>
inline void addingOperator(std::shared_ptr<T> &,
const std::shared_ptr<T> &) {
324 std::vector<std::string> values;
325 values.reserve(enumMap.size());
326 std::transform(enumMap.cbegin(), enumMap.cend(), std::back_inserter(values),
327 [](
const std::pair<OptionalBool::Value, std::string> &str) { return str.second; });
const std::vector< double > & rhs
double value
The value of the point.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Marks code as not implemented yet.
IValidator is the basic interface for all validators for properties.
virtual std::vector< std::string > allowedValues() const
The set of allowed values that this validator may have, if a discrete set exists.
OptionalBool : Tri-state bool.
static std::map< Value, std::string > enumToStrMap()
Iterator begin()
Iterator referring to first element in the container.
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
ConstIterator cend() const
Const iterator referring to the past-the-end element in the container.
ConstIterator cbegin() const
Const iterator referring to first element in the container.
std::size_t count() const
Get the total number of tokens.
DLLExport std::string joinCompress(ITERATOR_TYPE begin, ITERATOR_TYPE end, const std::string &separator=",", const std::string &listSeparator="-")
Join a set or vector of (something that turns into a string) together into one string,...
MANTID_KERNEL_DLL std::string shorten(const std::string &input, const size_t max_length)
Converts long strings into "start ... end".
DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, const std::string &separator, typename std::enable_if<!(std::is_same< typename std::iterator_traits< ITERATOR_TYPE >::iterator_category, std::random_access_iterator_tag >::value)>::type *=nullptr)
Join a set or vector of (something that turns into a string) together into one string,...
void toValue(const std::string &strvalue, std::vector< T > &value, std::true_type)
T extractToValueVector(const std::string &strvalue)
void toValue(const std::string &strvalue, T &value)
void appendValue(const std::string &strvalue, std::vector< T > &value)
std::string toString(const T &value)
Convert values to strings.
std::vector< std::string > determineAllowedValues(const T &, const IValidator &validator)
void addingOperator(T &lhs, const T &rhs)
int findSize(const T &)
Specialization for any type, should be appropriate for properties with a single value.
std::string toPrettyString(const T &value, size_t maxLength=0, bool collapseLists=true)
Convert values to pretty strings.
Helper class which provides the Collimation Length for SANS instruments.