Revision: 8434
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8434&view=rev
Author:   natepak
Date:     2009-11-22 20:16:52 +0000 (Sun, 22 Nov 2009)

Log Message:
-----------
Added the Timer class

Added Paths:
-----------
    code/gazebo/trunk/server/Timer.cc
    code/gazebo/trunk/server/Timer.hh

Added: code/gazebo/trunk/server/Timer.cc
===================================================================
--- code/gazebo/trunk/server/Timer.cc                           (rev 0)
+++ code/gazebo/trunk/server/Timer.cc   2009-11-22 20:16:52 UTC (rev 8434)
@@ -0,0 +1,73 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003  
+ *     Nate Koenig & Andrew Howard
+ *
+ *  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
+ *
+ */
+/* Desc: A timer class
+ * Author: Nate Koenig
+ * Date: 22 Nov 2009
+ */
+
+#include "Simulator.hh"
+#include "Timer.hh"
+
+using namespace gazebo;
+
+////////////////////////////////////////////////////////////////////////////////
+/// Constructor
+Timer::Timer(Type t)
+{
+  this->type = t;
+}
+        
+////////////////////////////////////////////////////////////////////////////////
+/// Destructor
+Timer::~Timer()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Start the timer
+void Timer::Start()
+{
+  if (this->type == SIM_TIMER)
+    this->start = Simulator::Instance()->GetSimTime();
+  else
+    this->start = Simulator::Instance()->GetWallTime();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the elapsed itme
+Time Timer::GetElapsed() const
+{
+  Time currentTime;
+
+  if (this->type == SIM_TIMER)
+    currentTime = Simulator::Instance()->GetSimTime();
+  else
+    currentTime = Simulator::Instance()->GetWallTime();
+
+  return currentTime - this->start;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the type of timer
+Timer::Type Timer::GetType()
+{
+  return this->type;
+}

Added: code/gazebo/trunk/server/Timer.hh
===================================================================
--- code/gazebo/trunk/server/Timer.hh                           (rev 0)
+++ code/gazebo/trunk/server/Timer.hh   2009-11-22 20:16:52 UTC (rev 8434)
@@ -0,0 +1,67 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003  
+ *     Nate Koenig & Andrew Howard
+ *
+ *  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
+ *
+ */
+/* Desc: A timer class
+ * Author: Nate Koenig
+ * Date: 22 Nov 2009
+ */
+
+#ifndef TIMER_HH
+#define TIMER_HH
+
+#include "Time.hh"
+
+namespace gazebo
+{
+  /// \brief A timer class
+  class Timer
+  {
+    public: enum Type {SIM_TIMER, REAL_TIMER};
+
+    /// \brief Constructor
+    /// \param t The type of timer (based on either the simulation or real
+    ///          time)
+    public: Timer(Type t);
+            
+    /// \brief Destructor
+    public: virtual ~Timer();
+
+    /// \brief Start the timer
+    public: void Start();
+
+    /// \brief Get the elapsed itme
+    public: Time GetElapsed() const;
+
+    /// \brief Get the type of timer
+    public: Type GetType();
+
+    public: friend std::ostream &operator<<(std::ostream &out, 
+                                            const gazebo::Timer &t)
+            {
+              out << t.GetElapsed();
+              return out;
+            }
+
+    private: Time start;
+    private: Type type;
+  };
+}
+
+#endif


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to