Moved DiskUsage class out of PackageImplIf
[platform/upstream/libzypp.git] / zypp / DiskUsage.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/DiskUsage.cc
10  *
11 */
12 #include "zypp/DiskUsage.h"
13 #include <iostream>
14
15 using namespace std;
16
17 ///////////////////////////////////////////////////////////////////
18 namespace zypp
19 { /////////////////////////////////////////////////////////////////
20   std::ostream & operator<<( std::ostream & str, const DiskUsage::Entry & obj )
21   {
22     return str << obj.path << '\t' << obj._size << "; files " << obj._files;
23   }
24
25   DiskUsage::Entry DiskUsage::extract( const std::string & dirname_r )
26   {
27     Entry ret( dirname_r );
28   
29     iterator fst = begin();
30     for ( ; fst != end() && !fst->isBelow( ret ); ++fst )
31       ; // seek 1st equal or below
32   
33     if ( fst != end() ) {
34       iterator lst = fst;
35       for ( ; lst != end() && lst->isBelow( ret ); ++lst ) {
36         // collect while below
37         ret += *lst;
38       }
39       // remove
40       _dirs.erase( fst, lst );
41     }
42   
43     return ret;
44   }
45
46   std::ostream & operator<<( std::ostream & str, const DiskUsage & obj )
47   {
48     str << "Package Disk Usage {" << endl;
49     for ( DiskUsage::EntrySet::const_iterator it = obj._dirs.begin(); it != obj._dirs.end(); ++it ) {
50       str << "   " << *it << endl;
51     }
52     return str << "}";
53   }
54
55
56 } // namespace zypp
57 ///////////////////////////////////////////////////////////////////