TriggeringEventEvaluatorFactory.cpp
Go to the documentation of this file.
00001 #include <log4cpp/TriggeringEventEvaluatorFactory.hh>
00002 #include <stdexcept>
00003 
00004 namespace log4cpp
00005 {
00006    static TriggeringEventEvaluatorFactory* evaluators_factory_ = 0;
00007    std::auto_ptr<TriggeringEventEvaluator> create_level_evaluator(const FactoryParams& params);
00008 
00009    TriggeringEventEvaluatorFactory& TriggeringEventEvaluatorFactory::getInstance()
00010    {
00011       if (!evaluators_factory_)
00012       {
00013          std::auto_ptr<TriggeringEventEvaluatorFactory> af(new TriggeringEventEvaluatorFactory);
00014          af->registerCreator("level", &create_level_evaluator);
00015          evaluators_factory_ = af.release();
00016       }
00017 
00018       return *evaluators_factory_;
00019    }
00020 
00021    void TriggeringEventEvaluatorFactory::registerCreator(const std::string& class_name, create_function_t create_function)
00022    {
00023       const_iterator i = creators_.find(class_name);
00024       if (i != creators_.end())
00025          throw std::invalid_argument("Creator for Triggering event evaluator with type name '" + class_name + "' allready registered");
00026 
00027       creators_[class_name] = create_function;
00028    }
00029 
00030    std::auto_ptr<TriggeringEventEvaluator> TriggeringEventEvaluatorFactory::create(const std::string& class_name, const params_t& params)
00031    {
00032       const_iterator i = creators_.find(class_name);
00033       if (i == creators_.end())
00034          throw std::invalid_argument("There is no triggering event evaluator with type name '" + class_name + "'");
00035 
00036       return (*i->second)(params);
00037    }
00038 
00039    bool TriggeringEventEvaluatorFactory::registered(const std::string& class_name) const
00040    {
00041       return creators_.end() != creators_.find(class_name);
00042    }
00043 }
00044 


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung.
autogenerated on Wed Sep 16 2015 10:27:14