You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/08/02 17:18:51 UTC
svn commit: r1368522 - in /incubator/etch/trunk/binding-cpp/runtime:
include/common/EtchInt32.h src/main/common/EtchInt32.cpp
src/test/common/EtchInt32Test.cpp
Author: veithm
Date: Thu Aug 2 15:18:51 2012
New Revision: 1368522
URL: http://svn.apache.org/viewvc?rev=1368522&view=rev
Log:
ETCH-132 Added some operators to EtchInt32
Change-Id: I63c32edbf69d32659331082aa9f14d0ca0db8c88
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchInt32.h
incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchInt32.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchInt32Test.cpp
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchInt32.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchInt32.h?rev=1368522&r1=1368521&r2=1368522&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchInt32.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchInt32.h Thu Aug 2 15:18:51 2012
@@ -65,8 +65,42 @@ public:
*/
capu::bool_t equals(const EtchObject * other) const;
-private:
+ /**
+ * assigns an integer number to the stored value
+ */
+ capu::int32_t& operator=(capu::int32_t const& other);
+
+ /**
+ * increments and assigns the stored integer value
+ */
+ capu::int32_t& operator++();
+
+ /**
+ * assigns and increments the stored integer value
+ */
+ const capu::int32_t operator++(int);
+
+ /**
+ * decrement and assigns the stored integer value
+ */
+ capu::int32_t& operator--();
+ /**
+ * assigns and decrement the stored integer value
+ */
+ const capu::int32_t operator--(int);
+
+ /**
+ * returns true if two objects are equal
+ */
+ capu::bool_t operator==(const EtchObject& other) const;
+
+ /**
+ * returns true if two objects are not equal
+ */
+ capu::bool_t operator!=(const EtchObject& other) const;
+
+private:
capu::int32_t mValue;
};
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchInt32.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchInt32.cpp?rev=1368522&r1=1368521&r2=1368522&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchInt32.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchInt32.cpp Thu Aug 2 15:18:51 2012
@@ -19,8 +19,8 @@
#include "common/EtchInt32.h"
const EtchObjectType* EtchInt32::TYPE() {
- const static EtchObjectType TYPE(EOTID_INT32, NULL);
- return &TYPE;
+ const static EtchObjectType TYPE(EOTID_INT32, NULL);
+ return &TYPE;
}
EtchInt32::EtchInt32()
@@ -53,3 +53,47 @@ capu::bool_t EtchInt32::equals(const Etc
EtchInt32 *a = (EtchInt32*) other;
return (a->mValue == this->mValue);
}
+
+capu::int32_t& EtchInt32::operator=(capu::int32_t const& other)
+{
+ if(mValue != other)
+ {
+ mValue = other;
+ }
+ return mValue;
+}
+
+capu::int32_t& EtchInt32::operator++() //pre increment
+{
+ ++mValue;
+ return mValue;
+}
+const capu::int32_t EtchInt32::operator++(int) //post increment
+{
+ capu::int32_t tmp(mValue);
+ ++mValue;
+ return tmp;
+}
+
+capu::int32_t& EtchInt32::operator--() //pre increment
+{
+ --mValue;
+ return mValue;
+}
+
+const capu::int32_t EtchInt32::operator--(int) //post increment
+{
+ capu::int32_t tmp(mValue);
+ --mValue;
+ return tmp;
+}
+
+capu::bool_t EtchInt32::operator==(const EtchObject& other) const
+{
+ return this->equals(&other);
+}
+
+capu::bool_t EtchInt32::operator!=(const EtchObject& other) const
+{
+ return !(*this == other);
+}
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchInt32Test.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchInt32Test.cpp?rev=1368522&r1=1368521&r2=1368522&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchInt32Test.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchInt32Test.cpp Thu Aug 2 15:18:51 2012
@@ -59,3 +59,71 @@ TEST(EtchInt32Test, equals){
i2.set(40);
EXPECT_TRUE(i1.equals(&i2) == true);
}
+
+TEST(EtchInt32Test, operator_equal){
+ EtchInt32 a = 0;
+ EXPECT_EQ(0, a.get());
+ a = 5;
+ EXPECT_EQ(5, a.get());
+ EtchInt32 b(12);
+ a = b;
+ EXPECT_EQ(12, a.get());
+}
+
+TEST(EtchInt32Test, operator_post_plusplus){
+ EtchInt32 a = 0;
+ for(int i = 1; i <= 10; i++)
+ {
+ a++;
+ EXPECT_EQ(i, a.get());
+ }
+ EXPECT_EQ(10, a++);
+ EXPECT_EQ(11, a.get());
+}
+
+TEST(EtchInt32Test, operator_pre_plusplus){
+ EtchInt32 a = 0;
+ for(int i = 1; i <= 10; i++)
+ {
+ EXPECT_EQ(i, ++a);
+ }
+ EXPECT_EQ(10, a.get());
+ EXPECT_EQ(11, ++a);
+}
+
+TEST(EtchInt32Test, operator_post_minusminus){
+ EtchInt32 a = 11;
+ for(int i = 10; i > 0; i--)
+ {
+ a--;
+ EXPECT_EQ(i, a.get());
+ }
+ EXPECT_EQ(1, a--);
+ EXPECT_EQ(0, a.get());
+}
+
+TEST(EtchInt32Test, operator_pre_minusminus){
+ EtchInt32 a = 11;
+ for(int i = 10; i > 0; i--)
+ {
+ EXPECT_EQ(i, --a);
+ }
+ EXPECT_EQ(1, a.get());
+ EXPECT_EQ(0, --a);
+}
+
+TEST(EtchInt32Test, operator_equalequal){
+ EtchInt32 a(12);
+ EtchInt32 b(12);
+ EXPECT_TRUE(a == b);
+ ++b;
+ EXPECT_FALSE(a == b);
+}
+
+TEST(EtchInt32Test, operator_unequal){
+ EtchInt32 a(12);
+ EtchInt32 b(11);
+ EXPECT_TRUE(a != b);
+ ++b;
+ EXPECT_FALSE(a != b);
+}