Switch to unified view

a/sc2src/conftree.h b/sc2src/conftree.h
...
...
47
 * The ConfStack class stacks several Con(Simple/Tree) objects so that
47
 * The ConfStack class stacks several Con(Simple/Tree) objects so that
48
 * parameters from the top of the stack override the values from lower
48
 * parameters from the top of the stack override the values from lower
49
 * (useful to have central/personal config files)
49
 * (useful to have central/personal config files)
50
 */
50
 */
51
51
52
#include <time.h>                       // for time_t
52
#include <time.h>
53
#include <algorithm>                    // for sort, unique
53
#include <algorithm>
54
#include <map>                          // for map, etc
54
#include <map>
55
#include <string>                       // for string, operator==, etc
55
#include <string>
56
#include <vector>                       // for vector, etc
56
#include <vector>
57
57
58
// rh7.3 likes iostream better...
58
// rh7.3 likes iostream better...
59
#if defined(__GNUC__) && __GNUC__ < 3
59
#if defined(__GNUC__) && __GNUC__ < 3
60
#include <iostream>
60
#include <iostream>
61
#else
61
#else
62
#include <istream>                      // for istream, ostream
62
#include <istream>
63
#include <ostream>
63
#endif
64
#endif
65
66
#include "pathut.h"
64
67
65
using std::string;
68
using std::string;
66
using std::vector;
69
using std::vector;
67
using std::map;
70
using std::map;
68
using std::istream;
71
using std::istream;
...
...
81
        return o.m_kind == m_kind && o.m_data == m_data;
84
        return o.m_kind == m_kind && o.m_data == m_data;
82
    }
85
    }
83
};
86
};
84
87
85
/**
88
/**
86
 * Virtual base class used to define an interface mostly useful for testing, + some utility functions
89
 * Virtual base class used to define an interface mostly useful for testing
87
 */
90
 */
88
class ConfNull {
91
class ConfNull {
89
public:
92
public:
90
    enum StatusCode {STATUS_ERROR = 0, STATUS_RO = 1, STATUS_RW = 2};
93
    enum StatusCode {STATUS_ERROR = 0, STATUS_RO = 1, STATUS_RW = 2};
91
    virtual ~ConfNull() {};
94
    virtual ~ConfNull() {};
...
...
101
    virtual void showall() const {};
104
    virtual void showall() const {};
102
    virtual vector<string> getSubKeys() const = 0;
105
    virtual vector<string> getSubKeys() const = 0;
103
    virtual vector<string> getSubKeys(bool) const = 0;
106
    virtual vector<string> getSubKeys(bool) const = 0;
104
    virtual bool holdWrites(bool) = 0;
107
    virtual bool holdWrites(bool) = 0;
105
    virtual bool sourceChanged() const = 0;
108
    virtual bool sourceChanged() const = 0;
106
    static void path_catslash(string& s);
107
    static string path_cat(const string& s1, const string& s2);
108
    static string path_home();
109
    static void trimstring(string& s, const char *ws = " \t");
110
    static string path_tildexpand(const string& s);
111
};
109
};
112
110
113
/**
111
/**
114
 * Manages a simple configuration file with subsections.
112
 * Manages a simple configuration file with subsections.
115
 */
113
 */
...
...
224
     * Return all subkeys
222
     * Return all subkeys
225
     */
223
     */
226
    virtual vector<string> getSubKeys(bool) const {
224
    virtual vector<string> getSubKeys(bool) const {
227
        return getSubKeys();
225
        return getSubKeys();
228
    }
226
    }
227
    virtual vector<string> getSubKeys_unsorted(bool = false) const {
228
        return m_subkeys_unsorted;
229
    }
229
    virtual vector<string> getSubKeys() const;
230
    virtual vector<string> getSubKeys() const;
230
    /** Test for subkey existence */
231
    /** Test for subkey existence */
231
    virtual bool hasSubKey(const string& sk) const {
232
    virtual bool hasSubKey(const string& sk) const {
232
        return m_submaps.find(sk) != m_submaps.end();
233
        return m_submaps.find(sk) != m_submaps.end();
233
    }
234
    }
...
...
262
    /**
263
    /**
263
     * Write in file format to out
264
     * Write in file format to out
264
     */
265
     */
265
    bool write(ostream& out) const;
266
    bool write(ostream& out) const;
266
267
268
    /** Give access to semi-parsed file contents */
269
    const vector<ConfLine>& getlines() const {
270
        return m_order;
271
    }
272
    
267
protected:
273
protected:
268
    bool dotildexpand;
274
    bool dotildexpand;
269
    StatusCode status;
275
    StatusCode status;
270
private:
276
private:
271
    // Set if we're working with a file
277
    // Set if we're working with a file
272
    string                            m_filename;
278
    string                            m_filename;
273
    time_t                            m_fmtime;
279
    time_t                            m_fmtime;
274
    // Configuration data submaps (one per subkey, the main data has a
280
    // Configuration data submaps (one per subkey, the main data has a
275
    // null subkey)
281
    // null subkey)
276
    map<string, map<string, string> > m_submaps;
282
    map<string, map<string, string> > m_submaps;
283
    vector<string> m_subkeys_unsorted;
277
    // Presentation data. We keep the comments, empty lines and
284
    // Presentation data. We keep the comments, empty lines and
278
    // variable and subkey ordering information in there (for
285
    // variable and subkey ordering information in there (for
279
    // rewriting the file while keeping hand-edited information)
286
    // rewriting the file while keeping hand-edited information)
280
    vector<ConfLine>                    m_order;
287
    vector<ConfLine>                    m_order;
281
    // Control if we're writing to the backing store
288
    // Control if we're writing to the backing store
...
...
390
            }
397
            }
391
        }
398
        }
392
        return false;
399
        return false;
393
    }
400
    }
394
401
395
    virtual int get(const string& name, string& value, const string& sk) const {
402
    virtual int get(const string& name, string& value, const string& sk,
403
                    bool shallow) const {
396
        typename vector<T*>::const_iterator it;
404
        typename vector<T*>::const_iterator it;
397
        for (it = m_confs.begin(); it != m_confs.end(); it++) {
405
        for (it = m_confs.begin(); it != m_confs.end(); it++) {
398
            if ((*it)->get(name, value, sk)) {
406
            if ((*it)->get(name, value, sk)) {
399
                return true;
407
                return true;
400
            }
408
            }
409
            if (shallow) {
410
                break;
411
            }
401
        }
412
        }
402
        return false;
413
        return false;
414
    }
415
    virtual int get(const string& name, string& value, const string& sk) const {
416
        return get(name, value, sk, false);
403
    }
417
    }
404
418
405
    virtual bool hasNameAnywhere(const string& nm) const {
419
    virtual bool hasNameAnywhere(const string& nm) const {
406
        typename vector<T*>::const_iterator it;
420
        typename vector<T*>::const_iterator it;
407
        for (it = m_confs.begin(); it != m_confs.end(); it++) {
421
        for (it = m_confs.begin(); it != m_confs.end(); it++) {