1 //===-- OptionValueArray.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_INTERPRETER_OPTIONVALUEARRAY_H 10 #define LLDB_INTERPRETER_OPTIONVALUEARRAY_H 11 12 #include <vector> 13 14 #include "lldb/Interpreter/OptionValue.h" 15 16 namespace lldb_private { 17 18 class OptionValueArray : public Cloneable<OptionValueArray, OptionValue> { 19 public: 20 OptionValueArray(uint32_t type_mask = UINT32_MAX, bool raw_value_dump = false) 21 : m_type_mask(type_mask), m_raw_value_dump(raw_value_dump) {} 22 23 ~OptionValueArray() override = default; 24 25 // Virtual subclass pure virtual overrides 26 27 OptionValue::Type GetType() const override { return eTypeArray; } 28 29 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 30 uint32_t dump_mask) override; 31 32 Status 33 SetValueFromString(llvm::StringRef value, 34 VarSetOperationType op = eVarSetOperationAssign) override; 35 36 void Clear() override { 37 m_values.clear(); 38 m_value_was_set = false; 39 } 40 41 lldb::OptionValueSP 42 DeepCopy(const lldb::OptionValueSP &new_parent) const override; 43 44 bool IsAggregateValue() const override { return true; } 45 46 lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx, 47 llvm::StringRef name, bool will_modify, 48 Status &error) const override; 49 50 // Subclass specific functions 51 52 size_t GetSize() const { return m_values.size(); } 53 54 lldb::OptionValueSP operator[](size_t idx) const { 55 lldb::OptionValueSP value_sp; 56 if (idx < m_values.size()) 57 value_sp = m_values[idx]; 58 return value_sp; 59 } 60 61 lldb::OptionValueSP GetValueAtIndex(size_t idx) const { 62 lldb::OptionValueSP value_sp; 63 if (idx < m_values.size()) 64 value_sp = m_values[idx]; 65 return value_sp; 66 } 67 68 bool AppendValue(const lldb::OptionValueSP &value_sp) { 69 // Make sure the value_sp object is allowed to contain values of the type 70 // passed in... 71 if (value_sp && (m_type_mask & value_sp->GetTypeAsMask())) { 72 m_values.push_back(value_sp); 73 return true; 74 } 75 return false; 76 } 77 78 bool InsertValue(size_t idx, const lldb::OptionValueSP &value_sp) { 79 // Make sure the value_sp object is allowed to contain values of the type 80 // passed in... 81 if (value_sp && (m_type_mask & value_sp->GetTypeAsMask())) { 82 if (idx < m_values.size()) 83 m_values.insert(m_values.begin() + idx, value_sp); 84 else 85 m_values.push_back(value_sp); 86 return true; 87 } 88 return false; 89 } 90 91 bool ReplaceValue(size_t idx, const lldb::OptionValueSP &value_sp) { 92 // Make sure the value_sp object is allowed to contain values of the type 93 // passed in... 94 if (value_sp && (m_type_mask & value_sp->GetTypeAsMask())) { 95 if (idx < m_values.size()) { 96 m_values[idx] = value_sp; 97 return true; 98 } 99 } 100 return false; 101 } 102 103 bool DeleteValue(size_t idx) { 104 if (idx < m_values.size()) { 105 m_values.erase(m_values.begin() + idx); 106 return true; 107 } 108 return false; 109 } 110 111 size_t GetArgs(Args &args) const; 112 113 Status SetArgs(const Args &args, VarSetOperationType op); 114 115 protected: 116 typedef std::vector<lldb::OptionValueSP> collection; 117 118 uint32_t m_type_mask; 119 collection m_values; 120 bool m_raw_value_dump; 121 }; 122 123 } // namespace lldb_private 124 125 #endif // LLDB_INTERPRETER_OPTIONVALUEARRAY_H 126