bpp-seq3  3.0.0
CoreSymbolList.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_CORESYMBOLLIST_H
6 #define BPP_SEQ_CORESYMBOLLIST_H
7 
8 #include <Bpp/Clonable.h>
9 
10 #include "Alphabet/Alphabet.h"
11 
12 // From the STL:
13 #include <string>
14 #include <vector>
15 #include <algorithm>
16 #include <iostream>
17 #include <memory>
18 
19 namespace bpp
20 {
28  public virtual Clonable
29 {
30 public:
36  CruxSymbolListInterface* clone() const override = 0;
39  // Class destructor
41 
42 public:
49  virtual std::shared_ptr<const Alphabet> getAlphabet() const = 0;
50 
57  virtual const Alphabet& alphabet() const = 0;
58 
64  virtual size_t size() const = 0;
65 
74  virtual std::string toString() const = 0;
75 
87  virtual void deleteElement(size_t pos) = 0;
88 
95  virtual void deleteElements(size_t pos, size_t len) = 0;
96 
112  virtual void shuffle() = 0;
122  virtual double getStateValueAt(size_t position, int state) const = 0;
123 
133  virtual double operator()(size_t position, int state) const = 0;
134 };
135 
136 
141 template<class T>
143  public virtual CruxSymbolListInterface
144 {
145 public:
151  TemplateCoreSymbolListInterface* clone() const override = 0;
154  // Class destructor
156 
157 public:
170  virtual void setContent(const std::vector<T>& list) = 0;
171 
172  virtual const std::vector<T>& getContent() const = 0;
173 
187  virtual void addElement(const T& c) = 0;
188 
195  virtual void addElement(size_t pos, const T& c) = 0;
196 
203  virtual void setElement(size_t pos, const T& c) = 0;
204 
210  virtual const T& getElement(size_t pos) const = 0;
211 
230  virtual const T& getValue(size_t pos) const = 0;
231 
238  virtual const T& operator[](size_t pos) const = 0;
239 
246  virtual T& operator[](size_t pos) = 0;
247 
249 };
250 
253 
254 
255 template<class T>
257 {
258 private:
260 
261 public:
263  list_(list) {}
264 
266 
268  {
269  list_ = slee.list_;
270  return *this;
271  }
272 
274 
275 public:
277  virtual const TemplateCoreSymbolListInterface<T>* getCoreSymbolList() const { return list_; }
278 };
279 
280 
281 template<class T>
284 {
285 private:
286  size_t pos_;
287  size_t len_;
288 
289 public:
291  CoreSymbolListEditionEvent<T>(list), pos_(pos), len_(len) {}
292 
293 public:
294  virtual size_t getPosition() const { return pos_; }
295  virtual size_t getLength() const { return len_; }
296 };
297 
298 
299 template<class T>
302 {
303 private:
304  size_t pos_;
305  size_t len_;
306 
307 public:
309  CoreSymbolListEditionEvent<T>(list), pos_(pos), len_(len) {}
310 
311 public:
312  virtual size_t getPosition() const { return pos_; }
313  virtual size_t getLength() const { return len_; }
314 };
315 
316 
317 template<class T>
320 {
321 private:
322  size_t begin_;
323  size_t end_;
324 
325 public:
327  CoreSymbolListEditionEvent<T>(list), begin_(begin), end_(end) {}
328 
329 public:
330  virtual size_t getBegin() const { return begin_; }
331  virtual size_t getEnd() const { return end_; }
332 };
333 
334 template<class T>
336  public virtual Clonable
337 {
338 public:
340 
341  virtual CoreSymbolListListener* clone() const = 0;
342 
343 public:
344  virtual bool isRemovable() const = 0;
345  virtual bool isShared() const = 0;
346  virtual void beforeSequenceChanged(const CoreSymbolListEditionEvent<T>& event) = 0;
347  virtual void afterSequenceChanged(const CoreSymbolListEditionEvent<T>& event) = 0;
351  virtual void afterSequenceDeleted(const CoreSymbolListDeletionEvent<T>& event) = 0;
354 };
355 
356 
369 template<class T>
371  public virtual TemplateCoreSymbolListInterface<T>
372 {
373 public:
379  virtual TemplateEventDrivenCoreSymbolListInterface* clone() const override = 0;
382  // Class destructor
384 
385 public:
391  virtual size_t getNumberOfListeners() const = 0;
392 
393  virtual const CoreSymbolListListener<T>& listener(size_t i) const = 0;
394 
395  virtual std::shared_ptr<const CoreSymbolListListener<T>> getListener(size_t i) const = 0;
396 
397  virtual CoreSymbolListListener<T>& listener(size_t i) = 0;
398 
399  virtual std::shared_ptr<CoreSymbolListListener<T>> getListener(size_t i) = 0;
400 
402 
404 
405 protected:
406  virtual void beforeSequenceChanged(const CoreSymbolListEditionEvent<T>& event) = 0;
407 
408  virtual void afterSequenceChanged(const CoreSymbolListEditionEvent<T>& event) = 0;
409 
412 
414  virtual void afterSequenceDeleted(const CoreSymbolListDeletionEvent<T>& event) = 0;
415 
418 
420 
422 
424 
426 
428 
430 
432 
434 
437 protected:
438  virtual void propagateEvents(bool yn) = 0;
439  virtual bool propagateEvents() const = 0;
440 };
441 
444 } // end of namespace bpp.
445 #endif // BPP_SEQ_CORESYMBOLLIST_H
The Alphabet interface.
Definition: Alphabet.h:99
virtual size_t getPosition() const
virtual size_t getLength() const
CoreSymbolListDeletionEvent(TemplateCoreSymbolListInterface< T > *list, size_t pos, size_t len)
CoreSymbolListEditionEvent(const CoreSymbolListEditionEvent< T > &slee)
CoreSymbolListEditionEvent< T > & operator=(const CoreSymbolListEditionEvent< T > &slee)
virtual TemplateCoreSymbolListInterface< T > * getCoreSymbolList()
CoreSymbolListEditionEvent(TemplateCoreSymbolListInterface< T > *list)
virtual const TemplateCoreSymbolListInterface< T > * getCoreSymbolList() const
TemplateCoreSymbolListInterface< T > * list_
CoreSymbolListInsertionEvent(TemplateCoreSymbolListInterface< T > *list, size_t pos, size_t len)
virtual size_t getPosition() const
virtual size_t getLength() const
virtual void afterSequenceChanged(const CoreSymbolListEditionEvent< T > &event)=0
virtual bool isShared() const =0
virtual bool isRemovable() const =0
virtual void beforeSequenceDeleted(const CoreSymbolListDeletionEvent< T > &event)=0
virtual void beforeSequenceInserted(const CoreSymbolListInsertionEvent< T > &event)=0
virtual void afterSequenceInserted(const CoreSymbolListInsertionEvent< T > &event)=0
virtual CoreSymbolListListener * clone() const =0
virtual void beforeSequenceSubstituted(const CoreSymbolListSubstitutionEvent< T > &event)=0
virtual void afterSequenceSubstituted(const CoreSymbolListSubstitutionEvent< T > &event)=0
virtual void afterSequenceDeleted(const CoreSymbolListDeletionEvent< T > &event)=0
virtual void beforeSequenceChanged(const CoreSymbolListEditionEvent< T > &event)=0
CoreSymbolListSubstitutionEvent(TemplateCoreSymbolListInterface< T > *list, size_t begin, size_t end)
The CruxSymbolList interface.
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
Get the alphabet associated to the list.
CruxSymbolListInterface * clone() const override=0
virtual void deleteElements(size_t pos, size_t len)=0
Remove the elements at position 'pos'.
virtual void deleteElement(size_t pos)=0
Remove the element at position 'pos'.
virtual void shuffle()=0
Randomly shuffle the content of the list, with linear complexity.
virtual size_t size() const =0
Get the number of elements in the list.
virtual std::string toString() const =0
Convert the list as a string.
virtual double operator()(size_t position, int state) const =0
get value of a state at a position
virtual const Alphabet & alphabet() const =0
Get the alphabet associated to the list.
virtual double getStateValueAt(size_t position, int state) const =0
get value of a state at a position
The CoreSymbolList interface.
virtual void addElement(const T &c)=0
Add a character to the end of the list.
virtual void setElement(size_t pos, const T &c)=0
Set the element at position 'pos' to character 'c'.
virtual const std::vector< T > & getContent() const =0
virtual void setContent(const std::vector< T > &list)=0
Set the whole content of the list.
TemplateCoreSymbolListInterface * clone() const override=0
virtual const T & getValue(size_t pos) const =0
checked access to a character in list.
virtual const T & getElement(size_t pos) const =0
Get the element at position 'pos' as a character.
virtual void addElement(size_t pos, const T &c)=0
Add a character at a certain position in the list.
virtual T & operator[](size_t pos)=0
Operator [] overloaded for quick access to a character in list.
virtual const T & operator[](size_t pos) const =0
Operator [] overloaded for quick access to a character in list.
Interface for event-driven CoreSymbolList objects.
virtual TemplateEventDrivenCoreSymbolListInterface * clone() const override=0
virtual void fireBeforeSequenceInserted(const CoreSymbolListInsertionEvent< T > &event)=0
virtual void beforeSequenceChanged(const CoreSymbolListEditionEvent< T > &event)=0
virtual void beforeSequenceDeleted(const CoreSymbolListDeletionEvent< T > &event)=0
virtual void fireAfterSequenceDeleted(const CoreSymbolListDeletionEvent< T > &event)=0
virtual void fireAfterSequenceInserted(const CoreSymbolListInsertionEvent< T > &event)=0
virtual void afterSequenceSubstituted(const CoreSymbolListSubstitutionEvent< T > &event)=0
virtual void removeCoreSymbolListListener(std::shared_ptr< CoreSymbolListListener< T >> listener)=0
virtual void fireAfterSequenceSubstituted(const CoreSymbolListSubstitutionEvent< T > &event)=0
virtual void afterSequenceInserted(const CoreSymbolListInsertionEvent< T > &event)=0
virtual void fireBeforeSequenceChanged(const CoreSymbolListEditionEvent< T > &event)=0
virtual void fireBeforeSequenceDeleted(const CoreSymbolListDeletionEvent< T > &event)=0
virtual void fireAfterSequenceChanged(const CoreSymbolListEditionEvent< T > &event)=0
virtual const CoreSymbolListListener< T > & listener(size_t i) const =0
virtual CoreSymbolListListener< T > & listener(size_t i)=0
virtual void addCoreSymbolListListener(std::shared_ptr< CoreSymbolListListener< T >> listener)=0
virtual std::shared_ptr< const CoreSymbolListListener< T > > getListener(size_t i) const =0
virtual void beforeSequenceSubstituted(const CoreSymbolListSubstitutionEvent< T > &event)=0
virtual std::shared_ptr< CoreSymbolListListener< T > > getListener(size_t i)=0
virtual void beforeSequenceInserted(const CoreSymbolListInsertionEvent< T > &event)=0
virtual size_t getNumberOfListeners() const =0
virtual void afterSequenceDeleted(const CoreSymbolListDeletionEvent< T > &event)=0
virtual void fireBeforeSequenceSubstituted(const CoreSymbolListSubstitutionEvent< T > &event)=0
virtual void afterSequenceChanged(const CoreSymbolListEditionEvent< T > &event)=0
This alphabet is used to deal NumericAlphabet.