1 //===-- OptionValueString.h --------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_OptionValueString_h_ 11 #define liblldb_OptionValueString_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <string> 16 17 // Other libraries and framework includes 18 // Project includes 19 #include "lldb/Core/Flags.h" 20 #include "lldb/Interpreter/OptionValue.h" 21 22 namespace lldb_private { 23 24 class OptionValueString : public OptionValue 25 { 26 public: 27 28 typedef Error (*ValidatorCallback) (const char* string, 29 void* baton); 30 31 enum Options 32 { 33 eOptionEncodeCharacterEscapeSequences = (1u << 0) 34 }; 35 OptionValueString()36 OptionValueString () : 37 OptionValue(), 38 m_current_value (), 39 m_default_value (), 40 m_options(), 41 m_validator(), 42 m_validator_baton() 43 { 44 } 45 46 OptionValueString (ValidatorCallback validator, 47 void* baton = NULL) : OptionValue()48 OptionValue(), 49 m_current_value (), 50 m_default_value (), 51 m_options(), 52 m_validator(validator), 53 m_validator_baton(baton) 54 { 55 } 56 OptionValueString(const char * value)57 OptionValueString (const char *value) : 58 OptionValue(), 59 m_current_value (), 60 m_default_value (), 61 m_options(), 62 m_validator(), 63 m_validator_baton() 64 { 65 if (value && value[0]) 66 { 67 m_current_value.assign (value); 68 m_default_value.assign (value); 69 } 70 } 71 OptionValueString(const char * current_value,const char * default_value)72 OptionValueString (const char *current_value, 73 const char *default_value) : 74 OptionValue(), 75 m_current_value (), 76 m_default_value (), 77 m_options(), 78 m_validator(), 79 m_validator_baton() 80 { 81 if (current_value && current_value[0]) 82 m_current_value.assign (current_value); 83 if (default_value && default_value[0]) 84 m_default_value.assign (default_value); 85 } 86 87 OptionValueString (const char *value, 88 ValidatorCallback validator, 89 void* baton = NULL) : OptionValue()90 OptionValue(), 91 m_current_value (), 92 m_default_value (), 93 m_options(), 94 m_validator(validator), 95 m_validator_baton(baton) 96 { 97 if (value && value[0]) 98 { 99 m_current_value.assign (value); 100 m_default_value.assign (value); 101 } 102 } 103 104 OptionValueString (const char *current_value, 105 const char *default_value, 106 ValidatorCallback validator, 107 void* baton = NULL) : OptionValue()108 OptionValue(), 109 m_current_value (), 110 m_default_value (), 111 m_options(), 112 m_validator(validator), 113 m_validator_baton(baton) 114 { 115 if (current_value && current_value[0]) 116 m_current_value.assign (current_value); 117 if (default_value && default_value[0]) 118 m_default_value.assign (default_value); 119 } 120 121 virtual ~OptionValueString()122 ~OptionValueString() 123 { 124 } 125 126 //--------------------------------------------------------------------- 127 // Virtual subclass pure virtual overrides 128 //--------------------------------------------------------------------- 129 130 virtual OptionValue::Type GetType()131 GetType () const 132 { 133 return eTypeString; 134 } 135 136 virtual void 137 DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); 138 139 virtual Error 140 SetValueFromCString (const char *value, 141 VarSetOperationType op = eVarSetOperationAssign); 142 143 virtual bool Clear()144 Clear () 145 { 146 m_current_value = m_default_value; 147 m_value_was_set = false; 148 return true; 149 } 150 151 virtual lldb::OptionValueSP 152 DeepCopy () const; 153 154 //--------------------------------------------------------------------- 155 // Subclass specific functions 156 //--------------------------------------------------------------------- 157 158 Flags & GetOptions()159 GetOptions () 160 { 161 return m_options; 162 } 163 164 const Flags & GetOptions()165 GetOptions () const 166 { 167 return m_options; 168 } 169 170 const char * 171 operator = (const char *value) 172 { 173 SetCurrentValue(value); 174 return m_current_value.c_str(); 175 } 176 177 const char * GetCurrentValue()178 GetCurrentValue() const 179 { 180 return m_current_value.c_str(); 181 } 182 183 const char * GetDefaultValue()184 GetDefaultValue() const 185 { 186 return m_default_value.c_str(); 187 } 188 189 Error 190 SetCurrentValue (const char *value); 191 192 Error 193 AppendToCurrentValue (const char *value); 194 195 void SetDefaultValue(const char * value)196 SetDefaultValue (const char *value) 197 { 198 if (value && value[0]) 199 m_default_value.assign (value); 200 else 201 m_default_value.clear(); 202 } 203 204 bool IsCurrentValueEmpty()205 IsCurrentValueEmpty () const 206 { 207 return m_current_value.empty(); 208 } 209 210 bool IsDefaultValueEmpty()211 IsDefaultValueEmpty () const 212 { 213 return m_default_value.empty(); 214 } 215 216 217 protected: 218 std::string m_current_value; 219 std::string m_default_value; 220 Flags m_options; 221 ValidatorCallback m_validator; 222 void* m_validator_baton; 223 }; 224 225 } // namespace lldb_private 226 227 #endif // liblldb_OptionValueString_h_ 228