Handlers.h revision 94431b5b4ceca8831e1ed6d6f646b99052680a85
1//===--- Handlers.h - Interfaces for receiving information ------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  Abstract interfaces for receiving information.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_INDEX_HANDLERS_H
15#define LLVM_CLANG_INDEX_HANDLERS_H
16
17#include "llvm/ADT/SmallVector.h"
18
19namespace clang {
20
21namespace idx {
22  class Entity;
23  class TranslationUnit;
24
25/// \brief Abstract interface for receiving Entities.
26class EntityHandler {
27public:
28  typedef Entity receiving_type;
29
30  virtual ~EntityHandler();
31  virtual void Handle(Entity Ent) = 0;
32};
33
34/// \brief Abstract interface for receiving TranslationUnits.
35class TranslationUnitHandler {
36public:
37  typedef TranslationUnit* receiving_type;
38
39  virtual ~TranslationUnitHandler();
40  virtual void Handle(TranslationUnit *TU) = 0;
41};
42
43/// \brief Helper for the Handler classes. Stores the objects into a vector.
44/// example:
45/// @code
46/// Storing<TranslationUnitHandler> TURes;
47/// IndexProvider.GetTranslationUnitsFor(Entity, TURes);
48/// for (Storing<TranslationUnitHandler>::iterator
49///   I = TURes.begin(), E = TURes.end(); I != E; ++I) { ....
50/// @endcode
51template <typename handler_type>
52class Storing : public handler_type {
53  typedef typename handler_type::receiving_type receiving_type;
54  typedef llvm::SmallVector<receiving_type, 8> StoreTy;
55  StoreTy Store;
56
57public:
58  virtual void Handle(receiving_type Obj) {
59    Store.push_back(Obj);
60  }
61
62  typedef typename StoreTy::const_iterator iterator;
63  iterator begin() const { return Store.begin(); }
64  iterator end() const { return Store.end(); }
65};
66
67} // namespace idx
68
69} // namespace clang
70
71#endif
72