unitconv.h 2.72 KB
Newer Older
1
2
3
4
//================================================================================
// Name        : unitconv.h
// Author      : Axel Auweter
// Copyright   : Leibniz Supercomputing Centre
Michael Ott's avatar
Michael Ott committed
5
// Description : C++ API for conversion of units in libdcdb.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//================================================================================
Axel Auweter's avatar
Axel Auweter committed
26
27
28
29

#include <cstdint>
#include <string>

30
31
32
33
34
#ifndef DCDB_UNITCONV_H
#define DCDB_UNITCONV_H

namespace DCDB {

35
/**
Michael Ott's avatar
Michael Ott committed
36
 * Enum type describing all units supported by the libdcdb's unit conversion scheme.
37
 */
Axel Auweter's avatar
Axel Auweter committed
38
39
typedef enum {
  /* Undefined */
40
  Unit_None,
Axel Auweter's avatar
Axel Auweter committed
41
42

  /* Base units */
43
44
45
46
47
48
49
  Unit_Meter,
  Unit_Second,
  Unit_Ampere,
  Unit_Kelvin,
  Unit_Watt,
  Unit_Volt,
  Unit_Hertz,
50
51
  Unit_Joules,
  Unit_WattHours,
Axel Auweter's avatar
Axel Auweter committed
52

Axel Auweter's avatar
Axel Auweter committed
53
  /* Others */
54
55
  Unit_Celsius,
  Unit_Fahrenheit,
Axel Auweter's avatar
Axel Auweter committed
56

Michael Ott's avatar
Michael Ott committed
57
  /* 1e3 */
58
  Unit_KiloHertz,
Michael Ott's avatar
Michael Ott committed
59
  Unit_KiloWatt,
60
61
  Unit_KiloJoules,
  Unit_KiloWattHours,
Michael Ott's avatar
Michael Ott committed
62
63

  /* 1e6 */
64
  Unit_MegaHertz,
Michael Ott's avatar
Michael Ott committed
65
  Unit_MegaWatt,
66
67
  Unit_MegaJoules,
  Unit_MegaWattHours,
Michael Ott's avatar
Michael Ott committed
68
69

  /* 1e9 */
70
  Unit_GigaHertz,
Michael Ott's avatar
Michael Ott committed
71

Michael Ott's avatar
Michael Ott committed
72
73
74
  /* 1e-1 */
  Unit_DeciCelsius,

75
  /* 1e-2 */
76
77
  Unit_CentiMeter,
  Unit_CentiCelsius,
78

Axel Auweter's avatar
Axel Auweter committed
79
  /* 1e-3 */
80
81
82
83
84
85
86
  Unit_MilliMeter,
  Unit_MilliSecond,
  Unit_MilliAmpere,
  Unit_MilliKelvin,
  Unit_MilliWatt,
  Unit_MilliVolt,
  Unit_MilliCelsius,
Axel Auweter's avatar
Axel Auweter committed
87
88

  /* 1e-6 */
89
90
91
92
93
94
95
96
  Unit_MicroMeter,
  Unit_MicroSecond,
  Unit_MicroAmpere,
  Unit_MicroKelvin,
  Unit_MicroWatt,
  Unit_MicroVolt,
  Unit_MicroCelsius,
} Unit;
Axel Auweter's avatar
Axel Auweter committed
97

98
/**
Michael Ott's avatar
Michael Ott committed
99
 * This class provides an interface to the unit conversion support of libdcdb.
100
 */
Axel Auweter's avatar
Axel Auweter committed
101
102
103
class UnitConv
{
public:
104
105
106
107
  static Unit fromString(std::string unit);
  static std::string toString(Unit unit);
  static bool convert(int64_t& value, Unit from, Unit to);
  static bool convert(double& value, Unit from, Unit to);
Axel Auweter's avatar
Axel Auweter committed
108
109
};

110
111
112
} /* End of namespace DCDB */

#endif /* DCDB_UNITCONV_H */