Skip to content

Commit

Permalink
Re #9731. Changed allowed values storage type to vector
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jul 23, 2014
1 parent 9c09868 commit fbd39ac
Show file tree
Hide file tree
Showing 37 changed files with 144 additions and 103 deletions.
Expand Up @@ -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<std::string> getExts() const
{ return std::set<std::string>(m_exts.begin(), m_exts.end()); }
std::vector<std::string> getExts() const { return m_exts; }

/// Returns the main file extension that's used
std::string getDefaultExt() const {return m_defaultExt;}
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h
Expand Up @@ -309,7 +309,7 @@ namespace Mantid
* For output workspaces, an empty set is returned
* @return set of objects in AnalysisDataService
*/
virtual std::set<std::string> allowedValues() const
virtual std::vector<std::string> allowedValues() const
{
if ( this->direction() == Kernel::Direction::Input || this->direction() == Kernel::Direction::InOut )
{
Expand All @@ -331,12 +331,12 @@ namespace Mantid
}
else ++it;
}
return vals;
return std::vector<std::string>(vals.begin(), vals.end());
}
else
{
// For output workspaces, just return an empty set
return std::set<std::string>();
return std::vector<std::string>();
}
}

Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/API/src/FileProperty.cpp
Expand Up @@ -224,10 +224,10 @@ bool FileProperty::extsMatchRunFiles()
const std::vector<std::string> facilityExts = facilityInfo.extensions();
std::vector<std::string>::const_iterator facilityExtsBegin = facilityExts.begin();
std::vector<std::string>::const_iterator facilityExtsEnd = facilityExts.end();
const std::set<std::string> allowedExts = this->allowedValues();
const std::vector<std::string> allowedExts = this->allowedValues();

bool match(false);
for( std::set<std::string>::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 )
{
Expand Down Expand Up @@ -271,7 +271,7 @@ std::string FileProperty::setLoadProperty(const std::string & propValue)
{
if( m_runFileProp ) // runfiles go through FileFinder::findRun
{
std::set<std::string> allowedExts(allowedValues());
std::vector<std::string> allowedExts(allowedValues());
std::vector<std::string> exts;
if (!m_defaultExt.empty())
{
Expand All @@ -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<std::string>::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);
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/API/test/WorkspacePropertyTest.h
Expand Up @@ -162,11 +162,11 @@ class WorkspacePropertyTest : public CxxTest::TestSuite

void testAllowedValues()
{
std::set<std::string> vals;
std::vector<std::string> 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() )

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h
Expand Up @@ -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()
Expand Down
Expand Up @@ -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<std::string> monitors = monSpec->allowedValues();
std::vector<std::string> monitors = monSpec->allowedValues();
TS_ASSERT_EQUALS(1,monitors.size());
TS_ASSERT_EQUALS("0",*(monitors.begin()));

Expand Down
Expand Up @@ -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<std::string> allowedValues() const;
std::vector<std::string> 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
Expand Down
Expand Up @@ -44,7 +44,7 @@ class MANTID_KERNEL_DLL DirectoryValidator : public FileValidator
public:
explicit DirectoryValidator(bool testDirectoryExists = true);
virtual ~DirectoryValidator();
virtual std::set<std::string> allowedValues() const;
virtual std::vector<std::string> allowedValues() const;
IValidator_sptr clone() const;

private:
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/FileValidator.h
Expand Up @@ -44,12 +44,12 @@ class MANTID_KERNEL_DLL FileValidator : public TypedValidator<std::string>
public:
explicit FileValidator(const std::vector<std::string>& extensions=std::vector<std::string>(), bool testFileExists = true, bool testCanWrite=false);
virtual ~FileValidator();
virtual std::set<std::string> allowedValues() const;
virtual std::vector<std::string> allowedValues() const;
IValidator_sptr clone() const;

protected:
/// The list of permitted extensions
const std::set<std::string> m_extensions;
const std::vector<std::string> m_extensions;
/// Flag indicating whether to test for existence of filename
bool m_testExist;
/// Flag indicating whether to test for the file being writable
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/IValidator.h
Expand Up @@ -14,7 +14,7 @@
# include <boost/type_traits/is_convertible.hpp>
# include <boost/type_traits/is_pointer.hpp>
#endif
#include <set>
#include <vector>
#include <string>
#include <sstream>

Expand Down Expand Up @@ -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<std::string> allowedValues() const { return std::set<std::string>(); }
virtual std::vector<std::string> allowedValues() const { return std::vector<std::string>(); }

/// Make a copy of the present type of validator
virtual IValidator_sptr clone() const = 0;
Expand Down
26 changes: 17 additions & 9 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/ListValidator.h
Expand Up @@ -9,6 +9,7 @@
# include <boost/lexical_cast.hpp>
#endif
#include <vector>
#include <map>

namespace Mantid
{
Expand Down Expand Up @@ -57,8 +58,8 @@ class ListValidator : public TypedValidator<TYPE>

/** Constructor
* @param values :: A vector of the valid values */
explicit ListValidator(const std::vector<TYPE>& values):
TypedValidator<TYPE>(), m_allowedValues(values.begin(), values.end())
explicit ListValidator(const std::vector<TYPE>& values, const std::map<std::string,TYPE>& aliases = std::map<std::string,TYPE>()):
TypedValidator<TYPE>(), m_allowedValues(values.begin(), values.end()), m_aliases(aliases.begin(),aliases.end())
{
}
/// Destructor
Expand All @@ -69,25 +70,30 @@ class ListValidator : public TypedValidator<TYPE>
* Returns the set of allowed values currently defined
* @returns A set of allowed values that this validator will currently allow
*/
std::set<std::string> allowedValues() const
std::vector<std::string> allowedValues() const
{
/// The interface requires strings
std::set<std::string> allowedStrings;
std::vector<std::string> 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<std::string>(*cit));
allowedStrings.push_back(boost::lexical_cast<std::string>(*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
Expand All @@ -96,7 +102,7 @@ class ListValidator : public TypedValidator<TYPE>
*/
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 "";
}
Expand Down Expand Up @@ -124,7 +130,9 @@ class ListValidator : public TypedValidator<TYPE>
bool isEmpty(const std::string & value) const { return value.empty(); }

/// The set of valid values
std::set<TYPE> m_allowedValues;
std::vector<TYPE> m_allowedValues;
/// The optional aliases for the allowed values.
std::map<std::string,TYPE> m_aliases;
};

/// ListValidator<std::string> is used heavily
Expand Down
Expand Up @@ -51,7 +51,7 @@ class MANTID_KERNEL_DLL MultiFileValidator : public TypedValidator<std::vector<s
IValidator_sptr clone() const;

/// Returns the set of allowed extensions.
virtual std::set<std::string> allowedValues() const;
virtual std::vector<std::string> allowedValues() const;

protected:
/// FileValidator instance used for validating multiple files.
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h
Expand Up @@ -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<std::string> allowedValues() const;
virtual std::vector<std::string> allowedValues() const;

virtual const PropertyHistory createHistory() const;

Expand Down
Expand Up @@ -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<std::string> allowedValues() const
virtual std::vector<std::string> allowedValues() const
{
return m_validator->allowedValues();
}
Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/Kernel/src/CompositeValidator.cpp
Expand Up @@ -23,7 +23,7 @@ namespace Mantid
* the intersection of the allowedValues for the child validators
* @return
*/
std::set<std::string> CompositeValidator::allowedValues() const
std::vector<std::string> CompositeValidator::allowedValues() const
{
std::set<std::string> elem_unique;
std::multiset<std::string> elem_all;
Expand All @@ -32,14 +32,14 @@ namespace Mantid
std::list<IValidator_sptr>::const_iterator itrEnd = m_children.end();
for( std::list<IValidator_sptr>::const_iterator itr = m_children.begin(); itr != itrEnd; ++itr)
{
std::set<std::string> subs = (*itr)->allowedValues();
std::vector<std::string> 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<std::string>( elem_unique.begin(), elem_unique.end() );
// there is more then one combination and we have to identify its union;
for(std::set<std::string>::const_iterator its=elem_unique.begin();its!=elem_unique.end();++its)
{
Expand All @@ -51,7 +51,7 @@ namespace Mantid
{
rez.insert(*im);
}
return rez;
return std::vector<std::string>( rez.begin(), rez.end() );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/src/DirectoryValidator.cpp
Expand Up @@ -22,9 +22,9 @@ DirectoryValidator::DirectoryValidator(bool testDirectoryExists)
DirectoryValidator::~DirectoryValidator() {}

/// Returns the set of valid values
std::set<std::string> DirectoryValidator::allowedValues() const
std::vector<std::string> DirectoryValidator::allowedValues() const
{
return std::set<std::string>();
return std::vector<std::string>();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Kernel/src/FileValidator.cpp
Expand Up @@ -48,7 +48,7 @@ FileValidator::FileValidator(const std::vector<std::string>& extensions, bool te
FileValidator::~FileValidator() {}

/// Returns the set of valid values
std::set<std::string> FileValidator::allowedValues() const
std::vector<std::string> FileValidator::allowedValues() const
{
return m_extensions;
}
Expand Down Expand Up @@ -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<std::string>::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() << "]";
}
Expand Down Expand Up @@ -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<std::string>::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;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Kernel/src/MultiFileValidator.cpp
Expand Up @@ -42,7 +42,7 @@ namespace Kernel
MultiFileValidator::~MultiFileValidator() {}

/// Returns the set of valid values
std::set<std::string> MultiFileValidator::allowedValues() const
std::vector<std::string> MultiFileValidator::allowedValues() const
{
return m_fileValidator.allowedValues();
}
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/src/Property.cpp
Expand Up @@ -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<std::string> Property::allowedValues() const
std::vector<std::string> Property::allowedValues() const
{
return std::set<std::string>();
return std::vector<std::string>();
}

/// Create a PropertyHistory object representing the current state of the Property.
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp
Expand Up @@ -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";

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/test/CompositeValidatorTest.h
Expand Up @@ -54,7 +54,7 @@ class CompositeValidatorTest : public CxxTest::TestSuite
CompositeValidator comp;
comp.add(IValidator_sptr(val1));

std::set<std::string> allowed=comp.allowedValues();
std::vector<std::string> allowed=comp.allowedValues();
TS_ASSERT_EQUALS(allowed_val1.size(),allowed.size());

std::vector<std::string> allowed_val2(3);
Expand All @@ -63,7 +63,7 @@ class CompositeValidatorTest : public CxxTest::TestSuite
StringListValidator * val2 = new StringListValidator(allowed_val2);
comp.add(IValidator_sptr(val2));

std::set<std::string> allowed2=comp.allowedValues();
std::vector<std::string> allowed2=comp.allowedValues();
TS_ASSERT_EQUALS(1,allowed2.size());
TS_ASSERT_EQUALS("b2",*(allowed2.begin()));

Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/Kernel/test/ListValidatorTest.h
Expand Up @@ -49,12 +49,12 @@ class ListValidatorTest : public CxxTest::TestSuite
StringListValidator v;
v.addAllowedValue("one");
v.addAllowedValue("two");
std::set<std::string> s;
std::vector<std::string> 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()
Expand Down

0 comments on commit fbd39ac

Please sign in to comment.