Add StrVar class (#1599)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 7 Jun 2018 09:39:20 +0000 (18:39 +0900)
committer서상민/동작제어Lab(SR)/Staff Engineer/삼성전자 <sangmin7.seo@samsung.com>
Thu, 7 Jun 2018 09:39:20 +0000 (18:39 +0900)
This commit adds StrVar class which reads string value from environment
(as it is). Default value will be used if corresponding environment variable
does not exists.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
tools/nnapi_unittests/inc/env.h
tools/nnapi_unittests/lib/env.cpp

index 8926dab..95b3875 100644 (file)
@@ -33,4 +33,16 @@ private:
   int32_t _value;
 };
 
+class StrVar
+{
+public:
+  StrVar(const std::string &name, const std::string &value);
+
+public:
+  const std::string &operator()(void) const { return _value; }
+
+private:
+  std::string _value;
+};
+
 #endif // __ENV_UTILS_H__
index efad443..f0646ed 100644 (file)
@@ -25,3 +25,18 @@ IntVar::IntVar(const std::string &name, int32_t value) : _value{value}
 {
   nnfw::util::env::IntAccessor{name}.access(_value);
 }
+
+//
+// String variable
+//
+#include <cstdlib>
+
+StrVar::StrVar(const std::string &name, const std::string &value) : _value{value}
+{
+  auto env = std::getenv(name.c_str());
+
+  if (env)
+  {
+    _value = std::string{env};
+  }
+}