ContextFactory.h revision 37b74a387bb3993387029859c2d9d051c41c724e
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_MC_CONTEXTFACTORY_H_
10#define MCLD_MC_CONTEXTFACTORY_H_
11
12#include "mcld/LD/LDContext.h"
13#include "mcld/Support/UniqueGCFactory.h"
14#include "mcld/Support/Path.h"
15
16namespace mcld {
17/** \class ContextFactory
18 *  \brief ContextFactory avoids the duplicated LDContext of the same file.
19 *
20 *  MCLinker is designed for efficient memory usage. Because user can give
21 *  MCLinker the same input file many times on the command line, MCLinker must
22 *  avoid opening identical file twice.
23 *
24 *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
25 *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
26 *  ContextFactory returns the identical reference of LDContext if it's openend.
27 *
28 *  @see LDContext
29 *  @see UniqueGCFactoryBase
30 */
31class ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0> {
32 public:
33  explicit ContextFactory(size_t pNum);
34  ~ContextFactory();
35
36  LDContext* produce();
37  LDContext* produce(const sys::fs::Path& pPath);
38  LDContext* produce(const char* pPath);
39};
40
41}  // namespace mcld
42
43#endif  // MCLD_MC_CONTEXTFACTORY_H_
44