libyui  3.4.2
YEnvVar.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YEnvVar.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YEnvVar_h
26 #define YEnvVar_h
27 
28 #include <string>
29 #include <iosfwd>
30 
31 
32 
33 /**
34  * Helper class to represent an environment variable and its value.
35  **/
36 class YEnvVar
37 {
38 public:
39  /**
40  * Constructor:
41  * Retrieve the environment variable 'name' and store the value
42  * (unless 'name' is empty).
43  **/
44  YEnvVar( const std::string & name = std::string() );
45 
46  /**
47  * Return the name of the environment variable.
48  **/
49  std::string name() const { return _name; }
50 
51  /**
52  * Return 'true' if the environment variable is set.
53  **/
54  bool isSet() const { return _isSet; }
55 
56  /**
57  * Return the value of the environment variable.
58  **/
59  std::string value() const { return _value; }
60 
61  /**
62  * Return 'true' if the environment variable is set and the value is
63  * 'str'.
64  **/
65  bool isEqual( const std::string & str, bool caseSensitive = false ) const;
66 
67  /**
68  * Case-insensitive comparison (shortcut for isEqual() ):
69  * Return 'true' if the environment variable is set and the value is
70  * 'str'.
71  **/
72  bool operator==( const std::string & str ) const
73  { return isEqual( str ); }
74 
75  /**
76  * Return 'true' if the environment variable is set and the value contains
77  * 'str'.
78  **/
79  bool contains( const std::string & str, bool caseSensitive = false ) const;
80 
81 
82 private:
83 
84  std::string _name;
85  std::string _value;
86  bool _isSet;
87 };
88 
89 
90 /**
91  * Stream output for YEnvVar
92  **/
93 std::ostream & operator<<( std::ostream & stream, const YEnvVar env );
94 
95 
96 /**
97  * Return 'str' converted to lower case.
98  **/
99 std::string tolower( const std::string & str );
100 
101 
102 #endif // YEnvVar_h
bool isEqual(const std::string &str, bool caseSensitive=false) const
Return &#39;true&#39; if the environment variable is set and the value is &#39;str&#39;.
Definition: YEnvVar.cc:54
bool isSet() const
Return &#39;true&#39; if the environment variable is set.
Definition: YEnvVar.h:54
std::string value() const
Return the value of the environment variable.
Definition: YEnvVar.h:59
bool operator==(const std::string &str) const
Case-insensitive comparison (shortcut for isEqual() ): Return &#39;true&#39; if the environment variable is s...
Definition: YEnvVar.h:72
YEnvVar(const std::string &name=std::string())
Constructor: Retrieve the environment variable &#39;name&#39; and store the value (unless &#39;name&#39; is empty)...
Definition: YEnvVar.cc:36
Helper class to represent an environment variable and its value.
Definition: YEnvVar.h:36
bool contains(const std::string &str, bool caseSensitive=false) const
Return &#39;true&#39; if the environment variable is set and the value contains &#39;str&#39;.
Definition: YEnvVar.cc:66
std::string name() const
Return the name of the environment variable.
Definition: YEnvVar.h:49