• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = 1,
32     TWO = 2,
33     THREE = 3,
34     FOUR = 4,
35 };
36 
37 enum NARG_POS {
38     FIRST = 0,
39     SECOND = 1,
40     THIRD = 2,
41     FOURTH = 3,
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 
52     size_t GetArgc() const;
53     napi_value GetThisVar() const;
54 
55     napi_value operator[](size_t idx) const;
56     napi_value GetArg(size_t argPos) const;
57 
58 private:
59     napi_env env_ = nullptr;
60     napi_callback_info info_ = nullptr;
61 
62     size_t argc_ = 0;
63     std::unique_ptr<napi_value[]> argv_ = {nullptr};
64     napi_value thisVar_ = nullptr;
65 
66     bool InitArgs(std::function<bool()> argcChecker);
67 
68     void SetArgc(size_t argc);
69     void SetThisVar(napi_value thisVar);
70 };
71 } // namespace LibN
72 } // namespace FileManagement
73 } // namespace OHOS
74 
75 #endif // FILEMGMT_LIBN_N_FUNC_ARG_H