1 //*******************************************************************
2 //
3 // License:  See top level LICENSE.txt file.
4 //
5 // DESCRIPTION:
6 //   Contains declaration of class ossimPreferences. This class provides
7 //   a static keywordlist for global preferences. Objects needing access to
8 //   application-wide global parameters shall do so through this class.
9 //
10 // SOFTWARE HISTORY:
11 //>
12 //   23Apr2001  Oscar Kramer
13 //              Initial coding.
14 //<
15 //*****************************************************************************
16 
17 #ifndef ossimPreferences_HEADER
18 #define ossimPreferences_HEADER
19 
20 #include <ossim/base/ossimFilename.h>
21 #include <ossim/base/ossimKeywordlist.h>
22 
23 /*!****************************************************************************
24  *
25  * CLASS:  ossimPreferences
26  *
27  *****************************************************************************/
28 class OSSIMDLLEXPORT ossimPreferences
29 {
30 public:
31    // This is only here so we can swig wrap this.  The destructor should never be called directly.
32    ~ossimPreferences();
33    /*!
34     * METHOD: instance()
35     * The static singleton instance of this object is accessed via this method:
36     */
37    static ossimPreferences* instance();
38 
39    /*!
40     * METHOD: loadPreferences()
41     * These methods clear the current preferences and load either the default
test(String[] args)42     * preferences file or the specified file. Returns TRUE if loaded properly:
43     */
44    bool loadPreferences();
45    bool loadPreferences(const ossimFilename& pathname);
46 
47    /*!
48     * METHOD: savePrefences()
49     * This method permits saving the preferences file to the default location
50     * or to a specified location:
51     */
52    bool savePreferences() const;
53    bool savePreferences(const ossimFilename& pathname);
54 
55    /*!
56     * METHOD: findPreference()
57     * Performs a lookup for the specified keyword in the preferences KWL:
58     */
59    const char* findPreference(const char* key) const {return theKWL.find(key);}
60 
61 
62    /*!
63     * METHOD: addPreference()
64     * Inserts keyword/value pair into the in-memory preferences KWL. It does
65     * save to disk. App must do a savePreferences() for changes to be saved.
66     */
67    void addPreference(const char* key,
68                       const char* value);
69 
70    /*!
71     * METHOD: preferencesKWL()
72     * An alternative to utilizing findPreference(), for objects derived from
73     * ossimObject, is to access the preferences KWL with this method
74     * (typically during construction) and provide it to the object's
75     * loadState() method.
76     */
77    const ossimKeywordlist& preferencesKWL() const { return theKWL; }
78 
79    /*!
80     * METHOD: preferencesKWL()
81     * An alternative to utilizing findPreference(), for objects derived from
82     * ossimObject, is to access the preferences KWL with this method
checkDefaults(MessageInfo info)83     * (typically during construction) and provide it to the object's
84     * loadState() method.
85     */
86    ossimKeywordlist& preferencesKWL()  { return theKWL; }
87 
88    void addPreferences(const ossimKeywordlist& kwl,
89                        const char* prefix=0,
90                        bool stripPrefix=true);
91 
92    /** @return The preference filename. */
93    ossimFilename getPreferencesFilename() const;
checkGetterSetters(MessageInfo info)94 
95 protected:
96    /*!
97     * Override the compiler default constructors:
98     */
99    ossimPreferences();
100    ossimPreferences(const ossimPreferences&) {}
101 
102    void operator = (const ossimPreferences&) const {}
103 
104    static ossimPreferences* theInstance;
105    ossimKeywordlist         theKWL;
106    ossimFilename            thePrefFilename;
107    mutable bool             theInstanceIsModified;
108 };
109 
110 #endif
testIAE(Runnable runnable)111