|
From: <den...@us...> - 2009-10-14 14:33:48
|
Revision: 45
http://stdair.svn.sourceforge.net/stdair/?rev=45&view=rev
Author: denis_arnaud
Date: 2009-10-14 14:33:39 +0000 (Wed, 14 Oct 2009)
Log Message:
-----------
[Test] Added tests on the inheritance mechanism.
Modified Paths:
--------------
trunk/stdair/configure.ac
trunk/stdair/test/Makefile.am
Added Paths:
-----------
trunk/stdair/test/inheritance/
trunk/stdair/test/inheritance/Makefile.am
trunk/stdair/test/inheritance/inherit.cpp
Modified: trunk/stdair/configure.ac
===================================================================
--- trunk/stdair/configure.ac 2009-10-13 07:52:49 UTC (rev 44)
+++ trunk/stdair/configure.ac 2009-10-14 14:33:39 UTC (rev 45)
@@ -4,7 +4,7 @@
AC_COPYRIGHT([Copyright (C) 2007-2009 Denis Arnaud <den...@us...>])
AC_INIT([STDAIR],[0.1.0],[den...@us...],[stdair])
AC_CONFIG_HEADER([stdair/config.h])
-AC_CONFIG_SRCDIR([stdair/bom/BomKey.cpp])
+AC_CONFIG_SRCDIR([stdair/bom/BomKey.hpp])
AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE
AM_PATH_CPPUNIT(1.10)
@@ -202,6 +202,7 @@
doc/sourceforge/howto_release_stdair.html
test/Makefile
test/com/Makefile
+ test/inheritance/Makefile
test/mpl/Makefile
test/mpl/book/Makefile)
AC_OUTPUT
Modified: trunk/stdair/test/Makefile.am
===================================================================
--- trunk/stdair/test/Makefile.am 2009-10-13 07:52:49 UTC (rev 44)
+++ trunk/stdair/test/Makefile.am 2009-10-14 14:33:39 UTC (rev 45)
@@ -4,7 +4,7 @@
MAINTAINERCLEANFILES = Makefile.in
##
-SUBDIRS = com mpl
+SUBDIRS = com inheritance mpl
EXTRA_DIST =
##
Property changes on: trunk/stdair/test/inheritance
___________________________________________________________________
Added: svn:ignore
+ .deps
.libs
Makefile
Makefile.in
inherit
Added: svn:propedit
+
Added: trunk/stdair/test/inheritance/Makefile.am
===================================================================
--- trunk/stdair/test/inheritance/Makefile.am (rev 0)
+++ trunk/stdair/test/inheritance/Makefile.am 2009-10-14 14:33:39 UTC (rev 45)
@@ -0,0 +1,14 @@
+## test/inheritance sub-directory
+include $(top_srcdir)/Makefile.common
+
+MAINTAINERCLEANFILES = Makefile.in
+
+SUBDIRS =
+
+check_PROGRAMS = inherit
+
+inherit_SOURCES = inherit.cpp
+inherit_CXXFLAGS = $(BOOST_CFLAGS)
+inherit_LDADD = $(BOOST_LIB)
+
+EXTRA_DIST =
Added: trunk/stdair/test/inheritance/inherit.cpp
===================================================================
--- trunk/stdair/test/inheritance/inherit.cpp (rev 0)
+++ trunk/stdair/test/inheritance/inherit.cpp 2009-10-14 14:33:39 UTC (rev 45)
@@ -0,0 +1,81 @@
+// STL
+#include <cassert>
+#include <iostream>
+#include <string>
+
+// ////////////////////////////////////
+typedef unsigned int Size_T;
+typedef std::pair<Size_T, Size_T> RectangleSize_T;
+
+// ////////////////////////////////////
+/** Rectangle */
+struct Rectangle {
+
+ /** Constructor */
+ Rectangle (const Size_T& iWidth, const Size_T& iHeight)
+ : _width (iWidth), _height (iHeight) { }
+ /** Destructor */
+ virtual ~Rectangle () { }
+
+ /** Get the size. */
+ RectangleSize_T getSize() const {
+ return RectangleSize_T (_width, _height);
+ }
+
+ /** Display. When the object is actually inherits from Rectangle,
+ the display() method actually called is the one of the
+ inheriting object. */
+ virtual void display () const {
+ std::cout << "Hello, I am a rectangle of size (" << _width << " x "
+ << _height << ")" << std::endl;
+ }
+
+ // //////// Attributes /////////
+ /** Width, Height */
+ Size_T _width;
+ Size_T _height;
+};
+
+/** Square */
+struct Square : public Rectangle {
+
+ /** Constructor */
+ Square (const Size_T& iWidth) : Rectangle (iWidth, iWidth) { }
+ /** Destructor */
+ virtual ~Square () { }
+
+ /** Get the size. That method overshadows the Rectangle::getSize() one. */
+ Size_T getSize() const {
+ return _width;
+ }
+
+ /** Display */
+ void display () const {
+ std::cout << "Hello, I am a square of size (" << _width << ")"
+ << std::endl;
+ }
+};
+
+
+// ////////// M A I N //////////////
+int main (int argc, char* argv[]) {
+
+ Square lSquare (10);
+ lSquare.display();
+ const Size_T& lSquareSize = lSquare.getSize();
+ std::cout << " and my size is: " << lSquareSize << std::endl;
+
+ Rectangle& lRectangle = lSquare;
+ lRectangle.display();
+ const RectangleSize_T& lRectangleSize = lRectangle.getSize();
+ std::cout << " and my size is: " << lRectangleSize.first << " x "
+ << lRectangleSize.second << std::endl;
+
+ Rectangle lRectangleCopy = lSquare;
+ lRectangleCopy.display();
+ const RectangleSize_T& lRectangleCopySize = lRectangleCopy.getSize();
+ std::cout << " and my size is: " << lRectangleCopySize.first << " x "
+ << lRectangleCopySize.second << std::endl;
+
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|