Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51122 - sandbox/thread_safe_signals/trunk/libs/signals2/example
From: fmhess_at_[hidden]
Date: 2009-02-08 22:02:15


Author: fmhess
Date: 2009-02-08 22:02:14 EST (Sun, 08 Feb 2009)
New Revision: 51122
URL: http://svn.boost.org/trac/boost/changeset/51122

Log:
Added some more comments to identify snippets for use in documentation.

Text files modified:
   sandbox/thread_safe_signals/trunk/libs/signals2/example/custom_combiners.cpp | 8 ++++++++
   sandbox/thread_safe_signals/trunk/libs/signals2/example/disconnect_and_block.cpp | 20 +++++++++++++++-----
   sandbox/thread_safe_signals/trunk/libs/signals2/example/passing_slots.cpp | 24 ++++++++++++++++--------
   sandbox/thread_safe_signals/trunk/libs/signals2/example/signal_return_value.cpp | 4 ++++
   sandbox/thread_safe_signals/trunk/libs/signals2/example/slot_arguments.cpp | 4 ++++
   5 files changed, 47 insertions(+), 13 deletions(-)

Modified: sandbox/thread_safe_signals/trunk/libs/signals2/example/custom_combiners.cpp
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/example/custom_combiners.cpp (original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/custom_combiners.cpp 2009-02-08 22:02:14 EST (Sun, 08 Feb 2009)
@@ -18,6 +18,7 @@
 float sum(float x, float y) { return x + y; }
 float difference(float x, float y) { return x - y; }
 
+//[ custom_combiners_maximum_def_code_snippet
 // combiner which returns the maximum value returned by all slots
 template<typename T>
 struct maximum
@@ -40,12 +41,14 @@
     return max_value;
   }
 };
+//]
 
 void maximum_combiner_example()
 {
   // signal which uses our custom "maximum" combiner
   boost::signals2::signal<float (float x, float y), maximum<float> > sig;
 
+//[ custom_combiners_maximum_usage_code_snippet
   sig.connect(&product);
   sig.connect(&quotient);
   sig.connect(&sum);
@@ -54,8 +57,10 @@
   // Outputs the maximum value returned by the connected slots, in this case
   // 15 from the product function.
   std::cout << "maximum: " << sig(5, 3) << std::endl;
+//]
 }
 
+//[ custom_combiners_aggregate_values_def_code_snippet
 // aggregate_values is a combiner which places all the values returned
 // from slots into a container
 template<typename Container>
@@ -75,6 +80,7 @@
     return values;
   }
 };
+//]
 
 void aggregate_values_example()
 {
@@ -82,6 +88,7 @@
   boost::signals2::signal<float (float, float),
     aggregate_values<std::vector<float> > > sig;
 
+//[ custom_combiners_aggregate_values_usage_code_snippet
   sig.connect(&quotient);
   sig.connect(&product);
   sig.connect(&sum);
@@ -92,6 +99,7 @@
   std::copy(results.begin(), results.end(),
     std::ostream_iterator<float>(std::cout, " "));
   std::cout << "\n";
+//]
 }
 
 int main()

Modified: sandbox/thread_safe_signals/trunk/libs/signals2/example/disconnect_and_block.cpp
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/example/disconnect_and_block.cpp (original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/disconnect_and_block.cpp 2009-02-08 22:02:14 EST (Sun, 08 Feb 2009)
@@ -23,32 +23,36 @@
 {
   boost::signals2::signal<void ()> sig;
 
+//[ disconnect_code_snippet
   boost::signals2::connection c = sig.connect(HelloWorld());
   // c is connected
- std::cout << "c.connected() is " << c.connected() << ".\n";
+ std::cout << "c is connected\n";
   sig(); // Prints "Hello, World!"
 
   c.disconnect(); // Disconnect the HelloWorld object
- std::cout << "c.connected() is " << c.connected() << ".\n";
+ std::cout << "c is disconnected\n";
   sig(); // Does nothing: there are no connected slots
+//]
 }
 
 void block_example()
 {
   boost::signals2::signal<void ()> sig;
 
+//[ block_code_snippet
   boost::signals2::connection c = sig.connect(HelloWorld());
   // connection is not blocked
- std::cout << "c.blocked() is " << c.blocked() << ".\n";
+ std::cout << "c is not blocked.\n";
   sig(); // Prints "Hello, World!"
 
   {
     boost::signals2::shared_connection_block block(c); // block the slot
- std::cout << "c.blocked() is " << c.blocked() << ".\n";
+ std::cout << "c is blocked.\n";
     sig(); // No output: the slot is blocked
   } // shared_connection_block going out of scope unblocks the slot
- std::cout << "c.blocked() is " << c.blocked() << ".\n";
+ std::cout << "c is not blocked.\n";
   sig(); // Prints "Hello, World!"}
+//]
 }
 
 struct ShortLived
@@ -63,21 +67,26 @@
 {
   boost::signals2::signal<void ()> sig;
 
+//[ scoped_connection_code_snippet
   {
     boost::signals2::scoped_connection c(sig.connect(ShortLived()));
     sig(); // will call ShortLived function object
   } // scoped_connection goes out of scope and disconnects
 
   sig(); // ShortLived function object no longer connected to sig
+//]
 }
 
+//[ disconnect_by_slot_def_code_snippet
 void foo() { std::cout << "foo"; }
 void bar() { std::cout << "bar\n"; }
+//]
 
 void disconnect_by_slot_example()
 {
   boost::signals2::signal<void()> sig;
 
+//[ disconnect_by_slot_usage_code_snippet
   sig.connect(&foo);
   sig.connect(&bar);
   sig();
@@ -85,6 +94,7 @@
   // disconnects foo, but not bar
   sig.disconnect(&foo);
   sig();
+//]
 }
 
 int main()

Modified: sandbox/thread_safe_signals/trunk/libs/signals2/example/passing_slots.cpp
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/example/passing_slots.cpp (original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/passing_slots.cpp 2009-02-08 22:02:14 EST (Sun, 08 Feb 2009)
@@ -12,6 +12,7 @@
 #include <iostream>
 #include <boost/signals2/signal.hpp>
 
+//[ passing_slots_defs_code_snippet
 // a pretend GUI button
 class Button
 {
@@ -19,29 +20,36 @@
 public:
   typedef OnClick::slot_type OnClickSlotType;
   // forward slots through Button interface to its private signal
- boost::signals2::connection doOnClick(const OnClickSlotType & slot)
- {
- return onClick.connect(slot);
- }
+ boost::signals2::connection doOnClick(const OnClickSlotType & slot);
 
   // simulate user clicking on GUI button at coordinates 52, 38
- void simulateClick()
- {
- onClick(52, 38);
- }
+ void simulateClick();
 private:
   OnClick onClick;
 };
 
+boost::signals2::connection Button::doOnClick(const OnClickSlotType & slot)
+{
+ return onClick.connect(slot);
+}
+
+void Button::simulateClick()
+{
+ onClick(52, 38);
+}
+
 void printCoordinates(long x, long y)
 {
   std::cout << "(" << x << ", " << y << ")\n";
 }
+//]
 
 int main()
 {
+//[ passing_slots_usage_code_snippet
   Button button;
   button.doOnClick(&printCoordinates);
   button.simulateClick();
+//]
   return 0;
 }

Modified: sandbox/thread_safe_signals/trunk/libs/signals2/example/signal_return_value.cpp
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/example/signal_return_value.cpp (original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/signal_return_value.cpp 2009-02-08 22:02:14 EST (Sun, 08 Feb 2009)
@@ -12,15 +12,18 @@
 #include <iostream>
 #include <boost/signals2/signal.hpp>
 
+//[ signal_return_value_slot_defs_code_snippet
 float product(float x, float y) { return x * y; }
 float quotient(float x, float y) { return x / y; }
 float sum(float x, float y) { return x + y; }
 float difference(float x, float y) { return x - y; }
+//]
 
 int main()
 {
   boost::signals2::signal<float (float x, float y)> sig;
 
+//[ signal_return_value_main_code_snippet
   sig.connect(&product);
   sig.connect(&quotient);
   sig.connect(&sum);
@@ -30,4 +33,5 @@
   // value of the last slot in the slot list, in this case the
   // difference function.
   std::cout << *sig(5, 3) << std::endl;
+//]
 };

Modified: sandbox/thread_safe_signals/trunk/libs/signals2/example/slot_arguments.cpp
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/example/slot_arguments.cpp (original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/slot_arguments.cpp 2009-02-08 22:02:14 EST (Sun, 08 Feb 2009)
@@ -12,6 +12,7 @@
 #include <iostream>
 #include <boost/signals2/signal.hpp>
 
+//[ slot_arguments_slot_defs_code_snippet
 void print_args(float x, float y)
 {
   std::cout << "The arguments are " << x << " and " << y << std::endl;
@@ -36,9 +37,11 @@
 {
   std::cout << "The quotient is " << x / y << std::endl;
 }
+//]
 
 int main()
 {
+//[ slot_arguments_main_code_snippet
   boost::signals2::signal<void (float, float)> sig;
 
   sig.connect(&print_args);
@@ -48,5 +51,6 @@
   sig.connect(&print_quotient);
 
   sig(5., 3.);
+//]
   return 0;
 };


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