Mantid
Loading...
Searching...
No Matches
PropertyHistory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
14
15#include <algorithm>
16#include <boost/lexical_cast.hpp>
17#include <cstdint>
18#include <ostream>
19#include <utility>
20
21namespace Mantid::Kernel {
22
24PropertyHistory::PropertyHistory(std::string name, std::string value, std::string type, const bool isdefault,
25 const unsigned int direction)
26 : m_name(std::move(name)), m_value(std::move(value)), m_type(std::move(type)), m_isDefault(isdefault),
27 m_direction(direction) {}
28
30 : m_name(prop->name()), m_value(prop->valueAsPrettyStr(0, true)), m_type(prop->type()),
31 m_isDefault(prop->isDefault()), m_direction(prop->direction()) {}
32
40void PropertyHistory::printSelf(std::ostream &os, const int indent, const size_t maxPropertyLength) const {
41 os << std::string(indent, ' ') << "Name: " << m_name;
42 if ((maxPropertyLength > 0) && (m_value.size() > maxPropertyLength)) {
43 os << ", Value: " << Strings::shorten(m_value, maxPropertyLength);
44 } else {
45 os << ", Value: " << m_value;
46 }
47 os << ", Default?: " << (m_isDefault ? "Yes" : "No");
48 os << ", Direction: " << Kernel::Direction::asText(m_direction) << '\n';
49}
50
56std::ostream &operator<<(std::ostream &os, const PropertyHistory &AP) {
57 AP.printSelf(os);
58 return os;
59}
60
65 bool emptyDefault = false;
66
67 // Static lists to be initialised on first call
68 static std::vector<std::string> numberTypes, emptyValues;
69 // Type strings corresponding to numbers
70 if (numberTypes.empty()) {
71 numberTypes.emplace_back(getUnmangledTypeName(typeid(int)));
72 numberTypes.emplace_back(getUnmangledTypeName(typeid(int64_t)));
73 numberTypes.emplace_back(getUnmangledTypeName(typeid(double)));
74 }
75 // Empty values
76 if (emptyValues.empty()) {
77 emptyValues.emplace_back(std::to_string(EMPTY_INT()));
78 emptyValues.emplace_back(boost::lexical_cast<std::string>(EMPTY_DBL()));
79 emptyValues.emplace_back(std::to_string(EMPTY_LONG()));
80 }
81
82 // If default, input, number type and matches empty value then return true
84 if (std::find(numberTypes.begin(), numberTypes.end(), m_type) != numberTypes.end()) {
85 if (std::find(emptyValues.begin(), emptyValues.end(), m_value) != emptyValues.end()) {
86 emptyDefault = true;
87 }
88 }
89 }
90 return emptyDefault;
91}
92
93} // namespace Mantid::Kernel
const std::string & m_value
Definition: Algorithm.cpp:71
double value
The value of the point.
Definition: FitMW.cpp:51
This class stores information about the parameters used by an algorithm.
bool m_isDefault
flag defining if the parameter is a default or a user-defined parameter
std::string m_name
The name of the parameter.
std::string m_value
The value of the parameter.
PropertyHistory(std::string name, std::string value, std::string type, const bool isdefault, const unsigned int direction=99)
Constructor.
bool isEmptyDefault() const
get whether algorithm parameter was left as default EMPTY_INT,LONG,DBL const
void printSelf(std::ostream &, const int indent=0, const size_t maxPropertyLength=0) const
print contents of object
std::string m_type
The type of the parameter.
unsigned int m_direction
direction of parameter
Base class for properties.
Definition: Property.h:94
MANTID_KERNEL_DLL std::string shorten(const std::string &input, const size_t max_length)
Converts long strings into "start ... end".
Definition: Strings.cpp:54
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
Definition: CPUTimer.cpp:86
MANTID_KERNEL_DLL std::string getUnmangledTypeName(const std::type_info &type)
Return the name corresponding to the mangled string given by typeid.
Definition: Property.cpp:300
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition: EmptyValues.h:25
constexpr long EMPTY_LONG() noexcept
Returns what we consider an "empty" long within a property.
Definition: EmptyValues.h:31
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Output
An output workspace.
Definition: Property.h:54
static const std::string asText(const unsigned int &direction)
Returns a text representation of the input Direction enum.
Definition: Property.h:60