Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 30, 2015, 9:13:14 PM (8 years ago)
Author:
landauf
Message:

MultiType now supports strongly typed enum classes. Their values are cast to the underlying type.
MultiType now also uses additional static_asserts to ensure that it is only used with supported values.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/network/synchronisable/Synchronisable.h

    r10996 r11002  
    207207  {
    208208    template <class T, bool = std::is_enum<T>::value>
    209     struct RealType;
     209    struct UnderlyingType;
    210210    template <class T>
    211     struct RealType<T, true> { typedef typename std::underlying_type<T>::type type; };
     211    struct UnderlyingType<T, true> { typedef typename std::underlying_type<T>::type type; };
    212212    template <class T>
    213     struct RealType<T, false> { typedef T type; };
     213    struct UnderlyingType<T, false> { typedef T type; };
    214214  }
    215215
     
    217217  void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    218218  {
    219     typedef typename detail::RealType<T>::type RealType;
     219    typedef typename detail::UnderlyingType<T>::type UnderlyingType;
    220220    if (bidirectional)
    221221    {
    222       syncList_.push_back(new SynchronisableVariableBidirectional<RealType>(reinterpret_cast<RealType&>(variable), mode, cb));
     222      syncList_.push_back(new SynchronisableVariableBidirectional<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb));
    223223      this->dataSize_ += syncList_.back()->getSize(state_);
    224224    }
    225225    else
    226226    {
    227       syncList_.push_back(new SynchronisableVariable<RealType>(reinterpret_cast<RealType&>(variable), mode, cb));
     227      syncList_.push_back(new SynchronisableVariable<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb));
    228228      if ( this->state_ == mode )
    229229        this->dataSize_ += syncList_.back()->getSize(state_);
     
    255255  void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    256256  {
    257     typedef typename detail::RealType<T>::type RealType;
     257    typedef typename detail::UnderlyingType<T>::type UnderlyingType;
    258258    SynchronisableVariableBase* sv;
    259259    if (bidirectional)
    260       sv = new SynchronisableVariableBidirectional<std::set<RealType>>(reinterpret_cast<std::set<RealType>&>(variable), mode, cb);
     260      sv = new SynchronisableVariableBidirectional<std::set<UnderlyingType>>(reinterpret_cast<std::set<UnderlyingType>&>(variable), mode, cb);
    261261    else
    262       sv = new SynchronisableVariable<std::set<RealType>>(reinterpret_cast<std::set<RealType>&>(variable), mode, cb);
     262      sv = new SynchronisableVariable<std::set<UnderlyingType>>(reinterpret_cast<std::set<UnderlyingType>&>(variable), mode, cb);
    263263    syncList_.push_back(sv);
    264264    stringList_.push_back(sv);
Note: See TracChangeset for help on using the changeset viewer.