summaryrefslogtreecommitdiff
path: root/i/marvin/src/data
diff options
context:
space:
mode:
authorhaller2005-11-17 11:10:17 +0000
committerhaller2005-11-17 11:10:17 +0000
commitda4a77ff094a0dc74414ec1de2cac08e8b7b60f4 (patch)
tree402c39246c164af44648fd98d2ea85500d58df58 /i/marvin/src/data
parent164d8870bc058450e6967a594dd9033d088316af (diff)
Importation brut du code récupérable de robert
Diffstat (limited to 'i/marvin/src/data')
-rw-r--r--i/marvin/src/data/Makefile.defs12
-rw-r--r--i/marvin/src/data/data_buffer.cc130
-rw-r--r--i/marvin/src/data/data_buffer.hh81
-rw-r--r--i/marvin/src/data/data_input.cc37
-rw-r--r--i/marvin/src/data/data_input.hh44
-rw-r--r--i/marvin/src/data/data_input_file.cc46
-rw-r--r--i/marvin/src/data/data_input_file.hh45
-rw-r--r--i/marvin/src/data/data_input_zlib.cc84
-rw-r--r--i/marvin/src/data/data_input_zlib.hh48
-rw-r--r--i/marvin/src/data/data_output.cc34
-rw-r--r--i/marvin/src/data/data_output.hh44
-rw-r--r--i/marvin/src/data/test_data.cc56
-rw-r--r--i/marvin/src/data/test_data_buffer.cc77
13 files changed, 738 insertions, 0 deletions
diff --git a/i/marvin/src/data/Makefile.defs b/i/marvin/src/data/Makefile.defs
new file mode 100644
index 0000000..31698f1
--- /dev/null
+++ b/i/marvin/src/data/Makefile.defs
@@ -0,0 +1,12 @@
+PROGRAMS += test_data test_data_buffer
+
+data_OBJECTS = data_input.o data_input_file.o data_input_zlib.o \
+ data_buffer.o data_output.o -lz
+
+test_data_OBJECTS = test_data.o $(data_OBJECTS)
+
+test_data_buffer_OBJECTS = test_data_buffer.o data_buffer.o
+
+test_data: $(test_data_OBJECTS)
+
+test_data_buffer: $(test_data_buffer_OBJECTS)
diff --git a/i/marvin/src/data/data_buffer.cc b/i/marvin/src/data/data_buffer.cc
new file mode 100644
index 0000000..c0d8cef
--- /dev/null
+++ b/i/marvin/src/data/data_buffer.cc
@@ -0,0 +1,130 @@
+// data_buffer.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Dufour Jérémy
+//
+// 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 "data_buffer.hh"
+
+#include <cstring> // std::memcpy
+#include <stdexcept> // std::runtime_error
+#include <algorithm> // std::swap
+
+static const unsigned min_size = 10;
+
+/// Constructeur par defaut
+DataBuffer::DataBuffer (void)
+ : size_ (min_size), headPos_ (0), tailPos_ (0), type_ (NoType)
+{
+ buffer_ = new uint8_t [size_];
+}
+
+/// Constructeur par recopie.
+DataBuffer::DataBuffer (const DataBuffer &d)
+ : headPos_ (0), type_ (NoType)
+{
+ unsigned sizeUse = d.tailPos_ - d.headPos_;
+ size_ = tailPos_ = sizeUse;
+ type_ = d.type_;
+ buffer_ = new uint8_t [size_];
+ std::memcpy (buffer_, &d.buffer_[headPos_], sizeUse);
+}
+
+/// Constructeur avec données.
+DataBuffer::DataBuffer (uint8_t *data, unsigned size, unsigned sizeAllocated,
+ dataType_e type)
+ : size_ (sizeAllocated), headPos_ (0), tailPos_ (size), type_ (type)
+{
+ if (!data || size > sizeAllocated)
+ throw std::invalid_argument ("Paramêtres invalides");
+ buffer_ = new uint8_t [size_];
+ std::memcpy (buffer_, data, tailPos_);
+}
+
+/// Surcharge de l'opérateur d'affectation
+DataBuffer &
+DataBuffer::operator= (const DataBuffer &d)
+{
+ DataBuffer b (d);
+ b.swap (*this);
+ return *this;
+}
+
+/// Lit des données. Même convention que le read de la libc, mais lance
+/// une exception en cas d'erreur.
+unsigned
+DataBuffer::read (uint8_t *buf, unsigned size)
+{
+ if (!buf)
+ throw std::invalid_argument ("Paramêtres invalides");
+ unsigned sizeTmp = tailPos_ - headPos_;
+ // On regarde combien de données peuvent être lues
+ if (size < sizeTmp)
+ sizeTmp = size;
+ std::memcpy (buf, &buffer_[headPos_], sizeTmp);
+ headPos_ += sizeTmp;
+ // Si il n'y a plus de données dans le buffer, on recommence de puis 0
+ if (headPos_ == tailPos_)
+ headPos_ = tailPos_ = 0;
+ return sizeTmp;
+}
+
+/// Écrit des données. Même convention que le write de la libc, mais lance
+/// une exception en cas d'erreur.
+void
+DataBuffer::write (const uint8_t *buf, unsigned size)
+{
+ // Vérification des paramêtres
+ if (!buf)
+ throw std::invalid_argument ("Parametres invalides");
+ // Agrandissement du buffer
+ grow (size);
+ // Ecriture des données
+ std::memcpy (&buffer_[tailPos_], buf, size);
+ tailPos_ += size;
+}
+
+/// Augmente la taille du buffer pour correspondre à size.
+void
+DataBuffer::grow (const unsigned size)
+{
+ // Taille restant non utilisé dans le buffer
+ unsigned tailleLibre = size_ - tailPos_;
+ // Si la taille du buffer n'est pas suffisante
+ if (tailleLibre < size)
+ {
+ // On augmente de deux fois la taille
+ DataBuffer d (&buffer_[headPos_], tailPos_ - headPos_,
+ 2 * size + size_, type_);
+ d.swap (*this);
+ }
+}
+
+/// Echange les buffers.
+void
+DataBuffer::swap (DataBuffer &d)
+{
+ std::swap (buffer_, d.buffer_);
+ std::swap (size_, d.size_);
+ std::swap (headPos_, d.headPos_);
+ std::swap (tailPos_, d.tailPos_);
+ std::swap (type_, d.type_);
+}
diff --git a/i/marvin/src/data/data_buffer.hh b/i/marvin/src/data/data_buffer.hh
new file mode 100644
index 0000000..3d2201d
--- /dev/null
+++ b/i/marvin/src/data/data_buffer.hh
@@ -0,0 +1,81 @@
+#ifndef data_buffer_hh
+#define data_buffer_hh
+// data_buffer.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Dufour Jérémy
+//
+// 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.
+//
+// Contact :
+// Web: %WEB%
+// Email: <dufourj@efrei.fr>
+// }}}
+
+#include "data_input.hh"
+#include "data_output.hh"
+
+#include <stdint.h> // uint8_t
+
+/// Classe contenant un buffer de données accessible en lecture et en
+/// écriture.
+class DataBuffer : public DataInput, public DataOutput
+{
+ public:
+ /// Type de données possible du buffer.
+ enum dataType_e {
+ NoType,
+ Image,
+ AskImage
+ };
+ private:
+ /// Buffer de données.
+ uint8_t *buffer_;
+ /// Taille alloué en mémoire pour le buffer.
+ unsigned size_;
+ /// Position du début et de la fin des données dans le buffer.
+ unsigned headPos_, tailPos_;
+ /// Type de données du buffer.
+ dataType_e type_;
+ /// Augmente la taille du buffer pour correspondre à size.
+ void grow (const unsigned size);
+ /// Echange les buffers.
+ void swap (DataBuffer &d);
+ public:
+ /// Constructeur par défaut.
+ DataBuffer (void);
+ /// Constructeur par recopie.
+ DataBuffer (const DataBuffer &d);
+ /// Constructeur avec données.
+ DataBuffer (uint8_t *data, unsigned size, unsigned sizeAllocated,
+ dataType_e type = NoType);
+ /// Destructeur par défaut.
+ ~DataBuffer (void) { delete [] buffer_; }
+ /// Surcharge de l'opérateur d'affectation
+ DataBuffer &operator= (const DataBuffer &d);
+ /// Lit des données. Même convention que le read de la libc, mais lance
+ /// une exception en cas d'erreur.
+ unsigned read (uint8_t *buf, unsigned size);
+ /// Écrit des données. Même convention que le write de la libc, mais lance
+ /// une exception en cas d'erreur.
+ void write (const uint8_t *buf, unsigned size);
+ /// Taille utile du buffer.
+ unsigned size (void) const { return tailPos_ - headPos_; }
+ /// Type de données du buffer.
+ dataType_e type (void) const { return type_; }
+ /// Change le type de données du buffer.
+ void setType (const dataType_e type) { type_ = type; }
+};
+#endif // data_buffer_hh
diff --git a/i/marvin/src/data/data_input.cc b/i/marvin/src/data/data_input.cc
new file mode 100644
index 0000000..cfc9b2a
--- /dev/null
+++ b/i/marvin/src/data/data_input.cc
@@ -0,0 +1,37 @@
+// data_input.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 "data_input.hh"
+
+/// Lit un caractère. Renvois -1 en cas de fin de fichier.
+int
+DataInput::getc (void)
+{
+ uint8_t c;
+ if (read (&c, 1) == 1)
+ return c & 0xff;
+ else
+ return -1;
+}
+
diff --git a/i/marvin/src/data/data_input.hh b/i/marvin/src/data/data_input.hh
new file mode 100644
index 0000000..ae59366
--- /dev/null
+++ b/i/marvin/src/data/data_input.hh
@@ -0,0 +1,44 @@
+#ifndef data_input_hh
+#define data_input_hh
+// data_input.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 <stdint.h>
+
+/// Classe d'entrée de données. C'est une sorte de istream simplifié
+/// permettant d'accéder à des données en lecture.
+class DataInput
+{
+ public:
+ /// Destructeur.
+ virtual ~DataInput (void) { }
+ /// Lit des données. Même convention que le read de la libc, mais lance
+ /// une exception en cas d'erreur.
+ virtual unsigned read (uint8_t *buf, unsigned size) = 0;
+ /// Lit un caractère. Renvois -1 en cas de fin de fichier.
+ int getc (void);
+};
+
+#endif // data_input_hh
diff --git a/i/marvin/src/data/data_input_file.cc b/i/marvin/src/data/data_input_file.cc
new file mode 100644
index 0000000..75b7500
--- /dev/null
+++ b/i/marvin/src/data/data_input_file.cc
@@ -0,0 +1,46 @@
+// data_input_file.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 "data_input_file.hh"
+#include "utils/errno_exception.hh"
+
+/// Constructeur.
+DataInputFile::DataInputFile (const std::string &name)
+ : name_ (name), file_ (name.c_str ())
+{
+ if (!file_)
+ throw errno_exception (name_, errno);
+}
+
+/// Lit des données. Même convention que le read de la libc, mais lance
+/// une exception en cas d'erreur.
+unsigned
+DataInputFile::read (uint8_t *buf, unsigned size)
+{
+ file_.read (reinterpret_cast<char *> (buf), size);
+ if (file_.bad ())
+ throw errno_exception (name_, errno);
+ return file_.gcount ();
+}
+
diff --git a/i/marvin/src/data/data_input_file.hh b/i/marvin/src/data/data_input_file.hh
new file mode 100644
index 0000000..29d22ca
--- /dev/null
+++ b/i/marvin/src/data/data_input_file.hh
@@ -0,0 +1,45 @@
+#ifndef data_input_file_hh
+#define data_input_file_hh
+// data_input_file.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 "data_input.hh"
+
+#include <string>
+#include <fstream>
+
+/// Data depuis un fichier standard.
+class DataInputFile : public DataInput
+{
+ std::string name_;
+ std::ifstream file_;
+ public:
+ /// Constructeur.
+ DataInputFile (const std::string &name);
+ /// Lit des données. Même convention que le read de la libc, mais lance
+ /// une exception en cas d'erreur.
+ unsigned read (uint8_t *buf, unsigned size);
+};
+
+#endif // data_input_file_hh
diff --git a/i/marvin/src/data/data_input_zlib.cc b/i/marvin/src/data/data_input_zlib.cc
new file mode 100644
index 0000000..f8f5322
--- /dev/null
+++ b/i/marvin/src/data/data_input_zlib.cc
@@ -0,0 +1,84 @@
+// data_input_zlib.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 "data_input_zlib.hh"
+
+#include <stdexcept>
+
+/// Constructeur.
+DataInputZlib::DataInputZlib (DataInput &data)
+ : data_ (data), inBuf_ (0)
+{
+ // Allocate input buffer.
+ inBuf_ = new uint8_t[inBufSize_];
+ // Initialise the zlib structure.
+ zStream_.next_in = 0;
+ zStream_.avail_in = 0;
+ zStream_.next_out = 0;
+ zStream_.avail_out = 0;
+ zStream_.zalloc = 0;
+ zStream_.zfree = 0;
+ zStream_.opaque = 0;
+ if (inflateInit2 (&zStream_, 32 + 15) != Z_OK)
+ {
+ delete[] inBuf_;
+ throw std::runtime_error (zStream_.msg);
+ }
+}
+
+/// Destructeur.
+DataInputZlib::~DataInputZlib (void)
+{
+ inflateEnd (&zStream_);
+ delete[] inBuf_;
+}
+
+/// Lit des données. Même convention que le read de la libc, mais lance
+/// une exception en cas d'erreur.
+unsigned
+DataInputZlib::read (uint8_t *buf, unsigned size)
+{
+ // Set output buffer.
+ zStream_.next_out = buf;
+ zStream_.avail_out = size;
+ // While not satisfied.
+ while (zStream_.avail_out)
+ {
+ // Feed more data.
+ if (zStream_.avail_in == 0)
+ {
+ zStream_.next_in = inBuf_;
+ zStream_.avail_in = data_.read (inBuf_, inBufSize_);
+ }
+ // Uncompress.
+ int r = inflate (&zStream_, Z_SYNC_FLUSH);
+ // Check result.
+ if (r == Z_STREAM_END)
+ return size - zStream_.avail_out;
+ else if (r != Z_OK)
+ throw std::runtime_error (zStream_.msg);
+ }
+ return size;
+}
+
diff --git a/i/marvin/src/data/data_input_zlib.hh b/i/marvin/src/data/data_input_zlib.hh
new file mode 100644
index 0000000..0b7cf5f
--- /dev/null
+++ b/i/marvin/src/data/data_input_zlib.hh
@@ -0,0 +1,48 @@
+#ifndef data_input_zlib_hh
+#define data_input_zlib_hh
+// data_input_zlib.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 "data_input.hh"
+
+#include <zlib.h>
+
+/// Data depuis un data compressé en zlib.
+class DataInputZlib : public DataInput
+{
+ DataInput &data_;
+ uint8_t *inBuf_;
+ static const unsigned inBufSize_ = 1024;
+ z_stream zStream_;
+ public:
+ /// Constructeur.
+ DataInputZlib (DataInput &data);
+ /// Destructeur.
+ ~DataInputZlib (void);
+ /// Lit des données. Même convention que le read de la libc, mais lance
+ /// une exception en cas d'erreur.
+ unsigned read (uint8_t *buf, unsigned size);
+};
+
+#endif // data_input_zlib_hh
diff --git a/i/marvin/src/data/data_output.cc b/i/marvin/src/data/data_output.cc
new file mode 100644
index 0000000..ed04e97
--- /dev/null
+++ b/i/marvin/src/data/data_output.cc
@@ -0,0 +1,34 @@
+// data_output.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 "data_output.hh"
+
+/// Écrit un caractère.
+void
+DataOutput::putc (int c)
+{
+ uint8_t uc = c;
+ write (&uc, 1);
+}
+
diff --git a/i/marvin/src/data/data_output.hh b/i/marvin/src/data/data_output.hh
new file mode 100644
index 0000000..7141892
--- /dev/null
+++ b/i/marvin/src/data/data_output.hh
@@ -0,0 +1,44 @@
+#ifndef data_output_hh
+#define data_output_hh
+// data_output.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 <stdint.h>
+
+/// Classe de sortie de données. C'est une sorte de ostream simplifié
+/// permettant d'accéder à des données en écriture.
+class DataOutput
+{
+ public:
+ /// Destructeur.
+ virtual ~DataOutput (void) { }
+ /// Écrit des données. Même convention que le write de la libc, mais lance
+ /// une exception en cas d'erreur.
+ virtual void write (const uint8_t *buf, unsigned size) = 0;
+ /// Écrit un caractère.
+ void putc (int c);
+};
+
+#endif // data_output_hh
diff --git a/i/marvin/src/data/test_data.cc b/i/marvin/src/data/test_data.cc
new file mode 100644
index 0000000..acc57ac
--- /dev/null
+++ b/i/marvin/src/data/test_data.cc
@@ -0,0 +1,56 @@
+// test_data.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// 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 "data_input_file.hh"
+#include "data_input_zlib.hh"
+
+#include <iostream>
+#include <stdexcept>
+#include <unistd.h>
+
+int
+main (int argc, char **argv)
+{
+ try
+ {
+ if (argc != 2)
+ throw std::runtime_error ("Syntax: test_data file");
+ DataInputFile f (argv[1]);
+ DataInputZlib z (f);
+ uint8_t buf[1024];
+ int r = z.read (buf, 1024);
+ while (r != 0)
+ {
+ write (1, buf, r);
+ r = z.read (buf, r);
+ }
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << e.what () << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
diff --git a/i/marvin/src/data/test_data_buffer.cc b/i/marvin/src/data/test_data_buffer.cc
new file mode 100644
index 0000000..36095ab
--- /dev/null
+++ b/i/marvin/src/data/test_data_buffer.cc
@@ -0,0 +1,77 @@
+// test_data_buffer.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Dufour Jérémy
+//
+// 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.
+//
+// Contact :
+// Web: %WEB%
+// Email: <dufourj@efrei.fr>
+// }}}
+
+#include "data_buffer.hh"
+
+#include <iostream>
+#include <stdexcept>
+#include <unistd.h>
+
+void
+check_data (uint8_t *b1, uint8_t *b2, unsigned size)
+{
+ for (unsigned i = 0; i < size; i ++)
+ if (b1[i] != b2[i])
+ throw std::runtime_error ("Erreur, buffers invalides");
+}
+
+int
+main (int argc, char **argv)
+{
+ try
+ {
+ DataBuffer d;
+ uint8_t bufW[100];
+ uint8_t bufR[150];
+ // Remplissage des buffers de test
+ memset (bufW, 42, 100);
+ memset (bufR, 1, 150);
+ // On en écrit 50
+ d.write (bufW, 50);
+ // On en lit 42
+ if (d.read (bufR, 42) == 42)
+ check_data (bufW, bufR, 42);
+ else
+ throw std::runtime_error ("Erreur de taille de données");
+ // On en re écrit 50
+ d.write (&bufW[50], 50);
+ unsigned pos = 42;
+ unsigned status;
+ // On lit jusqu'à la fin
+ do
+ {
+ status = d.read (&bufR[pos], 10);
+ if (status)
+ check_data (&bufW[pos], &bufR[pos], status);
+ pos += status;
+ } while (status);
+ // On vérifie que tout a été bien lue
+ }
+ catch (const std::runtime_error &r)
+ {
+ std::cerr << r.what () << std::endl;
+ return 1;
+ }
+ return 0;
+}