# 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  

new_path.h

Go to the documentation of this file.
00001 #if 0
00002 
00008 /* Copyright, 2000, 2001 Nevrax Ltd.
00009  *
00010  * This file is part of NEVRAX NEL.
00011  * NEVRAX NEL is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2, or (at your option)
00014  * any later version.
00015 
00016  * NEVRAX NEL is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00019  * General Public License for more details.
00020 
00021  * You should have received a copy of the GNU General Public License
00022  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00023  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00024  * MA 02111-1307, USA.
00025  */
00026 
00027 #ifndef NL_NEW_PATH_H
00028 #define NL_NEW_PATH_H
00029 
00030 #include "nel/misc/types_nl.h"
00031 
00032 #include <map>
00033 #include <string>
00034 #include <vector>
00035 
00036 namespace NLMISC {
00037 
00046 class CNewPath
00047 {
00048 public:
00063         static void                     addSearchPath (const std::string &path, bool recurse, bool alternative);
00064 
00066         static void                     addSearchPath (const std::string &path) { addSearchPath (path, false, true); }
00067 
00069         static void                     addSearchFile (const std::string &file, bool remap = false, const std::string &virtual_ext = "");
00070 
00072         static void                     addSearchListFile (const std::string &filename, bool recurse, bool alternative);
00073         
00075         static void                     addSearchBigFile (const std::string &filename, bool recurse, bool alternative);
00076 
00087         static std::string      lookup (const std::string &filename);
00088 
00091         static void clearMap ();
00092 
00098         static void remapExtension (const std::string &ext1, const std::string &ext2, bool substitute);
00099 
00100         static void display ();
00101 
00102 
00103 private:
00104 
00105         static CNewPath *getInstance ();
00106 
00107 
00108         static CNewPath *_Instance;
00109 
00110 private:
00111 
00112         std::vector<std::string> _Paths;
00113 
00114         // All path in this vector must have a terminated '/'
00115         std::vector<std::string> _AlternativePaths;
00116 
00117         struct CNewFileEntry
00118         {
00119                 CNewFileEntry (std::string      path, bool remapped, std::string ext) : Path(path), Remapped(remapped), Extension(ext) { }
00120                 std::string     Path;
00121                 bool            Remapped;               // true if the file is remapped
00122                 std::string     Extension;              // extention of the faile
00123         };
00124 
00128         std::map<std::string, CNewFileEntry> _Files;
00129 
00131         std::vector<std::pair<std::string, std::string> > _Extensions;
00132 
00133         sint            findExtension (const std::string &ext1, const std::string &ext2);
00134         static std::string      standardizePath (const std::string &path, bool addFinalSlash = true);
00135         static void             getPathContent (const std::string &path, bool recurse, bool wantDir, bool wantFile, std::vector<std::string> &result);
00136         static void             insertFileInMap (const std::string &filename, const std::string &filepath, bool remap, const std::string &extension);
00137 };
00138 
00139 
00140 
00147 struct CNewFile
00148 {
00153         static std::string getFilename (const std::string &filename);
00154 
00159         static std::string getPath (const std::string &filename);
00160 
00165         static bool isDirectory (const std::string &filename);
00166 
00172         static bool fileExists (const std::string &filename);
00173 
00179         static bool isExists (const std::string& filename);
00180 
00186         static std::string findNewFile (const std::string &filename);
00187 
00192         static int getLastSeparator (const std::string &filename);
00193 
00194         static std::string getFilenameWithoutExtension (const std::string &filename);
00195         static std::string getExtension (const std::string &filename);
00196 
00197 };
00198 
00199 
00200 
00201 
00202 } // NLMISC
00203 
00204 
00205 #endif // NL_NEW_PATH_H
00206 
00207 /* End of path.h */
00208 #enfif