~raghavendra-prabhu/percona-xtradb-cluster/galera-bug1153727

« back to all changes in this revision

Viewing changes to galerautils/src/gu_config.hpp

  • Committer: Raghavendra D Prabhu
  • Date: 2013-04-12 15:26:34 UTC
  • mfrom: (95.2.24 2.x)
  • Revision ID: raghavendra.prabhu@percona.com-20130412152634-2y2u0swshf5fie2x
Merge lp:galera-2.x upto revision 150.

Following bugs are fixed:

lp:1166065
lp:1164992

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * @file
5
5
 * Configuration management class
6
6
 *
7
 
 * $Id: gu_config.hpp 2875 2012-10-10 16:59:04Z alex $
 
7
 * $Id: gu_config.hpp 3034 2013-04-07 17:12:58Z alex $
8
8
 */
9
9
 
10
10
#ifndef _gu_config_hpp_
36
36
    typedef std::map <std::string, std::string> param_map_t;
37
37
 
38
38
    static void
39
 
    parse (param_map_t& list, const std::string& params) throw (Exception);
 
39
    parse (param_map_t& list, const std::string& params);
40
40
 
41
41
    /*! Convert string configuration values to other types.
42
42
     *  General template for integers, specialized templates follow below. */
43
43
    template <typename T> static inline T
44
 
    from_config (const std::string& value) throw (Exception)
 
44
    from_config (const std::string& value)
45
45
    {
46
46
        const char* str    = value.c_str();
47
47
        long long   ret;
59
59
        return ret;
60
60
    }
61
61
 
62
 
    Config () throw();
63
 
    Config (const std::string& params) throw (Exception);
 
62
    Config ();
 
63
    Config (const std::string& params);
64
64
 
65
65
    bool
66
 
    has (const std::string& key) const throw ()
 
66
    has (const std::string& key) const
67
67
    {
68
68
        return (params_.find(key) != params_.end());
69
69
    }
70
70
 
71
71
    void
72
 
    set (const std::string& key, const std::string& value) throw ()
 
72
    set (const std::string& key, const std::string& value)
73
73
    {
74
74
        params_[key] = value;
75
75
    }
76
76
 
77
77
    void
78
 
    set (const std::string& key, const char* value) throw ()
 
78
    set (const std::string& key, const char* value)
79
79
    {
80
80
        params_[key] = value;
81
81
    }
82
82
 
83
83
    /* General template for integer types */
84
84
    template <typename T> void
85
 
    set (const std::string& key, T val) throw ()
 
85
    set (const std::string& key, T val)
86
86
    {
87
87
        set_longlong (key, val);
88
88
    }
89
89
 
 
90
    /*! @throws NotFound */
90
91
    const std::string&
91
 
    get (const std::string& key) const throw (NotFound)
 
92
    get (const std::string& key) const
92
93
    {
93
94
        param_map_t::const_iterator i = params_.find(key);
94
95
        if (i == params_.end()) throw NotFound();
96
97
    }
97
98
 
98
99
    const std::string&
99
 
    get (const std::string& key, const std::string& def) const throw (Exception)
 
100
    get (const std::string& key, const std::string& def) const
100
101
    {
101
102
        try               { return get(key); }
102
103
        catch (NotFound&) { return def     ; }
103
104
    }
104
105
 
 
106
    /*! @throws NotFound */
105
107
    template <typename T> inline T
106
 
    get (const std::string& key) const throw (NotFound, Exception)
 
108
    get (const std::string& key) const
107
109
    {
108
110
        return from_config <T> (get(key));
109
111
    }
110
112
 
111
113
    template <typename T> inline T
112
 
    get(const std::string& key, const T& def) const throw (Exception)
 
114
    get(const std::string& key, const T& def) const
113
115
    {
114
116
        try { return get<T>(key); }
115
117
        catch (NotFound&) { return def; }
116
118
    }
117
119
 
118
 
    const param_map_t& params () const throw() { return params_; }
 
120
    const param_map_t& params () const { return params_; }
119
121
 
120
122
private:
121
123
 
122
124
    static void
123
 
    check_conversion (const char* ptr, const char* endptr, const char* type)
124
 
        throw (Exception);
 
125
    check_conversion (const char* ptr, const char* endptr, const char* type);
125
126
 
126
127
    static char
127
 
    overflow_char(long long ret) throw (Exception);
 
128
    overflow_char(long long ret);
128
129
 
129
130
    static short
130
 
    overflow_short(long long ret) throw (Exception);
 
131
    overflow_short(long long ret);
131
132
 
132
133
    static int
133
 
    overflow_int(long long ret) throw (Exception);
 
134
    overflow_int(long long ret);
134
135
 
135
136
    void set_longlong (const std::string& key, long long value);
136
137
 
148
149
    /*! Specialized templates for "funny" types */
149
150
 
150
151
    template <> inline double
151
 
    Config::from_config (const std::string& value) throw (Exception)
 
152
    Config::from_config (const std::string& value)
152
153
    {
153
154
        const char* str    = value.c_str();
154
155
        double      ret;
160
161
    }
161
162
 
162
163
    template <> inline bool
163
 
    Config::from_config (const std::string& value) throw (Exception)
 
164
    Config::from_config (const std::string& value)
164
165
    {
165
166
        const char* str    = value.c_str();
166
167
        bool        ret;
172
173
    }
173
174
 
174
175
    template <> inline void*
175
 
    Config::from_config (const std::string& value) throw (Exception)
 
176
    Config::from_config (const std::string& value)
176
177
    {
177
178
        const char* str    = value.c_str();
178
179
        void*       ret;
184
185
    }
185
186
 
186
187
    template <> inline void
187
 
    Config::set (const std::string& key, const void* value) throw ()
 
188
    Config::set (const std::string& key, const void* value)
188
189
    {
189
190
        set (key, to_string<const void*>(value));
190
191
    }
191
192
 
192
193
    template <> inline void
193
 
    Config::set (const std::string& key, double val) throw ()
 
194
    Config::set (const std::string& key, double val)
194
195
    {
195
196
        set (key, to_string<double>(val));
196
197
    }
197
198
 
198
199
    template <> inline void
199
 
    Config::set (const std::string& key, bool val) throw ()
 
200
    Config::set (const std::string& key, bool val)
200
201
    {
201
202
        const char* val_str(val ? "YES" : "NO"); // YES/NO is most generic
202
203
        set (key, val_str);