0.08.01
C++ Open Travel Request Parsing Library
Toggle main menu visibility
Loading...
Searching...
No Matches
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
16
#include <
opentrep/OPENTREP_Types.hpp
>
17
#include <
opentrep/OPENTREP_Abstract.hpp
>
18
19
namespace
OPENTREP
{
20
21
// ////////////////////////////////////////////////////////////////////
35
static
const
DistanceErrorScaleArray_T
K_DEFAULT_ERROR_SCALE
=
36
{ {3, 6, 9, 14, 19} };
37
38
39
// ///////////////////////////////////////////////////////////////
43
struct
DistanceErrorRule
:
public
OPENTREP_Abstract
{
44
public
:
45
// ///////// Getters ////////
49
const
DistanceErrorScale_T
&
getDistanceErrorScale
()
const
{
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
:
129
DistanceErrorRule
(
const
DistanceErrorScale_T
& iScale)
130
: _scale (iScale) {
131
}
132
136
DistanceErrorRule
(
const
NbOfErrors_T
iSize,
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
147
DistanceErrorRule
(
const
DistanceErrorScaleArray_T
& iScaleArray) {
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
:
158
DistanceErrorRule
();
159
163
DistanceErrorRule
(
const
DistanceErrorRule
&);
164
168
virtual
~DistanceErrorRule
() {}
169
170
171
private
:
172
// /////// Attributes /////////
176
DistanceErrorScale_T
_scale;
177
};
178
179
}
180
#endif
// __OPENTREP_DISTANCEERRORRULE_HPP
OPENTREP_Abstract.hpp
OPENTREP_Types.hpp
OPENTREP
Definition
BasChronometer.cpp:10
OPENTREP::NbOfLetters_T
unsigned int NbOfLetters_T
Definition
OPENTREP_Types.hpp:705
OPENTREP::NbOfErrors_T
unsigned short NbOfErrors_T
Definition
OPENTREP_Types.hpp:720
OPENTREP::K_DEFAULT_ERROR_SCALE
static const DistanceErrorScaleArray_T K_DEFAULT_ERROR_SCALE
Definition
DistanceErrorRule.hpp:35
OPENTREP::DistanceErrorScale_T
std::map< NbOfLetters_T, NbOfErrors_T > DistanceErrorScale_T
Definition
OPENTREP_Types.hpp:725
OPENTREP::DistanceErrorScaleArray_T
boost::array< NbOfLetters_T, 5 > DistanceErrorScaleArray_T
Definition
OPENTREP_Types.hpp:730
OPENTREP::DistanceErrorRule
Definition
DistanceErrorRule.hpp:43
OPENTREP::DistanceErrorRule::getDistanceErrorScale
const DistanceErrorScale_T & getDistanceErrorScale() const
Definition
DistanceErrorRule.hpp:49
OPENTREP::DistanceErrorRule::toShortString
std::string toShortString() const
Definition
DistanceErrorRule.hpp:102
OPENTREP::DistanceErrorRule::getAllowedDistanceError
NbOfErrors_T getAllowedDistanceError(const NbOfLetters_T &iNbOfLetters) const
Definition
DistanceErrorRule.hpp:63
OPENTREP::DistanceErrorRule::DistanceErrorRule
DistanceErrorRule(const DistanceErrorScaleArray_T &iScaleArray)
Definition
DistanceErrorRule.hpp:147
OPENTREP::DistanceErrorRule::DistanceErrorRule
DistanceErrorRule(const NbOfErrors_T iSize, const NbOfLetters_T iScaleArray[])
Definition
DistanceErrorRule.hpp:136
OPENTREP::DistanceErrorRule::toString
std::string toString() const
Definition
DistanceErrorRule.hpp:118
OPENTREP::DistanceErrorRule::DistanceErrorRule
DistanceErrorRule(const DistanceErrorScale_T &iScale)
Definition
DistanceErrorRule.hpp:129
OPENTREP::DistanceErrorRule::fromStream
void fromStream(std::istream &)
Definition
DistanceErrorRule.hpp:96
OPENTREP::DistanceErrorRule::toStream
void toStream(std::ostream &ioOut) const
Definition
DistanceErrorRule.hpp:87
OPENTREP::OPENTREP_Abstract::OPENTREP_Abstract
OPENTREP_Abstract()
Definition
OPENTREP_Abstract.hpp:43
Generated on
for OpenTREP by
1.17.0