Victor
 All Data Structures Functions Variables Friends Pages
Traceback.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __Traceback_H__
18 #define __Traceback_H__
19 
20 #include <Debug.h>
21 #include <iostream>
22 
23 namespace Victor { namespace Align2{
24 
30  class Traceback {
31  public:
32 
33  // CONSTRUCTORS:
34 
36 
37  Traceback() : i(-1), j(-1) {
38  }
39 
41 
42  Traceback(int i, int j) : i(i), j(j) {
43  }
44 
46 
47  Traceback(const Traceback &orig) {
48  copy(orig);
49  }
50 
52 
53  virtual ~Traceback() {
54  }
55 
56 
57  // OPERATORS:
58 
60  Traceback& operator =(const Traceback &orig);
61 
63  friend bool operator ==(const Traceback &left, const Traceback &right);
64 
65 
66  // PREDICATES:
67 
69  static bool isInvalidTraceback(const Traceback &tb);
70 
73 
75  virtual bool compare(const Traceback &other) const;
76 
77 
78  // MODIFIERS:
79 
81  virtual void copy(const Traceback &orig);
82 
84  virtual Traceback* newCopy();
85 
86 
87  // ATTRIBUTES:
88 
89  int i;
90  int j;
91 
92 
93  protected:
94 
95 
96  private:
97 
98  };
99 
100  // -----------------------------------------------------------------------------
101  // Traceback
102  // -----------------------------------------------------------------------------
103 
104  // OPERATORS:
105 
106  inline Traceback&
108  if (&orig != this)
109  copy(orig);
110  POSTCOND((orig == *this), exception);
111  return *this;
112  }
113 
114  inline bool
115  operator ==(const Traceback &left, const Traceback &right) {
116  return left.compare(right);
117  }
118 
119 
120  // PREDICATES:
121 
122  inline bool
124  return ((tb.i < 0) || (tb.j < 0));
125  }
126 
127  inline Traceback
129  Traceback tb;
130  tb.i = -1;
131  tb.j = -1;
132  return tb;
133  }
134 
135  inline bool
136  Traceback::compare(const Traceback &other) const {
137  return ((i == other.i) && (j == other.j));
138  }
139 
140 
141  // MODIFIERS:
142 
143  inline void
144  Traceback::copy(const Traceback &orig) {
145  i = orig.i;
146  j = orig.j;
147  }
148 
149  inline Traceback*
151  Traceback *tmp = new Traceback(*this);
152  return tmp;
153  }
154 
155 }} // namespace
156 
157 #endif
friend bool operator==(const Traceback &left, const Traceback &right)
Comparison operator.
Definition: Traceback.h:115
virtual ~Traceback()
Destructor.
Definition: Traceback.h:53
virtual void copy(const Traceback &orig)
Copy orig object to this object ("deep copy").
Definition: Traceback.h:144
int j
Position (column).
Definition: Traceback.h:90
virtual Traceback * newCopy()
Construct a new "deep copy" of this object.
Definition: Traceback.h:150
virtual bool compare(const Traceback &other) const
Return true if other and this object are equivalent.
Definition: Traceback.h:136
Traceback()
Default constructor.
Definition: Traceback.h:37
int i
Position (row).
Definition: Traceback.h:89
static bool isInvalidTraceback(const Traceback &tb)
Check if object is invalid.
Definition: Traceback.h:123
Reconstruct the path in the alignment matrix.
Definition: Traceback.h:30
static Traceback getInvalidTraceback()
Return invalid position.
Definition: Traceback.h:128
Traceback(const Traceback &orig)
Copy constructor.
Definition: Traceback.h:47
Traceback & operator=(const Traceback &orig)
Assignment operator.
Definition: Traceback.h:107
Traceback(int i, int j)
Constructor assigning i and j.
Definition: Traceback.h:42