Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

composition_object.hpp

Go to the documentation of this file.
00001 //
00002 // See license.txt for license information.
00003 //
00004 // composition_object.hpp
00005 //
00006 // 17-Jul-2003  phamilton  Created
00007 //
00008 
00009 #ifndef incCOMMON_COMPOSITION_OBJECT
00010 #define incCOMMON_COMPOSITION_OBJECT
00011 
00012 namespace ph {
00013 namespace common {
00014 
00015 class composite_object_base;
00016 
00017 class composition_object_base
00018 /**
00019         Abstract class representing a component object for composition.
00020         
00021         This class is the "Component" in the "Composite" pattern.
00022 */
00023 {
00024 public:
00025         virtual ~composition_object_base() {}
00026         
00027         // composite pattern
00028         virtual composite_object_base *composite()
00029                 { return 0; }
00030         virtual const composite_object_base *composite() const
00031                 { return 0; }
00032 };
00033 
00034 class composite_object_base : public composition_object_base
00035 /**
00036         Abstract class representing a composite object.
00037 
00038         This class is the "Composite" in the "Composite" pattern.
00039 */
00040 {
00041 public:
00042         virtual bool add(object_base *obj, bool owned) = 0;
00043                 //!< Add a new object to the composite object.
00044                 //! The client passes in their understanding of the 
00045                 //! ownership policy to make sure that it fits in with
00046                 //! the composites ownership. If they don't match, then
00047                 //! the object won't be added, and the client can take
00048                 //! appropriate action.
00049 
00050         virtual bool remove(object_base *obj) = 0;
00051                 //!< Remove and object from the composite.
00052                 //! Objects which are removed are not subject
00053                 //! to the ownership policy of the composite, since
00054                 //! they are simply forgotten by it.
00055                 
00056         virtual bool owned() const { return true; }
00057         virtual void owned(bool owned) { }
00058                 //!< Return true of the collection is owned.
00059                 //! normally this means that when the composite is deleted,
00060                 //! the objects it contains are deleted with it, but on
00061                 //! in a more complex system (which would need to 
00062                 //! provide the ability to clone objects), this 
00063                 //! could be used to provide owned/non-owned composites.
00064                 
00065         virtual bool singleton() const = 0;
00066                 //!< If the composite can only hold one value (so a second add() will
00067                 //! fail for example), then this returns true. It is used
00068                 //! when reflecting through composites to prevent subscripts
00069                 //! being required.
00070 
00071         virtual int count() const = 0;
00072                 //!< Return the number of objects contained in this
00073                 //! composite object.
00074                 
00075         // composite pattern
00076         virtual composite_object_base *composite()
00077                 { return this; }
00078         virtual const composite_object_base *composite() const
00079                 { return this; }
00080 };
00081 
00082 }; // common
00083 }; // ph
00084 
00085 #endif // incCOMMON_COMPOSITION_OBJECT

Generated on Wed Apr 5 22:03:23 2006 for cppxmlobj by  doxygen 1.4.3