Develop Biology
The language of life
bio::physical::Arrangement< TYPE > Class Template Reference

#include <Arrangement.h>

+ Inheritance diagram for bio::physical::Arrangement< TYPE >:
+ Collaboration diagram for bio::physical::Arrangement< TYPE >:

Public Member Functions

 Arrangement (const Index expectedSize=2)
 
virtual ~Arrangement ()
 
ByteStream Access (const Index index)
 
const ByteStream Access (const Index index) const
 
Index Add (const ByteStream content)
 
virtual bool AreEqual (Index internal, const ByteStream external) const
 
bool Erase (const Index index)
 
virtual const std::size_t GetStepSize () const
 
virtual TYPE OptimizedAccess (Index index)
 
virtual const TYPE OptimizedAccess (Index index) const
 
- Public Member Functions inherited from bio::Container
 Container (const Container &other)
 
 Container (const Index expectedSize=2, std::size_t stepSize=sizeof(ByteStream))
 
virtual ~Container ()
 
virtual ByteStream Access (const Index index)
 
virtual const ByteStream Access (const Index index) const
 
ByteStream Access (const SmartIterator itt)
 
virtual const ByteStream Access (const SmartIterator itt) const
 
virtual Index Add (const ByteStream content)
 
template<typename T >
std::vector< T > AsVector () const
 
virtual SmartIterator Begin () const
 
virtual void Clear ()
 
virtual IteratorConstructClassIterator (const Index index=InvalidIndex()) const
 
virtual SmartIterator End () const
 
bool Erase (const SmartIterator itt)
 
virtual bool Erase (Index index)
 
virtual void Expand ()
 
virtual Index GetAllocatedSize () const
 
virtual Index GetBeginIndex () const
 
virtual Index GetCapacity () const
 
virtual Index GetEndIndex () const
 
virtual Index GetNumberOfElements () const
 
bool Has (const ByteStream content) const
 
virtual void Import (const Container *other)
 
virtual Index Insert (const ByteStream content, const Index index)
 
virtual bool IsAllocated (const Index index) const
 
virtual bool IsFree (const Index index) const
 
virtual bool IsInRange (const Index index) const
 
virtual ByteStream operator[] (const Index index)
 
virtual const ByteStream operator[] (const Index index) const
 
virtual ByteStream operator[] (const SmartIterator itt)
 
virtual const ByteStream operator[] (const SmartIterator itt) const
 
Index SeekTo (const ByteStream content) const
 

Additional Inherited Members

- Protected Member Functions inherited from bio::Container
virtual bool AreEqual (Index internal, const ByteStream external) const
 
virtual Index GetNextAvailableIndex ()
 
virtual const std::size_t GetStepSize () const
 
- Protected Attributes inherited from bio::Container
std::deque< Indexm_deallocated
 
Index m_firstFree
 
Index m_size
 
unsigned char * m_store
 
Iteratorm_tempItt
 

Detailed Description

template<typename TYPE>
class bio::physical::Arrangement< TYPE >

Arrangements provide a more memory-efficient interface of the Container interface for a single type.

Template Parameters
TYPE

Definition at line 35 of file Arrangement.h.

Constructor & Destructor Documentation

◆ Arrangement()

template<typename TYPE >
bio::physical::Arrangement< TYPE >::Arrangement ( const Index  expectedSize = 2)
inline
Parameters
expectedSize

Definition at line 43 of file Arrangement.h.

44 :
46 expectedSize,
47 sizeof(TYPE))
48 {
49
50 }
Container(const Index expectedSize=2, std::size_t stepSize=sizeof(ByteStream))
Definition: Container.cpp:29

◆ ~Arrangement()

template<typename TYPE >
virtual bio::physical::Arrangement< TYPE >::~Arrangement ( )
inlinevirtual

Definition at line 55 of file Arrangement.h.

56 {
57
58 }

Member Function Documentation

◆ Access() [1/2]

template<typename TYPE >
ByteStream bio::physical::Arrangement< TYPE >::Access ( const Index  index)
inlinevirtual

Get access to an element. NOTE: THIS DOES NOT CHECK IF THE ELEMENT IsFree!!! Free checks can be done independently. This is done for speed.

Parameters
index
Returns
the value stored in *this at the given index.

Reimplemented from bio::Container.

Definition at line 75 of file Arrangement.h.

76 {
77 BIO_SANITIZE(this->IsAllocated(index), ,
78 return NULL)
79 TYPE* ret;
80 std::memcpy(
81 ret,
82 &this->m_store[index * sizeof(TYPE)],
83 sizeof(TYPE));
84 return *ret;
85 }
#define BIO_SANITIZE(test, success, failure)
unsigned char * m_store
Definition: Container.h:340
virtual bool IsAllocated(const Index index) const
Definition: Container.cpp:107

References BIO_SANITIZE, bio::Container::IsAllocated(), and bio::Container::m_store.

Referenced by bio::physical::Arrangement< TYPE >::AreEqual(), and bio::physical::Arrangement< TYPE >::OptimizedAccess().

◆ Access() [2/2]

template<typename TYPE >
const ByteStream bio::physical::Arrangement< TYPE >::Access ( const Index  index) const
inlinevirtual

Get access to an element. NOTE: THIS DOES NOT CHECK IF THE ELEMENT IsFree!!! Free checks can be done independently. This is done for speed.

Parameters
index
Returns
the value stored in *this at the given index.

Reimplemented from bio::Container.

Definition at line 87 of file Arrangement.h.

88 {
89 BIO_SANITIZE(this->IsAllocated(index), ,
90 return NULL)
91 TYPE* ret;
92 std::memcpy(
93 ret,
94 &this->m_store[index * sizeof(TYPE)],
95 sizeof(TYPE));
96 return *ret;
97 }

References BIO_SANITIZE, bio::Container::IsAllocated(), and bio::Container::m_store.

◆ Add()

template<typename TYPE >
Index bio::physical::Arrangement< TYPE >::Add ( const ByteStream  content)
inlinevirtual

Adds content to *this.

Parameters
content
Returns
the Index of the added content.

Reimplemented from bio::Container.

Definition at line 60 of file Arrangement.h.

61 {
62 BIO_SANITIZE(content.Is< TYPE >(), ,
63 return InvalidIndex())
64 Index ret = this->GetNextAvailableIndex();
65 BIO_SANITIZE(ret, ,
66 return InvalidIndex())
67 TYPE toAdd = content;
68 std::memcpy(
69 &this->m_store[ret * sizeof(TYPE)],
70 &toAdd,
71 sizeof(TYPE));
72 return ret;
73 }
virtual Index GetNextAvailableIndex()
Definition: Container.cpp:329
uint32_t Index
Definition: Types.h:57
const Index InvalidIndex()
Definition: Types.cpp:26

References BIO_SANITIZE, bio::Container::GetNextAvailableIndex(), bio::InvalidIndex(), bio::ByteStream::Is(), and bio::Container::m_store.

Referenced by bio::chemical::Atom::FormBondImplementation().

◆ AreEqual()

template<typename TYPE >
virtual bool bio::physical::Arrangement< TYPE >::AreEqual ( Index  internal,
const ByteStream  external 
) const
inlinevirtual

To make comparisons easier and reduce the work needed to optimize *this, children can define a comparison method which will be used for all searches.

Parameters
internal
external
Returns
whether or not the contents of *this at the given Index match the given datum.

Reimplemented from bio::Container.

Reimplemented in bio::physical::Line.

Definition at line 113 of file Arrangement.h.

117 {
118 BIO_SANITIZE(external.Is< TYPE >(), ,
119 return false)
120 return this->Access(internal).template As< TYPE >() == external.template As< TYPE >();
121 }
ByteStream Access(const Index index)
Definition: Arrangement.h:75

References bio::physical::Arrangement< TYPE >::Access(), BIO_SANITIZE, and bio::ByteStream::Is().

◆ Erase()

template<typename TYPE >
bool bio::physical::Arrangement< TYPE >::Erase ( const Index  index)
inlinevirtual

Removes content from *this.

Parameters
index
Returns
whether or not the erasure was successful.

Reimplemented from bio::Container.

Definition at line 99 of file Arrangement.h.

100 {
101 BIO_SANITIZE(this->IsAllocated(index), ,
102 return false)
103 TYPE* toDelete;
104 std::memcpy(
105 toDelete,
106 &this->m_store[index * sizeof(TYPE)],
107 sizeof(TYPE));
108 delete toDelete;
109 this->m_deallocated.push_back(index);
110 return true;
111 }
std::deque< Index > m_deallocated
Definition: Container.h:344

References BIO_SANITIZE, bio::Container::IsAllocated(), bio::Container::m_deallocated, and bio::Container::m_store.

◆ GetStepSize()

template<typename TYPE >
virtual const std::size_t bio::physical::Arrangement< TYPE >::GetStepSize ( ) const
inlinevirtual

Please override this to return the size of the type your Container interface is working with.

Returns
the size of the data type stored in *this.

Reimplemented from bio::Container.

Definition at line 147 of file Arrangement.h.

148 {
149 return sizeof(TYPE);
150 }

◆ OptimizedAccess() [1/2]

template<typename TYPE >
virtual TYPE bio::physical::Arrangement< TYPE >::OptimizedAccess ( Index  index)
inlinevirtual

Convenience wrapper for accessing without casting.

Parameters
index
Returns
the given position in *this as a TYPE.

Definition at line 128 of file Arrangement.h.

129 {
130 return this->Access(index);
131 }

References bio::physical::Arrangement< TYPE >::Access().

Referenced by bio::chemical::Atom::AsBonded(), bio::chemical::Atom::BreakBondImplementation(), bio::chemical::Atom::FormBondImplementation(), bio::chemical::Atom::GetBonded(), and bio::chemical::Atom::GetBondType().

◆ OptimizedAccess() [2/2]

template<typename TYPE >
virtual const TYPE bio::physical::Arrangement< TYPE >::OptimizedAccess ( Index  index) const
inlinevirtual

Convenience wrapper for accessing without casting.

Parameters
index
Returns
the given position in *this as a TYPE.

Definition at line 138 of file Arrangement.h.

139 {
140 return this->Access(index).template As< TYPE >();
141 }

References bio::physical::Arrangement< TYPE >::Access().


The documentation for this class was generated from the following file: