Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / cpp_interfaces / base / ie_memory_state_base.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <memory>
8 #include "details/ie_no_copy.hpp"
9 #include "ie_imemory_state.hpp"
10 #include "cpp_interfaces/exception2status.hpp"
11
12 namespace InferenceEngine {
13
14 /**
15  * @brief default implementation for IMemoryState
16  */
17 template <class T>
18 class MemoryStateBase : public IMemoryState  {
19 protected:
20     std::shared_ptr<T> impl;
21
22  public:
23     explicit MemoryStateBase(std::shared_ptr<T> impl) : impl(impl) {
24         if (impl == nullptr) {
25             THROW_IE_EXCEPTION << "MemoryStateBase implementation not defined";
26         }
27     }
28
29     StatusCode GetName(char *name, size_t len, ResponseDesc *resp) const noexcept override {
30         for (size_t i = 0; i != len; i++) {
31             name[i] = 0;
32         }
33         DescriptionBuffer buf(name, len);
34         TO_STATUS(buf << impl->GetName());
35         return OK;
36     }
37
38     StatusCode Reset(ResponseDesc *resp) noexcept override {
39         TO_STATUS(impl->Reset());
40     }
41
42     StatusCode SetState(Blob::Ptr newState, ResponseDesc *resp) noexcept override {
43         TO_STATUS(impl->SetState(newState));
44     }
45
46     StatusCode GetLastState(Blob::CPtr & lastState, ResponseDesc *resp) const noexcept override {
47         TO_STATUS(lastState = impl->GetLastState());
48     }
49 };
50
51 }  // namespace InferenceEngine