IODA Bundle
ODATranslator.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 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 /// \file ODATranslator.h
12 /// Piotr Kuchta - ECMWF June 2009
13 
14 #ifndef odc_ODATranslator_H
15 #define odc_ODATranslator_H
16 
17 #include "eckit/eckit.h"
18 #include "eckit/utils/Translator.h"
19 #include "eckit/types/Date.h"
20 #include "eckit/types/Time.h"
21 #include "odc/StringTool.h"
22 
23 template <typename T>
24 struct ODATranslator {
25  T operator()(double n) { return T(n); }
26 };
27 
28 template <>
29 struct ODATranslator<std::string> {
30  std::string operator()(double n)
31  {
32  std::string r (odc::StringTool::double_as_string(n));
33  eckit::Log::debug() << "ODATranslator<std::string>::operator()(double n=" << n << ") => " << r << std::endl;
34  return r;
35  }
36 };
37 
38 template <>
39 struct ODATranslator<eckit::Time> {
40  eckit::Time operator()(double n)
41  {
42  static const char * zeroes = "000000";
43 
44  std::string t (eckit::Translator<double, std::string>()(n));
45  if (t.size() < 6)
46  t = std::string(zeroes + t.size()) + t;
47 
48  eckit::Time tm (t);
49  eckit::Log::debug() << "ODATranslator<Time>::operator()(double n=" << n << ") => " << tm << std::endl;
50  return tm;
51  }
52 };
53 
54 template <>
55 struct ODATranslator<eckit::Date> {
56  eckit::Date operator()(double n)
57  {
58  static const char * zeroes ("000000");
59 
60  std::string t (eckit::Translator<long, std::string>()(n));
61  if (t.size() < 6)
62  t = std::string(zeroes + t.size()) + t;
63 
64  eckit::Date d (t);
65  eckit::Log::debug() << "ODATranslator<Date>::operator()(double n=" << n << ") => " << d << std::endl;
66  return d;
67  }
68 };
69 
70 #endif
static std::string double_as_string(double)
Definition: StringTool.cc:106
Definition: encode.cc:30
std::string operator()(double n)
Definition: ODATranslator.h:30
T operator()(double n)
Definition: ODATranslator.h:25