WPILibC++  unspecified
PropertyImpl.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef CSCORE_PROPERTYIMPL_H_
9 #define CSCORE_PROPERTYIMPL_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include <llvm/StringRef.h>
15 
16 #include "cscore_c.h"
17 
18 namespace cs {
19 
20 // Property data
21 class PropertyImpl {
22  public:
23  PropertyImpl() = default;
24  explicit PropertyImpl(llvm::StringRef name_) : name{name_} {}
25  PropertyImpl(llvm::StringRef name_, CS_PropertyKind kind_, int step_,
26  int defaultValue_, int value_)
27  : name{name_},
28  propKind{kind_},
29  step{step_},
30  defaultValue{defaultValue_},
31  value{value_} {}
32  virtual ~PropertyImpl() = default;
33  PropertyImpl(const PropertyImpl& oth) = delete;
34  PropertyImpl& operator=(const PropertyImpl& oth) = delete;
35 
36  void SetValue(int v) {
37  if (hasMinimum && v < minimum)
38  value = minimum;
39  else if (hasMaximum && v > maximum)
40  value = maximum;
41  else
42  value = v;
43  valueSet = true;
44  }
45 
46  void SetValue(llvm::StringRef v) {
47  valueStr = v;
48  valueSet = true;
49  }
50 
51  void SetDefaultValue(int v) {
52  if (hasMinimum && v < minimum)
53  defaultValue = minimum;
54  else if (hasMaximum && v > maximum)
55  defaultValue = maximum;
56  else
57  defaultValue = v;
58  }
59 
60  std::string name;
61  CS_PropertyKind propKind{CS_PROP_NONE};
62  bool hasMinimum{false};
63  bool hasMaximum{false};
64  int minimum{0};
65  int maximum{100};
66  int step{1};
67  int defaultValue{0};
68  int value{0};
69  std::string valueStr;
70  std::vector<std::string> enumChoices;
71  bool valueSet{false};
72 };
73 
74 } // namespace cs
75 
76 #endif // CSCORE_PROPERTYIMPL_H_
Definition: SinkImpl.h:19
Definition: PropertyImpl.h:21
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42