5 #ifndef BPP_SEQ_CONTAINER_VECTORPOSITIONEDCONTAINER_H
6 #define BPP_SEQ_CONTAINER_VECTORPOSITIONEDCONTAINER_H
105 throw Exception(
"VectorPositionedContainer::setSize : not possible to shorten the vector.");
127 const std::shared_ptr<T>
getObject(
size_t objectIndex)
const override
134 std::shared_ptr<T>
getObject(
size_t objectIndex)
override
141 const T&
object(
size_t objectIndex)
const override
162 void addObject(std::shared_ptr<T>
object,
size_t objectIndex,
bool checkPosition =
false)
167 if (checkPosition &&
positions_[objectIndex] !=
nullptr)
168 throw BadIntegerException(
"VectorPositionedContainer::addObject: object position already occupied in container ", (
int)objectIndex);
193 std::shared_ptr<T> ret =
positions_[objectIndex];
210 if (objectIndex + length >
getSize())
213 positions_.erase(
positions_.begin() +
static_cast<std::ptrdiff_t
>(objectIndex),
positions_.begin() +
static_cast<std::ptrdiff_t
>(objectIndex + length));
228 void addObject_(std::shared_ptr<T>
object,
size_t objectIndex,
bool checkPosition =
false)
const
233 if (checkPosition &&
positions_[objectIndex] !=
nullptr)
234 throw BadIntegerException(
"VectorPositionedContainer::setObject: object position already occupied in container ", (
int)objectIndex);
236 const_cast<std::vector<std::shared_ptr<T>
>& >(
positions_)[objectIndex] =
object;
The PositionedContainer interface.
The template VectorPositionedContainer class.
void setSize(size_t size) override
const T & object(size_t objectIndex) const override
Get a reference toward an object from the container.
std::shared_ptr< T > removeObject(size_t objectIndex) override
Extract and remove a object from the container.
size_t getSize() const override
the size
const std::shared_ptr< T > getObject(size_t objectIndex) const override
Retrieve an object from the container.
void deleteObject(size_t objectIndex) override
Delete an object from the container.
void appendObject(std::shared_ptr< T > object)
std::vector< std::shared_ptr< T > > positions_
VectorPositionedContainer< T > & operator=(const VectorPositionedContainer< T > &vsc)
copy where shared_ptr elements are shared
VectorPositionedContainer(const VectorPositionedContainer< T > &vsc)
T & object(size_t objectIndex) override
Get a reference toward an object from the container.
bool hasObjectWithPosition(size_t objectIndex) const
VectorPositionedContainer(size_t size=0)
Build a new empty container with specified size.
void addObject(std::shared_ptr< T > object, size_t objectIndex, bool checkPosition=false)
Add an object.
bool isAvailablePosition(size_t objectIndex) const
void insertObject(std::shared_ptr< T > object, size_t objectIndex)
Insert an object.
virtual ~VectorPositionedContainer()
void addObject_(std::shared_ptr< T > object, size_t objectIndex, bool checkPosition=false) const
std::shared_ptr< T > getObject(size_t objectIndex) override
Retrieve an object from the container.
virtual void nullify()
Nullify all elements.
std::shared_ptr< T > getObject_(size_t objectIndex) const
void deleteObjects(size_t objectIndex, size_t length)
void clear() override
Destroys the vector.
VectorPositionedContainer(const std::vector< std::shared_ptr< T >> &vs)
Build a new container from a set of positions.
VectorPositionedContainer< T > * clone() const override
This alphabet is used to deal NumericAlphabet.