os/ossrv/ossrv_pub/boost_apis/boost/regex/v4/fileiter.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 *
sl@0
     3
 * Copyright (c) 1998-2002
sl@0
     4
 * John Maddock
sl@0
     5
 *
sl@0
     6
 * Use, modification and distribution are subject to the 
sl@0
     7
 * Boost Software License, Version 1.0. (See accompanying file 
sl@0
     8
 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
     9
 *
sl@0
    10
 */
sl@0
    11
 
sl@0
    12
 /*
sl@0
    13
  *   LOCATION:    see http://www.boost.org for most recent version.
sl@0
    14
  *   FILE         fileiter.hpp
sl@0
    15
  *   VERSION      see <boost/version.hpp>
sl@0
    16
  *   DESCRIPTION: Declares various platform independent file and
sl@0
    17
  *                directory iterators, plus binary file input in
sl@0
    18
  *                the form of class map_file.
sl@0
    19
  */
sl@0
    20
sl@0
    21
#ifndef BOOST_RE_FILEITER_HPP_INCLUDED
sl@0
    22
#define BOOST_RE_FILEITER_HPP_INCLUDED
sl@0
    23
sl@0
    24
#ifndef BOOST_REGEX_CONFIG_HPP
sl@0
    25
#include <boost/regex/config.hpp>
sl@0
    26
#endif
sl@0
    27
#include <boost/assert.hpp>
sl@0
    28
sl@0
    29
#ifndef BOOST_REGEX_NO_FILEITER
sl@0
    30
sl@0
    31
#if (defined(__CYGWIN__) || defined(__CYGWIN32__)) && !defined(BOOST_REGEX_NO_W32)
sl@0
    32
#error "Sorry, can't mix <windows.h> with STL code and gcc compiler: if you ran configure, try again with configure --disable-ms-windows"
sl@0
    33
#define BOOST_REGEX_FI_WIN32_MAP
sl@0
    34
#define BOOST_REGEX_FI_POSIX_DIR
sl@0
    35
#elif (defined(__WIN32__) || defined(_WIN32) || defined(WIN32)) && !defined(BOOST_REGEX_NO_W32)
sl@0
    36
#define BOOST_REGEX_FI_WIN32_MAP
sl@0
    37
#define BOOST_REGEX_FI_WIN32_DIR
sl@0
    38
#else
sl@0
    39
#define BOOST_REGEX_FI_POSIX_MAP
sl@0
    40
#define BOOST_REGEX_FI_POSIX_DIR
sl@0
    41
#endif
sl@0
    42
sl@0
    43
#if defined(BOOST_REGEX_FI_WIN32_MAP)||defined(BOOST_REGEX_FI_WIN32_DIR)
sl@0
    44
#include <windows.h>
sl@0
    45
#endif
sl@0
    46
sl@0
    47
#if defined(BOOST_REGEX_FI_WIN32_DIR)
sl@0
    48
sl@0
    49
namespace boost{
sl@0
    50
   namespace re_detail{
sl@0
    51
sl@0
    52
typedef WIN32_FIND_DATAA _fi_find_data;
sl@0
    53
typedef HANDLE _fi_find_handle;
sl@0
    54
sl@0
    55
   } // namespace re_detail
sl@0
    56
sl@0
    57
} // namespace boost
sl@0
    58
sl@0
    59
#define _fi_invalid_handle INVALID_HANDLE_VALUE
sl@0
    60
#define _fi_dir FILE_ATTRIBUTE_DIRECTORY
sl@0
    61
sl@0
    62
#elif defined(BOOST_REGEX_FI_POSIX_DIR)
sl@0
    63
sl@0
    64
#include <cstddef>
sl@0
    65
#include <cstdio>
sl@0
    66
#include <cctype>
sl@0
    67
#include <iterator>
sl@0
    68
#include <list>
sl@0
    69
#include <cassert>
sl@0
    70
#include <dirent.h>
sl@0
    71
sl@0
    72
#if defined(__SUNPRO_CC)
sl@0
    73
using std::list;
sl@0
    74
#endif
sl@0
    75
sl@0
    76
#ifndef MAX_PATH
sl@0
    77
#define MAX_PATH 256
sl@0
    78
#endif
sl@0
    79
sl@0
    80
namespace boost{
sl@0
    81
   namespace re_detail{
sl@0
    82
sl@0
    83
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
    84
#  include BOOST_ABI_PREFIX
sl@0
    85
#endif
sl@0
    86
sl@0
    87
struct _fi_find_data
sl@0
    88
{
sl@0
    89
   unsigned dwFileAttributes;
sl@0
    90
   char cFileName[MAX_PATH];
sl@0
    91
};
sl@0
    92
sl@0
    93
struct _fi_priv_data;
sl@0
    94
sl@0
    95
typedef _fi_priv_data* _fi_find_handle;
sl@0
    96
#define _fi_invalid_handle 0
sl@0
    97
#define _fi_dir 1
sl@0
    98
sl@0
    99
_fi_find_handle _fi_FindFirstFile(const char* lpFileName, _fi_find_data* lpFindFileData);
sl@0
   100
bool _fi_FindNextFile(_fi_find_handle hFindFile,   _fi_find_data* lpFindFileData);
sl@0
   101
bool _fi_FindClose(_fi_find_handle hFindFile);
sl@0
   102
sl@0
   103
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
   104
#  include BOOST_ABI_SUFFIX
sl@0
   105
#endif
sl@0
   106
sl@0
   107
   } // namespace re_detail
sl@0
   108
} // namespace boost
sl@0
   109
sl@0
   110
#ifdef FindFirstFile
sl@0
   111
 #undef FindFirstFile
sl@0
   112
#endif
sl@0
   113
#ifdef FindNextFile
sl@0
   114
 #undef FindNextFile
sl@0
   115
#endif
sl@0
   116
#ifdef FindClose
sl@0
   117
 #undef FindClose
sl@0
   118
#endif
sl@0
   119
sl@0
   120
#define FindFirstFileA _fi_FindFirstFile
sl@0
   121
#define FindNextFileA _fi_FindNextFile
sl@0
   122
#define FindClose _fi_FindClose
sl@0
   123
sl@0
   124
#endif
sl@0
   125
sl@0
   126
namespace boost{
sl@0
   127
   namespace re_detail{
sl@0
   128
sl@0
   129
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
   130
#  include BOOST_ABI_PREFIX
sl@0
   131
#endif
sl@0
   132
sl@0
   133
#ifdef BOOST_REGEX_FI_WIN32_MAP // win32 mapfile
sl@0
   134
sl@0
   135
class BOOST_REGEX_DECL mapfile
sl@0
   136
{
sl@0
   137
   HANDLE hfile;
sl@0
   138
   HANDLE hmap;
sl@0
   139
   const char* _first;
sl@0
   140
   const char* _last;
sl@0
   141
public:
sl@0
   142
sl@0
   143
   typedef const char* iterator;
sl@0
   144
sl@0
   145
   mapfile(){ hfile = hmap = 0; _first = _last = 0; }
sl@0
   146
   mapfile(const char* file){ hfile = hmap = 0; _first = _last = 0; open(file); }
sl@0
   147
   ~mapfile(){ close(); }
sl@0
   148
   void open(const char* file);
sl@0
   149
   void close();
sl@0
   150
   const char* begin(){ return _first; }
sl@0
   151
   const char* end(){ return _last; }
sl@0
   152
   size_t size(){ return _last - _first; }
sl@0
   153
   bool valid(){ return (hfile != 0) && (hfile != INVALID_HANDLE_VALUE); }
sl@0
   154
};
sl@0
   155
sl@0
   156
sl@0
   157
#else
sl@0
   158
sl@0
   159
class BOOST_REGEX_DECL mapfile_iterator;
sl@0
   160
sl@0
   161
class BOOST_REGEX_DECL mapfile
sl@0
   162
{
sl@0
   163
   typedef char* pointer;
sl@0
   164
   std::FILE* hfile;
sl@0
   165
   long int _size;
sl@0
   166
   pointer* _first;
sl@0
   167
   pointer* _last;
sl@0
   168
   mutable std::list<pointer*> condemed;
sl@0
   169
   enum sizes
sl@0
   170
   {
sl@0
   171
      buf_size = 4096
sl@0
   172
   };
sl@0
   173
   void lock(pointer* node)const;
sl@0
   174
   void unlock(pointer* node)const;
sl@0
   175
public:
sl@0
   176
sl@0
   177
   typedef mapfile_iterator iterator;
sl@0
   178
sl@0
   179
   mapfile(){ hfile = 0; _size = 0; _first = _last = 0; }
sl@0
   180
   mapfile(const char* file){ hfile = 0; _size = 0; _first = _last = 0; open(file); }
sl@0
   181
   ~mapfile(){ close(); }
sl@0
   182
   void open(const char* file);
sl@0
   183
   void close();
sl@0
   184
   iterator begin()const;
sl@0
   185
   iterator end()const;
sl@0
   186
   unsigned long size()const{ return _size; }
sl@0
   187
   bool valid()const{ return hfile != 0; }
sl@0
   188
   friend class mapfile_iterator;
sl@0
   189
};
sl@0
   190
sl@0
   191
class BOOST_REGEX_DECL mapfile_iterator
sl@0
   192
#if !defined(BOOST_NO_STD_ITERATOR) || defined(BOOST_MSVC_STD_ITERATOR)
sl@0
   193
: public std::iterator<std::random_access_iterator_tag, char>
sl@0
   194
#endif
sl@0
   195
{
sl@0
   196
   typedef mapfile::pointer internal_pointer;
sl@0
   197
   internal_pointer* node;
sl@0
   198
   const mapfile* file;
sl@0
   199
   unsigned long offset;
sl@0
   200
   long position()const
sl@0
   201
   {
sl@0
   202
      return file ? ((node - file->_first) * mapfile::buf_size + offset) : 0;
sl@0
   203
   }
sl@0
   204
   void position(long pos)
sl@0
   205
   {
sl@0
   206
      if(file)
sl@0
   207
      {
sl@0
   208
         node = file->_first + (pos / mapfile::buf_size);
sl@0
   209
         offset = pos % mapfile::buf_size;
sl@0
   210
      }
sl@0
   211
   }
sl@0
   212
public:
sl@0
   213
   typedef std::ptrdiff_t                  difference_type;
sl@0
   214
   typedef char                            value_type;
sl@0
   215
   typedef const char*                     pointer;
sl@0
   216
   typedef const char&                     reference;
sl@0
   217
   typedef std::random_access_iterator_tag iterator_category;
sl@0
   218
sl@0
   219
   mapfile_iterator() { node = 0; file = 0; offset = 0; }
sl@0
   220
   mapfile_iterator(const mapfile* f, long arg_position)
sl@0
   221
   {
sl@0
   222
      file = f;
sl@0
   223
      node = f->_first + arg_position / mapfile::buf_size;
sl@0
   224
      offset = arg_position % mapfile::buf_size;
sl@0
   225
      if(file)
sl@0
   226
         file->lock(node);
sl@0
   227
   }
sl@0
   228
   mapfile_iterator(const mapfile_iterator& i)
sl@0
   229
   {
sl@0
   230
      file = i.file;
sl@0
   231
      node = i.node;
sl@0
   232
      offset = i.offset;
sl@0
   233
      if(file)
sl@0
   234
         file->lock(node);
sl@0
   235
   }
sl@0
   236
   ~mapfile_iterator()
sl@0
   237
   {
sl@0
   238
      if(file && node)
sl@0
   239
         file->unlock(node);
sl@0
   240
   }
sl@0
   241
   mapfile_iterator& operator = (const mapfile_iterator& i);
sl@0
   242
   char operator* ()const
sl@0
   243
   {
sl@0
   244
      BOOST_ASSERT(node >= file->_first);
sl@0
   245
      BOOST_ASSERT(node < file->_last);
sl@0
   246
      return file ? *(*node + sizeof(int) + offset) : char(0);
sl@0
   247
   }
sl@0
   248
   char operator[] (long off)const
sl@0
   249
   {
sl@0
   250
      mapfile_iterator tmp(*this);
sl@0
   251
      tmp += off;
sl@0
   252
      return *tmp;
sl@0
   253
   }
sl@0
   254
   mapfile_iterator& operator++ ();
sl@0
   255
   mapfile_iterator operator++ (int);
sl@0
   256
   mapfile_iterator& operator-- ();
sl@0
   257
   mapfile_iterator operator-- (int);
sl@0
   258
sl@0
   259
   mapfile_iterator& operator += (long off)
sl@0
   260
   {
sl@0
   261
      position(position() + off);
sl@0
   262
      return *this;
sl@0
   263
   }
sl@0
   264
   mapfile_iterator& operator -= (long off)
sl@0
   265
   {
sl@0
   266
      position(position() - off);
sl@0
   267
      return *this;
sl@0
   268
   }
sl@0
   269
sl@0
   270
   friend inline bool operator==(const mapfile_iterator& i, const mapfile_iterator& j)
sl@0
   271
   {
sl@0
   272
      return (i.file == j.file) && (i.node == j.node) && (i.offset == j.offset);
sl@0
   273
   }
sl@0
   274
sl@0
   275
   friend inline bool operator!=(const mapfile_iterator& i, const mapfile_iterator& j)
sl@0
   276
   {
sl@0
   277
      return !(i == j);
sl@0
   278
   }
sl@0
   279
sl@0
   280
   friend inline bool operator<(const mapfile_iterator& i, const mapfile_iterator& j)
sl@0
   281
   {
sl@0
   282
      return i.position() < j.position();
sl@0
   283
   }
sl@0
   284
   friend inline bool operator>(const mapfile_iterator& i, const mapfile_iterator& j)
sl@0
   285
   {
sl@0
   286
      return i.position() > j.position();
sl@0
   287
   }
sl@0
   288
   friend inline bool operator<=(const mapfile_iterator& i, const mapfile_iterator& j)
sl@0
   289
   {
sl@0
   290
      return i.position() <= j.position();
sl@0
   291
   }
sl@0
   292
   friend inline bool operator>=(const mapfile_iterator& i, const mapfile_iterator& j)
sl@0
   293
   {
sl@0
   294
      return i.position() >= j.position();
sl@0
   295
   }
sl@0
   296
sl@0
   297
   friend mapfile_iterator operator + (const mapfile_iterator& i, long off);
sl@0
   298
   friend mapfile_iterator operator + (long off, const mapfile_iterator& i)
sl@0
   299
   {
sl@0
   300
      mapfile_iterator tmp(i);
sl@0
   301
      return tmp += off;
sl@0
   302
   }
sl@0
   303
   friend mapfile_iterator operator - (const mapfile_iterator& i, long off);
sl@0
   304
   friend inline long operator - (const mapfile_iterator& i, const mapfile_iterator& j)
sl@0
   305
   {
sl@0
   306
      return i.position() - j.position();
sl@0
   307
   }
sl@0
   308
};
sl@0
   309
sl@0
   310
#endif
sl@0
   311
sl@0
   312
// _fi_sep determines the directory separator, either '\\' or '/'
sl@0
   313
BOOST_REGEX_DECL extern const char* _fi_sep;
sl@0
   314
sl@0
   315
struct file_iterator_ref
sl@0
   316
{
sl@0
   317
   _fi_find_handle hf;
sl@0
   318
   _fi_find_data _data;
sl@0
   319
   long count;
sl@0
   320
};
sl@0
   321
sl@0
   322
sl@0
   323
class BOOST_REGEX_DECL file_iterator 
sl@0
   324
{
sl@0
   325
   char* _root;
sl@0
   326
   char* _path;
sl@0
   327
   char* ptr;
sl@0
   328
   file_iterator_ref* ref;
sl@0
   329
sl@0
   330
public:
sl@0
   331
   typedef std::ptrdiff_t            difference_type;
sl@0
   332
   typedef const char*               value_type;
sl@0
   333
   typedef const char**              pointer;
sl@0
   334
   typedef const char*&              reference;
sl@0
   335
   typedef std::input_iterator_tag   iterator_category;
sl@0
   336
sl@0
   337
   file_iterator();
sl@0
   338
   file_iterator(const char* wild);
sl@0
   339
   ~file_iterator();
sl@0
   340
   file_iterator(const file_iterator&);
sl@0
   341
   file_iterator& operator=(const file_iterator&);
sl@0
   342
   const char* root()const { return _root; }
sl@0
   343
   const char* path()const { return _path; }
sl@0
   344
   const char* name()const { return ptr; }
sl@0
   345
   _fi_find_data* data() { return &(ref->_data); }
sl@0
   346
   void next();
sl@0
   347
   file_iterator& operator++() { next(); return *this; }
sl@0
   348
   file_iterator operator++(int);
sl@0
   349
   const char* operator*() { return path(); }
sl@0
   350
sl@0
   351
   friend inline bool operator == (const file_iterator& f1, const file_iterator& f2)
sl@0
   352
   {
sl@0
   353
      return ((f1.ref->hf == _fi_invalid_handle) && (f2.ref->hf == _fi_invalid_handle));
sl@0
   354
   }
sl@0
   355
sl@0
   356
   friend inline bool operator != (const file_iterator& f1, const file_iterator& f2)
sl@0
   357
   {
sl@0
   358
      return !(f1 == f2);
sl@0
   359
   }
sl@0
   360
sl@0
   361
};
sl@0
   362
sl@0
   363
// dwa 9/13/00 - suppress unused parameter warning
sl@0
   364
inline bool operator < (const file_iterator&, const file_iterator&)
sl@0
   365
{
sl@0
   366
   return false;
sl@0
   367
}
sl@0
   368
sl@0
   369
sl@0
   370
class BOOST_REGEX_DECL directory_iterator
sl@0
   371
{
sl@0
   372
   char* _root;
sl@0
   373
   char* _path;
sl@0
   374
   char* ptr;
sl@0
   375
   file_iterator_ref* ref;
sl@0
   376
sl@0
   377
public:
sl@0
   378
   typedef std::ptrdiff_t            difference_type;
sl@0
   379
   typedef const char*               value_type;
sl@0
   380
   typedef const char**              pointer;
sl@0
   381
   typedef const char*&              reference;
sl@0
   382
   typedef std::input_iterator_tag   iterator_category;
sl@0
   383
sl@0
   384
   directory_iterator();
sl@0
   385
   directory_iterator(const char* wild);
sl@0
   386
   ~directory_iterator();
sl@0
   387
   directory_iterator(const directory_iterator& other);
sl@0
   388
   directory_iterator& operator=(const directory_iterator& other);
sl@0
   389
sl@0
   390
   const char* root()const { return _root; }
sl@0
   391
   const char* path()const { return _path; }
sl@0
   392
   const char* name()const { return ptr; }
sl@0
   393
   _fi_find_data* data() { return &(ref->_data); }
sl@0
   394
   void next();
sl@0
   395
   directory_iterator& operator++() { next(); return *this; }
sl@0
   396
   directory_iterator operator++(int);
sl@0
   397
   const char* operator*() { return path(); }
sl@0
   398
sl@0
   399
   static const char* separator() { return _fi_sep; }
sl@0
   400
sl@0
   401
   friend inline bool operator == (const directory_iterator& f1, const directory_iterator& f2)
sl@0
   402
   {
sl@0
   403
      return ((f1.ref->hf == _fi_invalid_handle) && (f2.ref->hf == _fi_invalid_handle));
sl@0
   404
   }
sl@0
   405
sl@0
   406
sl@0
   407
   friend inline bool operator != (const directory_iterator& f1, const directory_iterator& f2)
sl@0
   408
   {
sl@0
   409
      return !(f1 == f2);
sl@0
   410
   }
sl@0
   411
sl@0
   412
   };
sl@0
   413
sl@0
   414
inline bool operator < (const directory_iterator&, const directory_iterator&)
sl@0
   415
{
sl@0
   416
   return false;
sl@0
   417
}
sl@0
   418
sl@0
   419
#ifdef BOOST_HAS_ABI_HEADERS
sl@0
   420
#  include BOOST_ABI_SUFFIX
sl@0
   421
#endif
sl@0
   422
sl@0
   423
sl@0
   424
} // namespace re_detail
sl@0
   425
using boost::re_detail::directory_iterator;
sl@0
   426
using boost::re_detail::file_iterator;
sl@0
   427
using boost::re_detail::mapfile;
sl@0
   428
} // namespace boost
sl@0
   429
sl@0
   430
#endif     // BOOST_REGEX_NO_FILEITER
sl@0
   431
#endif     // BOOST_RE_FILEITER_HPP
sl@0
   432
sl@0
   433
sl@0
   434
sl@0
   435
sl@0
   436
sl@0
   437
sl@0
   438
sl@0
   439
sl@0
   440
sl@0
   441
sl@0
   442
sl@0
   443
sl@0
   444
sl@0
   445
sl@0
   446
sl@0
   447
sl@0
   448
sl@0
   449