DDS  ver. 1.6
dds_env_prop.h
Go to the documentation of this file.
1 // Copyright 2015 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef DDSENVPROP_H_
6 #define DDSENVPROP_H_
7 
8 // STD
9 #include <cstdlib>
10 #include <string>
11 
12 namespace dds
13 {
15  enum EEnvProp
16  {
26  };
27 
36  template <EEnvProp T>
37  inline typename std::enable_if<T == task_id, uint64_t>::type env_prop()
38  {
39  size_t ret(0);
40  std::string envName;
41  switch (T)
42  {
43  case task_id:
44  envName = "DDS_TASK_ID";
45  break;
46  default:
47  return 0;
48  }
49  const char* env = std::getenv(envName.c_str());
50  if (nullptr == env)
51  return ret;
52 
53  try
54  {
55  ret = std::stoul(env);
56  }
57  catch (...)
58  {
59  return 0;
60  }
61 
62  return ret;
63  }
64 
73  template <EEnvProp T>
74  inline typename std::enable_if<T == task_index || T == collection_index, size_t>::type env_prop()
75  {
76  size_t ret(0);
77  std::string envName;
78  switch (T)
79  {
80  case task_index:
81  envName = "DDS_TASK_INDEX";
82  break;
83  case collection_index:
84  envName = "DDS_COLLECTION_INDEX";
85  break;
86  default:
87  return 0;
88  }
89  const char* env = std::getenv(envName.c_str());
90  if (nullptr == env)
91  return ret;
92 
93  try
94  {
95  ret = std::stoi(env);
96  }
97  catch (...)
98  {
99  return 0;
100  }
101 
102  return ret;
103  }
104 
113  template <EEnvProp T>
114  inline typename std::enable_if<T == task_name || T == collection_name || T == group_name || T == dds_location ||
115  T == task_path,
116  std::string>::type
118  {
119  std::string envName;
120  switch (T)
121  {
122  case task_name:
123  envName = "DDS_TASK_NAME";
124  break;
125  case collection_name:
126  envName = "DDS_COLLECTION_NAME";
127  break;
128  case group_name:
129  envName = "DDS_GROUP_NAME";
130  break;
131  case dds_location:
132  envName = "DDS_LOCATION";
133  break;
134  case task_path:
135  envName = "DDS_TASK_PATH";
136  break;
137  default:
138  return 0;
139  }
140  const char* env = std::getenv(envName.c_str());
141  if (nullptr == env)
142  return "";
143 
144  return std::string(env);
145  }
146 };
147 
148 #endif /*DDSENVPROP_H_*/
associated with $DDS_COLLECTION_NAME - ID of the parent collection.
Definition: dds_env_prop.h:23
associated with $DDS_TASK_PATH - full path to the user task, for example, main/group1/collection_12/t...
Definition: dds_env_prop.h:20
std::enable_if< T==task_id, uint64_t >::type env_prop()
The function returns a value for a given environment property.
Definition: dds_env_prop.h:37
Definition: dds-agent/src/AgentConnectionManager.h:16
associated with $DDS_TASK_ID environment variable.
Definition: dds_env_prop.h:17
associated with $DDS_GROUP_NAME - ID of the parent group.
Definition: dds_env_prop.h:24
EEnvProp
a list of envioronment properties
Definition: dds_env_prop.h:15
associated with $DDS_TASK_NAME - ID of the task.
Definition: dds_env_prop.h:19
associated with $DDS_TASK_INDEX environment variable.
Definition: dds_env_prop.h:18
associated with $DDS_COLLECTION_INDEX environemnt variable.
Definition: dds_env_prop.h:22
associated with $DDS_LOCATION environemnt variable.
Definition: dds_env_prop.h:25