1//===- ContextFactory.cpp -------------------------------------------------===//
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#include <mcld/LD/LDContext.h>
10#include <mcld/MC/ContextFactory.h>
11
12using namespace mcld;
13
14//===---------------------------------------------------------------------===//
15// LDContextFactory
16ContextFactory::ContextFactory(size_t pNum)
17  : UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>(pNum)
18{
19}
20
21ContextFactory::~ContextFactory()
22{
23}
24
25LDContext* ContextFactory::produce(const sys::fs::Path& pPath)
26{
27  LDContext* result = find(pPath);
28  if (0 == result) {
29    result = UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>::allocate();
30    new (result) LDContext();
31    f_KeyMap.insert(std::make_pair(pPath, result));
32  }
33  return result;
34}
35
36LDContext* ContextFactory::produce()
37{
38  LDContext* result = allocate();
39  new (result) LDContext();
40  return result;
41}
42
43