1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef ADC_ADC_CMD_HXX
25 #define ADC_ADC_CMD_HXX
26 
27 
28 
29 // USED SERVICES
30 	// BASE CLASSES
31 #include <cosv/comdline.hxx>
32 	// COMPONENTS
33 	// PARAMETERS
34 
35 
36 namespace autodoc
37 {
38 namespace command
39 {
40 
41 /** Context for a command, which can be read from the command line.
42 */
43 class Context
44 {
45   public:
46     typedef StringVector::const_iterator opt_iter;
47 
~Context()48     virtual             ~Context() {}
49 
50     void                Init(
51                             opt_iter &          it,
52                             opt_iter            itEnd );
53   private:
54     virtual void        do_Init(
55                             opt_iter &          it,
56                             opt_iter            itEnd ) = 0;
57 };
58 
59 // IMPLEMENTATION
60 inline void
Init(opt_iter & i_nCurArgsBegin,opt_iter i_nEndOfAllArgs)61 Context::Init( opt_iter &          i_nCurArgsBegin,
62                opt_iter            i_nEndOfAllArgs )
63 
64 { do_Init(i_nCurArgsBegin, i_nEndOfAllArgs); }
65 
66 
67 
68 /** Interface for commands, autodoc is able to perform.
69 */
70 class Command : public Context
71 {
72   public:
73     /** Running ranks of the commands are to be maintained at one location:
74         Here!
75     */
76     enum E_Ranks
77     {
78         rank_Load       = 10,
79         rank_Parse      = 20,
80         rank_Save       = 30,
81         rank_CreateHtml = 40,
82         rank_CreateXml  = 50
83     };
84 
85 
86     bool                Run() const;
87     int                 RunningRank() const;
88 
89   private:
90     virtual bool        do_Run() const = 0;
91     virtual int         inq_RunningRank() const = 0;
92 };
93 
94 // IMPLEMENTATION
95 inline bool
Run() const96 Command::Run() const
97 { return do_Run(); }
98 inline int
RunningRank() const99 Command::RunningRank() const
100 { return inq_RunningRank(); }
101 
102 
103 
104 
105 /** The exception thrown, if the command line is invalid.
106 */
107 class X_CommandLine
108 {
109   public:
X_CommandLine(const char * i_sExplanation)110                         X_CommandLine(
111                             const char *        i_sExplanation )
112                             :   sExplanation(i_sExplanation) {}
113 
Report(std::ostream & o_rOut)114     void                Report(
115                             std::ostream &      o_rOut )
116                             { o_rOut << "Error in command line: "
117                                      << sExplanation << Endl(); }
118   private:
119     String              sExplanation;
120 };
121 
122 
123 
124 
125 }   // namespace command
126 }   // namespace autodoc
127 #endif
128