ContextFactory.h revision affc150dc44fab1911775a49636d0ce85333b634
14b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes//===- ContextFactory.h ---------------------------------------------------===//
24b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes//
34b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes//                     The MCLinker Project
44b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes//
54b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes// This file is distributed under the University of Illinois Open Source
64b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes// License. See LICENSE.TXT for details.
74b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes//
84b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes//===----------------------------------------------------------------------===//
94b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#ifndef MCLD_CONTEXT_FACTORY_H
104b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#define MCLD_CONTEXT_FACTORY_H
114b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#ifdef ENABLE_UNITTEST
124b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#include <gtest.h>
134b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#endif
144b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes
154b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#include <mcld/LD/LDContext.h>
164b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#include <mcld/Support/UniqueGCFactory.h>
174b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes#include <mcld/Support/Path.h>
184b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes
194b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughesnamespace mcld
204b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes{
214b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes/** \class ContextFactory
224b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  \brief ContextFactory avoids the duplicated LDContext of the same file.
234b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *
244b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  MCLinker is designed for efficient memory usage. Because user can give
254b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  MCLinker the same input file many times on the command line, MCLinker must
264b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  avoid opening identical file twice.
274b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *
284b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  ContextFactory is the guard to prevent redundant opening. MCLinker does not
294b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  create LDContext directly. Instead, it creates LDContext by ContextFactory.
304b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  ContextFactory returns the identical reference of LDContext if it's openend.
314b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *
3205fc1d7050d5451aea08dc5f504d2670287b2d43Elliott Hughes *  @see LDContext
334b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes *  @see UniqueGCFactoryBase
347086ad6919feb2415c6027163f5c63323bcca27cElliott Hughes */
354b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughesclass ContextFactory : public UniqueGCFactoryBase<sys::fs::Path, LDContext, 0>
364b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes{
374b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughespublic:
3803eebcb6e8762e668a0d3af6bb303cccb88c5b81Christopher Ferris  explicit ContextFactory(size_t pNum);
398cf1b305670123aed7638d984ca39bfd22388440Yabin Cui  ~ContextFactory();
404b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes
414b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes  LDContext* produce();
428f2a5a0b40fc82126c691d5c30131d908772aab7Elliott Hughes  LDContext* produce(const sys::fs::Path& pPath);
434b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes};
444b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes
454b4a8824289c48c823cd38bc63289d121aae3d67Elliott Hughes} // namespace of mcld
460d236aa3f1e6d31b0c729448ae9d3ed1cad23fb4Elliott Hughes
470d236aa3f1e6d31b0c729448ae9d3ed1cad23fb4Elliott Hughes#endif
480d236aa3f1e6d31b0c729448ae9d3ed1cad23fb4Elliott Hughes
490d236aa3f1e6d31b0c729448ae9d3ed1cad23fb4Elliott Hughes