diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2014-01-22 11:56:49 -0600 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2014-01-22 11:56:49 -0600 |
commit | e2fd6e620ce7f18c2cbf7c7b353d7cb5f86dce11 (patch) | |
tree | f5409b9e2bdbcc0d8d3e9ed168143632c1dab239 /include/core/property.h | |
parent | 9ea8a269f3c984901e721e8bb0c796942bffb082 (diff) | |
download | ayatana-indicator-datetime-e2fd6e620ce7f18c2cbf7c7b353d7cb5f86dce11.tar.gz ayatana-indicator-datetime-e2fd6e620ce7f18c2cbf7c7b353d7cb5f86dce11.tar.bz2 ayatana-indicator-datetime-e2fd6e620ce7f18c2cbf7c7b353d7cb5f86dce11.zip |
remove the local snapshot of properties-cpp and add a dependency for it in debian/control and CMakeLists.txt
Diffstat (limited to 'include/core/property.h')
-rw-r--r-- | include/core/property.h | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/include/core/property.h b/include/core/property.h deleted file mode 100644 index 996ba8a..0000000 --- a/include/core/property.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright © 2013 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authored by: Thomas Voß <thomas.voss@canonical.com> - */ -#ifndef CORE_PROPERTY_H_ -#define CORE_PROPERTY_H_ - -#include <core/signal.h> - -#include <iostream> - -namespace core -{ -/** - * @brief A very simple, templated class that allows for uniform declaration of get-able/set-able/observable members. - * @tparam The type of the value contained within the property. - */ -template<typename T> -class Property -{ - public: - /** - * @brief ValueType refers to the type of the contained value. - */ - typedef T ValueType; - - /** - * @brief Property creates a new instance of property and initializes the contained value. - * @param t The initial value, defaults to Property<T>::default_value(). - */ - inline explicit Property(const T& t = T{}) : value{t} - { - } - - /** - * @brief Copy c'tor, only copies the contained value, not the changed signal and its connections. - * @param rhs - */ - inline Property(const Property<T>& rhs) : value{rhs.value} - { - } - - inline virtual ~Property() = default; - - /** - * @brief Assignment operator, only assigns to the contained value. - * @param rhs The right-hand-side, raw value to assign to this property. - */ - inline Property& operator=(const T& rhs) - { - set(rhs); - return *this; - } - - /** - * @brief Assignment operator, only assigns to the contained value, not the changed signal and its connections. - * @param rhs The right-hand-side property to assign from. - */ - inline Property& operator=(const Property<T>& rhs) - { - set(rhs.value); - return *this; - } - - /** - * @brief Explicit casting operator to the contained value type. - * @return A non-mutable reference to the contained value. - */ - inline operator const T&() const - { - return get(); - } - - /** - * @brief Provides access to a pointer to the contained value. - */ - inline const T* operator->() const - { - return &get(); - } - - /** - * @brief operator == checks if the value of a property and a raw value are equal. - * @param lhs Non-mutable reference to a property. - * @param rhs Non-mutable reference to a raw value. - * @return True iff the value contained in lhs equals rhs. - */ - friend inline bool operator==(const Property<T>& lhs, const T& rhs) - { - return lhs.get() == rhs; - } - - /** - * @brief operator == checks if the value of two properties are equal. - * @param lhs Non-mutable reference to a property. - * @param rhs Non-mutable reference to a property. - * @return True iff the value contained in lhs equals the value contained in rhs. - */ - friend inline bool operator==(const Property<T>& lhs, const Property<T>& rhs) - { - return lhs.get() == rhs.get(); - } - - /** - * @brief Set the contained value to the provided value. Notify observers of the change. - * @param [in] new_value The new value to assign to this property. - * @post get() == new_value; - */ - inline virtual void set(const T& new_value) - { - if (value != new_value) - { - value = new_value; - signal_changed(value); - } - } - - /** - * @brief Access the value contained within this property. - * @return A non-mutable reference to the property value. - */ - inline virtual const T& get() const - { - return value; - } - - /** - * @brief Access to the changed signal, allows observers to subscribe to change notifications. - * @return A non-mutable reference to the changed signal. - */ - inline const Signal<T>& changed() const - { - return signal_changed; - } - - /** - * @brief Provides in-place update facilities. - * - * The provided update_functor is applied to the contained value. If the update functor - * returns true, indicating that the value has been changed, the changed signal is emitted. - * - * @param update_functor The update function to be applied to the contained value. - * @return true iff application of the update functor has been successful. - */ - inline virtual bool update(const std::function<bool(T& t)>& update_functor) - { - if (update_functor(mutable_get())) - { - signal_changed(value); - return true; - } - - return false; - } - - protected: - inline T& mutable_get() const - { - return value; - } - - private: - mutable T value; - Signal<T> signal_changed; -}; -} - -#endif // CORE_PROPERTY_H_ |