|
Boost-Commit : |
From: johan_torp_at_[hidden]
Date: 2007-06-12 14:56:51
Author: johan_torp
Date: 2007-06-12 14:56:50 EDT (Tue, 12 Jun 2007)
New Revision: 7010
URL: http://svn.boost.org/trac/boost/changeset/7010
Log:
Initial commit to see if there is any interest in this library
Added:
sandbox/observable_value/
sandbox/observable_value/LICENSE_1_0.txt
sandbox/observable_value/boost/
sandbox/observable_value/boost/observable_value.hpp
sandbox/observable_value/libs/
sandbox/observable_value/libs/observable_value/
sandbox/observable_value/libs/observable_value/vc7_example/
sandbox/observable_value/libs/observable_value/vc7_example/vc7_example.cpp
sandbox/observable_value/libs/observable_value/vc7_example/vc7_example.vcproj
Added: sandbox/observable_value/LICENSE_1_0.txt
==============================================================================
--- (empty file)
+++ sandbox/observable_value/LICENSE_1_0.txt 2007-06-12 14:56:50 EDT (Tue, 12 Jun 2007)
@@ -0,0 +1,23 @@
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
Added: sandbox/observable_value/boost/observable_value.hpp
==============================================================================
--- (empty file)
+++ sandbox/observable_value/boost/observable_value.hpp 2007-06-12 14:56:50 EDT (Tue, 12 Jun 2007)
@@ -0,0 +1,107 @@
+// Copyright 2007 Johan Torp.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#ifndef BOOST_OBSERVABLE_VALUE_HPP
+#define BOOST_OBSERVABLE_VALUE_HPP
+
+#include <boost/signal.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/utility/value_init.hpp>
+
+namespace boost {
+
+/// A simple class which combines a value with a way of listening to changes in it
+template <typename T>
+class observable_value
+{
+private:
+ typedef boost::signal<void (const T&)> signal_type;
+public:
+ typedef typename signal_type::slot_type slot_type;
+ typedef T value_type;
+
+ /// Default constructor
+ /** Value intializes the observable value.
+ */
+ observable_value() : mValue(boost::value_initialized<T>()) {}
+ explicit observable_value(const T& t) : mValue(t) {}
+
+ /// Assignment operator
+ /** Assigns the observable value and notifies observers if the value changed.
+ */
+ observable_value<T>& operator=(const T& value)
+ {
+ set(value);
+ return *this;
+ }
+ /// Implicit type conversion operator
+ /** Enables implicit type conversion to T.
+ */
+ operator const T& () const { return mValue; }
+
+ /// connect
+ /** Connects a slot which will receive callbacks when the value is changed.
+ */
+ boost::signals::connection connect(const slot_type& slot) const
+ {
+ return mSignal.connect(slot);
+ }
+ /// connect
+ /** Connects a slot with a given call priority.
+ */
+ boost::signals::connection connect(int order, const slot_type& slot) const
+ {
+ return mSignal.connect(order, slot);
+ }
+ /// disconnect
+ /** Disconnects a slot.
+ */
+ void disconnect(const slot_type& slot) const
+ {
+ mSignal.disconnect(slot);
+ }
+
+ /// operator+=
+ /** Add right hand side to value and notify listeners if the value is changed
+ */
+ observable_value<T>& operator+=(const T& t)
+ {
+ T target_value(mValue);
+ target_value+=t;
+ set(target_value);
+ return *this;
+ }
+
+ observable_value<T>& operator-=(const T& t);
+ observable_value<T>& operator*=(const T& x);
+ observable_value<T>& operator/=(const T& x);
+ observable_value<T>& operator%=(const T& x);
+ observable_value<T>& operator|=(const T& x);
+ observable_value<T>& operator&=(const T& x);
+ observable_value<T>& operator^=(const T& x);
+
+private:
+ T mValue;
+ mutable boost::signal<void (const T&)> mSignal;
+
+ void set(const T& value)
+ {
+ if (!(value == mValue))
+ {
+ mValue=value;
+ mSignal(mValue);
+ }
+ }
+
+ BOOST_STATIC_ASSERT((boost::is_same<int, typename signal_type::group_type>::value));
+};
+
+
+} // namespace boost
+
+
+#endif // BOOST_OBSERVABLE_VALUE_HPP
Added: sandbox/observable_value/libs/observable_value/vc7_example/vc7_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/observable_value/libs/observable_value/vc7_example/vc7_example.cpp 2007-06-12 14:56:50 EDT (Tue, 12 Jun 2007)
@@ -0,0 +1,24 @@
+#include <iostream>
+#include <tchar.h>
+
+#include "../boost/observable_value.hpp"
+
+
+void bar(const int& value) { std::cout << "Changed: " << value << std::endl; }
+void foo(const boost::observable_value<int>& value)
+{
+ std::cout << "Original: " << value << std::endl;
+ value.connect(&bar);
+}
+
+int _tmain(int argc, _TCHAR* argv[])
+{
+ boost::observable_value<int> i(1);
+ foo(i);
+ i=1; // no change
+ i=0; // change
+ i+=0; // no change
+ i+=5; // change
+ return 0;
+}
+
Added: sandbox/observable_value/libs/observable_value/vc7_example/vc7_example.vcproj
==============================================================================
--- (empty file)
+++ sandbox/observable_value/libs/observable_value/vc7_example/vc7_example.vcproj 2007-06-12 14:56:50 EDT (Tue, 12 Jun 2007)
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="vc7_example"
+ ProjectGUID="{C27034EB-8ABA-4066-A916-5269A25E4C48}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/vc7_example.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/vc7_example.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="4"
+ UsePrecompiledHeader="3"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/vc7_example.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath=".\vc7_example.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk