summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschodet2004-05-02 04:38:40 +0000
committerschodet2004-05-02 04:38:40 +0000
commit266fc1e5a2933587dba65d1a2343480b27b1fcb2 (patch)
treee2eafaf88d492669cd78abc033fb2632707f5f02
parent811ebc5f5570b5d72ea4ac955d9dae80d5f7ab10 (diff)
Add: Point.
Mod: Hex: support de la detection d'erreur.
-rw-r--r--2004/i/nono/src/utils/hexa.cc51
-rw-r--r--2004/i/nono/src/utils/hexa.h3
-rw-r--r--2004/i/nono/src/utils/point.h130
3 files changed, 162 insertions, 22 deletions
diff --git a/2004/i/nono/src/utils/hexa.cc b/2004/i/nono/src/utils/hexa.cc
index fbcf4e9..236342b 100644
--- a/2004/i/nono/src/utils/hexa.cc
+++ b/2004/i/nono/src/utils/hexa.cc
@@ -28,24 +28,25 @@
static const char *digit2hexTbl_ = "0123456789abcdef";
// Table de conversion depuis l'hexa.
+#define hI hexInvalid
static const int hex2digitTbl_[] =
{
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 0-15 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 16-31 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 32-47 */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, /* 48-63 */
- -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 64-79 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-95 */
- -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 96-111 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 112-127 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 128-143 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 144-159 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 160-175 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 176-191 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 192-207 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 208-223 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 224-239 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 240-255 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 0-15 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 16-31 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 32-47 */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,hI,hI,hI,hI,hI,hI, /* 48-63 */
+ hI,10,11,12,13,14,15,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 64-79 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 80-95 */
+ hI,10,11,12,13,14,15,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 96-111 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 112-127 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 128-143 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 144-159 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 160-175 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 176-191 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 192-207 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 208-223 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 224-239 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 240-255 */
};
/// Converti un caractère hexa (0-9a-f) en chiffre (0-15).
@@ -66,17 +67,23 @@ digit2hex (int d)
int
hexSignedChar2int (const char *s)
{
- return (signed char) (hex2digit (s[0]) << 4
- | hex2digit (s[1]) << 0);
+ int h1 = hex2digit (s[0]);
+ int h0 = hex2digit (s[1]);
+ if (h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (signed char) (h1 << 4 | h0);
}
/// Décode un mot signé (2 octets).
int
hexSignedShort2int (const char *s)
{
- return (short) (hex2digit (s[0]) << 12
- | hex2digit (s[1]) << 8
- | hex2digit (s[2]) << 4
- | hex2digit (s[3]));
+ int h3 = hex2digit (s[0]);
+ int h2 = hex2digit (s[1]);
+ int h1 = hex2digit (s[2]);
+ int h0 = hex2digit (s[3]);
+ if (h3 == hexInvalid || h2 == hexInvalid || h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (short) (h3 << 12 | h2 << 8 | h1 << 4 | h0);
}
diff --git a/2004/i/nono/src/utils/hexa.h b/2004/i/nono/src/utils/hexa.h
index 54ee9dc..348f90d 100644
--- a/2004/i/nono/src/utils/hexa.h
+++ b/2004/i/nono/src/utils/hexa.h
@@ -25,6 +25,9 @@
//
// }}}
+/// Constante retournée pour une valeur invalide.
+const int hexInvalid = 1 << 24;
+
/// Converti un caractère hexa (0-9a-f) en chiffre (0-15).
int hex2digit (char c);
diff --git a/2004/i/nono/src/utils/point.h b/2004/i/nono/src/utils/point.h
new file mode 100644
index 0000000..b16d9e6
--- /dev/null
+++ b/2004/i/nono/src/utils/point.h
@@ -0,0 +1,130 @@
+#ifndef point_h
+#define point_h
+// point.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2004.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include <iostream>
+
+/// Structure repésentant un point.
+struct Point
+{
+ /// Coordonnées.
+ double x, y;
+ /// Constructeur.
+ Point (void) : x (0.0), y (0.0) { }
+ Point (double x_, double y_) : x (x_), y (y_) { }
+ //@{
+ /// Opérations.
+ Point &operator+= (const Point &rhs);
+ Point operator+ (const Point &rhs) const;
+ Point &operator-= (const Point &rhs);
+ Point operator- (const Point &rhs) const;
+ Point &operator*= (const Point &rhs);
+ Point operator* (const Point &rhs) const;
+ Point &operator*= (double rhs);
+ Point operator* (double rhs) const;
+ //@}
+};
+
+/// Sort sur un ostream.
+std::ostream &
+operator<< (std::ostream &os, const Point &p);
+
+// Inlines.
+
+/// Opérations.
+inline Point &
+Point::operator+= (const Point &rhs)
+{
+ x += rhs.x;
+ y += rhs.y;
+ return *this;
+}
+
+inline Point
+Point::operator+ (const Point &rhs) const
+{
+ Point p (*this);
+ p += rhs;
+ return p;
+}
+
+inline Point &
+Point::operator-= (const Point &rhs)
+{
+ x -= rhs.x;
+ y -= rhs.y;
+ return *this;
+}
+
+inline Point
+Point::operator- (const Point &rhs) const
+{
+ Point p (*this);
+ p -= rhs;
+ return p;
+}
+
+inline Point &
+Point::operator*= (const Point &rhs)
+{
+ x *= rhs.x;
+ y *= rhs.y;
+ return *this;
+}
+
+inline Point
+Point::operator* (const Point &rhs) const
+{
+ Point p (*this);
+ p *= rhs;
+ return p;
+}
+
+inline Point &
+Point::operator*= (double rhs)
+{
+ x *= rhs;
+ y *= rhs;
+ return *this;
+}
+
+inline Point
+Point::operator* (double rhs) const
+{
+ Point p (*this);
+ p *= rhs;
+ return p;
+}
+
+/// Sort sur un ostream.
+inline std::ostream &
+operator<< (std::ostream &os, const Point &p)
+{
+ os << p.x << ' ' << p.y;
+ return os;
+}
+
+#endif // point_h