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 RS_PROFILER_COMMAND_H 17 #define RS_PROFILER_COMMAND_H 18 19 #include "rs_profiler_utils.h" 20 21 namespace OHOS::Rosen { 22 23 class ArgList final { 24 public: 25 explicit ArgList() = default; ArgList(std::vector<std::string> args)26 explicit ArgList(std::vector<std::string> args) : args_(std::move(args)) {} 27 Count() const28 size_t Count() const 29 { 30 return args_.size(); 31 } 32 Empty() const33 bool Empty() const 34 { 35 return args_.empty(); 36 } 37 Clear()38 void Clear() 39 { 40 args_.clear(); 41 } 42 String(size_t index = 0u) const43 const std::string& String(size_t index = 0u) const 44 { 45 static const std::string EMPTY; 46 return index < Count() ? args_[index] : EMPTY; 47 } 48 Int8(size_t index = 0u) const49 int8_t Int8(size_t index = 0u) const 50 { 51 return Utils::ToInt8(String(index)); 52 } 53 Int16(size_t index = 0u) const54 int16_t Int16(size_t index = 0u) const 55 { 56 return Utils::ToInt16(String(index)); 57 } 58 Int32(size_t index = 0u) const59 int32_t Int32(size_t index = 0u) const 60 { 61 return Utils::ToInt32(String(index)); 62 } 63 Int64(size_t index = 0u) const64 int64_t Int64(size_t index = 0u) const 65 { 66 return Utils::ToInt64(String(index)); 67 } 68 Uint8(size_t index = 0u) const69 uint8_t Uint8(size_t index = 0u) const 70 { 71 return Utils::ToUint8(String(index)); 72 } 73 Uint16(size_t index = 0u) const74 uint16_t Uint16(size_t index = 0u) const 75 { 76 return Utils::ToUint16(String(index)); 77 } 78 Uint32(size_t index = 0u) const79 uint32_t Uint32(size_t index = 0u) const 80 { 81 return Utils::ToUint32(String(index)); 82 } 83 Uint64(size_t index = 0u) const84 uint64_t Uint64(size_t index = 0u) const 85 { 86 return Utils::ToUint64(String(index)); 87 } 88 Fp32(size_t index = 0u) const89 float Fp32(size_t index = 0u) const 90 { 91 return Utils::ToFp32(String(index)); 92 } 93 Fp64(size_t index = 0u) const94 double Fp64(size_t index = 0u) const 95 { 96 return Utils::ToFp64(String(index)); 97 } 98 Pid(size_t index = 0u) const99 pid_t Pid(size_t index = 0u) const 100 { 101 return static_cast<pid_t>(Uint32(index)); 102 } 103 Node(size_t index = 0u) const104 uint64_t Node(size_t index = 0u) const 105 { 106 return Uint64(index); 107 } 108 109 protected: 110 std::vector<std::string> args_; 111 }; 112 113 } // namespace OHOS::Rosen 114 115 #endif // RS_PROFILER_COMMAND_H