00001 #ifndef PHX_NAMED_INTERFACE_H
00002 #define PHX_NAMED_INTERFACE_H
00003
00004 #include <Phx/PhxConfig.h>
00005 #include <Phx/PhxTypes.h>
00006
00007 #include <Phx/Core/PhxDescription.h>
00008 #include <Phx/Util/PhxLocks.h>
00009
00017 namespace Phx {
00018
00030 class NamedInterface : public LockedPtrInterface<NamedInterface> {
00031 class TypeClass;
00032 class IdentifierClass;
00033
00034 public:
00035 class Manager;
00036
00044 typedef ValueType<TypeClass, uint32_t> Type;
00045
00054 typedef ValueType<IdentifierClass, uint32_t> Identifier;
00055
00059 static const Type INVALID_TYPE;
00060
00064 static const Identifier INVALID_IDENTIFIER;
00065
00086 const Type& type(void) const { return mType; }
00087
00097 const Identifier& identifier(void) const { return mIdentifier; }
00098
00107 const String& name(void) const { return mName; }
00108
00109 protected:
00110
00111
00112 NamedInterface(void);
00113
00114
00115 virtual ~NamedInterface() {}
00116
00117 private:
00118 friend class Manager;
00119
00120
00121 void setType(Type type) { mType = type; }
00122 void setIdentifier(Identifier identifier) { mIdentifier = identifier; }
00123 void setName(const String& name) { mName = name; }
00124
00125 Type mType;
00126 Identifier mIdentifier;
00127 String mName;
00128 };
00129
00140 class NamedInterface::Manager : public LockedPtrInterface<NamedInterface::Manager> {
00141 public:
00142
00143 const static NamedInterface::Type INTERFACE_TYPE;
00144 const static String INTERFACE_TYPE_NAME;
00145
00146
00147
00184 virtual Ptr<NamedInterface> newNamedInterface(NamedInterface::Type interfaceType,
00185 const Ptr<Description>& description,
00186 const String& instanceName,
00187 NamedInterface::Identifier identifier) = 0;
00188
00189
00190 virtual Ptr<NamedInterface> newNamedInterface(NamedInterface::Type interfaceType,
00191 const Ptr<Description>& description,
00192 const String& instanceName) = 0;
00193
00208 virtual Ptr<NamedInterface> namedInterface(NamedInterface::Identifier identifier) const = 0;
00209
00225 virtual Ptr<NamedInterface> namedInterface(const String& name) const = 0;
00226
00263 virtual void deleteNamedInterface(const Ptr<NamedInterface>& interface) = 0;
00264
00265
00266
00271 class TypeListener :
00272 public BaseMultiListener<NamedInterface::Manager, TypeListener, NamedInterface::Type> {
00273 public:
00294 virtual Ptr<NamedInterface> onNewNamedInterface(const Ptr<Description>& constructorData,
00295 const String& instanceName,
00296 NamedInterface::Identifier identifier) = 0;
00297
00309 virtual void onDeleteNamedInterface(const Ptr<NamedInterface>& interface) = 0;
00310 };
00311
00332 virtual void typeListener(NamedInterface::Type type, TypeListener* listener) = 0;
00333
00372 template <class T>
00373 Ptr<TypeListener> newNamedInterfaceType(void) {
00374
00375
00376 Ptr<DefaultTypeListener<T> > typeListenerPtr(new DefaultTypeListener<T>());
00377 typeListener(T::INTERFACE_TYPE, typeListenerPtr.ptr());
00378
00379 try {
00380
00381 if (T::INTERFACE_TYPE_NAME != "") {
00382 typeNameType(T::INTERFACE_TYPE_NAME, T::INTERFACE_TYPE);
00383 }
00384 } catch (...) {
00385
00386 typeListener(T::INTERFACE_TYPE, 0);
00387 throw ;
00388 }
00389
00390 return typeListenerPtr;
00391 }
00392
00410 virtual void typeNameType(const String& typeName, NamedInterface::Type type) = 0;
00411
00426 virtual NamedInterface::Type typeNameType(const String& typeName) const = 0;
00427
00428 protected:
00429
00430 void setNamedInterfaceType(const Ptr<NamedInterface>& interface, NamedInterface::Type type);
00431
00432
00433 void setNamedInterfaceName(const Ptr<NamedInterface>& interface, const String& name);
00434
00435
00436 void setNamedInterfaceIdentifier(const Ptr<NamedInterface>& interface,
00437 NamedInterface::Identifier identifier);
00438
00439 private:
00440
00441
00442 template <class T>
00443 class DefaultTypeListener : public TypeListener {
00444 virtual Ptr<NamedInterface> onNewNamedInterface(const Ptr<Description>& description,
00445 const String& instanceName,
00446 NamedInterface::Identifier identifier) {
00447 const NamedInterface::Manager* mgr = notifier();
00448 return Ptr<NamedInterface>(new T(description, instanceName, identifier, mgr));
00449 }
00450 virtual void onDeleteNamedInterface(const Ptr<NamedInterface>& interface) { }
00451 };
00452 };
00453
00454
00455 };
00456
00457 #endif