LifeV
Switch.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 Switches class
29 
30  @date 13-12-2010
31  @author
32 
33  @maintainer Radu Popescu <radu.popescu@epfl.ch>
34 */
35 
36 #include <lifev/core/LifeV.hpp>
37 #include <lifev/core/util/Switch.hpp>
38 
39 namespace LifeV
40 {
41 
42 // =======================
43 // Public methods
44 // =======================
45 
46 bool Switch::set ( std::string const& a )
47 {
48  iterator_Type i = find ( a );
49  if ( i == end() )
50  {
51  return false;
52  }
53 
54  else
55  {
56  i->second = true;
57  return true;
58  }
59 }
60 
61 bool Switch::set ( const char* a )
62 {
63  std::string temp ( a );
64  return set
65  ( temp );
66 }
67 
68 bool Switch::unset ( std::string const& a )
69 {
70  iterator_Type i = find ( a );
71  if ( i == end() )
72  {
73  return false;
74  }
75 
76  else
77  {
78  i->second = false;
79  return true;
80  }
81 }
82 
83 bool Switch::unset ( const char* a )
84 {
85  std::string temp ( a );
86  return unset ( temp );
87 
88 }
89 
90 bool Switch::toggle ( std::string const& a )
91 {
92  iterator_Type i = find ( a );
93  if ( i == end() )
94  {
95  return false;
96  }
97 
98  else
99  {
100  i->second = ! ( i->second );
101  return true;
102  }
103 }
104 
105 bool Switch::toggle ( const char* a )
106 {
107  std::string temp ( a );
108  return toggle ( temp );
109 
110 }
111 
112 void Switch::create ( std::string const& a, bool status )
113 {
114  iterator_Type i = find ( a );
115  if ( i == end() )
116  {
117  insert ( std::make_pair ( a, status ) );
118  }
119 
120  else
121  {
122  i->second = status;
123  }
124 }
125 
126 void Switch::create ( const char* a, bool status )
127 {
128  std::string temp ( a );
129  create ( temp, status );
130 }
131 
132 
133 std::pair<bool, bool> Switch::status ( std::string const& a ) const
134 {
135  iteratorConst_Type i = find ( a );
136  if ( i == end() )
137  {
138  return std::make_pair ( false, false );
139  }
140 
141  else
142  {
143  return std::make_pair ( true, i->second );
144  }
145 }
146 
147 std::pair<bool, bool> Switch::status ( const char* a ) const
148 {
149  std::string temp ( a );
150  return status ( temp );
151 }
152 
153 
154 bool
155 Switch::test ( std::string const& a ) const
156 {
157  iteratorConst_Type i = find ( a );
158  if ( i == end() )
159  {
160  return false;
161  }
162  else
163  {
164  return i->second;
165  }
166 }
167 
168 bool Switch::test ( const char* a ) const
169 {
170  std::string temp ( a );
171  return test ( temp );
172 }
173 
174 std::ostream& Switch::showMe ( bool verbose, std::ostream& out ) const
175 {
176  if ( verbose )
177  {
178  out << std::endl << " Status of switches" << std::endl;
179  for ( iteratorConst_Type i = begin(); i != end(); ++i )
180  {
181  out << "Switch named: " << i->first << " Value= " << i->second << std::endl;
182  }
183  }
184 
185  return out;
186 }
187 
188 }
I use standard constructor/destructors.
Definition: Switch.hpp:50
bool toggle(std::string const &a)
It toggles the switch Returns true if the switch s existed.
Definition: Switch.cpp:90
std::ostream & showMe(bool verbose=false, std::ostream &out=std::cout) const
Definition: Switch.cpp:174
std::pair< bool, bool > status(std::string const &a) const
Definition: Switch.cpp:133
bool set(const char *a)
Definition: Switch.cpp:61
void updateInverseJacobian(const UInt &iQuadPt)
void create(const char *a, bool status=false)
Definition: Switch.cpp:126
void create(std::string const &a, bool status=false)
Creates a switch (default is OFF) It sets the switch if it is there.
Definition: Switch.cpp:112
bool unset(std::string const &a)
It unsets the switch.
Definition: Switch.cpp:68
std::pair< bool, bool > status(const char *a) const
Definition: Switch.cpp:147
bool set(std::string const &a)
It sets the switch It does NOT create a new switch (use create); Returns true if the switch s existed...
Definition: Switch.cpp:46
bool test(std::string const &a) const
Definition: Switch.cpp:155
bool unset(const char *a)
Definition: Switch.cpp:83
std::map< std::string, bool >::const_iterator iteratorConst_Type
Definition: Switch.hpp:57
bool toggle(const char *a)
Definition: Switch.cpp:105
std::map< std::string, bool >::iterator iterator_Type
Definition: Switch.hpp:56
bool test(const char *a) const
Definition: Switch.cpp:168