00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 template <typename T>
00044 scv_extensions<T> scv_get_extensions(T& d) {
00045 scv_extensions<T> e;
00046 e._set_instance(&d);
00047 return e;
00048 };
00049
00050 template <typename T>
00051 const scv_extensions<T> scv_get_const_extensions(const T& d) {
00052 scv_extensions<T> e;
00053 e._set_instance((T*)&d);
00054 return e;
00055 };
00056
00057
00058
00059
00060 extern void _scv_insert_smart_ptr(scv_smart_ptr_if *);
00061
00062 template <typename T> scv_smart_ptr<T>::scv_smart_ptr()
00063 : data_(new T()),
00064 ext_(new scv_extensions<T>()),
00065 tmp_(&*ext_) {
00066 ext_->_set_instance(&*data_);
00067 init();
00068 }
00069
00070 template <typename T>
00071 scv_smart_ptr<T>::scv_smart_ptr(const string& name)
00072 : data_(new T()),
00073 ext_(new scv_extensions<T>()),
00074 tmp_(&*ext_) {
00075 ext_->_set_instance(&*data_);
00076 ext_->set_name(name.c_str());
00077 init();
00078 }
00079
00080 template <typename T>
00081 scv_smart_ptr<T>::scv_smart_ptr(const sc_string& name)
00082 : data_(new T()),
00083 ext_(new scv_extensions<T>()),
00084 tmp_(&*ext_) {
00085 ext_->_set_instance(&*data_);
00086 ext_->set_name(name.c_str());
00087 init();
00088 }
00089
00090 template <typename T>
00091 scv_smart_ptr<T>::scv_smart_ptr(const char * name)
00092 : data_(new T()),
00093 ext_(new scv_extensions<T>()),
00094 tmp_(&*ext_) {
00095 ext_->_set_instance(&*data_);
00096 ext_->set_name(name);
00097 init();
00098 }
00099
00100 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data)
00101 : data_(data),
00102 ext_(new scv_extensions<T>()),
00103 tmp_(&*ext_) {
00104 ext_->_set_instance(data);
00105 init();
00106 }
00107
00108 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data, const string& name)
00109 : data_(data),
00110 ext_(new scv_extensions<T>()),
00111 tmp_(&*ext_) {
00112 ext_->_set_instance(data);
00113 ext_->set_name(name.c_str());
00114 init();
00115 }
00116
00117 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data, const sc_string& name)
00118 : data_(data),
00119 ext_(new scv_extensions<T>()),
00120 tmp_(&*ext_) {
00121 ext_->_set_instance(data);
00122 ext_->set_name(name.c_str());
00123 init();
00124 }
00125
00126 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(T * data, const char * name)
00127 : data_(data),
00128 ext_(new scv_extensions<T>()),
00129 tmp_(&*ext_) {
00130 ext_->_set_instance(data);
00131 ext_->set_name(name);
00132 init();
00133 }
00134
00135 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(const scv_smart_ptr<T>& rhs)
00136 : data_(rhs.data_), ext_(rhs.ext_), tmp_(&*ext_) {
00137 }
00138
00139 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(
00140 scv_shared_ptr<T> data,
00141 scv_shared_ptr< scv_extensions<T> > ext,
00142 scv_extensions<T> *tmp
00143 ) : data_(data), ext_(ext), tmp_(tmp)
00144 { init(); }
00145
00146 void _scv_constraint_wrapup(scv_extensions_if* e);
00147
00148 template <typename T> scv_smart_ptr<T>::~scv_smart_ptr() {
00149 #ifndef _SCV_INTROSPECTION_ONLY
00150
00151 #endif
00152 }
00153
00154 template <typename T> void scv_smart_ptr<T>::init() {
00155 ext_->_set_dynamic();
00156 #ifndef _SCV_INTROSPECTION_ONLY
00157 ::_scv_insert_smart_ptr(this);
00158 #endif
00159 }
00160
00161 template <typename T> scv_smart_ptr<T>&
00162 scv_smart_ptr<T>::operator=(const scv_smart_ptr<T>& rhs) {
00163 data_ = rhs.data_;
00164 ext_ = rhs.ext_;
00165 tmp_ = rhs.tmp_;
00166 return *this;
00167 }
00168
00169 template<typename T> scv_extensions<T*>&
00170 scv_extensions<T*>::operator=(const scv_smart_ptr<T>& rhs) {
00171 *this->_get_instance() = (T*) rhs->_get_instance();
00172 if (rhs->is_dynamic()) {
00173
00174
00175
00176 this->_own_typed_ptr = false;
00177 this->_ptr = (scv_extensions<T>*) &*rhs;
00178 this->_typed_ptr = (scv_extensions<T>*) &*rhs;
00179 }
00180 _set_ptr();
00181 this->trigger_value_change_cb();
00182 return *this;
00183 }
00184
00185 template <typename T> scv_smart_ptr<T>::scv_smart_ptr(scv_shared_ptr<T> data)
00186 : data_(data), ext_(new scv_extensions<T>()), tmp_(&*ext_) {
00187 _scv_message::message(_scv_message::INTERNAL_ERROR,"scv_smart_ptr(scv_shared_ptr) should not be called.");
00188 ext_->_set_instance(&*data_);
00189 init();
00190 }
00191
00192
00193
00194
00195 template<typename T>
00196 class scv_extensions< scv_smart_ptr<T> > : public scv_extensions<T*> {
00197 public:
00198 scv_extensions() {}
00199 scv_extensions(const scv_extensions<T*>& rhs) : scv_extensions<T*>(rhs) {}
00200 virtual ~scv_extensions() {}
00201 scv_extensions& operator=(const scv_extensions<T*>& rhs) {
00202 return scv_extensions<T*>::operator=(rhs);
00203 }
00204 scv_extensions& operator=(const T * rhs) {
00205 return scv_extensions<T*>::operator=(rhs);
00206 }
00207 operator const T *() const { return *scv_extensions<T*>::_get_instance(); }
00208 scv_expression operator()() { return scv_extensions<T*>::form_expression(); }
00209
00210 virtual void _set_instance(T ** i) {
00211 scv_extensions<T*>::_set_instance(i);
00212 }
00213 virtual void _set_instance(scv_smart_ptr<T> * i) {
00214 scv_extensions<T*>::_set_instance(i->get_extension_ptr()->_get_instance());
00215 }
00216 };