44 #ifndef ITER_QUANITY_ACCESS_CONTINUOUS_DEF_H
45 #define ITER_QUANITY_ACCESS_CONTINUOUS_DEF_H
54 namespace IterationPack {
58 template<
class T_info>
61 ,
const std::string& name
66 ,abstract_factory_(abstract_factory)
72 template<
class T_info>
77 template<
class T_info>
83 abstract_factory_ = abstract_factory;
91 template<
class T_info>
94 num_quantities < 1, std::length_error
95 ,
"IterQuantityAccessContiguous::resize(num_quantities): Error, "
96 "name = "<<name_<<
", num_quantities = "<<num_quantities<<
" must be greater than zero" );
97 if( num_quantities_ != num_quantities )
99 num_quantities_ = num_quantities;
105 template<
class T_info>
113 template<
class T_info>
115 return name_.c_str();
118 template<
class T_info>
120 return is_initialized()
121 ? offset >= max_offset_ - num_quantities_ + 1
125 template<
class T_info>
127 if( !is_initialized() )
129 if( ( offset > max_offset_ ) || ( offset < max_offset_ - num_quantities_ + 1 ) )
131 return updated_[max_offset_ - offset];
134 template<
class T_info>
136 if( !is_initialized() )
137 return base_t::NONE_UPDATED;
139 for(
int offset = max_offset_;
140 offset >= max_offset_ - num_quantities_ + 1;
143 if( updated_[max_offset_ - offset] )
146 return base_t::NONE_UPDATED;
149 template<
class T_info>
151 this->assert_updated_k(offset);
152 updated_[max_offset_ - offset] =
false;
155 template<
class T_info>
157 if(!is_initialized())
return;
158 std::fill( updated_.begin(), updated_.end(), false );
161 template<
class T_info>
163 this->assert_updated_k(offset);
164 return set_offset - max_offset_ > num_quantities_ - (max_offset_ - offset) - 1;
167 template<
class T_info>
170 if( !is_initialized() )
return;
174 template<
class T_info>
177 const int last_updated = this->last_updated();
178 if(last_updated != base_t::NONE_UPDATED)
179 out <<
typeName(get_k(last_updated));
180 else if( abstract_factory_.get() == NULL )
183 out << typeName(*abstract_factory_->create());
188 template<
class T_info>
190 this->assert_updated_k(offset);
191 return *quantities_[max_offset_ - offset];
193 template<
class T_info>
195 this->assert_updated_k(offset);
196 return *quantities_[max_offset_ - offset];
199 template<
class T_info>
202 lazy_initialization();
204 this->assert_has_storage_k(offset);
206 if(offset > max_offset_ + num_quantities_ - 1) {
208 max_offset_ = offset;
209 std::fill(updated_.begin(), updated_.end(),
false);
213 if(offset > max_offset_) {
215 int shifted = offset - max_offset_;
225 itr_updated_from = updated_.begin(),
226 itr_updated_from_end = itr_updated_from + num_quantities_ - shifted,
227 itr_updated_to = itr_updated_from + shifted;
229 std::copy(itr_updated_from, itr_updated_from_end, itr_updated_to);
232 std::fill_n( updated_.begin(), shifted, false );
242 #if defined(_INTEL_CXX)
243 typedef std::reverse_iterator<T_info**, T_info*, T_info*&
244 , T_info**, ptrdiff_t> rev_t;
246 typedef std::reverse_iterator<T_info**> rev_t;
250 rev_t(&quantities_[0] + num_quantities_)
251 , rev_t(&quantities_[0] + num_quantities_ - shifted)
252 , rev_t(&quantities_[0]) );
254 max_offset_ = offset;
260 updated_[max_offset_ - offset] =
true;
261 return *quantities_[max_offset_ - offset];
264 template<
class T_info>
266 T_info& iq = this->get_k(get_offset);
267 return this->set_k(set_offset) = iq;
272 template<
class T_info>
274 return store_.size() > 0;
277 template<
class T_info>
279 if( !is_initialized() ) {
281 abstract_factory_.get() == NULL, std::logic_error
282 ,
"IterQuantityAccessContiguous::lazy_initialization(): Error, "
283 "iq_name = "<<name_<<
" the abstract factory can not be NULL" );
285 updated_.resize(num_quantities_,
false);
286 store_.resize(num_quantities_);
287 quantities_.resize(num_quantities_,NULL);
289 typename updated_t::iterator itr_updated = updated_.begin();
290 typename store_t::iterator itr_store = store_.begin();
291 typename quantities_t::iterator itr_quantities = quantities_.begin();
292 for( ; itr_store != store_.end(); ++itr_updated, ++itr_store, ++itr_quantities )
294 *itr_updated =
false;
295 *itr_store = abstract_factory_->create();
296 *itr_quantities = itr_store->get();
302 template<
class T_info>
306 quantities_.resize(0);
311 #endif // ITER_QUANITY_ACCESS_CONTINUOUS_DEF_H
void lazy_initialization()
void resize(int num_quantities)
Resize the number of contiguous storage locations.
std::string typeName(const T &t)
IterQuantityAccessContiguous()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_info & set_k(int offset)
void set_factory(const abstract_factory_ptr_t &abstract_factory)
Set the abstract factory to use to allocate storate.
bool will_loose_mem(int offset, int set_offset) const
void set_all_not_updated()
bool updated_k(int offset) const
void set_not_updated_k(int offset)
Iterface for information about Iteration Quantities.
bool is_initialized() const
bool has_storage_k(int offset) const
void copy(const f_int &N, const f_dbl_prec *X, const f_int &INCX, f_dbl_prec *Y, const f_int &INCY)
void print_concrete_type(std::ostream &out) const
const char * name() const
~IterQuantityAccessContiguous()
IterQuantity * clone() const
T_info & get_k(int offset)