• 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 OHOS_IDL_OPTIONS_H
17 #define OHOS_IDL_OPTIONS_H
18 
19 #include "util/string.h"
20 
21 namespace OHOS {
22 namespace Idl {
23 class Options {
24 public:
Options(int argc,char ** argv)25     Options(int argc, char** argv)
26     {
27         Parse(argc, argv);
28     }
29 
30     ~Options() = default;
31 
DoShowUsage()32     bool DoShowUsage() const
33     {
34         return doShowUsage_;
35     }
36 
DoShowVersion()37     bool DoShowVersion() const
38     {
39         return doShowVersion_;
40     }
41 
DoCompile()42     bool DoCompile() const
43     {
44         return doCompile_;
45     }
46 
DoDumpAST()47     bool DoDumpAST() const
48     {
49         return doDumpAST_;
50     }
51 
DoDumpMetadata()52     bool DoDumpMetadata() const
53     {
54         return doDumpMetadata_;
55     }
56 
DoSaveMetadata()57     bool DoSaveMetadata() const
58     {
59         return doSaveMetadata_;
60     }
61 
DoGenerateCode()62     bool DoGenerateCode() const
63     {
64         return doGenerateCode_;
65     }
66 
HasErrors()67     bool HasErrors() const
68     {
69         return !illegalOptions_.IsEmpty() || sourceFile_.IsEmpty();
70     }
71 
GetSourceFile()72     String GetSourceFile() const
73     {
74         return sourceFile_;
75     }
76 
GetMetadataFile()77     String GetMetadataFile() const
78     {
79         return metadataFile_;
80     }
81 
GetTargetLanguage()82     String GetTargetLanguage() const
83     {
84         return targetLanguage_;
85     }
86 
GetGenerationDirectory()87     String GetGenerationDirectory() const
88     {
89         return generationDirectory_;
90     }
91 
92     void ShowErrors();
93 
94     void ShowVersion();
95 
96     void ShowUsage();
97 
98 private:
99     void Parse(int argc, char** argv);
100 
101     static constexpr int VERSION_MAJOR = 0;
102     static constexpr int VERSION_MINOR = 1;
103 
104     String program_;
105     String sourceFile_;
106     String metadataFile_;
107     String targetLanguage_;
108     String generationDirectory_;
109     String illegalOptions_;
110 
111     bool doShowUsage_ = false;
112     bool doShowVersion_ = false;
113     bool doCompile_ = false;
114     bool doDumpAST_ = false;
115     bool doDumpMetadata_ = false;
116     bool doSaveMetadata_ = false;
117     bool doGenerateCode_ = false;
118 };
119 }
120 }
121 #endif // OHOS_IDL_OPTIONS_H
122