1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef IMAGE_CODEC_FORMAT_H
17 #define IMAGE_CODEC_FORMAT_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <any>
22 #include <memory>
23 
24 namespace OHOS::ImagePlugin {
25 class Format {
26 public:
27     Format() = default;
28     ~Format() = default;
29     explicit Format(const Format& src);
30     Format& operator=(const Format& src);
31 
32     bool ContainKey(const std::string &key) const;
33 
34     template<typename T>
SetValue(const std::string & key,const T & value)35     void SetValue(const std::string &key, const T &value)
36     {
37         m_items[key] = value;
38     }
39 
40     template<typename T>
GetValue(const std::string & key,T & value)41     bool GetValue(const std::string &key, T &value) const
42     {
43         const auto it = m_items.find(key);
44         if (it == m_items.end()) {
45             return false;
46         }
47         value = std::any_cast<T>(it->second);
48         return true;
49     }
50 
51 private:
52     std::unordered_map<std::string, std::any> m_items;
53 };
54 }; // namespace OHOS::ImagePlugin
55 #endif // IMAGE_CODEC_FORMAT_H