00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WMODULEINPUTDATA_H
00026 #define WMODULEINPUTDATA_H
00027
00028 #include <string>
00029 #include <sstream>
00030
00031 #include <boost/shared_ptr.hpp>
00032 #include <boost/thread/locks.hpp>
00033
00034
00035 template < typename T > class WModuleOutputData;
00036 #include "WModuleOutputData.h"
00037 #include "exceptions/WModuleConnectorUnconnected.h"
00038 #include "../common/WTransferable.h"
00039 #include "../common/WPrototyped.h"
00040
00041 #include "WModuleInputConnector.h"
00042 #include "WModuleOutputConnector.h"
00043
00044
00045
00046
00047
00048 template < typename T >
00049 class WModuleInputData: public WModuleInputConnector
00050 {
00051 public:
00052
00053
00054
00055 typedef boost::shared_ptr< WModuleInputData< T > > PtrType;
00056
00057
00058
00059
00060 typedef WModuleInputData< T >& RefType;
00061
00062
00063
00064
00065 typedef WModuleInputData< T > Type;
00066
00067
00068
00069
00070 typedef T TransferType;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 static PtrType create( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" );
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 static PtrType createAndAdd( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" );
00094
00095
00096
00097
00098
00099
00100
00101
00102 WModuleInputData( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" ):
00103 WModuleInputConnector( module, name, description ),
00104 m_disconnecting( false )
00105 {
00106 };
00107
00108
00109
00110
00111 virtual ~WModuleInputData()
00112 {
00113 };
00114
00115
00116
00117
00118
00119
00120
00121 virtual void disconnect( boost::shared_ptr<WModuleConnector> con, bool removeFromOwnList = true );
00122
00123
00124
00125
00126
00127
00128
00129
00130 const boost::shared_ptr< T > getData( bool reset = true )
00131 {
00132
00133 boost::shared_lock<boost::shared_mutex> lock = boost::shared_lock<boost::shared_mutex>( m_connectionListLock );
00134
00135
00136 if( reset )
00137 {
00138 handledUpdate();
00139 }
00140
00141
00142 if( m_disconnecting || m_connected.empty() )
00143 {
00144 lock.unlock();
00145 return boost::shared_ptr< T >();
00146 }
00147
00148
00149 boost::shared_ptr< T > dat = boost::shared_dynamic_cast< T >(
00150 boost::shared_dynamic_cast< WModuleOutputConnector >( *m_connected.begin() )->getRawData()
00151 );
00152
00153
00154 lock.unlock();
00155
00156 return dat;
00157 };
00158
00159
00160
00161
00162
00163
00164
00165
00166 virtual bool connectable( boost::shared_ptr<WModuleConnector> con )
00167 {
00168
00169
00170
00171 if( !WModuleInputConnector::connectable( con ) )
00172 {
00173 return false;
00174 }
00175
00176
00177
00178 boost::shared_ptr< WPrototyped > tProto =
00179 dynamic_cast< WModuleOutputConnector* >( con.get() )->getTransferPrototype();
00180
00181
00182 return dynamic_cast< T* >( tProto.get() );
00183 };
00184
00185 protected:
00186
00187 private:
00188
00189
00190
00191
00192 bool m_disconnecting;
00193 };
00194
00195 template < typename T >
00196 void WModuleInputData< T >::disconnect( boost::shared_ptr<WModuleConnector> con, bool removeFromOwnList )
00197 {
00198 m_disconnecting = true;
00199 WModuleInputConnector::disconnect( con, removeFromOwnList );
00200 m_disconnecting = false;
00201 }
00202
00203 template < typename T >
00204 typename WModuleInputData< T >::PtrType WModuleInputData< T >::create( boost::shared_ptr< WModule > module, std::string name,
00205 std::string description )
00206 {
00207 typedef typename WModuleInputData< T >::PtrType PTR;
00208 typedef typename WModuleInputData< T >::Type TYPE;
00209 return PTR( new TYPE( module, name, description ) );
00210 }
00211
00212 template < typename T >
00213 typename WModuleInputData< T >::PtrType WModuleInputData< T >::createAndAdd( boost::shared_ptr< WModule > module, std::string name,
00214 std::string description )
00215 {
00216 typename WModuleInputData< T >::PtrType c = create( module, name, description );
00217 module->addConnector( c );
00218 return c;
00219 }
00220
00221 #endif // WMODULEINPUTDATA_H
00222