[Branch,~jesse-barker/libmatrix/trunk] Rev 24: Enhance constness of vector addition and subtraction operators. Add a test to

Message ID 20110913163713.24006.53447.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Jesse Barker Sept. 13, 2011, 4:37 p.m.
------------------------------------------------------------
revno: 24
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Tue 2011-09-13 09:33:49 -0700
message:
  Enhance constness of vector addition and subtraction operators.  Add a test to
  enforce this (will fail at compile time).
added:
  test/const_vec_test.cc
  test/const_vec_test.h
modified:
  Makefile
  test/libmatrix_test.cc
  vec.h


--
lp:libmatrix
https://code.launchpad.net/~jesse-barker/libmatrix/trunk

You are subscribed to branch lp:libmatrix.
To unsubscribe from this branch go to https://code.launchpad.net/~jesse-barker/libmatrix/trunk/+edit-subscription

Patch

=== modified file 'Makefile'
--- Makefile	2011-06-22 23:11:46 +0000
+++ Makefile	2011-09-13 16:33:49 +0000
@@ -5,6 +5,7 @@ 
 TESTDIR = test
 LIBMATRIX_TESTS = $(TESTDIR)/libmatrix_test
 TESTSRCS = $(TESTDIR)/options.cc \
+           $(TESTDIR)/const_vec_test.cc \
            $(TESTDIR)/inverse_test.cc \
            $(TESTDIR)/transpose_test.cc \
            $(TESTDIR)/libmatrix_test.cc
@@ -23,6 +24,7 @@ 
 # Tests and execution targets here.
 $(TESTDIR)/options.o: $(TESTDIR)/options.cc $(TESTDIR)/libmatrix_test.h
 $(TESTDIR)/libmatrix_test.o: $(TESTDIR)/libmatrix_test.cc $(TESTDIR)/libmatrix_test.h $(TESTDIR)/inverse_test.h $(TESTDIR)/transpose_test.h
+$(TESTDIR)/const_vec_test.o: $(TESTDIR)/const_vec_test.cc $(TESTDIR)/const_vec_test.h $(TESTDIR)/libmatrix_test.h vec.h
 $(TESTDIR)/inverse_test.o: $(TESTDIR)/inverse_test.cc $(TESTDIR)/inverse_test.h $(TESTDIR)/libmatrix_test.h mat.h
 $(TESTDIR)/transpose_test.o: $(TESTDIR)/transpose_test.cc $(TESTDIR)/transpose_test.h $(TESTDIR)/libmatrix_test.h mat.h
 $(TESTDIR)/libmatrix_test: $(TESTOBJS) libmatrix.a

=== added file 'test/const_vec_test.cc'
--- test/const_vec_test.cc	1970-01-01 00:00:00 +0000
+++ test/const_vec_test.cc	2011-09-13 16:33:49 +0000
@@ -0,0 +1,48 @@ 
+//
+// Copyright (c) 2011 Linaro Limited
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the MIT License which accompanies
+// this distribution, and is available at
+// http://www.opensource.org/licenses/mit-license.php
+//
+// Contributors:
+//     Jesse Barker - original implementation.
+//
+#include <iostream>
+#include "libmatrix_test.h"
+#include "const_vec_test.h"
+#include "../vec.h"
+
+using LibMatrix::vec2;
+using LibMatrix::vec3;
+using LibMatrix::vec4;
+using std::cout;
+using std::endl;
+
+void
+Vec2TestConstOperator::run(const Options& options)
+{
+    const vec2 a(1.0, 1.0);
+    const vec2 b(2.0, 2.0);
+    vec2 aplusb(a + b);
+    vec2 aminusb(a - b);
+}
+
+void
+Vec3TestConstOperator::run(const Options& options)
+{
+    const vec3 a(1.0, 1.0, 1.0);
+    const vec3 b(2.0, 2.0, 2.0);
+    vec3 aplusb(a + b);
+    vec3 aminusb(a - b);
+}
+
+void
+Vec4TestConstOperator::run(const Options& options)
+{
+    const vec4 a(1.0, 1.0, 1.0, 1.0);
+    const vec4 b(2.0, 2.0, 2.0, 2.0);
+    vec4 aplusb(a + b);
+    vec4 aminusb(a - b);
+}

=== added file 'test/const_vec_test.h'
--- test/const_vec_test.h	1970-01-01 00:00:00 +0000
+++ test/const_vec_test.h	2011-09-13 16:33:49 +0000
@@ -0,0 +1,39 @@ 
+//
+// Copyright (c) 2011 Linaro Limited
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the MIT License which accompanies
+// this distribution, and is available at
+// http://www.opensource.org/licenses/mit-license.php
+//
+// Contributors:
+//     Jesse Barker - original implementation.
+//
+#ifndef CONST_VEC_TEST_H_
+#define CONST_VEC_TEST_H_
+
+class MatrixTest;
+class Options;
+
+class Vec2TestConstOperator : public MatrixTest
+{
+public:
+    Vec2TestConstOperator() : MatrixTest("vec2::const") {}
+    virtual void run(const Options& options);
+};
+
+class Vec3TestConstOperator : public MatrixTest
+{
+public:
+    Vec3TestConstOperator() : MatrixTest("vec3::const") {}
+    virtual void run(const Options& options);
+};
+
+class Vec4TestConstOperator : public MatrixTest
+{
+public:
+    Vec4TestConstOperator() : MatrixTest("vec4::const") {}
+    virtual void run(const Options& options);
+};
+
+#endif // CONST_VEC_TEST_H_

=== modified file 'test/libmatrix_test.cc'
--- test/libmatrix_test.cc	2011-06-22 23:11:46 +0000
+++ test/libmatrix_test.cc	2011-09-13 16:33:49 +0000
@@ -15,6 +15,7 @@ 
 #include "libmatrix_test.h"
 #include "inverse_test.h"
 #include "transpose_test.h"
+#include "const_vec_test.h"
 
 using std::cerr;
 using std::cout;

=== modified file 'vec.h'
--- vec.h	2010-12-17 17:07:27 +0000
+++ vec.h	2011-09-13 16:33:49 +0000
@@ -64,7 +64,7 @@ 
         return *this;
     }
 
-    const tvec2 operator/(const T& rhs)
+    const tvec2 operator/(const T& rhs) const
     {
         return tvec2(*this) /= rhs;
     }
@@ -76,7 +76,7 @@ 
         return *this;
     }
 
-    const tvec2 operator*(const T& rhs)
+    const tvec2 operator*(const T& rhs) const
     {
         return tvec2(*this) *= rhs;
     }
@@ -88,7 +88,7 @@ 
         return *this;
     }
     
-    const tvec2 operator+(const T& rhs)
+    const tvec2 operator+(const T& rhs) const
     {
         return tvec2(*this) += rhs;
     }
@@ -100,7 +100,7 @@ 
         return *this;
     }
 
-    const tvec2 operator+(const tvec2& rhs)
+    const tvec2 operator+(const tvec2& rhs) const
     {
         return tvec2(*this) += rhs;
     }
@@ -112,7 +112,7 @@ 
         return *this;
     }
     
-    const tvec2 operator-(const T& rhs)
+    const tvec2 operator-(const T& rhs) const
     {
         return tvec2(*this) -= rhs;
     }
@@ -124,7 +124,7 @@ 
         return *this;
     }
 
-    const tvec2 operator-(const tvec2& rhs)
+    const tvec2 operator-(const tvec2& rhs) const
     {
         return tvec2(*this) -= rhs;
     }
@@ -206,7 +206,7 @@ 
         return *this;
     }
 
-    const tvec3 operator/(const T& rhs)
+    const tvec3 operator/(const T& rhs) const
     {
         return tvec3(*this) /= rhs;
     }
@@ -219,7 +219,7 @@ 
         return *this;
     }
 
-    const tvec3 operator*(const T& rhs)
+    const tvec3 operator*(const T& rhs) const
     {
         return tvec3(*this) *= rhs;
     }
@@ -232,7 +232,7 @@ 
         return *this;
     }
 
-    const tvec3 operator+(const T& rhs)
+    const tvec3 operator+(const T& rhs) const
     {
         return tvec3(*this) += rhs;
     }
@@ -245,7 +245,7 @@ 
         return *this;
     }
 
-    const tvec3 operator+(const tvec3& rhs)
+    const tvec3 operator+(const tvec3& rhs) const
     {
         return tvec3(*this) += rhs;
     }
@@ -258,7 +258,7 @@ 
         return *this;
     }
 
-    const tvec3 operator-(const T& rhs)
+    const tvec3 operator-(const T& rhs) const
     {
         return tvec3(*this) -= rhs;
     }
@@ -271,7 +271,7 @@ 
         return *this;
     }
 
-    const tvec3 operator-(const tvec3& rhs)
+    const tvec3 operator-(const tvec3& rhs) const
     {
         return tvec3(*this) -= rhs;
     }
@@ -370,7 +370,7 @@ 
         return *this;
     }
 
-    const tvec4 operator/(const T& rhs)
+    const tvec4 operator/(const T& rhs) const
     {
         return tvec4(*this) /= rhs;
     }
@@ -384,7 +384,7 @@ 
         return *this;
     }
 
-    const tvec4 operator*(const T& rhs)
+    const tvec4 operator*(const T& rhs) const
     {
         return tvec4(*this) *= rhs;
     }
@@ -398,7 +398,7 @@ 
         return *this;
     }
 
-    const tvec4 operator+(const T& rhs)
+    const tvec4 operator+(const T& rhs) const
     {
         return tvec4(*this) += rhs;
     }
@@ -412,7 +412,7 @@ 
         return *this;
     }
 
-    const tvec4 operator+(const tvec4& rhs)
+    const tvec4 operator+(const tvec4& rhs) const
     {
         return tvec4(*this) += rhs;
     }
@@ -426,7 +426,7 @@ 
         return *this;
     }
 
-    const tvec4 operator-(const T& rhs)
+    const tvec4 operator-(const T& rhs) const
     {
         return tvec4(*this) -= rhs;
     }
@@ -440,7 +440,7 @@ 
         return *this;
     }
 
-    const tvec4 operator-(const tvec4& rhs)
+    const tvec4 operator-(const tvec4& rhs) const
     {
         return tvec4(*this) -= rhs;
     }