xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Interpreter/OptionValueSInt64.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- OptionValueSInt64.h --------------------------------------*- C++
20b57cec5SDimitry Andric //-*-===//
30b57cec5SDimitry Andric //
40b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric //
80b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric 
105ffd83dbSDimitry Andric #ifndef LLDB_INTERPRETER_OPTIONVALUESINT64_H
115ffd83dbSDimitry Andric #define LLDB_INTERPRETER_OPTIONVALUESINT64_H
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "lldb/Interpreter/OptionValue.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric namespace lldb_private {
160b57cec5SDimitry Andric 
17fe6060f1SDimitry Andric class OptionValueSInt64 : public Cloneable<OptionValueSInt64, OptionValue> {
180b57cec5SDimitry Andric public:
19fe6060f1SDimitry Andric   OptionValueSInt64() = default;
200b57cec5SDimitry Andric 
OptionValueSInt64(int64_t value)210b57cec5SDimitry Andric   OptionValueSInt64(int64_t value)
22fe6060f1SDimitry Andric       : m_current_value(value), m_default_value(value) {}
230b57cec5SDimitry Andric 
OptionValueSInt64(int64_t current_value,int64_t default_value)240b57cec5SDimitry Andric   OptionValueSInt64(int64_t current_value, int64_t default_value)
25fe6060f1SDimitry Andric       : m_current_value(current_value), m_default_value(default_value) {}
260b57cec5SDimitry Andric 
27fe6060f1SDimitry Andric   OptionValueSInt64(const OptionValueSInt64 &rhs) = default;
280b57cec5SDimitry Andric 
29fe6060f1SDimitry Andric   ~OptionValueSInt64() override = default;
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric   // Virtual subclass pure virtual overrides
320b57cec5SDimitry Andric 
GetType()330b57cec5SDimitry Andric   OptionValue::Type GetType() const override { return eTypeSInt64; }
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
360b57cec5SDimitry Andric                  uint32_t dump_mask) override;
370b57cec5SDimitry Andric 
ToJSON(const ExecutionContext * exe_ctx)38bdd1243dSDimitry Andric   llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
39bdd1243dSDimitry Andric     return m_current_value;
40bdd1243dSDimitry Andric   }
41bdd1243dSDimitry Andric 
420b57cec5SDimitry Andric   Status
430b57cec5SDimitry Andric   SetValueFromString(llvm::StringRef value,
440b57cec5SDimitry Andric                      VarSetOperationType op = eVarSetOperationAssign) override;
450b57cec5SDimitry Andric 
Clear()46e8d8bef9SDimitry Andric   void Clear() override {
470b57cec5SDimitry Andric     m_current_value = m_default_value;
480b57cec5SDimitry Andric     m_value_was_set = false;
490b57cec5SDimitry Andric   }
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric   // Subclass specific functions
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   const int64_t &operator=(int64_t value) {
540b57cec5SDimitry Andric     m_current_value = value;
550b57cec5SDimitry Andric     return m_current_value;
560b57cec5SDimitry Andric   }
570b57cec5SDimitry Andric 
GetCurrentValue()580b57cec5SDimitry Andric   int64_t GetCurrentValue() const { return m_current_value; }
590b57cec5SDimitry Andric 
GetDefaultValue()600b57cec5SDimitry Andric   int64_t GetDefaultValue() const { return m_default_value; }
610b57cec5SDimitry Andric 
SetCurrentValue(int64_t value)620b57cec5SDimitry Andric   bool SetCurrentValue(int64_t value) {
630b57cec5SDimitry Andric     if (value >= m_min_value && value <= m_max_value) {
640b57cec5SDimitry Andric       m_current_value = value;
650b57cec5SDimitry Andric       return true;
660b57cec5SDimitry Andric     }
670b57cec5SDimitry Andric     return false;
680b57cec5SDimitry Andric   }
690b57cec5SDimitry Andric 
SetDefaultValue(int64_t value)700b57cec5SDimitry Andric   bool SetDefaultValue(int64_t value) {
710b57cec5SDimitry Andric     if (value >= m_min_value && value <= m_max_value) {
720b57cec5SDimitry Andric       m_default_value = value;
730b57cec5SDimitry Andric       return true;
740b57cec5SDimitry Andric     }
750b57cec5SDimitry Andric     return false;
760b57cec5SDimitry Andric   }
770b57cec5SDimitry Andric 
SetMinimumValue(int64_t v)780b57cec5SDimitry Andric   void SetMinimumValue(int64_t v) { m_min_value = v; }
790b57cec5SDimitry Andric 
GetMinimumValue()800b57cec5SDimitry Andric   int64_t GetMinimumValue() const { return m_min_value; }
810b57cec5SDimitry Andric 
SetMaximumValue(int64_t v)820b57cec5SDimitry Andric   void SetMaximumValue(int64_t v) { m_max_value = v; }
830b57cec5SDimitry Andric 
GetMaximumValue()840b57cec5SDimitry Andric   int64_t GetMaximumValue() const { return m_max_value; }
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric protected:
87fe6060f1SDimitry Andric   int64_t m_current_value = 0;
88fe6060f1SDimitry Andric   int64_t m_default_value = 0;
89*0fca6ea1SDimitry Andric   int64_t m_min_value = std::numeric_limits<int64_t>::min();
90*0fca6ea1SDimitry Andric   int64_t m_max_value = std::numeric_limits<int64_t>::max();
910b57cec5SDimitry Andric };
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric } // namespace lldb_private
940b57cec5SDimitry Andric 
955ffd83dbSDimitry Andric #endif // LLDB_INTERPRETER_OPTIONVALUESINT64_H
96