17 |
/* along with this program; if not, write to the Free Software */ |
/* along with this program; if not, write to the Free Software */ |
18 |
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
19 |
|
|
|
/* $Id$ */ |
|
|
|
|
20 |
/** |
/** |
21 |
* \file coord.cpp |
* \file coord.cpp |
22 |
* \brief Eliot coordinate system |
* \brief Eliot coordinate system |
31 |
|
|
32 |
Coord::Coord() |
Coord::Coord() |
33 |
{ |
{ |
34 |
m_row = -1; |
m_row = -1; |
35 |
m_col = -1; |
m_col = -1; |
36 |
m_dir = HORIZONTAL; |
m_dir = HORIZONTAL; |
37 |
} |
} |
38 |
|
|
39 |
Coord::Coord(std::string str) |
Coord::Coord(const std::string &str) |
40 |
{ |
{ |
41 |
m_row = -1; |
m_row = -1; |
42 |
m_col = -1; |
m_col = -1; |
43 |
m_dir = HORIZONTAL; |
m_dir = HORIZONTAL; |
44 |
set(str); |
set(str); |
45 |
} |
} |
46 |
|
|
48 |
{ |
{ |
49 |
} |
} |
50 |
|
|
51 |
Direction |
Coord::Direction Coord::getDir() const |
|
Coord::getDir() const |
|
52 |
{ |
{ |
53 |
return m_dir; |
return m_dir; |
54 |
} |
} |
55 |
|
|
56 |
int |
int Coord::getRow() const |
|
Coord::getRow() const |
|
57 |
{ |
{ |
58 |
return m_row; |
return m_row; |
59 |
} |
} |
60 |
|
|
61 |
int |
int Coord::getCol() const |
|
Coord::getCol() const |
|
62 |
{ |
{ |
63 |
return m_col; |
return m_col; |
64 |
} |
} |
65 |
|
|
66 |
void |
void Coord::setRow(int iRow) |
|
Coord::setRow(int iRow) |
|
67 |
{ |
{ |
68 |
m_row = iRow; |
m_row = iRow; |
69 |
} |
} |
70 |
|
|
71 |
void |
void Coord::setCol(int iCol) |
|
Coord::setCol(int iCol) |
|
72 |
{ |
{ |
73 |
m_col = iCol; |
m_col = iCol; |
74 |
} |
} |
75 |
|
|
76 |
void |
void Coord::setDir(Direction iDir) |
|
Coord::setDir(Direction iDir) |
|
77 |
{ |
{ |
78 |
m_dir = iDir; |
m_dir = iDir; |
79 |
} |
} |
80 |
|
|
81 |
void |
void Coord::operator=(const Coord &iOther) |
|
Coord::operator=(const Coord &iOther) |
|
82 |
{ |
{ |
83 |
m_dir = iOther.m_dir; |
m_dir = iOther.m_dir; |
84 |
m_row = iOther.m_row; |
m_row = iOther.m_row; |
85 |
m_col = iOther.m_col; |
m_col = iOther.m_col; |
86 |
} |
} |
87 |
|
|
88 |
void |
void Coord::set(const std::string &str) |
|
Coord::set(std::string str) |
|
89 |
{ |
{ |
90 |
char l[4]; |
char l[4]; |
91 |
int col,row; |
int col; |
92 |
|
|
93 |
if (sscanf(str.c_str(), "%1[a-oA-O]%2d", l, &col) == 2) |
if (sscanf(str.c_str(), "%1[a-oA-O]%2d", l, &col) == 2) |
94 |
{ |
{ |
95 |
setDir(HORIZONTAL); |
setDir(HORIZONTAL); |
96 |
} |
} |
97 |
else if (sscanf(str.c_str(), "%2d%1[a-oA-O]", &col, l) == 2) |
else if (sscanf(str.c_str(), "%2d%1[a-oA-O]", &col, l) == 2) |
98 |
{ |
{ |
99 |
setDir(VERTICAL); |
setDir(VERTICAL); |
100 |
} |
} |
101 |
else |
else |
102 |
{ |
{ |
103 |
col = 1; |
col = 1; |
104 |
l[0] = 'A'; |
l[0] = 'A'; |
105 |
} |
} |
106 |
row = toupper(*l) - 'A' + 1; |
int row = toupper(*l) - 'A' + 1; |
107 |
setCol(col); |
setCol(col); |
108 |
setRow(row); |
setRow(row); |
109 |
} |
} |
110 |
|
|
111 |
std::string |
std::string Coord::toString() const |
|
Coord::toString() const |
|
112 |
{ |
{ |
113 |
std::string rs(""); |
std::string rs = ""; |
114 |
|
|
115 |
if (m_row == -1 || m_col == -1) |
if (m_row == -1 || m_col == -1) |
116 |
return rs; |
return rs; |
117 |
|
|
118 |
if (getDir() == HORIZONTAL) |
if (getDir() == HORIZONTAL) |
119 |
{ |
{ |
131 |
return rs; |
return rs; |
132 |
} |
} |
133 |
|
|
134 |
|
|
135 |
/// Local Variables: |
/// Local Variables: |
136 |
/// mode: hs-minor |
/// mode: hs-minor |
137 |
/// c-basic-offset: 4 |
/// c-basic-offset: 4 |