1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/regex/v4/fileiter.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,449 @@
1.4 +/*
1.5 + *
1.6 + * Copyright (c) 1998-2002
1.7 + * John Maddock
1.8 + *
1.9 + * Use, modification and distribution are subject to the
1.10 + * Boost Software License, Version 1.0. (See accompanying file
1.11 + * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.12 + *
1.13 + */
1.14 +
1.15 + /*
1.16 + * LOCATION: see http://www.boost.org for most recent version.
1.17 + * FILE fileiter.hpp
1.18 + * VERSION see <boost/version.hpp>
1.19 + * DESCRIPTION: Declares various platform independent file and
1.20 + * directory iterators, plus binary file input in
1.21 + * the form of class map_file.
1.22 + */
1.23 +
1.24 +#ifndef BOOST_RE_FILEITER_HPP_INCLUDED
1.25 +#define BOOST_RE_FILEITER_HPP_INCLUDED
1.26 +
1.27 +#ifndef BOOST_REGEX_CONFIG_HPP
1.28 +#include <boost/regex/config.hpp>
1.29 +#endif
1.30 +#include <boost/assert.hpp>
1.31 +
1.32 +#ifndef BOOST_REGEX_NO_FILEITER
1.33 +
1.34 +#if (defined(__CYGWIN__) || defined(__CYGWIN32__)) && !defined(BOOST_REGEX_NO_W32)
1.35 +#error "Sorry, can't mix <windows.h> with STL code and gcc compiler: if you ran configure, try again with configure --disable-ms-windows"
1.36 +#define BOOST_REGEX_FI_WIN32_MAP
1.37 +#define BOOST_REGEX_FI_POSIX_DIR
1.38 +#elif (defined(__WIN32__) || defined(_WIN32) || defined(WIN32)) && !defined(BOOST_REGEX_NO_W32)
1.39 +#define BOOST_REGEX_FI_WIN32_MAP
1.40 +#define BOOST_REGEX_FI_WIN32_DIR
1.41 +#else
1.42 +#define BOOST_REGEX_FI_POSIX_MAP
1.43 +#define BOOST_REGEX_FI_POSIX_DIR
1.44 +#endif
1.45 +
1.46 +#if defined(BOOST_REGEX_FI_WIN32_MAP)||defined(BOOST_REGEX_FI_WIN32_DIR)
1.47 +#include <windows.h>
1.48 +#endif
1.49 +
1.50 +#if defined(BOOST_REGEX_FI_WIN32_DIR)
1.51 +
1.52 +namespace boost{
1.53 + namespace re_detail{
1.54 +
1.55 +typedef WIN32_FIND_DATAA _fi_find_data;
1.56 +typedef HANDLE _fi_find_handle;
1.57 +
1.58 + } // namespace re_detail
1.59 +
1.60 +} // namespace boost
1.61 +
1.62 +#define _fi_invalid_handle INVALID_HANDLE_VALUE
1.63 +#define _fi_dir FILE_ATTRIBUTE_DIRECTORY
1.64 +
1.65 +#elif defined(BOOST_REGEX_FI_POSIX_DIR)
1.66 +
1.67 +#include <cstddef>
1.68 +#include <cstdio>
1.69 +#include <cctype>
1.70 +#include <iterator>
1.71 +#include <list>
1.72 +#include <cassert>
1.73 +#include <dirent.h>
1.74 +
1.75 +#if defined(__SUNPRO_CC)
1.76 +using std::list;
1.77 +#endif
1.78 +
1.79 +#ifndef MAX_PATH
1.80 +#define MAX_PATH 256
1.81 +#endif
1.82 +
1.83 +namespace boost{
1.84 + namespace re_detail{
1.85 +
1.86 +#ifdef BOOST_HAS_ABI_HEADERS
1.87 +# include BOOST_ABI_PREFIX
1.88 +#endif
1.89 +
1.90 +struct _fi_find_data
1.91 +{
1.92 + unsigned dwFileAttributes;
1.93 + char cFileName[MAX_PATH];
1.94 +};
1.95 +
1.96 +struct _fi_priv_data;
1.97 +
1.98 +typedef _fi_priv_data* _fi_find_handle;
1.99 +#define _fi_invalid_handle 0
1.100 +#define _fi_dir 1
1.101 +
1.102 +_fi_find_handle _fi_FindFirstFile(const char* lpFileName, _fi_find_data* lpFindFileData);
1.103 +bool _fi_FindNextFile(_fi_find_handle hFindFile, _fi_find_data* lpFindFileData);
1.104 +bool _fi_FindClose(_fi_find_handle hFindFile);
1.105 +
1.106 +#ifdef BOOST_HAS_ABI_HEADERS
1.107 +# include BOOST_ABI_SUFFIX
1.108 +#endif
1.109 +
1.110 + } // namespace re_detail
1.111 +} // namespace boost
1.112 +
1.113 +#ifdef FindFirstFile
1.114 + #undef FindFirstFile
1.115 +#endif
1.116 +#ifdef FindNextFile
1.117 + #undef FindNextFile
1.118 +#endif
1.119 +#ifdef FindClose
1.120 + #undef FindClose
1.121 +#endif
1.122 +
1.123 +#define FindFirstFileA _fi_FindFirstFile
1.124 +#define FindNextFileA _fi_FindNextFile
1.125 +#define FindClose _fi_FindClose
1.126 +
1.127 +#endif
1.128 +
1.129 +namespace boost{
1.130 + namespace re_detail{
1.131 +
1.132 +#ifdef BOOST_HAS_ABI_HEADERS
1.133 +# include BOOST_ABI_PREFIX
1.134 +#endif
1.135 +
1.136 +#ifdef BOOST_REGEX_FI_WIN32_MAP // win32 mapfile
1.137 +
1.138 +class BOOST_REGEX_DECL mapfile
1.139 +{
1.140 + HANDLE hfile;
1.141 + HANDLE hmap;
1.142 + const char* _first;
1.143 + const char* _last;
1.144 +public:
1.145 +
1.146 + typedef const char* iterator;
1.147 +
1.148 + mapfile(){ hfile = hmap = 0; _first = _last = 0; }
1.149 + mapfile(const char* file){ hfile = hmap = 0; _first = _last = 0; open(file); }
1.150 + ~mapfile(){ close(); }
1.151 + void open(const char* file);
1.152 + void close();
1.153 + const char* begin(){ return _first; }
1.154 + const char* end(){ return _last; }
1.155 + size_t size(){ return _last - _first; }
1.156 + bool valid(){ return (hfile != 0) && (hfile != INVALID_HANDLE_VALUE); }
1.157 +};
1.158 +
1.159 +
1.160 +#else
1.161 +
1.162 +class BOOST_REGEX_DECL mapfile_iterator;
1.163 +
1.164 +class BOOST_REGEX_DECL mapfile
1.165 +{
1.166 + typedef char* pointer;
1.167 + std::FILE* hfile;
1.168 + long int _size;
1.169 + pointer* _first;
1.170 + pointer* _last;
1.171 + mutable std::list<pointer*> condemed;
1.172 + enum sizes
1.173 + {
1.174 + buf_size = 4096
1.175 + };
1.176 + void lock(pointer* node)const;
1.177 + void unlock(pointer* node)const;
1.178 +public:
1.179 +
1.180 + typedef mapfile_iterator iterator;
1.181 +
1.182 + mapfile(){ hfile = 0; _size = 0; _first = _last = 0; }
1.183 + mapfile(const char* file){ hfile = 0; _size = 0; _first = _last = 0; open(file); }
1.184 + ~mapfile(){ close(); }
1.185 + void open(const char* file);
1.186 + void close();
1.187 + iterator begin()const;
1.188 + iterator end()const;
1.189 + unsigned long size()const{ return _size; }
1.190 + bool valid()const{ return hfile != 0; }
1.191 + friend class mapfile_iterator;
1.192 +};
1.193 +
1.194 +class BOOST_REGEX_DECL mapfile_iterator
1.195 +#if !defined(BOOST_NO_STD_ITERATOR) || defined(BOOST_MSVC_STD_ITERATOR)
1.196 +: public std::iterator<std::random_access_iterator_tag, char>
1.197 +#endif
1.198 +{
1.199 + typedef mapfile::pointer internal_pointer;
1.200 + internal_pointer* node;
1.201 + const mapfile* file;
1.202 + unsigned long offset;
1.203 + long position()const
1.204 + {
1.205 + return file ? ((node - file->_first) * mapfile::buf_size + offset) : 0;
1.206 + }
1.207 + void position(long pos)
1.208 + {
1.209 + if(file)
1.210 + {
1.211 + node = file->_first + (pos / mapfile::buf_size);
1.212 + offset = pos % mapfile::buf_size;
1.213 + }
1.214 + }
1.215 +public:
1.216 + typedef std::ptrdiff_t difference_type;
1.217 + typedef char value_type;
1.218 + typedef const char* pointer;
1.219 + typedef const char& reference;
1.220 + typedef std::random_access_iterator_tag iterator_category;
1.221 +
1.222 + mapfile_iterator() { node = 0; file = 0; offset = 0; }
1.223 + mapfile_iterator(const mapfile* f, long arg_position)
1.224 + {
1.225 + file = f;
1.226 + node = f->_first + arg_position / mapfile::buf_size;
1.227 + offset = arg_position % mapfile::buf_size;
1.228 + if(file)
1.229 + file->lock(node);
1.230 + }
1.231 + mapfile_iterator(const mapfile_iterator& i)
1.232 + {
1.233 + file = i.file;
1.234 + node = i.node;
1.235 + offset = i.offset;
1.236 + if(file)
1.237 + file->lock(node);
1.238 + }
1.239 + ~mapfile_iterator()
1.240 + {
1.241 + if(file && node)
1.242 + file->unlock(node);
1.243 + }
1.244 + mapfile_iterator& operator = (const mapfile_iterator& i);
1.245 + char operator* ()const
1.246 + {
1.247 + BOOST_ASSERT(node >= file->_first);
1.248 + BOOST_ASSERT(node < file->_last);
1.249 + return file ? *(*node + sizeof(int) + offset) : char(0);
1.250 + }
1.251 + char operator[] (long off)const
1.252 + {
1.253 + mapfile_iterator tmp(*this);
1.254 + tmp += off;
1.255 + return *tmp;
1.256 + }
1.257 + mapfile_iterator& operator++ ();
1.258 + mapfile_iterator operator++ (int);
1.259 + mapfile_iterator& operator-- ();
1.260 + mapfile_iterator operator-- (int);
1.261 +
1.262 + mapfile_iterator& operator += (long off)
1.263 + {
1.264 + position(position() + off);
1.265 + return *this;
1.266 + }
1.267 + mapfile_iterator& operator -= (long off)
1.268 + {
1.269 + position(position() - off);
1.270 + return *this;
1.271 + }
1.272 +
1.273 + friend inline bool operator==(const mapfile_iterator& i, const mapfile_iterator& j)
1.274 + {
1.275 + return (i.file == j.file) && (i.node == j.node) && (i.offset == j.offset);
1.276 + }
1.277 +
1.278 + friend inline bool operator!=(const mapfile_iterator& i, const mapfile_iterator& j)
1.279 + {
1.280 + return !(i == j);
1.281 + }
1.282 +
1.283 + friend inline bool operator<(const mapfile_iterator& i, const mapfile_iterator& j)
1.284 + {
1.285 + return i.position() < j.position();
1.286 + }
1.287 + friend inline bool operator>(const mapfile_iterator& i, const mapfile_iterator& j)
1.288 + {
1.289 + return i.position() > j.position();
1.290 + }
1.291 + friend inline bool operator<=(const mapfile_iterator& i, const mapfile_iterator& j)
1.292 + {
1.293 + return i.position() <= j.position();
1.294 + }
1.295 + friend inline bool operator>=(const mapfile_iterator& i, const mapfile_iterator& j)
1.296 + {
1.297 + return i.position() >= j.position();
1.298 + }
1.299 +
1.300 + friend mapfile_iterator operator + (const mapfile_iterator& i, long off);
1.301 + friend mapfile_iterator operator + (long off, const mapfile_iterator& i)
1.302 + {
1.303 + mapfile_iterator tmp(i);
1.304 + return tmp += off;
1.305 + }
1.306 + friend mapfile_iterator operator - (const mapfile_iterator& i, long off);
1.307 + friend inline long operator - (const mapfile_iterator& i, const mapfile_iterator& j)
1.308 + {
1.309 + return i.position() - j.position();
1.310 + }
1.311 +};
1.312 +
1.313 +#endif
1.314 +
1.315 +// _fi_sep determines the directory separator, either '\\' or '/'
1.316 +BOOST_REGEX_DECL extern const char* _fi_sep;
1.317 +
1.318 +struct file_iterator_ref
1.319 +{
1.320 + _fi_find_handle hf;
1.321 + _fi_find_data _data;
1.322 + long count;
1.323 +};
1.324 +
1.325 +
1.326 +class BOOST_REGEX_DECL file_iterator
1.327 +{
1.328 + char* _root;
1.329 + char* _path;
1.330 + char* ptr;
1.331 + file_iterator_ref* ref;
1.332 +
1.333 +public:
1.334 + typedef std::ptrdiff_t difference_type;
1.335 + typedef const char* value_type;
1.336 + typedef const char** pointer;
1.337 + typedef const char*& reference;
1.338 + typedef std::input_iterator_tag iterator_category;
1.339 +
1.340 + file_iterator();
1.341 + file_iterator(const char* wild);
1.342 + ~file_iterator();
1.343 + file_iterator(const file_iterator&);
1.344 + file_iterator& operator=(const file_iterator&);
1.345 + const char* root()const { return _root; }
1.346 + const char* path()const { return _path; }
1.347 + const char* name()const { return ptr; }
1.348 + _fi_find_data* data() { return &(ref->_data); }
1.349 + void next();
1.350 + file_iterator& operator++() { next(); return *this; }
1.351 + file_iterator operator++(int);
1.352 + const char* operator*() { return path(); }
1.353 +
1.354 + friend inline bool operator == (const file_iterator& f1, const file_iterator& f2)
1.355 + {
1.356 + return ((f1.ref->hf == _fi_invalid_handle) && (f2.ref->hf == _fi_invalid_handle));
1.357 + }
1.358 +
1.359 + friend inline bool operator != (const file_iterator& f1, const file_iterator& f2)
1.360 + {
1.361 + return !(f1 == f2);
1.362 + }
1.363 +
1.364 +};
1.365 +
1.366 +// dwa 9/13/00 - suppress unused parameter warning
1.367 +inline bool operator < (const file_iterator&, const file_iterator&)
1.368 +{
1.369 + return false;
1.370 +}
1.371 +
1.372 +
1.373 +class BOOST_REGEX_DECL directory_iterator
1.374 +{
1.375 + char* _root;
1.376 + char* _path;
1.377 + char* ptr;
1.378 + file_iterator_ref* ref;
1.379 +
1.380 +public:
1.381 + typedef std::ptrdiff_t difference_type;
1.382 + typedef const char* value_type;
1.383 + typedef const char** pointer;
1.384 + typedef const char*& reference;
1.385 + typedef std::input_iterator_tag iterator_category;
1.386 +
1.387 + directory_iterator();
1.388 + directory_iterator(const char* wild);
1.389 + ~directory_iterator();
1.390 + directory_iterator(const directory_iterator& other);
1.391 + directory_iterator& operator=(const directory_iterator& other);
1.392 +
1.393 + const char* root()const { return _root; }
1.394 + const char* path()const { return _path; }
1.395 + const char* name()const { return ptr; }
1.396 + _fi_find_data* data() { return &(ref->_data); }
1.397 + void next();
1.398 + directory_iterator& operator++() { next(); return *this; }
1.399 + directory_iterator operator++(int);
1.400 + const char* operator*() { return path(); }
1.401 +
1.402 + static const char* separator() { return _fi_sep; }
1.403 +
1.404 + friend inline bool operator == (const directory_iterator& f1, const directory_iterator& f2)
1.405 + {
1.406 + return ((f1.ref->hf == _fi_invalid_handle) && (f2.ref->hf == _fi_invalid_handle));
1.407 + }
1.408 +
1.409 +
1.410 + friend inline bool operator != (const directory_iterator& f1, const directory_iterator& f2)
1.411 + {
1.412 + return !(f1 == f2);
1.413 + }
1.414 +
1.415 + };
1.416 +
1.417 +inline bool operator < (const directory_iterator&, const directory_iterator&)
1.418 +{
1.419 + return false;
1.420 +}
1.421 +
1.422 +#ifdef BOOST_HAS_ABI_HEADERS
1.423 +# include BOOST_ABI_SUFFIX
1.424 +#endif
1.425 +
1.426 +
1.427 +} // namespace re_detail
1.428 +using boost::re_detail::directory_iterator;
1.429 +using boost::re_detail::file_iterator;
1.430 +using boost::re_detail::mapfile;
1.431 +} // namespace boost
1.432 +
1.433 +#endif // BOOST_REGEX_NO_FILEITER
1.434 +#endif // BOOST_RE_FILEITER_HPP
1.435 +
1.436 +
1.437 +
1.438 +
1.439 +
1.440 +
1.441 +
1.442 +
1.443 +
1.444 +
1.445 +
1.446 +
1.447 +
1.448 +
1.449 +
1.450 +
1.451 +
1.452 +