1 /*
2  * Copyright (c) 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 FILEMGMT_LIBN_N_FUNC_ARG_H
17 #define FILEMGMT_LIBN_N_FUNC_ARG_H
18 
19 #include <functional>
20 #include <map>
21 #include <memory>
22 
23 #include "n_napi.h"
24 #include "n_val.h"
25 
26 namespace OHOS {
27 namespace FileManagement {
28 namespace LibN {
29 enum NARG_CNT {
30     ZERO = 0,
31     ONE,
32     TWO,
33     THREE,
34     FOUR,
35 };
36 
37 enum NARG_POS {
38     FIRST = 0,
39     SECOND,
40     THIRD,
41     FOURTH,
42 };
43 
44 class NFuncArg final {
45 public:
46     NFuncArg(napi_env env, napi_callback_info info);
47     virtual ~NFuncArg();
48 
49     bool InitArgs(size_t argc);
50     bool InitArgs(size_t minArgc, size_t maxArgc);
51     size_t GetArgc() const;
52     napi_value GetThisVar() const;
53     napi_value operator[](size_t idx) const;
54     napi_value GetArg(size_t argPos) const;
55 
56 private:
57     napi_env env_ = nullptr;
58     napi_callback_info info_ = nullptr;
59     size_t argc_ = 0;
60     std::unique_ptr<napi_value[]> argv_ = {nullptr};
61     napi_value thisVar_ = nullptr;
62 
63     bool InitArgs(std::function<bool()> argcChecker);
64     void SetArgc(size_t argc);
65     void SetThisVar(napi_value thisVar);
66 };
67 } // namespace LibN
68 } // namespace FileManagement
69 } // namespace OHOS
70 
71 #endif // FILEMGMT_LIBN_N_FUNC_ARG_H