OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DistanceErrorRule.hpp
Go to the documentation of this file.
1 #ifndef __OPENTREP_DISTANCEERRORRULE_HPP
2 #define __OPENTREP_DISTANCEERRORRULE_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <istream>
9 #include <ostream>
10 #include <sstream>
11 #include <string>
12 #include <map>
13 // Boost Array
14 #include <boost/array.hpp>
15 // OpenTrep
18 
19 namespace OPENTREP {
20 
21  // ////////////////////////////////////////////////////////////////////
36  { {3, 6, 9, 14, 19} };
37 
38 
39  // ///////////////////////////////////////////////////////////////
44  public:
45  // ///////// Getters ////////
50  return _scale;
51  }
52 
53 
54  // ///////// Setters //////////
55 
56 
57  public:
58  // ///////// Business methods ////////
63  NbOfErrors_T getAllowedDistanceError (const NbOfLetters_T& iNbOfLetters) const {
64  NbOfErrors_T oNbOfErrors_T = 0;
65 
66  DistanceErrorScale_T::const_iterator itError =
67  _scale.lower_bound (iNbOfLetters);
68 
69  if (itError != _scale.end()) {
70  oNbOfErrors_T = itError->second;
71 
72  } else {
73  oNbOfErrors_T = iNbOfLetters / 4;
74  }
75 
76  return oNbOfErrors_T;
77  }
78 
79 
80  public:
81  // ///////// Display methods ////////
87  void toStream (std::ostream& ioOut) const {
88  ioOut << toString();
89  }
90 
96  void fromStream (std::istream&) {
97  }
98 
102  std::string toShortString() const {
103  std::ostringstream oStr;
104  NbOfLetters_T idx = 0;
105  for (DistanceErrorScale_T::const_iterator itError = _scale.begin();
106  itError != _scale.end(); ++itError, ++idx) {
107  if (idx != 0) {
108  oStr << ", ";
109  }
110  oStr << itError->second << ": " << itError->first;
111  }
112  return oStr.str();
113  }
114 
118  std::string toString() const {
119  std::ostringstream oStr;
120  oStr << toShortString();
121  return oStr.str();
122  }
123 
124 
125  public:
130  : _scale (iScale) {
131  }
132 
137  const NbOfLetters_T iScaleArray[]) {
138  for (NbOfErrors_T idx = 0; idx != iSize; ++idx) {
139  _scale.insert (DistanceErrorScale_T::value_type (iScaleArray[idx],
140  idx));
141  }
142  }
143 
148  for (NbOfErrors_T idx = 0; idx != iScaleArray.size(); ++idx) {
149  _scale.insert (DistanceErrorScale_T::value_type (iScaleArray[idx],
150  idx));
151  }
152  }
153 
154  private:
159 
164 
168  virtual ~DistanceErrorRule() {}
169 
170 
171  private:
172  // /////// Attributes /////////
176  DistanceErrorScale_T _scale;
177  };
178 
179 }
180 #endif // __OPENTREP_DISTANCEERRORRULE_HPP
std::string toShortString() const
void toStream(std::ostream &ioOut) const
boost::array< NbOfLetters_T, 5 > DistanceErrorScaleArray_T
static const DistanceErrorScaleArray_T K_DEFAULT_ERROR_SCALE
unsigned int NbOfLetters_T
std::map< NbOfLetters_T, NbOfErrors_T > DistanceErrorScale_T
DistanceErrorRule(const DistanceErrorScaleArray_T &iScaleArray)
const DistanceErrorScale_T & getDistanceErrorScale() const
unsigned short NbOfErrors_T
DistanceErrorRule(const DistanceErrorScale_T &iScale)
void fromStream(std::istream &)
DistanceErrorRule(const NbOfErrors_T iSize, const NbOfLetters_T iScaleArray[])
NbOfErrors_T getAllowedDistanceError(const NbOfLetters_T &iNbOfLetters) const