libzypp  13.10.6
Glob.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14 
15 #include "zypp/Glob.h"
16 
17 using std::endl;
18 
20 namespace zypp
21 {
22  namespace filesystem
24  {
25 
26  int Glob::add( const char * pattern_r, Flags flags_r )
27  {
28  static Flags _APPEND( GLOB_APPEND ); // not published
29  if ( ! flags_r )
30  flags_r = _defaultFlags;
31  if ( _result )
32  flags_r |= _APPEND;
33  else
34  _result.reset( new ::glob_t );
35  return( _lastGlobReturn = ::glob( pattern_r, flags_r, NULL, &(*_result) ) );
36  }
37 
38  void Glob::clear()
39  {
40  if ( _result )
41  {
42  ::globfree( &(*_result) );
43  _result.reset();
44  _lastGlobReturn = 0;
45  }
46  }
47 
48  /******************************************************************
49  **
50  ** FUNCTION NAME : operator<<
51  ** FUNCTION TYPE : std::ostream &
52  */
53  std::ostream & operator<<( std::ostream & str, const Glob & obj )
54  {
55  return dumpRange( str << "(" << obj.size() << ")", obj.begin(), obj.end() );
56  }
57 
59  } // namespace filesystem
62 } // namespace zypp
scoped_ptr< ::glob_t > _result
Definition: Glob.h:249
DefaultIntegral< int, 0 > _lastGlobReturn
Definition: Glob.h:250
std::ostream & dumpRange(std::ostream &str, _Iterator begin, _Iterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition: LogTools.h:91
Find pathnames matching a pattern.
Definition: Glob.h:57
const_iterator begin() const
Iterator pointing to the first result.
Definition: Glob.h:197
const_iterator end() const
Iterator pointing behind the last result.
Definition: Glob.h:201
size_type size() const
The number of matches found so far.
Definition: Glob.h:193
std::ostream & operator<<(std::ostream &str, const Glob &obj)
Definition: Glob.cc:53
void clear()
Clear all results found so far.
Definition: Glob.cc:38