Boost logo

Boost-Commit :

From: mconsoni_at_[hidden]
Date: 2007-06-07 19:28:28


Author: mconsoni
Date: 2007-06-07 19:28:27 EDT (Thu, 07 Jun 2007)
New Revision: 4493
URL: http://svn.boost.org/trac/boost/changeset/4493

Log:
This is a new example inspired in the task 9) a. That task is to write a new
unit test to check edge cases, in this case a class with six parameters. As
I was starting to write the new unit test I wondered that maybe I could
first write an example showing the multiple parameters functionality and
then test it.

- parameters: new directory containing the new test.

        . main_lp: main function, creates the factory and constructs the
                   implementation.

        . lots_of_parameters_interface.hpp: a dummy interface.
        . lots_of_parameters.cpp: implementation of the interface with a
                                  constructor with six parameters.

Added:
   sandbox/libs/extension/examples/parameters/
   sandbox/libs/extension/examples/parameters/lots_of_parameters.cpp
   sandbox/libs/extension/examples/parameters/lots_of_parameters_interface.hpp
   sandbox/libs/extension/examples/parameters/main_lp.cpp
Text files modified:
   sandbox/libs/extension/examples/Jamfile.v2 | 4 ++++
   1 files changed, 4 insertions(+), 0 deletions(-)

Modified: sandbox/libs/extension/examples/Jamfile.v2
==============================================================================
--- sandbox/libs/extension/examples/Jamfile.v2 (original)
+++ sandbox/libs/extension/examples/Jamfile.v2 2007-06-07 19:28:27 EDT (Thu, 07 Jun 2007)
@@ -16,6 +16,9 @@
 exe HelloWorld : main.cpp ;
 lib HelloWorldLib : hello_world.cpp : <link>shared ;
 
+exe Parameters : parameters/main_lp.cpp ;
+lib ParametersLib : parameters/lots_of_parameters.cpp : <link>shared ;
+
 exe MultilanguageWord : info/multilanguage_main.cpp ;
 lib MultilanguageHelloWorld : info/multilanguage_hello_world.cpp : <link>shared ;
 
@@ -42,6 +45,7 @@
 
 install ../bin :
   HelloWorld HelloWorldLib
+ Parameters ParametersLib
   MultilanguageWord MultilanguageHelloWorld
   IM IMPlugins
   Vehicle Boat FlyingCar Car Plane

Added: sandbox/libs/extension/examples/parameters/lots_of_parameters.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/parameters/lots_of_parameters.cpp 2007-06-07 19:28:27 EDT (Thu, 07 Jun 2007)
@@ -0,0 +1,36 @@
+/* (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 "lots_of_parameters_interface.hpp"
+#include <boost/extension/factory_map.hpp>
+
+#include <iostream>
+
+class six_parameters : public lots_of_parameters_interface
+{
+public:
+ six_parameters(bool b, unsigned int i, char c, std::string s, A a, boost::shared_ptr<A> ptr_a)
+ : lots_of_parameters_interface(b, i, c, s, a, ptr_a)
+ {
+ std::cout << "Constructor called." << std::endl << std::endl;
+ std::cout << "Parameters:" << std::endl;
+ std::cout << "\tbool: " << b << std::endl;
+ std::cout << "\tunsigned int: " << i << std::endl;
+ std::cout << "\tchar: " << c << std::endl;
+ std::cout << "\tstring: " << s << std::endl;
+ std::cout << "\tA.i: " << a.i << std::endl;
+ std::cout << "\tptr_a->i: " << ptr_a->i << std::endl;
+ std::cout << std::endl;
+ }
+
+ virtual ~six_parameters(void) {}
+};
+
+
+extern "C" void BOOST_EXTENSION_EXPORT_DECL extension_export(boost::extensions::factory_map & fm)
+{
+ fm.add< six_parameters, lots_of_parameters_interface, int, bool, unsigned int, char, std::string, A, boost::shared_ptr<A> >(6);
+}

Added: sandbox/libs/extension/examples/parameters/lots_of_parameters_interface.hpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/parameters/lots_of_parameters_interface.hpp 2007-06-07 19:28:27 EDT (Thu, 07 Jun 2007)
@@ -0,0 +1,25 @@
+/* (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/shared_ptr.hpp>
+
+#include <string>
+
+class A
+{
+public:
+ A(unsigned int i) : i(i) {}
+ int i;
+};
+
+
+class lots_of_parameters_interface
+{
+public:
+ lots_of_parameters_interface(bool b, unsigned int i, char c, std::string s, A a, boost::shared_ptr<A> ptr_a) {}
+ virtual ~lots_of_parameters_interface(void) {}
+};
+

Added: sandbox/libs/extension/examples/parameters/main_lp.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/parameters/main_lp.cpp 2007-06-07 19:28:27 EDT (Thu, 07 Jun 2007)
@@ -0,0 +1,39 @@
+/* (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 <iostream>
+#include <boost/extension/convenience.hpp>
+
+#include "lots_of_parameters_interface.hpp"
+
+int main(void)
+{
+ 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, "libParametersLib.extension", "extension_export");
+
+ // Get a reference to the list of constructors for words.
+ std::list<factory<lots_of_parameters_interface, int, bool, unsigned int, char, std::string, A, boost::shared_ptr<A> > > & factory_list =
+ fm.get<lots_of_parameters_interface, int, bool, unsigned int, char, std::string, A, boost::shared_ptr<A> >();
+ if (factory_list.size() != 1) {
+ std::cout << "Error - the class was not found.";
+ return 1;
+ }
+
+ std::list< factory<lots_of_parameters_interface, int, bool, unsigned int, char, std::string, A, boost::shared_ptr<A> > >::iterator par = factory_list.begin();
+ std::auto_ptr< lots_of_parameters_interface > par_ptr(par->create(true, 4, 'c', "test", A(2), boost::shared_ptr<A>(new A(15))));
+
+ // TODO: use it
+
+ 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