--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COMMON_PLATFORM_ENUM_H_
+#define COMMON_PLATFORM_ENUM_H_
+
+#include "platform_result.h"
+
+#include <string>
+#include <map>
+#include <vector>
+#include <initializer_list>
+
+
+namespace common {
+
+
+template<typename NativeEnumType>
+class PlatformEnum
+{
+using MapType = std::map<std::string, NativeEnumType>;
+using RevMapType = std::map<NativeEnumType, std::string>;
+
+using MapTypeConstIter = typename MapType::const_iterator;
+
+public:
+ PlatformEnum(std::initializer_list<std::pair<const std::string, NativeEnumType>> m) : mapping_(m) {
+ for (auto it: mapping_) {
+ rev_mapping_[it.second] = it.first;
+ }
+ }
+
+ PlatformResult getName(NativeEnumType value, std::string* name) const {
+ auto it = rev_mapping_.find(value);
+ if (it != rev_mapping_.end()) {
+ *name = it->second;
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "enum value not registered");
+ }
+
+ PlatformResult getValue(std::string name, NativeEnumType* value) const {
+ auto it = mapping_.find(name);
+ if (it != mapping_.end()) {
+ *value = it->second;
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+ return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "enum name not registered");
+ }
+
+ MapTypeConstIter begin() const {
+ return mapping_.cbegin();
+ }
+
+ MapTypeConstIter end() const {
+ return mapping_.cend();
+ }
+
+private:
+ MapType mapping_;
+ RevMapType rev_mapping_;
+};
+
+
+} // common
+
+
+#endif // COMMON_PLATFORM_ENUM_H_