OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Private Attributes | List of all members
ossimDirectory Class Reference

#include <ossimDirectory.h>

Public Types

enum  {
  OSSIM_DIR_FILES = 0x0001, OSSIM_DIR_DIRS = 0x0002, OSSIM_DIR_HIDDEN = 0x0004, OSSIM_DIR_DOTDOT = 0x0008,
  OSSIM_DIR_DEFAULT = OSSIM_DIR_FILES | OSSIM_DIR_DIRS | OSSIM_DIR_HIDDEN
}
 

Public Member Functions

 ossimDirectory ()
 
 ossimDirectory (const ossimFilename &dir)
 
 ~ossimDirectory ()
 
bool open (const ossimFilename &dir)
 
bool isOpened () const
 
bool getFirst (ossimFilename &filename, int flags=OSSIM_DIR_DEFAULT)
 
bool getNext (ossimFilename &filename) const
 
void findAllFilesThatMatch (std::vector< ossimFilename > &result, const ossimString &regularExpressionPattern, int flags=OSSIM_DIR_DEFAULT)
 
bool findCaseInsensitiveEquivalents (const ossimFilename &filename, std::vector< ossimFilename > &result, bool bExcludeExactMatch=true)
 

Private Attributes

ossimDirectoryDatatheData
 

Detailed Description

Definition at line 23 of file ossimDirectory.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

These flags define what kind of filenames is included in the list of files enumerated by GetFirst/GetNext.

Enumerator
OSSIM_DIR_FILES 
OSSIM_DIR_DIRS 
OSSIM_DIR_HIDDEN 
OSSIM_DIR_DOTDOT 
OSSIM_DIR_DEFAULT 

Definition at line 31 of file ossimDirectory.h.

32  {
33  OSSIM_DIR_FILES = 0x0001, // include files
34  OSSIM_DIR_DIRS = 0x0002, // include directories
35  OSSIM_DIR_HIDDEN = 0x0004, // include hidden files
36  OSSIM_DIR_DOTDOT = 0x0008, // include '.' and '..'
37 
38  // by default, enumerate everything except '.' and '..'
40  };

Constructor & Destructor Documentation

◆ ossimDirectory() [1/2]

ossimDirectory::ossimDirectory ( )

Definition at line 188 of file ossimDirectory.cpp.

189  :
190  theData(NULL)
191 {}
ossimDirectoryData * theData

◆ ossimDirectory() [2/2]

ossimDirectory::ossimDirectory ( const ossimFilename dir)

Definition at line 193 of file ossimDirectory.cpp.

References open(), and theData.

194 {
195  theData = NULL;
196  open(dirname);
197 }
bool open(const ossimFilename &dir)
ossimDirectoryData * theData

◆ ~ossimDirectory()

ossimDirectory::~ossimDirectory ( )

Definition at line 216 of file ossimDirectory.cpp.

References theData.

217 {
218  delete theData;
219 }
ossimDirectoryData * theData

Member Function Documentation

◆ findAllFilesThatMatch()

void ossimDirectory::findAllFilesThatMatch ( std::vector< ossimFilename > &  result,
const ossimString regularExpressionPattern,
int  flags = OSSIM_DIR_DEFAULT 
)

Definition at line 257 of file ossimDirectory.cpp.

References ossimString::c_str(), ossimRegExp::compile(), ossimFilename::file(), ossimRegExp::find(), getFirst(), getNext(), and ossimString::push_back().

Referenced by ossimLandsatTopoCorrectionFilter::findLandsatHeader(), ossimplugins::ossimTerraSarModel::findTSXLeader(), ossim::JsonConfig::JsonConfig(), and ossimFilename::wildcardRemove().

260 {
261  ossimFilename filename;
262  ossimRegExp regExpr;
263  regExpr.compile(regularExpressionPattern.c_str());
264  if(getFirst(filename, flags))
265  {
266  do
267  {
268  ossimString fileOnly = filename.file();
269  if(regExpr.find(fileOnly.c_str()))
270  {
271  result.push_back(filename);
272  }
273  }while(getNext(filename));
274  }
275 }
bool getFirst(ossimFilename &filename, int flags=OSSIM_DIR_DEFAULT)
bool getNext(ossimFilename &filename) const
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
void compile(const char *)
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
ossimFilename file() const
bool find(const char *)

◆ findCaseInsensitiveEquivalents()

bool ossimDirectory::findCaseInsensitiveEquivalents ( const ossimFilename filename,
std::vector< ossimFilename > &  result,
bool  bExcludeExactMatch = true 
)

Case insensitive search for files with the same name but with letters that have different case than the input name.

On Windows there can only be one match, but the case can be different than the input name. On UNIX there can be multiple matches.

If the bExcludeExactMatch input parameter is set to false, the original input name will be included in the 'result' vector if it is found in the directory. Otherwise (the default), the input name is excluded from the 'result' vector even if it is found in the directory.

Returns true if a name has been added to the result vector.

Definition at line 279 of file ossimDirectory.cpp.

References ossimString::c_str(), getFirst(), getNext(), ossimString::length(), and true.

283 {
284  bool bSuccess = false;
285  ossimFilename candidate;
286  bool bFoundCandidate = getFirst( candidate );
287  int compareSize = static_cast<int>( filename.length() );
288 
289  while( bFoundCandidate == true )
290  {
291  // Do a case insensitive string compare
292 #if defined (_WIN32)
293  bool bFoundEquivalent = _strnicmp( filename.c_str(), candidate.c_str(),
294  compareSize ) == 0 ? true : false;
295 #else
296  //bool bFoundEquivalent = strnicmp( filename.c_str(), candidate.c_str(), //
297  // compareSize ) == 0 ? true : false;
298  bool bFoundEquivalent = strncasecmp( filename.c_str(), candidate.c_str(),
299  compareSize ) == 0 ? true : false;
300 #endif
301 
302  if ( bFoundEquivalent == true )
303  {
304  bool bFoundExact = ( filename == candidate.c_str() ) ? true : false;
305  bool bShouldExclude = ( bFoundExact == true &&
306  bExcludeExactMatch == true ) ? true : false;
307 
308  if ( bShouldExclude == false )
309  {
310  bSuccess = true;
311  result.push_back( candidate );
312  }
313  }
314 
315  bFoundCandidate = getNext( candidate );
316  }
317 
318  return bSuccess;
319 }
bool getFirst(ossimFilename &filename, int flags=OSSIM_DIR_DEFAULT)
bool getNext(ossimFilename &filename) const
std::string::size_type length() const
Definition: ossimString.h:408
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

◆ getFirst()

bool ossimDirectory::getFirst ( ossimFilename filename,
int  flags = OSSIM_DIR_DEFAULT 
)

◆ getNext()

bool ossimDirectory::getNext ( ossimFilename filename) const

Get next file in the enumeration started with either GetFirst() or GetFirstNormal().

Definition at line 240 of file ossimDirectory.cpp.

References isOpened(), ossimDirectoryData::read(), and theData.

Referenced by findAllFilesThatMatch(), findCaseInsensitiveEquivalents(), ossimDirectoryTree::getFirst(), getFirst(), ossimDirectoryTree::getNext(), ossimElevManager::loadElevationPath(), ossimInit::loadPlugins(), ossimGeneralRasterElevationDatabase::openGeneralRasterDirectory(), and ossimGeneralRasterElevFactory::setDirectory().

241 {
242  if(theData && isOpened())
243  {
244  return theData->read(filename);
245  }
246 
247  return false;
248 }
bool isOpened() const
bool read(ossimFilename &filename)
ossimDirectoryData * theData

◆ isOpened()

bool ossimDirectory::isOpened ( ) const

Definition at line 250 of file ossimDirectory.cpp.

References theData.

Referenced by getFirst(), getNext(), ossimDirectoryTree::isOpened(), and ossimDirectoryTree::open().

251 {
252  return theData != NULL;
253 }
ossimDirectoryData * theData

◆ open()

bool ossimDirectory::open ( const ossimFilename dir)

Member Data Documentation

◆ theData

ossimDirectoryData* ossimDirectory::theData
private

Definition at line 101 of file ossimDirectory.h.

Referenced by getFirst(), getNext(), isOpened(), open(), ossimDirectory(), and ~ossimDirectory().


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