1 //===--- Handlers.h - Interfaces for receiving information ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Abstract interfaces for receiving information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_INDEX_HANDLERS_H
15 #define LLVM_CLANG_INDEX_HANDLERS_H
17 #include "llvm/ADT/SmallVector.h"
23 class TranslationUnit;
26 /// \brief Abstract interface for receiving Entities.
29 typedef Entity receiving_type;
31 virtual ~EntityHandler();
32 virtual void Handle(Entity Ent) = 0;
35 /// \brief Abstract interface for receiving TranslationUnits.
36 class TranslationUnitHandler {
38 typedef TranslationUnit* receiving_type;
40 virtual ~TranslationUnitHandler();
41 virtual void Handle(TranslationUnit *TU) = 0;
44 /// \brief Abstract interface for receiving TULocations.
45 class TULocationHandler {
47 typedef TULocation receiving_type;
49 virtual ~TULocationHandler();
50 virtual void Handle(TULocation TULoc) = 0;
53 /// \brief Helper for the Handler classes. Stores the objects into a vector.
56 /// Storing<TranslationUnitHandler> TURes;
57 /// IndexProvider.GetTranslationUnitsFor(Entity, TURes);
58 /// for (Storing<TranslationUnitHandler>::iterator
59 /// I = TURes.begin(), E = TURes.end(); I != E; ++I) { ....
61 template <typename handler_type>
62 class Storing : public handler_type {
63 typedef typename handler_type::receiving_type receiving_type;
64 typedef llvm::SmallVector<receiving_type, 8> StoreTy;
68 virtual void Handle(receiving_type Obj) {
72 typedef typename StoreTy::const_iterator iterator;
73 iterator begin() const { return Store.begin(); }
74 iterator end() const { return Store.end(); }