OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ossimInit Class Reference

#include <ossimInit.h>

Public Member Functions

 ~ossimInit ()
 
void addOptions (ossimArgumentParser &parser)
 
void initialize (int &argc, char **argv)
 
void initialize (ossimArgumentParser &parser)
 
void initialize ()
 
void finalize ()
 
void usage ()
 
bool getElevEnabledFlag () const
 
void setElevEnabledFlag (bool flag)
 Sets theElevEnabledFlag. More...
 
void setPluginLoaderEnabledFlag (bool flag)
 
void loadPlugins (const ossimFilename &plugin, const char *options=0)
 Can take a file or a directory. More...
 
void initializePlugins ()
 
void initializeDefaultFactories ()
 
void initializeElevation ()
 
void initializeLogFile ()
 Initializes log file from preferences keyword lookup of "ossim.log.file" if log file has not already been set and keyword is set in preferences. More...
 
ossimString version () const
 
ossimFilename appName () const
 

Static Public Member Functions

static ossimInitinstance ()
 

Protected Member Functions

 ossimInit ()
 protected default constructor. More...
 
 ossimInit (const ossimInit &obj)
 Hidden from use copy constructor. More...
 
void operator= (const ossimInit &rhs) const
 Hidden from use assignment operator. More...
 
void parseOptions (ossimArgumentParser &parser)
 
void parseNotifyOption (ossimArgumentParser &parser)
 
void parseEnvOptions (ossimArgumentParser &parser)
 
void parsePrefsOptions (ossimArgumentParser &parser)
 
void removeOption (int &argc, char **argv, int argToRemove)
 

Protected Attributes

bool theInitializedFlag
 
ossimFilename theAppName
 
ossimPreferencesthePreferences
 
bool theElevEnabledFlag
 
bool thePluginLoaderEnabledFlag
 

Static Protected Attributes

static ossimInittheInstance = 0
 

Detailed Description

Definition at line 29 of file ossimInit.h.

Constructor & Destructor Documentation

◆ ~ossimInit()

ossimInit::~ossimInit ( )

Definition at line 74 of file ossimInit.cpp.

References theInstance.

75 {
76  theInstance = 0;
77 }
static ossimInit * theInstance
Definition: ossimInit.h:146

◆ ossimInit() [1/2]

ossimInit::ossimInit ( )
protected

protected default constructor.

Definition at line 79 of file ossimInit.cpp.

Referenced by instance().

80  :
81  theInitializedFlag(false),
82  theAppName(),
83  thePreferences(0), // Delay instance() call until stream factory init.
84  theElevEnabledFlag(true),
86 {
87 }
bool theElevEnabledFlag
Definition: ossimInit.h:150
bool theInitializedFlag
Definition: ossimInit.h:147
bool thePluginLoaderEnabledFlag
Definition: ossimInit.h:151
ossimPreferences * thePreferences
Definition: ossimInit.h:149
ossimFilename theAppName
Definition: ossimInit.h:148

◆ ossimInit() [2/2]

ossimInit::ossimInit ( const ossimInit obj)
protected

Hidden from use copy constructor.

Definition at line 930 of file ossimInit.cpp.

931 : theInitializedFlag(false),
932  theAppName(),
934  theElevEnabledFlag(true),
936 {}
bool theElevEnabledFlag
Definition: ossimInit.h:150
bool theInitializedFlag
Definition: ossimInit.h:147
bool thePluginLoaderEnabledFlag
Definition: ossimInit.h:151
ossimPreferences * thePreferences
Definition: ossimInit.h:149
static ossimPreferences * instance()
ossimFilename theAppName
Definition: ossimInit.h:148

Member Function Documentation

◆ addOptions()

void ossimInit::addOptions ( ossimArgumentParser parser)

Definition at line 100 of file ossimInit.cpp.

References ossimApplicationUsage::addCommandLineOption(), and ossimArgumentParser::getApplicationUsage().

Referenced by main(), ossimHillshadeTool::setUsage(), ossimInfo::setUsage(), ossimChipProcTool::setUsage(), ossimTool::setUsage(), ossimPointCloudTool::usage(), ossimAutRegUtil::usage(), ossimImageUtil::usage(), and ossimChipperUtil::usage().

101 {
102  parser.getApplicationUsage()->addCommandLineOption("--env", "Specify an env variable to set. Any number of these can appear with format --env VARIABLE=VALUE");
103  parser.getApplicationUsage()->addCommandLineOption("-P", "specify a preference file to load");
104  parser.getApplicationUsage()->addCommandLineOption("-K", "specify individual keywords to add to the preferences keyword list: name=value");
105  parser.getApplicationUsage()->addCommandLineOption("-T", "specify the classes to trace, ex: ossimInit|ossimImage.* \nwill trace ossimInit and all ossimImage classes");
106  parser.getApplicationUsage()->addCommandLineOption("--disable-elev", "Will disable the elevation");
107  parser.getApplicationUsage()->addCommandLineOption("--disable-plugin", "Will disable the plugin loader");
108 
109  parser.getApplicationUsage()->addCommandLineOption("--ossim-logfile", "takes a logfile as an argument. All output messages are redirected to the specified log file. By default there is no log file and all messages are enabled.");
110  parser.getApplicationUsage()->addCommandLineOption("--disable-notify", "Takes an argument. Arguments are ALL, WARN, NOTICE, INFO, FATAL, DEBUG. If you want multiple disables then just do multiple --disable-notify on the command line. All argument are case insensitive. Default is all are enabled.");
111 }
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()

◆ appName()

ossimFilename ossimInit::appName ( ) const

Definition at line 925 of file ossimInit.cpp.

References theAppName.

926 {
927  return theAppName;
928 }
ossimFilename theAppName
Definition: ossimInit.h:148

◆ finalize()

void ossimInit::finalize ( )

Definition at line 261 of file ossimInit.cpp.

Referenced by main().

262 {
263 
264 }

◆ getElevEnabledFlag()

bool ossimInit::getElevEnabledFlag ( ) const
Returns
theElevEnabledFlag

Definition at line 290 of file ossimInit.cpp.

References theElevEnabledFlag.

291 {
292  return theElevEnabledFlag;
293 }
bool theElevEnabledFlag
Definition: ossimInit.h:150

◆ initialize() [1/3]

void ossimInit::initialize ( int &  argc,
char **  argv 
)

METHOD: initialize() This method shall be called from the application's main module with the command-line arguments. Every OSSIM application should have the following line early in the main module:

ossimInit::initialize(argc, argv);

OR

ossimInit::instance()->initialize(argc, argv);

The two forms are functionally identical. Pick the latter form if you like to type. The argv command line options are parsed and may be stripped. the value of argc will be adjusted to account for stripped options.


METHOD: ossimInit::initialize()

Method called from the OSSIM application main.

Definition at line 119 of file ossimInit.cpp.

References initialize(), theInitializedFlag, and theInstance.

Referenced by initialize(), and main().

120 {
121  static std::mutex m;
122  std::lock_guard<std::mutex> lock(m);
123  if( !theInitializedFlag )
124  {
125  ossimArgumentParser argumentParser(&argc, argv);
126  theInstance->initialize(argumentParser);
127  }
128 }
void initialize(int &argc, char **argv)
Definition: ossimInit.cpp:119
bool theInitializedFlag
Definition: ossimInit.h:147
static ossimInit * theInstance
Definition: ossimInit.h:146

◆ initialize() [2/3]

void ossimInit::initialize ( ossimArgumentParser parser)

Definition at line 130 of file ossimInit.cpp.

References theInitializedFlag.

131 {
132  static std::mutex m;
133  std::lock_guard<std::mutex> lock(m);
135  {
136  if (traceDebug())
137  {
139  << "DEBUG ossimInit::initialize(parser):"
140  << " Already initialized, returning......"
141  << std::endl;
142  }
143  return;
144  }
145  theInstance->parseEnvOptions(parser);
148 
150 
151  //Parse the command line:
152 
153  theInstance->parseOptions(parser);
154  // we will also support defining a trace pattern from an Environment
155  // variable. This will make JNI code easier to enable tracing
156  //
157  ossimString traceVariable = ossimEnvironmentUtility::instance()->getEnvironmentVariable("OSSIM_TRACE");
158 
159  if(!traceVariable.empty())
160  {
162  }
163 
165 
166  if ( theElevEnabledFlag )
167  {
169  }
170 
172 
174  {
176  }
177 
178  if (traceDebug())
179  {
181  << "ossim preferences file: "
183  << "\nVersion: " << version()
184  << "\nossimInit::initialize(parser): leaving..." << std::endl;
185  }
186 
187  theInitializedFlag = true;
188 }
void parseEnvOptions(ossimArgumentParser &parser)
Definition: ossimInit.cpp:474
static ossimTraceManager * instance()
void parseOptions(ossimArgumentParser &parser)
Definition: ossimInit.cpp:379
const ossimString & getApplicationName() const
bool theElevEnabledFlag
Definition: ossimInit.h:150
void initializePlugins()
Definition: ossimInit.cpp:561
bool theInitializedFlag
Definition: ossimInit.h:147
bool thePluginLoaderEnabledFlag
Definition: ossimInit.h:151
ossimApplicationUsage * getApplicationUsage()
void parseNotifyOption(ossimArgumentParser &parser)
Definition: ossimInit.cpp:438
void parsePrefsOptions(ossimArgumentParser &parser)
Definition: ossimInit.cpp:335
void initializeElevation()
Definition: ossimInit.cpp:825
void setTracePattern(const ossimString &pattern)
Sets "thePattern" to "pattern", then calls setTraceFlags(true).
ossimPreferences * thePreferences
Definition: ossimInit.h:149
void initializeDefaultFactories()
Definition: ossimInit.cpp:526
void initializeLogFile()
Initializes log file from preferences keyword lookup of "ossim.log.file" if log file has not already ...
Definition: ossimInit.cpp:884
static ossimEnvironmentUtility * instance()
ossimFilename theAppName
Definition: ossimInit.h:148
bool empty() const
Definition: ossimString.h:411
ossimString getEnvironmentVariable(const ossimString &variable) const
static ossimInit * theInstance
Definition: ossimInit.h:146
ossimString version() const
Definition: ossimInit.cpp:905
ossimFilename getPreferencesFilename() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ initialize() [3/3]

void ossimInit::initialize ( )

Definition at line 190 of file ossimInit.cpp.

References theInitializedFlag.

191 {
193  {
194  if (traceDebug())
195  {
197  << "DEBUG ossimInit::initialize(parser):"
198  << " Already initialized, returning......"
199  << std::endl;
200  }
201  return;
202  }
203 
204  int argc = 1;
205  char* argv[1];
206 
207  argv[0] = new char[1];
208  argv[0][0] = '\0';
209  initialize(argc, argv);
210  delete [] argv[0];
211 
212 #if 0
213  static std::mutex m;
214  std::lock_guard<std::mutex> lock(m);
216  {
217  if (traceDebug())
218  {
220  << "DEBUG ossimInit::initialize(): Already initialized, returning......" << std::endl;
221  }
222  return;
223  }
224 
225  theInstance->theAppName = "";
228 
229  if ( theElevEnabledFlag )
230  {
232  }
233 
235 
236  //---
237  // To do:
238  // We need a mechanism to register factories to the "front" or the
239  // "back" of factory list so that plugins can override things. For
240  // now we will initialize the plugins last...
241  //---
243  {
245  }
246 
247  if (traceDebug())
248  {
250  << "ossim preferences file: "
252  << "\nVersion: " << version()
253  << "\nossimInit::initialize() leaving..."
254  << std::endl;
255  }
256 
257  theInitializedFlag = true;
258 #endif
259 }
bool theElevEnabledFlag
Definition: ossimInit.h:150
void initializePlugins()
Definition: ossimInit.cpp:561
bool theInitializedFlag
Definition: ossimInit.h:147
bool thePluginLoaderEnabledFlag
Definition: ossimInit.h:151
void initializeElevation()
Definition: ossimInit.cpp:825
ossimPreferences * thePreferences
Definition: ossimInit.h:149
void initializeDefaultFactories()
Definition: ossimInit.cpp:526
static ossimPreferences * instance()
void initializeLogFile()
Initializes log file from preferences keyword lookup of "ossim.log.file" if log file has not already ...
Definition: ossimInit.cpp:884
ossimFilename theAppName
Definition: ossimInit.h:148
void initialize()
Definition: ossimInit.cpp:190
static ossimInit * theInstance
Definition: ossimInit.h:146
ossimString version() const
Definition: ossimInit.cpp:905
ossimFilename getPreferencesFilename() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ initializeDefaultFactories()

void ossimInit::initializeDefaultFactories ( )

Definition at line 526 of file ossimInit.cpp.

References ossimFactoryListInterface< T, NativeType >::addFactory(), ossimCodecFactoryRegistry::instance(), ossimImageSourceFactoryRegistry::instance(), ossim::ImageHandlerStateFactory::instance(), ossimBaseObjectFactory::instance(), ossimProjectionViewControllerFactory::instance(), ossimImageMetaDataWriterRegistry::instance(), ossimFontFactoryRegistry::instance(), ossimImageGeometryRegistry::instance(), ossimObjectFactoryRegistry::instance(), ossim::ImageHandlerStateRegistry::instance(), ossim2dTo2dTransformRegistry::instance(), ossimProjectionFactoryRegistry::instance(), ossimImageWriterFactoryRegistry::instance(), ossimOverviewBuilderFactory::instance(), ossimDatumFactoryRegistry::instance(), ossimOverviewBuilderFactoryRegistry::instance(), ossimImageHandlerRegistry::instance(), ossim::StreamFactoryRegistry::instance(), and ossimFactoryListInterface< T, NativeType >::registerFactory().

527 {
531 
532  //---
533  // Because of how the imagehandlers work off a magic number make sure
534  // we place the writer first if we don't then the imagehandler will
535  // be false and will then try to open the filename and go through a
536  // magic number and if the file already
537  // existed it will open and create a handler instead of a writer.
538  //---
546  // Initialize the overview factories.
548  registerFactory(ossimOverviewBuilderFactory::instance(), true);
549 
551 
552  // initialize. projection factory.
554 
555  // add the view controllers
557 
559 }
static ossimCodecFactoryRegistry * instance()
static ossimImageGeometryRegistry * instance()
static std::shared_ptr< ossim::ImageHandlerStateFactory > instance()
static ossimDatumFactoryRegistry * instance()
instance method
static ossimBaseObjectFactory * instance()
static ossimImageWriterFactoryRegistry * instance()
static ossimOverviewBuilderFactory * instance()
static instance method.
static ossimObjectFactoryRegistry * instance()
static StreamFactoryRegistry * instance()
void addFactory(T *factory)
This is for backward compatability and calls registerFactory for simple adds.
void registerFactory(T *factory, bool pushToFrontFlag=false)
Will register a factory to the factory list.
static ossimProjectionFactoryRegistry * instance()
static ossimOverviewBuilderFactoryRegistry * instance()
instance method for access to theInstance pointer.
static ossimProjectionViewControllerFactory * instance()
static ossimFontFactoryRegistry * instance()
static std::shared_ptr< ImageHandlerStateRegistry > instance()
static ossim2dTo2dTransformRegistry * instance()
static ossimImageHandlerRegistry * instance()
static ossimImageSourceFactoryRegistry * instance()
static ossimImageMetaDataWriterRegistry * instance()

◆ initializeElevation()

void ossimInit::initializeElevation ( )

Definition at line 825 of file ossimInit.cpp.

826 {
827  if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)
828  << "DEBUG ossimInit::initializeElevation(): Entered..." << std::endl;
829 
831 
832 #if 0 /* All autoload stuff disabled. drb 20170408 */
833  ossimFilename appPath = theAppName.path();
834 
835  // look for bundled elevation and geoids
836  {
837  ossimFilename geoid = appPath.dirCat("geoids");
838  geoid = geoid.dirCat("geoid1996");
839  geoid = geoid.dirCat("egm96.grd");
840  if(geoid.exists())
841  {
842  ossimGeoid* geoidPtr = new ossimGeoidEgm96(geoid);
843 
844  if (geoidPtr->getErrorStatus() == ossimErrorCodes::OSSIM_OK)
845  {
847  }
848 
849  }
850  }
851 #endif
852 
854 
855  //---
856  // Auto load removed to avoid un-wanted directory scanning.
857  // Use ossim preferences. drb - 28 March 2016.
858  //---
859 #if 0
860  ossimFilename elevation = appPath.dirCat("elevation");
861  if(elevation.exists())
862  {
864  }
865 #endif
866 
867  // lets do backward compatability here
868  //
869  ossimString regExpression = ossimString("^(") + "elevation_source[0-9]+.)";
870  vector<ossimString> keys =
871  KWL.getSubstringKeyList( regExpression );
872  if(!keys.empty())
873  {
874  ossimNotify(ossimNotifyLevel_WARN) << "Please specify elevation_source keywords with the new prefix\n"
875  << "of elevation_manager.elevation_source....\n";
876  thePreferences->preferencesKWL().addPrefixToKeysThatMatch("elevation_manager.", regExpression);
877  }
878  ossimElevManager::instance()->loadState(KWL, "elevation_manager.");
879 
880  if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)
881  << "DEBUG ossimInit::initializeElevation(): leaving..." << std::endl;
882 }
const ossimKeywordlist & preferencesKWL() const
void addPrefixToKeysThatMatch(const ossimString &prefix, const ossimString &regularExpression)
Represents serializable keyword/value map.
static const ossimErrorCode OSSIM_OK
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
ossimPreferences * thePreferences
Definition: ossimInit.h:149
bool exists() const
static ossimGeoidManager * instance()
Implements singelton pattern:
bool loadElevationPath(const ossimFilename &path, bool set_as_first=false)
Adds a new elevation file (or multiple files if path is a directory) to the collection.
virtual void addGeoid(ossimRefPtr< ossimGeoid > geoid, bool toFrontFlag=false)
Permits adding additional geoids to the list:
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
virtual ossimErrorCode getErrorStatus() const
ossimFilename theAppName
Definition: ossimInit.h:148
ossimFilename dirCat(const ossimFilename &file) const
ossimFilename path() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ initializeLogFile()

void ossimInit::initializeLogFile ( )

Initializes log file from preferences keyword lookup of "ossim.log.file" if log file has not already been set and keyword is set in preferences.

So this should be called after parse options as the –ossim-logfile should override any preferences setting.

Definition at line 884 of file ossimInit.cpp.

References ossimKeywordlist::find(), ossimGetLogFilename(), ossimSetLogFilename(), ossimPreferences::preferencesKWL(), ossimString::size(), and thePreferences.

885 {
886  //---
887  // Do not set if already as --ossim-logfile take precidence over preferences
888  // file.
889  //---
890  ossimFilename logFile;
891  ossimGetLogFilename(logFile);
892 
893  if ( (logFile.size() == 0) && thePreferences )
894  {
895  const char* lookup =
896  thePreferences->preferencesKWL().find("ossim.log.file");
897  if (lookup)
898  {
899  logFile = lookup;
900  ossimSetLogFilename(logFile);
901  }
902  }
903 }
const ossimKeywordlist & preferencesKWL() const
OSSIMDLLEXPORT void ossimGetLogFilename(ossimFilename &logFile)
Returns the log filename if set.
const char * find(const char *key) const
ossimPreferences * thePreferences
Definition: ossimInit.h:149
std::string::size_type size() const
Definition: ossimString.h:405
OSSIMDLLEXPORT void ossimSetLogFilename(const ossimFilename &filename)

◆ initializePlugins()

void ossimInit::initializePlugins ( )

Definition at line 561 of file ossimInit.cpp.

References ossimString::c_str(), ossimFilename::dirCat(), ossimString::empty(), ossimFilename::exists(), ossimKeywordlist::find(), ossimKeywordlist::findKey(), ossimKeywordlist::getNumberOfSubstringKeys(), ossimKeywordlist::getSubstringKeyList(), ossimEnvironmentUtility::getUserOssimPluginDir(), ossimEnvironmentUtility::instance(), ossimSharedPluginRegistry::instance(), ossimPreferences::instance(), loadPlugins(), ossimDirectory::OSSIM_DIR_FILES, ossimFilename::path(), ossimPreferences::preferencesKWL(), ossimSharedPluginRegistry::registerPlugin(), ossimString::size(), ossimString::string(), theAppName, thePreferences, ossimString::toBool(), ossimString::toInt(), and ossimString::toString().

562 {
563 
564 #if 0
565  // Note: Removed "autoload" code. Commented out below.
566 
568 
569  //---
570  // Look for plugins in the form of:
571  // plugin0.file: $(OSSIM_INSTALL_PREFIX)/lib64/ossim/plugins/libossim_png_plugin.so
572  // plugin0.option: front
573  //---
574  ossimString regExp = ossimString("^(") + "plugin[0-9]+.file)";
575  ossim_uint32 numberOfPlugins = KWL.getNumberOfSubstringKeys( regExp );
576  if ( numberOfPlugins )
577  {
578  const ossim_uint32 MAX_INDEX = numberOfPlugins + 1000; // for skipage...
579  ossim_uint32 index = 0;
580  ossim_uint32 processedIndexes = 0;
581  const std::string PREFIX_BASE = "plugin";
582  const std::string DOT = ".";
583  const std::string FILE_KEY = "file";
584  const std::string OPTIONS_KEY = "options";
585 
586  ossimString prefix;
587  ossimFilename pluginFile;
588  ossimString pluginOptions;
589 
590  // Loop to load plugins in order. Note allows for skipage.
591  while ( processedIndexes < MAX_INDEX )
592  {
593  prefix = PREFIX_BASE + ossimString::toString(index).string() + DOT;
594  pluginFile = KWL.findKey( prefix, FILE_KEY );
595  if ( pluginFile.size() )
596  {
597  if ( pluginFile.exists() )
598  {
599  // Found plugin, look for options:
600  pluginOptions = KWL.findKey( prefix, OPTIONS_KEY );
601 
602  ossimSharedPluginRegistry::instance()->registerPlugin(pluginFile, pluginOptions);
603  }
604  ++processedIndexes;
605  }
606  if ( processedIndexes == numberOfPlugins )
607  {
608  break;
609  }
610  ++index;
611  }
612  }
613 
614  //---
615  // Look for plugins in the form of:
616  // plugin.file0: $(OSSIM_INSTALL_PREFIX)/lib64/ossim/plugins/libossim_png_plugin.so
617  //---
618  regExp = ossimString("^(") + "plugin.file[0-9]+)";
619  numberOfPlugins = KWL.getNumberOfSubstringKeys( regExp );
620  if ( numberOfPlugins )
621  {
622  const ossim_uint32 MAX_INDEX = numberOfPlugins + 1000; // for skipage...
623  ossim_uint32 index = 0;
624  ossim_uint32 processedIndexes = 0;
625  const std::string PREFIX_BASE = "plugin.file";
626  std::string fileKey;
627 
628  ossimString prefix;
629  ossimFilename pluginFile;
630  ossimString pluginOptions = ""; // No options:
631 
632  // Loop to load plugins in order. Note allows for skipage.
633  while ( processedIndexes < MAX_INDEX )
634  {
635  fileKey = PREFIX_BASE + ossimString::toString(index).string();
636  pluginFile = KWL.findKey( fileKey );
637  if ( pluginFile.size() )
638  {
639  if ( pluginFile.exists() )
640  {
641  ossimSharedPluginRegistry::instance()->registerPlugin(pluginFile, pluginOptions);
642  }
643  ++processedIndexes;
644  }
645 
646  if ( processedIndexes == numberOfPlugins )
647  {
648  break;
649  }
650  ++index;
651  }
652  }
653 
654 #else /* Old code that auto loads plugins. */
655  #if 0
656  ossimString regExpressionDir = ossimString("^(") + "plugin.dir[0-9]+)";
657  ossimString regExpressionFile = ossimString("^(") + "plugin.file[0-9]+)";
658 
660 
661  vector<ossimString> keys = kwl.getSubstringKeyList( regExpressionDir );
662 
663  ossim_uint32 numberOfDirs = (ossim_uint32)keys.size();
664  ossim_uint32 offset = (ossim_uint32)ossimString("plugin.dir").size();
665  int idx = 0;
666 
667  std::vector<int> numberList(numberOfDirs);
668 
669  // register user plugins first
671  loadPlugins(userPluginDir);
672 
673  if(numberList.size()>0)
674  {
675  for(idx = 0; idx < (int)numberList.size();++idx)
676  {
677  ossimString numberStr(keys[idx].begin() + offset,
678  keys[idx].end());
679  numberList[idx] = numberStr.toInt();
680  }
681 
682  std::sort(numberList.begin(), numberList.end());
683  for(idx=0;idx < (int)numberList.size();++idx)
684  {
685  ossimString newPrefix = "plugin.dir";
686  newPrefix += ossimString::toString(numberList[idx]);
687  const char* directory = kwl.find(newPrefix.c_str());
688 
689  if(directory)
690  {
691  loadPlugins(ossimFilename(directory));
692  }
693  }
694  }
695  keys = kwl.getSubstringKeyList( regExpressionFile );
696 
697  ossim_uint32 numberOfFiles = (ossim_uint32)keys.size();
698  offset = (ossim_uint32)ossimString("plugin.file").size();
699  numberList.resize(numberOfFiles);
700  if(numberList.size()>0)
701  {
702  for(idx = 0; idx < (int)numberList.size();++idx)
703  {
704  ossimString numberStr(keys[idx].begin() + offset,
705  keys[idx].end());
706  numberList[idx] = numberStr.toInt();
707  }
708 
709  std::sort(numberList.begin(), numberList.end());
710  for(idx=0;idx < (int)numberList.size();++idx)
711  {
712  ossimString newPrefix="plugin.file";
713  newPrefix += ossimString::toString(numberList[idx]);
714  const char* file = kwl.find(newPrefix.c_str());
715 
716  if(file&&ossimFilename(file).exists())
717  {
718  loadPlugins(file);
719 // ossimSharedPluginRegistry::instance()->registerPlugin(file);
720  }
721  }
722  }
723  #endif
724  // now check new plugin loading that supports passing options to the plugins
725  //
727  ossimString regExpressionFile = ossimString("^(") + "plugin[0-9]+\\.file)";
728  vector<ossimString> keys = kwl.getSubstringKeyList( regExpressionFile );
729 
730  ossim_uint32 numberOfFiles = (ossim_uint32)keys.size();
731  ossim_uint32 offset = (ossim_uint32)ossimString("plugin").size();
732  std::vector<int> numberList(numberOfFiles);
733 
734  if(numberList.size()>0)
735  {
736  ossim_uint32 idx = 0;
737  for(idx = 0; idx < numberList.size();++idx)
738  {
739  ossimString numberStr(keys[idx].begin() + offset,
740  keys[idx].end());
741  numberList[idx] = numberStr.toInt();
742  }
743  std::sort(numberList.begin(), numberList.end());
744  ossimFilename pluginFile;
745  ossimString options;
746  for(std::vector<ossim_int32>::const_iterator iter = numberList.begin();
747  iter != numberList.end();++iter)
748  {
749  ossimString newPrefix = ossimString("plugin")+ossimString::toString(*iter) + ".";
750 
751  pluginFile = kwl.find((newPrefix+"file").c_str());
752  options = kwl.find((newPrefix+"options").c_str());
753  if(pluginFile.exists())
754  {
755  ossimSharedPluginRegistry::instance()->registerPlugin(pluginFile, options);
756  }
757  }
758  }
759 
760  regExpressionFile = ossimString("^(") + "plugin.file[0-9]+)";
761  keys = kwl.getSubstringKeyList( regExpressionFile );
762 
763  numberOfFiles = (ossim_uint32)keys.size();
764  offset = (ossim_uint32)ossimString("plugin.file").size();
765  numberList.resize(numberOfFiles);
766 
767  if(numberList.size()>0)
768  {
769  ossim_uint32 idx = 0;
770  for(idx = 0; idx < numberList.size();++idx)
771  {
772  ossimString numberStr(keys[idx].begin() + offset,
773  keys[idx].end());
774  numberList[idx] = numberStr.toInt();
775  }
776  std::sort(numberList.begin(), numberList.end());
777  ossimFilename pluginFile;
778  ossimString options;
779  for(std::vector<ossim_int32>::const_iterator iter = numberList.begin();
780  iter != numberList.end();++iter)
781  {
782  ossimString newPrefix = ossimString("plugin.file")+ossimString::toString(*iter);
783 
784  pluginFile = kwl.find(newPrefix.c_str());
785  if(pluginFile.exists())
786  {
787  ossimSharedPluginRegistry::instance()->registerPlugin(pluginFile, options);
788  }
789  }
790  }
791 
792 
793 
794  ossimString auto_load_plugins(ossimPreferences::instance()->findPreference("ossim_init.auto_load_plugins"));
795 
796  if(auto_load_plugins.empty()) auto_load_plugins = "false";
797  // now load any plugins not found in the keywordlist
798  //
799  // check for plugins in the current directory
800  // and load them
801  if(auto_load_plugins.toBool())
802  {
803  ossimFilename ossimpluginsDir = ossimFilename(theAppName).dirCat("ossimplugins");
804  ossimDirectory currentDir(theAppName.path());
805 
806  if(ossimpluginsDir.exists())
807  {
808  currentDir = ossimpluginsDir;
809  }
810  std::vector<ossimFilename> result;
811  currentDir.findAllFilesThatMatch(result, "ossim.*plugin.*", ossimDirectory::OSSIM_DIR_FILES);
812 
813  if(result.size())
814  {
815  ossim_uint32 idx = 0;
816  for(idx = 0; idx < result.size(); ++idx)
817  {
819  }
820  }
821  }
822 #endif
823 }
const ossimKeywordlist & preferencesKWL() const
ossim_uint32 getNumberOfSubstringKeys(const ossimString &regularExpression) const
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
const char * find(const char *key) const
void loadPlugins(const ossimFilename &plugin, const char *options=0)
Can take a file or a directory.
Definition: ossimInit.cpp:305
static ossimString toString(bool aValue)
Numeric to string methods.
ossimFilename getUserOssimPluginDir() const
ossimPreferences * thePreferences
Definition: ossimInit.h:149
static ossimSharedPluginRegistry * instance()
bool exists() const
std::string::size_type size() const
Definition: ossimString.h:405
unsigned int ossim_uint32
static ossimPreferences * instance()
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
static ossimEnvironmentUtility * instance()
ossimFilename theAppName
Definition: ossimInit.h:148
ossimFilename dirCat(const ossimFilename &file) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool registerPlugin(const ossimFilename &filename, const ossimString &options="")
ossimFilename path() const
const std::string & string() const
Definition: ossimString.h:414

◆ instance()

ossimInit * ossimInit::instance ( )
static

Returns the static instance of an ossimInit object. This is of no use until non-static methods are implemented.

Definition at line 89 of file ossimInit.cpp.

References ossimInit(), and theInstance.

Referenced by main(), ossimHillshadeTool::setUsage(), ossimInfo::setUsage(), ossimChipProcTool::setUsage(), ossimTool::setUsage(), ossimPointCloudTool::usage(), ossimAutRegUtil::usage(), ossimImageUtil::usage(), and ossimChipperUtil::usage().

90 {
91  static std::mutex m;
92  std::lock_guard<std::mutex> lock(m);
93  if (!theInstance)
94  {
95  theInstance = new ossimInit();
96  }
97  return theInstance;
98 }
ossimInit()
protected default constructor.
Definition: ossimInit.cpp:79
static ossimInit * theInstance
Definition: ossimInit.h:146

◆ loadPlugins()

void ossimInit::loadPlugins ( const ossimFilename plugin,
const char *  options = 0 
)

Can take a file or a directory.

If a directory is givien then it will check all files in the directory and add each file that is detected to be a valid plugin.

Parameters
pluginIs the filename of the plugin to load
optionsIs a keywordlist of plugin specific options

Definition at line 305 of file ossimInit.cpp.

References ossimFilename::exists(), ossimDirectory::getFirst(), ossimDirectory::getNext(), ossimSharedPluginRegistry::instance(), ossimFilename::isDir(), ossimDirectory::open(), ossimDirectory::OSSIM_DIR_FILES, ossimSharedPluginRegistry::registerPlugin(), and thePluginLoaderEnabledFlag.

Referenced by initializePlugins().

306 {
307  if(!thePluginLoaderEnabledFlag) return;
308 
309  if(plugin.exists())
310  {
311  if(plugin.isDir())
312  {
313  ossimDirectory dir;
314  if(dir.open(plugin))
315  {
316  ossimFilename file;
317 
319  {
320  do
321  {
323  }
324  while(dir.getNext(file));
325  }
326  }
327  }
328  else
329  {
331  }
332  }
333 }
bool getFirst(ossimFilename &filename, int flags=OSSIM_DIR_DEFAULT)
bool thePluginLoaderEnabledFlag
Definition: ossimInit.h:151
bool isDir() const
bool getNext(ossimFilename &filename) const
static ossimSharedPluginRegistry * instance()
bool exists() const
bool open(const ossimFilename &dir)
bool registerPlugin(const ossimFilename &filename, const ossimString &options="")

◆ operator=()

void ossimInit::operator= ( const ossimInit rhs) const
protected

Hidden from use assignment operator.

Definition at line 938 of file ossimInit.cpp.

939 {}

◆ parseEnvOptions()

void ossimInit::parseEnvOptions ( ossimArgumentParser parser)
protected

Definition at line 474 of file ossimInit.cpp.

References ossimString::after(), ossimString::before(), ossimString::c_str(), ossimString::contains(), ossimEnvironmentUtility::instance(), ossimArgumentParser::read(), and ossimEnvironmentUtility::setEnvironmentVariable().

475 {
476  std::string tempString;
477  ossimArgumentParser::ossimParameter stringParameter(tempString);
478  while(parser.read("--env", stringParameter))
479  {
480  ossimString option = tempString;
481  if (option.contains("=") )
482  {
483  ossimString delimiter = "=";
484  ossimString key (option.before(delimiter));
485  ossimString value = option.after(delimiter);
486  ossimEnvironmentUtility::instance()->setEnvironmentVariable(key.c_str(), value.c_str());
487 
488  }
489  else
490  {
491  ossimString key (option);
493  }
494  }
495 }
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
bool contains(char aChar) const
Definition: ossimString.h:58
static ossimEnvironmentUtility * instance()
void setEnvironmentVariable(const char *variable, const char *value) const
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.

◆ parseNotifyOption()

void ossimInit::parseNotifyOption ( ossimArgumentParser parser)
protected

Definition at line 438 of file ossimInit.cpp.

References ossimString::downcase(), ossimDisableNotify(), ossimNotifyFlags_ALL, ossimNotifyFlags_DEBUG, ossimNotifyFlags_FATAL, ossimNotifyFlags_INFO, ossimNotifyFlags_NOTICE, ossimNotifyFlags_WARN, and ossimArgumentParser::read().

439 {
440  std::string tempString;
441  ossimArgumentParser::ossimParameter stringParameter(tempString);
442  while(parser.read("--disable-notify", stringParameter))
443  {
444  ossimString tempDownCase = tempString;
445  tempDownCase = tempDownCase.downcase();
446 
447  if(tempDownCase == "warn")
448  {
450  }
451  else if(tempDownCase == "fatal")
452  {
454  }
455  else if(tempDownCase == "debug")
456  {
458  }
459  else if(tempDownCase == "info")
460  {
462  }
463  else if(tempDownCase == "notice")
464  {
466  }
467  else if(tempDownCase == "all")
468  {
470  }
471  }
472 }
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
OSSIMDLLEXPORT void ossimDisableNotify(ossimNotifyFlags notifyLevel=ossimNotifyFlags_ALL)
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48

◆ parseOptions()

void ossimInit::parseOptions ( ossimArgumentParser parser)
protected

Definition at line 379 of file ossimInit.cpp.

380 {
381  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
382  << "DEBUG ossimInit::parseOptions: entering..." << std::endl;
383 
384  std::string tempString;
385  ossimArgumentParser::ossimParameter stringParameter(tempString);
386 
387  tempString = "";
388 
389  while(parser.read("-T", stringParameter))
390  {
392  }
393 
394  while(parser.read("--ossim-logfile", stringParameter))
395  {
396  ossimSetLogFilename(ossimFilename(tempString));
397  }
398  while(parser.read("--disable-notify", stringParameter))
399  {
400  ossimString tempDownCase = tempString;
401  tempDownCase = tempDownCase.downcase();
402 
403  if(tempDownCase == "warn")
404  {
406  }
407  else if(tempDownCase == "fatal")
408  {
410  }
411  else if(tempDownCase == "debug")
412  {
414  }
415  else if(tempDownCase == "info")
416  {
418  }
419  else if(tempDownCase == "notice")
420  {
422  }
423  else if(tempDownCase == "all")
424  {
426  }
427  }
428  if(parser.read("--disable-elev"))
429  {
430  theElevEnabledFlag = false;
431  }
432  if(parser.read("--disable-plugin"))
433  {
435  }
436 }
static ossimTraceManager * instance()
bool theElevEnabledFlag
Definition: ossimInit.h:150
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
OSSIMDLLEXPORT void ossimDisableNotify(ossimNotifyFlags notifyLevel=ossimNotifyFlags_ALL)
bool thePluginLoaderEnabledFlag
Definition: ossimInit.h:151
void setTracePattern(const ossimString &pattern)
Sets "thePattern" to "pattern", then calls setTraceFlags(true).
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
OSSIMDLLEXPORT void ossimSetLogFilename(const ossimFilename &filename)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ parsePrefsOptions()

void ossimInit::parsePrefsOptions ( ossimArgumentParser parser)
protected

Definition at line 335 of file ossimInit.cpp.

336 {
337  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
338  << "DEBUG ossimInit::parseOptions: entering..." << std::endl;
339 
340 
341  std::string tempString;
342  ossimArgumentParser::ossimParameter stringParameter(tempString);
343 
344  tempString = "";
345  ossimString prefsFile = ossimEnvironmentUtility::instance()->getEnvironmentVariable("OSSIM_PREFS_FILE");
347  if(!prefsFile.empty())
348  {
349  thePreferences->loadPreferences();// Use the default load
350  }
351  tempString = "";
352  // override ENV with passed in variable
353  while(parser.read("-P", stringParameter));
354 
355  if(tempString != "")
356  {
358  }
359  tempString = "";
360  while(parser.read("-K", stringParameter))
361  {
362  ossimString option = tempString;
363  if (option.contains("=") )
364  {
365  ossimString delimiter = "=";
366  ossimString key (option.before(delimiter));
367  ossimString value = option.after(delimiter);
368  thePreferences->addPreference(key.c_str(), value.c_str());
369  }
370  else
371  {
372  ossimString key (option);
373  thePreferences->addPreference(key, "");
374  }
375  }
376 
377 }
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
bool contains(char aChar) const
Definition: ossimString.h:58
ossimPreferences * thePreferences
Definition: ossimInit.h:149
static ossimPreferences * instance()
void addPreference(const char *key, const char *value)
static ossimEnvironmentUtility * instance()
bool empty() const
Definition: ossimString.h:411
ossimString getEnvironmentVariable(const ossimString &variable) const
static ossimInit * theInstance
Definition: ossimInit.h:146
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ removeOption()

void ossimInit::removeOption ( int &  argc,
char **  argv,
int  argToRemove 
)
protected

METHOD: removeOptions() Utility for stripping from argv all characters associated with a particular option:


METHOD: ossimInit::removeOption()

Removes all characters associated with the indicated option from the command line string.

Definition at line 503 of file ossimInit.cpp.

506 {
507  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
508  << "DEBUG ossimInit::removeOption(argc, argv, argToRemove): entering..."
509  << std::endl;
510 
511  // Shift the args up by one position, overwriting the arg being removed:
512  for (int i=argToRemove+1; i<argc; i++)
513  {
514  argv[i - 1] = argv[i];
515  }
516 
517  argc--;
518  argv[argc] = 0;
519 
520  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
521  << "DEBUG ossimInit::removeOption(argc, argv, argToRemove): leaving..."
522  << std::endl;
523  return;
524 }
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ setElevEnabledFlag()

void ossimInit::setElevEnabledFlag ( bool  flag)

Sets theElevEnabledFlag.

Parameters
flagIf true ossimElevManager will be initialized. Set to false to NOT initialize the ossimElevManager from preferences. Default in class is true.

Definition at line 295 of file ossimInit.cpp.

References theElevEnabledFlag.

296 {
297  theElevEnabledFlag = flag;
298 }
bool theElevEnabledFlag
Definition: ossimInit.h:150

◆ setPluginLoaderEnabledFlag()

void ossimInit::setPluginLoaderEnabledFlag ( bool  flag)

Definition at line 300 of file ossimInit.cpp.

References thePluginLoaderEnabledFlag.

301 {
303 }
bool thePluginLoaderEnabledFlag
Definition: ossimInit.h:151

◆ usage()

void ossimInit::usage ( )

METHOD: usage() Prints to stdout the list of command line options that this object parses


Prints to stdout the list of command line options that this object parses.

Definition at line 268 of file ossimInit.cpp.

References ossimNotify(), and ossimNotifyLevel_INFO.

269 {
271  << "INFORMATION ossimInit::usage():\n"
272  << "Additional command-line options available are as follows: "
273  << "\n"
274  << "\n -P<pref_filename> -- Allows the user to override the loading "
275  << "\n of the default preferences with their own pref file."
276  << "\n"
277  << "\n -K<keyword>[=<value>] -- Allows the user to specify additional"
278  << "\n keyword/value pairs that are added onto the preferences "
279  << "\n previously loaded. Keywords specified here override those in"
280  << "\n the preferences file."
281  << "\n"
282  << "\n -T<trace_tag> -- Lets user turn on specific trace flags."
283  << "\n"
284  << "\n -S<session_filename> -- Allows user to specify a session file"
285  << "\n to load."
286  << std::endl;
287  return;
288 }
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ version()

ossimString ossimInit::version ( ) const
Returns
The version in the form of: "version major.minor.release (yyyymmdd)" where yyyymmdd is the build date.

e.g. "version 1.7.0 (20071003)"

Definition at line 905 of file ossimInit.cpp.

References OSSIM_BUILD_DATE, and OSSIM_VERSION.

906 {
907  ossimString versionString;
908 #ifdef OSSIM_VERSION
909  versionString += OSSIM_VERSION;
910 #else
911  versionString += "Version ?.?.?";
912 #endif
913 
914  versionString += " ";
915 
916 #ifdef OSSIM_BUILD_DATE
917  versionString += OSSIM_BUILD_DATE;
918 #else
919  versionString += "(yyyymmdd)";
920 #endif
921 
922  return versionString;
923 }
#define OSSIM_VERSION
Definition: ossimVersion.h:4
#define OSSIM_BUILD_DATE
Definition: ossimVersion.h:12

Member Data Documentation

◆ theAppName

ossimFilename ossimInit::theAppName
protected

Definition at line 148 of file ossimInit.h.

Referenced by appName(), and initializePlugins().

◆ theElevEnabledFlag

bool ossimInit::theElevEnabledFlag
protected

Definition at line 150 of file ossimInit.h.

Referenced by getElevEnabledFlag(), and setElevEnabledFlag().

◆ theInitializedFlag

bool ossimInit::theInitializedFlag
protected

Definition at line 147 of file ossimInit.h.

Referenced by initialize().

◆ theInstance

ossimInit * ossimInit::theInstance = 0
staticprotected

Definition at line 146 of file ossimInit.h.

Referenced by initialize(), instance(), and ~ossimInit().

◆ thePluginLoaderEnabledFlag

bool ossimInit::thePluginLoaderEnabledFlag
protected

Definition at line 151 of file ossimInit.h.

Referenced by loadPlugins(), and setPluginLoaderEnabledFlag().

◆ thePreferences

ossimPreferences* ossimInit::thePreferences
protected

Definition at line 149 of file ossimInit.h.

Referenced by initializeLogFile(), and initializePlugins().


The documentation for this class was generated from the following files: