coherence/lang/SmartMember.hpp

00001 /*
00002 * SmartMember.hpp
00003 *
00004 * Copyright 2001-2008 by Oracle. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_SMART_MEMBER_HPP
00017 #define COH_SMART_MEMBER_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/Object.hpp"
00022 
00023 COH_OPEN_NAMESPACE2(coherence,lang)
00024 
00025 
00026 /**
00027 * Base class for smart data-members of managed Objects.
00028 *
00029 * Smart data-members include additional information regarding their
00030 * life-cycle, including a reference to their enclosing Object (parent). The
00031 * smart member is initalized with a reference to its parent, and has the same
00032 * life-cycle as the parent. Creating a SmartMember which is not a data-member
00033 * of the parent used during initialization will result in unsafe/undefined
00034 * behavior.
00035 *
00036 * @author mf 2008.01.30
00037 */
00038 class COH_EXPORT SmartMember
00039     {
00040     // ----- constructor ----------------------------------------------------
00041 
00042     public:
00043         /**
00044         * Construct a new SmartMember
00045         *
00046         * @param oParent  the data-member's parent Object.
00047         */
00048         SmartMember(Object& oParent);
00049 
00050         /**
00051         * Destruct the SmartMember.
00052         */
00053         virtual ~SmartMember();
00054 
00055     protected:
00056         /**
00057         * Construct an orphaned SmartMember.
00058         *
00059         * The smart-member will not be usable until a parent is assigned.
00060         *
00061         * @see #setParent()
00062         */
00063         SmartMember();
00064 
00065     private:
00066         /**
00067         * Blocked copy constructor.
00068         */
00069         SmartMember(const SmartMember&);
00070 
00071 
00072     // ----- operators ------------------------------------------------------
00073 
00074     public:
00075         SmartMember& operator=(const SmartMember& that);
00076 
00077 
00078     // ----- SmartMember interface ------------------------------------------
00079 
00080     public:
00081         /**
00082         * Return the parent Object for this data member.
00083         *
00084         * @return the parent Object for this data member.
00085         */
00086         Object& getParent();
00087 
00088         /**
00089         * Return the parent Object for this data member.
00090         *
00091         * @return the parent Object for this data member.
00092         */
00093         const Object& getParent() const;
00094 
00095     protected:
00096         /**
00097         * Set the parent for this member.
00098         *
00099         * @throws IllegalStateException if a parent has already been
00100         *                               specified
00101         */
00102         void setParent(Object& oParent);
00103 
00104 
00105     // ----- life cycle events ----------------------------------------------
00106 
00107     protected:
00108         /**
00109         * Event called once the parent Object has finished being constructed.
00110         * Specifically when the first attachment is made.
00111         *
00112         * As with all event methods any derived implementation should
00113         * include a call to the super class's implementation.
00114         *
00115         * The default implmenetation calls the onInit() method of each of the
00116         * Object's SmartMembers.
00117         */
00118         virtual void onInit();
00119 
00120         /**
00121         * Event called when the parent Object becomes only referenced via
00122         * const pointers (Views). As the SmartMember is a data-member
00123         * of this Object, the data-member infer that only const methods will
00124         * be called from now on.
00125         *
00126         * Derived implementations of this method should include a delegation
00127         * call to their super class onConst() method, after they've done
00128         * their own processing of the event.
00129         */
00130         virtual void onConst();
00131 
00132 
00133     // ----- data members ---------------------------------------------------
00134 
00135     private:
00136         /**
00137         * The Membe's parent.
00138         */
00139         Object* m_pParent;
00140 
00141         /**
00142         * The next SmartMember in the parent's SmartMember stack.
00143         */
00144         SmartMember* m_pNext;
00145 
00146 
00147     // ----- friends --------------------------------------------------------
00148 
00149     friend class Object;
00150     friend class SynchronizedMemberBlock;
00151     };
00152 
00153 COH_CLOSE_NAMESPACE2
00154 
00155 #endif // COH_SMART_MEMBER_HPP
Copyright (c) 2000-2008 Oracle. All rights reserved.