Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
constant-factory.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This file is part of the gobelijn software.
4  * Gobelijn is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or any later
7  * version. Gobelijn is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9  * or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for details. You should have received
11  * a copy of the GNU General Public License along with the software. If not,
12  * see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2016, Jan Broeckhove.
15  */
21 #include "factory.h"
22 
23 namespace AbstractFactory {
28 template <typename TResult, typename... TArgs>
29 class ConstantFactory : public Factory<TResult, TArgs...>
30 {
31 public:
33  ConstantFactory(const TResult& value) : m_value(value) {}
34 
36  TResult Create(TArgs...) final { return m_value; }
37 
39  virtual ~ConstantFactory() = default;
40 
41 private:
42  TResult m_value;
43 };
44 } // namespace AbstractFactory
virtual ~ConstantFactory()=default
ConstantFactory(const TResult &value)
Creates a factory that always produces the given value.
A factory class template that always returns a constant, pre-defined value.
Factory interface.
TResult Create(TArgs...) final
Instructs this factory to create a value.
A class template for abstract factories: objects that construct values based on their internal state...
Definition: factory.h:27