$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: mconsoni_at_[hidden]
Date: 2007-06-05 17:46:24
Author: mconsoni
Date: 2007-06-05 17:46:23 EDT (Tue, 05 Jun 2007)
New Revision: 4458
URL: http://svn.boost.org/trac/boost/changeset/4458
Log:
- word.hpp: just added an extra \n at the end to avoid gcc warnings.
- info directory: new example showing an use of the info class, in this case
                  different implementations of words according to the language.
        . multilanguage_main.cpp: main function that iterates over the factories
                                  showing the different implementations. Similar
                                  to hello world's main.cpp.
        . multilanguage_hello_world.cpp: definition of the implementations and 
                                         insertion in the factory map.
        . word_description.hpp: info struct for the word interface.
- Jamfile.v2: now the example is included.
Added:
   sandbox/libs/extension/examples/info/
   sandbox/libs/extension/examples/info/multilanguage_hello_world.cpp
   sandbox/libs/extension/examples/info/multilanguage_main.cpp
   sandbox/libs/extension/examples/info/word_description.hpp
Text files modified: 
   sandbox/libs/extension/examples/Jamfile.v2 |     7 ++++++-                                 
   sandbox/libs/extension/examples/word.hpp   |     2 +-                                      
   2 files changed, 7 insertions(+), 2 deletions(-)
Modified: sandbox/libs/extension/examples/Jamfile.v2
==============================================================================
--- sandbox/libs/extension/examples/Jamfile.v2	(original)
+++ sandbox/libs/extension/examples/Jamfile.v2	2007-06-05 17:46:23 EDT (Tue, 05 Jun 2007)
@@ -16,6 +16,9 @@
 exe HelloWorld : main.cpp ;
 lib HelloWorldLib : hello_world.cpp : <link>shared ;
 
+exe MultilanguageWord : info/multilanguage_main.cpp ;
+lib MultilanguageHelloWorld : info/multilanguage_hello_world.cpp : <link>shared ;
+
 lib Vehicle : multiple_inheritance/vehicle.cpp : <link>shared ;
 lib Car : multiple_inheritance/car.cpp Vehicle : <link>shared ;
 lib Plane : multiple_inheritance/plane.cpp Vehicle : <link>shared ;
@@ -35,7 +38,9 @@
 exe RegistryExample : registry/registry_example.cpp ;
 
 install ../bin : 
-  HelloWorld HelloWorldLib Vehicle Boat FlyingCar Car Plane
+  HelloWorld HelloWorldLib 
+  MultilanguageWord MultilanguageHelloWorld
+  Vehicle Boat FlyingCar Car Plane
   CarOfTheFuture MultipleInheritance RegistryLibrary Computer
   RegistryExample
   :
Added: sandbox/libs/extension/examples/info/multilanguage_hello_world.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/info/multilanguage_hello_world.cpp	2007-06-05 17:46:23 EDT (Tue, 05 Jun 2007)
@@ -0,0 +1,74 @@
+/* (C) Copyright Mariano G. Consoni 2007
+ * 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)
+ */
+
+#include "word_description.hpp"
+#include <boost/extension/factory_map.hpp>
+
+
+class world : public word
+{
+public:
+	virtual const char * get_val(){return "world!";}
+};
+
+class mundo : public word
+{
+public:
+	virtual const char * get_val(){return "mundo!";}
+};
+
+class monde : public word
+{
+public:
+	virtual const char * get_val(){return "monde!";}
+};
+
+class mondo : public word
+{
+public:
+	virtual const char * get_val(){return "mondo!";}
+};
+
+
+class hello : public word
+{
+public:
+	virtual const char * get_val(){return "hello";}
+};
+
+class hola : public word
+{
+public:
+	virtual const char * get_val(){return "hola";}
+};
+
+class bonjour : public word
+{
+public:
+	virtual const char * get_val(){return "bonjour";}
+};
+
+class buonasera : public word
+{
+public:
+	virtual const char * get_val(){return "buonasera";}
+};
+
+
+extern "C" void BOOST_EXTENSION_EXPORT_DECL extension_export_multilanguage_word(boost::extensions::factory_map & fm)
+{
+	fm.add<hola, word, word_description>(word_description("spanish", "hello"));
+	fm.add<mundo, word, word_description>(word_description("spanish", "world!"));
+
+	fm.add<bonjour, word, word_description>(word_description("french", "hello"));
+	fm.add<monde, word, word_description>(word_description("french", "world!"));
+
+	fm.add<buonasera, word, word_description>(word_description("italian", "hello"));
+	fm.add<mondo, word, word_description>(word_description("italian", "world!"));
+
+	fm.add<hello, word, word_description>(word_description("english", "hello"));
+	fm.add<world, word, word_description>(word_description("english", "world!"));
+}
Added: sandbox/libs/extension/examples/info/multilanguage_main.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/info/multilanguage_main.cpp	2007-06-05 17:46:23 EDT (Tue, 05 Jun 2007)
@@ -0,0 +1,45 @@
+/* (C) Copyright Mariano G. Consoni 2007
+ * 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)
+ */
+
+#include <boost/extension/factory_map.hpp>
+#include <boost/extension/shared_library.hpp>
+#include <boost/extension/convenience.hpp>
+
+#include <iostream>
+
+#include "word_description.hpp"
+
+int main()
+{
+	using namespace boost::extensions;
+	//  Create the factory_map object - it will hold all of the available
+	//  constructors. Multiple factory_maps can be constructed.
+	factory_map fm;
+
+	// load the shared library with 
+	load_single_library(fm, "libMultilanguageHelloWorld.extension", "extension_export_multilanguage_word");
+	//  Get a reference to the list of constructors for words.
+	std::list<factory<word, word_description> > & factory_list = fm.get<word, word_description>();  
+
+	if (factory_list.size() < 4+4) {
+		std::cout << "Error - the classes were not found (" << factory_list.size() << " classes)" << std::endl;
+		return 1;
+	}
+
+	for (std::list<factory<word, word_description> >::iterator current_word = factory_list.begin();
+	     current_word != factory_list.end(); ++current_word)
+	{
+		//  Using auto_ptr to avoid needing delete. Using smart_ptrs is recommended.
+		//  Note that this has a zero argument constructor - currently constructors
+		//  with up to six arguments can be used.
+		std::auto_ptr<word> word_ptr(current_word->create());
+		std::cout << word_ptr->get_val() << " is " << current_word->get_info().english_translation 
+			  << " in " << current_word->get_info().language << std::endl;
+	}
+	std::cout << std::endl;
+
+	return 0;
+}
Added: sandbox/libs/extension/examples/info/word_description.hpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/info/word_description.hpp	2007-06-05 17:46:23 EDT (Tue, 05 Jun 2007)
@@ -0,0 +1,18 @@
+/* (C) Copyright Mariano G. Consoni 2007
+ * 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)
+ */
+
+#include "../word.hpp"
+#include <string>
+
+// info class for word interface
+struct word_description
+{
+	std::string language;
+	std::string english_translation;
+
+	word_description(std::string language, std::string english_translation)
+		: language(language), english_translation(english_translation) {}
+};
Modified: sandbox/libs/extension/examples/word.hpp
==============================================================================
--- sandbox/libs/extension/examples/word.hpp	(original)
+++ sandbox/libs/extension/examples/word.hpp	2007-06-05 17:46:23 EDT (Tue, 05 Jun 2007)
@@ -9,4 +9,4 @@
 public:
   virtual ~word(){}
   virtual const char * get_val(){return "";}
-};
\ No newline at end of file
+};