1 /* 2 * Copyright (c) 2021-2022 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 OHOS_ABILITY_BASE_ARRAY_WRAPPER_H 17 #define OHOS_ABILITY_BASE_ARRAY_WRAPPER_H 18 19 #include <functional> 20 #include <vector> 21 22 #include "base_object.h" 23 24 namespace OHOS { 25 namespace AAFwk { 26 class Array : public Object, public IArray { 27 public: 28 Array(long size, const InterfaceID &id); 29 ~Array()30 inline ~Array() 31 {} 32 33 IINTERFACE_DECL(); 34 35 ErrCode Get(long index, /* [in] */ 36 sptr<IInterface> &value) override; /* [out] */ 37 38 ErrCode GetLength(long &size) override; /* [out] */ 39 40 ErrCode GetType(InterfaceID &id) override; /* [out] */ 41 42 ErrCode Set(long index, /* [in] */ 43 IInterface *value) override; /* [in] */ 44 45 bool Equals(IObject &other) override; /* [in] */ 46 47 std::string ToString() override; 48 49 static sptr<IArray> Parse(const std::string &arrayStr); /* [in] */ 50 51 static bool IsBooleanArray(IArray *array); /* [in] */ 52 53 static bool IsCharArray(IArray *array); /* [in] */ 54 55 static bool IsByteArray(IArray *array); /* [in] */ 56 57 static bool IsShortArray(IArray *array); /* [in] */ 58 59 static bool IsIntegerArray(IArray *array); /* [in] */ 60 61 static bool IsLongArray(IArray *array); /* [in] */ 62 63 static bool IsFloatArray(IArray *array); /* [in] */ 64 65 static bool IsDoubleArray(IArray *array); /* [in] */ 66 67 static bool IsStringArray(IArray *array); /* [in] */ 68 69 static bool IsWantParamsArray(IArray *array); /* [in] */ 70 71 static void ForEach(IArray *array, /* [in] */ 72 std::function<void(IInterface *)> func); /* [in] */ 73 74 static constexpr char SIGNATURE = '['; 75 76 private: 77 static void ParseElement(IArray *array, /* [in] */ 78 std::function<sptr<IInterface>(std::string &)> func, /* [in] */ 79 const std::string &values, /* [in] */ 80 long size); /* [in] */ 81 82 std::vector<sptr<IInterface>> values_; 83 long size_; 84 InterfaceID typeId_; 85 86 static sptr<IArray> ParseString(const std::string &values, long size); 87 static sptr<IArray> ParseBoolean(const std::string &values, long size); 88 static sptr<IArray> ParseByte(const std::string &values, long size); 89 static sptr<IArray> ParseShort(const std::string &values, long size); 90 static sptr<IArray> ParseInteger(const std::string &values, long size); 91 static sptr<IArray> ParseLong(const std::string &values, long size); 92 static sptr<IArray> ParseFloat(const std::string &values, long size); 93 static sptr<IArray> ParseDouble(const std::string &values, long size); 94 static sptr<IArray> ParseChar(const std::string &values, long size); 95 static sptr<IArray> ParseArray(const std::string &values, long size); 96 static sptr<IArray> ParseWantParams(const std::string &values, long size); 97 }; 98 } // namespace AAFwk 99 } // namespace OHOS 100 #endif // OHOS_ABILITY_BASE_ARRAY_WRAPPER_H 101