Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:43

0001 /*
0002  * Copyright (c) 2019 Opticks Team. All Rights Reserved.
0003  *
0004  * This file is part of Opticks
0005  * (see https://bitbucket.org/simoncblyth/opticks).
0006  *
0007  * Licensed under the Apache License, Version 2.0 (the "License"); 
0008  * you may not use this file except in compliance with the License.  
0009  * You may obtain a copy of the License at
0010  *
0011  *   http://www.apache.org/licenses/LICENSE-2.0
0012  *
0013  * Unless required by applicable law or agreed to in writing, software 
0014  * distributed under the License is distributed on an "AS IS" BASIS, 
0015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0016  * See the License for the specific language governing permissions and 
0017  * limitations under the License.
0018  */
0019 
0020 #pragma once
0021 
0022 /**
0023 SPath
0024 ======
0025 
0026 **/
0027 
0028 #include <string>
0029 #include "plog/Severity.h"
0030 #include "SYSRAP_API_EXPORT.hh"
0031 
0032 enum { NOOP, FILEPATH, DIRPATH } ;
0033 
0034 struct SYSRAP_API SPath 
0035 {
0036     static const plog::Severity LEVEL ; 
0037     static const char* Stem( const char* name );
0038     static bool IsReadable(const char* base, const char* name);
0039     static bool IsReadable(const char* path);
0040     static const char* GetHomePath(const char* rel); 
0041     static const char* Dirname(const char* path); 
0042     static const char* Basename(const char* path); 
0043     static const char* ChangeName(const char* srcpath, const char* name) ;
0044 
0045     static int mtime(const char* base, const char* name); 
0046     static int mtime(const char* path); 
0047       
0048 
0049 
0050     static const char* UserTmpDir(const char* pfx="/tmp", const char* user_envvar="USER", const char* sub="opticks", char sep='/'  );
0051 
0052     // create_dirs:(0 do nothing, 1:assume file path, 2:assume dir path)
0053     static const char* Resolve(int create_dirs); 
0054     static const char* Resolve(const char* path, int create_dirs); 
0055     static const char* Resolve(const char* dir, const char* name, int create_dirs);
0056     static const char* Resolve(const char* dir, const char* reldir, const char* name, int create_dirs);
0057     static const char* Resolve(const char* dir, const char* reldir, const char* rel2dir, const char* name, int create_dirs);
0058     static const char* Resolve(const char* dir, const char* reldir, const char* rel2dir, const char* rel3dir, const char* name, int create_dirs);
0059 
0060 
0061     static const char* Resolve(const char* dir, int idx, int create_dirs); 
0062     static const char* Resolve(const char* dir, const char* name, int idx, int create_dirs); 
0063     static const char* Resolve(const char* dir, const char* reldir, const char* name, int idx, int create_dirs); 
0064 
0065 
0066     // mode:(0 do nothing, 1:assume file path, 2:assume dir path) 
0067     static void CreateDirs(const char* path, int mode); 
0068 
0069     static bool LooksLikePath(const char* path);
0070     static int MakeDirs( const char* path, int mode=0 ) ; 
0071     static void chdir(const char* path, int create_dirs=2 ); 
0072     static const char* getcwd() ; 
0073 
0074     static void MakeEmpty(const char* path_); 
0075     static bool Exists(const char* path_); 
0076     static bool Exists(const char* base, const char* relf); 
0077     static const char* PickFirstExisting(const char* path0, const char* path1, const char* path2=nullptr ); 
0078 
0079     static int Remove(const char* path_); 
0080 
0081     static void Copy( const char* dst , const char* src ); 
0082     static void Copy( const char* dstname, const char* srcname, const char* dir ); 
0083 
0084 
0085     template<typename T> static const char* MakePath( const char* prefix, const char* reldir, const T real, const char* name); 
0086 
0087 
0088     static std::string MakeName( const char* stem, int index, const char* ext ); 
0089     static const char* Make( const char* base, const char* reldir,                      const char* stem, int index, const char* ext, int create_dirs ); 
0090     static const char* Make( const char* base, const char* reldir, const char* reldir2, const char* stem, int index, const char* ext, int create_dirs ); 
0091 
0092     static const char* SearchDirUpTreeWithFile( const char* startdir, const char* relf ); 
0093 
0094 
0095     template<typename ... Args> static std::string Join_( Args ... args ); 
0096     template<typename ... Args> static const char* Join(  Args ... args ); 
0097 
0098 };
0099 
0100 
0101