// This file is part of PUMA.
// Copyright (C) 1999-2015  The PUMA developer team.
//                                                                
// This program is free software;  you can redistribute it and/or 
// modify it under the terms of the GNU General Public License as 
// published by the Free Software Foundation; either version 2 of 
// the License, or (at your option) any later version.            
//                                                                
// 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.  See the  
// GNU General Public License for more details.                   
//                                                                
// You should have received a copy of the GNU General Public      
// License along with this program; if not, write to the Free     
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
// MA  02111-1307  USA                                            

#ifndef PUMA_FilenameInfo_H
#define PUMA_FilenameInfo_H

/** \file
 * Filename information. */

#include "Puma/SmartPtr.h"
#include "Puma/DString.h"

namespace Puma {

/** \class FilenameInfo FilenameInfo.h Puma/FilenameInfo.h
 * Information about a filename supporting Puma::SmartPtr.
 * This object stores the name of the file, its path portion,
 * and the root portion if the filename is absolute.
 * \ingroup common */
class FilenameInfo : public SmartPtr<FilenameInfo>::RefCnt {
  DString m_name;
  const char *m_path;
  const char *m_root;

public:
  /** Constructor. */
  FilenameInfo()
      : m_path(0), m_root(0) {
  }
  /** Destructor. Frees the allocated strings. */
  ~FilenameInfo();
  /** Set a new filename.
   * \param filename The new filename. */
  void name(const char *filename);
  /** Get the filename.
   * \return The filename. */
  const char *name() const {
    return m_name.c_str();
  }
  /** Get the path portion of the filename.
   * \return The path to the file. */
  const char *path();
  /** Get the root of an absolute filename, i.e. everything
   * up to the first path delimiter. This is for instance the
   * drive portion of the filename on Windows (c:\). On Unix systems
   * this is simply a slash (/).
   * \return The root or NULL if filename is not absolute. */
  const char *root();
  /** Check whether the filename is absolute, i.e. starts at the
   * root of the file system.
   * \return True if the filename is absolute. */
  bool is_absolute() const;
  /** Check if this filename equals the given.
   * \param filename The other filename.
   * \return True if both filenames are equal. */
  bool operator==(const FilenameInfo &filename) const {
    return m_name == filename.m_name;
  }
};

} // namespace Puma

#endif /* PUMA_FilenameInfo_H */
