OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDirectoryData.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts (gpotts@imagelinks)
6 //
7 // Description:
8 // Class designed to be used by ossimDirectory class. Should not be used
9 // directly.
10 //
11 //*************************************************************************
12 // $Id: ossimDirectoryData.cpp 9966 2006-11-29 02:01:07Z gpotts $
13 
14 #ifndef _MSC_VER
15 
16 #include <sys/types.h>
17 #include <iostream>
18 using namespace std;
19 
22 
23 // ----------------------------------------------------------------------------
24 // ossimDirectoryData
25 // ----------------------------------------------------------------------------
26 
27 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
28 
30  : theDirectoryName(dirname)
31 {
32  theDir = NULL;
33 
34  // throw away the trailing slashes
35  size_t n = theDirectoryName.length();
36  if(n > 0)
37  {
38 
39  while ( n > 0 && theDirectoryName[--n] == '/' )
40  ;
41 
42 // theDirectoryName.Truncate(n + 1);
43 
44  // do open the dir
45  theDir = opendir(theDirectoryName.c_str());
46  }
47 }
48 
50 {
51  if ( theDir )
52  {
53  if ( closedir(theDir) != 0 )
54  {
55  // ERROR closing directory
56  }
57  }
58 }
59 
61 {
62  filename = ossimFilename::NIL;
63  dirent *de = (dirent *)NULL; // just to silent compiler warnings
64  bool matches = false;
65  ossimFilename temp;
66 
67  while ( !matches )
68  {
69  de = readdir(theDir);
70  if ( !de )
71  {
72  return false;
73  }
74 
75  temp = theDirectoryName.dirCat(de->d_name);
76 
77  //***
78  // NOTE:
79  // The check for "." and ".." did not work so added pattern match check.
80  //***
81 
82  // Check for "." and ".." match at the end of the name.
83  ossimString s = temp.match("\\.$|\\.\\.$");
84 
85  // don't return "." and ".." unless asked for
86  if ( (temp == "..") ||
87  (temp == ".") ||
88  (s == ".") ||
89  (s == "..") )
90  {
92  {
93  matches = true;
94  }
95  }
96  else if((temp.isDir()) &&
98  {
99  matches = true;
100  }
101  else if((temp.isFile()) &&
103  {
104  matches = true;
105  }
106  else
107  {
108  matches = false;
109  }
110  }
111 
112  if (matches)
113  {
114  filename = temp;//de->d_name;
115  }
116 
117  return matches;
118 }
119 
120 #else // old VMS (TODO)
121 
123 {
124 }
125 
127 {
128 }
129 
131 {
132  return false;
133 }
134 
135 #endif // not or new VMS/old VMS
136 
138 {
139  theFlags = flags;
140 }
141 
143 {
144  return theFlags;
145 }
146 
148 {
149  rewinddir(theDir);
150 }
151 
152 #endif /* #ifndef _MSC_VER */
153 
154 
ossimString match(const char *regularExpressionPattern) const
Returns from found pattern to end of pattern.
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
void setFlags(int flags)
ossimFilename theDirectoryName
bool isDir() const
std::string::size_type length() const
Definition: ossimString.h:408
os2<< "> n<< " > nendobj n
bool isFile() const
ossimDirectoryData(const ossimFilename &dirname)
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 read(ossimFilename &filename)