#ifndef HEPDIR_H
#define HEPDIR_H


// ----------------------------------------------------------------------
//
// HepDir.h - class declaration for FileManager Directories
//
//
// History:
//   24-Jul-1998  Philippe Canal  Initial Revision
//
// ----------------------------------------------------------------------

#ifndef ZMENVIRONMENT_H
  #include "ZMutility/ZMenvironment.h"
#endif

#include <string>

#ifndef  HEPOBJ_H
  #include "HepTuple/HepObj.h"
#endif


ZM_BEGIN_NAMESPACE( zmht )	/*  namespace zmht  {  */

class HepDir  :  public HepObj  {

  friend class HepFileManager;

protected:

  HepDir(                            // constructor
    HepFileManager * mgr
  , HepDir* parent
  , const std::string& title
  );

  // Used for dummy construction ...
  // the object is then not valid ...
  HepDir( );                         // default constructor

public:

  // type identifier ( is equal to type() for this object )
  static const char typeId;

  typedef std::vector<HepObj *> HepObjList;

  virtual ~HepDir();                 // destructor

  virtual std::string absTitle() const;         // return the absolute path.

  // utilities routines

  // top directory in path 
  static std::string topname(const std::string& path); 
  // all but the last level of path
  static std::string dirname(const std::string& path); 
  // last level of path  
  static std::string basename(const std::string& path);
  static bool isAbsPath(const std::string& path);
  static bool isRelPath(const std::string& path);

protected:

  virtual HepDir *makeDirClone(HepDir* parent, const std::string& title);
  // used ny mksubdir to create a new HepDir with the correct type
  // (if HepDir is sub-classed).

  virtual void rmdir(HepDir* subdir);
  // remove subdir from the list of sub-directory.  subdir HAS to be
  // an element of the list.

  virtual HepDir* mksubdir(const std::string& path); 
  // create a subdirectory with the relative name path
  // if path is a composite name ("sub1/sub2") sub1 needs to exist.
  virtual HepDir* getsubdir(const std::string& path) const; 
  // path HAS to be a relative path

  HepObjList::const_iterator findDir(const std::string& path) const;
  HepObjList::const_iterator findObj(const std::string& title) const;
  HepObjList::const_iterator findObj(int uid) const;

private:
  
  HepDir* up_;                       // parent directory
  HepObjList down_;                  // list of leaf directories
  HepObjList objList_;               // List of object in this directory

  // forbidden operations, hence private
  HepDir( const HepDir & );              // copy constructor
  HepDir & operator=( const HepDir & );  // assignment

};  // HepDir

ZM_END_NAMESPACE( zmht )	/*  }  // namespace zmht  */

#define HEPDIR_ICC
#include "HepTuple/HepDir.icc"
#undef HEPDIR_ICC

#endif  // HEPDIR_H
