Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:50

0001 //===-- OptionValueString.h -------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_INTERPRETER_OPTIONVALUESTRING_H
0010 #define LLDB_INTERPRETER_OPTIONVALUESTRING_H
0011 
0012 #include <string>
0013 
0014 #include "lldb/Utility/Flags.h"
0015 
0016 #include "lldb/Interpreter/OptionValue.h"
0017 
0018 namespace lldb_private {
0019 
0020 class OptionValueString : public Cloneable<OptionValueString, OptionValue> {
0021 public:
0022   typedef Status (*ValidatorCallback)(const char *string, void *baton);
0023 
0024   enum Options { eOptionEncodeCharacterEscapeSequences = (1u << 0) };
0025 
0026   OptionValueString() = default;
0027 
0028   OptionValueString(ValidatorCallback validator, void *baton = nullptr)
0029       : m_validator(validator), m_validator_baton(baton) {}
0030 
0031   OptionValueString(const char *value) {
0032     if (value && value[0]) {
0033       m_current_value.assign(value);
0034       m_default_value.assign(value);
0035     }
0036   }
0037 
0038   OptionValueString(const char *current_value, const char *default_value) {
0039     if (current_value && current_value[0])
0040       m_current_value.assign(current_value);
0041     if (default_value && default_value[0])
0042       m_default_value.assign(default_value);
0043   }
0044 
0045   OptionValueString(const char *value, ValidatorCallback validator,
0046                     void *baton = nullptr)
0047       : m_validator(validator), m_validator_baton(baton) {
0048     if (value && value[0]) {
0049       m_current_value.assign(value);
0050       m_default_value.assign(value);
0051     }
0052   }
0053 
0054   OptionValueString(const char *current_value, const char *default_value,
0055                     ValidatorCallback validator, void *baton = nullptr)
0056       : m_validator(validator), m_validator_baton(baton) {
0057     if (current_value && current_value[0])
0058       m_current_value.assign(current_value);
0059     if (default_value && default_value[0])
0060       m_default_value.assign(default_value);
0061   }
0062 
0063   ~OptionValueString() override = default;
0064 
0065   // Virtual subclass pure virtual overrides
0066 
0067   OptionValue::Type GetType() const override { return eTypeString; }
0068 
0069   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
0070                  uint32_t dump_mask) override;
0071 
0072   llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
0073     return m_current_value;
0074   }
0075 
0076   Status
0077   SetValueFromString(llvm::StringRef value,
0078                      VarSetOperationType op = eVarSetOperationAssign) override;
0079 
0080   void Clear() override {
0081     m_current_value = m_default_value;
0082     m_value_was_set = false;
0083   }
0084 
0085   // Subclass specific functions
0086 
0087   Flags &GetOptions() { return m_options; }
0088 
0089   const Flags &GetOptions() const { return m_options; }
0090 
0091   const char *operator=(const char *value) {
0092     SetCurrentValue(value);
0093     return m_current_value.c_str();
0094   }
0095 
0096   const char *GetCurrentValue() const { return m_current_value.c_str(); }
0097   llvm::StringRef GetCurrentValueAsRef() const { return m_current_value; }
0098 
0099   const char *GetDefaultValue() const { return m_default_value.c_str(); }
0100   llvm::StringRef GetDefaultValueAsRef() const { return m_default_value; }
0101 
0102   Status SetCurrentValue(llvm::StringRef value);
0103 
0104   Status AppendToCurrentValue(const char *value);
0105 
0106   void SetDefaultValue(const char *value) {
0107     if (value && value[0])
0108       m_default_value.assign(value);
0109     else
0110       m_default_value.clear();
0111   }
0112 
0113   bool IsCurrentValueEmpty() const { return m_current_value.empty(); }
0114 
0115   bool IsDefaultValueEmpty() const { return m_default_value.empty(); }
0116 
0117   void SetValidator(ValidatorCallback validator, void *baton = nullptr) {
0118     m_validator = validator;
0119     m_validator_baton = baton;
0120   }
0121 
0122 protected:
0123   std::string m_current_value;
0124   std::string m_default_value;
0125   Flags m_options;
0126   ValidatorCallback m_validator = nullptr;
0127   void *m_validator_baton = nullptr;
0128 };
0129 
0130 } // namespace lldb_private
0131 
0132 #endif // LLDB_INTERPRETER_OPTIONVALUESTRING_H