.. index:: pair: class; EE::ComputedValue .. _doxid-class_e_e_1_1_computed_value: template class EE::ComputedValue ================================ .. toctree:: :hidden: struct_EE_ComputedValue_State.rst Overview ~~~~~~~~ A read-only observable whose value is synchronously derived from explicit dependencies. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include template class ComputedValue { public: // typedefs typedef T :target:`ValueType`; typedef typename :ref:`ObservableValue`:::ref:`Callback` :target:`Callback`; typedef typename :ref:`ObservableValue`:::ref:`Connection` :target:`Connection`; // structs struct :ref:`State`; // construction :ref:`ComputedValue`(Calculator calculator, Dependencies&... dependencies); :target:`ComputedValue`(const ComputedValue&); :target:`ComputedValue`(ComputedValue&&); // methods ComputedValue& :target:`operator=`(const ComputedValue&); ComputedValue& :target:`operator=`(ComputedValue&&); const T& :ref:`get`() const; const T& :target:`operator*`() const; const T* :target:`operator->`() const; :target:`operator const T &`() const; :ref:`Connection` :ref:`observe`(:ref:`Callback` callback); std::size_t :ref:`observerCount`() const; static constexpr std::size_t :ref:`dependencyCount`(); }; .. _details-class_e_e_1_1_computed_value: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ A read-only observable whose value is synchronously derived from explicit dependencies. Dependencies are observed in argument order. A dependency change updates its cached value and recomputes the result before the dependency's set() returns. Destroying a dependency leaves the computed value at its last result; destroying either endpoint safely expires scoped observers. :ref:`ComputedValue ` is single-threaded, like :ref:`ObservableValue `. Construction ------------ .. index:: pair: function; ComputedValue .. _doxid-class_e_e_1_1_computed_value_1ab5c767904aa3e57728fddf1ac57743ac: .. ref-code-block:: cpp :class: doxyrest-title-code-block ComputedValue(Calculator calculator, Dependencies&... dependencies) Creates a computed value and evaluates ``calculator`` once from the current dependencies. The calculator receives the dependency values as const references in the same order in which the dependencies are passed. Every dependency must outlive this object if further updates are expected from it. Methods ------- .. index:: pair: function; get .. _doxid-class_e_e_1_1_computed_value_1a5771ed5aa9b89f4d11a9661f9d2f154e: .. ref-code-block:: cpp :class: doxyrest-title-code-block const T& get() const .. rubric:: Returns: The most recently calculated value. .. index:: pair: function; observe .. _doxid-class_e_e_1_1_computed_value_1a86cfd4308e5b16fedb36bc067ed5c89c: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Connection` observe(:ref:`Callback` callback) Observes later changes to the calculated value. The callback is not invoked immediately. Read :ref:`get() ` when the initial value is needed. .. rubric:: Returns: A scoped connection; destroying it disconnects the callback. .. index:: pair: function; observerCount .. _doxid-class_e_e_1_1_computed_value_1ac6087bfb8113968183ad9d93bcb0cf3c: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::size_t observerCount() const .. rubric:: Returns: The number of observers currently attached to the calculated output. .. index:: pair: function; dependencyCount .. _doxid-class_e_e_1_1_computed_value_1a7c1534a96a58b5b1dd259ca3505e0603: .. ref-code-block:: cpp :class: doxyrest-title-code-block static constexpr std::size_t dependencyCount() .. rubric:: Returns: The number of observable dependencies captured by this computed value.