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