Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

FileNameTmp.h

Go to the documentation of this file.
00001 #ifndef Impala_Basis_FileNameTmp_h
00002 #define Impala_Basis_FileNameTmp_h
00003 
00004 #include "Basis/String.h"
00005 #include "Basis/CmdOptions.h"
00006 
00007 namespace Impala
00008 {
00009 
00013 inline String
00014 GetTmpPath()
00015 {
00016     static String tempFolder("*");
00017     if(tempFolder == "*")
00018     {
00019         CmdOptions& options = CmdOptions::GetInstance();
00020         tempFolder = options.GetString("tmpPath");
00021         if(!tempFolder.empty())
00022         {
00023             if((tempFolder[tempFolder.size()-1] == '/') ||
00024                (tempFolder[tempFolder.size()-1] == '\\'))
00025             {
00026                 tempFolder = tempFolder.substr(0, tempFolder.size() - 1);
00027             }
00028             // if you are on Windows, then the path should just exist already
00029             // on *nix, we try to make the path for the user
00030 #ifdef unix
00031             String cmd = "mkdir -p " + tempFolder;
00032             system(cmd.c_str());
00033 #endif
00034         }
00035     }
00036     return tempFolder;
00037 }
00038 
00046 inline String
00047 PathJoin(String path1, String path2)
00048 {
00049     String a = StringReplace(path1, "\\", "/");
00050     String b = StringReplace(path2, "\\", "/");
00051     if(b[0] == '/')
00052     {
00053         return b;
00054     }
00055     if(a.empty())
00056     {
00057         return b;
00058     }
00059     if(a[a.size()-1] == '/')
00060     {
00061         return a + b;
00062     }
00063     else
00064     {
00065         return a + "/" + b;
00066     }
00067 }
00068 
00069 inline String
00070 PathJoin(String path1, String path2, String path3)
00071 {
00072     return PathJoin(path1, PathJoin(path2, path3));
00073 }
00074 
00075 inline String
00076 PathJoin(String path1, String path2, String path3, String path4)
00077 {
00078     return PathJoin(path1, PathJoin(path2, path3, path4));
00079 }
00080 
00081 inline String
00082 PathJoin(String path1, String path2, String path3, String path4, String path5)
00083 {
00084     return PathJoin(path1, PathJoin(path2, path3, path4, path5));
00085 }
00086 
00087 inline String
00088 FileNameTmp()
00089 {
00090     static int nr = 0;
00091     char hName[256];
00092 #ifdef unix
00093     gethostname(hName, 256);
00094     pid_t p = getpid();
00095 #else
00096     DWORD hNameSize = 256;
00097     GetComputerNameA(hName, &hNameSize);
00098     int p = getpid();
00099 #endif
00100     char res[256];
00101     sprintf(res, "tmpFile_%s_%d_%d", hName, p, nr++);
00102     return PathJoin(GetTmpPath(), String(res));
00103 }
00104 
00105 
00106 } // namespace Impala
00107 
00108 #endif

Generated on Fri Mar 19 09:30:42 2010 for ImpalaSrc by  doxygen 1.5.1