PlasCom2  1.0
XPACC Multi-physics simluation application
UnixUtils.H
Go to the documentation of this file.
1 #ifndef _UNIX_UTIL_H_
7 #define _UNIX_UTIL_H_
8 
9 #include <sys/types.h>
10 #include <dirent.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <time.h>
14 #include <istream>
15 #include <ostream>
16 #include <streambuf>
17 #include <cstdio>
18 #include <cstring>
19 #include <vector>
20 #include <iostream>
21 #include <cstdlib>
22 #include <errno.h>
23 #include <sstream>
24 #include <sys/utsname.h>
25 
26 namespace ix {
27 
29  namespace sys {
30 
31  struct platform_info {
33  std::string hostName;
34  std::string operatingSystem;
35  std::string systemArchitecture;
37  int numCores;
39  std::string Pack()
40  {
41  std::ostringstream Ostr;
42  Ostr << (hostName.empty() ? "[NULL]" : hostName.c_str() ) << " "
43  << (operatingSystem.empty() ? "[NULL]" : operatingSystem.c_str() ) << " "
44  << (systemArchitecture.empty() ? "[NULL]" : systemArchitecture.c_str()) << " "
45  << numProcessors << " " << numCores << " " << numThreads;
46  return(Ostr.str());
47  };
48  void UnPack(const std::string &infoString)
49  {
50  std::istringstream Istr(infoString);
51  Istr >> hostName;
52  if(hostName == "[NULL]")
53  hostName.erase();
54  Istr >> operatingSystem;
55  if(operatingSystem == "[NULL]")
56  operatingSystem.erase();
57  Istr >> systemArchitecture;
58  if(systemArchitecture == "[NULL]")
59  systemArchitecture.erase();
60  Istr >> numProcessors >> numCores >> numThreads;
61  };
62  };
63 
64  std::ostream &operator<<(std::ostream &outStream,const platform_info &platformInfo);
65  platform_info PlatformInfo(const std::string &systemInfo);
66  std::string SystemInfo();
67  std::string LogTime();
68  void TokenizePath(std::vector<std::string> rv,const std::string &path);
69  std::string TempFileName(const std::string &stub);
70  int OpenTemp(std::string &stub);
71  const std::string Hostname(bool longname = false);
72  const std::string StripDirs(const std::string &);
73  const std::string CWD();
74  int SymLink(const std::string &source,const std::string &target);
75  void SafeRemove(const std::string &fname,const std::string &ext);
76  int ChDir(const std::string &path);
77  bool FILEEXISTS(const std::string &fname);
78  bool ISDIR(const std::string &fname);
79  bool ISLINK(const std::string &fname);
80  int CreateDirectory(const std::string &fname);
81  const std::string ResolveLink(const std::string &path);
82  int Remove(const std::string &fname);
83  int Rename(const std::string &source_file,const std::string &target_file);
84  class Directory : public std::vector<std::string>
85  {
86  private:
87  std::string _path;
88  bool _good;
89  DIR *_dir;
90  public:
91  Directory(const std::string &s = "");
92  ~Directory();
93  int open(const std::string &s = "");
94  void close();
95  operator void* ();
96  bool operator ! ();
97  };
98 
99 
100  class Environment : public std::vector< std::pair<std::string,std::string> >
101  {
102  public:
103  Environment();
104  int SetEnv(const std::string &,const std::string &,bool);
105  void UnSetEnv(const std::string &);
106 #ifndef DARWIN
107  int ClearEnv();
108 #endif
109  const std::string GetEnv(const std::string &) const;
110  std::string &GetEnv(const std::string &);
111  int PutEnv(char *);
112  void Refresh();
113  char **GetRawEnv();
114  private:
115  void init();
116  std::string empty_string;
117  };
118  };
119 };
120 #endif
std::string Pack()
Definition: UnixUtils.H:39
bool ISDIR(const std::string &fname)
Definition: UnixUtils.C:197
std::string _path
Definition: UnixUtils.H:87
int Remove(const std::string &fname)
Definition: UnixUtils.C:141
std::ostream & operator<<(std::ostream &outStream, const platform_info &platformInfo)
int ChDir(const std::string &path)
Definition: UnixUtils.C:297
Defines MPI-specific parallel global and program classes.
const std::string StripDirs(const std::string &)
Definition: UnixUtils.C:303
const std::string ResolveLink(const std::string &path)
Definition: UnixUtils.C:222
std::string hostName
Definition: UnixUtils.H:32
int OpenTemp(std::string &stub)
Definition: UnixUtils.C:333
std::string TempFileName(const std::string &stub)
Definition: UnixUtils.C:313
bool ISLINK(const std::string &fname)
Definition: UnixUtils.C:207
void SafeRemove(const std::string &fname, const std::string &ext)
Definition: UnixUtils.C:170
void UnPack(const std::string &infoString)
Definition: UnixUtils.H:48
int CreateDirectory(const std::string &fname)
Definition: UnixUtils.C:217
std::string LogTime()
Definition: UnixUtils.C:160
int SymLink(const std::string &source, const std::string &target)
Definition: UnixUtils.C:136
bool FILEEXISTS(const std::string &fname)
Definition: UnixUtils.C:189
std::string operatingSystem
Definition: UnixUtils.H:34
int Rename(const std::string &source_file, const std::string &target_file)
Definition: UnixUtils.C:132
const std::string Hostname(bool longname=false)
Definition: UnixUtils.C:17
std::string SystemInfo()
Definition: UnixUtils.C:99
const std::string CWD()
Definition: UnixUtils.C:291
std::string systemArchitecture
Definition: UnixUtils.H:35
std::string empty_string
Definition: UnixUtils.H:116
platform_info PlatformInfo(const std::string &systemInfo)
Definition: UnixUtils.C:45
void TokenizePath(std::vector< std::string > rv, const std::string &path)
Definition: UnixUtils.C:350