LayoutsFactory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2002, Log4cpp Project. All rights reserved.
3  *
4  * See the COPYING file for the terms of usage and distribution.
5  */
6 
8 #include <stdexcept>
9 
10 namespace log4cpp
11 {
13 
14  std::auto_ptr<Layout> create_simple_layout(const FactoryParams& params);
15  std::auto_ptr<Layout> create_basic_layout(const FactoryParams& params);
16  std::auto_ptr<Layout> create_pattern_layout(const FactoryParams& params);
17  std::auto_ptr<Layout> create_pattern_layout(const FactoryParams& params);
18  std::auto_ptr<Layout> create_pass_through_layout(const FactoryParams& params);
19 
21  {
22  if (!layouts_factory_)
23  {
24  std::auto_ptr<LayoutsFactory> lf(new LayoutsFactory);
25  lf->registerCreator("simple", &create_simple_layout);
26  lf->registerCreator("basic", &create_basic_layout);
27  lf->registerCreator("pattern", &create_pattern_layout);
28  lf->registerCreator("pass through", &create_pass_through_layout);
29  layouts_factory_ = lf.release();
30  }
31 
32  return *layouts_factory_;
33  }
34 
35  void LayoutsFactory::registerCreator(const std::string& class_name, create_function_t create_function)
36  {
37  const_iterator i = creators_.find(class_name);
38  if (i != creators_.end())
39  throw std::invalid_argument("Layout creator for type name '" + class_name + "' allready registered");
40 
41  creators_[class_name] = create_function;
42  }
43 
44  std::auto_ptr<Layout> LayoutsFactory::create(const std::string& class_name, const params_t& params)
45  {
46  const_iterator i = creators_.find(class_name);
47  if (i == creators_.end())
48  throw std::invalid_argument("There is no layout with type name '" + class_name + "'");
49 
50  return (*i->second)(params);
51  }
52 
53  bool LayoutsFactory::registed(const std::string& class_name) const
54  {
55  return creators_.find(class_name) != creators_.end();
56  }
57 }
std::auto_ptr< Layout > create_pass_through_layout(const FactoryParams &params)
std::auto_ptr< Layout > create_basic_layout(const FactoryParams &params)
Definition: BasicLayout.cpp:40
creators_t::const_iterator const_iterator
std::auto_ptr< Layout > create_simple_layout(const FactoryParams &params)
bool registed(const std::string &class_name) const
void registerCreator(const std::string &class_name, create_function_t create_function)
static LayoutsFactory * layouts_factory_
std::auto_ptr< Layout > create(const std::string &class_name, const params_t &params)
std::auto_ptr< Layout > create_pattern_layout(const FactoryParams &params)
static LayoutsFactory & getInstance()
std::auto_ptr< Layout >(* create_function_t)(const params_t &params)


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:14:17