Documentation for OpenFLUID 2.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VarHelpers.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file VarHelpers.hpp
34 
35  @author Armel THÖNI <armel.thoni@inrae.fr>
36 */
37 
38 
39 #ifndef __OPENFLUID_TOOLS_VARHELPERS_HPP__
40 #define __OPENFLUID_TOOLS_VARHELPERS_HPP__
41 
42 
43 #include <algorithm>
44 #include <map>
45 #include <vector>
46 
47 #include <openfluid/config.hpp>
48 #include <openfluid/dllexport.hpp>
49 #include <openfluid/core/TypeDefs.hpp>
50 
51 
52 namespace openfluid { namespace tools {
53 
54 
56 {
57  // simple structure to describe a Variable associated with a Unit class
59 
61 
62  UnitVarPair(): UnitsClass(""), VariableName("")
63  {
64  }
65 
67  UnitsClass(Classes), VariableName(Vars)
68  {
69  }
70 
71  UnitVarPair(std::initializer_list<std::string> Data)
72  {
73  std::vector<std::string> TmpV(Data);
74  if (TmpV.size() == 2)
75  {
76  UnitsClass = TmpV[0];
77  VariableName = TmpV[1];
78  }
79  else
80  {
81  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
82  "Bad unit class/variable pair format");
83  }
84  }
85 
86  bool operator==(const UnitVarPair& P)
87  {
88  return (P.UnitsClass == UnitsClass && P.VariableName == VariableName);
89  }
90 };
91 
92 
93 // =====================================================================
94 // =====================================================================
95 
96 
98 {
99 
100  std::string UnitsIDsStr;
101 
102  ClassIDVar(): UnitVarPair(), UnitsIDsStr("")
103  {
104  }
105 
107  UnitVarPair(Classes, Vars), UnitsIDsStr(IDs)
108  {
109  }
110 
111  ClassIDVar(std::initializer_list<std::string> Data)
112  {
113  std::vector<std::string> TmpV(Data);
114  if (TmpV.size() == 2)
115  {
116  UnitsClass = TmpV[0];
117  UnitsIDsStr = openfluid::config::CHAR_JOKER;
118  VariableName = TmpV[1];
119  }
120  else if (Data.size() == 3)
121  {
122  UnitsClass = TmpV[0];
123  UnitsIDsStr = TmpV[1];
124  VariableName = TmpV[2];
125  }
126  else
127  {
128  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
129  "Bad unit class/variable pair format");
130  }
131  }
132 
133  std::string getClassIDVarString() const;
134 
135  bool operator==(const ClassIDVar& P)
136  {
137  return (UnitVarPair::operator==(P) && UnitsIDsStr==P.UnitsIDsStr);
138  }
139 };
140 
141 
142 // =====================================================================
143 // =====================================================================
144 
145 
147 {
148 
149  bool HasPrecision = false;
150  unsigned int Precision;
151 
152  std::string FloatFormat;
153 
155  {
156  }
157 
159  unsigned int P, std::string FFormat) :
160  ClassIDVar(Classes, IDs, Vars), Precision(P), FloatFormat(FFormat)
161  {
162  }
163 
164  std::string getClassIDVarString(bool WithPrecision) const;
165 };
166 
167 
168 typedef std::vector<UnitVarPair> UnitVarPairs_t;
169 typedef std::vector<ClassIDVar> UnitVarTriplets_t;
170 
172 
174 
176 
177 } }
178 
179 
180 #endif /* __OPENFLUID_TOOLS_VARHELPERS_HPP__ */
Definition: FrameworkException.hpp:51
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::string VariableName_t
Definition: TypeDefs.hpp:131
std::string UnitsClass_t
Definition: TypeDefs.hpp:98
std::vector< ClassIDVar > UnitVarTriplets_t
Definition: VarHelpers.hpp:169
UnitVarTriplets_t OPENFLUID_API deserializeVarTriplets(const std::string &Selection)
std::vector< UnitVarPair > UnitVarPairs_t
Definition: VarHelpers.hpp:168
UnitVarPairs_t OPENFLUID_API deduceVarPairs(const UnitVarTriplets_t &Triplets)
std::string OPENFLUID_API serializeVarTriplets(const UnitVarTriplets_t &Triplets)
Definition: ApplicationException.hpp:47
Definition: VarHelpers.hpp:147
std::string getClassIDVarString(bool WithPrecision) const
ClassIDVarPrecision()
Definition: VarHelpers.hpp:154
std::string FloatFormat
Definition: VarHelpers.hpp:152
unsigned int Precision
Definition: VarHelpers.hpp:150
ClassIDVarPrecision(openfluid::core::UnitsClass_t Classes, std::string IDs, openfluid::core::VariableName_t Vars, unsigned int P, std::string FFormat)
Definition: VarHelpers.hpp:158
Definition: VarHelpers.hpp:98
ClassIDVar()
Definition: VarHelpers.hpp:102
std::string getClassIDVarString() const
ClassIDVar(openfluid::core::UnitsClass_t Classes, std::string IDs, openfluid::core::VariableName_t Vars)
Definition: VarHelpers.hpp:106
bool operator==(const ClassIDVar &P)
Definition: VarHelpers.hpp:135
ClassIDVar(std::initializer_list< std::string > Data)
Definition: VarHelpers.hpp:111
std::string UnitsIDsStr
Definition: VarHelpers.hpp:100
Definition: VarHelpers.hpp:56
UnitVarPair()
Definition: VarHelpers.hpp:62
bool operator==(const UnitVarPair &P)
Definition: VarHelpers.hpp:86
openfluid::core::VariableName_t VariableName
Definition: VarHelpers.hpp:60
UnitVarPair(openfluid::core::UnitsClass_t Classes, openfluid::core::VariableName_t Vars)
Definition: VarHelpers.hpp:66
openfluid::core::UnitsClass_t UnitsClass
Definition: VarHelpers.hpp:58
UnitVarPair(std::initializer_list< std::string > Data)
Definition: VarHelpers.hpp:71