$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r51662 - in trunk: doc libs/signals2/doc libs/signals2/doc/snippets
From: fmhess_at_[hidden]
Date: 2009-03-09 15:24:32
Author: fmhess
Date: 2009-03-09 15:24:31 EDT (Mon, 09 Mar 2009)
New Revision: 51662
URL: http://svn.boost.org/trac/boost/changeset/51662
Log:
Tweaked generation of Signals2 code snippets a bit.
Added:
   trunk/libs/signals2/doc/snippet-extractor.jam   (contents, props changed)
      - copied, changed from r51658, /trunk/libs/signals2/doc/snippets/snippet-extractor.jam
   trunk/libs/signals2/doc/snippet_extractor.cpp   (contents, props changed)
      - copied, changed from r51658, /trunk/libs/signals2/doc/snippets/snippet_extractor.cpp
Removed:
   trunk/libs/signals2/doc/snippets/
Text files modified: 
   trunk/doc/Jamfile.v2                          |     3                                         
   trunk/libs/signals2/doc/Jamfile.v2            |    14 ++++                                    
   trunk/libs/signals2/doc/snippet-extractor.jam |     4                                         
   trunk/libs/signals2/doc/snippet_extractor.cpp |   118 ++++++++++++++++++++------------------- 
   trunk/libs/signals2/doc/tutorial.xml          |   108 ++++++++++++++++++------------------    
   5 files changed, 132 insertions(+), 115 deletions(-)
Modified: trunk/doc/Jamfile.v2
==============================================================================
--- trunk/doc/Jamfile.v2	(original)
+++ trunk/doc/Jamfile.v2	2009-03-09 15:24:31 EDT (Mon, 09 Mar 2009)
@@ -46,7 +46,7 @@
     <dependency>../libs/units/doc//units
     <dependency>../libs/unordered/doc//unordered
     <dependency>../libs/thread/doc//thread
-    <dependency>../libs/signals2/doc/snippets//
+    <dependency>../libs/signals2/doc//hello_world_def_code_snippet.xml
 
     ## Add path references to the QuickBook generated docs...
 
@@ -67,6 +67,7 @@
     <implicit-dependency>../libs/units/doc//units
     <implicit-dependency>../libs/unordered/doc//unordered
     <implicit-dependency>../libs/thread/doc//thread
+    <implicit-dependency>../libs/signals2/doc//hello_world_def_code_snippet.xml
 
     <xsl:param>boost.libraries=../../libs/libraries.htm
 
Modified: trunk/libs/signals2/doc/Jamfile.v2
==============================================================================
--- trunk/libs/signals2/doc/Jamfile.v2	(original)
+++ trunk/libs/signals2/doc/Jamfile.v2	2009-03-09 15:24:31 EDT (Mon, 09 Mar 2009)
@@ -5,7 +5,9 @@
 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 boostbook standalone : signals.xml :
-    <dependency>./snippets//
+    <dependency>hello_world_def_code_snippet.xml
+    <implicit-dependency>hello_world_def_code_snippet.xml
+
     <xsl:param>html.stylesheet=../../../../doc/html/boostbook.css
     <xsl:param>boost.root=../../../..
     <xsl:param>boost.libraries=../../../libraries.htm
@@ -21,3 +23,13 @@
 #    <xsl:param>boost.compact.function=0
 #    <xsl:param>boost.compact.enum=0
     ;
+
+import snippet-extractor ;
+
+exe snippet_extractor : snippet_extractor.cpp ;
+
+make hello_world_def_code_snippet.xml
+  : [ glob ../example/*.cpp ]
+  : snippet-extractor.extract-snippets
+  : <extractor-command>.//snippet_extractor
+  ;
Copied: trunk/libs/signals2/doc/snippet-extractor.jam (from r51658, /trunk/libs/signals2/doc/snippets/snippet-extractor.jam)
==============================================================================
--- /trunk/libs/signals2/doc/snippets/snippet-extractor.jam	(original)
+++ trunk/libs/signals2/doc/snippet-extractor.jam	2009-03-09 15:24:31 EDT (Mon, 09 Mar 2009)
@@ -1,4 +1,4 @@
-# Boost.Signals2 Library 
+# Boost.Signals2 Library
 
 # Copyright Frank Mori Hess 2009.
 
@@ -17,7 +17,7 @@
 
 rule extract-snippets ( target : sources * : properties * )
 {
-    DEPENDS $(target) : [ on $(target) return $(EXTRACTOR_COMMAND) ] ;
+    DEPENDS $(target) : [ on $(target) return $(EXTRACTOR-COMMAND) ] ;
 }
 actions extract-snippets bind EXTRACTOR-COMMAND
 {
Copied: trunk/libs/signals2/doc/snippet_extractor.cpp (from r51658, /trunk/libs/signals2/doc/snippets/snippet_extractor.cpp)
==============================================================================
--- /trunk/libs/signals2/doc/snippets/snippet_extractor.cpp	(original)
+++ trunk/libs/signals2/doc/snippet_extractor.cpp	2009-03-09 15:24:31 EDT (Mon, 09 Mar 2009)
@@ -15,61 +15,65 @@
 
 int main(int argc, const char *argv[])
 {
-	if(argc < 3)
-	{
-		std::cerr << "Too few arguments: need output directory and input file name(s).\n";
-		return -1;
-	}
-	static const std::string output_directory = argv[1];
-	static const int num_files = argc - 2;
-	int i;
-	for(i = 0; i < num_files; ++i)
-	{
-		const std::string file_name = argv[2 + i];
-		std::cout << "opening file: " << file_name << std::endl;
-		std::ifstream infile(file_name.c_str());
-		bool inside_snippet = false;
-		std::ofstream snippet_out_file;
-		while(infile.good())
-		{
-			std::string line;
-			getline(infile, line);
-			if(infile.bad()) break;
-			if(inside_snippet)
-			{
-				size_t snippet_end_pos = line.find("//]");
-				if(snippet_end_pos == std::string::npos)
-				{
-					snippet_out_file << line << "\n";
-				}else
-				{
-					inside_snippet = false;
-					std::cout << "done.\n";
-					continue;
-				}
-			}else
-			{
-				size_t snippet_start_pos = line.find("//[");
-				if(snippet_start_pos == std::string::npos)
-				{
-					continue;
-				}else
-				{
-					inside_snippet = true;
-					std::string snippet_name = line.substr(snippet_start_pos + 3);
-					std::istringstream snippet_stream(snippet_name);
-					snippet_stream >> snippet_name;
-					if(snippet_name == "")
-					{
-						throw std::runtime_error("failed to obtain snippet name");
-					}
-					snippet_out_file.close();
-					snippet_out_file.open(std::string(output_directory + "/" + snippet_name + ".txt").c_str());
-					std::cout << "processing snippet \"" << snippet_name << "\"... ";
-					continue;
-				}
-			}
-		}
-	}
-	return 0;
+  if(argc < 3)
+  {
+    std::cerr << "Too few arguments: need output directory and input file name(s).\n";
+    return -1;
+  }
+  static const std::string output_directory = argv[1];
+  static const int num_files = argc - 2;
+  int i;
+  for(i = 0; i < num_files; ++i)
+  {
+    const std::string file_name = argv[2 + i];
+    std::cout << "opening file: " << file_name << std::endl;
+    std::ifstream infile(file_name.c_str());
+    bool inside_snippet = false;
+    std::ofstream snippet_out_file;
+    while(infile.good())
+    {
+      std::string line;
+      getline(infile, line);
+      if(infile.bad()) break;
+      if(inside_snippet)
+      {
+        size_t snippet_end_pos = line.find("//]");
+        if(snippet_end_pos == std::string::npos)
+        {
+          snippet_out_file << line << "\n";
+        }else
+        {
+          snippet_out_file << "]]></code>";
+          inside_snippet = false;
+          std::cout << "done.\n";
+          continue;
+        }
+      }else
+      {
+        size_t snippet_start_pos = line.find("//[");
+        if(snippet_start_pos == std::string::npos)
+        {
+          continue;
+        }else
+        {
+          inside_snippet = true;
+          std::string snippet_name = line.substr(snippet_start_pos + 3);
+          std::istringstream snippet_stream(snippet_name);
+          snippet_stream >> snippet_name;
+          if(snippet_name == "")
+          {
+            throw std::runtime_error("failed to obtain snippet name");
+          }
+          snippet_out_file.close();
+          snippet_out_file.open(std::string(output_directory + "/" + snippet_name + ".xml").c_str());
+          snippet_out_file << "<!-- Code snippet \"" << snippet_name <<
+            "\" extracted from \"" << file_name << "\" by snippet_extractor.\n" <<
+            "--><code><![CDATA[";
+          std::cout << "processing snippet \"" << snippet_name << "\"... ";
+          continue;
+        }
+      }
+    }
+  }
+  return 0;
 }
Modified: trunk/libs/signals2/doc/tutorial.xml
==============================================================================
--- trunk/libs/signals2/doc/tutorial.xml	(original)
+++ trunk/libs/signals2/doc/tutorial.xml	2009-03-09 15:24:31 EDT (Mon, 09 Mar 2009)
@@ -58,8 +58,8 @@
 <code>sig</code> like a function to call the slots, which in turns
 invokes <code>HelloWorld::operator()</code> to print "Hello,
 World!".</para>
-<programlisting><xi:include href="./snippets/hello_world_def_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="hello_world_def_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
   <informaltable>
     <tgroup cols="2" align="left">
       <thead>
@@ -71,8 +71,8 @@
       <tbody>
         <row>
           <entry>
-<programlisting><xi:include href="./snippets/hello_world_single_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="hello_world_single_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 </entry>
 <entry>
 <programlisting>  // Signal with no arguments and a void return value
@@ -99,12 +99,12 @@
 the work of printing "Hello, World!" into two completely separate
 slots. The first slot will print "Hello" and may look like
 this:</para>
-<programlisting><xi:include href="./snippets/hello_def_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="hello_def_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <para>The second slot will print ", World!" and a newline, to complete
 the program. The second slot may look like this:</para>
-<programlisting><xi:include href="./snippets/world_def_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="world_def_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <para>Like in our previous example, we can create a signal
 <code>sig</code> that takes no arguments and has a
 <code>void</code> return value. This time, we connect both a
@@ -121,8 +121,8 @@
       <tbody>
         <row>
           <entry>
-<programlisting><xi:include href="./snippets/hello_world_multi_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="hello_world_multi_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
           </entry>
           <entry>
 <programlisting>  boost::signals2::signal0<void> sig;
@@ -166,8 +166,8 @@
       <tbody>
         <row>
           <entry>
-<programlisting><xi:include href="./snippets/hello_world_ordered_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="hello_world_ordered_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 </entry>
             <entry>
 <programlisting>  boost::signals2::signal0<void> sig;
@@ -203,10 +203,10 @@
 <para>
   If we add a new slot to our example like this:
 </para>
-<programlisting><xi:include href="./snippets/good_morning_def_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
-<programlisting><xi:include href="./snippets/hello_world_ordered_invoke_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="good_morning_def_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
+<programlisting><xi:include href="hello_world_ordered_invoke_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <para>... we will get the result we wanted:</para>
 <programlisting>
 Hello, World!
@@ -225,8 +225,8 @@
 <code>float</code> arguments to its slots. Then we'll create a few
 slots that print the results of various arithmetic operations on
 these values.</para>
-<programlisting><xi:include href="./snippets/slot_arguments_slot_defs_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="slot_arguments_slot_defs_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
   <informaltable>
     <tgroup cols="2" align="left">
       <thead>
@@ -238,8 +238,8 @@
       <tbody>
         <row>
           <entry>
-<programlisting><xi:include href="./snippets/slot_arguments_main_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="slot_arguments_main_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 </entry>
 <entry>
 <programlisting>  boost::signals2::signal2<void, float, float> sig;
@@ -288,8 +288,8 @@
 slightly so that the slots all return the results of computing the
 product, quotient, sum, or difference. Then the signal itself can
 return a value based on these results to be printed:</para>
-<programlisting><xi:include href="./snippets/signal_return_value_slot_defs_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="signal_return_value_slot_defs_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
   <informaltable>
     <tgroup cols="2" align="left">
       <thead>
@@ -310,8 +310,8 @@
           </tbody>
         </tgroup>
       </informaltable>
-<programlisting><xi:include href="./snippets/signal_return_value_main_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="signal_return_value_main_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
 <para>This example program will output <code>2</code>. This is because the
 default behavior of a signal that has a return type
@@ -324,8 +324,8 @@
 <para>A more interesting signal result would be the maximum of the
 values returned by any slot. To do this, we create a custom
 combiner that looks like this:</para>
-<programlisting><xi:include href="./snippets/custom_combiners_maximum_def_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="custom_combiners_maximum_def_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <para>The <code>maximum</code> class template acts as a function
 object. Its result type is given by its template parameter, and
 this is the type it expects to be computing the maximum based on
@@ -368,8 +368,8 @@
 
 <para>Now we can connect slots that perform arithmetic functions and
 use the signal:</para>
-<programlisting><xi:include href="./snippets/custom_combiners_maximum_usage_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="custom_combiners_maximum_usage_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <para>The output of this program will be <code>15</code>, because
 regardless of the order in which the slots are connected, the product
 of 5 and 3 will be larger than the quotient, sum, or
@@ -377,8 +377,8 @@
 <para>In other cases we might want to return all of the values
 computed by the slots together, in one large data structure. This
 is easily done with a different combiner:</para>
-<programlisting><xi:include href="./snippets/custom_combiners_aggregate_values_def_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="custom_combiners_aggregate_values_def_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <para>
 Again, we can create a signal with this new combiner:
 </para>
@@ -406,8 +406,8 @@
           </tbody>
         </tgroup>
       </informaltable>
-<programlisting><xi:include href="./snippets/custom_combiners_aggregate_values_usage_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="custom_combiners_aggregate_values_usage_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <para>The output of this program will contain 15, 8, 1.6667, and 2. It
 is interesting here that
 the first template argument for the <code>signal</code> class,
@@ -465,8 +465,8 @@
 called. Each call to the signal's <code>connect()</code> method
 returns a connection object, which can be used to determine if the
 connection still exists or to disconnect the signal and slot.</para>
-<programlisting><xi:include href="./snippets/disconnect_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="disconnect_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 </section>
 
 <section><title>Blocking Slots (Beginner)</title>
@@ -485,8 +485,8 @@
 Here is an example of
 blocking/unblocking slots:</para>
 
-<programlisting><xi:include href="./snippets/block_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="block_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
 </section>
 
@@ -496,8 +496,8 @@
 the <code>scoped_connection</code> class goes out of scope. This
 ability is useful when a connection need only be temporary,
 e.g.,</para>
-<programlisting><xi:include href="./snippets/scoped_connection_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="scoped_connection_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
 <para>
   Note, attempts to initialize a scoped_connection with the assignment syntax
@@ -526,8 +526,8 @@
 operator. For instance:
 
 </para>
-<programlisting><xi:include href="./snippets/disconnect_by_slot_def_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="disconnect_by_slot_def_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
   <informaltable>
     <tgroup cols="2" align="left">
       <thead>
@@ -550,8 +550,8 @@
       </informaltable>
 
 </section>
-<programlisting><xi:include href="./snippets/disconnect_by_slot_usage_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="disconnect_by_slot_usage_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
 <section id="signals2.tutorial.connection-management"><title>Automatic Connection Management (Intermediate)</title>
 <para>Boost.Signals2 can automatically track the lifetime of objects
@@ -734,11 +734,11 @@
 <code>slot_type</code> for each particular signal type and any
 function object compatible with the signature of the signal can be
 passed to a <code>slot_type</code> parameter. For instance:</para>
-<programlisting><xi:include href="./snippets/passing_slots_defs_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<programlisting><xi:include href="passing_slots_defs_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 <programlisting>
-<xi:include href="./snippets/passing_slots_usage_code_snippet.txt"
-	xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+<xi:include href="passing_slots_usage_code_snippet.xml"
+  xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
 <para>The <code>doOnClick</code> method is now functionally equivalent
 to the <code>connect</code> method of the <code>onClick</code>
@@ -757,8 +757,8 @@
   that it stores a single signal to which all of the views will be
   connected.</para>
 
-  <programlisting><xi:include href="./snippets/document_def_code_snippet.txt"
-    xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+  <programlisting><xi:include href="document_def_code_snippet.xml"
+    xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
   <para>
     Next, we can begin to define views. The
@@ -766,15 +766,15 @@
     document text.
   </para>
 
-  <programlisting><xi:include href="./snippets/text_view_def_code_snippet.txt"
-    xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+  <programlisting><xi:include href="text_view_def_code_snippet.xml"
+    xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
   <para>Alternatively, we can provide a view of the document
     translated into hex values using the <code>HexView</code>
     view:</para>
 
-  <programlisting><xi:include href="./snippets/hex_view_def_code_snippet.txt"
-    xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+  <programlisting><xi:include href="hex_view_def_code_snippet.xml"
+    xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
   <para>
     To tie the example together, here is a
@@ -782,8 +782,8 @@
     modifies the document:
   </para>
 
-  <programlisting><xi:include href="./snippets/document_view_main_code_snippet.txt"
-    xmlns:xi="http://www.w3.org/2001/XInclude" parse="text"/></programlisting>
+  <programlisting><xi:include href="document_view_main_code_snippet.xml"
+    xmlns:xi="http://www.w3.org/2001/XInclude" parse="xml"/></programlisting>
 
   <para>The complete example source, contributed by Keith MacDonald,
     is available in the <link linkend="signals2.examples.document-view">examples</link> section.