* add the Matrix copy contructor
[diffractometer.git] / src / TangoHKLAdapterFactory.cpp
blob27a4d8dba8de226bfee4c1f108739b560fb1d092
1 #include "TangoHKLAdapterFactory.h"
2 #include "TangoHKLAdapter.h"
3 #include "DiffractometerDevice.h"
5 namespace DiffractometerDevice_ns
7 /**
9 * Static instance of the factory
12 TangoHKLAdapterFactory * TangoHKLAdapterFactory::_instance = NULL;
14 /**
16 * Return the instance of the factory
19 TangoHKLAdapterFactory * TangoHKLAdapterFactory::instance(void)
21 if (!_instance)
22 _instance = new TangoHKLAdapterFactory();
23 return _instance;
26 /**
27 * method: DiffractometerFactory::createDiffractometer
29 * description: create a hkl library associated with device name
31 * @return an instance of hkl adapter which contains an instance of the library
34 TangoHKLAdapter * TangoHKLAdapterFactory::attach_device(
35 DiffractometerDevice *device,
36 HklGeometryType type)
38 TangoHKLAdapter * adapter = NULL;
40 // Check if it already build
41 adapterMap_t::const_iterator iter;
42 iter = _adapterMap.find( device );
44 if (iter == _adapterMap.end()) {
45 adapter = new TangoHKLAdapter(device, type);
46 _adapterMap[device] = adapter;
47 std::cout << "TangoHKLAdapterFactory::attach_device new Diffractometer device " << device->get_name() << " created." << std::endl;
48 } else
49 adapter = iter->second;
51 return adapter;
54 void TangoHKLAdapterFactory::detach_device(DiffractometerDevice *device)
56 // Find the name in map
57 adapterMap_t::iterator iter;
58 iter = _adapterMap.find( device );
60 if (iter != _adapterMap.end()) {
61 // Do Delete it as it is used by the PseudoAxes.
62 //delete iter->second;
63 //_adapterMap.erase(iter);
64 std::cout << "TangoHKLAdapterFactory::removeDiffractometer Diffractometer device " << device->get_name() << " removed." << std::endl;
68 /**
69 * @brief Get the TangoHKLAdapter associated to a device named:
70 * @param devicename The name of the device.
71 * @return The TangoHKLAdapter pointer of the Device or NULL if the device is not present.
73 TangoHKLAdapter * TangoHKLAdapterFactory::get_diffractometer_adapter(std::string const & diffractometerProxyName)
75 TangoHKLAdapter * adapter = NULL;
77 adapterMap_t::iterator iter = _adapterMap.begin();
78 adapterMap_t::iterator end = _adapterMap.end();
79 while(iter != end) {
80 if (iter->first->get_name() == diffractometerProxyName) {
81 adapter = iter->second;
82 break;
84 ++iter;
87 return adapter;
90 TangoHKLAdapterFactory::~TangoHKLAdapterFactory()
92 if (_instance) {
93 // remove all undeleted devices.
94 adapterMap_t::iterator iter = _adapterMap.begin();
95 adapterMap_t::iterator end = _adapterMap.end();
96 while(iter != end) {
97 delete iter->second;
98 ++iter;
100 _adapterMap.clear();
101 _instance = NULL;