Unit
Biblioteca utilitária para facilitar o tratamento de unidades
unitConverter.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2012 K2FS Sistemas e Projetos Ltd.
4 ** All rights reserved.
5 **
6 ** This file is part of the "Pdm version 2" library and should not
7 ** be included in other softwares without written permission of K2
8 ** Sistemas. It is provided AS IS, with NO WARRANTY OF ANY KIND,
9 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
10 ** A PARTICULAR PURPOSE.
11 **
12 ** Contact information: www.k2sistemas.com.br
13 **
14 ************************************************************************/
15 
26 #ifndef _UNIT_CONVERTER_H_
27 #define _UNIT_CONVERTER_H_
28 
29 #include "unit.h"
30 
32 class UNIT_API_EXPORT UnitConverter
33 {
34 public:
37 
38  UnitConverter(const Unit& srcUnit, const Unit& destUnit);
39  ~UnitConverter();
40 
42  bool isValid() const { return !_converter.isNull() && _converter.data()->conv; }
43 
45  const Unit& srcUnit() const { return _srcUnit; }
46 
48  const Unit& destUnit() const { return _destUnit; }
49 
50  double convert(double value) const;
51 
52  double* convertArray(const double* srcValues, int size, double* dstValues) const;
53 
55  UnitConverter reverseConverter() const { return UnitConverter(_destUnit, _srcUnit); }
56 
57 private:
58  friend class UnitManager;
59 
67  {
69  UnitConverterWrapper(cv_converter* c) : conv(c) {}
71  ~UnitConverterWrapper() { cv_free(conv); }
72 
73  cv_converter* conv;
74  };
75 
78 
79  UnitConverter(SharedUnitConverterWrapper conv, const Unit& srcUnit,
80  const Unit& destUnit);
81 
84 
86 };
87 
88 #endif
bool isValid() const
Retorna true se a conversão entre fonte e destino é possível.
Definition: unitConverter.h:42
UnitConverter()
Construtor default.
Definition: unitConverter.h:36
Classe singleton responsável por gerenciar os tipos de unidades e categorias disponíveis.
Definition: unitManager.h:39
Unit _srcUnit
Unidade base em que os dados a serem convertidos estão expressos.
Definition: unitConverter.h:82
UnitConverter reverseConverter() const
Returns a new converter operating in the opposite direction.
Definition: unitConverter.h:55
~UnitConverterWrapper()
Destrutor.
Definition: unitConverter.h:71
Classe responsável por identificar e agrupar tipos de unidades.
Definition: unit.h:41
Unit _destUnit
Unidade para a qual os dados deverão ser convertidos.
Definition: unitConverter.h:83
QSharedPointer< UnitConverterWrapper > SharedUnitConverterWrapper
Tipo auxiliar para uso interno. SharedPointer para um UnitConverterWrapper.
Definition: unitConverter.h:77
cv_converter * conv
Representação do conversor pela biblioteca UDUNITS.
Definition: unitConverter.h:73
const Unit & srcUnit() const
Retorna referência para a unidade em que os dados estão expressos.
Definition: unitConverter.h:45
Definicao da classe Unit.
Classe responsável pela conversão de unidades entre valores numéricos.
Definition: unitConverter.h:32
const Unit & destUnit() const
Retorna referência para a unidade na qual os dados serão convertidos.
Definition: unitConverter.h:48
Estrutura auxiliar para uso interno por UnitConverter.
Definition: unitConverter.h:66
UnitConverterWrapper(cv_converter *c)
Construtor. Armazena a repreesntação interna de um conversor.
Definition: unitConverter.h:69
SharedUnitConverterWrapper _converter
Conversor de unidades.
Definition: unitConverter.h:85