• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ContextFactory.h ---------------------------------------------------===//
2 //
3 //                     The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef MCLD_CONTEXT_FACTORY_H
10 #define MCLD_CONTEXT_FACTORY_H
11 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 
15 #include <mcld/LD/LDContext.h>
16 #include <mcld/Support/UniqueGCFactory.h>
17 #include <mcld/Support/Path.h>
18 
19 namespace mcld
20 {
21 /** \class ContextFactory
22  *  \brief ContextFactory avoids the duplicated LDContext of the same file.
23  *
24  *  MCLinker is designed for efficient memory usage. Because user can give
25  *  MCLinker the same input file many times on the command line, MCLinker must
26  *  avoid opening identical file twice.
27  *
28  *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
29  *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
30  *  ContextFactory returns the identical reference of LDContext if it's openend.
31  *
32  *  @see LDContext
33  *  @see UniqueGCFactoryBase
34  */
35 class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>
36 {
37 public:
38   explicit ContextFactory(size_t pNum);
39   ~ContextFactory();
40 
41   LDContext* produce();
42   LDContext* produce(const sys::fs::Path& pPath);
43 };
44 
45 } // namespace of mcld
46 
47 #endif
48 
49