ALBA
albaInteractionFactory.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaInteractionFactory
5 Authors: Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16#ifndef __albaInteractionFactory_h
17#define __albaInteractionFactory_h
18//----------------------------------------------------------------------------
19// includes :
20//----------------------------------------------------------------------------
21#include "albaObjectFactory.h"
22#include "albaConfigure.h"
23#include <set>
24
26#define albaPlugDeviceMacro(node_type,descr) \
27 RegisterNewDevice(node_type::GetStaticTypeName(), descr, node_type::NewObject);
28
30#define albaPlugAvatarMacro(node_type,descr) \
31 RegisterNewAvatar(node_type::GetStaticTypeName(), descr, node_type::NewObject);
32
33//----------------------------------------------------------------------------
34// forward declarations :
35//----------------------------------------------------------------------------
36class albaAvatar;
37class albaDevice;
38
43class ALBA_EXPORT albaInteractionFactory : public albaObjectFactory
44{
45public:
47 virtual const char* GetALBASourceVersion() const;
48 virtual const char* GetDescription() const;
49
50 /* Initialize the factory creating and registering a new instance */
51 static int Initialize();
52
54 static albaInteractionFactory *GetInstance();// {if (!m_Instance) Initialize(); return m_Instance;}
55
57 static albaDevice *CreateDeviceInstance(const char *type_name);
58
61 void RegisterNewDevice(const char* node_name, const char* description, albaCreateObjectFunction createFunction);
62
64 const static std::set<std::string> *GetDeviceNames();
65
67 const char *GetDeviceName(int idx);
68
71
73 const char *GetDeviceTypeName(const char *device_name);
74
76 static albaAvatar *CreateAvatarInstance(const char *type_name);
77
80 void RegisterNewAvatar(const char* node_name, const char* description, albaCreateObjectFunction createFunction);
81
83 const static std::set<std::string> *GetAvatarNames();
84
87
89 const char *GetAvatarName(int idx);
90
92 const char *GetAvatarDescription(const char *device_name);
93
94protected:
97
98 static bool m_Initialized;
99 //static albaInteractionFactory *m_Instance;
100 static std::set<std::string> m_DeviceNames;
101 static std::set<std::string> m_AvatarNames;
102
103private:
104 albaInteractionFactory(const albaInteractionFactory&); // Not implemented.
105 void operator=(const albaInteractionFactory&); // Not implemented.
106};
107
109template <class T>
111{
112 public:
113 albaPlugAvatar(const char *description);
114
115};
116
117//------------------------------------------------------------------------------
119template <class T>
120albaPlugAvatar<T>::albaPlugAvatar(const char *description)
121//------------------------------------------------------------------------------
122{
124 if (factory)
125 {
126 factory->RegisterNewAvatar(T::GetStaticTypeName(), description, T::NewObject);
127 }
128}
129
131template <class T>
133{
134 public:
135 albaPlugDevice(const char *description);
136
137};
138
139//------------------------------------------------------------------------------
141template <class T>
142albaPlugDevice<T>::albaPlugDevice(const char *description)
143//------------------------------------------------------------------------------
144{
146 if (factory)
147 {
148 factory->RegisterNewDevice(T::GetStaticTypeName(), description, T::NewObject);
149 }
150}
151
152#endif
albaObject *(* albaCreateObjectFunction)()
Avatars are entities moving in the virtual world according to user's movements, and thus representing...
Definition: albaAvatar.h:48
This abstract class manages function calls coming from devices and issue specific events to interacto...
Definition: albaDevice.h:40
Object factory for Devices and Avatars.
int GetNumberOfAvatars()
return number of devices registered to this factory
int GetNumberOfDevices()
return number of devices registered to this factory
void RegisterNewDevice(const char *node_name, const char *description, albaCreateObjectFunction createFunction)
This function can be used by Application code to register new Objects's to the mflCoreFactory.
static albaInteractionFactory * GetInstance()
return the instance pointer of the factory.
static std::set< std::string > m_AvatarNames
static const std::set< std::string > * GetDeviceNames()
return list of names for nodes plugged into this factory
static std::set< std::string > m_DeviceNames
void RegisterNewAvatar(const char *node_name, const char *description, albaCreateObjectFunction createFunction)
This function can be used by Application code to register new Objects's to the mflCoreFactory.
const char * GetAvatarName(int idx)
return device name
static const std::set< std::string > * GetAvatarNames()
return list of names for nodes plugged into this factory
const char * GetDeviceTypeName(const char *device_name)
return the comment field of the device object plugged in the factory
static int Initialize()
albaTypeMacro(albaInteractionFactory, albaObjectFactory)
virtual const char * GetALBASourceVersion() const
All sub-classes of albaObjectFactory should must return the version of ALBA they were built with.
virtual const char * GetDescription() const
Return a descriptive string describing the factory.
static albaAvatar * CreateAvatarInstance(const char *type_name)
create an instance of the node give its type name
const char * GetDeviceName(int idx)
return device name
static albaDevice * CreateDeviceInstance(const char *type_name)
create an instance of the node give its type name
const char * GetAvatarDescription(const char *device_name)
return the comment field of the avatar object plugged in the factory
Create instances of classes using an object factory.
Plug a node in the main ALBA Avatar factory.
albaPlugAvatar(const char *description)
Plug a new Avatar class into the Avatar factory.
Plug a node in the main ALBA Device factory.
albaPlugDevice(const char *description)
Plug a new Device class into the Device factory.