[openrtm-commit:00656] r2301 - trunk/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2012年 2月 4日 (土) 02:45:46 JST


Author: n-ando
Date: 2012-02-04 02:45:45 +0900 (Sat, 04 Feb 2012)
New Revision: 2301

Modified:
   trunk/OpenRTM-aist/src/lib/rtm/RTObjectStateMachine.h
   trunk/OpenRTM-aist/src/lib/rtm/StateMachine.h
Log:
[incompat,header/impl,func] Now callback member function pointer list is std::vector.

Modified: trunk/OpenRTM-aist/src/lib/rtm/RTObjectStateMachine.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/RTObjectStateMachine.h	2012-02-03 17:31:23 UTC (rev 2300)
+++ trunk/OpenRTM-aist/src/lib/rtm/RTObjectStateMachine.h	2012-02-03 17:45:45 UTC (rev 2301)
@@ -23,7 +23,7 @@
 #include <rtm/SystemLogger.h>
 #include <coil/NonCopyable.h>
 #include <rtm/idl/RTCSkel.h>
-#include <rtm/StateMachine2.h>
+#include <rtm/StateMachine.h>
 #include <assert.h>
 #include <iostream>
 

Modified: trunk/OpenRTM-aist/src/lib/rtm/StateMachine.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/StateMachine.h	2012-02-03 17:31:23 UTC (rev 2300)
+++ trunk/OpenRTM-aist/src/lib/rtm/StateMachine.h	2012-02-03 17:45:45 UTC (rev 2301)
@@ -19,7 +19,8 @@
 #ifndef RTC_STATEMACHINE_H
 #define RTC_STATEMACHINE_H
 
-#include <rtm/RTC.h>
+#include <cassert>
+#include <vector>
 #include <coil/Mutex.h>
 #include <coil/Guard.h>
 
@@ -284,31 +285,54 @@
      */
     StateMachine(int num_of_state)
       : m_num(num_of_state),
-	m_entry (new Callback[m_num]),
-	m_predo (new Callback[m_num]),
-	m_do    (new Callback[m_num]),
-	m_postdo(new Callback[m_num]),
-	m_exit  (new Callback[m_num])
+        m_listener(NULL),
+        m_entry(m_num, (Callback)NULL),
+        m_predo(m_num, (Callback)NULL),
+        m_do(m_num, (Callback)NULL),
+        m_postdo(m_num, (Callback)NULL),
+        m_exit(m_num, (Callback)NULL),
+        m_transit(NULL)
     {
-      setNullFunc(m_entry,  NULL);
-      setNullFunc(m_do,     NULL);
-      setNullFunc(m_exit,   NULL);
-      setNullFunc(m_predo,  NULL);
-      setNullFunc(m_postdo, NULL);
-      m_transit = NULL;
     };
-    
 
     virtual ~StateMachine()
     {
-      delete [] m_entry;
-      delete [] m_predo;
-      delete [] m_do;
-      delete [] m_postdo;
-      delete [] m_exit;
     };
 
+    StateMachine(const StateMachine& other)
+      : m_num(other.m_num),
+        m_listener(other.m_listener),
+        m_entry (other.m_entry),
+        m_predo (other.m_predo),
+        m_do    (other.m_do),
+        m_postdo(other.m_postdo),
+        m_exit  (other.m_exit),
+        m_transit(other.m_transit),
+        m_states(other.m_states),
+        m_selftrans(other.m_selftrans)
+    {
+    }
 
+    StateMachine& operator=(const StateMachine& other)
+    {
+      StateMachine temp(other);
+      swap(temp);
+      return *this;
+    }
+
+    void swap(StateMachine& other)
+    {
+      std::swap(m_num,       other.m_num);
+      std::swap(m_listener,  other.m_listener);
+      std::swap(m_entry,     other.m_entry);
+      std::swap(m_predo,     other.m_predo);
+      std::swap(m_do,        other.m_do);
+      std::swap(m_postdo,    other.m_postdo);
+      std::swap(m_exit,      other.m_exit);
+      std::swap(m_transit,   other.m_transit);
+      std::swap(m_states,    other.m_states);
+      std::swap(m_selftrans, other.m_selftrans);
+    }
     /*!
      * @if jp
      * @brief NOP関数を登録する
@@ -355,6 +379,7 @@
      */
     void setListener(Listener* listener)
     {
+      assert(listener != NULL);
       m_listener = listener;
     }
     
@@ -384,7 +409,15 @@
      */
     bool setEntryAction(State state, Callback call_back)
     {
-      m_entry[state] = call_back;
+     try
+        {
+          m_entry.at(state) = call_back;
+        }
+      catch (...)
+        {
+          assert(false);
+          return false;
+        }
       return true;
     }
     
@@ -413,7 +446,15 @@
      */
     bool setPreDoAction(State state, Callback call_back)
     {
-      m_predo[state] = call_back;
+      try
+        {
+          m_predo.at(state) = call_back;
+        }
+      catch (...)
+        {
+          assert(false);
+          return false;
+        }
       return true;
     }
     
@@ -442,7 +483,15 @@
      */
     bool setDoAction(State state, Callback call_back)
     {
-      m_do[state] = call_back;
+      try
+        {
+          m_do.at(state) = call_back;
+        }
+      catch (...)
+        {
+          assert(false);
+          return false;
+        }
       return true;
     }
     
@@ -471,7 +520,15 @@
      */
     bool setPostDoAction(State state, Callback call_back)
     {
-      m_postdo[state] = call_back;
+      try
+        {
+          m_postdo.at(state) = call_back;
+        }
+      catch (...)
+        {
+          assert(false);
+          return false;
+        }
       return true;
     }
     
@@ -500,7 +557,15 @@
      */
     bool setExitAction(State state, Callback call_back)
     {
-      m_exit[state] = call_back;
+      try
+        {
+          m_exit.at(state) = call_back;
+        }
+      catch (...)
+        {
+          assert(false);
+          return false;
+        }
       return true;
     }
     
@@ -736,7 +801,6 @@
     //
     void worker_pre()
     {
-      //      std::cout << "worker_pre()" << std::endl;
       States state;
       sync(state);
       if (state.curr == state.next)
@@ -767,7 +831,6 @@
 
     void worker_do()
     {
-      //      std::cout << "worker_do()" << std::endl;
       States state;
       sync(state);
       if (m_do[state.curr] != NULL)
@@ -778,7 +841,6 @@
 
     void worker_post()
     {
-      //      std::cout << "worker_post()" << std::endl;
       States state;
       sync(state);
       if (m_postdo[state.curr] != NULL)
@@ -807,9 +869,14 @@
      *
      * @endif
      */
-    void setNullFunc(Callback* s, Callback nullfunc)
+    void setNullFunc(std::vector<Callback>& s, Callback nullfunc)
     {
-      for (int i = 0; i < m_num; ++i) s[i] = nullfunc;
+      s.clear();
+      //      assert((size_t)m_num == s.size());
+      for (size_t i(0); i < m_num; ++i)
+        {
+          s.push_back(nullfunc);
+        }
     }
 
     /*!
@@ -837,7 +904,7 @@
      * @brief Callback function for Entry action
      * @endif
      */
-    Callback* m_entry;
+    std::vector<Callback> m_entry;
 
     /*!
      * @if jp
@@ -846,7 +913,7 @@
      * @brief Callback function for PreDo action
      * @endif
      */
-    Callback* m_predo;
+    std::vector<Callback> m_predo;
 
     /*!
      * @if jp
@@ -855,7 +922,7 @@
      * @brief Callback function for Do action
      * @endif
      */
-    Callback* m_do;
+    std::vector<Callback> m_do;
 
     /*!
      * @if jp
@@ -864,7 +931,7 @@
      * @brief Callback function for PostDo action
      * @endif
      */
-    Callback* m_postdo;
+    std::vector<Callback> m_postdo;
 
     /*!
      * @if jp
@@ -873,7 +940,7 @@
      * @brief Callback function for Exit action
      * @endif
      */
-    Callback* m_exit;
+    std::vector<Callback> m_exit;
 
     /*!
      * @if jp



openrtm-commit メーリングリストの案内