LayoutsFactory.cpp
Go to the documentation of this file.
00001 #include <log4cpp/LayoutsFactory.hh>
00002 #include <stdexcept>
00003 
00004 namespace log4cpp
00005 {
00006    static LayoutsFactory* layouts_factory_ = 0;\
00007 
00008    std::auto_ptr<Layout> create_simple_layout(const FactoryParams& params);
00009    std::auto_ptr<Layout> create_basic_layout(const FactoryParams& params);
00010    std::auto_ptr<Layout> create_pattern_layout(const FactoryParams& params);
00011    std::auto_ptr<Layout> create_pattern_layout(const FactoryParams& params);
00012    std::auto_ptr<Layout> create_pass_through_layout(const FactoryParams& params);
00013 
00014    LayoutsFactory& LayoutsFactory::getInstance()
00015    {
00016       if (!layouts_factory_)
00017       {
00018          std::auto_ptr<LayoutsFactory> lf(new LayoutsFactory);
00019          lf->registerCreator("simple", &create_simple_layout);
00020          lf->registerCreator("basic", &create_basic_layout);
00021          lf->registerCreator("pattern", &create_pattern_layout);
00022          lf->registerCreator("pass through", &create_pass_through_layout);
00023          layouts_factory_ = lf.release();
00024       }
00025 
00026       return *layouts_factory_;
00027    }
00028 
00029    void LayoutsFactory::registerCreator(const std::string& class_name, create_function_t create_function)
00030    {
00031       const_iterator i = creators_.find(class_name);
00032       if (i != creators_.end())
00033          throw std::invalid_argument("Layout creator for type name '" + class_name + "' allready registered");
00034 
00035       creators_[class_name] = create_function;
00036    }
00037 
00038    std::auto_ptr<Layout> LayoutsFactory::create(const std::string& class_name, const params_t& params)
00039    {
00040       const_iterator i = creators_.find(class_name);
00041       if (i == creators_.end())
00042          throw std::invalid_argument("There is no layout with type name '" + class_name + "'");
00043 
00044       return (*i->second)(params);
00045    }
00046 
00047    bool LayoutsFactory::registed(const std::string& class_name) const
00048    {
00049       return creators_.find(class_name) != creators_.end();
00050    }
00051 }


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Aug 14 2016 03:18:26