1#ifndef DATAMODEL_ELEMENTLINKVECTOR_H
2#define DATAMODEL_ELEMENTLINKVECTOR_H
4#ifndef DATAMODEL_DATALINK_H
5# include "DataModel/DataLink.h"
8#ifndef DATAMODEL_ELEMENTLINK_H
9# include "DataModel/ElementLink.h"
18#ifndef _CPP_FUNCTIONAL
24#ifndef BOOST_ITERATOR_ADAPTOR_DWA053000_HPP_
25# include <boost/iterator_adaptors.hpp>
49template <
typename DOBJ,
class StoragePolicy = DataProxyStorage<DOBJ>,
50 class IndexingPolicy =
typename SG::GenerateIndexingPolicy<DOBJ>::type>
53 typedef typename std::vector<DataLink<DOBJ, StoragePolicy>> DataLinkVector;
60 class ElemLinkRef :
public IndexingPolicy {
63 typedef typename ElemLinkVec::ElemLink ElemLink;
70 ElemLinkRef(
const ElemLinkRef& rhs );
72 ElemLinkRef& operator=(
const ElemLinkRef& rhs );
75 ElemLinkRef(
const ElemLinkVec& linkVect,
const ElemLink& link = ElemLink() );
77 using IndexingPolicy::index;
83 typename DataLinkVector::size_type shortRef()
const {
return m_shortRef; }
86 ElemLink elementLink()
const {
return ElemLink( dataID(), index(), m_ptr ); }
90 bool operator==(
const ElemLinkRef& rhs )
const {
91 return ( ( index() == rhs.index() ) && ( dataID() == rhs.dataID() ) );
93 bool operator<(
const ElemLinkRef& rhs )
const {
94 return ( ( index() < rhs.index() ) ||
95 ( ( index() == rhs.index() ) && ( dataID() < rhs.dataID() ) ) );
99 ElemLinkVec & m_linkVect;
100 ElementPointer m_ptr;
101 typename DataLinkVector::size_type m_shortRef;
107 struct Short2LongRef :
public std::unary_function<ElemLinkRef, ElemLink> {
108 ElemLink operator()(
const ElemLinkRef& shortRef )
const {
return shortRef.elementLink(); }
112 typedef typename std::vector<ElemLinkRef> RefVector;
113 RefVector m_shortRefs;
116 DataLinkVector m_hostDObjs;
128 typedef typename boost::transform_iterator_generator<
130 typedef typename boost::transform_iterator_generator<
138 typedef typename boost::transform_iterator_generator<
140 typedef typename boost::transform_iterator_generator<
149 return m_shortRefs[index].cptr();
158 return m_shortRefs[index].shortRef();
164 typename DataLinkVector::iterator
beginHostDObjs() {
return m_hostDObjs.begin(); }
165 typename DataLinkVector::iterator
endHostDObjs() {
return m_hostDObjs.end(); }
167 return m_hostDObjs.begin();
169 typename DataLinkVector::const_iterator
endHostDObjs()
const {
return m_hostDObjs.end(); }
171 typename DataLinkVector::const_iterator
findHostDObj(
const ElemLink& link )
const;
173 typename DataLinkVector::iterator
findHostDObj(
const ElemLink& link );
182 : m_shortRefs(
n, ElemLinkRef( *this, link ) ) {
187 : m_shortRefs(
n, ElemLinkRef( *this, link ) ) {
192 : m_shortRefs(
n, ElemLinkRef( *this, link ) ) {
199 : m_shortRefs(
vec.m_shortRefs ), m_hostDObjs(
vec.m_hostDObjs ) {}
201 template <
class InputIterator>
void assign( InputIterator first, InputIterator last ) {
258 m_shortRefs.push_back( ElemLinkRef( *
this, link ) );
261 removeHostObj(
back() );
262 m_shortRefs.pop_back();
272 m_hostDObjs.swap(
vec.m_hostDObjs );
273 m_shortRefs.swap(
vec.m_shortRefs );
284 void removeHostObj(
const ElemLink&
290 std::cout <<
"DUMMY removeHostDObj called for link " << link.dataID() <<
"/"
291 << link.index() << std::endl;
299 void addHostObj(
const ElemLink& link ) {
302 m_hostDObjs.push_back( DataLink<DOBJ, StoragePolicy>( link.dataID() ) );
304 std::cout <<
"addHostDObj added link " << link.dataID() <<
"/" << link.index()
310 typename RefVector::const_iterator shortIterFromLong(
const_iterator longIter )
const {
311 typename RefVector::const_iterator ret( m_shortRefs.begin() );
312 advance( ret, distance(
begin(), longIter ) );
314 std::cout <<
"shortIterFromLong(const version) called for " << longIter->dataID() <<
"/"
315 << longIter->index() <<
" advance by " << distance(
begin(), longIter )
316 <<
" result is " << ret->dataID() <<
"/" << ret->index() << std::endl;
322 typename RefVector::iterator shortIterFromLong(
iterator longIter ) {
323 typename RefVector::iterator ret( m_shortRefs.begin() );
324 advance( ret, distance(
begin(), longIter ) );
326 std::cout <<
"shortIterFromLong called for " << longIter->dataID() <<
"/"
327 << longIter->index() <<
" advance by " << distance(
begin(), longIter )
328 <<
" result is " << ret->dataID() <<
"/" << ret->index() << std::endl;
335 template <
class InputIterator>
ElementLinkVector( InputIterator first, InputIterator last );
336 template <
class InputIterator>
337 void insert(
iterator position, InputIterator first, InputIterator last );
341 friend bool operator== <>(
const ElemLinkVec&,
const ElemLinkVec& );
343 friend bool operator< <>(
const ElemLinkVec&,
const ElemLinkVec& );
346#ifndef STOREGATE_ELEMENTLINKVECTOR_HH
347# include "DataModel/ElementLinkVector.icc"
352template <
typename DOBJ,
class StoragePolicy,
class IndexingPolicy>
355 return ( lhs.m_shortRefs < rhs.m_shortRefs );
357template <
typename DOBJ,
class StoragePolicy,
class IndexingPolicy>
362template <
typename DOBJ,
class StoragePolicy,
class IndexingPolicy>
365 return ( lhs.m_shortRefs == rhs.m_shortRefs );
367template <
typename DOBJ,
class StoragePolicy,
class IndexingPolicy>
376template <
typename DOBJ,
class StoragePolicy,
class IndexingPolicy>
380 std::cout <<
"std::swap called for lhs " << std::hex << &lhs <<
" rhs " << &rhs << std::dec
bool operator>(const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &lhs, const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &rhs)
bool operator==(const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &lhs, const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &rhs)
bool operator!=(const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &lhs, const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &rhs)
bool operator<(const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &lhs, const ElementLinkVector< DOBJ, StoragePolicy, IndexingPolicy > &rhs)
a vector of "compact" element links. It turns the host data object key into an index....
reverse_iterator rbegin()
iterator erase(iterator position)
const_reference back() const
void push_back(const ElemLink &link)
DataLinkVector::const_iterator endHostDObjs() const
boost::transform_iterator_generator< Short2LongRef, typenameRefVector::const_iterator >::type const_iterator
RefVector::difference_type difference_type
iterator insert(iterator position, const ElemLink &link)
DataLinkVector::const_iterator findHostDObj(const ElemLink &link) const
find the host of an element. Returns endHostDObjs() if not found
boost::transform_iterator_generator< Short2LongRef, typenameRefVector::reverse_iterator >::type reverse_iterator
boost::transform_iterator_generator< Short2LongRef, typenameRefVector::iterator >::type iterator
ElemLink::ElementConstPointer ElementConstPointer
const_reverse_iterator rend() const
void insert(iterator position, size_type n, const ElemLink &link)
ElementLinkVector(int n, const ElemLink &link=ElemLink())
RefVector::allocator_type allocator_type
DataLinkVector::iterator findHostDObj(const ElemLink &link)
find the host of an element. Returns endHostDObjs() if not found
const_reference front() const
ID_type elementDataID(size_type index) const
dataID (long ref) of an element, given its ElementLinkVector index. O(1)
void reserve(size_type n)
const_iterator begin() const
ElementLinkVector(long n, const ElemLink &link=ElemLink())
friend bool operator<(const ElemLinkVec &, const ElemLinkVec &)
access m_shortRefs
RefVector::size_type size_type
const ElemLink * const_pointer
DataLinkVector::size_type elementShortRef(size_type index) const
index of an element dobj in its ElementLinkVector host dobjs list . O(1)
boost::transform_iterator_generator< Short2LongRef, typenameRefVector::const_reverse_iterator >::type const_reverse_iterator
const_reverse_iterator rbegin() const
const_reference at(size_type n) const
size_type max_size() const
iterator erase(iterator first, iterator last)
ElemLink::ID_type ID_type
DataLinkVector::iterator beginHostDObjs()
const_reference operator[](size_type n) const
void swap(ElemLinkVec &vec)
ElementLinkVector(const ElemLinkVec &vec)
void assign(InputIterator first, InputIterator last)
friend bool operator==(const ElemLinkVec &, const ElemLinkVec &)
access m_shortRefs
const_iterator end() const
ElementLinkVector(size_type n)
DataLinkVector::iterator endHostDObjs()
ElementLinkVector(size_type n, const ElemLink &link=ElemLink())
ElemLink::index_type index_type
void resize(size_type sz, ElemLink &link)
size_type capacity() const
DataLinkVector::const_iterator beginHostDObjs() const
void assign(size_type n, const ElemLink &link)
index_type elementIndex(size_type index) const
host index of an element, given its ElementLinkVector index. O(1)
ElementConstPointer elementCPtr(size_type index) const
pointer to an element, given its ElementLinkVector index. O(1)
a persistable pointer to an element of a STORABLE (data object)
IndexingPolicy::ElementConstPointer ElementConstPointer
IndexingPolicy::ElementPointer ElementPointer
IndexingPolicy::index_type index_type