00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef COH_FINAL_VIEW_HPP
00017 #define COH_FINAL_VIEW_HPP
00018
00019 #include "coherence/lang/compatibility.hpp"
00020
00021 #include "coherence/lang/MemberView.hpp"
00022 #include "coherence/lang/TypedHandle.hpp"
00023
00024 COH_OPEN_NAMESPACE2(coherence,lang)
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 template<class T>
00036 class FinalView
00037 : public MemberView<T>
00038 {
00039
00040
00041 public:
00042
00043
00044
00045 typedef T ValueType;
00046
00047
00048
00049
00050 typedef typename T::View ValueView;
00051
00052
00053
00054
00055 public:
00056
00057
00058
00059
00060
00061 FinalView(const Object& oGuardian)
00062 : MemberView<T>(oGuardian)
00063 {
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 FinalView(const Object& oGuardian, const ValueView& that)
00073 : MemberView<T>(oGuardian, that)
00074 {
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 FinalView(const Object& oGuardian, const ValueView& that, bool fMutable)
00086 : MemberView<T>(oGuardian, that, fMutable)
00087 {
00088 }
00089
00090
00091
00092
00093 public:
00094
00095
00096
00097
00098
00099 operator ValueView() const
00100 {
00101 return ValueView(MemberView<T>::m_cpo);
00102 }
00103
00104
00105
00106
00107
00108
00109 template<class PT>
00110 operator TypedHandle<const PT>() const
00111 {
00112 return MemberView<T>::m_cpo;
00113 }
00114
00115
00116
00117
00118
00119
00120 template<class PT>
00121 operator TypedHolder<PT>() const
00122 {
00123 return ValueView(MemberView<T>::m_cpo);
00124 }
00125
00126
00127
00128
00129
00130
00131 const T* operator->() const
00132 {
00133 const T* cpo = MemberView<T>::m_cpo;
00134 if (NULL == cpo)
00135 {
00136 coh_throw_npe(typeid(const T));
00137 }
00138 return cpo;
00139 }
00140
00141 private:
00142
00143
00144
00145 FinalView& operator=(const ValueView& that);
00146
00147
00148
00149
00150 FinalView& operator=(const FinalView<T>& that);
00151
00152
00153
00154
00155 protected:
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 void initialize(ValueView that)
00169 {
00170 if (MemberView<T>::m_cpo != NULL)
00171 {
00172 coh_throw_illegal_state(
00173 "attempt to multiply initialize FinalView");
00174 }
00175 if (MemberView<T>::getGuardian()._isEscaped())
00176 {
00177 coh_throw_illegal_state(
00178 "attempt to initialize FinalView after it has escaped");
00179 }
00180 if (MemberView<T>::m_nMutability >= MemberView<T>::forever_immutable)
00181 {
00182 coh_throw_illegal_state(
00183 "attempt to initialize const FinalView");
00184 }
00185
00186 const T* cpo = get_pointer(that);
00187 MemberView<T>::m_cpo =
00188 NULL == cpo || NULL == cpo->_attach( false) ? NULL : cpo;
00189 }
00190
00191
00192
00193
00194
00195
00196 template<class _T, class V> friend void initialize(FinalView<_T>& fh,
00197 V that);
00198 };
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 template<class D, class T>
00212 D cast(const FinalView<T>& v, bool fThrow = true)
00213 {
00214 return cast<D>((typename FinalView<T>::ValueView) v, fThrow);
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224 template<class D, class T>
00225 bool instanceof(const FinalView<T>& v)
00226 {
00227 return NULL != cast<D>(v, false);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 template<class T, class V>
00245 void initialize(FinalView<T>& h, V that)
00246 {
00247 h.initialize(that);
00248 }
00249
00250
00251 COH_CLOSE_NAMESPACE2
00252
00253 #endif // COH_FINAL_VIEW_HPP