bpp-seq3  3.0.0
UserAlphabetIndex1.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_ALPHABETINDEX_USERALPHABETINDEX1_H
6 #define BPP_SEQ_ALPHABETINDEX_USERALPHABETINDEX1_H
7 
8 
9 #include "AlphabetIndex1.h"
10 
11 // From the STL:
12 #include <vector>
13 
14 namespace bpp
15 {
20  public virtual AlphabetIndex1
21 {
22 private:
23  std::shared_ptr<const Alphabet> alph_;
24  std::vector<double> index_;
25 
26 public:
27  UserAlphabetIndex1(std::shared_ptr<const Alphabet> alph) :
28  alph_(alph),
29  index_(alph->getSize(), 0)
30  {}
31 
33  alph_(uAlph.alph_),
34  index_(uAlph.index_)
35  {}
36 
38  {
39  alph_ = uAlph.alph_;
40  index_ = uAlph.index_;
41  return *this;
42  }
43 
44  virtual ~UserAlphabetIndex1() {}
45 
46  UserAlphabetIndex1* clone() const override { return new UserAlphabetIndex1(*this); }
47 
48 public:
49  double getIndex(int state) const
50  {
51  return index_[alph_->getStateIndex(state) - 1];
52  }
53 
54  void setIndex(int state, double val)
55  {
56  index_[alph_->getStateIndex(state) - 1] = val;
57  }
58 
59  double getIndex(const std::string& state) const
60  {
61  return index_[alph_->getStateIndex(state) - 1];
62  }
63 
64  void setIndex(const std::string& state, double val)
65  {
66  index_[alph_->getStateIndex(state) - 1] = val;
67  }
68 
69  const std::vector<double>& indexVector() const { return index_; }
70 
71  std::shared_ptr<const Alphabet> getAlphabet() const { return alph_; }
72 
73  const Alphabet& alphabet() const { return *alph_; }
74 };
75 } // end of namespace bpp.
76 #endif // BPP_SEQ_ALPHABETINDEX_USERALPHABETINDEX1_H
One dimensionnal alphabet index interface.
The Alphabet interface.
Definition: Alphabet.h:99
Alphabet index given by user.
double getIndex(int state) const
Get the index associated to a state.
std::vector< double > index_
double getIndex(const std::string &state) const
Get the index associated to a state.
void setIndex(int state, double val)
UserAlphabetIndex1(std::shared_ptr< const Alphabet > alph)
const Alphabet & alphabet() const
Get the alphabet associated to this index.
void setIndex(const std::string &state, double val)
const std::vector< double > & indexVector() const
UserAlphabetIndex1 & operator=(const UserAlphabetIndex1 &uAlph)
std::shared_ptr< const Alphabet > getAlphabet() const
Get the alphabet associated to this index.
UserAlphabetIndex1 * clone() const override
std::shared_ptr< const Alphabet > alph_
UserAlphabetIndex1(const UserAlphabetIndex1 &uAlph)
This alphabet is used to deal NumericAlphabet.