Initial release
KeyValueInt.cpp
- Committer:
- masakjm
- Date:
- 2018-09-17
- Revision:
- 0:28fb3e9ef81a
- Child:
- 3:b6e9850d3e76
File content as of revision 0:28fb3e9ef81a:
//================================= // Class KeyValueInt //================================= // The MIT License (MIT) Copyright (c) 2018 Masatomo Kojima // // Keys and values are stored in pairs, maximum and minimum values are set, // and values can be easily increased or decreased. // キーと値をペアで記憶し、値の最大値、最小値を設定し、値の増減を容易にします。 #include "KeyValueInt.h" KeyValueInt::KeyValueInt(const char *key, char disp, int data, int min, int max, bool rotation) { this->key = key; this->disp = (disp==0 ? key[0] : disp); this->value = data; this->min = min; this->max = max; this->rotation = rotation; set(data); } int KeyValueInt::range(int data){ if (this->rotation) { if (data < this->min) data = this->max; if (data > this->max) data = this->min; } else { if (data < this->min) data = this->min; if (data > this->max) data = this->max; } return data; } int KeyValueInt::set(int data){ this->value = range(data); return this->value; } void KeyValueInt::inc(int delta){ set(range(value + delta)); } void KeyValueInt::dec(int delta){ set(range(value - delta)); }