LifeV
StringData.cpp
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 #include <stdexcept>
38 #include <sstream>
39 
40 #include <lifev/core/util/StringData.hpp>
41 #include <lifev/core/util/LifeDebug.hpp>
42 
43 namespace LifeV
44 {
45 
46 // ===============
47 // Constructors
48 // ===============
49 
50 StringData::StringData ( std::string str, Int val, std::string help ) :
51  M_string ( str ), M_value ( val ), M_help ( help )
52 {}
53 
54 StringDataList::StringDataList ( std::string title ) :
55  M_title ( title )
56 {}
57 
58 // ===============
59 // Public methods
60 // ===============
61 
62 void StringDataList::add ( std::string str, Int val, std::string help )
63 {
64  M_list.push_back ( StringData ( str, val, help ) );
65 }
66 
67 void StringDataList::showMe ( std::ostream& c, bool val ) const
68 {
69  c << M_title << " : " << std::endl;
70  for ( std::vector<StringData>::const_iterator ds = M_list.begin();
71  ds != M_list.end(); ++ds )
72  {
73  c << " " << ds->string() << " : " << ds->help();
74  if ( val )
75  {
76  c << " (" << ds->value() << ")";
77  }
78  c << std::endl;
79  }
80 }
81 
82 Int StringDataList::value ( const std::string& str ) const
83 {
84  std::vector<StringData>::const_iterator ds = M_list.begin();
85  while ( ds != M_list.end() )
86  {
87  if ( ds->string() == str )
88  {
89  return ds->value();
90  }
91  ++ds;
92  };
93  std::ostringstream exception;
94  exception << "Error in " << LIFEV_FUNCINFO << ": "
95  << str << " is not in the list of possible choices for '"
96  << M_title;
97  throw std::invalid_argument ( exception.str() );
98 }
99 
100 }
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
void updateInverseJacobian(const UInt &iQuadPt)
#define LIFEV_FUNCINFO
Definition: LifeDebug.hpp:58
StringData(std::string str, Int val, std::string help)
Definition: StringData.cpp:50
void add(std::string str, Int val, std::string help)
Definition: StringData.cpp:62
void showMe(std::ostream &c=std::cout, bool val=false) const
State printing function (val=true:the values are shown)
Definition: StringData.cpp:67
StringDataList(std::string title)
Definition: StringData.cpp:54
Int value(const std::string &str) const
Definition: StringData.cpp:82