Wallaroo  0.8
dynamic_loader.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * wallaroo - A library for configurable creation and wiring of C++ classes.
3  * Copyright (C) 2012 Daniele Pallastrelli
4  *
5  * This file is part of wallaroo.
6  * For more information, see http://wallaroolib.sourceforge.net/
7  *
8  * Boost Software License - Version 1.0 - August 17th, 2003
9  *
10  * Permission is hereby granted, free of charge, to any person or organization
11  * obtaining a copy of the software and accompanying documentation covered by
12  * this license (the "Software") to use, reproduce, display, distribute,
13  * execute, and transmit the Software, and to prepare derivative works of the
14  * Software, and to permit third-parties to whom the Software is furnished to
15  * do so, all subject to the following:
16  *
17  * The copyright notices in the Software and this entire statement, including
18  * the above license grant, this restriction and the following disclaimer,
19  * must be included in all copies of the Software, in whole or in part, and
20  * all derivative works of the Software, unless such copies or derivative
21  * works are solely in the form of machine-executable object code generated by
22  * a source language processor.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
27  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
28  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
29  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  ******************************************************************************/
32 
33 #ifndef WALLAROO_DYNAMIC_LOADER_H_
34 #define WALLAROO_DYNAMIC_LOADER_H_
35 
36 #include <string>
37 #include <vector>
38 #include "cxx0x.h"
39 #include "part.h"
40 #include "class.h"
41 #include "exceptions.h"
43 #include "detail/dynamic_library.h"
44 
45 namespace wallaroo
46 {
47 
60 class Plugin
61 {
62 public:
69  static cxx0x::shared_ptr< Plugin > Load( const std::string& fileName )
70  {
71  using namespace detail;
72  cxx0x::shared_ptr< Plugin > p( new Plugin( fileName ) );
73  typedef std::vector< Descriptor >* (*Function)(void);
74  Function GetClasses = p -> library.GetFunction< Function >( "GetClasses" );
75  if ( GetClasses == nullptr ) throw WrongFile( fileName );
76  std::vector< Descriptor >* descriptors = GetClasses();
77  for ( std::size_t i = 0; i < descriptors -> size(); ++i )
78  Class< void, void >::Register( (*descriptors)[ i ].name, (*descriptors)[ i ].create, p );
79  return p;
80  }
86  static std::string Suffix()
87  {
89  }
90 private:
91  // throw WrongFile if the file does not exist or its format is wrong.
92  Plugin( const std::string& fileName ) :
93  library( fileName )
94  {
95  }
96  detail::DynamicLibrary library;
97 };
98 
99 } // namespace wallaroo
100 
101 #endif // WALLAROO_DYNAMIC_LOADER_H_
static std::string Suffix()
Definition: dynamic_loader.h:86
WALLAROO_DLL_PREFIX std::vector< wallaroo::detail::Descriptor > * GetClasses()
Definition: dynamic_lib.h:49
Definition: dynamic_loader.h:60
Definition: class.h:54
static std::string Suffix()
Definition: dynamic_library.h:79
Definition: attribute.h:45
Definition: exceptions.h:176
static cxx0x::shared_ptr< Plugin > Load(const std::string &fileName)
Definition: dynamic_loader.h:69