From 62440d5c986e06cbdd1cca6809c152da72d85855 Mon Sep 17 00:00:00 2001 From: schodet Date: Sat, 28 Feb 2004 19:25:28 +0000 Subject: Add: Config::get, pour simplifier la configuration des modules. --- 2004/i/nono/src/config/config.h | 22 ++++++++++++- 2004/i/nono/src/motor/asserv.cc | 52 +++++++----------------------- 2004/i/nono/src/motor/motor.cc | 34 +++++--------------- 2004/i/nono/src/motor/movement_goto.cc | 58 +++++++--------------------------- 2004/i/nono/src/motor/tracker.cc | 28 ++++------------ 5 files changed, 59 insertions(+), 135 deletions(-) (limited to '2004/i/nono/src') diff --git a/2004/i/nono/src/config/config.h b/2004/i/nono/src/config/config.h index a958844..f56d558 100644 --- a/2004/i/nono/src/config/config.h +++ b/2004/i/nono/src/config/config.h @@ -41,7 +41,6 @@ class Config int getNum (void); Config &operator>> (int &num) { num = getNum (); return *this; } const char *getId (void); - Config &operator>> (const char *&s) { s = getId (); return *this; } bool getBool (void); Config &operator>> (bool &b) { b = getBool (); return *this; } double getFloat (void); @@ -51,6 +50,11 @@ class Config void getEof (void); // Vérifie si le prochain token est... bool isId (const char *s); + /// Récupère la valeur associée à un identificateur \a id. Retourne \c + /// false si l'identificateur ne correspond pas, lance une exception si il + /// n'y a pas d'identificateur. + template + bool get (const char *id, T &v); // Retourne true si à la fin du fichier. bool eof (void); // Lance une erreur, on a pas trouvé ce qu'on voulais. @@ -61,4 +65,20 @@ class Config bool wrap (void); }; +/// Récupère la valeur associée à un identificateur \a id. Retourne \c +/// false si l'identificateur ne correspond pas, lance une exception si il +/// n'y a pas d'identificateur. +template +bool +Config::get (const char *id, T &v) +{ + if (isId (id)) + { + getId (); + *this >> v; + return true; + } + return false; +} + #endif // config_h diff --git a/2004/i/nono/src/motor/asserv.cc b/2004/i/nono/src/motor/asserv.cc index 2d005b9..40c5944 100644 --- a/2004/i/nono/src/motor/asserv.cc +++ b/2004/i/nono/src/motor/asserv.cc @@ -44,47 +44,17 @@ Asserv::Asserv (AsservTracker &asservTracker) Config rc ("rc/asserv"); while (!rc.eof ()) { - if (rc.isId ("accel")) - { - rc.getId (); - rc >> accel_; - } - else if (rc.isId ("kp")) - { - rc.getId (); - rc >> kp_; - } - else if (rc.isId ("ki")) - { - rc.getId (); - rc >> ki_; - } - else if (rc.isId ("kd")) - { - rc.getId (); - rc >> kd_; - } - else if (rc.isId ("tty")) - { - rc.getId (); - rc >> ttyname_; - } - else if (rc.isId ("stats")) - { - rc.getId (); - rc >> statMotor_; - } - else if (rc.isId ("counter")) - { - rc.getId (); - rc >> counter_; - } - else if (rc.isId ("buffer")) - { - rc.getId (); - rc >> inBufSize_; - } - else rc.noId (); + if (!( + rc.get ("accel", accel_) || + rc.get ("kp", kp_) || + rc.get ("ki", ki_) || + rc.get ("kd", kd_) || + rc.get ("tty", ttyname_) || + rc.get ("stats", statMotor_) || + rc.get ("counter", counter_) || + rc.get ("buffer", inBufSize_) + )) + rc.noId (); } // Ouvre le port série. serial_.open (ttyname_.c_str ()); diff --git a/2004/i/nono/src/motor/motor.cc b/2004/i/nono/src/motor/motor.cc index 615511c..d150688 100644 --- a/2004/i/nono/src/motor/motor.cc +++ b/2004/i/nono/src/motor/motor.cc @@ -43,32 +43,14 @@ Motor::Motor (void) Config rc ("rc/motor"); while (!rc.eof ()) { - if (rc.isId ("scale")) - { - rc.getId (); - rc >> s_; - } - else if (rc.isId ("speedscale")) - { - rc.getId (); - rc >> vs_; - } - else if (rc.isId ("accelscale")) - { - rc.getId (); - rc >> as_; - } - else if (rc.isId ("maxspeed")) - { - rc.getId (); - rc >> maxSpeed_; - } - else if (rc.isId ("minspeed")) - { - rc.getId (); - rc >> minSpeed_; - } - else rc.noId (); + if (!( + rc.get ("scale", s_) || + rc.get ("speedscale", vs_) || + rc.get ("accelscale", as_) || + rc.get ("maxspeed", maxSpeed_) || + rc.get ("minspeed", minSpeed_) + )) + rc.noId (); } asserv_.reset (); } diff --git a/2004/i/nono/src/motor/movement_goto.cc b/2004/i/nono/src/motor/movement_goto.cc index 1b0a683..794463c 100644 --- a/2004/i/nono/src/motor/movement_goto.cc +++ b/2004/i/nono/src/motor/movement_goto.cc @@ -39,52 +39,18 @@ MovementGotoParam::MovementGotoParam (void) Config rc ("rc/movement/goto"); while (!rc.eof ()) { - if (rc.isId ("epsilon")) - { - rc.getId (); - rc >> eps_;; - } - else if (rc.isId ("distance")) - { - rc.getId (); - rc >> dist_; - } - else if (rc.isId ("kpl")) - { - rc.getId (); - rc >> kpl_; - } - else if (rc.isId ("kpa")) - { - rc.getId (); - rc >> kpa_; - } - else if (rc.isId ("kil")) - { - rc.getId (); - rc >> kil_; - } - else if (rc.isId ("kia")) - { - rc.getId (); - rc >> kia_; - } - else if (rc.isId ("is")) - { - rc.getId (); - rc >> is_; - } - else if (rc.isId ("kdl")) - { - rc.getId (); - rc >> kdl_; - } - else if (rc.isId ("kda")) - { - rc.getId (); - rc >> kda_; - } - else rc.noId (); + if (!( + rc.get ("epsilon", eps_) || + rc.get ("distance", dist_) || + rc.get ("kpl", kpl_) || + rc.get ("kpa", kpa_) || + rc.get ("kil", kil_) || + rc.get ("kia", kia_) || + rc.get ("is", is_) || + rc.get ("kdl", kdl_) || + rc.get ("kda", kda_) + )) + rc.noId (); } } diff --git a/2004/i/nono/src/motor/tracker.cc b/2004/i/nono/src/motor/tracker.cc index 4229864..7b77dea 100644 --- a/2004/i/nono/src/motor/tracker.cc +++ b/2004/i/nono/src/motor/tracker.cc @@ -37,27 +37,13 @@ Tracker::Tracker (void) Config rc ("rc/tracker"); while (!rc.eof ()) { - if (rc.isId ("startx")) - { - rc.getId (); - rc >> posX_; - } - else if (rc.isId ("starty")) - { - rc.getId (); - rc >> posY_; - } - else if (rc.isId ("startangle")) - { - rc.getId (); - rc >> angle_; - } - else if (rc.isId ("footing")) - { - rc.getId (); - rc >> f_; - } - else rc.noId (); + if (!( + rc.get ("startx", posX_) || + rc.get ("starty", posY_) || + rc.get ("startangle", angle_) || + rc.get ("footing", f_) + )) + rc.noId (); } } -- cgit v1.2.3