summaryrefslogtreecommitdiff
path: root/2004/i
diff options
context:
space:
mode:
authorschodet2004-04-22 21:55:20 +0000
committerschodet2004-04-22 21:55:20 +0000
commitb11f2892ee9d83845323feb1bf02007db613186d (patch)
tree01f2d78741e2e52ec3be5b1bace634f1c36defd5 /2004/i
parent66b1ebc00ffc4bc57ad80343576f7594f19dafe7 (diff)
Date: Design pattern singleton.
Diffstat (limited to '2004/i')
-rw-r--r--2004/i/nono/src/camera/dumpimage.cc1
-rw-r--r--2004/i/nono/src/camera/test_camera.cc1
-rw-r--r--2004/i/nono/src/date/date.cc10
-rw-r--r--2004/i/nono/src/date/date.h18
-rw-r--r--2004/i/nono/src/date/test_date.cc2
-rw-r--r--2004/i/nono/src/vision/test_vision.cc1
6 files changed, 12 insertions, 21 deletions
diff --git a/2004/i/nono/src/camera/dumpimage.cc b/2004/i/nono/src/camera/dumpimage.cc
index 90909af..f192546 100644
--- a/2004/i/nono/src/camera/dumpimage.cc
+++ b/2004/i/nono/src/camera/dumpimage.cc
@@ -12,7 +12,6 @@ int
main (int argc, char **argv)
{
Camera cam;
- Date date;
int w, h, d;
cam.getSize (w, h, d);
unsigned char *image = new unsigned char[w * h * d];
diff --git a/2004/i/nono/src/camera/test_camera.cc b/2004/i/nono/src/camera/test_camera.cc
index 9b616af..b975422 100644
--- a/2004/i/nono/src/camera/test_camera.cc
+++ b/2004/i/nono/src/camera/test_camera.cc
@@ -16,7 +16,6 @@ main (int argc, char **argv)
try
{
Camera cam;
- Date date;
sleep (5);
int w, h, d;
cam.getSize (w, h, d);
diff --git a/2004/i/nono/src/date/date.cc b/2004/i/nono/src/date/date.cc
index 25243ad..7553914 100644
--- a/2004/i/nono/src/date/date.cc
+++ b/2004/i/nono/src/date/date.cc
@@ -27,21 +27,11 @@
#include <sys/time.h>
#include <time.h>
-// Pointeur vers l'instance unique.
-Date *Date::m_instance = 0;
-
// Constructeur.
Date::Date (void)
{
m_start = getDate ();
m_round = -1;
- m_instance = this;
-}
-
-// Destructeur.
-Date::~Date (void)
-{
- m_instance = 0;
}
// Signale le début du match.
diff --git a/2004/i/nono/src/date/date.h b/2004/i/nono/src/date/date.h
index 1a40adc..c249dd2 100644
--- a/2004/i/nono/src/date/date.h
+++ b/2004/i/nono/src/date/date.h
@@ -29,15 +29,9 @@ class Date
{
// On travaille en millième de seconde, ça nous fait 24 jours dans un int.
int m_start, m_round;
- // Pointeur vers l'instance unique.
- static Date *m_instance;
public:
- // Constructeur.
- Date (void);
- // Destructeur.
- ~Date (void);
// Retourne une référence vers l'instance unique.
- static Date &getInstance (void) { return *m_instance; }
+ static Date &getInstance (void);
// Retourne la date depuis le début du match, en millième de secondes.
int round (void) { return m_round == -1 ? 0 : getDate () - m_round; }
// Retourne la date depuis le début du programme.
@@ -47,8 +41,18 @@ class Date
// Attend un nombre de millisecondes.
static void wait (int t);
private:
+ // Constructeur.
+ Date (void);
// Retourne la date système.
int getDate (void);
};
+// Retourne une référence vers l'instance unique.
+inline Date &
+Date::getInstance (void)
+{
+ static Date instance;
+ return instance;
+}
+
#endif // date_h
diff --git a/2004/i/nono/src/date/test_date.cc b/2004/i/nono/src/date/test_date.cc
index fe020e1..84b9738 100644
--- a/2004/i/nono/src/date/test_date.cc
+++ b/2004/i/nono/src/date/test_date.cc
@@ -30,7 +30,7 @@
int
main (void)
{
- Date d;
+ Date &d = Date::getInstance ();
sleep (2);
cout << "date " << d.start () << ' ' << d.round () << endl;
d.startRound ();
diff --git a/2004/i/nono/src/vision/test_vision.cc b/2004/i/nono/src/vision/test_vision.cc
index 9792910..4d1c993 100644
--- a/2004/i/nono/src/vision/test_vision.cc
+++ b/2004/i/nono/src/vision/test_vision.cc
@@ -13,7 +13,6 @@ extern "C" {
int
main (int argc, char **argv)
{
- Date d;
Image *i;
Camera *c;
Thresholds *t;