UFO
ObsFunctionBase.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UCAR
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  */
7 
9 
10 #include <map>
11 #include <string>
12 
13 #include "eckit/exception/Exceptions.h"
14 #include "oops/util/DateTime.h"
15 #include "oops/util/Logger.h"
16 
17 namespace ufo {
18 
19 const char *ObsFunctionTraits<float>::valueTypeName = "float";
20 const char *ObsFunctionTraits<int>::valueTypeName = "int";
21 const char *ObsFunctionTraits<std::string>::valueTypeName = "std::string";
22 const char *ObsFunctionTraits<util::DateTime>::valueTypeName = "util::DateTime";
23 
24 const char *ObsFunctionTraits<float>::groupName = "ObsFunction";
25 const char *ObsFunctionTraits<int>::groupName = "IntObsFunction";
26 const char *ObsFunctionTraits<std::string>::groupName = "StringObsFunction";
27 const char *ObsFunctionTraits<util::DateTime>::groupName = "DateTimeObsFunction";
28 
29 // -----------------------------------------------------------------------------
30 
31 template <typename FunctionValue>
33  if (getMakers().find(name) != getMakers().end()) {
34  throw eckit::UserError(name + " already registered in ufo::ObsFunctionFactory<" +
36  Here());
37  }
38  getMakers()[name] = this;
39 }
40 
41 // -----------------------------------------------------------------------------
42 
43 template <typename FunctionValue>
45  oops::Log::trace() << "ObsFunctionBase::create starting" << std::endl;
46  typename std::map<std::string, ObsFunctionFactory*>::iterator jloc =
47  getMakers().find(var.variable());
48  if (jloc == getMakers().end()) {
49  throw eckit::UserError(var.variable() + " does not exist in ufo::ObsFunctionFactory<" +
51  Here());
52  }
53  ObsFunctionBase<FunctionValue> * ptr = jloc->second->make(var.options());
54  oops::Log::trace() << "ObsFunctionFactory::create done" << std::endl;
55  return ptr;
56 }
57 
58 // -----------------------------------------------------------------------------
59 
60 template <typename FunctionValue>
61 bool ObsFunctionFactory<FunctionValue>::functionExists(const std::string & name) {
62  return (getMakers().find(name) != getMakers().end());
63 }
64 
65 // -----------------------------------------------------------------------------
66 
67 // Explicit instantiations for the supported value types
68 template class ObsFunctionFactory<float>;
69 template class ObsFunctionFactory<int>;
70 template class ObsFunctionFactory<std::string>;
72 
73 // -----------------------------------------------------------------------------
74 
75 } // namespace ufo
Factory of ObsFunctions producing values of type FunctionValue.
static bool functionExists(const std::string &)
ObsFunctionFactory(const std::string &)
static ObsFunctionBase< FunctionValue > * create(const Variable &)
const std::string & variable() const
Definition: Variable.cc:99
const eckit::LocalConfiguration & options() const
Definition: Variable.h:47
Definition: RunCRTM.h:27
static const char * valueTypeName
Name of the type of values produced by subclasses of ObsFunctionBase<float>.
static const char * groupName
Name of the group identifying ObsFunctions producing floats.
static const char * valueTypeName
Name of the type of values produced by subclasses of ObsFunctionBase<int>.
static const char * groupName
Name of the group identifying ObsFunctions producing ints.
static const char * valueTypeName
Name of the type of values produced by subclasses of ObsFunctionBase<std::string>.
static const char * groupName
Name of the group identifying ObsFunctions producing strings.
Common properties of ObsFunctions producing values of type FunctionValue.