diff options
| author | Chris Lattner <sabre@nondot.org> | 2001-07-22 03:57:31 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2001-07-22 03:57:31 +0000 |
| commit | 953e0d7076cd09a7bebd15d5f738028b45b4b063 (patch) | |
| tree | 85f69ce200926317dfe7a4e930ba72cdb5a87483 /include/llvm/Support | |
| parent | 29f921ca75d44fc36c10f0e2597470b4b3ada6e0 (diff) | |
| download | external_llvm-953e0d7076cd09a7bebd15d5f738028b45b4b063.zip external_llvm-953e0d7076cd09a7bebd15d5f738028b45b4b063.tar.gz external_llvm-953e0d7076cd09a7bebd15d5f738028b45b4b063.tar.bz2 | |
Convert from using C style char*'s to strings.
Look ma, no strdups
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support')
| -rw-r--r-- | include/llvm/Support/ProgramOption.h | 66 | ||||
| -rw-r--r-- | include/llvm/Support/ProgramOptions.h | 10 |
2 files changed, 34 insertions, 42 deletions
diff --git a/include/llvm/Support/ProgramOption.h b/include/llvm/Support/ProgramOption.h index 767e27c..83eeac6 100644 --- a/include/llvm/Support/ProgramOption.h +++ b/include/llvm/Support/ProgramOption.h @@ -17,20 +17,14 @@ #ifndef LLVM_SUPPORT_PROGRAMOPTION_H #define LLVM_SUPPORT_PROGRAMOPTION_H -//************************** System Include Files **************************/ - -#include <string> - -//*************************** User Include Files ***************************/ - #include "llvm/Support/Unique.h" +#include <string> -//********************** Local Variable Definitions ************************/ class ProgramOption: public Unique { public: - /*ctor*/ ProgramOption (const char* _argString, - const char* _helpMesg, + /*ctor*/ ProgramOption (const string &_argString, + const string &_helpMesg, int _minExpectedArgs = 1) : optionSpecified(false), argString(_argString), @@ -46,17 +40,17 @@ public: // were consumed by EvalOpt and should be discarded. // A return value of -1 indicates an error. // - virtual int EvalOpt (const char* optarg) = 0; + virtual int EvalOpt (const string &) = 0; // Returns the value associated with the option as a human-readable - // string. The memory returned is allocated via `malloc'. - virtual char* GetTextValue () const = 0; + // string. + virtual string GetTextValue () const = 0; // Inline accessor functions for common option information // bool OptionSpecified () const { return optionSpecified; } - const char* ArgString () const { return argString.c_str(); } - const char* HelpMesg () const { return helpMesg.c_str(); } + const string ArgString () const { return argString; } + const string HelpMesg () const { return helpMesg; } int MinExpectedArgs () const { return minExpectedArgs; } protected: @@ -70,19 +64,19 @@ protected: class StringOption : public ProgramOption { public: - /*ctor*/ StringOption (const char* argString, - const char* helpMesg, - const char* initValue = "", + /*ctor*/ StringOption (const string &argString, + const string &helpMesg, + const string &initValue = "", bool append = false); // append = false: EvalOpt will overwrite preexisting value // append = true : EvalOpt will append <optArg> to value /*dtor*/ virtual ~StringOption () {} - virtual int EvalOpt (const char* optarg); + virtual int EvalOpt (const string &optarg); - const char* Value () const { return value.c_str(); } - virtual char* GetTextValue () const { return strdup(Value()); } + const string &Value() const { return value; } + virtual string GetTextValue() const { return value; } protected: string value; @@ -99,50 +93,48 @@ protected: class FlagOption : public ProgramOption { public: - /*ctor*/ FlagOption (const char* argString, - const char* helpMesg, - bool initValue = false); + FlagOption(const string &argString, const string &helpMesg, + bool initValue = false); - /*dtor*/ virtual ~FlagOption () {} + virtual ~FlagOption() {} - virtual int EvalOpt (const char* optarg); + virtual int EvalOpt (const string &optarg); bool Value () const { return value; } - virtual char* GetTextValue () const { return strdup( - value ? "true" : "false");} + virtual string GetTextValue() const { return value ? "true" : "false";} private: - bool value; + bool value; }; //**************************************************************************/ class RealValuedOption : public ProgramOption { public: - /*ctor*/ RealValuedOption(const char* argString, - const char* helpMesg, + /*ctor*/ RealValuedOption(const string &argString, + const string &helpMesg, double initValue = 0.0); /*dtor*/ virtual ~RealValuedOption() {} - virtual int EvalOpt (const char* optarg); + virtual int EvalOpt (const string &optarg); double Value () const { return value; } - virtual char* GetTextValue () const; + virtual string GetTextValue() const; private: - double value; + double value; }; //**************************************************************************/ class IntegerValuedOption : public RealValuedOption { public: - /*ctor*/ IntegerValuedOption(const char* argString, - const char* helpMesg, + /*ctor*/ IntegerValuedOption(const string &argString, + const string &helpMesg, int initValue = 0); /*ctor*/ virtual ~IntegerValuedOption() {} - int Value () const; - virtual char* GetTextValue () const; + int Value() const; + virtual string GetTextValue() const; }; //**************************************************************************/ diff --git a/include/llvm/Support/ProgramOptions.h b/include/llvm/Support/ProgramOptions.h index f2a4f7c..9ebc975 100644 --- a/include/llvm/Support/ProgramOptions.h +++ b/include/llvm/Support/ProgramOptions.h @@ -58,12 +58,12 @@ public: // The required argument is specified by the optionString. //-------------------------------------------------------------------- - const char* StringOptionValue(const char* optionString) const; - bool FlagOptionValue (const char* optionString) const; - double RealOptionValue (const char* optionString) const; - int IntOptionValue (const char* optionString) const; + string StringOptionValue(const string &optionString) const; + bool FlagOptionValue (const string &optionString) const; + double RealOptionValue (const string &optionString) const; + int IntOptionValue (const string &optionString) const; - bool OptionSpecified (const char* optionString) const; + bool OptionSpecified (const string &optionString) const; //-------------------------------------------------------------------- // The name used to invoke this program. |
