LifeV
Switch.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 Switches class
29 
30  @date 13-12-2010
31  @author
32 
33  @maintainer Radu Popescu <radu.popescu@epfl.ch>
34 */
35 
36 #ifndef SWITCH_H
37 #define SWITCH_H
38 
39 #include<iostream>
40 #include<map>
41 #include<string>
42 
43 #include <lifev/core/util/StringUtility.hpp>
44 
45 namespace LifeV
46 {
47 
48 /*! A better Switches class */
49 //! I use standard constructor/destructors
50 class Switch: public std::map<std::string, bool>
51 {
52 
53 public:
54  //! @name Public typedefs
55  //@{
56  typedef std::map<std::string, bool>::iterator iterator_Type;
58  //@}
59 
60  //! @name Public methods
61  //@{
62  //! It sets the switch It does NOT create a new switch (use create);
63  //! Returns true if the switch s existed
64  bool set ( std::string const& a );
65 
66  bool set ( const char* a );
67 
68  //! It unsets the switch. It does NOT create a new switch (use create)
69  //! Returns true if the switch s existed
70  bool unset ( std::string const& a );
71 
72  bool unset ( const char* a );
73 
74  //! It toggles the switch
75  //! Returns true if the switch s existed
76  bool toggle ( std::string const& a );
77 
78  bool toggle ( const char* a );
79 
80  //! Creates a switch (default is OFF)
81  //! It sets the switch if it is there
82  void create ( std::string const& a, bool status = false );
83  void create ( const char* a, bool status = false );
84 
85  std::ostream& showMe ( bool verbose = false, std::ostream& out = std::cout ) const;
86 
87  /*! Returns the status of the switch:
88  true-> set false-> unset or non existent.
89  It does not distinguish between not existent and unset switches: use status if you want
90  the full information */
91  bool test ( std::string const& a ) const;
92 
93  bool test ( const char* a ) const;
94 
95  /*! Returns a std::pair of bools : the first refers to the
96  existence in the list of switches, the second on the status (true or false)
97  If the first bool is false also the second is false */
98  std::pair<bool, bool> status ( std::string const& a ) const;
99 
100  std::pair<bool, bool> status ( const char* a ) const;
101  //@}
102 };
103 
104 } // Namespace LifeV
105 
106 #endif // SWITCH_H
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