29#ifndef SC_VECTOR_H_INCLUDED_
30#define SC_VECTOR_H_INCLUDED_
41#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
43#pragma warning(disable: 4251)
48template<
typename T >
class sc_vector;
49template<
typename T,
typename MT >
class sc_vector_assembly;
50template<
typename T,
typename MT >
class sc_vector_iter;
53template<
typename Container,
typename ArgumentIterator >
54typename Container::iterator
56 , ArgumentIterator first
57 , ArgumentIterator last
58 ,
typename Container::iterator from );
61template<
typename Container,
typename ArgumentIterator >
62typename Container::iterator
64 , ArgumentIterator first
65 , ArgumentIterator last
66 ,
typename Container::iterator from );
74class sc_vector_element;
91 const char *
kind()
const {
return "sc_vector"; }
96 {
return vec_.size(); }
98 void lock() { locked =
true; };
121 {
delete objs_vec_; }
136 { vec_.push_back(
static_cast<handle_type>(item) ); }
163 mutable std::vector< sc_object* >* objs_vec_;
173template<
typename CT,
typename T >
175 std::is_same_v<std::remove_const_t<CT>, std::remove_const_t<T>> &&
176 std::is_const_v<CT> >= std::is_const_v<T>;
179template<
typename ElementType >
193 ,
typename = std::enable_if_t<sc_is_more_const_v<type, typename U::policy::element_type>>>
201template<
typename ElementType
202 ,
typename AccessType >
229 {
return &(this_->*ptr_); }
236template<
typename ElementType
237 ,
typename AccessPolicy = sc_direct_access<ElementType> >
239 :
private AccessPolicy
242 typedef typename AccessPolicy::policy access_policy;
244 typedef typename AccessPolicy::const_policy
const_policy;
246 typedef std::remove_const_t<ElementType>
plain_type;
260 template<
typename U >
struct select_iter
261 {
typedef typename storage_type::iterator
type; };
262 template<
typename U >
struct select_iter< const U >
263 {
typedef typename storage_type::const_iterator
type; };
265 typedef typename select_iter<ElementType>::type raw_iterator;
266 typedef sc_vector_iter< const_plain_type, const_policy > const_iterator;
267 typedef sc_vector_iter< const_plain_type, const_direct_policy >
268 const_direct_iterator;
274 sc_vector_iter( raw_iterator it, access_policy acc = access_policy() )
275 : access_policy(acc), it_(it) {}
277 access_policy
const & get_policy()
const {
return *
this; }
300 template<
typename It
301 ,
typename = std::enable_if_t<sc_is_more_const_v<element_type, typename It::policy::element_type>>>
303 : access_policy( it.get_policy() ), it_( it.it_ )
314 {
return this_type( it_ + n, get_policy()); }
316 {
return this_type( it_ - n, get_policy()); }
323 {
return *access_policy::get(
static_cast<element_type*
>((
void*)*it_) ); }
325 {
return access_policy::get(
static_cast<element_type*
>((
void*)*it_) ); }
327 {
return *access_policy::get(
static_cast<element_type*
>((
void*)it_[n]) ); }
331 {
return it_-that.it_; }
333 raw_iterator
raw()
const {
return it_; }
339template<
typename T1,
typename Pol1,
typename T2,
typename Pol2
340 ,
typename = std::enable_if_t<std::is_same_v<std::remove_const_t<T1>, std::remove_const_t<T2>>>>
343 {
return a.
raw() ==
b.raw(); }
345template<
typename T1,
typename Pol1,
typename T2,
typename Pol2 >
348 {
return !(a ==
b); }
350template<
typename T1,
typename Pol1,
typename T2,
typename Pol2
351 ,
typename = std::enable_if_t<std::is_same_v<std::remove_const_t<T1>, std::remove_const_t<T2>>>>
354 {
return a.
raw() <
b.raw(); }
356template<
typename T1,
typename Pol1,
typename T2,
typename Pol2 >
361template<
typename T1,
typename Pol1,
typename T2,
typename Pol2 >
366template<
typename T1,
typename Pol1,
typename T2,
typename Pol2 >
372template<
typename T >
397 template<
typename Creator >
402 init( n, creator, init_pol );
423 template<
typename Creator >
429 template<
typename... Args >
433 template<
typename... Args >
447 template<
typename ContainerType,
typename ArgumentType >
451 template<
typename BindableContainer >
453 {
return bind( c.begin(), c.end() ); }
455 template<
typename BindableIterator >
457 {
return bind( first, last, this->
begin() ); }
459 template<
typename BindableIterator >
460 iterator
bind( BindableIterator first, BindableIterator last
464 template<
typename ContainerType,
typename ArgumentType >
468 template<
typename ArgumentContainer >
472 template<
typename ArgumentIterator >
476 template<
typename ArgumentIterator >
477 iterator
operator()( ArgumentIterator first, ArgumentIterator last
483 template<
typename MT >
496template<
typename T,
typename MT >
523 const char*
kind()
const {
return "sc_vector_assembly"; }
526 {
return iterator( (*vec_).begin().it_, ptr_ ); }
528 {
return iterator( (*vec_).end().it_, ptr_ ); }
544 {
return (*vec_)[idx].*ptr_; }
546 {
return vec_->
at(idx).*ptr_; }
548 {
return (*vec_)[idx].*ptr_; }
550 {
return vec_->
at(idx).*ptr_; }
552 template<
typename ContainerType,
typename ArgumentType >
556 template<
typename BindableContainer >
558 {
return bind( c.begin(), c.end() ); }
560 template<
typename BindableIterator >
562 {
return bind( first, last, this->
begin() ); }
564 template<
typename BindableIterator >
565 iterator
bind( BindableIterator first, BindableIterator last
569 template<
typename BindableIterator >
572 {
return bind( first, last,
iterator(from.it_, ptr_) ); }
574 template<
typename ContainerType,
typename ArgumentType >
578 template<
typename ArgumentContainer >
582 template<
typename ArgumentIterator >
586 template<
typename ArgumentIterator >
587 iterator
operator()( ArgumentIterator first, ArgumentIterator last
591 template<
typename ArgumentIterator >
611 swap( vec_, that.vec_ );
612 swap( ptr_, that.ptr_ );
613 swap( child_vec_, that.child_vec_ );
620 {
delete child_vec_; }
636 mutable std::vector< sc_object* >* child_vec_;
639template<
typename T,
typename MT >
640sc_vector_assembly<T,MT>
646template<
typename T >
650 return new T( name );
653template<
typename T >
654template<
typename Creator >
658 if ( base_type::check_init(n) )
660 base_type::reserve( n );
669 std::string name = make_name( basename(), i );
670 const char* cname = name.c_str();
673 base_type::push_back(p);
688template<
typename T >
689template<
typename... Args >
691 if (check_locked()) {
693 T* p =
new T( make_name( basename(), size()).c_str() ,
694 std::forward<Args>(args)...);
695 base_type::push_back(p);
699template<
typename T >
700template<
typename... Args >
702 if (check_locked()) {
704 T *p =
new T(std::forward<Args>(args)...);
705 base_type::push_back(p);
709template<
typename T >
716 delete &( (*this)[i] );
721template<
typename Container,
typename ArgumentIterator >
722typename Container::iterator
724 , ArgumentIterator first
725 , ArgumentIterator last
726 ,
typename Container::iterator from )
728 typename Container::iterator end = cont.end();
730 if( !cont.size() || from == end || first == last )
731 cont.report_empty_bind( cont.kind(), from == end );
733 while( from!=end && first != last )
734 (*from++).bind( *first++ );
738template<
typename Container,
typename ArgumentIterator >
739typename Container::iterator
741 , ArgumentIterator first
742 , ArgumentIterator last
743 ,
typename Container::iterator from )
745 typename Container::iterator end = cont.end();
747 if( !cont.size() || from == end || first == last )
748 cont.report_empty_bind( cont.kind(), from == end );
750 while( from!=end && first != last )
751 (*from++)( *first++ );
755template<
typename T >
761template<
typename T,
typename MT >
762std::vector< sc_object* >
const &
766 child_vec_ =
new std::vector< sc_object* >;
768 if( child_vec_->size() || !size() )
771 child_vec_->reserve( size() );
773 if(
sc_object * obj = object_cast(
const_cast<MT*
>(&*it) ) )
774 child_vec_->push_back( obj );
784#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
auto operator>(const sc_vector_iter< T1, Pol1 > &a, const sc_vector_iter< T2, Pol2 > &b) -> decltype((b< a))
Container::iterator sc_vector_do_bind(Container &cont, ArgumentIterator first, ArgumentIterator last, typename Container::iterator from)
bool operator!=(const sc_process_handle &left, const sc_process_handle &right)
auto operator<=(const sc_vector_iter< T1, Pol1 > &a, const sc_vector_iter< T2, Pol2 > &b) -> decltype(!(b< a))
bool operator==(const sc_process_handle &left, const sc_process_handle &right)
@ SC_VECTOR_LOCK_AFTER_ELABORATION
@ SC_VECTOR_LOCK_AFTER_INIT
Container::iterator sc_vector_do_operator_paren(Container &cont, ArgumentIterator first, ArgumentIterator last, typename Container::iterator from)
bool operator<(const sc_process_handle &left, const sc_process_handle &right)
auto operator>=(const sc_vector_iter< T1, Pol1 > &a, const sc_vector_iter< T2, Pol2 > &b) -> decltype(!(a< b))
constexpr bool sc_is_more_const_v
sc_vector_assembly< T, MT > sc_assemble_vector(sc_vector< T > &vec, MT(T::*ptr))
uint64 const sc_uint_base int b
const char * name() const
const element_type & at(size_type i) const
void init(size_type n, sc_vector_init_policy init_pol=SC_VECTOR_LOCK_AFTER_INIT)
void emplace_back(Args &&... args)
iterator bind(BindableIterator first, BindableIterator last, iterator from)
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
element_type & at(size_type i)
iterator operator()(ArgumentIterator first, ArgumentIterator last)
const_iterator cbegin() const
sc_vector(const char *prefix, size_type n, Creator creator, sc_vector_init_policy init_pol=SC_VECTOR_LOCK_AFTER_INIT)
sc_vector_iter< const element_type > const_iterator
iterator operator()(ArgumentContainer &c)
sc_vector(const char *prefix)
iterator bind(BindableContainer &c)
iterator operator()(ArgumentIterator first, ArgumentIterator last, iterator from)
sc_vector_assembly< T, MT > assemble(MT(T::*member_ptr))
static element_type * create_element(const char *prefix, size_type index)
const element_type & operator[](size_type i) const
void emplace_back_with_name(Args &&... args)
virtual sc_object * object_cast(void *p) const
iterator bind(BindableIterator first, BindableIterator last)
sc_vector_iter< element_type > iterator
const_iterator end() const
const_iterator begin() const
const_iterator cend() const
iterator operator()(sc_vector_assembly< ContainerType, ArgumentType > c)
element_type & operator[](size_type i)
sc_vector(const char *prefix, size_type n, sc_vector_init_policy init_pol=SC_VECTOR_LOCK_AFTER_INIT)
iterator bind(sc_vector_assembly< ContainerType, ArgumentType > c)
base_type::size_type size_type
access_typeT::* member_type
const std::vector< sc_object * > & get_elements() const
const_reference at(size_type idx) const
void swap(sc_vector_assembly &that)
iterator operator()(ArgumentContainer &c)
const_iterator cbegin() const
iterator bind(BindableContainer &c)
iterator::pointer pointer
const_iterator::reference const_reference
iterator operator()(sc_vector_assembly< ContainerType, ArgumentType > c)
iterator bind(BindableIterator first, BindableIterator last, iterator from)
reference operator[](size_type idx)
const_iterator cend() const
iterator operator()(ArgumentIterator first, ArgumentIterator last, typename base_type::iterator from)
reference at(size_type idx)
sc_vector_assembly & operator=(sc_vector_assembly other_copy)
const_iterator end() const
iterator operator()(ArgumentIterator first, ArgumentIterator last, iterator from)
sc_vector_iter< const T, sc_member_access< const T, const MT > > const_iterator
iterator::reference reference
iterator operator()(ArgumentIterator first, ArgumentIterator last)
const_reference operator[](size_type idx) const
const char * kind() const
void report_empty_bind(const char *kind_, bool dst_empty_) const
const char * name() const
iterator bind(BindableIterator first, BindableIterator last)
base_type::difference_type difference_type
const_iterator begin() const
const_iterator::pointer const_pointer
sc_vector_assembly(const sc_vector_assembly &other)
iterator bind(BindableIterator first, BindableIterator last, typename base_type::iterator from)
sc_vector_iter< T, sc_member_access< T, MT > > iterator
this_type operator-(difference_type n) const
friend class sc_vector_iter
std::ptrdiff_t difference_type
sc_vector_iter(const It &it)
std::random_access_iterator_tag iterator_category
this_type operator+(difference_type n) const
this_type operator--(int)
this_type & operator-=(difference_type n)
reference operator[](difference_type n) const
access_policy::type value_type
difference_type operator-(const_direct_iterator const &that) const
reference operator*() const
pointer operator->() const
this_type operator++(int)
this_type & operator+=(difference_type n)
void reserve(size_type n)
storage_type::iterator iterator
virtual sc_object * object_cast(void *) const =0
const_iterator begin() const
std::vector< sc_object * > const & get_elements() const
storage_type::const_iterator const_iterator
std::vector< handle_type > storage_type
void check_index(size_type i) const
void push_back(void *item)
static std::string make_name(const char *prefix, size_type index)
sc_vector_base(const char *prefix)
void stage_callback(const sc_stage &stage)
sc_object * implicit_cast(sc_object *p) const
bool check_init(size_type n) const
const_iterator end() const
sc_vector_element * handle_type
storage_type::difference_type difference_type
sc_object * implicit_cast(...) const
bool check_locked() const
const char * kind() const
void report_empty_bind(const char *kind_, bool dst_range_) const
void const * at(size_type i) const
storage_type::size_type size_type
sc_direct_access< plain_type > non_const_policy
sc_direct_access(const U &)
std::remove_const_t< type > plain_type
sc_direct_access< type > policy
type * get(type *this_) const
sc_direct_access< const plain_type > const_policy
std::remove_const_t< ElementType > plain_elem_type
sc_member_access< element_type, access_type > policy
sc_member_access(member_type ptr)
access_typeElementType::* member_type
sc_member_access< const plain_elem_type, const plain_type > const_policy
std::remove_const_t< type > plain_type
sc_member_access< plain_elem_type, plain_type > non_const_policy
sc_member_access(const non_const_policy &other)
access_type * get(element_type *this_) const