LLVM API Documentation

RegistryParser.h
Go to the documentation of this file.
00001 //=== RegistryParser.h - Linker-supported plugin registries -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Defines a command-line parser for a registry.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_SUPPORT_REGISTRYPARSER_H
00015 #define LLVM_SUPPORT_REGISTRYPARSER_H
00016 
00017 #include "llvm/Support/CommandLine.h"
00018 #include "llvm/Support/Registry.h"
00019 
00020 namespace llvm {
00021 
00022   /// A command-line parser for a registry. Use like such:
00023   ///
00024   ///   static cl::opt<Registry<Collector>::entry, false,
00025   ///                  RegistryParser<Collector> >
00026   ///   GCOpt("gc", cl::desc("Garbage collector to use."),
00027   ///               cl::value_desc());
00028   ///
00029   /// To make use of the value:
00030   ///
00031   ///   Collector *TheCollector = GCOpt->instantiate();
00032   ///
00033   template <typename T, typename U = RegistryTraits<T> >
00034   class RegistryParser :
00035   public cl::parser<const typename U::entry*>,
00036     public Registry<T, U>::listener {
00037     typedef U traits;
00038     typedef typename U::entry entry;
00039     typedef typename Registry<T, U>::listener listener;
00040 
00041   protected:
00042     void registered(const entry &E) {
00043       addLiteralOption(traits::nameof(E), &E, traits::descof(E));
00044     }
00045 
00046   public:
00047     void initialize(cl::Option &O) {
00048       listener::init();
00049       cl::parser<const typename U::entry*>::initialize(O);
00050     }
00051   };
00052 
00053 }
00054 
00055 #endif // LLVM_SUPPORT_REGISTRYPARSER_H