1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5
6#ifndef _FACTORY_H_
7#define _FACTORY_H_
8
9template<typename PRODUCT>
10class Factory
11{
12public:
13 virtual PRODUCT* Create() = 0;
14 virtual ~Factory() {}
15};
16
17template<typename PRODUCT, DWORD MAX_FACTORY_PRODUCT = 64>
18class InlineFactory : public Factory<PRODUCT>
19{
20public:
21 InlineFactory() : m_next(NULL), m_cProduct(0) { WRAPPER_NO_CONTRACT; }
22 ~InlineFactory() { WRAPPER_NO_CONTRACT; if (m_next) delete m_next; }
23 PRODUCT* Create();
24
25private:
26 InlineFactory* GetNext()
27 {
28 CONTRACTL {
29 NOTHROW;
30 GC_NOTRIGGER;
31 } CONTRACTL_END;
32
33 if (m_next == NULL)
34 {
35 m_next = new (nothrow) InlineFactory<PRODUCT, MAX_FACTORY_PRODUCT>();
36 }
37
38 return m_next;
39 }
40
41 InlineFactory* m_next;
42 PRODUCT m_product[MAX_FACTORY_PRODUCT];
43 INT32 m_cProduct;
44};
45
46#include "factory.inl"
47
48#endif
49
50