Skip to content

Commit

Permalink
Refs #10281. Added simple factory function for Group-objects.
Browse files Browse the repository at this point in the history
Since groups can be constructed from strings only and are probably not used directly in code so much, this solution seems simpler than a complete factory.
  • Loading branch information
Michael Wedel committed Oct 7, 2014
1 parent d281ab2 commit c2cbd2b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Expand Up @@ -43,11 +43,10 @@ namespace Geometry
class MANTID_GEOMETRY_DLL CyclicGroup : public Group
{
public:
CyclicGroup(const std::string &symmetryOperationString);
CyclicGroup(const SymmetryOperation &symmetryOperation);
virtual ~CyclicGroup() { }

static Group_const_sptr create(const std::string &symmetryOperation);

protected:
std::vector<SymmetryOperation> generateAllOperations(const SymmetryOperation &operation) const;

Expand Down
Expand Up @@ -8,6 +8,7 @@
#include <set>

#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>

namespace Mantid
{
Expand Down Expand Up @@ -71,6 +72,14 @@ class MANTID_GEOMETRY_DLL Group
typedef boost::shared_ptr<Group> Group_sptr;
typedef boost::shared_ptr<const Group> Group_const_sptr;

namespace GroupFactory {
template<typename T>
Group_const_sptr create(const std::string &initializationString)
{
return boost::make_shared<const T>(initializationString);
}
}

MANTID_GEOMETRY_DLL Group_const_sptr operator *(const Group_const_sptr &lhs, const Group_const_sptr &rhs);
MANTID_GEOMETRY_DLL std::vector<Kernel::V3D> operator *(const Group_const_sptr &lhs, const Kernel::V3D &rhs);
MANTID_GEOMETRY_DLL bool operator ==(const Group_const_sptr &lhs, const Group_const_sptr &rhs);
Expand Down
9 changes: 5 additions & 4 deletions Code/Mantid/Framework/Geometry/src/Crystal/CyclicGroup.cpp
Expand Up @@ -8,14 +8,15 @@ namespace Geometry
{

/// Construct cyclic group from one symmetry operation by applying it to itself until identity is obtained.
CyclicGroup::CyclicGroup(const SymmetryOperation &symmetryOperation) :
Group(generateAllOperations(symmetryOperation))
CyclicGroup::CyclicGroup(const std::string &symmetryOperationString) :
Group(generateAllOperations(SymmetryOperationFactory::Instance().createSymOp(symmetryOperationString)))
{

}

Group_const_sptr CyclicGroup::create(const std::string &symmetryOperation)
CyclicGroup::CyclicGroup(const SymmetryOperation &symmetryOperation) :
Group(generateAllOperations(symmetryOperation))
{
return boost::make_shared<const CyclicGroup>(SymmetryOperationFactory::Instance().createSymOp(symmetryOperation));
}

std::vector<SymmetryOperation> CyclicGroup::generateAllOperations(const SymmetryOperation &operation) const
Expand Down
18 changes: 9 additions & 9 deletions Code/Mantid/Framework/Geometry/test/CyclicGroupTest.h
Expand Up @@ -29,7 +29,7 @@ class CyclicGroupTest : public CxxTest::TestSuite

void testCreate()
{
Group_const_sptr group = CyclicGroup::create("-x,-y,-z");
Group_const_sptr group = GroupFactory::create<CyclicGroup>("-x,-y,-z");
TS_ASSERT(boost::dynamic_pointer_cast<const CyclicGroup>(group));

TS_ASSERT_EQUALS(group->order(), 2);
Expand All @@ -41,15 +41,15 @@ class CyclicGroupTest : public CxxTest::TestSuite
* the method used to generate point groups.
*/

Group_const_sptr groupOne = CyclicGroup::create("-x,-y,z");
Group_const_sptr groupTwo = CyclicGroup::create("x,-y,-z");
Group_const_sptr groupOne = GroupFactory::create<CyclicGroup>("-x,-y,z");
Group_const_sptr groupTwo = GroupFactory::create<CyclicGroup>("x,-y,-z");

// This is in fact point group 222
Group_const_sptr groupThree = groupOne * groupTwo;

TS_ASSERT_EQUALS(groupThree->order(), 4);

Group_const_sptr groupFour = CyclicGroup::create("-x,-y,-z");
Group_const_sptr groupFour = GroupFactory::create<CyclicGroup>("-x,-y,-z");

// Which becomes mmm, if inversion is added.
Group_const_sptr groupFive = groupFour * groupThree;
Expand All @@ -59,11 +59,11 @@ class CyclicGroupTest : public CxxTest::TestSuite
void testSpaceGroup()
{
// Small test, constructing Fm-3m (225) from the generators listed in ITA
Group_const_sptr group1 = CyclicGroup::create("-x,-y,z");
Group_const_sptr group2 = CyclicGroup::create("-x,y,-z");
Group_const_sptr group3 = CyclicGroup::create("z,x,y");
Group_const_sptr group4 = CyclicGroup::create("y,x,-z");
Group_const_sptr group5 = CyclicGroup::create("-x,-y,-z");
Group_const_sptr group1 = GroupFactory::create<CyclicGroup>("-x,-y,z");
Group_const_sptr group2 = GroupFactory::create<CyclicGroup>("-x,y,-z");
Group_const_sptr group3 = GroupFactory::create<CyclicGroup>("z,x,y");
Group_const_sptr group4 = GroupFactory::create<CyclicGroup>("y,x,-z");
Group_const_sptr group5 = GroupFactory::create<CyclicGroup>("-x,-y,-z");

// Make a translation group "F"
std::vector<SymmetryOperation> lops;
Expand Down

0 comments on commit c2cbd2b

Please sign in to comment.