1c7a70340d24618df1441531b115c79a094a95b0
[platform/core/uifw/aurum.git] / bootstrap / server / src / ObjectMapper.cc
1 #include "ObjectMapper.h"
2
3 ObjectMapper::ObjectMapper() : mObjectMap{}, mObjCounter{0} {}
4
5 ObjectMapper::~ObjectMapper() {}
6
7 ObjectMapper *ObjectMapper::getInstance()
8 {
9     static ObjectMapper *mInstance = new ObjectMapper();
10     return mInstance;
11 }
12
13 std::string ObjectMapper::addElement(std::unique_ptr<UiObject> object)
14 {
15     ++mObjCounter;
16     std::string key = std::to_string(mObjCounter);
17     mObjectMap[key] = std::move(object);
18     return key;
19 }
20
21 UiObject *ObjectMapper::getElement(const std::string &key)
22 {
23     unsigned long long keyCnt = (unsigned long long)std::stoi(key); // this key is a result of calling std:to_string(mObjCounter)
24     if (keyCnt <= 0 || keyCnt > mObjCounter) return nullptr;
25     if (mObjectMap.count(key)) {
26         UiObject *obj = mObjectMap[key].get();
27         const_cast<const UiObject *>(obj)->refresh();
28         return obj;
29     }
30     return nullptr;
31 }