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