mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
// Copyright (c) FIRST and other WPILib contributors.
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
#include "PropertyImpl.h"
|
|
|
|
using namespace cs;
|
|
|
|
PropertyImpl::PropertyImpl(std::string_view name_) : name{name_} {}
|
|
PropertyImpl::PropertyImpl(std::string_view name_, CS_PropertyKind kind_,
|
|
int step_, int defaultValue_, int value_)
|
|
: name{name_},
|
|
propKind{kind_},
|
|
step{step_},
|
|
defaultValue{defaultValue_},
|
|
value{value_} {}
|
|
PropertyImpl::PropertyImpl(std::string_view name_, CS_PropertyKind kind_,
|
|
int minimum_, int maximum_, int step_,
|
|
int defaultValue_, int value_)
|
|
: name{name_},
|
|
propKind{kind_},
|
|
hasMinimum{true},
|
|
hasMaximum{true},
|
|
minimum{minimum_},
|
|
maximum{maximum_},
|
|
step{step_},
|
|
defaultValue{defaultValue_},
|
|
value{value_} {}
|
|
|
|
void PropertyImpl::SetValue(int v) {
|
|
int oldValue = value;
|
|
if (hasMinimum && v < minimum) {
|
|
value = minimum;
|
|
} else if (hasMaximum && v > maximum) {
|
|
value = maximum;
|
|
} else {
|
|
value = v;
|
|
}
|
|
bool wasValueSet = valueSet;
|
|
valueSet = true;
|
|
if (!wasValueSet || value != oldValue) {
|
|
changed();
|
|
}
|
|
}
|
|
|
|
void PropertyImpl::SetValue(std::string_view v) {
|
|
bool valueChanged = false;
|
|
if (valueStr != v) {
|
|
valueStr = v;
|
|
valueChanged = true;
|
|
}
|
|
bool wasValueSet = valueSet;
|
|
valueSet = true;
|
|
if (!wasValueSet || valueChanged) {
|
|
changed();
|
|
}
|
|
}
|
|
|
|
void PropertyImpl::SetDefaultValue(int v) {
|
|
if (hasMinimum && v < minimum) {
|
|
defaultValue = minimum;
|
|
} else if (hasMaximum && v > maximum) {
|
|
defaultValue = maximum;
|
|
} else {
|
|
defaultValue = v;
|
|
}
|
|
}
|