inlib  1.2.0
Public Types | Public Member Functions | Protected Attributes
inlib::dir::tree Class Reference

List of all members.

Public Types

typedef bool(* match_func )(const std::string &, const std::string &)

Public Member Functions

 tree (std::ostream &a_out)
virtual ~tree ()
 tree (const tree &a_from)
treeoperator= (const tree &a_from)
void set_path (const std::string &a_path)
void set_match_func (match_func a_func)
bool build (const std::string &a_pattern="")
bool visit (visitor &a_visitor)

Protected Attributes

std::ostream & m_out
std::string m_path
std::vector< tree * > m_dirs
std::vector< std::string > m_files
match_func m_match_func

Detailed Description

Definition at line 366 of file dir.


Member Typedef Documentation

typedef bool(* inlib::dir::tree::match_func)(const std::string &, const std::string &)

Definition at line 368 of file dir.


Constructor & Destructor Documentation

inlib::dir::tree::tree ( std::ostream &  a_out) [inline]

Definition at line 370 of file dir.

:m_out(a_out),m_match_func(0){}
virtual inlib::dir::tree::~tree ( ) [inline, virtual]

Definition at line 371 of file dir.

                  {
   {std::vector<tree*>::iterator it;
    for(it=m_dirs.begin();it!=m_dirs.end();++it) delete *it;
    m_dirs.clear();}
  }
inlib::dir::tree::tree ( const tree a_from) [inline]

Definition at line 377 of file dir.

                          :m_out(a_from.m_out) {    
    m_path = a_from.m_path;
    m_files = a_from.m_files;
   {std::vector<tree*>::const_iterator it;
    for(it=a_from.m_dirs.begin();it!=a_from.m_dirs.end();++it) {
      m_dirs.push_back(new tree(*(*it)));
    }}
  }

Member Function Documentation

bool inlib::dir::tree::build ( const std::string &  a_pattern = "") [inline]

Definition at line 404 of file dir.

                                              {
    if(m_path.empty()) {
      m_out << "tree::build :"
            << " empty path."
            << std::endl;
      return false;
    }
    std::vector<std::string> files;
    if(!entries(m_path,files)) {
      m_out << "tree::build :"
            << " dir::entries failed for \"" << m_path << "\"."
            << std::endl;
      return false;
    }
    //printf("debug : build : \"%s\" %d files.\n",
    //       aTree.path().c_str(),(int)files.size());
    std::vector<std::string>::iterator it;
    for(it=files.begin();it!=files.end();++it) {
      const std::string& name = *it;
      bool is;
      if(!is_a(name,is)) {
        m_out << "tree::build :"
              << " is_a failed for \"" << name << "\"."
              << std::endl;
        return false;
      }
      if(is) {
        if(is_dot(name)) {
          //bypass dot directories.
        } else {
          tree* dir = new tree(m_out);
          m_dirs.push_back(dir);
          dir->set_path(name);
          dir->set_match_func(m_match_func);
          if(!dir->build(a_pattern)) return false;
        }
      } else {
        if( (a_pattern.empty()) || (a_pattern=="*") ) {
          m_files.push_back(name);
        } else {
          if(!m_match_func) {
            m_out << "tree::build :"
                  << " pattern given but no match function given."
                  << std::endl;
            return false;
          }
          bool ok = m_match_func(name,a_pattern);
          //printf("debug : build : \"%s\" match \"%s\" ? %d\n",
          //       name.c_str(),a_pattern.c_str(),ok);
          if(ok) m_files.push_back(name);
        }
      }
    }
    return true;
  }
tree& inlib::dir::tree::operator= ( const tree a_from) [inline]

Definition at line 385 of file dir.

                                      {    
    m_path = a_from.m_path;
    m_files = a_from.m_files;

   {std::vector<tree*>::iterator it;
    for(it=m_dirs.begin();it!=m_dirs.end();++it) delete *it;
    m_dirs.clear();}
    
   {std::vector<tree*>::const_iterator it;
    for(it=a_from.m_dirs.begin();it!=a_from.m_dirs.end();++it) {
      m_dirs.push_back(new tree(*(*it)));
    }}

    return *this;
  }
void inlib::dir::tree::set_match_func ( match_func  a_func) [inline]

Definition at line 402 of file dir.

{m_match_func = a_func;}
void inlib::dir::tree::set_path ( const std::string &  a_path) [inline]

Definition at line 401 of file dir.

{m_path = a_path;}
bool inlib::dir::tree::visit ( visitor a_visitor) [inline]

Definition at line 460 of file dir.

                                 {
    if(m_path.empty()) return true;
    bool process;
    if(!a_visitor.directory(m_path,process)) return false;
    if(!process) return true;
   {std::vector<std::string>::iterator it;
    for(it=m_files.begin();it!=m_files.end();++it) {
      if(!a_visitor.file(*it)) return false;
    }}
   {std::vector<tree*>::iterator it;
    for(it=m_dirs.begin();it!=m_dirs.end();++it) {
      if(!(*it)->visit(a_visitor)) return false;
    }}
    return true;
  }

Member Data Documentation

std::vector<tree*> inlib::dir::tree::m_dirs [protected]

Definition at line 478 of file dir.

std::vector<std::string> inlib::dir::tree::m_files [protected]

Definition at line 479 of file dir.

Definition at line 480 of file dir.

std::ostream& inlib::dir::tree::m_out [protected]

Definition at line 476 of file dir.

std::string inlib::dir::tree::m_path [protected]

Definition at line 477 of file dir.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines