bpp-seq3  3.0.0
SequenceContainer.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_SEQ_CONTAINER_SEQUENCECONTAINER_H
6 #define BPP_SEQ_CONTAINER_SEQUENCECONTAINER_H
7 
8 #include "SequenceData.h"
10 #include "../Sequence.h"
11 #include "../ProbabilisticSequence.h"
12 
13 // From the STL:
14 #include <string>
15 
16 namespace bpp
17 {
29 template<class SequenceType, class HashType = std::string>
31  public virtual TemplateSequenceDataInterface<HashType>
32 {
33 public:
36 
37 public:
47  createEmptyContainer() const override = 0;
48 
61  virtual const SequenceType& sequence(const HashType& sequenceKey) const override = 0;
62 
72  virtual void setSequence(const HashType& sequenceKey, std::unique_ptr<SequenceType>& sequencePtr) = 0;
73 
83  virtual void addSequence(const HashType& sequenceKey, std::unique_ptr<SequenceType>& sequencePtr) = 0;
84 
90  virtual std::unique_ptr<SequenceType> removeSequence(const HashType& sequenceKey) = 0;
91 
99  virtual const typename SequenceType::ElementType& valueAt(const HashType& sequenceKey, size_t sitePosition) const = 0;
100 
108  virtual typename SequenceType::ElementType& valueAt(const HashType& sequenceKey, size_t sitePosition) = 0;
109 
125  virtual const SequenceType& sequence(size_t sequencePosition) const override = 0;
126 
134  virtual void setSequence(size_t sequencePosition, std::unique_ptr<SequenceType>& sequencePtr) = 0;
135 
144  virtual void setSequence(size_t sequencePosition, std::unique_ptr<SequenceType>& sequencePtr, const HashType& sequenceKey) = 0;
145 
153  virtual void insertSequence(size_t sequencePosition, std::unique_ptr<SequenceType>& sequencePtr, const HashType& sequenceKey) = 0;
154 
160  virtual std::unique_ptr<SequenceType> removeSequence(size_t sequencePosition) = 0;
161 
169  virtual const typename SequenceType::ElementType& valueAt(size_t sequencePosition, size_t sitePosition) const = 0;
170 
178  virtual typename SequenceType::ElementType& valueAt(size_t sequencePosition, size_t sitePosition) = 0;
180 };
181 
182 // Aliases:
185 
186 template<class T>
188 {
189 private:
190  bool doDelete_;
191 
192 public:
194 
195 public:
196  void operator()(T* ptr) const
197  {
198  if (doDelete_) delete ptr;
199  }
200 
201  void on() { doDelete_ = true; }
202  void off() { doDelete_ = false; }
203 
204  bool isOn() const { return doDelete_; }
205 };
206 } // end of namespace bpp.
207 #endif // BPP_SEQ_CONTAINER_SEQUENCECONTAINER_H
void operator()(T *ptr) const
The SequenceContainer interface.
virtual void addSequence(const HashType &sequenceKey, std::unique_ptr< SequenceType > &sequencePtr)=0
Add a sequence to the container.
virtual const SequenceType::ElementType & valueAt(const HashType &sequenceKey, size_t sitePosition) const =0
Get the content of the dataset at a specific position (sequence key, site position).
virtual void setSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr)=0
Replace a sequence in the container.
virtual const SequenceType::ElementType & valueAt(size_t sequencePosition, size_t sitePosition) const =0
Get the content of the dataset at a specific position (sequence position, site position).
virtual std::unique_ptr< SequenceType > removeSequence(size_t sequencePosition)=0
Remove a sequence from the container.
virtual TemplateSequenceContainerInterface< SequenceType, HashType > * createEmptyContainer() const override=0
Return a copy of this container, but with no data inside.
virtual SequenceType::ElementType & valueAt(size_t sequencePosition, size_t sitePosition)=0
Get the content of the dataset at a specific position (sequence position, site position).
virtual std::unique_ptr< SequenceType > removeSequence(const HashType &sequenceKey)=0
Remove a sequence from the container.
virtual void insertSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr, const HashType &sequenceKey)=0
Insert a sequence in the container.
virtual void setSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr, const HashType &sequenceKey)=0
Replace a sequence in the container.
virtual SequenceType::ElementType & valueAt(const HashType &sequenceKey, size_t sitePosition)=0
Get the content of the dataset at a specific position (sequence key, site position).
virtual void setSequence(const HashType &sequenceKey, std::unique_ptr< SequenceType > &sequencePtr)=0
Replace a sequence in the container.
virtual const SequenceType & sequence(const HashType &sequenceKey) const override=0
Retrieve a sequence object from the container.
virtual const SequenceType & sequence(size_t sequencePosition) const override=0
Retrieve a sequence object from the container.
The SequenceData interface.
Definition: SequenceData.h:30
virtual const std::string & sequenceKey(size_t sequencePosition) const=0
Get the key associated to a given sequence.
This alphabet is used to deal NumericAlphabet.