Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/synchronisable/Synchronisable.h

    r9667 r11071  
    3838#include <queue>
    3939#include <set>
     40#include <type_traits>
    4041
    4142#include "util/mbool.h"
     
    171172  protected:
    172173    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);
    175176    template <class T> void unregisterVariable(T& var);
    176177
     
    203204  };
    204205
    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;
    207220    if (bidirectional)
    208221    {
    209       syncList_.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
     222      syncList_.push_back(new SynchronisableVariableBidirectional<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb));
    210223      this->dataSize_ += syncList_.back()->getSize(state_);
    211224    }
    212225    else
    213226    {
    214       syncList_.push_back(new SynchronisableVariable<T>(variable, mode, cb));
     227      syncList_.push_back(new SynchronisableVariable<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb));
    215228      if ( this->state_ == mode )
    216229        this->dataSize_ += syncList_.back()->getSize(state_);
     
    218231  }
    219232 
    220   template <class T> void Synchronisable::unregisterVariable(T& variable)
     233  template <class T>
     234  void Synchronisable::unregisterVariable(T& variable)
    221235  {
    222236    std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin();
     
    238252  }
    239253
    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;
    242258    SynchronisableVariableBase* sv;
    243259    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);
    245261    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);
    247263    syncList_.push_back(sv);
    248264    stringList_.push_back(sv);
     
    250266
    251267  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> >( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     268//   template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T>>( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    253269  template <> _NetworkExport void Synchronisable::unregisterVariable( std::string& variable );
    254270
Note: See TracChangeset for help on using the changeset viewer.