diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 18:09:04 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 18:09:04 +0000 |
commit | 393f1b414746a7f1977971dd7659dd2b47092b11 (patch) | |
tree | 81d0ca1ee70ab86a7d79c1991abe5c387b655fb2 /src/optparser.h | |
parent | c259f95bd0e58b247940a339bb9b4b401b4e9438 (diff) | |
parent | 7e25a863325dc3e9762397e700030969e093b087 (diff) | |
download | libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.gz libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.bz2 libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.xz libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.zip |
Wow! Merged the branch, streams are updated, and there's no more FString, run
the fixstrings.sh script in the support directory to (hopefully) automatically
update your projects.
Diffstat (limited to 'src/optparser.h')
-rw-r--r-- | src/optparser.h | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/optparser.h b/src/optparser.h index 7ec69e5..4142e22 100644 --- a/src/optparser.h +++ b/src/optparser.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2007-2010 Xagasoft, All rights reserved. | 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. |
3 | * | 3 | * |
4 | * This file is part of the libbu++ library and is released under the | 4 | * This file is part of the libbu++ library and is released under the |
5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
@@ -8,7 +8,7 @@ | |||
8 | #ifndef BU_OPT_PARSER_H | 8 | #ifndef BU_OPT_PARSER_H |
9 | #define BU_OPT_PARSER_H | 9 | #define BU_OPT_PARSER_H |
10 | 10 | ||
11 | #include "bu/fstring.h" | 11 | #include "bu/string.h" |
12 | #include "bu/list.h" | 12 | #include "bu/list.h" |
13 | #include "bu/hash.h" | 13 | #include "bu/hash.h" |
14 | #include "bu/signals.h" | 14 | #include "bu/signals.h" |
@@ -19,7 +19,7 @@ | |||
19 | 19 | ||
20 | namespace Bu | 20 | namespace Bu |
21 | { | 21 | { |
22 | typedef Bu::Array<Bu::FString> StrArray; | 22 | typedef Bu::Array<Bu::String> StrArray; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * POSIX/Gnu style command line parser. Handles long and short options in | 25 | * POSIX/Gnu style command line parser. Handles long and short options in |
@@ -41,7 +41,7 @@ namespace Bu | |||
41 | _ValueProxy(); | 41 | _ValueProxy(); |
42 | virtual ~_ValueProxy(); | 42 | virtual ~_ValueProxy(); |
43 | 43 | ||
44 | virtual void setValueFromStr( const Bu::FString & )=0; | 44 | virtual void setValueFromStr( const Bu::String & )=0; |
45 | virtual void setValue( const Bu::Variant &vVar )=0; | 45 | virtual void setValue( const Bu::Variant &vVar )=0; |
46 | virtual _ValueProxy *clone()=0; | 46 | virtual _ValueProxy *clone()=0; |
47 | }; | 47 | }; |
@@ -59,7 +59,7 @@ namespace Bu | |||
59 | { | 59 | { |
60 | } | 60 | } |
61 | 61 | ||
62 | virtual void setValueFromStr( const Bu::FString &sVal ) | 62 | virtual void setValueFromStr( const Bu::String &sVal ) |
63 | { | 63 | { |
64 | Bu::MemBuf mb( sVal ); | 64 | Bu::MemBuf mb( sVal ); |
65 | Bu::Formatter f( mb ); | 65 | Bu::Formatter f( mb ); |
@@ -72,9 +72,9 @@ namespace Bu | |||
72 | { | 72 | { |
73 | v = vVar.get<ptype>(); | 73 | v = vVar.get<ptype>(); |
74 | } | 74 | } |
75 | else if( vVar.getType() == typeid(Bu::FString) ) | 75 | else if( vVar.getType() == typeid(Bu::String) ) |
76 | { | 76 | { |
77 | setValueFromStr( vVar.get<Bu::FString>() ); | 77 | setValueFromStr( vVar.get<Bu::String>() ); |
78 | } | 78 | } |
79 | else | 79 | else |
80 | { | 80 | { |
@@ -101,23 +101,23 @@ namespace Bu | |||
101 | virtual ~Option(); | 101 | virtual ~Option(); |
102 | 102 | ||
103 | char cOpt; | 103 | char cOpt; |
104 | Bu::FString sOpt; | 104 | Bu::String sOpt; |
105 | Bu::FString sHelp; | 105 | Bu::String sHelp; |
106 | OptionSignal sUsed; | 106 | OptionSignal sUsed; |
107 | _ValueProxy *pProxy; | 107 | _ValueProxy *pProxy; |
108 | Bu::Variant sOverride; | 108 | Bu::Variant sOverride; |
109 | Bu::FString sHelpDefault; | 109 | Bu::String sHelpDefault; |
110 | }; | 110 | }; |
111 | 111 | ||
112 | private: | 112 | private: |
113 | typedef Bu::List<Option> OptionList; | 113 | typedef Bu::List<Option> OptionList; |
114 | typedef Bu::Hash<char, Option *> ShortOptionHash; | 114 | typedef Bu::Hash<char, Option *> ShortOptionHash; |
115 | typedef Bu::Hash<Bu::FString, Option *> LongOptionHash; | 115 | typedef Bu::Hash<Bu::String, Option *> LongOptionHash; |
116 | 116 | ||
117 | class Banner | 117 | class Banner |
118 | { | 118 | { |
119 | public: | 119 | public: |
120 | Bu::FString sText; | 120 | Bu::String sText; |
121 | bool bFormatted; | 121 | bool bFormatted; |
122 | OptionList::const_iterator iAfter; | 122 | OptionList::const_iterator iAfter; |
123 | }; | 123 | }; |
@@ -133,8 +133,8 @@ namespace Bu | |||
133 | void addOption( const Option &opt ); | 133 | void addOption( const Option &opt ); |
134 | 134 | ||
135 | template<typename vtype> | 135 | template<typename vtype> |
136 | void addOption( vtype &var, char cOpt, const Bu::FString &sOpt, | 136 | void addOption( vtype &var, char cOpt, const Bu::String &sOpt, |
137 | const Bu::FString &sHelp ) | 137 | const Bu::String &sHelp ) |
138 | { | 138 | { |
139 | Option o; | 139 | Option o; |
140 | o.cOpt = cOpt; | 140 | o.cOpt = cOpt; |
@@ -145,20 +145,20 @@ namespace Bu | |||
145 | } | 145 | } |
146 | 146 | ||
147 | template<typename vtype> | 147 | template<typename vtype> |
148 | void addOption( vtype &var, const Bu::FString &sOpt, | 148 | void addOption( vtype &var, const Bu::String &sOpt, |
149 | const Bu::FString &sHelp ) | 149 | const Bu::String &sHelp ) |
150 | { | 150 | { |
151 | addOption( var, '\0', sOpt, sHelp ); | 151 | addOption( var, '\0', sOpt, sHelp ); |
152 | } | 152 | } |
153 | 153 | ||
154 | template<typename vtype> | 154 | template<typename vtype> |
155 | void addOption( vtype &var, char cOpt, const Bu::FString &sHelp ) | 155 | void addOption( vtype &var, char cOpt, const Bu::String &sHelp ) |
156 | { | 156 | { |
157 | addOption( var, cOpt, "", sHelp ); | 157 | addOption( var, cOpt, "", sHelp ); |
158 | } | 158 | } |
159 | 159 | ||
160 | void addOption( OptionSignal sUsed, char cOpt, const Bu::FString &sOpt, | 160 | void addOption( OptionSignal sUsed, char cOpt, const Bu::String &sOpt, |
161 | const Bu::FString &sHelp ) | 161 | const Bu::String &sHelp ) |
162 | { | 162 | { |
163 | Option o; | 163 | Option o; |
164 | o.cOpt = cOpt; | 164 | o.cOpt = cOpt; |
@@ -168,27 +168,27 @@ namespace Bu | |||
168 | addOption( o ); | 168 | addOption( o ); |
169 | } | 169 | } |
170 | 170 | ||
171 | void addOption( OptionSignal sUsed, const Bu::FString &sOpt, | 171 | void addOption( OptionSignal sUsed, const Bu::String &sOpt, |
172 | const Bu::FString &sHelp ) | 172 | const Bu::String &sHelp ) |
173 | { | 173 | { |
174 | addOption( sUsed, '\0', sOpt, sHelp ); | 174 | addOption( sUsed, '\0', sOpt, sHelp ); |
175 | } | 175 | } |
176 | 176 | ||
177 | void addOption( OptionSignal sUsed, char cOpt, | 177 | void addOption( OptionSignal sUsed, char cOpt, |
178 | const Bu::FString &sHelp ) | 178 | const Bu::String &sHelp ) |
179 | { | 179 | { |
180 | addOption( sUsed, cOpt, "", sHelp ); | 180 | addOption( sUsed, cOpt, "", sHelp ); |
181 | } | 181 | } |
182 | 182 | ||
183 | void setOverride( char cOpt, const Bu::Variant &sOverride ); | 183 | void setOverride( char cOpt, const Bu::Variant &sOverride ); |
184 | void setOverride( const Bu::FString &sOpt, | 184 | void setOverride( const Bu::String &sOpt, |
185 | const Bu::Variant &sOverride ); | 185 | const Bu::Variant &sOverride ); |
186 | 186 | ||
187 | void setHelpDefault( const Bu::FString &sOpt, const Bu::FString &sTxt ); | 187 | void setHelpDefault( const Bu::String &sOpt, const Bu::String &sTxt ); |
188 | 188 | ||
189 | void addHelpOption( char c='h', const Bu::FString &s="help", | 189 | void addHelpOption( char c='h', const Bu::String &s="help", |
190 | const Bu::FString &sHelp="This help." ); | 190 | const Bu::String &sHelp="This help." ); |
191 | void addHelpBanner( const Bu::FString &sText, bool bFormatted=true ); | 191 | void addHelpBanner( const Bu::String &sText, bool bFormatted=true ); |
192 | 192 | ||
193 | int optHelp( StrArray aParams ); | 193 | int optHelp( StrArray aParams ); |
194 | 194 | ||
@@ -200,12 +200,12 @@ namespace Bu | |||
200 | * been handled by an option, and isn't an option (starts with - or --). | 200 | * been handled by an option, and isn't an option (starts with - or --). |
201 | * To change this behaviour call | 201 | * To change this behaviour call |
202 | */ | 202 | */ |
203 | virtual void optionError( const Bu::FString &sOption ); | 203 | virtual void optionError( const Bu::String &sOption ); |
204 | 204 | ||
205 | void setNonOption( OptionSignal sSignal ); | 205 | void setNonOption( OptionSignal sSignal ); |
206 | 206 | ||
207 | private: | 207 | private: |
208 | Bu::FString format( const Bu::FString &sIn, int iWidth, int iIndent ); | 208 | Bu::String format( const Bu::String &sIn, int iWidth, int iIndent ); |
209 | 209 | ||
210 | OptionList lOption; | 210 | OptionList lOption; |
211 | ShortOptionHash hsOption; | 211 | ShortOptionHash hsOption; |