15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- ContextFactory.h ---------------------------------------------------===//
25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//                     The MCLinker Project
45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source
65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details.
75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifndef MCLD_CONTEXT_FACTORY_H
105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#define MCLD_CONTEXT_FACTORY_H
115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifdef ENABLE_UNITTEST
125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <gtest.h>
135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif
145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/LD/LDContext.h>
165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Support/UniqueGCFactory.h>
175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Support/Path.h>
185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld
205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class ContextFactory
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  \brief ContextFactory avoids the duplicated LDContext of the same file.
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  MCLinker is designed for efficient memory usage. Because user can give
255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  MCLinker the same input file many times on the command line, MCLinker must
265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  avoid opening identical file twice.
275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  ContextFactory returns the identical reference of LDContext if it's openend.
315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  @see LDContext
335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  @see UniqueGCFactoryBase
345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */
355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>
365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  explicit ContextFactory(size_t pNum);
395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ~ContextFactory();
405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
41affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  LDContext* produce();
425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  LDContext* produce(const sys::fs::Path& pPath);
435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao};
445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} // namespace of mcld
465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif
485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
49