49 #ifndef __SYSTEMC_EXT_UTIL_SC_VECTOR_HH__ 50 #define __SYSTEMC_EXT_UTIL_SC_VECTOR_HH__ 58 #include "../core/sc_module.hh" 59 #include "../core/sc_object.hh" 67 #if __cplusplus >= 201103L 70 using std::remove_const;
76 template<
bool Cond,
typename T=
void>
97 template <
typename T,
typename U>
100 static const bool value =
false;
102 template <
typename T>
105 static const bool value =
true;
108 template <
typename T>
111 static const bool value =
false;
113 template <
typename T>
116 static const bool value =
true;
121 template <
typename CT,
typename T>
124 static const bool value =
133 template <
typename T>
137 template <
typename T>
143 #define SC_RPTYPE_(Type) \ 144 ::sc_gem5::remove_special_fptr< \ 145 ::sc_gem5::special_result & (*) Type>::type::value 147 #define SC_ENABLE_IF_(Cond) \ 148 typename ::sc_gem5::enable_if<SC_RPTYPE_(Cond)>::type * = NULL 155 template <
typename T,
typename MT>
158 template <
typename T>
161 template <
typename T,
typename MT>
172 virtual const char *
kind()
const {
return "sc_vector"; }
173 size_type size()
const;
189 virtual sc_object *objectCast(
void *)
const = 0;
191 void checkIndex(size_type
index)
const;
192 void forceParent()
const;
193 void unforceParent()
const;
195 void reportEmpty(
const char *kind_,
bool empty_dest)
const;
204 template <
typename Element>
219 template <
typename U>
223 ElementType,
typename U::Policy::ElementType>
229 get(ElementType *this_)
const 235 template <
typename Element,
typename Access>
239 template <
typename,
typename>
256 AccessType *
get(ElementType *this_)
const {
return &(this_->*ptr_); }
262 template <
typename Element,
265 public std::iterator<std::random_access_iterator_tag,
266 typename AccessPolicy::Type>,
271 typedef typename AccessPolicy::Policy
Policy;
282 template <
typename,
typename>
284 template <
typename,
typename>
287 typedef std::iterator<std::random_access_iterator_tag, AccessType>
293 template <
typename U>
298 template <
typename U>
326 template <
typename It>
330 ElementType,
typename It::Policy::ElementType>
332 ) : Policy(it.get_policy()), it_(it.it_)
365 return ThisType(it_ + n, get_policy());
370 return ThisType(it_ - n, get_policy());
374 operator += (difference_type
n)
381 operator -= (difference_type
n)
390 return it_ == other.
it_;
395 return it_ != other.
it_;
400 return it_ <= other.
it_;
405 return it_ >= other.
it_;
410 return it_ < other.
it_;
415 return it_ > other.
it_;
421 return *Policy::get(static_cast<ElementType *>((
void *)*it_));
426 return Policy::get(static_cast<ElementType *>((
void *)*it_));
429 operator [] (difference_type
n)
const 431 return *Policy::get(static_cast<ElementType *>((
void *)it_[n]));
437 return it_ - other.
it_;
441 template <
typename T>
455 template <
typename Creator>
459 init(_size, creator);
474 template <
typename Creator>
498 return *
static_cast<const T *
>(objs[
index]);
504 this->checkIndex(index);
505 return *
static_cast<T *
>(objs[
index]);
510 this->checkIndex(index);
511 return *
static_cast<const T *
>(objs[
index]);
514 iterator
begin() {
return objs.begin(); }
515 iterator
end() {
return objs.end(); }
516 const_iterator
begin()
const {
return objs.begin(); }
517 const_iterator
end()
const {
return objs.end(); }
518 const_iterator
cbegin()
const {
return objs.begin(); }
519 const_iterator
cend()
const {
return objs.end(); }
521 template <
typename ContainerType,
typename ArgumentType>
528 template <
typename BindableContainer>
532 return bind(c.begin(), c.end());
535 template <
typename BindableIterator>
537 bind(BindableIterator first, BindableIterator last)
539 return bind(first, last, this->begin());
542 template <
typename BindableIterator>
544 bind(BindableIterator first, BindableIterator last, iterator from)
546 if (!size() || from == end() || first == last)
547 reportEmpty(kind(), from == end());
549 while (from != end() && first != last)
550 (*from++).bind(*first++);
554 template <
typename ContainerType,
typename ArgumentType>
561 template <
typename ArgumentContainer>
563 operator () (ArgumentContainer &
c)
565 return (*
this)(c.begin(), c.end());
568 template <
typename ArgumentIterator>
570 operator () (ArgumentIterator first, ArgumentIterator last)
572 return (*
this)(first, last, this->begin());
575 template <
typename ArgumentIterator>
577 operator () (ArgumentIterator first, ArgumentIterator last, iterator from)
579 if (!size() || from == end() || first == last)
580 reportEmpty(kind(), from == end());
582 while (from != end() && first != last)
596 delete static_cast<T *
>(obj);
599 template <
typename,
typename>
605 return implicitCast(static_cast<T *>(ptr));
609 template <
typename T,
typename MT>
623 vec_(other.vec_), ptr_(other.ptr_)
626 iterator
begin() {
return iterator(vec_->begin().it_, ptr_); }
627 iterator
end() {
return iterator(vec_->end().it_, ptr_); }
632 return const_iterator(vec_->begin().it_, ptr_);
637 return const_iterator(vec_->end().it_, ptr_);
643 return const_iterator(vec_->begin().it_, ptr_);
648 return const_iterator(vec_->end().it_, ptr_);
651 size_type
size()
const {
return vec_->size(); }
657 for (const_iterator it = begin(); it != end(); it++) {
658 sc_object *obj_ptr = vec_->objectCast(const_cast<MT *>(&*it));
661 ret.push_back(obj_ptr);
667 operator [] (size_type
i)
669 return (*vec_)[
i].*ptr_;
672 operator [] (size_type
i)
const 674 return (*vec_)[
i].*ptr_;
680 return vec_->at(i).*ptr_;
685 return vec_->at(i).*ptr_;
688 template <
typename ContainerType,
typename ArgumentType>
695 template <
typename BindableContainer>
699 return bind(c.begin(), c.end());
702 template <
typename BindableIterator>
704 bind(BindableIterator first, BindableIterator last)
706 return bind(first, last, this->begin());
709 template <
typename BindableIterator>
711 bind(BindableIterator first, BindableIterator last, iterator from)
713 if (!size() || from == end() || first == last)
714 vec_->reportEmpty(
"sc_vector_assembly", from == end());
716 while (from != end() && first != last)
717 (*from++).bind(*first++);
721 template <
typename BindableIterator>
723 bind(BindableIterator first, BindableIterator last,
726 return bind(first, last, iterator(from.
it_, ptr_));
729 template <
typename ContainerType,
typename ArgumentType>
736 template <
typename ArgumentContainer>
738 operator () (ArgumentContainer &
c)
740 return (*
this)(c.begin(), c.end());
743 template <
typename ArgumentIterator>
745 operator () (ArgumentIterator first, ArgumentIterator last)
747 return (*
this)(first, last, this->begin());
750 template <
typename ArgumentIterator>
752 operator () (ArgumentIterator first, ArgumentIterator last, iterator from)
754 if (!size() || from == end() || first == last)
755 vec_->reportEmpty(
"sc_vector_assembly", from == end());
757 while (from != end() && first != last)
762 template <
typename ArgumentIterator>
764 operator () (ArgumentIterator first, ArgumentIterator last,
767 return (*
this)(first, last, iterator(from.
it_, ptr_));
779 template <
typename T,
typename MT>
788 #endif //__SYSTEMC_EXT_UTIL_SC_VECTOR_HH__
sc_gem5::remove_const< ElementType >::type PlainType
sc_direct_access< PlainType > NonConstPolicy
sc_vector< PlainType > VectorType
sc_vector_iter(const It &it, SC_ENABLE_IF_((sc_gem5::is_more_const< ElementType, typename It::Policy::ElementType >)))
sc_member_access< const PlainElemType, const PlainType > ConstPolicy
const_iterator cbegin() const
iterator bind(BindableContainer &c)
Time operator+(const Time &l, const Time &r)
sc_member_access< ElementType, AccessType > Policy
sc_direct_access< const PlainType > ConstPolicy
#define SC_ENABLE_IF_(Cond)
const std::string & name()
Policy const & get_policy() const
sc_direct_access(const NonConstPolicy &)
sc_direct_access< ElementType > Policy
const_iterator cend() const
sc_vector_assembly(const sc_vector_assembly &other)
std::vector< sc_object * > get_elements() const
const char * sc_gen_unique_name(const char *seed)
sc_object * objectCast(void *ptr) const
sc_vector_iter(RawIterator it, Policy acc=Policy())
std::vector< sc_object * > elements
AccessTypeElementType::* MemberType
sc_direct_access< PlainType >::ConstPolicy ConstDirectPolicy
sc_object * implicitCast(...) const
AccessPolicy::ConstPolicy ConstPolicy
sc_vector_iter< const T > const_iterator
void init(size_type _size, Creator creator)
sc_vector_base(const char *_name)
sc_vector_assembly< T, MT > sc_assemble_vector(sc_vector< T > &v, MT(T::*ptr))
AccessPolicy::NonConstPolicy NonConstPolicy
const char SC_ID_VECTOR_NONOBJECT_ELEMENTS_[]
AccessPolicy::Policy Policy
std::vector< void * >::iterator type
sc_vector(const char *_name)
bool operator>=(const Time &l, const Time &r)
static bool operator==(const ExtMachInst &emi1, const ExtMachInst &emi2)
std::vector< void * > StorageType
iterator bind(BindableIterator first, BindableIterator last, iterator from)
sc_member_access(MemberType ptr)
sc_member_access(const NonConstPolicy &other)
sc_vector_assembly(sc_vector< T > &v, MemberType ptr)
const T & at(size_type index) const
sc_gem5::remove_const< ElementType >::type PlainElemType
BaseType::difference_type difference_type
const_iterator end() const
sc_gem5::remove_const< ElementType >::type PlainType
BaseType::pointer pointer
iterator bind(BindableIterator first, BindableIterator last, typename sc_vector< T >::iterator from)
static T * create_element(const char *_name, size_type index)
virtual const char * kind() const
sc_vector_iter< T > iterator
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
iterator bind(BindableIterator first, BindableIterator last)
sc_vector_iter< T, sc_member_access< T, MT > > iterator
sc_vector_iter< ConstPlainType, ConstDirectPolicy > ConstDirectIterator
iterator bind(BindableContainer &c)
SelectIter< ElementType >::type RawIterator
const PlainType ConstPlainType
const_iterator begin() const
iterator bind(BindableIterator first, BindableIterator last, iterator from)
const_iterator cbegin() const
sc_vector_iter< ConstPlainType, ConstPolicy > ConstIterator
sc_vector(const char *_name, size_type _size)
sc_member_access< PlainElemType, PlainType > NonConstPolicy
std::vector< void * >::const_iterator type
iterator bind(BindableIterator first, BindableIterator last)
BaseType::reference reference
sc_vector(const char *_name, size_type _size, Creator creator)
sc_direct_access(const U &, SC_ENABLE_IF_((sc_gem5::is_more_const< ElementType, typename U::Policy::ElementType >)))
const_iterator::reference at(size_type i) const
bool operator<=(const Time &l, const Time &r)
bool operator>(const Time &l, const Time &r)
const_iterator begin() const
#define SC_REPORT_ERROR(msg_type, msg)
bool operator!=(const RefCountingPtr< T > &l, const RefCountingPtr< T > &r)
Check for inequality of two reference counting pointers.
Temp operator*(Temp l, Temp r)
sc_object * implicitCast(sc_object *p) const
iterator::reference at(size_type i)
const_iterator cend() const
std::iterator< std::random_access_iterator_tag, AccessType > BaseType
sc_gem5::remove_const< AccessType >::type PlainType
const_iterator end() const
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
bool operator<(const Time &l, const Time &r)
std::vector< void * > objs
sc_vector_iter< const T, sc_member_access< const T, const MT > > const_iterator
void init(size_type _size)
const FlagsType init
This Stat is Initialized.
Time operator-(const Time &l, const Time &r)