~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/ptb-filesystem-v3.diff/bear-factory/bear-editor/src/bf/impl/scan_dir.tpp

  • Committer: Package Import Robot
  • Author(s): Vincent Cheng, Evgeni Golov, Gonéri Le Bouder, Julien Jorge, Vincent Cheng
  • Date: 2014-01-23 13:20:52 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140123132052-r0kg74mh6egto11t
Tags: 0.6.0-2
* Team upload.

[ Evgeni Golov ]
* Correct Vcs-* URLs to point to anonscm.debian.org

[ Gonéri Le Bouder ]
* import patches by Julien Jorge to fix a FTBFS  with the current
  Boost.FileSystem (closes: #720819)
* Add myself in Uploaders
* Indent the B-D

[ Julien Jorge ]
* Add mipsn32el mips64 mips64el in the architecures (closes: #726176)
* Add a patch to use the full path to the icon in the menu files
  (closes: #726853)

[ Vincent Cheng ]
* Refresh patches.
* Update to Standards version 3.9.5.
* Update to source format "3.0 (quilt)".

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Bear Engine - Editor library
 
3
 
 
4
    Copyright (C) 20052011 Julien Jorge, Sebastien Angibaud
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify it
 
7
    under the terms of the GNU General Public License as published by the
 
8
    Free Software Foundation; either version 2 of the License, or (at your
 
9
    option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful, but WITHOUT
 
12
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
    more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License along
 
17
    with this program; if not, write to the Free Software Foundation, Inc.,
 
18
    51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 
 
20
    contact: plee-the-bear@gamned.org
 
21
 
 
22
    Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file bf/impl/scan_dir.tpp
 
26
 * \brief Implementation of the bf::scan_dir class.
 
27
 * \author Julien Jorge
 
28
 */
 
29
 
 
30
#include <boost/filesystem/path.hpp>
 
31
#include <boost/filesystem/convenience.hpp>
 
32
#include <queue>
 
33
 
 
34
/*----------------------------------------------------------------------------*/
 
35
/**
 
36
 * \brief Read all item files from a given directory and in its subdirectories.
 
37
 * \param dir The path where the files are searched.
 
38
 * \param f A copyable function object called on each file found in the
 
39
 *        directory.
 
40
 * \param first_ext Iterator on the first valid extension.
 
41
 * \param last_ext Iterator just after the last valid extension.
 
42
 */
 
43
template<typename Func>
 
44
template<typename Iterator>
 
45
void bf::scan_dir<Func>::operator()
 
46
( const std::string& dir, Func& f, Iterator first_ext, Iterator last_ext )
 
47
{
 
48
  std::queue<boost::filesystem::path> pending;
 
49
  boost::filesystem::path path(dir, boost::filesystem::native);
 
50
 
 
51
  if ( !boost::filesystem::exists(path) )
 
52
    return;
 
53
 
 
54
  pending.push(path);
 
55
 
 
56
  while ( !pending.empty() )
 
57
    {
 
58
      path = pending.front();
 
59
      pending.pop();
 
60
 
 
61
      boost::filesystem::directory_iterator it(path);
 
62
      boost::filesystem::directory_iterator eit;
 
63
 
 
64
      for ( ; it!=eit; ++it)
 
65
        if ( boost::filesystem::is_directory(*it) )
 
66
          pending.push(*it);
 
67
        else if (supported_extension( it->string(), first_ext, last_ext ))
 
68
          f(it->string());
 
69
    }
 
70
} // scan_dir::operator()
 
71
 
 
72
/*----------------------------------------------------------------------------*/
 
73
/**
 
74
 * \brief Tell if a path correspond to a supported extension.
 
75
 * \param path The path to check.
 
76
 * \param first_ext Iterator on the first valid extension.
 
77
 * \param last_ext Iterator just after the last valid extension.
 
78
 */
 
79
template<typename Func>
 
80
template<typename Iterator>
 
81
bool bf::scan_dir<Func>::supported_extension
 
82
( const std::string& path, Iterator first_ext, Iterator last_ext )
 
83
{
 
84
  // return true if no extension is given
 
85
  bool result( first_ext == last_ext );
 
86
 
 
87
  for ( ; !result && (first_ext!=last_ext); ++first_ext )
 
88
    if ( path.size() >= first_ext->size() )
 
89
      result = path.rfind(*first_ext) == path.size() - first_ext->size();
 
90
 
 
91
  return result;
 
92
} // scan_dir::supported_extension()