Show
Ignore:
Timestamp:
05/01/07 14:55:06 (2 years ago)
Author:
aronb
Message:

Use shared_ptrs for gadget::Proxy and derived classes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/gadgeteer/gadget/Type/DeviceInterface.h

    r19729 r20061  
    3131#include <vector> 
    3232#include <gadget/Util/Debug.h> 
     33#include <gadget/Type/ProxyPtr.h> 
    3334 
    3435#include <boost/concept_check.hpp> 
     
    3637namespace gadget 
    3738{ 
    38  
    39 class Proxy; 
    40 class AnalogProxy; 
    41 class DigitalProxy; 
    42 class GestureProxy; 
    43 class GloveProxy; 
    44 class KeyboardMouseProxy; 
    45 class PositionProxy; 
    46 class StringProxy; 
    47 class CommandProxy; 
    4839 
    4940/** \class BaseDeviceInterface DeviceInterface.h gadget/Type/DeviceInterface.h 
     
    9384   bool isConnected() const 
    9485   { 
    95       return (NULL != mProxyPtr); 
     86      return (NULL != mProxyPtr.get()); 
    9687   } 
    9788 
    9889protected: 
    99    Proxy    mProxyPtr;   /**<  Ptr to the proxy */ 
     90   ProxyPtr    mProxyPtr;   /**<  Ptr to the proxy */ 
    10091   std::string mProxyName;  /**< The name of the proxy (or alias) we are looking at */ 
    10192   bool        mNameSet;    /**< Has the user set a name?? */ 
     
    136127      : BaseDeviceInterface(other) 
    137128   { 
    138       if (other.mTypeSpecificProxy != NULL) 
     129      mDummyProxy = boost::shared_ptr<PROXY_TYPE>(new PROXY_TYPE); 
     130 
     131      if (NULL != other.mTypeSpecificProxy.get()) 
    139132      { 
    140133         mTypeSpecificProxy = other.mTypeSpecificProxy; 
     
    142135      else 
    143136      { 
    144          mTypeSpecificProxy = &mDummyProxy; 
     137         mTypeSpecificProxy = mDummyProxy; 
    145138      } 
    146139   } 
     
    150143      : BaseDeviceInterface() 
    151144   { 
    152       mTypeSpecificProxy = &mDummyProxy; 
     145      mDummyProxy = boost::shared_ptr<PROXY_TYPE>(new PROXY_TYPE); 
     146      mTypeSpecificProxy = mDummyProxy; 
    153147   } 
    154148 
     
    167161    * @see init() 
    168162    */ 
    169    PROXY_TYPE* operator->() 
     163   boost::shared_ptr<PROXY_TYPE> operator->() 
    170164   { 
    171165      return mTypeSpecificProxy; 
     
    186180 
    187181   /** Returns the underlying proxy to which we are connected. */ 
    188    PROXY_TYPE* getProxy() 
     182   boost::shared_ptr<PROXY_TYPE> getProxy() 
    189183   { 
    190184      return mTypeSpecificProxy; 
     
    206200   { 
    207201      BaseDeviceInterface::refresh(); 
    208       if(mProxyPtr != NULL
    209       { 
    210          mTypeSpecificProxy = dynamic_cast<PROXY_TYPE*>(mProxyPtr); 
    211          if(NULL == mTypeSpecificProxy
     202      if(NULL!= mProxyPtr.get()
     203      { 
     204         mTypeSpecificProxy = boost::dynamic_pointer_cast<PROXY_TYPE>(mProxyPtr); 
     205         if(NULL == mTypeSpecificProxy.get()
    212206         { 
    213207            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 
     
    220214 
    221215      // If either one of the proxy pointers are NULL, then use a dummy 
    222       if((NULL == mProxyPtr) || (NULL == mTypeSpecificProxy)) 
    223       { 
    224          mTypeSpecificProxy = &mDummyProxy; 
     216      if((NULL == mProxyPtr.get()) || (NULL == mTypeSpecificProxy.get())) 
     217      { 
     218         mTypeSpecificProxy = mDummyProxy; 
    225219      } 
    226220   } 
    227221 
    228222private: 
    229    PROXY_TYPE*    mTypeSpecificProxy;   /**< The proxy that is being wrapped */ 
    230    PROXY_TYPE     mDummyProxy; 
     223   boost::shared_ptr<PROXY_TYPE>        mTypeSpecificProxy;   /**< The proxy that is being wrapped */ 
     224   boost::shared_ptr<PROXY_TYPE>        mDummyProxy; 
    231225}; 
    232226 
    233227 
    234228// --- Typedefs to the old types --- // 
    235 typedef DeviceInterface<AnalogProxy>      AnalogInterface; 
    236 typedef DeviceInterface<DigitalProxy>     DigitalInterface; 
    237 typedef DeviceInterface<GestureProxy>     GestureInterface; 
    238 typedef DeviceInterface<GloveProxy>       GloveInterface; 
    239 typedef DeviceInterface<KeyboardMouseProxy> KeyboardMouseInterface; 
    240 typedef DeviceInterface<PositionProxy>    PositionInterface; 
    241 typedef DeviceInterface<CommandProxy>     CommandInterface; 
    242 typedef DeviceInterface<StringProxy>      StringInterface; 
     229typedef DeviceInterface<class AnalogProxy>      AnalogInterface; 
     230typedef DeviceInterface<class DigitalProxy>     DigitalInterface; 
     231typedef DeviceInterface<class GestureProxy>     GestureInterface; 
     232typedef DeviceInterface<class GloveProxy>       GloveInterface; 
     233typedef DeviceInterface<class KeyboardMouseProxy> KeyboardMouseInterface; 
     234typedef DeviceInterface<class PositionProxy>    PositionInterface; 
     235typedef DeviceInterface<class CommandProxy>     CommandInterface; 
     236typedef DeviceInterface<class StringProxy>      StringInterface; 
    243237 
    244238} // end namespace