29 #ifndef SC_VECTOR_H_INCLUDED_ 30 #define SC_VECTOR_H_INCLUDED_ 39 #if SC_CPLUSPLUS >= 201103L // use C++11 for type traits 40 # include <type_traits> 41 #else // use Boost for type traits 42 # include "sysc/packages/boost/config.hpp" 43 # include "sysc/packages/boost/utility/enable_if.hpp" 46 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN) 48 #pragma warning(disable: 4251) // DLL import for std::vector 54 #if SC_CPLUSPLUS >= 201103L // use C++11 for type traits 56 using std::remove_const;
60 # define SC_STATIC_CONSTANT_(Type,Value) \ 61 static const Type Value 63 #else // use Boost/local implementation for type traits 64 template<
bool Cond,
typename T =
void>
65 struct enable_if : sc_boost::enable_if_c<Cond, T> {};
67 # define SC_STATIC_CONSTANT_(Type,Value) \ 68 SC_BOOST_STATIC_CONSTANT(Type,Value) 74 template<
typename T,
typename U >
75 struct is_same { SC_BOOST_STATIC_CONSTANT(
bool,
value =
false ); };
76 template<
typename T >
77 struct is_same<T,T> { SC_BOOST_STATIC_CONSTANT(
bool,
value =
true ); };
79 template<
typename T >
81 template<
typename T >
82 struct is_const< const T> { SC_BOOST_STATIC_CONSTANT(
bool,
value =
true ); };
86 template<
typename CT,
typename T >
97 template<
typename T >
102 #define SC_RPTYPE_(Type) \ 103 ::sc_core::sc_meta::remove_special_fptr \ 104 < ::sc_core::sc_meta::special_result& (*) Type >::type::value 107 #define SC_ENABLE_IF_( Cond ) \ 108 typename ::sc_core::sc_meta::enable_if \ 109 < SC_RPTYPE_(Cond) >::type * = NULL 119 template<
typename Container,
typename ArgumentIterator >
120 typename Container::iterator
122 , ArgumentIterator first
123 , ArgumentIterator last
124 ,
typename Container::iterator from );
127 template<
typename Container,
typename ArgumentIterator >
128 typename Container::iterator
130 , ArgumentIterator first
131 , ArgumentIterator last
132 ,
typename Container::iterator from );
134 class sc_vector_element;
150 const char *
kind()
const {
return "sc_vector"; }
152 std::vector<sc_object*>
const & get_elements()
const;
155 {
return vec_.size(); }
173 {
delete objs_vec_; }
175 void *
at( size_type i )
178 void const *
at( size_type i )
const 188 { vec_.push_back( static_cast<handle_type>(item) ); }
190 void check_index( size_type i )
const;
191 bool check_init( size_type n )
const;
193 static std::string make_name(
const char* prefix, size_type index );
195 iterator
begin() {
return vec_.begin(); }
196 iterator
end() {
return vec_.end(); }
198 const_iterator
begin()
const {
return vec_.begin(); }
199 const_iterator
end()
const {
return vec_.end(); }
201 virtual sc_object* object_cast(
void* )
const = 0;
215 void report_empty_bind(
const char* kind_,
bool dst_range_ )
const;
219 mutable std::vector< sc_object* >* objs_vec_;
228 template<
typename ElementType >
249 type*
get( type* this_ )
const 254 template<
typename ElementType
255 ,
typename AccessType >
281 access_type *
get( element_type* this_ )
const 282 {
return &(this_->*ptr_); }
289 template<
typename ElementType
292 :
public std::iterator< std::random_access_iterator_tag
293 , typename AccessPolicy::type >
294 ,
private AccessPolicy
296 typedef ElementType element_type;
297 typedef typename AccessPolicy::policy access_policy;
298 typedef typename AccessPolicy::non_const_policy non_const_policy;
299 typedef typename AccessPolicy::const_policy const_policy;
303 typedef const plain_type const_plain_type;
311 typedef std::iterator< std::random_access_iterator_tag, access_type > base_type;
317 template<
typename U >
struct select_iter
318 {
typedef typename storage_type::iterator type; };
319 template<
typename U >
struct select_iter< const U >
320 {
typedef typename storage_type::const_iterator type; };
322 typedef typename select_iter<ElementType>::type raw_iterator;
331 sc_vector_iter( raw_iterator it, access_policy acc = access_policy() )
332 : access_policy(acc), it_(it) {}
334 access_policy
const & get_policy()
const {
return *
this; }
355 template<
typename It >
359 ,
typename It::policy::element_type >
361 : access_policy( it.get_policy() ), it_( it.it_ )
367 this_type
operator++(
int){ this_type old(*
this); ++it_;
return old; }
368 this_type
operator--(
int){ this_type old(*
this); --it_;
return old; }
372 {
return this_type( it_ + n, get_policy()); }
374 {
return this_type( it_ - n, get_policy()); }
376 this_type&
operator+=( difference_type n ) { it_+=n;
return *
this; }
377 this_type&
operator-=( difference_type n ) { it_-=n;
return *
this; }
381 {
return it_ == that.it_; }
383 {
return it_ != that.it_; }
385 {
return it_ <= that.it_; }
387 {
return it_ >= that.it_; }
388 bool operator< (
const const_direct_iterator& that )
const 389 {
return it_ < that.it_; }
390 bool operator> (
const const_direct_iterator& that )
const 391 {
return it_ > that.it_; }
395 {
return *access_policy::get( static_cast<element_type*>((
void*)*it_) ); }
397 {
return access_policy::get( static_cast<element_type*>((
void*)*it_) ); }
399 {
return *access_policy::get( static_cast<element_type*>((
void*)it_[n]) ); }
402 difference_type
operator-( const_direct_iterator
const& that )
const 403 {
return it_-that.it_; }
407 template<
typename T >
422 : base_type( prefix )
426 : base_type( prefix )
429 template<
typename Creator >
431 : base_type( prefix )
439 {
return *
static_cast<element_type*
>( base_type::at(i) ); }
442 { check_index(i);
return (*
this)[i]; }
445 {
return *
static_cast<element_type
const *
>( base_type::at(i) ); }
448 { check_index(i);
return (*
this)[i]; }
451 { init( n, &this_type::create_element ); }
453 template<
typename Creator >
456 static element_type * create_element(
const char* prefix,
size_type index );
458 iterator
begin() {
return base_type::begin(); }
459 iterator
end() {
return base_type::end(); }
461 const_iterator
begin()
const {
return base_type::begin(); }
462 const_iterator
end()
const {
return base_type::end(); }
464 const_iterator
cbegin()
const {
return base_type::begin(); }
465 const_iterator
cend()
const {
return base_type::end(); }
467 template<
typename ContainerType,
typename ArgumentType >
469 {
return bind( c.
begin(), c.
end() ); }
471 template<
typename BindableContainer >
472 iterator
bind( BindableContainer & c )
473 {
return bind( c.begin(), c.end() ); }
475 template<
typename BindableIterator >
476 iterator
bind( BindableIterator first, BindableIterator last )
477 {
return bind( first, last, this->begin() ); }
479 template<
typename BindableIterator >
480 iterator
bind( BindableIterator first, BindableIterator last
484 template<
typename ContainerType,
typename ArgumentType >
486 {
return operator()( c.
begin(), c.
end() ); }
488 template<
typename ArgumentContainer >
490 {
return operator()( c.begin(), c.end() ); }
492 template<
typename ArgumentIterator >
493 iterator
operator()( ArgumentIterator first, ArgumentIterator last )
494 {
return operator()( first, last, this->begin() ); }
496 template<
typename ArgumentIterator >
497 iterator
operator()( ArgumentIterator first, ArgumentIterator last
503 template<
typename MT >
512 {
return implicit_cast( static_cast<element_type*>(p) ); }
516 template<
typename T,
typename MT >
542 const char*
name()
const {
return vec_->name(); }
543 const char*
kind()
const {
return "sc_vector_assembly"; }
546 {
return iterator( (*vec_).begin().it_, ptr_ ); }
548 {
return iterator( (*vec_).end().it_, ptr_ ); }
551 {
return const_iterator( (*vec_).cbegin().it_, ptr_ ); }
553 {
return const_iterator( (*vec_).cend().it_, ptr_ ); }
556 {
return const_iterator( (*vec_).begin().it_, ptr_ ); }
557 const_iterator
end()
const 558 {
return const_iterator( (*vec_).end().it_, ptr_ ); }
560 size_type
size()
const {
return vec_->size(); }
561 const std::vector< sc_object* > & get_elements()
const;
564 {
return (*vec_)[idx].*ptr_; }
565 reference
at( size_type idx )
566 {
return vec_->at(idx).*ptr_; }
568 {
return (*vec_)[idx].*ptr_; }
569 const_reference
at( size_type idx )
const 570 {
return vec_->at(idx).*ptr_; }
572 template<
typename ContainerType,
typename ArgumentType >
574 {
return bind( c.
begin(), c.
end() ); }
576 template<
typename BindableContainer >
577 iterator
bind( BindableContainer & c )
578 {
return bind( c.begin(), c.end() ); }
580 template<
typename BindableIterator >
581 iterator
bind( BindableIterator first, BindableIterator last )
582 {
return bind( first, last, this->begin() ); }
584 template<
typename BindableIterator >
585 iterator
bind( BindableIterator first, BindableIterator last
589 template<
typename BindableIterator >
590 iterator
bind( BindableIterator first, BindableIterator last
592 {
return bind( first, last, iterator(from.it_, ptr_) ); }
594 template<
typename ContainerType,
typename ArgumentType >
596 {
return operator()( c.
begin(), c.
end() ); }
598 template<
typename ArgumentContainer >
600 {
return operator()( c.begin(), c.end() ); }
602 template<
typename ArgumentIterator >
603 iterator
operator()( ArgumentIterator first, ArgumentIterator last )
604 {
return operator()( first, last, this->begin() ); }
606 template<
typename ArgumentIterator >
607 iterator
operator()( ArgumentIterator first, ArgumentIterator last
611 template<
typename ArgumentIterator >
612 iterator
operator()( ArgumentIterator first, ArgumentIterator last
614 {
return operator()( first, last, iterator(from.it_, ptr_) ); }
631 swap( vec_, that.vec_ );
632 swap( ptr_, that.ptr_ );
633 swap( child_vec_, that.child_vec_ );
637 { vec_->report_empty_bind( kind_, dst_empty_ ); }
640 {
delete child_vec_; }
650 sc_object* object_cast( pointer p )
const 651 {
return vec_->implicit_cast( p ); }
656 mutable std::vector< sc_object* >* child_vec_;
659 template<
typename T,
typename MT >
666 template<
typename T >
670 return new T( name );
673 template<
typename T >
674 template<
typename Creator >
678 if ( base_type::check_init(n) )
683 base_type::reserve( n );
689 std::string name = make_name( basename(), i );
690 const char* cname = name.c_str();
692 element_type* p = c( cname, i ) ;
693 base_type::push_back(p);
704 template<
typename T >
711 delete &( (*this)[i] );
716 template<
typename Container,
typename ArgumentIterator >
717 typename Container::iterator
719 , ArgumentIterator first
720 , ArgumentIterator last
721 ,
typename Container::iterator from )
723 typename Container::iterator end = cont.end();
725 if( !cont.size() || from == end || first == last )
726 cont.report_empty_bind( cont.kind(), from == end );
728 while( from!=end && first != last )
729 (*from++).bind( *first++ );
733 template<
typename Container,
typename ArgumentIterator >
734 typename Container::iterator
736 , ArgumentIterator first
737 , ArgumentIterator last
738 ,
typename Container::iterator from )
740 typename Container::iterator end = cont.end();
742 if( !cont.size() || from == end || first == last )
743 cont.report_empty_bind( cont.kind(), from == end );
745 while( from!=end && first != last )
746 (*from++)( *first++ );
750 template<
typename T >
756 template<
typename T,
typename MT >
757 std::vector< sc_object* >
const &
761 child_vec_ =
new std::vector< sc_object* >;
763 if( child_vec_->size() || !size() )
766 child_vec_->reserve( size() );
767 for( const_iterator it=begin(); it != end(); ++it )
768 if(
sc_object * obj = object_cast( const_cast<MT*>(&*it) ) )
769 child_vec_->push_back( obj );
776 #undef SC_STATIC_CONSTANT_ 780 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN) 812 #endif // SC_VECTOR_H_INCLUDED_ storage_type::size_type size_type
sc_vector_iter(const It &it, SC_ENABLE_IF_((sc_meta::is_more_const< element_type, typename It::policy::element_type >)))
sc_vector_element * handle_type
bool operator<=(const const_direct_iterator &that) const
sc_direct_access< const plain_type > const_policy
static element_type * create_element(const char *prefix, size_type index)
this_type operator++(int)
const char * kind() const
sc_vector_iter< const element_type > const_iterator
const_iterator end() const
const_iterator begin() const
const_reference at(size_type idx) const
Abstract base class of all SystemC `simulation' objects.
iterator operator()(sc_vector_assembly< ContainerType, ArgumentType > c)
this_type & operator-=(difference_type n)
this_type operator+(difference_type n) const
element_type & at(size_type i)
sc_object * implicit_cast(sc_object *p) const
#define SC_ENABLE_IF_(Cond)
reference operator*() const
sc_vector_assembly(const sc_vector_assembly &other)
storage_type::iterator iterator
const_iterator cbegin() const
sc_member_access< const plain_elem_type, const plain_type > const_policy
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
iterator bind(BindableContainer &c)
void report_empty_bind(const char *kind_, bool dst_empty_) const
sc_direct_access< plain_type > non_const_policy
this_type operator-(difference_type n) const
sc_direct_access< type > policy
iterator operator()(ArgumentIterator first, ArgumentIterator last, iterator from)
difference_type operator-(const_direct_iterator const &that) const
base_type::difference_type difference_type
iterator bind(BindableIterator first, BindableIterator last, typename base_type::iterator from)
virtual sc_object * object_cast(void *p) const
const char * name() const
const char * kind() const
const std::vector< sc_object *> & get_elements() const
sc_member_access< element_type, access_type > policy
Container::iterator sc_vector_do_bind(Container &cont, ArgumentIterator first, ArgumentIterator last, typename Container::iterator from)
reference operator[](difference_type n) const
iterator::reference reference
const_iterator cend() const
sc_vector_base(const char *prefix)
iterator bind(BindableIterator first, BindableIterator last)
pointer operator->() const
const_iterator begin() const
iterator operator()(ArgumentIterator first, ArgumentIterator last, typename base_type::iterator from)
iterator bind(BindableIterator first, BindableIterator last, iterator from)
element_type & operator[](size_type i)
const_iterator cend() const
sc_direct_access(const non_const_policy &)
const_iterator begin() const
this_type operator--(int)
base_type::difference_type difference_type
iterator::pointer pointer
iterator bind(BindableContainer &c)
void reserve(size_type n)
void swap(sc_vector_assembly &that)
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
sc_vector(const char *prefix, size_type n)
sc_vector_iter< T, sc_member_access< T, MT > > iterator
bool operator>(const sc_int_base &a, const sc_int_base &b)
Abstract base class of all SystemC `simulation' objects.
const_iterator cbegin() const
const_iterator end() const
const_iterator::pointer const_pointer
iterator bind(BindableIterator first, BindableIterator last, iterator from)
bool operator!=(const const_direct_iterator &that) const
void const * at(size_type i) const
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
const_iterator::reference const_reference
sc_vector(const char *prefix)
reference at(size_type idx)
const_iterator end() const
sc_direct_access(const U &, SC_ENABLE_IF_((sc_meta::is_more_const< type, typename U::policy::element_type >)))
const element_type & operator[](size_type i) const
#define SC_STATIC_CONSTANT_(Type, Value)
Container::iterator sc_vector_do_operator_paren(Container &cont, ArgumentIterator first, ArgumentIterator last, typename Container::iterator from)
base_type::pointer pointer
sc_member_access< plain_elem_type, plain_type > non_const_policy
sc_vector_iter< element_type > iterator
iterator operator()(ArgumentContainer &c)
storage_type::const_iterator const_iterator
bool operator<(const sc_process_handle &left, const sc_process_handle &right)
bool operator==(const const_direct_iterator &that) const
std::vector< handle_type > storage_type
iterator operator()(ArgumentContainer &c)
void push_back(void *item)
access_typeElementType::* member_type
sc_vector_assembly< T, MT > sc_assemble_vector(sc_vector< T > &vec, MT(T::*ptr))
sc_vector_assembly< T, MT > assemble(MT(T::*member_ptr))
sc_meta::remove_const< type >::type plain_type
base_type::reference reference
sc_member_access(const non_const_policy &other)
const_reference operator[](size_type idx) const
sc_meta::remove_const< type >::type plain_type
bool operator>=(const const_direct_iterator &that) const
sc_vector_assembly & operator=(sc_vector_assembly other_copy)
sc_vector_iter< const T, sc_member_access< const T, const MT > > const_iterator
iterator operator()(ArgumentIterator first, ArgumentIterator last)
sc_vector(const char *prefix, size_type n, Creator creator)
storage_type::difference_type difference_type
sc_member_access(member_type ptr)
this_type & operator+=(difference_type n)
sc_meta::remove_const< ElementType >::type plain_elem_type
const element_type & at(size_type i) const
iterator operator()(sc_vector_assembly< ContainerType, ArgumentType > c)
iterator operator()(ArgumentIterator first, ArgumentIterator last, iterator from)
iterator bind(BindableIterator first, BindableIterator last)
access_typeT::* member_type
iterator operator()(ArgumentIterator first, ArgumentIterator last)
reference operator[](size_type idx)
base_type::size_type size_type