FV3 Bundle
WeightingFct.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include "oops/base/WeightingFct.h"
12 
13 #include <map>
14 #include <string>
15 
16 #include "eckit/config/Configuration.h"
17 #include "oops/util/abor1_cpp.h"
18 #include "oops/util/Logger.h"
19 
20 namespace oops {
21 
22 // -----------------------------------------------------------------------------
23 // Factory
24 // -----------------------------------------------------------------------------
25 
26 // We have to use a pointer here because we don't know the order in
27 // which objects are created and this causes problems with xlc.
28 
29 std::map < std::string, WeightFactory * > * WeightFactory::makers_ = 0;
30 
31 // -----------------------------------------------------------------------------
32 
33 WeightFactory::WeightFactory(const std::string & name) {
34  if (!makers_) makers_=new std::map < std::string, WeightFactory * >();
35 
36  if (makers_->find(name) != makers_->end()) {
37  Log::error() << name << " already registered in weight function factory." << std::endl;
38  ABORT("Element already registered in WeightFactory.");
39  }
40  (*makers_)[name] = this;
41 }
42 
43 // -----------------------------------------------------------------------------
44 
45 WeightingFct * WeightFactory::create(const eckit::Configuration & config) {
46  if (!makers_) makers_=new std::map < std::string, WeightFactory * >();
47 
48  std::string id = config.getString("type");
49  std::map<std::string, WeightFactory *>::iterator j = makers_->find(id);
50  if (j == makers_->end()) {
51  Log::error() << id << " does not exist in weight function factory." << std::endl;
52  ABORT("Element does not exist in WeightFactory.");
53  }
54  return (*j).second->make(config);
55 }
56 
57 // -----------------------------------------------------------------------------
58 
59 } // namespace oops
static std::map< std::string, WeightFactory *> * makers_
Definition: WeightingFct.h:57
l_size ! loop over number of fields ke do j
character(len=32) name
The namespace for the main oops code.
integer error
Definition: mpp.F90:1310
WeightFactory(const std::string &)
Definition: WeightingFct.cc:33
Weighting Function.
Definition: WeightingFct.h:36
static WeightingFct * create(const eckit::Configuration &)
Definition: WeightingFct.cc:45