~ubuntu-branches/ubuntu/trusty/presage/trusty-proposed

« back to all changes in this revision

Viewing changes to src/lib/core/profile.h

  • Committer: Bazaar Package Importer
  • Author(s): Matteo Vescovi
  • Date: 2011-08-06 09:26:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110806092615-0wvhajaht9974ncx
Tags: upstream-0.8.6
ImportĀ upstreamĀ versionĀ 0.8.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************
 
3
 *  Presage, an extensible predictive text entry system
 
4
 *  ---------------------------------------------------
 
5
 *
 
6
 *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
 
7
 
 
8
    This program is free software; you can redistribute it and/or modify
 
9
    it under the terms of the GNU General Public License as published by
 
10
    the Free Software Foundation; either version 2 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    This program is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU General Public License along
 
19
    with this program; if not, write to the Free Software Foundation, Inc.,
 
20
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
21
                                                                             *
 
22
                                                                **********(*)*/
 
23
 
 
24
 
 
25
#ifndef PRESAGE_PROFILE
 
26
#define PRESAGE_PROFILE
 
27
 
 
28
#include "config.h"
 
29
 
 
30
#include <tinyxml.h>
 
31
 
 
32
#include <vector>
 
33
#include <string>
 
34
#include <map>
 
35
 
 
36
typedef std::string Value;
 
37
#include "configuration.h"
 
38
#include "presageException.h"
 
39
 
 
40
/** Profile provides access to the active profile configuration variables.
 
41
 *
 
42
 * Profile only provides an accessor method to read configuration
 
43
 * values. The class is immutable. It is not possible to modify
 
44
 * configuration values. Configuration values are set when the Profile
 
45
 * is constructed.
 
46
 *
 
47
 * Profile acts as an interface to ProfileManager. It converts simple
 
48
 * requests for configuration variable values from client objects
 
49
 * (such as Plugin objects) into requests to ProfileManager.  There is
 
50
 * no need to have a map containing the variable, value pairs. It is
 
51
 * sufficient to keep a reference to ProfileManager and have
 
52
 * ProfileManager expose an interface that Profile can use to query
 
53
 * variable values.
 
54
 *
 
55
 */
 
56
class Profile {
 
57
public:
 
58
    /** Profile constructor.
 
59
     *
 
60
     * \param filename where profile is saved to
 
61
     */
 
62
    Profile(const std::string& filename);
 
63
 
 
64
    /** Profile destructor.
 
65
     *
 
66
     * Destructor deallocates the Configuration object passed in costructor.
 
67
     *
 
68
     */
 
69
    virtual ~Profile();
 
70
 
 
71
    /** Writes configuration from XML DOM document into configuration.
 
72
     * 
 
73
     */
 
74
    void read_into_configuration(Configuration* configuration);
 
75
 
 
76
    /* Reads from configuration and writes to XML DOM document.
 
77
     *
 
78
     */
 
79
    void read_from_configuration (Configuration* configuration);
 
80
 
 
81
    bool file_read_ok () const;
 
82
 
 
83
    bool write_to_file () const;
 
84
 
 
85
    class ProfileException : public PresageException {
 
86
    public:
 
87
        ProfileException(presage_error_code_t code, const std::string& desc) throw() : PresageException(code, desc) { }
 
88
        virtual ~ProfileException() throw() { }
 
89
        
 
90
    private:
 
91
        ProfileException() throw() : PresageException(PRESAGE_ERROR, "") { }
 
92
 
 
93
    };
 
94
 
 
95
protected:
 
96
    void init_configuration(Configuration* config, TiXmlDocument* node);
 
97
    void visit_node(Configuration* config, TiXmlNode* node, std::vector<std::string> variable);
 
98
 
 
99
    TiXmlDocument* xmlProfileDoc;
 
100
    std::string xml_filename;
 
101
    bool xml_profile_read_ok;
 
102
};
 
103
 
 
104
#endif // PRESAGE_PROFILE