diff --git a/Framework/API/inc/MantidAPI/AlgorithmHistory.h b/Framework/API/inc/MantidAPI/AlgorithmHistory.h index 1466bbad3d0576c33012df4f117ffcb0d6053b64..7b9208a96c82cabad1c6fcd702a4b77a567ed5c9 100644 --- a/Framework/API/inc/MantidAPI/AlgorithmHistory.h +++ b/Framework/API/inc/MantidAPI/AlgorithmHistory.h @@ -121,7 +121,8 @@ public: /// Retrieve the number of child algorithms size_t childHistorySize() const; /// print contents of object - void printSelf(std::ostream &, const int indent = 0, const size_t maxPropertyLength = 0) const; + void printSelf(std::ostream &, const int indent = 0, + const size_t maxPropertyLength = 0) const; /// Less than operator inline bool operator<(const AlgorithmHistory &other) const { return (execCount() < other.execCount()); diff --git a/Framework/API/src/Algorithm.cpp b/Framework/API/src/Algorithm.cpp index 2341774faeae35e0d2faa128af12e46c071c23db..5218fa7cf41176fb8c32b782b6cccda62104fb5a 100644 --- a/Framework/API/src/Algorithm.cpp +++ b/Framework/API/src/Algorithm.cpp @@ -1061,9 +1061,8 @@ void Algorithm::logAlgorithmInfo() const { // here AlgorithmHistory algHistory(this); size_t maxPropertyLength = 40; - if (logger.is(Logger::Priority::PRIO_DEBUG)) - { - //include the full property value when logging in debug + if (logger.is(Logger::Priority::PRIO_DEBUG)) { + // include the full property value when logging in debug maxPropertyLength = 0; } algHistory.printSelf(logger.information(), 0, maxPropertyLength); diff --git a/Framework/API/src/AlgorithmHistory.cpp b/Framework/API/src/AlgorithmHistory.cpp index 1d4d56d51a50931c164510959a9b38f8a8a0d11b..bb8d206656d2401a2562bbd81296eaca847a4124 100644 --- a/Framework/API/src/AlgorithmHistory.cpp +++ b/Framework/API/src/AlgorithmHistory.cpp @@ -204,10 +204,11 @@ AlgorithmHistory::getChildAlgorithm(const size_t index) const { * @param os :: The output stream to write to * @param indent :: an indentation value to make pretty printing of object and * sub-objects - * @param maxPropertyLength :: the max length for any property value string (0 = full length) + * @param maxPropertyLength :: the max length for any property value string (0 + * = full length) */ void AlgorithmHistory::printSelf(std::ostream &os, const int indent, - const size_t maxPropertyLength) const { + const size_t maxPropertyLength) const { os << std::string(indent, ' ') << "Algorithm: " << m_name; os << std::string(indent, ' ') << " v" << m_version << '\n'; diff --git a/Framework/Kernel/inc/MantidKernel/Property.h b/Framework/Kernel/inc/MantidKernel/Property.h index f6c1eaef2c4e157105fc811a4e16479a9d128d56..6633c660cc55555ae1df5988ee38fe11a78d4c4d 100644 --- a/Framework/Kernel/inc/MantidKernel/Property.h +++ b/Framework/Kernel/inc/MantidKernel/Property.h @@ -140,10 +140,10 @@ public: "', property type not implemented."); } /// Returns the value of the property as a string - virtual std::string value() const = 0; + virtual std::string value() const = 0; /// Returns the value of the property as a pretty printed string virtual std::string valuePrettyPrint(size_t maxLength = 0, - bool collapseLists = true) const; + bool collapseLists = true) const; /// Set the value of the property via a string. If the value is unacceptable /// the value is not changed but a string is returned virtual std::string setValue(const std::string &) = 0; diff --git a/Framework/Kernel/inc/MantidKernel/PropertyHelper.h b/Framework/Kernel/inc/MantidKernel/PropertyHelper.h index 5fb3fb4e24101ea29301863012d99b5ff6f6bde1..96f803f754a98e035a1dd36f574ae0298cfc1cd8 100644 --- a/Framework/Kernel/inc/MantidKernel/PropertyHelper.h +++ b/Framework/Kernel/inc/MantidKernel/PropertyHelper.h @@ -31,7 +31,7 @@ template <typename T> std::string toString(const boost::shared_ptr<T> &value) { /// Specialization for a property of type std::vector. template <typename T> std::string toString(const std::vector<T> &value, - const std::string &delimiter = ",") { + const std::string &delimiter = ",") { std::stringstream result; std::size_t vsize = value.size(); for (std::size_t i = 0; i < vsize; ++i) { @@ -45,8 +45,8 @@ std::string toString(const std::vector<T> &value, /// Specialization for a property of type std::vector<std::vector>. template <typename T> std::string toString(const std::vector<std::vector<T>> &value, - const std::string &outerDelimiter = ",", - const std::string &innerDelimiter = "+") { + const std::string &outerDelimiter = ",", + const std::string &innerDelimiter = "+") { std::stringstream result; std::size_t vsize = value.size(); for (std::size_t i = 0; i < vsize; ++i) { @@ -65,14 +65,16 @@ std::string toString(const std::vector<std::vector<T>> &value, // --------------------- convert values to pretty strings /// Convert values to pretty strings. -template <typename T> std::string toPrettyString(const T &value, size_t maxLength = 0, - bool collapseLists = true) { +template <typename T> +std::string toPrettyString(const T &value, size_t maxLength = 0, + bool collapseLists = true) { return boost::lexical_cast<std::string>(value); } /// Throw an exception if a shared pointer is converted to a pretty string. -template <typename T> std::string toPrettyString(const boost::shared_ptr<T> &value, size_t maxLength = 0, - bool collapseLists = true) { +template <typename T> +std::string toPrettyString(const boost::shared_ptr<T> &value, + size_t maxLength = 0, bool collapseLists = true) { UNUSED_ARG(value); throw boost::bad_lexical_cast(); } @@ -82,12 +84,12 @@ template <typename T> std::string toPrettyString(const boost::shared_ptr<T> &val * This simply concatenates the values using a delimiter */ template <typename T> -std::string -toPrettyString(const std::vector<T> &value, size_t maxLength = 0, - bool collapseLists = true, const std::string &delimiter = ",", - const std::string &unusedDelimiter = "+", - typename std::enable_if<!(std::is_integral<T>::value && - std::is_arithmetic<T>::value)>::type * = 0) { +std::string toPrettyString( + const std::vector<T> &value, size_t maxLength = 0, + bool collapseLists = true, const std::string &delimiter = ",", + const std::string &unusedDelimiter = "+", + typename std::enable_if<!(std::is_integral<T>::value && + std::is_arithmetic<T>::value)>::type * = 0) { UNUSED_ARG(unusedDelimiter); return Strings::join(value.begin(), value.end(), delimiter); } @@ -100,12 +102,12 @@ toPrettyString(const std::vector<T> &value, size_t maxLength = 0, * will be compressed into a list syntax e.g. 1-5. */ template <typename T> -std::string -toPrettyString(const std::vector<T> &value, size_t maxLength = 0, - bool collapseLists = true, const std::string &delimiter = ",", - const std::string &listDelimiter = "-", - typename std::enable_if<std::is_integral<T>::value && - std::is_arithmetic<T>::value>::type * = 0) { +std::string toPrettyString( + const std::vector<T> &value, size_t maxLength = 0, + bool collapseLists = true, const std::string &delimiter = ",", + const std::string &listDelimiter = "-", + typename std::enable_if<std::is_integral<T>::value && + std::is_arithmetic<T>::value>::type * = 0) { return Strings::joinCompress(value.begin(), value.end(), delimiter, listDelimiter); } @@ -115,22 +117,20 @@ toPrettyString(const std::vector<T> &value, size_t maxLength = 0, * This simply concatenates the values using a delimiter */ template <> -std::string -toPrettyString(const std::vector<bool> &value, size_t maxLength, - bool collapseLists, const std::string &delimiter, - const std::string &unusedDelimiter, - typename std::enable_if<std::is_same<bool, bool>::value>::type *) { +std::string toPrettyString( + const std::vector<bool> &value, size_t maxLength, bool collapseLists, + const std::string &delimiter, const std::string &unusedDelimiter, + typename std::enable_if<std::is_same<bool, bool>::value>::type *) { UNUSED_ARG(unusedDelimiter); return Strings::join(value.begin(), value.end(), delimiter); } /// Specialization for a property of type std::vector<std::vector>. template <typename T> -std::string toPrettyString(const std::vector<std::vector<T>> &value, - size_t maxLength = 0, - bool collapseLists = true, - const std::string &outerDelimiter = ",", - const std::string &innerDelimiter = "+") { +std::string toPrettyString(const std::vector<std::vector<T>> &value, + size_t maxLength = 0, bool collapseLists = true, + const std::string &outerDelimiter = ",", + const std::string &innerDelimiter = "+") { return toString<T>(value, outerDelimiter, innerDelimiter); } diff --git a/Framework/Kernel/inc/MantidKernel/PropertyHistory.h b/Framework/Kernel/inc/MantidKernel/PropertyHistory.h index 4f300cce3ac962e315119679642b1c621fd41081..c45a142bc2bb018b1487c52a81a7c59a76b267a1 100644 --- a/Framework/Kernel/inc/MantidKernel/PropertyHistory.h +++ b/Framework/Kernel/inc/MantidKernel/PropertyHistory.h @@ -70,7 +70,8 @@ public: /// get direction flag of algorithm parameter const unsigned int direction() const { return m_direction; }; /// print contents of object - void printSelf(std::ostream &, const int indent = 0, const size_t maxPropertyLength = 0) const; + void printSelf(std::ostream &, const int indent = 0, + const size_t maxPropertyLength = 0) const; /// get whether algorithm parameter was left as default EMPTY_INT,LONG,DBL /// const bool isEmptyDefault() const; diff --git a/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h b/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h index d6f8684c2dd61ac307caa48a910c7531b6acb19c..2a07ad4bf88433aebd86f654bebb1a37460750a5 100644 --- a/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h +++ b/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h @@ -67,7 +67,7 @@ public: void saveProperty(::NeXus::File *file) override; std::string value() const override; std::string valuePrettyPrint(size_t maxLength = 0, - bool collapseLists = true) const; + bool collapseLists = true) const; virtual bool operator==(const PropertyWithValue<TYPE> &rhs) const; virtual bool operator!=(const PropertyWithValue<TYPE> &rhs) const; int size() const override; diff --git a/Framework/Kernel/inc/MantidKernel/Strings.h b/Framework/Kernel/inc/MantidKernel/Strings.h index 4cc570346d64899f84b1b417916b36a5428e3c09..85f82450ec6566b48e9658747e5093257fddbf21 100644 --- a/Framework/Kernel/inc/MantidKernel/Strings.h +++ b/Framework/Kernel/inc/MantidKernel/Strings.h @@ -131,7 +131,7 @@ DLLExport std::string joinCompress(ITERATOR_TYPE begin, ITERATOR_TYPE end, } /// Return a string with all matching occurence-strings MANTID_KERNEL_DLL std::string shortenList(const std::string &input, - const size_t &max_length); + const size_t &max_length); /// Return a string with all matching occurence-strings MANTID_KERNEL_DLL std::string replace(const std::string &input, diff --git a/Framework/Kernel/src/Property.cpp b/Framework/Kernel/src/Property.cpp index bdd8b90383518bb81012eaf44997824a5a51b9bb..d655d1dfab4f4ed51856dd98152187f7ae6d4074 100644 --- a/Framework/Kernel/src/Property.cpp +++ b/Framework/Kernel/src/Property.cpp @@ -119,9 +119,9 @@ void Property::setRemember(bool remember) { m_remember = remember; } * @param collapseLists :: Whether to collapse 1,2,3 into 1-3 */ std::string Property::valuePrettyPrint(size_t maxLength, - bool collapseLists) const { + bool collapseLists) const { UNUSED_ARG(collapseLists); - return Strings::shortenList(value(),maxLength); + return Strings::shortenList(value(), maxLength); } /** Sets the user level description of the property. diff --git a/Framework/Kernel/src/PropertyHistory.cpp b/Framework/Kernel/src/PropertyHistory.cpp index 916eca6810f30f88139d1f97202d6c18f2a982d0..69a5a7b965ab7b57ea22601ef3c0510eb659ea1d 100644 --- a/Framework/Kernel/src/PropertyHistory.cpp +++ b/Framework/Kernel/src/PropertyHistory.cpp @@ -23,18 +23,19 @@ PropertyHistory::PropertyHistory(const std::string &name, m_direction(direction) {} PropertyHistory::PropertyHistory(Property const *const prop) - : m_name(prop->name()), - m_value(prop->valuePrettyPrint(0,true)), m_type(prop->type()), - m_isDefault(prop->isDefault()), m_direction(prop->direction()) {} + : m_name(prop->name()), m_value(prop->valuePrettyPrint(0, true)), + m_type(prop->type()), m_isDefault(prop->isDefault()), + m_direction(prop->direction()) {} /** Prints a text representation of itself * @param os :: The output stream to write to * @param indent :: an indentation value to make pretty printing of object and * sub-objects - * @param maxPropertyLength :: the max length for any property value string (0 = full length) + * @param maxPropertyLength :: the max length for any property value string (0 + * = full length) */ void PropertyHistory::printSelf(std::ostream &os, const int indent, - const size_t maxPropertyLength) const { + const size_t maxPropertyLength) const { os << std::string(indent, ' ') << "Name: " << m_name; if ((maxPropertyLength > 0) && (m_value.size() > maxPropertyLength)) { os << ", Value: " << Strings::shortenList(m_value, maxPropertyLength); diff --git a/Framework/Kernel/src/Strings.cpp b/Framework/Kernel/src/Strings.cpp index d304bea38620bcb98811b31a833d70ac42e0fa73..7ba90bdd142d7f014743fe5a2918a15ec53e7093 100644 --- a/Framework/Kernel/src/Strings.cpp +++ b/Framework/Kernel/src/Strings.cpp @@ -39,26 +39,27 @@ std::string loadFile(const std::string &filename) { // ------------------------------------------------------------------------------------------------ /** Return a string shortened with the center replace by " ... " -* If the string is already short enough then the original string will be returned. -* If the max length or input string length is smaller than the ellipsis, the input will be returned. +* If the string is already short enough then the original string will be +*returned. +* If the max length or input string length is smaller than the ellipsis, the +*input will be returned. * * @param input :: input string -* @param max_length :: The maximum length of the return string (0 = return full string) +* @param max_length :: The maximum length of the return string (0 = return full +*string) * @return the modified string. */ -std::string shortenList(const std::string & input, const size_t & max_length) { +std::string shortenList(const std::string &input, const size_t &max_length) { const std::string ellipsis = " ... "; const size_t ellipsisSize = ellipsis.size(); // limit too small or input too small, return input string - if ((max_length == 0) || - (input.size() < ellipsisSize+2) || + if ((max_length == 0) || (input.size() < ellipsisSize + 2) || (input.size() <= max_length)) return input; const size_t end_length = (max_length - ellipsisSize) / 2; - std::string retVal = input.substr(0, end_length) + - ellipsis + - input.substr(input.size() - end_length, end_length); + std::string retVal = input.substr(0, end_length) + ellipsis + + input.substr(input.size() - end_length, end_length); return retVal; } diff --git a/Framework/Kernel/test/ArrayPropertyTest.h b/Framework/Kernel/test/ArrayPropertyTest.h index 4914ee2905896176640203813f8742f3829fe6fd..2faef00ec6846d8c35cba621b12334caf5c7b60d 100644 --- a/Framework/Kernel/test/ArrayPropertyTest.h +++ b/Framework/Kernel/test/ArrayPropertyTest.h @@ -353,7 +353,7 @@ public: bool success = true; for (size_t i = 0; i < inputList.size(); i++) { ArrayProperty<T> listProperty("i", inputList[i]); - std::string response = listProperty.valuePrettyPrint(0,true); + std::string response = listProperty.valuePrettyPrint(0, true); TS_ASSERT_EQUALS(response, resultList[i]); if (response != resultList[i]) { success = false; diff --git a/Framework/Kernel/test/PropertyHistoryTest.h b/Framework/Kernel/test/PropertyHistoryTest.h index 519c592fd4cf42f674663401eb2e9d6073bba2c1..1270f80abee86dcb66da7664134944bde04c30eb 100644 --- a/Framework/Kernel/test/PropertyHistoryTest.h +++ b/Framework/Kernel/test/PropertyHistoryTest.h @@ -35,11 +35,12 @@ public: correctOutput = correctOutput + "Direction: Input\n"; // a long property that should get shortened - PropertyHistory propHistory("arg1_param", "123456798012345678901234567890", "argument", true, Direction::Input); + PropertyHistory propHistory("arg1_param", "123456798012345678901234567890", + "argument", true, Direction::Input); // dump output to sting std::ostringstream output; - TS_ASSERT_THROWS_NOTHING(propHistory.printSelf(output,0,20)); + TS_ASSERT_THROWS_NOTHING(propHistory.printSelf(output, 0, 20)); TS_ASSERT_EQUALS(output.str(), correctOutput); } diff --git a/Framework/Kernel/test/StringsTest.h b/Framework/Kernel/test/StringsTest.h index 4e42b24cab88b0b85f01b3a16e98bd540be391b1..abe206f08782ff292911bec6848f343652dfcd1d 100644 --- a/Framework/Kernel/test/StringsTest.h +++ b/Framework/Kernel/test/StringsTest.h @@ -288,63 +288,51 @@ public: void test_shortenList() { std::vector<std::string> inputList{ - "", // empty - "1,2", // shorter than the ellipsis - "1,2,3", // equal in length than the ellipsis - "1,2,35", // one longer than the ellipsis - "1,2,3,4", // two longer than the ellipsis - "1,2,3,45", // just long enough for the ellipsis - "12,3,4,56", // another past the ellipsis - "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20" }; + "", // empty + "1,2", // shorter than the ellipsis + "1,2,3", // equal in length than the ellipsis + "1,2,35", // one longer than the ellipsis + "1,2,3,4", // two longer than the ellipsis + "1,2,3,45", // just long enough for the ellipsis + "12,3,4,56", // another past the ellipsis + "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"}; std::vector<std::string> resultListMaxLength7{ - "", // empty - "1,2", // shorter than the ellipsis - "1,2,3", // equal in length than the ellipsis - "1,2,35", // one longer than the ellipsis - "1,2,3,4", // two longer than the ellipsis - "1 ... 5", // just long enough for the ellipsis - "1 ... 6", // another past the ellipsis - "1 ... 0" }; + "", // empty + "1,2", // shorter than the ellipsis + "1,2,3", // equal in length than the ellipsis + "1,2,35", // one longer than the ellipsis + "1,2,3,4", // two longer than the ellipsis + "1 ... 5", // just long enough for the ellipsis + "1 ... 6", // another past the ellipsis + "1 ... 0"}; std::vector<std::string> resultListMaxLength20{ - "", // empty - "1,2", // shorter than the ellipsis - "1,2,3", // equal in length than the ellipsis - "1,2,35", // one longer than the ellipsis - "1,2,3,4", // two longer than the ellipsis - "1,2,3,45", // just long enough for the ellipsis - "12,3,4,56", // another past the ellipsis - "1,2,3,4 ... 8,19,20" }; - - //test very short max size + "", // empty + "1,2", // shorter than the ellipsis + "1,2,3", // equal in length than the ellipsis + "1,2,35", // one longer than the ellipsis + "1,2,3,4", // two longer than the ellipsis + "1,2,3,45", // just long enough for the ellipsis + "12,3,4,56", // another past the ellipsis + "1,2,3,4 ... 8,19,20"}; + + // test very short max size int maxLength = 7; for (size_t i = 0; i < inputList.size(); i++) { const auto &input = inputList[i]; std::string result = shortenList(input, maxLength); - TS_ASSERT_EQUALS( - result, - resultListMaxLength7[i]); - TS_ASSERT_LESS_THAN_EQUALS( - result.size(), - maxLength); - TS_ASSERT_LESS_THAN_EQUALS( - result.size(), - input.size()); + TS_ASSERT_EQUALS(result, resultListMaxLength7[i]); + TS_ASSERT_LESS_THAN_EQUALS(result.size(), maxLength); + TS_ASSERT_LESS_THAN_EQUALS(result.size(), input.size()); } - //test longer max size + // test longer max size maxLength = 20; for (size_t i = 0; i < inputList.size(); i++) { const auto &input = inputList[i]; std::string result = shortenList(input, maxLength); - TS_ASSERT_EQUALS( - result, - resultListMaxLength20[i]); - TS_ASSERT_LESS_THAN_EQUALS( - result.size(), - maxLength); - TS_ASSERT_LESS_THAN_EQUALS( - result.size(), - input.size()); + TS_ASSERT_EQUALS(result, resultListMaxLength20[i]); + TS_ASSERT_LESS_THAN_EQUALS(result.size(), maxLength); + TS_ASSERT_LESS_THAN_EQUALS(result.size(), input.size()); } }