PetrFlajsingr / pf_imgui

Dear ImGui wrapper along with some other useful libraries.
MIT License
21 stars 3 forks source link

Clean up property types #240

Closed PetrFlajsingr closed 2 years ago

PetrFlajsingr commented 2 years ago

ObservableProperty<Owner, Type, ReadOnlyTag> is kinda lengthy

PetrFlajsingr commented 2 years ago
template <typename T>
struct PropertyOwner {
  template<typename U>
  using ReadOnlyProperty = ObservableProperty<T, U, ReadOnlyTag>;
  template<typename U>
  using Property = ObservableProperty<T, U, ReadWriteTag>;

protected:
  /** Provides access to transaction - which may be private - in derived classes */
  template<typename U, OneOf<ReadOnlyTag, ReadWriteTag> Tag>
  ObservableProperty<T, U, Tag>::Transaction modifyProperty(ObservableProperty<T, U, Tag> &property) {
    return property.modify();
  }
  /** Provides acces to inner value of a property */
  template<typename U, OneOf<ReadOnlyTag, ReadWriteTag> Tag>
  ObservableProperty<T, U, Tag>::reference getPropertyValueRef(ObservableProperty<T, U, Tag> &property) {
    return property.value; 
  }
  /** Allows triggering of listeners, when internal value is changed without transaction */
  template<typename U, OneOf<ReadOnlyTag, ReadWriteTag> Tag>
  void triggerPropertyListeners(ObservableProperty<T, U, Tag> &property) {
    return property.triggerListeners();
  }
}