Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Glob.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Glob.cc
10  *
11 */
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14
15 #include "zypp/Glob.h"
16
17 using std::endl;
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22   ///////////////////////////////////////////////////////////////////
23   namespace filesystem
24   { /////////////////////////////////////////////////////////////////
25
26     int Glob::add( const char * pattern_r, Flags flags_r )
27     {
28       static Flags kAppend( GLOB_APPEND ); // not published
29       if ( ! flags_r )
30         flags_r = _defaultFlags;
31       if ( _result )
32         flags_r |= kAppend;
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
58     /////////////////////////////////////////////////////////////////
59   } // namespace filesystem
60   ///////////////////////////////////////////////////////////////////
61   /////////////////////////////////////////////////////////////////
62 } // namespace zypp
63 ///////////////////////////////////////////////////////////////////