g4tools  5.4.0
path_env
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_path_env
5 #define tools_path_env
6 
7 #include "put_env"
8 
9 #include "num2s"
10 #include "words"
11 #include "sep"
12 #include "vmanip"
13 
14 namespace tools {
15 
16 inline bool env_append(const std::string& a_env,const std::string& a_sep,const std::vector<std::string>& a_vals){
17  std::string env_value;
18  if(is_env(a_env)) {
19  if(!get_env(a_env,env_value)) return false;
20  }
21 
22  {std::vector<std::string>::const_iterator it;
23  for(it=a_vals.begin();it!=a_vals.end();++it) {
24  const std::string& value = *it;
25  if(value.empty()) continue;
26 
27  if(env_value.size()) {
28  std::vector<std::string> ws;
29  words(env_value,a_sep,false,ws);
30  // Remove existing one, so that value be put at end.
31  remove(ws,value);
32  if(!nums2s<std::string>(ws,env_value,a_sep)) {}
33  }
34 
35  if(env_value.size()) env_value += a_sep;
36  env_value += value;
37  }}
38 
39  if(!put_env(a_env,env_value)) return false;
40 
41  return true;
42 }
43 
44 inline bool env_path_append(const std::string& a_env,const std::vector<std::string>& a_paths){
45  return env_append(a_env,psep(),a_paths);
46 }
47 
48 inline bool env_append_path(const std::string& a_env,const std::string& a_path){
49  std::vector<std::string> v;
50  v.push_back(a_path);
51  return env_append(a_env,psep(),v);
52 }
53 
54 }
55 
56 #endif
tools::remove
bool remove(std::vector< T > &a_vals, const T &a_elem)
Definition: vmanip:119
tools::value
Definition: value:18
tools::get_env
bool get_env(const std::string &a_string, std::string &a_value)
Definition: get_env:18
tools::psep
const std::string & psep()
Definition: sep:20
num2s
tools::env_path_append
bool env_path_append(const std::string &a_env, const std::vector< std::string > &a_paths)
Definition: path_env:44
tools::env_append
bool env_append(const std::string &a_env, const std::string &a_sep, const std::vector< std::string > &a_vals)
Definition: path_env:16
tools::put_env
bool put_env(const std::string &a_env, const std::string &a_value)
Definition: put_env:15
tools::is_env
bool is_env(const std::string &a_string)
Definition: get_env:13
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
vmanip
tools::words
void words(const std::string &a_string, const std::string &a_sep, bool a_take_empty, std::vector< std::string > &a_words, bool a_clear=true)
Definition: words:12
words
tools::env_append_path
bool env_append_path(const std::string &a_env, const std::string &a_path)
Definition: path_env:48
sep
put_env