# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NLMISC::CPath Class Reference

Utility class for searching files in differents paths. More...

#include <path.h>

List of all members.

Static Public Methods

void addSearchPath (const std::string &path, bool recurse, bool alternative)
 Adds a search path. More...

void addSearchPath (const std::string &path)
 Used only for compatibility with the old CPath. More...

void addSearchFile (const std::string &file, bool remap=false, const std::string &virtual_ext="")
 Same as AddSearchPath but with a file "c:/autoexec.bat" this file only will included. More...

void addSearchListFile (const std::string &filename, bool recurse, bool alternative)
 Same as AddSearchPath but with a path file "c:/test.pth" all files name contain in this file will be included (the extention is used to know that it's a path file). More...

void addSearchBigFile (const std::string &filename, bool recurse, bool alternative)
 Same as AddSearchPath but with a big file "c:/test.nbf" all files name contain in the big file will be included (the extention (Nel Big File) is used to know that it's a big file). More...

void removeAllAlternativeSearchPath ()
 Remove all search path contains in the alternative directories. More...

std::string lookup (const std::string &filename, bool throwException=true, bool displayWarning=true, bool lookupInLocalDirectory=true)
 Returns the long name (path + filename) for the specified file. More...

bool exists (const std::string &filename)
 Return if a file is present in the lookup map. More...

void clearMap ()
 Clears the map that contains all cached files (Use this function to take into account new files). More...

void remapExtension (const std::string &ext1, const std::string &ext2, bool substitute)
 Add a remapping function to allow file extension substitution. More...

void display ()
std::string standardizePath (const std::string &path, bool addFinalSlash=true)
 Take a path and put it in the portable format and add a terminated / if needed ie: "C:\Game/dir1" will become "C:/Game/dir1/" or "C:/Game/dir1" if addFinalSlash is false. More...

std::string standardizeDosPath (const std::string &path)
 Remplace / with \ for fucking dos process. More...

void getPathContent (const std::string &path, bool recurse, bool wantDir, bool wantFile, std::vector< std::string > &result)
 List all files in a directory. More...

std::string getFullPath (const std::string &path, bool addFinalSlash=true)
 Get the full path based on a file/path and the current directory. More...

std::string getCurrentPath ()
 Returns the current path of the applicated. More...

void getFileList (const std::string &extension, std::vector< std::string > &filenames)
 Create a list of file having the requested extension. More...


Private Methods

sint findExtension (const std::string &ext1, const std::string &ext2)

Static Private Methods

CPath * getInstance ()
void insertFileInMap (const std::string &filename, const std::string &filepath, bool remap, const std::string &extension)

Private Attributes

std::vector< std::string > _AlternativePaths
std::map< std::string, CFileEntry_Files
 first is the filename, second the full path for the filename. More...

std::vector< std::pair< std::string,
std::string > > 
_Extensions
 first ext1, second ext2 (ext1 could remplace ext2). More...


Static Private Attributes

CPath * _Instance = NULL


Detailed Description

Utility class for searching files in differents paths.

Warning:
addSearchPath(), clearMap() and remapExtension() are not reentrant.
all path and files are *case sensitive* on linux.
Author:
Vianney Lecroart , Nevrax France
Date:
2001

Definition at line 54 of file path.h.


Member Function Documentation

void NLMISC::CPath::addSearchBigFile const std::string &    filename,
bool    recurse,
bool    alternative
[static]
 

Same as AddSearchPath but with a big file "c:/test.nbf" all files name contain in the big file will be included (the extention (Nel Big File) is used to know that it's a big file).

Definition at line 800 of file path.cpp.

References NLMISC::BF_ALWAYS_OPENED, NLMISC::BF_CACHE_FILE_ON_OPEN, insertFileInMap, nlwarning, and NLMISC::strlwr.

Referenced by addSearchFile.

void NLMISC::CPath::addSearchFile const std::string &    file,
bool    remap = false,
const std::string &    virtual_ext = ""
[static]
 

Same as AddSearchPath but with a file "c:/autoexec.bat" this file only will included.

wildwards *doesn't* work

Definition at line 708 of file path.cpp.

References addSearchBigFile, file, insertFileInMap, NL_DISPLAY_PATH, nlwarning, standardizePath, and NLMISC::strlwr.

Referenced by addSearchPath.

void NLMISC::CPath::addSearchListFile const std::string &    filename,
bool    recurse,
bool    alternative
[static]
 

Same as AddSearchPath but with a path file "c:/test.pth" all files name contain in this file will be included (the extention is used to know that it's a path file).

Definition at line 772 of file path.cpp.

References nlwarning.

void NLMISC::CPath::addSearchPath const std::string &    path [inline, static]
 

Used only for compatibility with the old CPath.

In this case, we don't use the map to have the same behavior as the old CPath

Definition at line 76 of file path.h.

References addSearchPath.

void NLMISC::CPath::addSearchPath const std::string &    path,
bool    recurse,
bool    alternative
[static]
 

Adds a search path.

The path is a directory "c:/temp" all files in the directory will be included (and recursively if asked)

Alternative directories are not precached (instead of non Alternative files) and will used when a file is not found in the standard directories. For example, local data will be in the cached directories and server repository files will be in the Alternative files. If a new file is not found in the local data, we'll try to find it on the repositrory.

When Alternative is false, all added file names must be uniq or a warning will be display. In the Alternative directories, it could have more than one file with the same name.

Warning:
the path you provide is case sensitive, you must be sure that the path name is exactly the same
Parameters:
path  the path name. The separator for directories could be '/' or '\' (bit '\' will be translate into '/' in the function).
recurse  true if you want the function recurse in sub-directories.
Alternative  true if you want to add the path in the Alternative directories.

Definition at line 623 of file path.cpp.

References addSearchFile, addSearchPath, getPathContent, H_AUTO_INST, NL_DISPLAY_PATH, nlinfo, nlwarning, and standardizePath.

Referenced by addSearchPath.

void NLMISC::CPath::clearMap   [static]
 

Clears the map that contains all cached files (Use this function to take into account new files).

Definition at line 107 of file path.cpp.

References NL_DISPLAY_PATH.

void NLMISC::CPath::display   [static]
 

Definition at line 910 of file path.cpp.

References nlinfo.

bool NLMISC::CPath::exists const std::string &    filename [static]
 

Return if a file is present in the lookup map.

The function changes filename into lower case and removes ended spaces before searching.

Warning:
This function checks *only* in the map, not in local dir or alternative dir
Parameters:
filename  the file name you are seeking. (ex: "test.txt")
lookupInLocalDirectory  if true, the lookup() will first try to open the file without path.
Returns:
true if the filename exists in the map used by lookup to know where the file is, false otherwise

Definition at line 274 of file path.cpp.

References NLMISC::strlwr.

sint NLMISC::CPath::findExtension const std::string &    ext1,
const std::string &    ext2
[private]
 

Definition at line 114 of file path.cpp.

std::string NLMISC::CPath::getCurrentPath   [static]
 

Returns the current path of the applicated.

Definition at line 349 of file path.cpp.

Referenced by getFullPath.

void NLMISC::CPath::getFileList const std::string &    extension,
std::vector< std::string > &    filenames
[static]
 

Create a list of file having the requested extension.

Definition at line 85 of file path.cpp.

References _Files, and getInstance.

Referenced by loadForm.

std::string NLMISC::CPath::getFullPath const std::string &    path,
bool    addFinalSlash = true
[static]
 

Get the full path based on a file/path and the current directory.

Example, imagine that the current path is c:\temp and toto is a directory getFullPath ("toto") returns "c:/temp/toto/" getFullPath ("../toto") returns "c:/temp/../toto/" getFullPath ("d:\dir\toto") returns "d:/dir/toto/" getFullPath ("\toto") returns "c:/toto/" getFullPath ("") returns "c:/temp/"

Parameters:
path  the path
Returns:
the full path

Definition at line 360 of file path.cpp.

References getCurrentPath, and standardizePath.

CPath * NLMISC::CPath::getInstance   [static, private]
 

Definition at line 98 of file path.cpp.

References _Instance.

Referenced by getFileList.

void NLMISC::CPath::getPathContent const std::string &    path,
bool    recurse,
bool    wantDir,
bool    wantFile,
std::vector< std::string > &    result
[static]
 

List all files in a directory.

Parameters:
path  path where files are scanned (MUST NOT BE EMPTY)
recurse  true if want to recurs directories
wantDir  true if want to add directorires in result
wantFile  true if want to add files in result
result  list of string where directories/files names are added.

Definition at line 523 of file path.cpp.

References NLMISC::BasePathgetPathContent, NLMISC::getname, NLMISC::isdirectory, NLMISC::isfile, NL_DISPLAY_PATH, and standardizePath.

Referenced by addSearchPath, and NL3D::CAnimationSet::loadFromFiles.

void NLMISC::CPath::insertFileInMap const std::string &    filename,
const std::string &    filepath,
bool    remap,
const std::string &    extension
[static, private]
 

Definition at line 881 of file path.cpp.

References NL_DISPLAY_PATH, nlinfo, nlwarning, and NLMISC::strlwr.

Referenced by addSearchBigFile, addSearchFile, and remapExtension.

string NLMISC::CPath::lookup const std::string &    filename,
bool    throwException = true,
bool    displayWarning = true,
bool    lookupInLocalDirectory = true
[static]
 

Returns the long name (path + filename) for the specified file.

The directory separator is always '/'. First, the lookup() lookups in standard directories (Alternative=false). If not found, it lookups in the Alternative directories. If not found the lookup() returns empty string "" (and generate an exception if throwException is true)

The filename is not case sensitive so if the real filename is "FooBAR.Jpg" and you call lookup("fOOBar.jPg"), it'll return the real filename "FooBAR.Jpg"

Parameters:
filename  the file name you are seeking. (ex: "test.txt")
throwException  used for backward compatibility, set to true to generate an EPathNotFound.
displayWarning  set to false if you don't want the function displays a warning if the file is not found
lookupInLocalDirectory  if true, the lookup() will first try to open the file without path.
Returns:
empty string if file is not found or the full path + file name (ex: "c:/temp/test.txt");

Definition at line 201 of file path.cpp.

References NL_DISPLAY_PATH, nlwarning, s, and NLMISC::strlwr.

Referenced by NL3D::CAnimationSetUser::addAnimation, NL3D::CAnimationSetUser::addSkeletonWeight, NL3D::UAnimation::createAnimation, and loadForm.

void NLMISC::CPath::remapExtension const std::string &    ext1,
const std::string &    ext2,
bool    substitute
[static]
 

Add a remapping function to allow file extension substitution.

  • eg remapExtension("dds", "tga", true) Where the boolean indicates whether the "dds" should replace a "tga" if one exists - again - a warning should be generated if the two are present.
ie: If you have a file called pic.dds and you call remapExtension("dds", "tga", true), if you call lookup("pic.tga"), it'll return "pic.dds"

Definition at line 127 of file path.cpp.

References file, insertFileInMap, NL_DISPLAY_PATH, nlassert, nlwarning, and NLMISC::strlwr.

void NLMISC::CPath::removeAllAlternativeSearchPath   [static]
 

Remove all search path contains in the alternative directories.

Definition at line 615 of file path.cpp.

References NL_DISPLAY_PATH.

std::string NLMISC::CPath::standardizeDosPath const std::string &    path [static]
 

Remplace / with \ for fucking dos process.

Use only this function if can't do another way. For exemple, if you do a system("copy data/toto data/tata"); it'll not work because dos doesn't understand /. But in the majority of case, / working (it works for fopen for example)

Definition at line 327 of file path.cpp.

string NLMISC::CPath::standardizePath const std::string &    path,
bool    addFinalSlash = true
[static]
 

Take a path and put it in the portable format and add a terminated / if needed ie: "C:\Game/dir1" will become "C:/Game/dir1/" or "C:/Game/dir1" if addFinalSlash is false.

Definition at line 296 of file path.cpp.

Referenced by addSearchFile, addSearchPath, getFullPath, and getPathContent.


Member Data Documentation

std::vector<std::string> NLMISC::CPath::_AlternativePaths [private]
 

Definition at line 185 of file path.h.

std::vector<std::pair<std::string, std::string> > NLMISC::CPath::_Extensions [private]
 

first ext1, second ext2 (ext1 could remplace ext2).

Definition at line 201 of file path.h.

std::map<std::string, CFileEntry> NLMISC::CPath::_Files [private]
 

first is the filename, second the full path for the filename.

Due to the remapping, first and second.path could have different extention.

Definition at line 198 of file path.h.

Referenced by getFileList.

CPath * NLMISC::CPath::_Instance = NULL [static, private]
 

Definition at line 78 of file path.cpp.

Referenced by getInstance.


The documentation for this class was generated from the following files: