The Artima Developer Community
Sponsored Link

The C++ Source
globsequence.h: Declaration of the unixstl::glob_sequence class

This page shows the complete listing of class glob_sequence, which is described in the article, "Wild-card Searches of UNIX Directories with Random-Access Iterators":

// globsequence.h: Declaration of the unixstl::glob_sequence class
#include "unixstl.h"                    // UNIXSTL root header
#include "unixstl_filesystem_traits.h"  // filesystem_traits
#include "unixstl_file_path_buffer.h"   // basic_file_path_buffer
#include "stlsoft_iterator.h"           // iterator helper classes
#include "stlsoft_auto_buffer.h"        // auto_buffer
#include <sys/types.h>
#include <sys/stat.h>             // stat()
#include <errno.h>
#include <glob.h>                 // glob(), globfree()
#include <algorithm>              // std::sort
#include <utility>                // std::swap

class glob_sequence
{
/// Types
public:
  typedef glob_sequence                class_type;
  typedef char                         char_type;
  typedef filesystem_traits<char_type> traits_type;
  typedef char_type const              *value_type;
  typedef value_type const             &const_reference;
  typedef value_type const             *const_pointer;
  typedef size_t                       size_type;
  typedef ptrdiff_t                    difference_type;

  typedef stlsoft::pointer_iterator < value_type
                                    , const_pointer
                                    , const_reference
                                    >::iterator_type const_iterator;

  typedef stlsoft::reverse_iterator_base< const_iterator
                                        , value_type
                                        , const_reference
                                        , const_pointer
                                        , difference_type
                                        > const_reverse_iterator;
/// Flags
public:
  enum
  {
      includeDots   = 0x0008
    , directories   = 0x0010
    , files         = 0x0020
    , noSort        = 0x0100
    , markDirs      = 0x0200
    , absolutePath  = 0x0400
  };

/// Construction
public:
  explicit glob_sequence(char const *pattern, unsigned flags = noSort);
  glob_sequence(char_type const *directory, char_type const *pattern, unsigned flags = noSort);
  ~glob_sequence();
  unsigned init_(char_type const *directory, char_type const *pattern);

/// Attributes
public:
  size_t  size() const;
  bool    empty() const;
  const value_type operator [](size_type index) const;

/// Iteration
public:
  const_iterator begin() const;
  const_iterator end() const;
  const_reverse_iterator  rbegin() const;
  const_reverse_iterator  rend() const;

// Implementation
private:
  static unsigned validate_flags_(unsigned flags);
  static bool     is_end_of_path_elements_(char_type const *pch, difference_type index);
  static bool     is_dots_maybe_slashed_(char_type const *s, bool &bTwoDots);
  size_t          init_glob_(char_type const *directory, char_type const *pattern);

// Members
private:
  typedef stlsoft::auto_buffer< char_type*
                              , stlsoft::malloc_allocator<char_type*>
                              , 32
                              >         buffer_type;

  unsigned const  m_flags;
  char_type const **m_base;
  size_t          m_cItems;
  buffer_type     m_buffer;
  glob_t          m_glob;

// Not to be implemented
private:
  glob_sequence(class_type const &);
  class_type const &operator =(class_type const &);
};

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us