2019-05-04 08:52:18 +00:00
|
|
|
/*
|
2020-01-28 18:09:39 +00:00
|
|
|
Copyright (C) 2019-2020 Fredrik Öhrström
|
2019-05-04 08:52:18 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UNITS_H
|
|
|
|
#define UNITS_H
|
|
|
|
|
|
|
|
#include<string>
|
|
|
|
#include<vector>
|
|
|
|
|
2020-09-24 17:49:45 +00:00
|
|
|
#define LIST_OF_QUANTITIES \
|
|
|
|
X(Energy,KWH) \
|
|
|
|
X(Reactive_Energy,KVARH) \
|
2020-09-24 19:23:06 +00:00
|
|
|
X(Apparent_Energy,KVAH) \
|
2020-09-24 17:49:45 +00:00
|
|
|
X(Power,KW) \
|
|
|
|
X(Volume,M3) \
|
|
|
|
X(Flow,M3H) \
|
|
|
|
X(Temperature,C) \
|
|
|
|
X(RelativeHumidity,RH) \
|
|
|
|
X(HCA,HCA) \
|
|
|
|
X(Text,TXT) \
|
|
|
|
X(Counter,INT) \
|
|
|
|
X(Time,Hour) \
|
2021-01-29 16:20:54 +00:00
|
|
|
X(Voltage,Volt) \
|
|
|
|
X(Current,Ampere) \
|
|
|
|
X(Frequency,Hz)
|
2021-01-30 08:07:14 +00:00
|
|
|
|
2019-05-04 11:07:37 +00:00
|
|
|
#define LIST_OF_UNITS \
|
Fix compilation error on gcc 10.x
Fixes the following compilation error:
In file included from src/config.h:21,
from src/cmdline.h:21,
from src/cmdline.cc:18:
src/units.h:42:11: error: extended character ° is not valid in an identifier
42 | X(C,c,°C,Temperature,"celsius") \
| ^
src/units.h:43:11: error: extended character ° is not valid in an identifier
43 | X(F,f,°F,Temperature,"fahrenheit") \
| ^
make: *** [Makefile:93: build/cmdline.o] Error 1
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
2020-02-28 17:20:22 +00:00
|
|
|
X(KWH,kwh,"kWh",Energy,"kilo Watt hour") \
|
2020-08-18 16:20:30 +00:00
|
|
|
X(MJ,mj,"MJ",Energy,"Mega Joule") \
|
Fix compilation error on gcc 10.x
Fixes the following compilation error:
In file included from src/config.h:21,
from src/cmdline.h:21,
from src/cmdline.cc:18:
src/units.h:42:11: error: extended character ° is not valid in an identifier
42 | X(C,c,°C,Temperature,"celsius") \
| ^
src/units.h:43:11: error: extended character ° is not valid in an identifier
43 | X(F,f,°F,Temperature,"fahrenheit") \
| ^
make: *** [Makefile:93: build/cmdline.o] Error 1
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
2020-02-28 17:20:22 +00:00
|
|
|
X(GJ,gj,"GJ",Energy,"Giga Joule") \
|
2020-09-24 17:49:45 +00:00
|
|
|
X(KVARH,kvarh,"kVARh",Reactive_Energy,"kilo volt amperes reactive hour") \
|
2020-09-24 19:23:06 +00:00
|
|
|
X(KVAH,kvah,"kVAh",Apparent_Energy,"kilo volt amperes hour") \
|
Fix compilation error on gcc 10.x
Fixes the following compilation error:
In file included from src/config.h:21,
from src/cmdline.h:21,
from src/cmdline.cc:18:
src/units.h:42:11: error: extended character ° is not valid in an identifier
42 | X(C,c,°C,Temperature,"celsius") \
| ^
src/units.h:43:11: error: extended character ° is not valid in an identifier
43 | X(F,f,°F,Temperature,"fahrenheit") \
| ^
make: *** [Makefile:93: build/cmdline.o] Error 1
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
2020-02-28 17:20:22 +00:00
|
|
|
X(M3,m3,"m3",Volume,"cubic meter") \
|
|
|
|
X(L,l,"l",Volume,"litre") \
|
|
|
|
X(KW,kw,"kW",Power,"kilo Watt") \
|
|
|
|
X(M3H,m3h,"m3/h",Flow,"cubic meters per hour") \
|
2020-12-17 22:10:14 +00:00
|
|
|
X(LH,lh,"l/h",Flow,"liters per hour") \
|
Fix compilation error on gcc 10.x
Fixes the following compilation error:
In file included from src/config.h:21,
from src/cmdline.h:21,
from src/cmdline.cc:18:
src/units.h:42:11: error: extended character ° is not valid in an identifier
42 | X(C,c,°C,Temperature,"celsius") \
| ^
src/units.h:43:11: error: extended character ° is not valid in an identifier
43 | X(F,f,°F,Temperature,"fahrenheit") \
| ^
make: *** [Makefile:93: build/cmdline.o] Error 1
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
2020-02-28 17:20:22 +00:00
|
|
|
X(C,c,"°C",Temperature,"celsius") \
|
|
|
|
X(F,f,"°F",Temperature,"fahrenheit") \
|
|
|
|
X(RH,rh,"RH",RelativeHumidity,"relative humidity") \
|
|
|
|
X(HCA,hca,"hca",HCA,"heat cost allocation") \
|
|
|
|
X(TXT,txt,"txt",Text,"text") \
|
2020-06-30 14:02:38 +00:00
|
|
|
X(INT,int,"int",Counter,"int") \
|
Fix compilation error on gcc 10.x
Fixes the following compilation error:
In file included from src/config.h:21,
from src/cmdline.h:21,
from src/cmdline.cc:18:
src/units.h:42:11: error: extended character ° is not valid in an identifier
42 | X(C,c,°C,Temperature,"celsius") \
| ^
src/units.h:43:11: error: extended character ° is not valid in an identifier
43 | X(F,f,°F,Temperature,"fahrenheit") \
| ^
make: *** [Makefile:93: build/cmdline.o] Error 1
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
2020-02-28 17:20:22 +00:00
|
|
|
X(Second,s,"s",Time,"second") \
|
2021-02-13 15:43:51 +00:00
|
|
|
X(Minute,m,"m",Time,"minute") \
|
2020-04-22 20:38:40 +00:00
|
|
|
X(Hour,h,"h",Time,"hour") \
|
2021-02-14 21:55:25 +00:00
|
|
|
X(Day,d,"d",Time,"day") \
|
2021-01-29 16:20:54 +00:00
|
|
|
X(Year,y,"y",Time,"year") \
|
2021-01-30 08:07:14 +00:00
|
|
|
X(Volt,v,"V",Voltage,"volt") \
|
|
|
|
X(Ampere,a,"A",Current,"ampere") \
|
2021-01-29 16:20:54 +00:00
|
|
|
X(Hz,hz,"Hz",Frequency,"hz")
|
2019-05-04 11:07:37 +00:00
|
|
|
|
2019-05-04 08:52:18 +00:00
|
|
|
enum class Unit
|
|
|
|
{
|
2019-05-04 11:07:37 +00:00
|
|
|
#define X(cname,lcname,hrname,quantity,explanation) cname,
|
|
|
|
LIST_OF_UNITS
|
|
|
|
#undef X
|
|
|
|
Unknown
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Quantity
|
|
|
|
{
|
2019-05-04 11:55:52 +00:00
|
|
|
#define X(quantity,default_unit) quantity,
|
2019-05-04 11:07:37 +00:00
|
|
|
LIST_OF_QUANTITIES
|
|
|
|
#undef X
|
|
|
|
Unknown
|
2019-05-04 08:52:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool canConvert(Unit from, Unit to);
|
|
|
|
double convert(double v, Unit from, Unit to);
|
2019-05-04 11:07:37 +00:00
|
|
|
Unit toUnit(std::string s);
|
|
|
|
bool isQuantity(Unit u, Quantity q);
|
|
|
|
void assertQuantity(Unit u, Quantity q);
|
2019-05-04 11:55:52 +00:00
|
|
|
Unit defaultUnitForQuantity(Quantity q);
|
|
|
|
std::string unitToStringHR(Unit u);
|
|
|
|
std::string unitToStringLowerCase(Unit u);
|
|
|
|
std::string unitToStringUpperCase(Unit u);
|
2019-05-04 17:56:17 +00:00
|
|
|
std::string valueToString(double v, Unit u);
|
2019-05-04 08:52:18 +00:00
|
|
|
|
2019-05-04 11:55:52 +00:00
|
|
|
Unit replaceWithConversionUnit(Unit u, std::vector<Unit> cs);
|
2019-05-04 08:52:18 +00:00
|
|
|
|
|
|
|
#endif
|