RINGMesh  Version 5.0.0
A programming library for geological model meshes
test-factory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
36 #include <ringmesh/ringmesh_tests_config.h>
37 
38 #include <memory>
39 
40 #include <ringmesh/basic/factory.h>
41 
46 using namespace RINGMesh;
47 
48 class A
49 {
51 
52 public:
53  A() = default;
54 };
55 
56 class B
57 {
59 
60 public:
61  B() = default;
62 };
63 
64 class Base
65 {
66 public:
67  virtual ~Base() = default;
68 
69 protected:
70  Base( A& a, B& b ) : a_( a ), b_( b )
71  {
72  }
73 
74 protected:
75  A& a_;
76  B& b_;
77 };
78 
79 class Derived : public Base
80 {
81 public:
82  Derived( A& a, B& b ) : Base( a, b )
83  {
84  }
85 };
86 
87 void verdict( bool is_instantiated, std::string name )
88 {
89  if( !is_instantiated )
90  {
91  throw RINGMeshException(
92  "TEST", "Failed to instantiate the ", name, " class" );
93  }
94 }
95 
96 int main()
97 {
98  using namespace RINGMesh;
99 
100  try
101  {
103  Logger::out( "TEST", "Test Factory" );
104 
105  using factory = Factory< std::string, Base, A&, B& >;
106  factory::register_creator< Derived >( "Derived" );
107 
108  A a;
109  B b;
110  auto d = factory::create( "Derived", a, b );
111  verdict( d != nullptr, "Derived" );
112  }
113  catch( const RINGMeshException& e )
114  {
115  Logger::err( e.category(), e.what() );
116  return 1;
117  }
118  catch( const std::exception& e )
119  {
120  Logger::err( "Exception", e.what() );
121  return 1;
122  }
123  Logger::out( "TEST", "SUCCESS" );
124  return 0;
125 }
A & a_
int main()
void verdict(bool is_instantiated, std::string name)
Base(A &a, B &b)
static void err(const std::string &feature, const Args &... args)
Definition: logger.h:68
static void out(const std::string &feature, const Args &... args)
Definition: logger.h:61
B & b_
#define ringmesh_disable_copy(Class)
Definition: common.h:66
const std::string & category() const
Definition: common.h:165
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
Derived(A &a, B &b)
void RINGMESH_API default_configure()
Definition: common.cpp:99