LifeV
StringData.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6 Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8 This file is part of LifeV.
9 
10 LifeV is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 
15 LifeV is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 /*!
27  @file
28  @brief Small classes to manage list data strings
29 
30  @date 1-11-2002
31  @author J. F. Gerbeau
32 
33  @contributor
34  @maintainer Radu Popescu <radu.popescu@epfl.ch>
35 */
36 
37 #ifndef STRING_DATA_H
38 #define STRING_DATA_H
39 
40 #include <lifev/core/LifeV.hpp>
41 
42 namespace LifeV
43 {
44 
45 /*!
46  @class StringData
47 
48  A data string contains a string (the name used
49  in a data file), a integer value (the value used inside
50  the code), a small help text
51 */
53 {
54 public:
55  //! @name Constructor
56  //@{
58  StringData ( std::string str, Int val, std::string help );
59 
60  virtual ~StringData() {}
61  //@}
62 
63  //! @name Get methods
64  //@{
65  inline const std::string& help() const
66  {
67  return M_help;
68  }
69 
70  inline std::string& help()
71  {
72  return M_help;
73  }
74 
75  inline const std::string& string () const
76  {
77  return M_string;
78  }
79 
80  inline std::string& string ()
81  {
82  return M_string;
83  }
84 
85  inline const Int& value () const
86  {
87  return M_value;
88  }
89 
90  inline Int& value ()
91  {
92  return M_value;
93  }
94  //@}
95 
96 private:
97  //! @name Private members
98  //@{
99  std::string M_string;
101  std::string M_help;
102  //@}
103 };
104 
105 /*!
106  @class StringDataList
107 
108  To build a list of data string.
109 
110  Example:
111 
112  You want to propose to the user three solvers: cg, gmres, cgs
113  inside the code these solvers are identified by the values 1, 2, 3
114 
115  You first create the list:
116 
117  StringDataList solver_list("My solvers");
118  solver_list.add("cg",1,"preconditioned conjugate gradient method");
119  solver_list.add("gmres",2,"preconditioned gmres method");
120  solver_list.add("cgs",2,"preconditioned cg squared method");
121 
122  Next, you read (for example) a GetPot data file, where the user
123  gives you a string string_string. To get the value corresponding
124  the string provided by the user:
125 
126  solver = aztec_solver_list.value(user_string);
127 
128  if the "user_string" belongs to the list, then solver has the corresponding
129  value,
130  else, the list of possible choices (with help) is given and
131  the code stop with an error.
132 */
134 {
135 public:
136  //! @name Constructor
137  //@{
139  StringDataList ( std::string title );
140 
141  virtual ~StringDataList() {}
142  //@}
143 
144  //! @name Public methods
145  //@{
146  void add ( std::string str, Int val, std::string help );
147 
148  //! State printing function (val=true:the values are shown)
149  void showMe ( std::ostream& c = std::cout, bool val = false ) const;
150 
151  Int value ( const std::string& str ) const;
152  //@}
153 
154 private:
155  //! @name Private data members
156  //@{
157  std::string M_title;
159  //@}
160 };
161 }
162 #endif // STRING_DATA_H
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
void updateInverseJacobian(const UInt &iQuadPt)
const std::string & help() const
Definition: StringData.hpp:65
const Int & value() const
Definition: StringData.hpp:85
std::string M_string
Definition: StringData.hpp:99
std::string M_help
Definition: StringData.hpp:101
virtual ~StringData()
Definition: StringData.hpp:60
std::string & help()
Definition: StringData.hpp:70
void showMe(std::ostream &c=std::cout, bool val=false) const
State printing function (val=true:the values are shown)
Definition: StringData.cpp:67
std::vector< StringData > M_list
Definition: StringData.hpp:158