00001 #ifndef PHX_DESCRIPTION_H 00002 #define PHX_DESCRIPTION_H 00003 00004 #include <Phx/PhxConfig.h> 00005 #include <Phx/PhxTypes.h> 00006 00007 #include <Phx/Util/PhxBitVector.h> 00008 #include <Phx/Util/PhxListeners.h> 00009 #include <Phx/Util/PhxXmlDescription.h> 00010 00018 namespace Phx { 00019 00092 class Description : public LockedPtrInterface<Description> { 00093 class TypeClass; 00094 public: 00095 class Manager; 00096 00101 typedef ValueType<TypeClass, uint32_t> Type; 00102 00111 static const Type INVALID_TYPE; 00112 00123 virtual BitVector serializedData(void) const = 0; 00124 00144 virtual void serializedData(const BitVector& serializedData) = 0; 00145 00154 virtual XmlDescriptionNode xmlData(void) const = 0; 00155 00168 virtual void xmlData(const XmlDescriptionNode& xmlNode) = 0; 00169 00178 Type type() const { return mType; } 00179 00180 protected: 00181 Description(void); 00182 // virtual destructor 00183 virtual ~Description() {} 00184 00185 private: 00186 // no assignment 00187 Description& operator=(const Description& rhs); 00188 00189 friend class Manager; 00190 void setType(Type type) { mType = type; } 00191 00192 Type mType; 00193 }; 00194 00195 00205 class Description::Manager : public LockedPtrInterface<Description::Manager> { 00206 template <class T> 00207 class DefaultTypeListener; 00208 00209 public: 00210 00211 // ------------ CREATING DESCRIPTIONS ------------ 00212 00232 virtual Ptr<Description> newDescription(Description::Type type) = 0; 00233 00234 00251 virtual Ptr<Description> newDescription(const Ptr<const Description>& description) = 0; 00252 00253 00271 virtual Ptr<Description> newDescription(const XmlDescriptionNode& node) = 0; 00272 00273 00293 virtual Ptr<const Description> fileDescription(const String& filename) = 0; 00294 00295 00296 // ----------- DESCRIPTION TYPES ----------- 00297 00308 class TypeListener : 00309 public BaseMultiListener<Description::Manager, TypeListener, Description::Type> { 00310 00311 public: 00326 virtual Ptr<Description> onNewDescription(const Ptr<const Description>& description) = 0; 00327 }; 00328 00349 virtual void typeListener(Description::Type type, TypeListener* listener) = 0; 00350 00351 00372 virtual void typeNameType(const String& typeName, Type type) = 0; 00373 00388 virtual Type typeNameType(const String& typeName) const = 0; 00389 00418 template <class T> 00419 Ptr<TypeListener> newDescriptionType() { 00420 Ptr<DefaultTypeListener<T> > typeListenerPtr(new DefaultTypeListener<T>()); 00421 typeListener(T::DESCRIPTION_TYPE, typeListenerPtr.ptr()); 00422 typeNameType(T::DESCRIPTION_TYPE_NAME, T::DESCRIPTION_TYPE); 00423 return typeListenerPtr; 00424 } 00425 00426 00427 // virtual destructor 00428 virtual ~Manager() { } 00429 00430 private: 00431 // A default listener implementation that returns a default 00432 // constructed instance of the template parameter type T. 00433 template <class T> 00434 class DefaultTypeListener : public TypeListener { 00435 virtual Ptr<Description> 00436 onNewDescription(const Ptr<const Description>& description) { 00437 const Ptr<const T> descT = description.dynamicCast<const T>(); 00438 if (!description || descT) { 00439 return Ptr<Description>(new T(descT, notifier())); 00440 } 00441 return 0; 00442 } 00443 }; 00444 }; 00445 00446 }; // namespace Phx 00447 00448 #endif /* PHX_DESCRIPTION_H */
1.4.2