1 //*******************************************************************
2 //
3 // License:  See top level LICENSE.txt file.
4 //
5 // DESCRIPTION:
6 //   Contains declaration of class ossimInit. This object handles all aspects
7 //   of initialization for OSSIM applications. These tasks include:
8 //
9 //      1. Parsing the command line.
10 //      2. Instantiating all class factories as declared in ossimFactories.h
11 //      3. Initializing the "trace" code execution tracing functionality.
12 //      4. Scanning the preferences file for relevant values.
13 //
14 // SOFTWARE HISTORY:
15 //>
16 //   24Apr2001  Oscar Kramer
17 //              Initial coding.
18 //<
19 //*****************************************************************************
20 // $Id: ossimInit.h 19440 2011-04-25 16:41:28Z dburken $
21 #ifndef ossimInit_HEADER
22 #define ossimInit_HEADER 1
23 
24 #include <ossim/base/ossimFilename.h>
25 
26 class ossimPreferences;
27 class ossimArgumentParser;
28 
29 class OSSIMDLLEXPORT ossimInit
30 {
31 public:
32 
33    ~ossimInit();
34    /*!
35     * Returns the static instance of an ossimInit object. This is of no use
36     * until non-static methods are implemented.
37     */
38    static ossimInit* instance();
39 
40    void addOptions(ossimArgumentParser& parser);
41 
42    /*!
43     * METHOD: initialize()
44     * This method shall be called from the application's main module with
45     * the command-line arguments. Every OSSIM application should have the
46     * following line early in the main module:
47     *
48     *   ossimInit::initialize(argc, argv);
49     *
50     * OR
51     *
52     *   ossimInit::instance()->initialize(argc, argv);
53     *
54     * The two forms are functionally identical. Pick the latter form if you
55     * like to type. The argv command line options are parsed and may be
56     * stripped. the value of argc will be adjusted to account for stripped
57     * options.
58     */
59    void initialize(int& argc, char** argv);
60 
61    void initialize(ossimArgumentParser& parser);
62 
63    void initialize();
64 
65    void finalize();
66 
67    /*!
68     * METHOD: usage()
69     * Prints to stdout the list of command line options that this object parses
70     */
71    void usage();
72 
73    /** @return theElevEnabledFlag */
74    bool getElevEnabledFlag() const;
75 
76    /**
77     * @brief Sets theElevEnabledFlag.
78     * @param flag If true ossimElevManager will be initialized. Set to false
79     * to NOT initialize the ossimElevManager from preferences.
80     * Default in class is true.
81     */
82    void setElevEnabledFlag(bool flag);
83 
84    void setPluginLoaderEnabledFlag(bool flag);
85 
86    /**
87     * Can take a file or a directory.  If a directory is givien then it will check all files in
88     * the directory and add each file that is detected to be a valid plugin.
89     *
90     * @param plugin Is the filename of the plugin to load
91     * @param options Is a keywordlist of plugin specific options
92 
93     */
94    void loadPlugins(const ossimFilename& plugin, const char* options=0);
95 
96    void initializePlugins();
97    void initializeDefaultFactories();
98    void initializeElevation();
99 
100    /**
101     * @brief Initializes log file from preferences keyword lookup
102     * of "ossim.log.file" if log file has not already been set and
103     * keyword is set in preferences.
104     *
105     * So this should be called after parse options as the --ossim-logfile
106     * should override any preferences setting.
107     */
108    void initializeLogFile();
109 
110    /**
111     * @return The version in the form of:
112     * "version major.minor.release (yyyymmdd)"
113     * where
114     * yyyymmdd is the build date.
115     *
116     * e.g. "version 1.7.0 (20071003)"
117     */
118    ossimString version() const;
119 
120    ossimFilename appName()const;
121 
122 protected:
123    /** protected default constructor. */
124    ossimInit();
125 
126    /** Hidden from use copy constructor. */
127    ossimInit(const ossimInit& obj);
128 
129    /** Hidden from use assignment operator. */
130    void operator=(const ossimInit& rhs) const;
131 
132    void parseOptions(ossimArgumentParser& parser);
133 
134    void parseNotifyOption(ossimArgumentParser& parser);
135    void parseEnvOptions(ossimArgumentParser& parser);
136    void parsePrefsOptions(ossimArgumentParser& parser);
137    /*!
138     * METHOD: removeOptions()
139     * Utility for stripping from argv all characters associated with a
140     * particular option:
141     */
142    void removeOption(int&   argc,
143                      char** argv,
144                      int    argToRemove);
145 
146    static ossimInit*  theInstance;
147    bool               theInitializedFlag;
148    ossimFilename      theAppName;
149    ossimPreferences*  thePreferences;
150    bool               theElevEnabledFlag;
151    bool               thePluginLoaderEnabledFlag;
152 };
153 
154 #endif
155