// ---------------------------------------------------------------------------
// - Directory.hpp                                                           -
// - afnix:sio library - directory class definition                          -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - This program  is  distributed in  the hope  that it will be useful, but -
// - without  any  warranty;  without  even   the   implied    warranty   of -
// - merchantability or fitness for a particular purpose.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2005 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_DIRECTORY_HPP
#define  AFNIX_DIRECTORY_HPP

#ifndef  AFNIX_LIST_HPP
#include "List.hpp"
#endif

namespace afnix {

  /// The Directory class provides facilities to access a directory
  /// and retreive its contents. The directory contents is returned as
  /// a vector of names. The default constructor opens the '.' directory.
  /// @author amaury darsch

  class Directory : public Object {
  private:
    /// the directory name
    String d_name;
    /// the directory handle
    void* p_handle;

  public:
    /// open the default directory
    Directory (void);

    /// open a directory by name
    /// @param name the directory to open
    Directory (const String& name);

    /// destroy this directory accessor
    ~Directory (void);

    /// @return the class name
    String repr (void) const;

    /// @return the directory name
    String getname (void) const {
      return d_name;
    }

    /// @return a list of this directory names
    List* getlist (void);

    /// @return a list of this directory files
    List* getfiles (void);

    /// @return a list of sub directories
    List* getdirs (void);

    /// create a new directory by name
    /// @param name the directory name
    void mkdir (const String& name);

    /// remove a directory by name
    /// @param name the directory to remove
    void rmdir (const String& name);

    /// remove a file by name
    /// @param name the file to remove
    void rmfile (const String& name);

    /// generate a new directory
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);

    /// apply this directory with a set of arguments and a quark
    /// @param robj  the current runnable
    /// @param nset  the current nameset    
    /// @param quark the quark to apply these arguments
    /// @param argv  the arguments to apply
    Object* apply (Runnable* robj, Nameset* nset, const long quark,
		   Vector* argv);

  private:
    // make the copy constructor private
    Directory (const Directory&);
    // make the assignment operator private
    Directory& operator = (const Directory&);
  };
}

#endif
