BUG: fix some bad changes in progress calc
[cmake.git] / Source / cmCommandArgumentsHelper.h
blob2454fd363f28dc6760781d8b43d9e97333862370
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCommandArgumentsHelper.h,v $
5 Language: C++
6 Date: $Date: 2007-08-23 20:13:15 $
7 Version: $Revision: 1.2 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmCommandArgumentsHelper_h
18 #define cmCommandArgumentsHelper_h
20 #include "cmStandardIncludes.h"
22 class cmCommandArgumentsHelper;
23 class cmCommandArgumentGroup;
25 /* cmCommandArgumentsHelper, cmCommandArgumentGroup and cmCommandArgument (i.e.
26 its derived classes cmCAXXX can be used to simplify the processing of
27 arguments to cmake commands. Maybe they can also be used to generate
28 documentation.
30 For every argument supported by a command one cmCommandArgument is created
31 and added to cmCommandArgumentsHelper. cmCommand has a cmCommandArgumentsHelper
32 as member variable so this should be used.
34 The order of the arguments is defined using the Follows(arg) method. It says
35 that this argument follows immediateley the given argument. It can be used
36 with multiple arguments if the argument can follow after different arguments.
38 Arguments can be arranged in groups using cmCommandArgumentGroup. Every
39 member of a group can follow any other member of the group. These groups
40 can also be used to define the order.
42 Once all arguments and groups are set up, cmCommandArgumentsHelper::Parse()
43 is called and afterwards the values of the arguments can be evaluated.
45 For an example see cmExportCommand.cxx.
47 class cmCommandArgument
49 public:
50 cmCommandArgument(cmCommandArgumentsHelper* args,
51 const char* key,
52 cmCommandArgumentGroup* group=0);
53 virtual ~cmCommandArgument() {}
55 /// this argument may follow after arg. 0 means it comes first.
56 void Follows(const cmCommandArgument* arg);
58 /// this argument may follow after any of the arguments in the given group
59 void FollowsGroup(const cmCommandArgumentGroup* group);
61 /// Returns true if the argument was found in the argument list
62 bool WasFound() const {return this->WasActive;}
64 // The following methods are only called from
65 // cmCommandArgumentsHelper::Parse(), but making this a friend would
66 // give it access to everything
68 /// Make the current argument the currently active argument
69 void Activate();
70 /// Consume the current string
71 bool Consume(const std::string& arg);
73 /// Return true if this argument may follow after the given argument.
74 bool MayFollow(const cmCommandArgument* current) const;
76 /** Returns true if the given key matches the key for this argument.
77 If this argument has an empty key everything matches. */
78 bool KeyMatches(const std::string& key) const;
80 /// Make this argument follow all members of the own group
81 void ApplyOwnGroup();
83 /// Reset argument, so it's back to its initial state
84 void Reset();
85 private:
86 const char* Key;
87 std::set<const cmCommandArgument*> ArgumentsBefore;
88 cmCommandArgumentGroup* Group;
89 bool WasActive;
90 bool ArgumentsBeforeEmpty;
91 unsigned int CurrentIndex;
93 virtual bool DoConsume(const std::string& arg, unsigned int index) = 0;
94 virtual void DoReset() = 0;
97 /** cmCAStringVector is to be used for arguments which can consist of more
98 than one string, e.g. the FILES argument in INSTALL(FILES f1 f2 f3 ...). */
99 class cmCAStringVector : public cmCommandArgument
101 public:
102 cmCAStringVector(cmCommandArgumentsHelper* args,
103 const char* key,
104 cmCommandArgumentGroup* group=0);
106 /// Return the vector of strings
107 const std::vector<std::string>& GetVector() const {return this->Vector;}
109 /** Is there a keyword which should be skipped in
110 the arguments (e.g. ARGS for ADD_CUSTOM_COMMAND) ? */
111 void SetIgnore(const char* ignore) {this->Ignore=ignore;}
112 private:
113 std::vector<std::string> Vector;
114 unsigned int DataStart;
115 const char* Ignore;
116 cmCAStringVector();
117 virtual bool DoConsume(const std::string& arg, unsigned int index);
118 virtual void DoReset();
121 /** cmCAString is to be used for arguments which consist of one value,
122 e.g. the executable name in ADD_EXECUTABLE(). */
123 class cmCAString : public cmCommandArgument
125 public:
126 cmCAString(cmCommandArgumentsHelper* args,
127 const char* key,
128 cmCommandArgumentGroup* group=0);
130 /// Return the string
131 const std::string& GetString() const {return this->String;}
132 const char* GetCString() const {return this->String.c_str();}
133 void SetDefaultString(const char* text)
134 {this->DefaultString = (text ? text : "");}
135 private:
136 std::string String;
137 std::string DefaultString;
138 unsigned int DataStart;
139 virtual bool DoConsume(const std::string& arg, unsigned int index);
140 virtual void DoReset();
141 cmCAString();
144 /** cmCAEnabler is to be used for options which are off by default and can be
145 enabled using a special argument, e.g. EXCLUDE_FROM_ALL in ADD_EXECUTABLE(). */
146 class cmCAEnabler : public cmCommandArgument
148 public:
149 cmCAEnabler(cmCommandArgumentsHelper* args,
150 const char* key,
151 cmCommandArgumentGroup* group=0);
153 /// Has it been enabled ?
154 bool IsEnabled() const {return this->Enabled;}
155 private:
156 bool Enabled;
157 virtual bool DoConsume(const std::string& arg, unsigned int index);
158 virtual void DoReset();
159 cmCAEnabler();
162 /** cmCADisable is to be used for options which are on by default and can be
163 disabled using a special argument.*/
164 class cmCADisabler : public cmCommandArgument
166 public:
167 cmCADisabler(cmCommandArgumentsHelper* args,
168 const char* key,
169 cmCommandArgumentGroup* group=0);
171 /// Is it still enabled ?
172 bool IsEnabled() const {return this->Enabled;}
173 private:
174 bool Enabled;
175 virtual bool DoConsume(const std::string& arg, unsigned int index);
176 virtual void DoReset();
177 cmCADisabler();
181 /** Group of arguments, needed for ordering. E.g. WIN32, EXCLUDE_FROM_ALL and
182 MACSOX_BUNDLE from ADD_EXECUTABLE() are a group.
184 class cmCommandArgumentGroup
186 friend class cmCommandArgument;
187 public:
188 cmCommandArgumentGroup() {}
190 /// All members of this group may follow the given argument
191 void Follows(const cmCommandArgument* arg);
193 /// All members of this group may follow all members of the given group
194 void FollowsGroup(const cmCommandArgumentGroup* group);
195 private:
196 std::vector<cmCommandArgument*> ContainedArguments;
199 class cmCommandArgumentsHelper
201 public:
202 /// Parse the argument list
203 void Parse(const std::vector<std::string>* args,
204 std::vector<std::string>* unconsumedArgs);
205 /// Add an argument.
206 void AddArgument(cmCommandArgument* arg);
207 private:
208 std::vector<cmCommandArgument*> Arguments;
212 #endif