bpp-seq  2.2.0
Site.cpp
Go to the documentation of this file.
1 //
2 // File Site.cpp
3 // Author: Julien Dutheil
4 // Guillaume Deuchst
5 // Created on: Tuesday August 7 2003
6 //
7 
8 /*
9 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11 This software is a computer program whose purpose is to provide classes
12 for sequences analysis.
13 
14 This software is governed by the CeCILL license under French law and
15 abiding by the rules of distribution of free software. You can use,
16 modify and/ or redistribute the software under the terms of the CeCILL
17 license as circulated by CEA, CNRS and INRIA at the following URL
18 "http://www.cecill.info".
19 
20 As a counterpart to the access to the source code and rights to copy,
21 modify and redistribute granted by the license, users are provided only
22 with a limited warranty and the software's author, the holder of the
23 economic rights, and the successive licensors have only limited
24 liability.
25 
26 In this respect, the user's attention is drawn to the risks associated
27 with loading, using, modifying and/or developing or reproducing the
28 software by the user in light of its specific status of free software,
29 that may mean that it is complicated to manipulate, and that also
30 therefore means that it is reserved for developers and experienced
31 professionals having in-depth computer knowledge. Users are therefore
32 encouraged to load and test the software's suitability as regards their
33 requirements in conditions enabling the security of their systems and/or
34 data to be ensured and, more generally, to use and operate it in the
35 same conditions as regards security.
36 
37 The fact that you are presently reading this means that you have had
38 knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #include "Site.h"
42 
43 #include "StringSequenceTools.h"
44 
45 using namespace bpp;
46 
47 // From the STL:
48 #include <iostream>
49 
50 using namespace std;
51 
52 /****************************************************************************************/
53 
54 Site::Site(const Alphabet* alpha) : BasicSymbolList(alpha), position_(0) {}
55 
56 Site::Site(const Alphabet* alpha, int position) : BasicSymbolList(alpha), position_(position) {}
57 
58 Site::Site(const vector<string>& site, const Alphabet* alpha) throw (BadCharException) : BasicSymbolList(site, alpha), position_(0) {}
59 
60 Site::Site(const vector<string>& site, const Alphabet* alpha, int position) throw (BadCharException) : BasicSymbolList(site, alpha), position_(position) {}
61 
62 Site::Site(const vector<int>& site, const Alphabet* alpha) throw (BadIntException) : BasicSymbolList(site, alpha), position_(0) {}
63 
64 Site::Site(const vector<int>& site, const Alphabet* alpha, int position) throw (BadIntException) : BasicSymbolList(site, alpha), position_(position) {}
65 
66 /****************************************************************************************/
67 
68 Site::Site(const Site& site): BasicSymbolList(site), position_(site.getPosition()) {}
69 
71 {
72  SymbolList::operator=(s);
73  content_ = s.getContent();
74  position_ = s.getPosition();
75  return *this;
76 }
77 
78 /****************************************************************************************/
79 
80 bool operator==(const Site& site1, const Site& site2)
81 {
82  // Verify that site's size, position and content are equals
83  if(site1.size() != site2.size()) return false;
84  if(site1.getPosition() != site2.getPosition()) return false;
85  else {
86  for(unsigned int i = 0; i < site1.size(); i++) {
87  if(site1[i] != site2[i]) return false;
88  }
89  return true;
90  }
91 }
92 
93 /****************************************************************************************/
94 
95 bool operator<(const Site& site1, const Site& site2)
96 {
97  return site1.getPosition() < site2.getPosition();
98 }
99 
100 /****************************************************************************************/
101 
An alphabet exception thrown when trying to specify a bad char to the alphabet.
bool operator==(const Site &site1, const Site &site2)
Definition: Site.cpp:80
virtual int getPosition() const
Get the position of this site.
Definition: Site.h:162
This alphabet is used to deal NumericAlphabet.
The Alphabet interface.
Definition: Alphabet.h:130
Site(const Alphabet *alpha)
Build a new void Site object with the specified alphabet.
Definition: Site.cpp:54
STL namespace.
virtual const std::vector< int > & getContent() const
Get the whole content of the list as a vector of int.
Definition: SymbolList.h:352
int position_
The position associated to this site.
Definition: Site.h:68
bool operator<(const Site &site1, const Site &site2)
Definition: Site.cpp:95
A basic SymbolList object.
Definition: SymbolList.h:264
Site & operator=(const Site &s)
The assignment operator.
Definition: Site.cpp:70
std::vector< int > content_
The list content.
Definition: SymbolList.h:280
virtual size_t size() const
Get the number of elements in the list.
Definition: SymbolList.h:350
An alphabet exception thrown when trying to specify a bad int to the alphabet.
The Site class.
Definition: Site.h:61