/* -*-c++-*- $Id$ */
/**
 * OsgAL - OpenSceneGraph Audio Library
 * Copyright (C) 2004 VRlab, Ume University
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */


#ifndef __OSGAL_FILEPATHCONTAINER_H__
#define __OSGAL_FILEPATHCONTAINER_H__

#ifdef _WIN32
  #pragma warning(disable:4786) // Disable warnings about long names
  #pragma warning(disable: 4251) // Disable warnings about exporting functions
#endif

#include <string>
#include <list>
#include <fstream>
#include <iostream>

namespace osgAL {

class FilePathContainer 
{

  #if defined(WIN32) && !defined(__CYGWIN__)
    #define FP_PATH_DELIMITER ";"
  #else
    #define FP_PATH_DELIMITER ":"
  #endif


public:
  /** Constructor */
  FilePathContainer();

  /** Constructor - set the file path found in given environment variable */
  FilePathContainer(const std::string& env);

  /** Destructor */
  ~FilePathContainer();

  /** Set the file path using a single string deliminated with given delimitor */
  void setFilePathList(const std::string& paths, const std::string& delimitor = FP_PATH_DELIMITER); 

  /** Set the file path found in given environment variable - returns true if env var found */
  bool setEnvironmentVariable(const std::string& env);

  /** Set the file path directly */
  void setFilePath(const std::string& path);
  
  /** Adds a list of paths to the previous one */
  void FilePathContainer::addFilePath(const std::string& path);

  /**  Adds a filepath to the end of the list */
  void pushbackPath(const std::string& path);

  /**  Adds a filepath to the beginning of the list */
  void pushfrontPath(const std::string& path);

  /** Get file path list */
  std::list<std::string>& getFilePathList();

  /** Get directory from path */
  std::string extractDirectory(const std::string& path);

  /** Get filename from path */
  std::string extractFilename(const std::string& path);

  /** Return path to given filename if file exists in any directory */
  std::string findFile(const std::string& filename);

private:

  /** Path list */
  typedef  std::list<std::string>  PathList;
  PathList m_path_list;


  /** Convert given string to list with sub strings (seperated by delimitor in string) */
  void convertStringToList(const std::string& str, PathList& lst, const std::string& delimitor);


  /** Delimitor used when parsing environment varaible */
  std::string m_delimiter;

};

} // namespace osgAL

#endif // _FILEPATHCONTAINER_H

/*------------------------------------------

* $Source$
* $Revision$ 
* $Date$
* $Author$ 
* $Locker$

* Description: 
 
 Copyright (C) Peter Sunna, VRlab, Ume University 2002

 Created: 2002-06-26

* $Log$
* Revision 1.1.1.2  2004/12/07 18:15:08  loic
* upstream update osgal-v022-041121.tgz
*
* Revision 1.4  2004/11/19 07:46:09  andersb
* *** empty log message ***
*
* Revision 1.3  2004/04/20 12:26:03  andersb
* Added SoundRoot
*
* Revision 1.2  2004/03/05 09:42:30  andersb
* *** empty log message ***
*
* Revision 1.1  2004/03/03 07:50:49  andersb
* *** empty log message ***
*
*
----------------------------------------------------------------------------*/

