Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #10135. Added factory for SymmetryOperations
- Loading branch information
Michael Wedel
committed
Sep 10, 2014
1 parent
2fb944c
commit 2dbbe8a
Showing
5 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryOperationFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifndef MANTID_GEOMETRY_SYMMETRYOPERATIONFACTORY_H_ | ||
#define MANTID_GEOMETRY_SYMMETRYOPERATIONFACTORY_H_ | ||
|
||
#include "MantidGeometry/DllConfig.h" | ||
#include "MantidKernel/DynamicFactory.h" | ||
#include "MantidKernel/SingletonHolder.h" | ||
#include "MantidGeometry/Crystal/SymmetryOperation.h" | ||
|
||
#include <list> | ||
#include <iostream> | ||
|
||
namespace Mantid | ||
{ | ||
namespace Geometry | ||
{ | ||
/** SymmetryOperationFactory | ||
A factory for symmetry operations. Symmetry operations are stored | ||
with respect to their identifier (see SymmetryOperations for details). | ||
Creation of symmetry operations is then performed like this: | ||
SymmetryOperations_sptr inversion = SymmetryOperationFactory::Instance().createSymOp("-1"); | ||
There's a method to query all available symmetry operations. | ||
@author Michael Wedel, Paul Scherrer Institut - SINQ | ||
@date 10/09/2014 | ||
Copyright © 2014 PSI-MSS | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class MANTID_GEOMETRY_DLL SymmetryOperationFactoryImpl : public Kernel::DynamicFactory<const SymmetryOperation> | ||
{ | ||
public: | ||
SymmetryOperation_const_sptr createSymOp(const std::string &identifier) const; | ||
|
||
const std::list<std::string> &getAllSymOpIdentifiers() const; | ||
|
||
/// Subscribes a symmetry operation into the factory | ||
template <class C> | ||
void subscribeSymOp() | ||
{ | ||
Kernel::Instantiator<const C, const SymmetryOperation> *instantiator = new Kernel::Instantiator<const C, const SymmetryOperation>; | ||
SymmetryOperation_const_sptr temporarySymOp = instantiator->createInstance(); | ||
std::string identifier = temporarySymOp->identifier(); | ||
|
||
subscribe(identifier, instantiator); | ||
addToAvailable(identifier); | ||
} | ||
|
||
/// Unsubscribes a symmetry operation from the factory | ||
void unsubscribeSymOp(const std::string &identifier) | ||
{ | ||
unsubscribe(identifier); | ||
removeFromAvailable(identifier); | ||
} | ||
|
||
private: | ||
friend struct Mantid::Kernel::CreateUsingNew<SymmetryOperationFactoryImpl>; | ||
|
||
SymmetryOperationFactoryImpl(); | ||
void addToAvailable(const std::string &identifier); | ||
void removeFromAvailable(const std::string &identifier); | ||
|
||
std::list<std::string> m_availableSymOps; | ||
}; | ||
|
||
// This is taken from FuncMinimizerFactory | ||
#ifdef _WIN32 | ||
template class MANTID_GEOMETRY_DLL Mantid::Kernel::SingletonHolder<SymmetryOperationFactory>; | ||
#endif | ||
|
||
typedef Mantid::Kernel::SingletonHolder<SymmetryOperationFactoryImpl> SymmetryOperationFactory; | ||
|
||
|
||
} // namespace Geometry | ||
} // namespace Mantid | ||
|
||
#define DECLARE_SYMMETRY_OPERATION(classname) \ | ||
namespace { \ | ||
Mantid::Kernel::RegistrationHelper register_symop_##classname( \ | ||
((Mantid::Geometry::SymmetryOperationFactory::Instance().subscribeSymOp<classname>()) \ | ||
, 0)); \ | ||
} | ||
|
||
#endif /* MANTID_GEOMETRY_SYMMETRYOPERATIONFACTORY_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Code/Mantid/Framework/Geometry/src/Crystal/SymmetryOperationFactory.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "MantidGeometry/Crystal/SymmetryOperationFactory.h" | ||
#include "MantidKernel/LibraryManager.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Geometry | ||
{ | ||
|
||
/// Creates a SymmetryOperation object from its Hermann-Mauguin symbol. | ||
SymmetryOperation_const_sptr SymmetryOperationFactoryImpl::createSymOp(const std::string &identifier) const | ||
{ | ||
return create(identifier); | ||
} | ||
|
||
/// Returns the Hermann-Mauguin symbols of all registered point groups. | ||
const std::list<std::string> &SymmetryOperationFactoryImpl::getAllSymOpIdentifiers() const | ||
{ | ||
return m_availableSymOps; | ||
} | ||
|
||
/// Private default constructor. | ||
SymmetryOperationFactoryImpl::SymmetryOperationFactoryImpl() : Kernel::DynamicFactory<const SymmetryOperation>(), | ||
m_availableSymOps() | ||
{ | ||
Kernel::LibraryManager::Instance(); | ||
} | ||
|
||
/// Adds a point group to a map that stores pairs of Hermann-Mauguin symbol and crystal system. | ||
void SymmetryOperationFactoryImpl::addToAvailable(const std::string &identifier) | ||
{ | ||
m_availableSymOps.insert(m_availableSymOps.end(), identifier); | ||
} | ||
|
||
/// Removes point group from internal crystal system map. | ||
void SymmetryOperationFactoryImpl::removeFromAvailable(const std::string &identifier) | ||
{ | ||
m_availableSymOps.remove(identifier); | ||
} | ||
|
||
} // namespace Geometry | ||
} // namespace Mantid |
28 changes: 28 additions & 0 deletions
28
Code/Mantid/Framework/Geometry/test/SymmetryOperationFactoryTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef MANTID_GEOMETRY_SYMMETRYOPERATIONFACTORYTEST_H_ | ||
#define MANTID_GEOMETRY_SYMMETRYOPERATIONFACTORYTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidGeometry/Crystal/SymmetryOperationFactory.h" | ||
|
||
using Mantid::Geometry::SymmetryOperationFactory; | ||
|
||
class SymmetryOperationFactoryTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static SymmetryOperationFactoryTest *createSuite() { return new SymmetryOperationFactoryTest(); } | ||
static void destroySuite( SymmetryOperationFactoryTest *suite ) { delete suite; } | ||
|
||
|
||
void test_Something() | ||
{ | ||
TSM_ASSERT( "You forgot to write a test!", 0); | ||
} | ||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_GEOMETRY_SYMMETRYOPERATIONFACTORYTEST_H_ */ |