LCOV - code coverage report
Current view: top level - snapwebsites - glob_dir.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 4 0.0 %
Date: 2019-12-15 17:13:15 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Snap Websites Servers -- glob a directory and enumerate the files
       2             : // Copyright (c) 2016-2019  Made to Order Software Corp.  All Rights Reserved
       3             : //
       4             : // https://snapwebsites.org/
       5             : // contact@m2osw.com
       6             : //
       7             : // This program is free software; you can redistribute it and/or modify
       8             : // it under the terms of the GNU General Public License as published by
       9             : // the Free Software Foundation; either version 2 of the License, or
      10             : // (at your option) any later version.
      11             : //
      12             : // This program is distributed in the hope that it will be useful,
      13             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             : // GNU General Public License for more details.
      16             : //
      17             : // You should have received a copy of the GNU General Public License
      18             : // along with this program; if not, write to the Free Software
      19             : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      20             : //
      21             : #pragma once
      22             : 
      23             : // snapwebsites lib
      24             : //
      25             : #include "snapwebsites/snap_exception.h"
      26             : 
      27             : // snapdev lib
      28             : //
      29             : #include <snapdev/raii_generic_deleter.h>
      30             : 
      31             : // Qt lib
      32             : //
      33             : #include <QString>
      34             : 
      35             : // C++ lib
      36             : //
      37             : #include <functional>
      38             : #include <memory>
      39             : 
      40             : // C lib
      41             : //
      42             : #include <glob.h>
      43             : 
      44             : 
      45             : namespace snap
      46             : {
      47             : 
      48           0 : class glob_dir_exception : public snap_exception
      49             : {
      50             : public:
      51             :     // no sub-name
      52             :     explicit glob_dir_exception(int const error_num, char const *        what_msg) : snap_exception(what_msg), f_error_num(error_num) {}
      53             :     explicit glob_dir_exception(int const error_num, std::string const & what_msg) : snap_exception(what_msg), f_error_num(error_num) {}
      54           0 :     explicit glob_dir_exception(int const error_num, QString const &     what_msg) : snap_exception(what_msg), f_error_num(error_num) {}
      55             : 
      56             :     int get_error_num() const { return f_error_num; }
      57             : 
      58             : private:
      59             :     int f_error_num = -1;
      60             : };
      61             : 
      62             : 
      63           0 : class glob_dir
      64             : {
      65             : public:
      66           0 :     typedef std::unique_ptr<glob_t, raii_pointer_deleter<glob_t, decltype(&::globfree), &::globfree>> glob_pointer_t;
      67             : 
      68             :                     glob_dir();
      69             :                     glob_dir( char const * path, int const flags = 0, bool allow_empty = false );
      70             :                     glob_dir( std::string const & path, int const flags = 0, bool allow_empty = false );
      71             :                     glob_dir( QString const & path, int const flags = 0, bool allow_empty = false );
      72             : 
      73             :     void            set_path( char const * path, int const flags = 0, bool allow_empty = false );
      74             :     void            set_path( std::string const & path, int const flags = 0, bool allow_empty = false );
      75             :     void            set_path( QString const & path, int const flags = 0, bool allow_empty = false );
      76             : 
      77             :     void            enumerate_glob( std::function<void (std::string path)> func ) const;
      78             :     void            enumerate_glob( std::function<void (QString path)> func ) const;
      79             : 
      80             : private:
      81             :     glob_pointer_t  f_dir = glob_pointer_t();
      82             : };
      83             : 
      84             : } // namespace snap
      85             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13