Changeset 11071 for code/trunk/src/libraries/network/synchronisable
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/synchronisable/NetworkCallback.h
r6417 r11071 53 53 NetworkCallback(T* object, void (T::*function) (void)) : object_(object), function_(function) {} 54 54 virtual ~NetworkCallback() {} 55 virtual void call() 55 virtual void call() override 56 56 { (this->object_->*function_)(); } 57 57 … … 68 68 NetworkCallbackNotify() {} 69 69 virtual ~NetworkCallbackNotify() {} 70 virtual void call() 70 virtual void call() override 71 71 { (this->object_->*function_)( this->oldValue_ ); } 72 72 void setOldValue(const U& value){ this->oldValue_ = value; } -
code/trunk/src/libraries/network/synchronisable/Serialise.h
r10624 r11071 90 90 { 91 91 // *const_cast<typename Loki::TypeTraits<T*>::UnqualifiedType*>(&variable) = dynamic_cast<T*>(variable->getSynchronisable( *(uint32_t*)(mem) )); 92 *const_cast<typename Loki::TypeTraits<StrongPtr<T> 92 *const_cast<typename Loki::TypeTraits<StrongPtr<T>>::UnqualifiedType*>(&variable) = orxonox_cast<T*>(T::getSynchronisable(*(uint32_t*)(mem))); 93 93 mem += returnSize( variable ); 94 94 } … … 125 125 { 126 126 // *const_cast<typename Loki::TypeTraits<T*>::UnqualifiedType*>(&variable) = dynamic_cast<T*>(variable->getSynchronisable( *(uint32_t*)(mem) )); 127 *const_cast<typename Loki::TypeTraits<WeakPtr<T> 127 *const_cast<typename Loki::TypeTraits<WeakPtr<T>>::UnqualifiedType*>(&variable) = orxonox_cast<T*>(T::getSynchronisable(*(uint32_t*)(mem))); 128 128 mem += returnSize( variable ); 129 129 } -
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r10624 r11071 88 88 } 89 89 // delete all Synchronisable Variables from syncList_ ( which are also in stringList_ ) 90 for( std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); it!=syncList_.end(); it++)91 delete (*it);90 for(SynchronisableVariableBase* variable : syncList_) 91 delete variable; 92 92 syncList_.clear(); 93 93 stringList_.clear(); … … 105 105 uint32_t Synchronisable::findContextID(Context* context) 106 106 { 107 if (context == NULL)107 if (context == nullptr) 108 108 return OBJECTID_UNKNOWN; 109 109 110 110 Synchronisable* synchronisableContext = orxonox_cast<Synchronisable*>(context); 111 if (synchronisableContext != NULL)111 if (synchronisableContext != nullptr) 112 112 return synchronisableContext->getObjectID(); 113 113 else … … 140 140 { 141 141 mem += header.getDataSize() + header.getSize(); 142 return 0;142 return nullptr; 143 143 } 144 144 // assert( !header.isDiffed() ); … … 156 156 } 157 157 assert(id); 158 Context* context = 0;158 Context* context = nullptr; 159 159 if (header.getContextID() != OBJECTID_UNKNOWN) 160 160 { … … 164 164 mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header 165 165 assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^ 166 return 0;166 return nullptr; 167 167 } 168 168 else … … 172 172 context = Context::getRootContext(); 173 173 174 assert(getSynchronisable(header.getObjectID())== 0); //make sure no object with this id exists174 assert(getSynchronisable(header.getObjectID())==nullptr); //make sure no object with this id exists 175 175 BaseObject *bo = orxonox_cast<BaseObject*>(id->fabricate(context)); 176 176 assert(bo); … … 226 226 return it1->second; 227 227 // if the objects not in the map it should'nt exist at all anymore 228 return NULL;228 return nullptr; 229 229 } 230 230 … … 266 266 assert(this->classID_==this->getIdentifier()->getNetworkID()); 267 267 assert(this->objectID_!=OBJECTID_UNKNOWN); 268 std::vector<SynchronisableVariableBase*>::iterator i;269 268 270 269 // start copy header … … 276 275 // orxout(verbose, context::network) << "objectid: " << this->objectID_ << ":"; 277 276 // copy to location 278 for( i=syncList_.begin(); i!=syncList_.end(); ++i)279 { 280 uint32_t varsize = (*i)->getData( mem, mode );277 for(SynchronisableVariableBase* variable : syncList_) 278 { 279 uint32_t varsize = variable->getData( mem, mode ); 281 280 // orxout(verbose, context::network) << " " << varsize; 282 281 tempsize += varsize; … … 348 347 assert( this->getContextID() == syncHeader2.getContextID() ); 349 348 mem += SynchronisableHeader::getSize(); 350 std::vector<SynchronisableVariableBase *>::iterator i; 351 for(i=syncList_.begin(); i!=syncList_.end(); ++i) 349 for(SynchronisableVariableBase* variable : syncList_) 352 350 { 353 351 assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream 354 (*i)->putData( mem, mode, forceCallback );352 variable->putData( mem, mode, forceCallback ); 355 353 } 356 354 assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeader::getSize() ); … … 388 386 assert( mode==state_ ); 389 387 tsize += this->dataSize_; 390 std::vector<SynchronisableVariableBase*>::iterator i; 391 for(i=stringList_.begin(); i!=stringList_.end(); ++i) 392 { 393 tsize += (*i)->getSize( mode ); 388 for(SynchronisableVariableBase* variable : stringList_) 389 { 390 tsize += variable->getSize( mode ); 394 391 } 395 392 return tsize; -
code/trunk/src/libraries/network/synchronisable/Synchronisable.h
r9667 r11071 38 38 #include <queue> 39 39 #include <set> 40 #include <type_traits> 40 41 41 42 #include "util/mbool.h" … … 171 172 protected: 172 173 Synchronisable(Context* context); 173 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb= 0, bool bidirectional=false);174 template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb= 0, bool bidirectional=false);174 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=nullptr, bool bidirectional=false); 175 template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=nullptr, bool bidirectional=false); 175 176 template <class T> void unregisterVariable(T& var); 176 177 … … 203 204 }; 204 205 205 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 206 { 206 namespace detail 207 { 208 template <class T, bool = std::is_enum<T>::value> 209 struct UnderlyingType; 210 template <class T> 211 struct UnderlyingType<T, true> { typedef typename std::underlying_type<T>::type type; }; 212 template <class T> 213 struct UnderlyingType<T, false> { typedef T type; }; 214 } 215 216 template <class T> 217 void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 218 { 219 typedef typename detail::UnderlyingType<T>::type UnderlyingType; 207 220 if (bidirectional) 208 221 { 209 syncList_.push_back(new SynchronisableVariableBidirectional< T>(variable, mode, cb));222 syncList_.push_back(new SynchronisableVariableBidirectional<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb)); 210 223 this->dataSize_ += syncList_.back()->getSize(state_); 211 224 } 212 225 else 213 226 { 214 syncList_.push_back(new SynchronisableVariable< T>(variable, mode, cb));227 syncList_.push_back(new SynchronisableVariable<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb)); 215 228 if ( this->state_ == mode ) 216 229 this->dataSize_ += syncList_.back()->getSize(state_); … … 218 231 } 219 232 220 template <class T> void Synchronisable::unregisterVariable(T& variable) 233 template <class T> 234 void Synchronisable::unregisterVariable(T& variable) 221 235 { 222 236 std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); … … 238 252 } 239 253 240 template <class T> void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 241 { 254 template <class T> 255 void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 256 { 257 typedef typename detail::UnderlyingType<T>::type UnderlyingType; 242 258 SynchronisableVariableBase* sv; 243 259 if (bidirectional) 244 sv = new SynchronisableVariableBidirectional<std::set< T> >(variable, mode, cb);260 sv = new SynchronisableVariableBidirectional<std::set<UnderlyingType>>(reinterpret_cast<std::set<UnderlyingType>&>(variable), mode, cb); 245 261 else 246 sv = new SynchronisableVariable<std::set< T> >(variable, mode, cb);262 sv = new SynchronisableVariable<std::set<UnderlyingType>>(reinterpret_cast<std::set<UnderlyingType>&>(variable), mode, cb); 247 263 syncList_.push_back(sv); 248 264 stringList_.push_back(sv); … … 250 266 251 267 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 252 // template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T> 268 // template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T>>( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 253 269 template <> _NetworkExport void Synchronisable::unregisterVariable( std::string& variable ); 254 270 -
code/trunk/src/libraries/network/synchronisable/SynchronisableVariable.h
r10624 r11071 71 71 { 72 72 public: 73 SynchronisableVariable(T& variable, uint8_t syncDirection=VariableDirection::ToClient, NetworkCallbackBase *cb= 0);73 SynchronisableVariable(T& variable, uint8_t syncDirection=VariableDirection::ToClient, NetworkCallbackBase *cb=nullptr); 74 74 virtual ~SynchronisableVariable(); 75 75 76 virtual inline uint8_t getMode() { return mode_; }77 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode) ;78 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false) ;79 virtual inline uint32_t getSize(uint8_t mode) ;80 virtual inline void* getReference() { return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); }76 virtual inline uint8_t getMode() override{ return mode_; } 77 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode) override; 78 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false) override; 79 virtual inline uint32_t getSize(uint8_t mode) override; 80 virtual inline void* getReference() override{ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); } 81 81 protected: 82 82 T& variable_; … … 89 89 { 90 90 public: 91 SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb= 0);91 SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb=nullptr); 92 92 virtual ~SynchronisableVariableBidirectional(); 93 93
Note: See TracChangeset
for help on using the changeset viewer.