xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Interpreter/OptionValueSInt64.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===-- OptionValueSInt64.h --------------------------------------*- C++
2*0b57cec5SDimitry Andric //-*-===//
3*0b57cec5SDimitry Andric //
4*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*0b57cec5SDimitry Andric //
8*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
9*0b57cec5SDimitry Andric 
10*0b57cec5SDimitry Andric #ifndef liblldb_OptionValueSInt64_h_
11*0b57cec5SDimitry Andric #define liblldb_OptionValueSInt64_h_
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric #include "lldb/Interpreter/OptionValue.h"
14*0b57cec5SDimitry Andric 
15*0b57cec5SDimitry Andric namespace lldb_private {
16*0b57cec5SDimitry Andric 
17*0b57cec5SDimitry Andric class OptionValueSInt64 : public OptionValue {
18*0b57cec5SDimitry Andric public:
19*0b57cec5SDimitry Andric   OptionValueSInt64()
20*0b57cec5SDimitry Andric       : OptionValue(), m_current_value(0), m_default_value(0),
21*0b57cec5SDimitry Andric         m_min_value(INT64_MIN), m_max_value(INT64_MAX) {}
22*0b57cec5SDimitry Andric 
23*0b57cec5SDimitry Andric   OptionValueSInt64(int64_t value)
24*0b57cec5SDimitry Andric       : OptionValue(), m_current_value(value), m_default_value(value),
25*0b57cec5SDimitry Andric         m_min_value(INT64_MIN), m_max_value(INT64_MAX) {}
26*0b57cec5SDimitry Andric 
27*0b57cec5SDimitry Andric   OptionValueSInt64(int64_t current_value, int64_t default_value)
28*0b57cec5SDimitry Andric       : OptionValue(), m_current_value(current_value),
29*0b57cec5SDimitry Andric         m_default_value(default_value), m_min_value(INT64_MIN),
30*0b57cec5SDimitry Andric         m_max_value(INT64_MAX) {}
31*0b57cec5SDimitry Andric 
32*0b57cec5SDimitry Andric   OptionValueSInt64(const OptionValueSInt64 &rhs)
33*0b57cec5SDimitry Andric       : OptionValue(rhs), m_current_value(rhs.m_current_value),
34*0b57cec5SDimitry Andric         m_default_value(rhs.m_default_value), m_min_value(rhs.m_min_value),
35*0b57cec5SDimitry Andric         m_max_value(rhs.m_max_value) {}
36*0b57cec5SDimitry Andric 
37*0b57cec5SDimitry Andric   ~OptionValueSInt64() override {}
38*0b57cec5SDimitry Andric 
39*0b57cec5SDimitry Andric   // Virtual subclass pure virtual overrides
40*0b57cec5SDimitry Andric 
41*0b57cec5SDimitry Andric   OptionValue::Type GetType() const override { return eTypeSInt64; }
42*0b57cec5SDimitry Andric 
43*0b57cec5SDimitry Andric   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
44*0b57cec5SDimitry Andric                  uint32_t dump_mask) override;
45*0b57cec5SDimitry Andric 
46*0b57cec5SDimitry Andric   Status
47*0b57cec5SDimitry Andric   SetValueFromString(llvm::StringRef value,
48*0b57cec5SDimitry Andric                      VarSetOperationType op = eVarSetOperationAssign) override;
49*0b57cec5SDimitry Andric   Status
50*0b57cec5SDimitry Andric   SetValueFromString(const char *,
51*0b57cec5SDimitry Andric                      VarSetOperationType = eVarSetOperationAssign) = delete;
52*0b57cec5SDimitry Andric 
53*0b57cec5SDimitry Andric   bool Clear() override {
54*0b57cec5SDimitry Andric     m_current_value = m_default_value;
55*0b57cec5SDimitry Andric     m_value_was_set = false;
56*0b57cec5SDimitry Andric     return true;
57*0b57cec5SDimitry Andric   }
58*0b57cec5SDimitry Andric 
59*0b57cec5SDimitry Andric   lldb::OptionValueSP DeepCopy() const override;
60*0b57cec5SDimitry Andric 
61*0b57cec5SDimitry Andric   // Subclass specific functions
62*0b57cec5SDimitry Andric 
63*0b57cec5SDimitry Andric   const int64_t &operator=(int64_t value) {
64*0b57cec5SDimitry Andric     m_current_value = value;
65*0b57cec5SDimitry Andric     return m_current_value;
66*0b57cec5SDimitry Andric   }
67*0b57cec5SDimitry Andric 
68*0b57cec5SDimitry Andric   int64_t GetCurrentValue() const { return m_current_value; }
69*0b57cec5SDimitry Andric 
70*0b57cec5SDimitry Andric   int64_t GetDefaultValue() const { return m_default_value; }
71*0b57cec5SDimitry Andric 
72*0b57cec5SDimitry Andric   bool SetCurrentValue(int64_t value) {
73*0b57cec5SDimitry Andric     if (value >= m_min_value && value <= m_max_value) {
74*0b57cec5SDimitry Andric       m_current_value = value;
75*0b57cec5SDimitry Andric       return true;
76*0b57cec5SDimitry Andric     }
77*0b57cec5SDimitry Andric     return false;
78*0b57cec5SDimitry Andric   }
79*0b57cec5SDimitry Andric 
80*0b57cec5SDimitry Andric   bool SetDefaultValue(int64_t value) {
81*0b57cec5SDimitry Andric     if (value >= m_min_value && value <= m_max_value) {
82*0b57cec5SDimitry Andric       m_default_value = value;
83*0b57cec5SDimitry Andric       return true;
84*0b57cec5SDimitry Andric     }
85*0b57cec5SDimitry Andric     return false;
86*0b57cec5SDimitry Andric   }
87*0b57cec5SDimitry Andric 
88*0b57cec5SDimitry Andric   void SetMinimumValue(int64_t v) { m_min_value = v; }
89*0b57cec5SDimitry Andric 
90*0b57cec5SDimitry Andric   int64_t GetMinimumValue() const { return m_min_value; }
91*0b57cec5SDimitry Andric 
92*0b57cec5SDimitry Andric   void SetMaximumValue(int64_t v) { m_max_value = v; }
93*0b57cec5SDimitry Andric 
94*0b57cec5SDimitry Andric   int64_t GetMaximumValue() const { return m_max_value; }
95*0b57cec5SDimitry Andric 
96*0b57cec5SDimitry Andric protected:
97*0b57cec5SDimitry Andric   int64_t m_current_value;
98*0b57cec5SDimitry Andric   int64_t m_default_value;
99*0b57cec5SDimitry Andric   int64_t m_min_value;
100*0b57cec5SDimitry Andric   int64_t m_max_value;
101*0b57cec5SDimitry Andric };
102*0b57cec5SDimitry Andric 
103*0b57cec5SDimitry Andric } // namespace lldb_private
104*0b57cec5SDimitry Andric 
105*0b57cec5SDimitry Andric #endif // liblldb_OptionValueSInt64_h_
106