aboutsummaryrefslogtreecommitdiff
path: root/src/optparser.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-01-20 02:14:08 +0000
committerMike Buland <eichlan@xagasoft.com>2011-01-20 02:14:08 +0000
commitf5aca1a1b402bd7ebc944dc6e6fe65828d863365 (patch)
tree4a0fdd8e166d5c4b03543279d332b9a858ef62df /src/optparser.h
parent10c557562e1d67c55314c212371ea9cb7f802863 (diff)
downloadlibbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.tar.gz
libbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.tar.bz2
libbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.tar.xz
libbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.zip
Bu::FString is now String, and there's a shell script to fix any other programs
that were using fstring, I hope.
Diffstat (limited to 'src/optparser.h')
-rw-r--r--src/optparser.h56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/optparser.h b/src/optparser.h
index 7ec69e5..9781542 100644
--- a/src/optparser.h
+++ b/src/optparser.h
@@ -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
20namespace Bu 20namespace 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;