poly_sequence_model.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /******************************************************************************/ 00008 00009 #ifndef ADOBE_POLY_SEQUENCE_MODEL_HPP 00010 #define ADOBE_POLY_SEQUENCE_MODEL_HPP 00011 00012 /******************************************************************************/ 00013 00014 #include <boost/concept_check.hpp> 00015 00016 #include <adobe/sequence_model_fwd.hpp> 00017 #include <adobe/poly.hpp> 00018 #include <adobe/vector.hpp> 00019 00020 /******************************************************************************/ 00021 00022 namespace adobe { 00023 00024 /******************************************************************************/ 00034 /******************************************************************************/ 00040 template <class SequenceModel> 00041 struct sequence_model_value_type 00042 { 00043 typedef typename SequenceModel::value_type type; 00044 }; 00045 00051 template <class SequenceModel> 00052 struct sequence_model_key_type 00053 { 00054 typedef typename SequenceModel::key_type type; 00055 }; 00056 00057 /******************************************************************************/ 00063 template <class SM> // SM models SequenceModel 00064 inline void push_back(SM& v, 00065 const typename sequence_model_value_type<SM>::type& x) 00066 { v.push_back(x); } 00067 00073 template <class SM> // SM models SequenceModel 00074 inline void set(SM& v, 00075 typename sequence_model_key_type<SM>::type key, 00076 const typename sequence_model_value_type<SM>::type& x) 00077 { v.set(key, x); } 00078 00084 template <class SM> // SM models SequenceModel 00085 inline void insert_set(SM& v, 00086 typename sequence_model_key_type<SM>::type before, 00087 const vector<typename sequence_model_value_type<SM>::type>& x) 00088 { v.insert_set(before, x); } 00089 00095 template <class SM> // SM models SequenceModel 00096 inline void insert(SM& v, 00097 typename sequence_model_key_type<SM>::type before, 00098 const typename sequence_model_value_type<SM>::type& x) 00099 { v.insert(before, x); } 00100 00106 template <class SM> // SM models SequenceModel 00107 inline void sequence_model_erase(SM& v, 00108 const vector<typename sequence_model_key_type<SM>::type>& x) 00109 { v.erase(x); } 00110 00116 template <class SM> // SM models SequenceModel 00117 inline void sequence_model_clear(SM& v) 00118 { v.clear(); } 00119 00120 /******************************************************************************/ 00126 template <class SequenceModel> 00127 struct SequenceModelConcept 00128 { 00130 typedef typename sequence_model_value_type<SequenceModel>::type value_type; 00131 typedef typename sequence_model_key_type<SequenceModel>::type key_type; 00132 00134 void constraints() 00135 { 00136 push_back(*model, *value); 00137 set(*model, *key, *value); 00138 insert_set(*model, *key, *value_set); 00139 insert(*model, *key, *value); 00140 sequence_model_erase(*model, *key_set); 00141 sequence_model_clear(*model); 00142 } 00143 00144 static void push_back(SequenceModel& model, const value_type& x) 00145 { 00146 using adobe::push_back; 00147 00148 push_back(model, x); 00149 } 00150 00151 static void set(SequenceModel& model, key_type key, const value_type& x) 00152 { 00153 using adobe::set; 00154 00155 set(model, key, x); 00156 } 00157 00158 static void insert_set(SequenceModel& model, key_type before, const vector<value_type>& x) 00159 { 00160 using adobe::insert_set; 00161 00162 insert_set(model, before, x); 00163 } 00164 00165 static void insert(SequenceModel& model, key_type before, const value_type& x) 00166 { 00167 using adobe::insert; 00168 00169 insert(model, before, x); 00170 } 00171 00172 static void erase(SequenceModel& model, const vector<key_type>& x) 00173 { 00174 using adobe::sequence_model_erase; 00175 00176 sequence_model_erase(model, x); 00177 } 00178 00179 static void clear(SequenceModel& model) 00180 { 00181 using adobe::sequence_model_clear; 00182 00183 sequence_model_clear(model); 00184 } 00185 00186 #ifndef ADOBE_NO_DOCUMENTATION 00187 SequenceModel* model; 00188 key_type* key; 00189 value_type* value; 00190 vector<value_type>* value_set; 00191 vector<key_type>* key_set; 00192 #endif 00193 }; 00194 00195 /******************************************************************************/ 00200 template <class T> 00201 struct SequenceModelConcept<boost::reference_wrapper<T> > : SequenceModelConcept<T> 00202 { 00203 void constraints() { 00204 //boost concept check lib gets confused on VC8 without this 00205 SequenceModelConcept<T>::constraints(); 00206 } 00207 }; 00208 00209 /******************************************************************************/ 00210 #if 0 00211 #pragma mark - 00212 #endif 00213 /******************************************************************************/ 00219 template <typename T> 00220 struct poly_sequence_model_interface : poly_copyable_interface 00221 { 00222 virtual void push_back(const T& x) = 0; 00223 00224 virtual void set(sequence_key<T> key, const T& value) = 0; 00225 00226 virtual void insert_set(sequence_key<T> before, const vector<T>& value_set) = 0; 00227 00228 virtual void insert(sequence_key<T> before, const T& value) = 0; 00229 00230 virtual void erase(const vector<sequence_key<T> >& key_set) = 0; 00231 00232 virtual void clear() = 0; 00233 }; 00234 00235 /******************************************************************************/ 00241 template <typename T> 00242 struct poly_sequence_model_instance 00243 { 00244 template <typename V> 00245 struct type : optimized_storage_type<V, poly_sequence_model_interface<T> >::type 00246 { 00247 typedef typename optimized_storage_type<V, poly_sequence_model_interface<T> >::type base_t; 00248 00249 BOOST_CLASS_REQUIRE(V, adobe, SequenceModelConcept); 00250 00251 explicit type(const V& x) : 00252 base_t(x) 00253 { } 00254 00255 type(move_from<type> x) : 00256 base_t(move_from<base_t>(x.source)) 00257 { } 00258 00259 void push_back(const T& x) 00260 { SequenceModelConcept<V>::push_back(this->get(), x); } 00261 00262 void set(sequence_key<T> key, const T& x) 00263 { SequenceModelConcept<V>::set(this->get(), key, x); } 00264 00265 void insert_set(sequence_key<T> before, const vector<T>& value_set) 00266 { SequenceModelConcept<V>::insert_set(this->get(), before, value_set); } 00267 00268 void insert(sequence_key<T> before, const T& x) 00269 { SequenceModelConcept<V>::insert(this->get(), before, x); } 00270 00271 void erase(const vector<sequence_key<T> >& key_set) 00272 { SequenceModelConcept<V>::erase(this->get(), key_set); } 00273 00274 void clear() 00275 { SequenceModelConcept<V>::clear(this->get()); } 00276 }; 00277 }; 00278 00279 /******************************************************************************/ 00285 template <typename T> 00286 struct sequence_model_base : poly_base<poly_sequence_model_interface<T>, 00287 poly_sequence_model_instance<T>::template type> 00288 { 00289 typedef poly_base<poly_sequence_model_interface<T>, 00290 poly_sequence_model_instance<T>::template type> base_t; 00291 00292 template <typename V> 00293 explicit sequence_model_base(const V& s) : 00294 base_t(s) 00295 { } 00296 00297 sequence_model_base(move_from<sequence_model_base> x) : 00298 base_t(move_from<base_t>(x.source)) 00299 { } 00300 00301 void push_back(const T& x) 00302 { this->interface_ref().push_back(x); } 00303 00304 void set(sequence_key<T> key, const T& x) 00305 { this->interface_ref().set(key, x); } 00306 00307 void insert_set(sequence_key<T> before, const vector<T>& value_set) 00308 { this->interface_ref().insert_set(before, value_set); } 00309 00310 void insert(sequence_key<T> before, const T& x) 00311 { this->interface_ref().insert(before, x); } 00312 00313 void erase(const vector<sequence_key<T> >& key_set) 00314 { this->interface_ref().erase(key_set); } 00315 00316 void clear() 00317 { this->interface_ref().clear(); } 00318 }; 00319 00320 /******************************************************************************/ 00321 00322 template <typename T> 00323 struct poly_sequence_model 00324 { 00325 typedef poly< sequence_model_base<T> > type; 00326 }; 00327 00328 /******************************************************************************/ 00329 00330 } // namespace adobe 00331 00332 /******************************************************************************/ 00333 00334 // ADOBE_POLY_SEQUENCE_MODEL_HPP 00335 #endif 00336 00337 /******************************************************************************/ |