summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-22 05:17:33 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-22 05:17:33 -0700
commitf16847ab29d474e2b20d7f8c9f3a0f229b54c850 (patch)
tree1b66e989cb28ce42070abcf739157170b1f780ff
parent0914ea9fc9795cc997f8fdb22a8c678ad0ff40ba (diff)
{auto} support for modulus operator
-rw-r--r--include/value.h30
-rw-r--r--src/value.cpp30
2 files changed, 60 insertions, 0 deletions
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
@@ -569,6 +569,22 @@ Value &Value::operator/=(const char *value) { return Arithmetic<std::div
Value &Value::operator/=(double value) { return Arithmetic<std::divides>(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
* @return Value
@@ -628,6 +644,20 @@ Value Value::operator/(const std::string &value) { return Arithmetic<std::div
Value Value::operator/(const char *value) { return Arithmetic<std::divides>(this).apply(value); }
Value Value::operator/(double value) { return Arithmetic<std::divides>(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