ConfigurationSettings.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef CONFIGURATIONSETTINGS_H
00011 #define CONFIGURATIONSETTINGS_H
00012 
00013 #include "DataVariant.h"
00014 #include "Filename.h"
00015 #include "Subject.h"
00016 #include "Service.h"
00017 #include "TypesFile.h"
00018 
00019 #include <map>
00020 #include <string>
00021 
00022 class DynamicObject;
00023 class Filename;
00024 
00025 /**
00026  * This macro creates 4 static functions that
00027  * will provide get/set, has and getName functions for
00028  * a given setting in ConfigurationSettings.  These
00029  * methods should be used because they create type-safe
00030  * get/set functions for the given setting.  This macro
00031  * should be used for non-pointer types, the SETTING_PTR() macro
00032  * should be used for pointer types.
00033  *
00034  * Please see \ref settingsmacros for more details
00035  *
00036  * @param settingname
00037  *        the name of the setting.  The three generated methods will
00038  *        be getSetting[settingname], setSetting[settingname] and
00039  *        hasSetting[settingname]
00040  * @param classname
00041  *        this will be used to namespace the setting within
00042  *        ConfigurationSettings, ie. the key used to store
00043  *        the value in ConfigurationSettings will be 
00044  *        classname + "/" + settingname.
00045  * @param type
00046  *        this should be the C++ type used to store the setting,
00047  *        ie. unsigned int, bool.  This version of the macro
00048  *        should only be used with non-pointer types (ie. value types)
00049  * @param errorDefault
00050  *        The getSetting method generated by this macro must
00051  *        always return a value. If the setting does not
00052  *        exist in ConfigurationSettings, the value
00053  *        provided here will be returned by the getSetting
00054  *        method.  If the value provided here must be
00055  *        returned a verification error will be raised by
00056  *        the getSetting function.
00057  *
00058  */
00059 #define SETTING(settingname,classname,type,errorDefault) \
00060    /**
00061     * Returns the current value for this setting.  If this
00062     * setting does not exist in ConfigurationSettings, a
00063     * verification error will be logged to the message log
00064     * and potentially a verification error message box
00065     * will be displayed to the user.
00066     *
00067     * Please see \ref settingsmacros for more details
00068     * 
00069     * \return the current value for this setting.
00070     */ \
00071    static type getSetting##settingname() \
00072    { \
00073       Service<ConfigurationSettings> pSettings; \
00074       return dv_cast_with_verification< type >(pSettings->getSetting(getSetting##settingname##Key()), errorDefault); \
00075    } \
00076    /**
00077     * Returns \c true if this setting exists and has a 
00078     * value in ConfigurationSettings.
00079     *
00080     * Please see \ref settingsmacros for more details
00081     *
00082     * \return \c true if this setting exists, \c false otherwise.
00083     */ \
00084    static bool hasSetting##settingname() \
00085    { \
00086       Service<ConfigurationSettings> pSettings; \
00087       const DataVariant& dv = pSettings->getSetting(getSetting##settingname##Key()); \
00088       if (dv_cast< type >(&dv) != NULL) \
00089       { \
00090          return true; \
00091       } \
00092       return false; \
00093    } \
00094    /**
00095     * Changes the current value of this setting to the new value.
00096     *
00097     * Please see \ref settingsmacros for more details
00098     *
00099     * \param newValue
00100     *        the new value for this setting.
00101     * \param setIfSame
00102     *        If \c true, the value will be set into ConfigurationSettings
00103     *        even if the newValue and existing value are the same.  This
00104     *        has the side-effect of making the value a per-user setting
00105     *        and stored in the user's configuration file.  If \c false, this
00106     *        value will only be set if the newValue and existing value
00107     *        are different.  Therefore the value will only be stored in 
00108     *        the user's configuration file if the newValue is unique
00109     *        to the user.
00110     */ \
00111    static void setSetting##settingname(type newValue, bool setIfSame = false) \
00112    { \
00113       Service<ConfigurationSettings> pSettings; \
00114       pSettings->setSetting(getSetting##settingname##Key(), newValue, setIfSame); \
00115    } \
00116    /**
00117     * Returns the key for this setting that
00118     * could be passed to ConfigurationSettings::getSetting()
00119     * or ConfigurationSettings::setSetting().
00120     *
00121     * Please see \ref settingsmacros for more details
00122     *
00123     * @return the key used for this setting.
00124     */ \
00125     static std::string getSetting##settingname##Key() \
00126    { \
00127       std::string keyValue(#classname "/" #settingname); \
00128       return keyValue; \
00129    } \
00130 
00131 /**
00132  * This macro creates 4 static functions that
00133  * will provide get/set, has and getName functions for
00134  * a given setting in ConfigurationSettings.  These
00135  * methods should be used because they create type-safe
00136  * get/set functions for the given setting.  This macro
00137  * should be used for pointer types, the SETTING() macro
00138  * should be used for non-pointer types.
00139  *
00140  * Please see \ref settingsmacros for more details
00141  *
00142  * @param settingname
00143  *        the name of the setting.  The three generated methods will
00144  *        be getSetting[settingname], setSetting[settingname] and
00145  *        hasSetting[settingname]
00146  * @param classname
00147  *        this will be used to namespace the setting within
00148  *        ConfigurationSettings, ie. the key used to store
00149  *        the value in ConfigurationSettings will be 
00150  *        classname + "/" + settingname.
00151  * @param type
00152  *        this should be the C++ type used to store the setting,
00153  *        ie. DynamicObject, Filename (ie. without the *).
00154  *        The macro will add the * where required.
00155  */
00156 #define SETTING_PTR(settingname,classname,type) \
00157    /**
00158     * Returns the current value for this setting.  If this
00159     * setting does not exist in ConfigurationSettings, a
00160     * \c NULL value will be returned.
00161     *
00162     * Please see \ref settingsmacros for more details
00163     * 
00164     * \return the current value for this setting or \c NULL if not found.
00165     */ \
00166    static const type* getSetting##settingname() \
00167    { \
00168       Service<ConfigurationSettings> pSettings; \
00169       return dv_cast< type >(&pSettings->getSetting(getSetting##settingname##Key())); \
00170    } \
00171    /**
00172     * Returns \c true if this setting exists in ConfigurationSettings.
00173     * It may still be \c NULL however.
00174     *
00175     * Please see \ref settingsmacros for more details
00176     *
00177     * \return \c true if this setting exists, \c false otherwise.
00178     */ \
00179    static bool hasSetting##settingname() \
00180    { \
00181       Service<ConfigurationSettings> pSettings; \
00182       const DataVariant& dv = pSettings->getSetting(getSetting##settingname##Key()); \
00183       if (dv_cast< type >(&dv) != NULL) \
00184       { \
00185          return true; \
00186       } \
00187       return false; \
00188    } \
00189    /**
00190     * Changes the current value of this setting to the new value.
00191     *
00192     * Please see \ref settingsmacros for more details
00193     *
00194     * \param pNewValue
00195     *        the new value for this setting.  If \c NULL, the value will not be set.
00196     * \param setIfSame
00197     *        If \c true, the value will be set into ConfigurationSettings
00198     *        even if the pNewValue and existing value are the same.  This
00199     *        has the side-effect of making the value a per-user setting
00200     *        and stored in the user's configuration file.  If \c false, this
00201     *        value will only be set if the pNewValue and existing value
00202     *        are different.  Therefore the value will only be stored in 
00203     *        the user's configuration file if the pNewValue is unique
00204     *        to the user.
00205     */ \
00206    static void setSetting##settingname(type* pNewValue, bool setIfSame = false) \
00207    { \
00208       Service<ConfigurationSettings> pSettings; \
00209       if (pNewValue != NULL) \
00210       { \
00211          pSettings->setSetting(getSetting##settingname##Key(), *pNewValue, setIfSame); \
00212       } \
00213    } \
00214    /**
00215     * Returns the key for this setting that
00216     * could be passed to ConfigurationSettings::getSetting()
00217     * or ConfigurationSettings::setSetting().
00218     *
00219     * Please see \ref settingsmacros for more details
00220     *
00221     * @return the key used for this setting.
00222     */ \
00223     static std::string getSetting##settingname##Key() \
00224    { \
00225       std::string keyValue(#classname "/" #settingname); \
00226       return keyValue; \
00227    }
00228 
00229 /**
00230  * This macro creates 4 static functions that
00231  * will provide get/set, has and getName functions for
00232  * a given setting in ConfigurationSettings.  These
00233  * methods should be used because they create type-safe
00234  * get/set functions for the given setting.
00235  * This macro should be used instead of SETTING() if
00236  * and additional string needs to be provided at runtime
00237  * to make a unique key for the setting.  For instance, if
00238  * there should be a different setting value for each plug-in, then
00239  * this macro will generate functions that take the plug-in name
00240  * as an argument.
00241  * This macro should be used for non-pointer types, the CUSTOM_SETTING_PTR() macro
00242  * should be used for pointer types.
00243  *
00244  * Please see \ref settingsmacros for more details
00245  *
00246  * @param settingname
00247  *        the name of the setting.  The three generated methods will
00248  *        be getSetting[settingname], setSetting[settingname] and
00249  *        hasSetting[settingname]
00250  * @param classname
00251  *        this will be used to namespace the setting within
00252  *        ConfigurationSettings, ie. the key used to store
00253  *        the value in ConfigurationSettings will be 
00254  *        classname + "/" + namespaceStr + "/" + settingname.
00255  *        namespaceStr is an argument to the getSetting/setSetting
00256  *        and hasSetting functions generated by this macro.
00257  * @param type
00258  *        this should be the C++ type used to store the setting,
00259  *        ie. unsigned int, bool.  This version of the macro
00260  *        should only be used with non-pointer types (ie. value types)
00261  * @param errorDefault
00262  *        The getSetting method generated by this macro must
00263  *        always return a value. If the setting does not
00264  *        exist in ConfigurationSettings, the value
00265  *        provided here will be returned by the getSetting
00266  *        method.  If the value provided here must be
00267  *        returned a verification error will be raised by
00268  *        the getSetting function.
00269  */
00270 #define CUSTOM_SETTING(settingname,classname,type,errorDefault) \
00271    /**
00272     * Returns the current value for this setting.  If this
00273     * setting does not exist in ConfigurationSettings, a
00274     * verification error will be logged to the message log
00275     * and potentially a verification error message box
00276     * will be displayed to the user.
00277     *
00278     * Please see \ref settingsmacros for more details
00279     *
00280     * \param namespaceStr
00281     *        This string will be used to create a unique
00282     *        identifier for this particular setting so
00283     *        that it can be stored and retrieved from ConfigurationSettings.
00284     * 
00285     * \return the current value for this setting.
00286     */ \
00287    static type getSetting##settingname(const std::string& namespaceStr ) \
00288    { \
00289       Service<ConfigurationSettings> pSettings; \
00290       return dv_cast_with_verification< type >(pSettings->getSetting(getSetting##settingname##Key(namespaceStr)), errorDefault); \
00291    } \
00292    /**
00293     * Returns \c true if this setting exists and has a 
00294     * value in ConfigurationSettings.
00295     *
00296     * Please see \ref settingsmacros for more details
00297     *
00298     * \param namespaceStr
00299     *        This string will be used to create a unique
00300     *        identifier for this particular setting so
00301     *        that it can be stored and retrieved from ConfigurationSettings.
00302     *
00303     * \return \c true if this setting exists, \c false otherwise.
00304     */ \
00305    static bool hasSetting##settingname(const std::string& namespaceStr ) \
00306    { \
00307       Service<ConfigurationSettings> pSettings; \
00308       const DataVariant& dv = pSettings->getSetting(getSetting##settingname##Key(namespaceStr)); \
00309       if (dv_cast< type >(&dv) != NULL) \
00310       { \
00311          return true; \
00312       } \
00313       return false; \
00314    } \
00315    /**
00316     * Changes the current value of this setting to the new value.
00317     *
00318     * Please see \ref settingsmacros for more details
00319     *
00320     * \param namespaceStr
00321     *        This string will be used to create a unique
00322     *        identifier for this particular setting so
00323     *        that it can be stored and retrieved from ConfigurationSettings.
00324     * \param newValue
00325     *        the new value for this setting.
00326     * \param setIfSame
00327     *        If \c true, the value will be set into ConfigurationSettings
00328     *        even if the newValue and existing value are the same.  This
00329     *        has the side-effect of making the value a per-user setting
00330     *        and stored in the user's configuration file.  If \c false, this
00331     *        value will only be set if the newValue and existing value
00332     *        are different.  Therefore the value will only be stored in 
00333     *        the user's configuration file if the newValue is unique
00334     *        to the user.
00335     */ \
00336    static void setSetting##settingname(const std::string& namespaceStr, type newValue, bool setIfSame = false) \
00337    { \
00338       Service<ConfigurationSettings> pSettings; \
00339       pSettings->setSetting(getSetting##settingname##Key(namespaceStr), newValue, setIfSame); \
00340    } \
00341    /**
00342     * Returns the key for this setting that
00343     * could be passed to ConfigurationSettings::getSetting()
00344     * or ConfigurationSettings::setSetting().
00345     *
00346     * Please see \ref settingsmacros for more details
00347     *
00348     * \param namespaceStr
00349     *        This string will be used to create a unique
00350     *        identifier for this particular setting so
00351     *        that it can be stored and retrieved from ConfigurationSettings.
00352     *
00353     * @return the key used for this setting.
00354     */ \
00355     static std::string getSetting##settingname##Key(const std::string& namespaceStr) \
00356    { \
00357       std::string keyValue(#classname "/" + namespaceStr + "/" #settingname); \
00358       return keyValue; \
00359    }
00360 
00361 /**
00362  * This macro creates 4 static functions that
00363  * will provide get/set, has and getName functions for
00364  * a given setting in ConfigurationSettings.  These
00365  * methods should be used because they create type-safe
00366  * get/set functions for the given setting. 
00367  * This macro should be used instead of SETTING_PTR() if
00368  * and additional string needs to be provided at runtime
00369  * to make a unique key for the setting.  For instance, if
00370  * there should be a different setting value for each plug-in, then
00371  * this macro will generate functions that take the plug-in name
00372  * as an argument.
00373  * This macro should be used for pointer types, the CUSTOM_SETTING() macro
00374  * should be used for non-pointer types.
00375  *
00376  * Please see \ref settingsmacros for more details
00377  *
00378  * @param settingname
00379  *        the name of the setting.  The three generated methods will
00380  *        be getSetting[settingname], setSetting[settingname] and
00381  *        hasSetting[settingname]
00382  * @param classname
00383  *        this will be used to namespace the setting within
00384  *        ConfigurationSettings, ie. the key used to store
00385  *        the value in ConfigurationSettings will be 
00386  *        classname + "/" + namespaceStr + "/" + settingname.
00387  *        namespaceStr is an argument to the getSetting/setSetting
00388  *        and hasSetting functions generated by this macro.
00389  * @param type
00390  *        this should be the C++ type used to store the setting,
00391  *        ie. DynamicObject, Filename (ie. without the *).
00392  *        The macro will add the * where required.
00393  */
00394 #define CUSTOM_SETTING_PTR(settingname,classname,type) \
00395    /**
00396     * Returns the current value for this setting.  If this
00397     * setting does not exist in ConfigurationSettings, a
00398     * \c NULL value will be returned.
00399     *
00400     * Please see \ref settingsmacros for more details
00401     * 
00402     * \param namespaceStr
00403     *        This string will be used to create a unique
00404     *        identifier for this particular setting so
00405     *        that it can be stored and retrieved from ConfigurationSettings.
00406     *
00407     * \return the current value for this setting or \c NULL if not found.
00408     */ \
00409    static const type* getSetting##settingname(const std::string& namespaceStr) \
00410    { \
00411       Service<ConfigurationSettings> pSettings; \
00412       return dv_cast< type >(&pSettings->getSetting(getSetting##settingname##Key(namespaceStr))); \
00413    } \
00414    /**
00415     * Returns \c true if this setting exists in ConfigurationSettings.
00416     * It may still be \c NULL however.
00417     *
00418     * Please see \ref settingsmacros for more details
00419     *
00420     * \param namespaceStr
00421     *        This string will be used to create a unique
00422     *        identifier for this particular setting so
00423     *        that it can be stored and retrieved from ConfigurationSettings.
00424     *
00425     * \return \c true if this setting exists, \c false otherwise.
00426     */ \
00427    static bool hasSetting##settingname(const std::string& namespaceStr ) \
00428    { \
00429       Service<ConfigurationSettings> pSettings; \
00430       const DataVariant& dv = pSettings->getSetting(getSetting##settingname##Key(namespaceStr)); \
00431       if (dv_cast< type >(&dv) != NULL) \
00432       { \
00433          return true; \
00434       } \
00435       return false; \
00436    } \
00437    /**
00438     * Changes the current value of this setting to the new value.
00439     *
00440     * Please see \ref settingsmacros for more details
00441     *
00442     * \param namespaceStr
00443     *        This string will be used to create a unique
00444     *        identifier for this particular setting so
00445     *        that it can be stored and retrieved from ConfigurationSettings.
00446     * \param pNewValue
00447     *        the new value for this setting.  If \c NULL, the value will not be set.
00448     * \param setIfSame
00449     *        If \c true, the value will be set into ConfigurationSettings
00450     *        even if the pNewValue and existing value are the same.  This
00451     *        has the side-effect of making the value a per-user setting
00452     *        and stored in the user's configuration file.  If \c false, this
00453     *        value will only be set if the pNewValue and existing value
00454     *        are different.  Therefore the value will only be stored in 
00455     *        the user's configuration file if the pNewValue is unique
00456     *        to the user.
00457     */ \
00458    static void setSetting##settingname(const std::string& namespaceStr, type* pNewValue, bool setIfSame = false) \
00459    { \
00460       Service<ConfigurationSettings> pSettings; \
00461       if (pNewValue != NULL) \
00462       { \
00463          pSettings->setSetting(getSetting##settingname##Key(namespaceStr), *pNewValue, setIfSame); \
00464       } \
00465    } \
00466    /**
00467     * Returns the key for this setting that
00468     * could be passed to ConfigurationSettings::getSetting()
00469     * or ConfigurationSettings::setSetting().
00470     *
00471     * Please see \ref settingsmacros for more details
00472     *
00473     * \param namespaceStr
00474     *        This string will be used to create a unique
00475     *        identifier for this particular setting so
00476     *        that it can be stored and retrieved from ConfigurationSettings.
00477     *
00478     * @return the key used for this setting.
00479     */ \
00480     static std::string getSetting##settingname##Key(const std::string& namespaceStr) \
00481    { \
00482       std::string keyValue(#classname "/" + namespaceStr + "/" #settingname); \
00483       return keyValue; \
00484    }
00485    
00486 /**
00487  * \ingroup ServiceModule
00488  * Contains settings specific to the user and application run that
00489  * will be persisted between runs of the application.
00490  *
00491  * The configuration settings allow data values to be stored per-user and
00492  * during an application run.  Settings which are saved per-user and persist
00493  * between application runs are called per-user settings.  Settings which
00494  * only exist during one application run are called per-session or temporary settings.
00495  *
00496  * These settings are initialized on application startup.  This is done by
00497  * locating any .cfg files contained in getHome()/DefaultSettings and the
00498  * directory defined by the AdditionalDefaultDir value of the deployment file.
00499  * Please see @ref deploymentfiles for more details. These .cfg
00500  * files must follow the naming convention of "[LoadOrder]-[Name].cfg" where
00501  * LoadOrder is an unsigned int and Name can be any text recognized by the file
00502  * system. These .cfg's are then parsed according to the LoadOrder, with 1 reserved
00503  * for the application and being the first .cfg that will be parsed.  After
00504  * these files are parsed, there is a .cfg file for the user that is running
00505  * the application that will be parsed and created as per-user settings.
00506  *
00507  * The directory that is used to store per-user settings can be controlled
00508  * by a plug-in developer by creating a deployment file.
00509  * See \ref deploymentfiles for more details.
00510  *
00511  * The configuration settings can also be used to allow the Studio to create
00512  * PlugInArg objects prior to plug-in execution.  If the plug-in args cannot be
00513  * defined, the configuration setting are queried for specific values using the
00514  * plug-in name for the Setting group name.
00515  *
00516  * This subclass of Subject will notify upon the following conditions:
00517  * - The following methods are called: setSetting(), setTemporarySetting,
00518  *   deleteUserSetting, deleteTemporarySetting.
00519  */
00520 class ConfigurationSettings : public Subject
00521 {
00522 public:
00523    /**
00524     * Emitted with any<std::string> when setSetting or setTemporarySetting is called.
00525     * The string will be the key of the setting that was modified.
00526     */
00527    SIGNAL_METHOD(ConfigurationSettings, SettingModified);
00528    /**
00529     * Emitted with no data just prior to save of the configuration settings
00530     * to disk.
00531     */
00532    SIGNAL_METHOD(ConfigurationSettings, AboutToSave);
00533 
00534    SETTING_PTR(ExtensionFilesPath, FileLocations, Filename)
00535    SETTING_PTR(ExportPath, FileLocations, Filename)
00536    SETTING_PTR(ImportPath, FileLocations, Filename)
00537    SETTING_PTR(SaveOpenSessionPath, FileLocations, Filename)
00538    SETTING_PTR(InternalPath, FileLocations, Filename)
00539    SETTING(PathBookmarks, FileLocations, std::vector<Filename*>, std::vector<Filename*>())
00540    SETTING_PTR(MessageLogPath, FileLocations, Filename)
00541    SETTING(NumberOfMruFiles, General, unsigned int, 3)
00542    SETTING_PTR(SupportFilesPath, FileLocations, Filename)
00543    SETTING(ShowStatusBarCubeValue, StatusBar, bool, true)
00544    SETTING(ShowStatusBarElevationValue, StatusBar, bool, true)
00545    SETTING(ShowStatusBarGeoCoords, StatusBar, bool, true)
00546    SETTING(ShowStatusBarPixelCoords, StatusBar, bool, true)
00547    SETTING(ShowStatusBarResultValue, StatusBar, bool, true)
00548    SETTING(ShowStatusBarRotationValue, StatusBar, bool, true)
00549    SETTING_PTR(TempPath, FileLocations, Filename)
00550    SETTING(ThreadCount, Edit, unsigned int, 1)
00551    SETTING(UndoBufferSize, Edit, unsigned int, 10)
00552    SETTING_PTR(WizardPath, FileLocations, Filename)
00553    SETTING_PTR(TextEditor, FileLocations, Filename)
00554    SETTING(TextEditorArguments, FileLocations, std::string, std::string())
00555    SETTING_PTR(JvmLoaderLibraryPath, FileLocations, Filename)
00556    CUSTOM_SETTING_PTR(PluginWorkingDirectory, FileLocations, Filename)
00557    SETTING(AlternateMouseWheelZoom, Edit, bool, true)
00558    SETTING(GpuTextureCacheSize, General, unsigned int, 0)
00559    SETTING(DisplayClassificationMarkings, General, bool, true)
00560 
00561    /**
00562     * Gets the root directory for the main application.
00563     *
00564     * This method returns the fully qualified path for the base 
00565     * of the directory tree associated with the main application.
00566     *
00567     * This path can be adjusted by a plug-in developer by creating
00568     * a deployment file. See @ref deploymentfiles for more details.
00569     *
00570     * @return   Base folder for the main application.
00571     */
00572    virtual std::string getHome() const = 0;
00573 
00574    /**
00575     * Gets the application creator.
00576     *
00577     * @return   The application creator.
00578     */
00579    virtual std::string getCreator() const = 0;
00580 
00581    /**
00582     * Gets the application name.
00583     *
00584     * @return   The application name.
00585     */
00586    virtual std::string getProduct() const = 0;
00587 
00588    /**
00589     * Gets the application version.
00590     *
00591     * @return   The application version.
00592     */
00593    virtual std::string getVersion() const = 0;
00594 
00595    /**
00596     * Gets the build revision of the application.
00597     *
00598     * @return The build revision.
00599     */
00600    virtual std::string getBuildRevision() const = 0;
00601 
00602    /**
00603     * Gets the username of the user currently running the application.
00604     *
00605     * @return   The username of the current user.
00606     */
00607    virtual std::string getUserName() const = 0;
00608 
00609    /**
00610     * Gets the path to the user's documents folder.
00611     *
00612     * @return  The full path to the current user's documents folder.  On Windows this is usually
00613     *          C:\\Documents and Settings\\username\\My Documents\\%Opticks and on Solaris it is
00614     *          usually /export/home/username/Opticks.
00615     */
00616    virtual std::string getUserDocs() const = 0;
00617 
00618    /**
00619     * Gets the operating system name.
00620     *
00621     * Returns the general operating system name that the
00622     * application was compiled against. (ie. "Solaris" or "Windows")
00623     * This name should only be used within the context of
00624     * the application and is not intended to be passed to any
00625     * system api's or used to conditionally execute code, see
00626     * AppConfig.h for that.  This name is also not
00627     * guaranteed to match any similiar operating system
00628     * name returned by using system calls.
00629     *
00630     * @return The operating system name.
00631     */
00632    virtual std::string getOperatingSystemName() const = 0;
00633 
00634    /**
00635     * Gets the architecture name.
00636     *
00637     * Returns the general architecture name that the
00638     * application was compiled to work with. (ie. "x86-64", "Sparc64")
00639     * This name should only be used within the context of
00640     * the application and is not intended to be passed to any
00641     * system api's or used to conditionally execute code, see
00642     * AppConfig.h for that.  This name is also not
00643     * guaranteed to match any similiar architecture 
00644     * name returned by using system calls.
00645     *
00646     * @return The architecture name.
00647     */
00648    virtual std::string getArchitectureName() const = 0;
00649 
00650    /**
00651     * Gets the production status.
00652     *
00653     * @return   \c true if the application and all plug-ins are production.
00654     */
00655    virtual bool isProductionRelease() const = 0;
00656 
00657    /**
00658     * Gets the release type.
00659     *
00660     * @return  An enum describing the release type.
00661     */
00662    virtual ReleaseType getReleaseType() const = 0;
00663 
00664    /**
00665     * Gets the release description.
00666     *
00667     * @return  A string describing the release.
00668     */
00669    virtual std::string getReleaseDescription() const = 0;
00670 
00671    /**
00672     * Gets the plug-in path.
00673     *
00674     * This is the directory where plug-ins must be placed if they are to be
00675     * loaded by the application.
00676     *
00677     * This path can be adjusted by a plug-in developer by creating
00678     * a deployment file. See @ref deploymentfiles for more details.
00679     *
00680     * @return  The plug-in path.
00681     */
00682    virtual std::string getPlugInPath() const = 0;
00683 
00684    /**
00685     * Sets the given setting.
00686     *
00687     * This method sets the given setting.  If the setting
00688     * already exists, the data is simply replaced.  If the
00689     * setting does not exist, it is created.  This
00690     * setting will be saved into the user's configuration file
00691     * during application shutdown
00692     * meaning the particular value set for this setting will be
00693     * a per-user value.  If the given setting was previously set
00694     * with setTemporarySetting(), it will no longer be a temporary setting
00695     * and will become a per-user setting.
00696     *
00697     * This method is preferred to adoptSetting() unless
00698     * you are passing an already constructed DataVariant in
00699     * which case, adoptSetting() will be faster because
00700     * it avoids a deep copy.
00701     *
00702     * @param   key
00703     *          The name of the setting.  This key
00704     *          can have '/' in it, in which it will behave like DynamicObject::setAttributeByPath.
00705     * @param   var
00706     *          The value of the setting. If this is invalid, no setting will 
00707     *          be added or modified.
00708     * @param   setIfSame
00709     *          If \c false, the setting will not be set if the new value of the
00710     *          setting is equal to the current value (ie. getSetting()) for the setting
00711     *          (ie. the value will not be serialized to the user's configuration file).
00712     *          If \c true, the setting will be set regardless of the current
00713     *          value (ie. it will be serialized to the user's configuration file).
00714     *
00715     * @return  \c true if the setting was successfully set, and \c false otherwise.
00716     *
00717     * @see     DynamicObject::setAttribute, adoptSetting()
00718     */
00719    template<typename T>
00720    bool setSetting(const std::string& key, const T& var, bool setIfSame = false)
00721    {
00722       DataVariant temp(var);
00723       return adoptSetting(key, temp, setIfSame);
00724    }
00725 
00726    /**
00727     * Sets the given setting.
00728     *
00729     * This method sets the given setting.  If the setting
00730     * already exists, the data is simply replaced.  If the
00731     * setting does not exist, it is created.  This
00732     * setting will be saved into the user's configuration file
00733     * during application shutdown
00734     * meaning the particular value set for this setting will be
00735     * a per-user value.  If the given setting was previously set
00736     * with setTemporarySetting(), it will no longer be a temporary setting
00737     * and will become a per-user setting.
00738     *
00739     * This method should not be used; generally setSetting() is
00740     * preferred. This method and setSetting() have identical
00741     * performance characteristics and setSetting() is easier to
00742     * call.  This method is faster than setSetting() though if
00743     * you have an already constructed DataVariant and is
00744     * preferred to setSetting() in this case.
00745     *
00746     * @param   key
00747     *          The name of the setting.  This key
00748     *          can have '/' in it, in which it will behave like DynamicObject::setAttributeByPath.
00749     * @param   var
00750     *          The value of the setting. If this is invalid, no setting will 
00751     *          be added or modified. On return, this will contain the value
00752     *          previously stored. If the value did not previously exist, then this
00753     *          will contain an invalid DataVariant.
00754     * @param   setIfSame
00755     *          If \c false, the setting will not be set if the new value of the
00756     *          setting is equal to the current value (ie. getSetting()) for the setting
00757     *          (ie. the value will not be serialized to the user's configuration file).
00758     *          If \c true, the setting will be set regardless of the current
00759     *          value (ie. it will be serialized to the user's configuration file).
00760     *
00761     * @return  \c true if the setting was successfully set, and \c false otherwise.
00762     *
00763     * @see     DynamicObject::adoptAttribute, setSetting()
00764     */
00765    virtual bool adoptSetting(const std::string& key, DataVariant& var, bool setIfSame = false) = 0;
00766 
00767    /**
00768     * Sets the given setting for this session only.  Any value
00769     * set using this method will only be valid while the application
00770     * is running. The value set using this method will not be saved during
00771     * a session save, and will not be restored during a session restore.
00772     * If a plug-in sets a value using this method and needs the value
00773     * saved/restored during session save/restore, it is the responsibility
00774     * of the plug-in to save/restore the value during session save/restore.
00775     *
00776     * This method is preferred to adoptTemporarySetting() unless
00777     * you are passing an already constructed DataVariant in
00778     * which case, adoptTemporarySetting() will be faster because
00779     * it avoids a deep copy.
00780     *
00781     * @param key
00782     *        The name of the setting.  This key
00783     *        can have '/' in it, in which it will behave like DynamicObject::setAttributeByPath.
00784     * @param var
00785     *        The value of the setting. If this is invalid, no setting will 
00786     *        be added or modified.
00787     *
00788     * @return \c true if the setting was successfully set, and \c false otherwise.
00789     */
00790    template<typename T>
00791    bool setTemporarySetting(const std::string& key, const T& var)
00792    {
00793       DataVariant temp(var);
00794       return adoptTemporarySetting(key, temp);
00795    }
00796 
00797    /**
00798     * Sets the given setting for this session only.  Any value
00799     * set using this method will only be valid while the application
00800     * is running. The value set using this method will not be saved during
00801     * a session save, and will not be restored during a session restore.
00802     * If a plug-in sets a value using this method and needs the value
00803     * saved/restored during session save/restore, it is the responsibility
00804     * of the plug-in to save/restore the value during session save/restore.
00805     *
00806     * This method should not be used; generally setTemporarySetting() is
00807     * preferred. This method and setTemporarySetting() have identical
00808     * performance characteristics and setTemporarySetting() is easier to
00809     * call.  This method is faster than setTemporarySetting() though if
00810     * you have an already constructed DataVariant and is
00811     * preferred to setTemporarySetting() in this case.
00812     *
00813     * @param key
00814     *        The name of the setting.  This key
00815     *        can have '/' in it, in which it will behave like DynamicObject::setAttributeByPath.
00816     * @param var
00817     *        The value of the setting. If this is invalid, no setting will 
00818     *        be added or modified.  On return, this will contain the value
00819     *        previously stored. If the value did not previously exist, then this
00820     *        will contain an invalid DataVariant.
00821     *
00822     * @return \c true if the setting was successfully set, and \c false otherwise.
00823     */
00824    virtual bool adoptTemporarySetting(const std::string& key, DataVariant& var) = 0;
00825 
00826    /**
00827     * Gets the current value for the given setting.  The value
00828     * returned will be located in the following order: temporary setting,
00829     * per-user setting and default setting.  
00830     *
00831     * @see setTemporarySetting(), setSetting()
00832     *
00833     * @param   key
00834     *          Name of the setting to be found.  This key
00835     *          can have '/' in it, in which case it will behave like
00836     *          DynamicObject::getAttributeByPath.
00837     *
00838     * @return  The setting in a DataVariant. If the setting was not found,
00839     *          an invalid DataVariant will be returned.
00840     */
00841    virtual const DataVariant& getSetting(const std::string& key) const = 0;
00842 
00843    /**
00844     * Queries whether a given setting has a per-user value defined.
00845     *
00846     * @param key
00847     *        Name of the setting to be found.  This key
00848     *        can have '/' in it, in which case it will behave like
00849     *        DynamicObject::getAttributeByPath.
00850     *
00851     * @return \c true if this particular setting has a per-user value set and
00852     *         does not have a per-session value set.
00853     */
00854    virtual bool isUserSetting(const std::string& key) const = 0;
00855 
00856    /**
00857     * Queries whether a given setting has been set using setTemporarySetting().
00858     *
00859     * @param key
00860     *        Name of the setting to be found.  This key
00861     *        can have '/' in it, in which case it will behave like
00862     *        DynamicObject::getAttributeByPath.
00863     *
00864     * @return true if this particular setting has been set using setTemporarySetting().
00865     */
00866    virtual bool isTemporarySetting(const std::string& key) const = 0;
00867 
00868    /**
00869     * Queries whether a given setting is the default value, i.e. it has not been
00870     * overridden by the user or by calling setTemporarySetting().
00871     *
00872     * @param key
00873     *        Name of the setting to be found.  This key
00874     *        can have '/' in it, in which case it will behave like
00875     *        DynamicObject::getAttributeByPath.
00876     *
00877     * @return true if this particular setting is the default value.
00878     */
00879    virtual bool isDefaultSetting(const std::string& key) const = 0;
00880 
00881    /**
00882     * Removes a per-user setting.  See getSetting() for
00883     * more details.
00884     *
00885     * @param   key
00886     *          Name of the setting to be deleted.
00887     */
00888    virtual void deleteUserSetting(const std::string& key) = 0;
00889 
00890    /**
00891     * Removes a per-session temporary setting.  See getSetting() for
00892     * more details.  
00893     *
00894     * @param   key
00895     *          Name of the setting to be deleted.
00896     */
00897    virtual void deleteTemporarySetting(const std::string& key) = 0;
00898 
00899    /**
00900     * Copies the value of the given setting into the provided
00901     * DynamicObject. This method is intended to be used
00902     * when creating default files, so a plug-in developer
00903     * can copy a setting into a DynamicObject which can
00904     * be written to a defaults file using serializeAsDefaults().
00905     *
00906     * @param key
00907     *        Name of the setting to copy into the DynamicObject.
00908     * @param pObject
00909     *        The DynamicObject that the setting should be copied into.
00910     *        It will be copied in, such that it can be retrieved by
00911     *        calling pObject->getAttributeByPath(group + "/" + key);
00912     */
00913    virtual void copySetting(const std::string& key, DynamicObject* pObject) const = 0;
00914 
00915    /**
00916     * Saves the given DynamicObject values into a .cfg file that could be put
00917     * into the AppHome/DefaultSettings directory and be used as defaults
00918     * by the application.
00919     *
00920     * @param pFilename
00921     *        The full path of the file where the dynamic object should be saved.
00922     * @param pObject
00923     *        The settings that should be saved into the file.
00924     *
00925     * @return \c true if the save was successful, otherwise \c false.
00926     */
00927    virtual bool serializeAsDefaults(const Filename* pFilename, const DynamicObject* pObject) const = 0;
00928 
00929    /**
00930     * Loads the given settings from the file and return them as a 
00931     * DynamicObject. The load settings are simply returned as a
00932     * dynamic object, existing setting values are left unchanged.
00933     *
00934     * @param pFilename
00935     *        the full path to the file containing the settings.
00936     *
00937     * @return A dynamic object containing the loaded settings or \c NULL
00938     *         if the settings could not be loaded.
00939     */
00940    virtual DynamicObject* deserialize(const Filename* pFilename) const = 0;
00941 
00942 protected:
00943    /**
00944     * This will be cleaned up during application close.  Plug-ins do not
00945     * need to destroy it.
00946     */
00947    virtual ~ConfigurationSettings() {}
00948 };
00949 
00950 #endif

Software Development Kit - Opticks 4.9.0 Build 16218