• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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  *     http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software
8  * distributed under the License is distributed on an "AS IS" BASIS,
9  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  * See the License for the specific language governing permissions and
11  * limitations under the License.
12  */
13 
14 #include "config_parser.h"
15 
16 namespace OHOS::Camera {
GetTypeId(const std::string & str,G_STREAM_INFO info,const int32_t & size) const17 std::optional<int32_t> ConfigParser::GetTypeId(const std::string& str, G_STREAM_INFO info, const int32_t& size) const
18 {
19     if (str.empty() || info == nullptr) {
20         return std::nullopt;
21     }
22 
23     for (int i = 0; i < size; i++) {
24         if (info[i].name != nullptr) {
25             if (std::string(info[i].name) == str) {
26                 return info[i].id;
27             }
28         }
29     }
30     return std::nullopt;
31 }
32 
GetTypeStr(const int32_t & type,G_STREAM_INFO info,const int32_t & size) const33 std::string ConfigParser::GetTypeStr(const int32_t& type, G_STREAM_INFO info, const int32_t& size) const
34 {
35     std::string result = "";
36     if (info == nullptr) {
37         CAMERA_LOGE("info is nullptr.");
38         return result;
39     }
40 
41     for (int i = 0; i < size; i++) {
42         if (((info + i) != nullptr) && (info[i].name != nullptr)) {
43             if (info[i].id == type) {
44                 result = info[i].name;
45                 break;
46             }
47         }
48     }
49     return result;
50 }
51 }