From f16847ab29d474e2b20d7f8c9f3a0f229b54c850 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Tue, 22 Oct 2013 05:17:33 -0700 Subject: {auto} support for modulus operator --- include/value.h | 30 ++++++++++++++++++++++++++++++ src/value.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/value.h b/include/value.h index ed6cec4..bb7f354 100644 --- a/include/value.h +++ b/include/value.h @@ -163,6 +163,21 @@ public: Value &operator/=(const std::string &value); Value &operator/=(const char *value); Value &operator/=(double value); + + /** + * Divide the object with a certain value, and get the rest + * @param value + * @return Value + */ + Value &operator%=(const Value &value); + Value &operator%=(int16_t value); + Value &operator%=(int32_t value); + Value &operator%=(int64_t value); + Value &operator%=(bool value); + Value &operator%=(char value); + Value &operator%=(const std::string &value); + Value &operator%=(const char *value); + Value &operator%=(double value); /** * Assignment operator @@ -223,6 +238,21 @@ public: Value operator/(const std::string &value); Value operator/(const char *value); Value operator/(double value); + + /** + * Modulus operator + * @param value + * @return Value + */ + Value operator%(const Value &value); + Value operator%(int16_t value); + Value operator%(int32_t value); + Value operator%(int64_t value); + Value operator%(bool value); + Value operator%(char value); + Value operator%(const std::string &value); + Value operator%(const char *value); + Value operator%(double value); /** * The type of object diff --git a/src/value.cpp b/src/value.cpp index b1ec3c8..5e6d9b0 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -568,6 +568,22 @@ Value &Value::operator/=(const std::string &value) { return Arithmetic(this).assign(value); } Value &Value::operator/=(double value) { return Arithmetic(this).assign(value); } +/** + * Divide the object with a certain value and get the rest + * Note that this does not use the Arithmetic object, because no conversion between floats is necessary + * @param value + * @return Value + */ +Value &Value::operator%=(const Value &value) { return operator=(numericValue() % value.numericValue()); } +Value &Value::operator%=(int16_t value) { return operator=(numericValue() % value); } +Value &Value::operator%=(int32_t value) { return operator=(numericValue() % value); } +Value &Value::operator%=(int64_t value) { return operator=(numericValue() % value); } +Value &Value::operator%=(bool value) { return operator=(numericValue() % value); } +Value &Value::operator%=(char value) { return operator=(numericValue() % value); } +Value &Value::operator%=(const std::string &value) { return operator=(numericValue() % atoi(value.c_str())); } +Value &Value::operator%=(const char *value) { return operator=(numericValue() % atoi(value)); } +Value &Value::operator%=(double value) { return operator=(numericValue() % (int)value); } + /** * Assignment operator * @param value @@ -628,6 +644,20 @@ Value Value::operator/(const std::string &value) { return Arithmetic(this).apply(value); } Value Value::operator/(double value) { return Arithmetic(this).apply(value); } +/** + * Modulus operator + * @param value + * @return Value + */ +Value Value::operator%(const Value &value) { return Value(numericValue() % value.numericValue()); } +Value Value::operator%(int16_t value) { return Value(numericValue() % value); } +Value Value::operator%(int32_t value) { return Value(numericValue() % value); } +Value Value::operator%(int64_t value) { return Value(numericValue() % value); } +Value Value::operator%(bool value) { return Value(numericValue() % value); } +Value Value::operator%(char value) { return Value(numericValue() % value); } +Value Value::operator%(const std::string &value) { return Value(numericValue() % atoi(value.c_str())); } +Value Value::operator%(const char *value) { return Value(numericValue() % atoi(value)); } +Value Value::operator%(double value) { return Value(numericValue() % (int)value); } /** * The type of object -- cgit v1.2.3