27 #ifndef SC_VECTOR_H_INCLUDED_
28 #define SC_VECTOR_H_INCLUDED_
36 #include "sysc/packages/boost/config.hpp"
37 #include "sysc/packages/boost/utility/enable_if.hpp"
44 using ::sc_boost::enable_if;
50 template<
typename T,
typename U >
52 template<
typename T >
55 template<
typename T >
57 template<
typename T >
60 template<
typename CT,
typename T >
71 template<
typename T >
75 #define SC_RPTYPE_(Type) \
76 typename ::sc_core::sc_meta::remove_special_fptr \
77 < ::sc_core::sc_meta::special_result& (*) Type >::type
79 #define SC_ENABLE_IF_( Cond ) \
80 typename ::sc_core::sc_meta::enable_if \
81 < SC_RPTYPE_(Cond) >::type * = NULL
91 template<
typename Container,
typename ArgumentIterator >
92 typename Container::iterator
94 , ArgumentIterator first
95 , ArgumentIterator last
96 ,
typename Container::iterator from );
99 template<
typename Container,
typename ArgumentIterator >
100 typename Container::iterator
102 , ArgumentIterator first
103 , ArgumentIterator last
104 ,
typename Container::iterator from );
119 const char *
kind()
const {
return "sc_vector"; }
124 {
return vec_.size(); }
142 {
delete objs_vec_; }
157 { vec_.push_back(item); }
181 mutable std::vector< sc_object* >* objs_vec_;
190 template<
typename ElementType >
216 template<
typename ElementType
217 ,
typename AccessType >
244 {
return &(this_->*ptr_); }
251 template<
typename ElementType
252 ,
typename AccessPolicy = sc_direct_access<ElementType> >
254 :
public std::iterator< std::random_access_iterator_tag
255 , typename AccessPolicy::type >
256 ,
private AccessPolicy
258 typedef ElementType element_type;
259 typedef typename AccessPolicy::policy access_policy;
260 typedef typename AccessPolicy::non_const_policy non_const_policy;
261 typedef typename AccessPolicy::const_policy const_policy;
262 typedef typename access_policy::type access_type;
264 typedef typename sc_meta::remove_const<ElementType>::type plain_type;
265 typedef const plain_type const_plain_type;
271 typedef std::iterator< std::random_access_iterator_tag, access_type > base_type;
277 template<
typename U >
struct select_iter
278 {
typedef typename storage_type::iterator type; };
279 template<
typename U >
struct select_iter< const U >
280 {
typedef typename storage_type::const_iterator type; };
282 typedef typename select_iter<ElementType>::type raw_iterator;
283 typedef sc_vector_iter< const_plain_type, const_policy > const_iterator;
289 sc_vector_iter( raw_iterator it, access_policy acc = access_policy() )
290 : access_policy(acc), it_(it) {}
292 access_policy
const & get_policy()
const {
return *
this; }
305 template<
typename OtherElement,
typename OtherPolicy >
309 ,
typename OtherPolicy::element_type >
312 : access_policy( it.get_policy() ), it_( it.it_ )
323 {
return this_type( it_ + n, get_policy()); }
325 {
return this_type( it_ - n, get_policy()); }
340 {
return *access_policy::get( static_cast<element_type*>(*it_) ); }
342 {
return access_policy::get( static_cast<element_type*>(*it_) ); }
344 {
return *access_policy::get( static_cast<element_type*>(it_[n]) ); }
348 {
return it_-that.it_; }
352 template<
typename T >
354 :
public sc_vector_base
357 typedef sc_vector<T> this_type;
374 template<
typename Creator >
398 template<
typename Creator >
412 template<
typename ContainerType,
typename ArgumentType >
416 template<
typename BindableContainer >
418 {
return bind( c.begin(), c.end() ); }
420 template<
typename BindableIterator >
422 {
return bind( first, last, this->
begin() ); }
424 template<
typename BindableIterator >
429 template<
typename ContainerType,
typename ArgumentType >
433 template<
typename ArgumentContainer >
437 template<
typename ArgumentIterator >
441 template<
typename ArgumentIterator >
448 template<
typename MT >
461 template<
typename T,
typename MT >
462 class sc_vector_assembly
488 const char*
kind()
const {
return "sc_vector_assembly"; }
491 {
return iterator( (*vec_).begin().it_, ptr_ ); }
493 {
return iterator( (*vec_).end().it_, ptr_ ); }
509 {
return (*vec_)[idx].*ptr_; }
511 {
return vec_->
at(idx).*ptr_; }
513 {
return (*vec_)[idx].*ptr_; }
515 {
return vec_->
at(idx).*ptr_; }
517 template<
typename ContainerType,
typename ArgumentType >
519 {
return bind( c.begin(), c.end() ); }
521 template<
typename BindableContainer >
523 {
return bind( c.begin(), c.end() ); }
525 template<
typename BindableIterator >
527 {
return bind( first, last, this->
begin() ); }
529 template<
typename BindableIterator >
534 template<
typename BindableIterator >
537 {
return bind( first, last,
iterator(from.it_, ptr_) ); }
539 template<
typename ContainerType,
typename ArgumentType >
543 template<
typename ArgumentContainer >
547 template<
typename ArgumentIterator >
551 template<
typename ArgumentIterator >
556 template<
typename ArgumentIterator >
576 swap( vec_, that.vec_ );
577 swap( ptr_, that.ptr_ );
578 swap( child_vec_, that.child_vec_ );
585 {
delete child_vec_; }
595 sc_object* object_cast(
pointer p )
const
601 mutable std::vector< sc_object* >* child_vec_;
604 template<
typename T,
typename MT >
605 sc_vector_assembly<T,MT>
606 sc_assemble_vector( sc_vector<T> & vec, MT (T::*ptr) )
608 return vec.assemble( ptr );
611 template<
typename T >
612 typename sc_vector<T>::element_type *
615 return new T( name );
618 template<
typename T >
619 template<
typename Creator >
623 if ( base_type::check_init(n) )
625 base_type::reserve( n );
631 std::string name = make_name( basename(), i );
632 const char* cname = name.c_str();
634 void* p = c( cname, i ) ;
635 base_type::push_back(p);
646 template<
typename T >
653 delete &( (*this)[i] );
654 base_type::at(i) = 0;
659 template<
typename Container,
typename ArgumentIterator >
660 typename Container::iterator
662 , ArgumentIterator first
663 , ArgumentIterator last
664 ,
typename Container::iterator from )
666 typename Container::iterator end = cont.end();
668 if( !cont.size() || from == end || first == last )
669 cont.report_empty_bind( cont.kind(), from == end );
671 while( from!=end && first != last )
672 (*from++).bind( *first++ );
676 template<
typename Container,
typename ArgumentIterator >
677 typename Container::iterator
679 , ArgumentIterator first
680 , ArgumentIterator last
681 ,
typename Container::iterator from )
683 typename Container::iterator end = cont.end();
685 if( !cont.size() || from == end || first == last )
686 cont.report_empty_bind( cont.kind(), from == end );
688 while( from!=end && first != last )
689 (*from++)( *first++ );
693 template<
typename T >
699 template<
typename T,
typename MT >
700 std::vector< sc_object* >
const &
704 child_vec_ =
new std::vector< sc_object* >;
706 if( child_vec_->size() || !size() )
709 child_vec_->reserve( size() );
711 if(
sc_object * obj = object_cast( const_cast<MT*>(&*it) ) )
712 child_vec_->push_back( obj );
749 #endif // SC_VECTOR_H_INCLUDED_
const_iterator::pointer const_pointer
sc_direct_access< const plain_type > const_policy
sc_vector(const char *prefix, size_type n, Creator creator)
this_type & operator-=(difference_type n)
iterator bind(BindableIterator first, BindableIterator last, iterator from)
sc_member_access(const non_const_policy &other)
const_iterator end() const
iterator operator()(ArgumentIterator first, ArgumentIterator last)
sc_vector_iter< const T, sc_member_access< const T, const MT > > const_iterator
const_iterator end() const
bool operator>(const this_type &that) const
const_iterator cbegin() const
#define SC_ENABLE_IF_(Cond)
iterator bind(BindableIterator first, BindableIterator last)
this_type operator++(int)
const char * kind() const
iterator::pointer pointer
static std::string make_name(const char *prefix, size_type index)
reference operator*() const
sc_direct_access(const U &, SC_ENABLE_IF_((sc_meta::is_more_const< type, typename U::policy::element_type >)))
sc_vector_assembly(const sc_vector_assembly &other)
base_type::size_type size_type
void const * at(size_type i) const
void report_empty_bind(const char *kind_, bool dst_range_) const
iterator operator()(ArgumentContainer &c)
const_iterator begin() const
iterator bind(BindableContainer &c)
storage_type::difference_type difference_type
const char * name() const
const_iterator end() const
pointer operator->() const
std::vector< sc_object * > const & get_elements() const
sc_vector(const char *prefix)
virtual sc_object * object_cast(void *p) const
base_type::pointer pointer
access_typeT::* member_type
static element_type * create_element(const char *prefix, size_type index)
reference operator[](size_type idx)
SC_BOOST_STATIC_CONSTANT(bool, value=(is_same< typename remove_const< CT >::type, typename remove_const< T >::type >::value &&(is_const< CT >::value >=is_const< T >::value)))
this_type operator--(int)
storage_type::size_type size_type
sc_vector_iter(const sc_vector_iter< OtherElement, OtherPolicy > &it, SC_ENABLE_IF_((sc_meta::is_more_const< element_type, typename OtherPolicy::element_type >)))
sc_member_access(member_type ptr)
const_iterator::reference const_reference
void swap(sc_vector_assembly &that)
void push_back(void *item)
iterator operator()(ArgumentIterator first, ArgumentIterator last, iterator from)
const_reference operator[](size_type idx) const
SC_BOOST_STATIC_CONSTANT(bool, value=false)
sc_direct_access< plain_type > non_const_policy
base_type::difference_type difference_type
iterator bind(BindableIterator first, BindableIterator last)
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
this_type operator+(difference_type n) const
iterator bind(BindableIterator first, BindableIterator last, typename base_type::iterator from)
bool check_init(size_type n) const
std::vector< void * > storage_type
void check_index(size_type i) const
base_type::reference reference
const_reference at(size_type idx) const
sc_vector_iter< const element_type > const_iterator
base_type::difference_type difference_type
sc_member_access< element_type, access_type > policy
bool operator<=(const this_type &that) const
sc_member_access< const plain_elem_type, const plain_type > const_policy
sc_vector_assembly & operator=(sc_vector_assembly other_copy)
sc_vector(const char *prefix, size_type n)
iterator operator()(ArgumentIterator first, ArgumentIterator last, typename base_type::iterator from)
sc_meta::remove_const< ElementType >::type plain_elem_type
iterator operator()(sc_vector_assembly< ContainerType, ArgumentType > c)
const char * kind() const
sc_member_access< plain_elem_type, plain_type > non_const_policy
Container::iterator sc_vector_do_bind(Container &cont, ArgumentIterator first, ArgumentIterator last, typename Container::iterator from)
reference at(size_type idx)
reference operator[](difference_type n) const
access_typeElementType::* member_type
sc_object * implicit_cast(sc_object *p) const
storage_type::iterator iterator
bool operator<(const this_type &that) const
element_type & operator[](size_type i)
sc_direct_access(const non_const_policy &)
void reserve(size_type n)
void report_empty_bind(const char *kind_, bool dst_empty_) const
const std::vector< sc_object * > & get_elements() const
sc_vector_iter< element_type > iterator
sc_vector_assembly< T, MT > assemble(MT(T::*member_ptr))
sc_direct_access< type > policy
iterator operator()(ArgumentIterator first, ArgumentIterator last, iterator from)
virtual sc_object * object_cast(void *) const =0
iterator::reference reference
sc_meta::remove_const< type >::type plain_type
const_iterator begin() const
this_type & operator+=(difference_type n)
const_iterator cbegin() const
sc_meta::remove_const< type >::type plain_type
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
iterator operator()(ArgumentIterator first, ArgumentIterator last)
difference_type operator-(this_type const &that) const
iterator operator()(sc_vector_assembly< ContainerType, ArgumentType > c)
const_iterator cend() const
iterator bind(BindableIterator first, BindableIterator last, iterator from)
sc_clock period is zero sc_clock low time is zero sc_fifo< T > cannot have more than one writer bind interface to port failed complete binding failed remove port failed insert primitive channel failed sc_signal< T > cannot have more than one driver resolved port not bound to resolved signal sc_semaphore requires an initial value
iterator bind(BindableContainer &c)
iterator operator()(ArgumentContainer &c)
sc_vector_iter< T, sc_member_access< T, MT > > iterator
element_type & at(size_type i)
const char * name() const
sc_vector_base(const char *prefix)
Container::iterator sc_vector_do_operator_paren(Container &cont, ArgumentIterator first, ArgumentIterator last, typename Container::iterator from)
bool operator==(const this_type &that) const
bool operator>=(const this_type &that) const
this_type operator-(difference_type n) const
const_iterator cend() const
const_iterator begin() const
bool operator!=(const this_type &that) const
SC_BOOST_STATIC_CONSTANT(bool, value=false)
const element_type & at(size_type i) const
Abstract base class of all SystemC `simulation' objects.
storage_type::const_iterator const_iterator
const element_type & operator[](size_type i) const