From fbd39acd5ea92fb6fe876958eca8a42b49931f6d Mon Sep 17 00:00:00 2001 From: Roman Tolchenov Date: Wed, 23 Jul 2014 15:32:59 +0100 Subject: [PATCH] Re #9731. Changed allowed values storage type to vector --- .../API/inc/MantidAPI/MultipleFileProperty.h | 3 +- .../API/inc/MantidAPI/WorkspaceProperty.h | 6 ++-- .../Mantid/Framework/API/src/FileProperty.cpp | 8 ++--- .../API/test/WorkspacePropertyTest.h | 6 ++-- .../Algorithms/test/AddTimeSeriesLogTest.h | 4 +-- .../Algorithms/test/NormaliseToMonitorTest.h | 2 +- .../inc/MantidKernel/CompositeValidator.h | 2 +- .../inc/MantidKernel/DirectoryValidator.h | 2 +- .../Kernel/inc/MantidKernel/FileValidator.h | 4 +-- .../Kernel/inc/MantidKernel/IValidator.h | 4 +-- .../Kernel/inc/MantidKernel/ListValidator.h | 26 +++++++++----- .../inc/MantidKernel/MultiFileValidator.h | 2 +- .../Kernel/inc/MantidKernel/Property.h | 2 +- .../inc/MantidKernel/PropertyWithValue.h | 2 +- .../Kernel/src/CompositeValidator.cpp | 8 ++--- .../Kernel/src/DirectoryValidator.cpp | 4 +-- .../Framework/Kernel/src/FileValidator.cpp | 6 ++-- .../Kernel/src/MultiFileValidator.cpp | 2 +- Code/Mantid/Framework/Kernel/src/Property.cpp | 4 +-- .../Kernel/src/TimeSeriesProperty.cpp | 3 ++ .../Kernel/test/CompositeValidatorTest.h | 4 +-- .../Framework/Kernel/test/ListValidatorTest.h | 8 ++--- .../Kernel/test/PropertyWithValueTest.h | 36 ++++++++++++++++--- .../Kernel/test/StartsWithValidatorTest.h | 8 ++--- .../MDAlgorithms/test/ConvertToMDTest.h | 21 ++++++----- .../mantid/api/src/Exports/IAlgorithm.cpp | 2 +- .../MantidQt/API/src/AlgorithmDialog.cpp | 6 ++-- .../MantidQt/API/src/FilePropertyWidget.cpp | 12 +++---- .../API/src/OptionsPropertyWidget.cpp | 4 +-- .../src/CreateSampleShapeDialog.cpp | 4 +-- .../MantidQt/CustomDialogs/src/FitDialog.cpp | 4 +-- .../MantidQt/CustomDialogs/src/LoadDialog.cpp | 6 ++-- .../CustomDialogs/src/LoadRawDialog.cpp | 12 +++---- .../MantidQtCustomInterfaces/SANSAddFiles.h | 4 +-- .../src/CreateMDWorkspaceAlgDialog.cpp | 2 +- .../CustomInterfaces/src/SANSAddFiles.cpp | 8 ++--- .../MantidQt/MantidWidgets/src/MWRunFiles.cpp | 6 ++-- 37 files changed, 144 insertions(+), 103 deletions(-) diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h b/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h index f34f61754b5d..2735f4cc62a7 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/MultipleFileProperty.h @@ -112,8 +112,7 @@ namespace API virtual std::string getDefault() const; /// @return the vector of suggested extensions. For use in GUIs showing files. - std::set getExts() const - { return std::set(m_exts.begin(), m_exts.end()); } + std::vector getExts() const { return m_exts; } /// Returns the main file extension that's used std::string getDefaultExt() const {return m_defaultExt;} diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h b/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h index c4e56872e2d6..496a71cc0efe 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h @@ -309,7 +309,7 @@ namespace Mantid * For output workspaces, an empty set is returned * @return set of objects in AnalysisDataService */ - virtual std::set allowedValues() const + virtual std::vector allowedValues() const { if ( this->direction() == Kernel::Direction::Input || this->direction() == Kernel::Direction::InOut ) { @@ -331,12 +331,12 @@ namespace Mantid } else ++it; } - return vals; + return std::vector(vals.begin(), vals.end()); } else { // For output workspaces, just return an empty set - return std::set(); + return std::vector(); } } diff --git a/Code/Mantid/Framework/API/src/FileProperty.cpp b/Code/Mantid/Framework/API/src/FileProperty.cpp index 8a76e4065d4d..dfa8da1a787d 100644 --- a/Code/Mantid/Framework/API/src/FileProperty.cpp +++ b/Code/Mantid/Framework/API/src/FileProperty.cpp @@ -224,10 +224,10 @@ bool FileProperty::extsMatchRunFiles() const std::vector facilityExts = facilityInfo.extensions(); std::vector::const_iterator facilityExtsBegin = facilityExts.begin(); std::vector::const_iterator facilityExtsEnd = facilityExts.end(); - const std::set allowedExts = this->allowedValues(); + const std::vector allowedExts = this->allowedValues(); bool match(false); - for( std::set::const_iterator it = allowedExts.begin(); it != allowedExts.end(); ++it ) + for( auto it = allowedExts.begin(); it != allowedExts.end(); ++it ) { if( std::find(facilityExtsBegin, facilityExtsEnd, *it) != facilityExtsEnd ) { @@ -271,7 +271,7 @@ std::string FileProperty::setLoadProperty(const std::string & propValue) { if( m_runFileProp ) // runfiles go through FileFinder::findRun { - std::set allowedExts(allowedValues()); + std::vector allowedExts(allowedValues()); std::vector exts; if (!m_defaultExt.empty()) { @@ -285,7 +285,7 @@ std::string FileProperty::setLoadProperty(const std::string & propValue) std::transform(m_defaultExt.begin(), m_defaultExt.end(), upper.begin(), toupper); addExtension(upper, exts); } - for(std::set::iterator it = allowedExts.begin();it!=allowedExts.end();++it) + for(auto it = allowedExts.begin();it!=allowedExts.end();++it) { std::string lower(*it); std::string upper(*it); diff --git a/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h b/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h index b45fb6e5b8e2..d9663ac0227f 100644 --- a/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h +++ b/Code/Mantid/Framework/API/test/WorkspacePropertyTest.h @@ -162,11 +162,11 @@ class WorkspacePropertyTest : public CxxTest::TestSuite void testAllowedValues() { - std::set vals; + std::vector vals; TS_ASSERT_THROWS_NOTHING( vals = wsp1->allowedValues() ) TS_ASSERT_EQUALS( vals.size(), 2 ) - TS_ASSERT( vals.count("ws1") ) - TS_ASSERT( vals.count("ws3") ) + TS_ASSERT( std::find( vals.begin(), vals.end(), "ws1") != vals.end() ) + TS_ASSERT( std::find( vals.begin(), vals.end(), "ws3") != vals.end() ) TS_ASSERT( wsp2->allowedValues().empty() ) diff --git a/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h b/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h index 5f9c9e94146c..2b14bb34f75a 100644 --- a/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h +++ b/Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h @@ -47,8 +47,8 @@ class AddTimeSeriesLogTest : public CxxTest::TestSuite const auto allowedValues = prop->allowedValues(); TS_ASSERT_EQUALS(2, allowedValues.size()); - TS_ASSERT_EQUALS(1, allowedValues.count("int")); - TS_ASSERT_EQUALS(1, allowedValues.count("double")); + TS_ASSERT( std::find( allowedValues.begin(), allowedValues.end(), "int") != allowedValues.end() ); + TS_ASSERT( std::find( allowedValues.begin(), allowedValues.end(), "double") != allowedValues.end() ); } void test_delete_existing_removes_complete_log_first() diff --git a/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h b/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h index d238a916a8f2..9dea3ac21850 100644 --- a/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h +++ b/Code/Mantid/Framework/Algorithms/test/NormaliseToMonitorTest.h @@ -321,7 +321,7 @@ class NormaliseToMonitorTest : public CxxTest::TestSuite TS_ASSERT_THROWS_NOTHING(pSett= monSpec->getSettings()); TS_ASSERT_THROWS_NOTHING(pSett->applyChanges(&norm6, monSpec)); // it should return the list of allowed monitor ID-s - std::set monitors = monSpec->allowedValues(); + std::vector monitors = monSpec->allowedValues(); TS_ASSERT_EQUALS(1,monitors.size()); TS_ASSERT_EQUALS("0",*(monitors.begin())); diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h index 82186c0051bb..36b57a0204b5 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/CompositeValidator.h @@ -49,7 +49,7 @@ namespace Kernel ///Gets the type of the validator std::string getType() const { return "composite"; } /// Return the instersection of allowed values from children - std::set allowedValues() const; + std::vector allowedValues() const; /// Clones this and the children into a new Validator IValidator_sptr clone() const; /// Adds a validator to the group of validators to check diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h index d16ff94d8222..9b19d4c9a385 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/DirectoryValidator.h @@ -44,7 +44,7 @@ class MANTID_KERNEL_DLL DirectoryValidator : public FileValidator public: explicit DirectoryValidator(bool testDirectoryExists = true); virtual ~DirectoryValidator(); - virtual std::set allowedValues() const; + virtual std::vector allowedValues() const; IValidator_sptr clone() const; private: diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h index f6d444dba8ba..e9c0d03ddfc6 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h @@ -44,12 +44,12 @@ class MANTID_KERNEL_DLL FileValidator : public TypedValidator public: explicit FileValidator(const std::vector& extensions=std::vector(), bool testFileExists = true, bool testCanWrite=false); virtual ~FileValidator(); - virtual std::set allowedValues() const; + virtual std::vector allowedValues() const; IValidator_sptr clone() const; protected: /// The list of permitted extensions - const std::set m_extensions; + const std::vector m_extensions; /// Flag indicating whether to test for existence of filename bool m_testExist; /// Flag indicating whether to test for the file being writable diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h index 47bf2b7dcc95..f220777ae4b5 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h @@ -14,7 +14,7 @@ # include # include #endif -#include +#include #include #include @@ -106,7 +106,7 @@ class DLLExport IValidator * Overridden in applicable concrete validators; the base class just returns an empty set. * @return The set of allowed values that this validator may have or an empty set */ - virtual std::set allowedValues() const { return std::set(); } + virtual std::vector allowedValues() const { return std::vector(); } /// Make a copy of the present type of validator virtual IValidator_sptr clone() const = 0; diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h index 8fd5e39a2742..328c2f972df4 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h @@ -9,6 +9,7 @@ # include #endif #include +#include namespace Mantid { @@ -57,8 +58,8 @@ class ListValidator : public TypedValidator /** Constructor * @param values :: A vector of the valid values */ - explicit ListValidator(const std::vector& values): - TypedValidator(), m_allowedValues(values.begin(), values.end()) + explicit ListValidator(const std::vector& values, const std::map& aliases = std::map()): + TypedValidator(), m_allowedValues(values.begin(), values.end()), m_aliases(aliases.begin(),aliases.end()) { } /// Destructor @@ -69,25 +70,30 @@ class ListValidator : public TypedValidator * Returns the set of allowed values currently defined * @returns A set of allowed values that this validator will currently allow */ - std::set allowedValues() const + std::vector allowedValues() const { /// The interface requires strings - std::set allowedStrings; + std::vector allowedStrings; + allowedStrings.reserve(m_allowedValues.size()); auto cend = m_allowedValues.end(); for(auto cit = m_allowedValues.begin(); cit != cend; ++cit) { - allowedStrings.insert(boost::lexical_cast(*cit)); + allowedStrings.push_back(boost::lexical_cast(*cit)); } return allowedStrings; } /** - * Add value to the list of allowable values + * Add value to the list of allowable values if it's not already there * @param value :: A value of the templated type */ void addAllowedValue(const TYPE &value) { - m_allowedValues.insert(value); + // add only new values + if ( std::find( m_allowedValues.begin(), m_allowedValues.end(), value ) == m_allowedValues.end() ) + { + m_allowedValues.push_back(value); + } } protected: /** Checks if the string passed is in the list @@ -96,7 +102,7 @@ class ListValidator : public TypedValidator */ std::string checkValidity(const TYPE & value) const { - if ( m_allowedValues.count(value) ) + if ( m_allowedValues.end() != std::find( m_allowedValues.begin(), m_allowedValues.end(), value ) ) { return ""; } @@ -124,7 +130,9 @@ class ListValidator : public TypedValidator bool isEmpty(const std::string & value) const { return value.empty(); } /// The set of valid values - std::set m_allowedValues; + std::vector m_allowedValues; + /// The optional aliases for the allowed values. + std::map m_aliases; }; /// ListValidator is used heavily diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h index b784cdd1b773..cec9ca9815a1 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/MultiFileValidator.h @@ -51,7 +51,7 @@ class MANTID_KERNEL_DLL MultiFileValidator : public TypedValidator allowedValues() const; + virtual std::vector allowedValues() const; protected: /// FileValidator instance used for validating multiple files. diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h index 570ed6f9f332..f12efa4e6013 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h @@ -137,7 +137,7 @@ class MANTID_KERNEL_DLL Property /// Get the default value for the property which is the value the property was initialised with virtual std::string getDefault() const = 0; - virtual std::set allowedValues() const; + virtual std::vector allowedValues() const; virtual const PropertyHistory createHistory() const; diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h index 167cf066263e..7bb0942632a8 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h @@ -486,7 +486,7 @@ class DLLExport PropertyWithValue : public Property * If not, it returns an empty vector. * @return Returns the set of valid values for this property, or it returns an empty vector. */ - virtual std::set allowedValues() const + virtual std::vector allowedValues() const { return m_validator->allowedValues(); } diff --git a/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp b/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp index c708532a088a..e617ba961dac 100644 --- a/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp +++ b/Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp @@ -23,7 +23,7 @@ namespace Mantid * the intersection of the allowedValues for the child validators * @return */ - std::set CompositeValidator::allowedValues() const + std::vector CompositeValidator::allowedValues() const { std::set elem_unique; std::multiset elem_all; @@ -32,14 +32,14 @@ namespace Mantid std::list::const_iterator itrEnd = m_children.end(); for( std::list::const_iterator itr = m_children.begin(); itr != itrEnd; ++itr) { - std::set subs = (*itr)->allowedValues(); + std::vector subs = (*itr)->allowedValues(); if ( subs.empty())continue; elem_unique.insert(subs.begin(),subs.end()); elem_all.insert(subs.begin(),subs.end()); n_combinations++; } // empty or single set of allowed values - if(n_combinations<2)return elem_unique; + if(n_combinations<2)return std::vector( elem_unique.begin(), elem_unique.end() ); // there is more then one combination and we have to identify its union; for(std::set::const_iterator its=elem_unique.begin();its!=elem_unique.end();++its) { @@ -51,7 +51,7 @@ namespace Mantid { rez.insert(*im); } - return rez; + return std::vector( rez.begin(), rez.end() ); } /** diff --git a/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp b/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp index e2e6e775e55b..d0c2daa5b4c0 100644 --- a/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp +++ b/Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp @@ -22,9 +22,9 @@ DirectoryValidator::DirectoryValidator(bool testDirectoryExists) DirectoryValidator::~DirectoryValidator() {} /// Returns the set of valid values -std::set DirectoryValidator::allowedValues() const +std::vector DirectoryValidator::allowedValues() const { - return std::set(); + return std::vector(); } /** diff --git a/Code/Mantid/Framework/Kernel/src/FileValidator.cpp b/Code/Mantid/Framework/Kernel/src/FileValidator.cpp index 254444b8a284..e9be79a6d66d 100644 --- a/Code/Mantid/Framework/Kernel/src/FileValidator.cpp +++ b/Code/Mantid/Framework/Kernel/src/FileValidator.cpp @@ -48,7 +48,7 @@ FileValidator::FileValidator(const std::vector& extensions, bool te FileValidator::~FileValidator() {} /// Returns the set of valid values -std::set FileValidator::allowedValues() const +std::vector FileValidator::allowedValues() const { return m_extensions; } @@ -83,7 +83,7 @@ std::string FileValidator::checkValidity(const std::string &value) const g_log.debug() << "Unrecognised extension in file \"" << value << "\""; if (!this->m_extensions.empty()) { g_log.debug() << " [ "; - for (std::set::const_iterator it = this->m_extensions.begin(); it != this->m_extensions.end(); ++it) + for (auto it = this->m_extensions.begin(); it != this->m_extensions.end(); ++it) g_log.debug() << *it << " "; g_log.debug() << "]"; } @@ -190,7 +190,7 @@ bool FileValidator::endswith(const std::string &value) const std::transform(value_copy.begin(), value_copy.end(), value_copy.begin(), tolower); // check for the ending - for (std::set::const_iterator it = m_extensions.begin(); + for (auto it = m_extensions.begin(); it != m_extensions.end(); ++it) { if (has_ending(value, *it)) // original case return true; diff --git a/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp b/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp index d1edf007089f..15090af71e07 100644 --- a/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp +++ b/Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp @@ -42,7 +42,7 @@ namespace Kernel MultiFileValidator::~MultiFileValidator() {} /// Returns the set of valid values - std::set MultiFileValidator::allowedValues() const + std::vector MultiFileValidator::allowedValues() const { return m_fileValidator.allowedValues(); } diff --git a/Code/Mantid/Framework/Kernel/src/Property.cpp b/Code/Mantid/Framework/Kernel/src/Property.cpp index 90562b02d15d..7adf842043f2 100644 --- a/Code/Mantid/Framework/Kernel/src/Property.cpp +++ b/Code/Mantid/Framework/Kernel/src/Property.cpp @@ -182,9 +182,9 @@ void Property::setBriefDocumentation( const std::string& documentation ) * If not, it returns an empty set. * @return the set of valid values for this property or an empty set */ -std::set Property::allowedValues() const +std::vector Property::allowedValues() const { - return std::set(); + return std::vector(); } /// Create a PropertyHistory object representing the current state of the Property. diff --git a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp index 4203056b2ec7..fd5486eac227 100644 --- a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp +++ b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp @@ -1786,6 +1786,9 @@ namespace Mantid ++ vit; } + // update m_size + countSize(); + // 3. Finish g_log.warning() << "Log " << this->name() << " has " << numremoved << " entries removed due to duplicated time. " << "\n"; diff --git a/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h b/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h index e6e36c5a62c9..795420bd2d84 100644 --- a/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h +++ b/Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h @@ -54,7 +54,7 @@ class CompositeValidatorTest : public CxxTest::TestSuite CompositeValidator comp; comp.add(IValidator_sptr(val1)); - std::set allowed=comp.allowedValues(); + std::vector allowed=comp.allowedValues(); TS_ASSERT_EQUALS(allowed_val1.size(),allowed.size()); std::vector allowed_val2(3); @@ -63,7 +63,7 @@ class CompositeValidatorTest : public CxxTest::TestSuite StringListValidator * val2 = new StringListValidator(allowed_val2); comp.add(IValidator_sptr(val2)); - std::set allowed2=comp.allowedValues(); + std::vector allowed2=comp.allowedValues(); TS_ASSERT_EQUALS(1,allowed2.size()); TS_ASSERT_EQUALS("b2",*(allowed2.begin())); diff --git a/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h b/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h index 566f529f8181..21ff66fb9d16 100644 --- a/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h +++ b/Code/Mantid/Framework/Kernel/test/ListValidatorTest.h @@ -49,12 +49,12 @@ class ListValidatorTest : public CxxTest::TestSuite StringListValidator v; v.addAllowedValue("one"); v.addAllowedValue("two"); - std::set s; + std::vector s; TS_ASSERT_THROWS_NOTHING( s = v.allowedValues() ) TS_ASSERT_EQUALS( s.size(), 2 ) - TS_ASSERT( s.count("one") ) - TS_ASSERT( s.count("two") ) - TS_ASSERT( ! s.count("three") ) + TS_ASSERT( std::find( s.begin(), s.end(), "one") != s.end() ) + TS_ASSERT( std::find( s.begin(), s.end(), "two") != s.end() ) + TS_ASSERT( std::find( s.begin(), s.end(), "three") == s.end() ) } void testAddAllowedValue() diff --git a/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h b/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h index 0ae11f401009..d13bc1d6101d 100644 --- a/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h +++ b/Code/Mantid/Framework/Kernel/test/PropertyWithValueTest.h @@ -502,11 +502,11 @@ class PropertyWithValueTest : public CxxTest::TestSuite TS_ASSERT_EQUALS( p.setValue("three"), "The value \"three\" is not in the list of allowed values" ); TS_ASSERT_EQUALS( p.value(), "two" ); TS_ASSERT_EQUALS( p.isValid(), "" ); - std::set vals; - TS_ASSERT_THROWS_NOTHING( vals = p.allowedValues() ); - TS_ASSERT_EQUALS( vals.size(), 2 ); - TS_ASSERT( vals.count("one") ); - TS_ASSERT( vals.count("two") ); + std::vector s; + TS_ASSERT_THROWS_NOTHING( s = p.allowedValues() ); + TS_ASSERT_EQUALS( s.size(), 2 ); + TS_ASSERT( std::find( s.begin(), s.end(), "one") != s.end() ) + TS_ASSERT( std::find( s.begin(), s.end(), "two") != s.end() ) } void testIsDefault() @@ -603,6 +603,32 @@ class PropertyWithValueTest : public CxxTest::TestSuite delete p1; delete p2; } + + void test_string_property_alias() + { + // system("pause"); + std::vector allowedValues; + allowedValues.push_back( "Hello"); + allowedValues.push_back( "World"); + std::map alias; + alias["Hello"] = "1"; + alias["World"] = "0"; + auto validator = boost::make_shared>(allowedValues,alias); + PropertyWithValue prop("String","",validator); + TS_ASSERT_THROWS_NOTHING( prop = "Hello" ); + std::string value = prop; + TS_ASSERT_EQUALS( value, "Hello" ); + + TS_ASSERT_THROWS( prop = "Mantid", std::invalid_argument ); + + //TS_ASSERT_THROWS_NOTHING( prop = "1" ); + //value = prop; + //TS_ASSERT_EQUALS( value, "Hello" ); + // + //TS_ASSERT_THROWS_NOTHING( prop = "0" ); + //value = prop; + //TS_ASSERT_EQUALS( value, "World" ); + } private: PropertyWithValue *iProp; diff --git a/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h b/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h index 7f53f9e44cfd..39a4f0a4bc79 100644 --- a/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h +++ b/Code/Mantid/Framework/Kernel/test/StartsWithValidatorTest.h @@ -49,12 +49,12 @@ class StartsWithValidatorTest : public CxxTest::TestSuite StartsWithValidator v; v.addAllowedValue("one"); v.addAllowedValue("two"); - std::set s; + std::vector s; TS_ASSERT_THROWS_NOTHING( s = v.allowedValues() ) TS_ASSERT_EQUALS( s.size(), 2 ) - TS_ASSERT( s.count("one") ) - TS_ASSERT( s.count("two") ) - TS_ASSERT( ! s.count("three") ) + TS_ASSERT( std::find( s.begin(), s.end(), "one") != s.end() ) + TS_ASSERT( std::find( s.begin(), s.end(), "two") != s.end() ) + TS_ASSERT( std::find( s.begin(), s.end(), "three") == s.end() ) } void testLongValues() diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h index 25ac7ac9eed1..85a3fc70baeb 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h @@ -55,6 +55,7 @@ class ConvertToMDTest : public CxxTest::TestSuite static ConvertToMDTest *createSuite() { return new ConvertToMDTest(); } static void destroySuite(ConvertToMDTest * suite) { delete suite; } +typedef std::vector PropertyAllowedValues; void testInit(){ @@ -193,21 +194,20 @@ void testAlgorithmProperties() TSM_ASSERT_THROWS_NOTHING("Property name has changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimProperty = alg.getProperty("MinValues")); TSM_ASSERT_THROWS_NOTHING("Property name has changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimProperty = alg.getProperty("MaxValues")); - typedef std::set PropertyAllowedValues; QDimProperty =alg.getProperty("QDimensions"); PropertyAllowedValues QDimValues = QDimProperty->allowedValues(); TSM_ASSERT_EQUALS("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", 3, QDimValues.size()); - TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimValues.find("CopyToMD") != QDimValues.end()); - TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimValues.find("|Q|") != QDimValues.end()); - TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", QDimValues.find("Q3D") != QDimValues.end()); + TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( QDimValues,"CopyToMD") ); + TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( QDimValues, "|Q|") ); + TSM_ASSERT("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( QDimValues, "Q3D") ); Mantid::Kernel::Property *dEAnalysisMode =alg.getProperty("dEAnalysisMode"); PropertyAllowedValues dEAnalysisModeValues = dEAnalysisMode->allowedValues(); TSM_ASSERT_EQUALS("QDimensions property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", 3, dEAnalysisModeValues.size()); -// TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", dEAnalysisModeValues.find("NoDE") != dEAnalysisModeValues.end()); - TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", dEAnalysisModeValues.find("Direct") != dEAnalysisModeValues.end()); - TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", dEAnalysisModeValues.find("Indirect") != dEAnalysisModeValues.end()); - TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", dEAnalysisModeValues.find("Elastic") != dEAnalysisModeValues.end()); +// TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( dEAnalysisModeValues, "NoDE") ); + TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( dEAnalysisModeValues, "Direct") ); + TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( dEAnalysisModeValues, "Indirect") ); + TSM_ASSERT("dEAnalysisMode property values have changed. This has broken Create MD Workspace GUI. Fix CreateMDWorkspaceGUI!", findValue( dEAnalysisModeValues, "Elastic") ); } @@ -239,6 +239,11 @@ ConvertToMDTest(){ TS_ASSERT_DELTA(bin.second, bin_max, 1e-8); } } + + bool findValue(const PropertyAllowedValues& container, const std::string& value) + { + return std::find( container.begin(), container.end(), value) != container.end(); + } }; //------------------------------------------------------------------------------------------------- diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp index 0344859c63e1..7dd6d4ba2b73 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IAlgorithm.cpp @@ -167,7 +167,7 @@ namespace if (!prop->isValid().empty()) buffer << ":req"; buffer << ") *" << prop->type() << "* "; - std::set allowed = prop->allowedValues(); + std::vector allowed = prop->allowedValues(); if (!prop->documentation().empty() || !allowed.empty()) { buffer << " " << prop->documentation(); diff --git a/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp b/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp index 58104745db7e..21d06a50739d 100644 --- a/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp +++ b/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp @@ -610,9 +610,9 @@ void AlgorithmDialog::fillAndSetComboBox(const QString & propName, QComboBox* op Mantid::Kernel::Property *property = getAlgorithmProperty(propName); if( !property ) return; - std::set items = property->allowedValues(); - std::set::const_iterator vend = items.end(); - for(std::set::const_iterator vitr = items.begin(); vitr != vend; + std::vector items = property->allowedValues(); + std::vector::const_iterator vend = items.end(); + for(std::vector::const_iterator vitr = items.begin(); vitr != vend; ++vitr) { optionsBox->addItem(QString::fromStdString(*vitr)); diff --git a/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp b/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp index 8cb24dd914ec..4ff4b79bbeb0 100644 --- a/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp +++ b/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp @@ -98,7 +98,7 @@ namespace API * @param defaultExt :: default extension to use * @return a string that filters files by extenstions */ - QString getFileDialogFilter(const std::set& exts, const std::string& defaultExt) + QString getFileDialogFilter(const std::vector& exts, const std::string& defaultExt) { QString filter(""); @@ -110,9 +110,9 @@ namespace API if( !exts.empty() ) { // --------- Load a File ------------- - std::set::const_iterator iend = exts.end(); + auto iend = exts.end(); // Push a wild-card onto the front of each file suffix - for( std::set::const_iterator itr = exts.begin(); itr != iend; ++itr) + for( auto itr = exts.begin(); itr != iend; ++itr) { if( (*itr) != defaultExt ) { @@ -138,7 +138,7 @@ namespace API if( !prop ) return ""; //The allowed values in this context are file extensions - std::set exts = prop->allowedValues(); + std::vector exts = prop->allowedValues(); std::string defaultExt = prop->getDefaultExt(); /* MG 20/07/09: Static functions such as these that use native Windows and MAC dialogs @@ -160,8 +160,8 @@ namespace API { filter = "*" + QString::fromStdString(defaultExt) + ";;"; } - std::set::const_iterator iend = exts.end(); - for( std::set::const_iterator itr = exts.begin(); itr != iend; ++itr) + auto iend = exts.end(); + for( auto itr = exts.begin(); itr != iend; ++itr) { if( (*itr) != defaultExt ) { diff --git a/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp b/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp index d5f518f96db1..f190d2600c17 100644 --- a/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp +++ b/Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp @@ -41,8 +41,8 @@ namespace API m_combo->setToolTip(m_doc); m_widgets.push_back(m_combo); - std::set items = prop->allowedValues(); - for(std::set::const_iterator vitr = items.begin(); vitr != items.end(); ++vitr) + std::vector items = prop->allowedValues(); + for(auto vitr = items.begin(); vitr != items.end(); ++vitr) { m_combo->addItem(QString::fromStdString(*vitr)); } diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp index 36b3c5ca6373..54c9353030ea 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp +++ b/Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp @@ -124,8 +124,8 @@ void CreateSampleShapeDialog::initLayout() // Check input workspace property. If there are available workspaces then // these have been set as allowed values - std::set workspaces = getAlgorithmProperty("InputWorkspace")->allowedValues(); - for( std::set::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr ) + std::vector workspaces = getAlgorithmProperty("InputWorkspace")->allowedValues(); + for( std::vector::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr ) { m_uiForm.wksp_opt->addItem(QString::fromStdString(*itr)); } diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp index 557acaf4f8dd..7b4217a2dc42 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp +++ b/Code/Mantid/MantidQt/CustomDialogs/src/FitDialog.cpp @@ -589,8 +589,8 @@ QString FitDialog::getStoredPropertyValue(const QString& propName) const QStringList FitDialog::getAllowedPropertyValues(const QString& propName) const { QStringList out; - std::set workspaces = getAlgorithmProperty(propName)->allowedValues(); - for( std::set::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr ) + std::vector workspaces = getAlgorithmProperty(propName)->allowedValues(); + for( std::vector::const_iterator itr = workspaces.begin(); itr != workspaces.end(); ++itr ) { out << QString::fromStdString(*itr); } diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp index b7a7e950f1cd..6f92896ad552 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp +++ b/Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp @@ -338,9 +338,9 @@ namespace MantidQt { QComboBox *optionsBox = new QComboBox(parent); inputWidget = optionsBox; - std::set items = prop->allowedValues(); - std::set::const_iterator vend = items.end(); - for(std::set::const_iterator vitr = items.begin(); vitr != vend; + std::vector items = prop->allowedValues(); + std::vector::const_iterator vend = items.end(); + for(std::vector::const_iterator vitr = items.begin(); vitr != vend; ++vitr) { optionsBox->addItem(QString::fromStdString(*vitr)); diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp b/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp index ce126c57199a..3805668c10da 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp +++ b/Code/Mantid/MantidQt/CustomDialogs/src/LoadRawDialog.cpp @@ -128,9 +128,9 @@ void LoadRawDialog::initLayout() if(cacheProp) { QComboBox *cacheBox = new QComboBox; - std::set items =cacheProp->allowedValues(); - std::set::const_iterator vend = items.end(); - for(std::set::const_iterator vitr = items.begin(); vitr != vend; + std::vector items =cacheProp->allowedValues(); + std::vector::const_iterator vend = items.end(); + for(std::vector::const_iterator vitr = items.begin(); vitr != vend; ++vitr) { cacheBox->addItem(QString::fromStdString(*vitr)); @@ -161,9 +161,9 @@ void LoadRawDialog::initLayout() QComboBox *monitorsBox =new QComboBox; - std::set monitoritems =loadMonitors->allowedValues(); - std::set::const_iterator mend = monitoritems.end(); - for(std::set::const_iterator mitr = monitoritems.begin(); mitr != mend; + std::vector monitoritems =loadMonitors->allowedValues(); + std::vector::const_iterator mend = monitoritems.end(); + for(std::vector::const_iterator mitr = monitoritems.begin(); mitr != mend; ++mitr) { if (std::find(excluded_values.begin(), excluded_values.end(), *mitr)==excluded_values.end()) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h index 83a90bcfe65c..fd9c38103569 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSAddFiles.h @@ -29,9 +29,9 @@ class SANSAddFiles : public MantidQt::API::UserSubWindow //set to true when execution of the python scripts starts and false on completion bool m_pythonRunning; //this is set to the extensions supported by the Load algorithm - std::set m_exts; + std::vector m_exts; //this is set to the extensions supported by LoadRaw - std::set m_rawExts; + std::vector m_rawExts; ///the directory to which files will be saved QString m_outDir; ///The text that goes into the beginning of the output directory message diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp index 8749d77d5501..7c4e45513b9d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspaceAlgDialog.cpp @@ -26,7 +26,7 @@ CreateMDWorkspaceAlgDialog::CreateMDWorkspaceAlgDialog() auto QModes = convertToMD->getPointerToProperty("QDimensions")->allowedValues(); if ( QModes.empty() ) // avoid weird situations with factory not initiated { - QModes.insert("No Q modes available; error Initiating Q-conversion factory"); + QModes.push_back("No Q modes available; error Initiating Q-conversion factory"); } for ( auto it = QModes.begin(); it != QModes.end(); ++it ) { diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp index e97ad25caad4..c700e19be24d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSAddFiles.cpp @@ -276,8 +276,8 @@ void SANSAddFiles::runPythonAddFiles() code_torun += ext+"'"; code_torun += ", rawTypes=("; - std::set::const_iterator end = m_rawExts.end(); - for(std::set::const_iterator j=m_rawExts.begin(); j != end; ++j) + std::vector::const_iterator end = m_rawExts.end(); + for(std::vector::const_iterator j=m_rawExts.begin(); j != end; ++j) { code_torun += "'"+QString::fromStdString(*j)+"',"; } @@ -339,8 +339,8 @@ void SANSAddFiles::new2AddBrowse() QString fileFilter = "Files ("; - std::set::const_iterator end = m_exts.end(); - for(std::set::const_iterator i = m_exts.begin(); i != end; ++i) + std::vector::const_iterator end = m_exts.end(); + for(std::vector::const_iterator i = m_exts.begin(); i != end; ++i) { fileFilter += " *"+QString::fromStdString(*i); } diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp index 751e73620627..f269286f0aef 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp @@ -933,7 +933,7 @@ QStringList MWRunFiles::getFileExtensionsFromAlgorithm(const QString & algName, FileProperty *fileProp = dynamic_cast(prop); MultipleFileProperty *multiFileProp = dynamic_cast(prop); - std::set allowed; + std::vector allowed; QString preferredExt; if( fileProp ) @@ -951,9 +951,9 @@ QStringList MWRunFiles::getFileExtensionsFromAlgorithm(const QString & algName, return fileExts; } - std::set::const_iterator iend = allowed.end(); + std::vector::const_iterator iend = allowed.end(); int index(0); - for(std::set::const_iterator it = allowed.begin(); it != iend; ++it) + for(std::vector::const_iterator it = allowed.begin(); it != iend; ++it) { if ( ! it->empty() ) {