[opengtl-commits] [718] introduce convenient functio to test if a type is an integer or a float

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 718
Author:   cyrille
Date:     2009-04-11 13:04:48 +0200 (Sat, 11 Apr 2009)

Log Message:
-----------
introduce convenient functio to test if a type is an integer or a float

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type.h
    trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2009-04-09 14:19:19 UTC (rev 717)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2009-04-11 11:04:48 UTC (rev 718)
@@ -281,5 +281,15 @@
 
 bool Type::isNumber() const
 {
-  return d->dataType == BOOLEAN or d->dataType == INTEGER8 or d->dataType == UNSIGNED_INTEGER8 or d->dataType == INTEGER16 or d->dataType == UNSIGNED_INTEGER16 or d->dataType == INTEGER32 or d->dataType == UNSIGNED_INTEGER32 or d->dataType == DOUBLE or d->dataType == FLOAT or d->dataType == HALF;
+  return isInteger() or isFloatingPoint();
 }
+
+bool Type::isInteger() const
+{
+  return d->dataType == BOOLEAN or d->dataType == INTEGER8 or d->dataType == UNSIGNED_INTEGER8 or d->dataType == INTEGER16 or d->dataType == UNSIGNED_INTEGER16 or d->dataType == INTEGER32 or d->dataType == UNSIGNED_INTEGER32;
+}
+
+bool Type::isFloatingPoint() const
+{
+  return d->dataType == DOUBLE or d->dataType == FLOAT or d->dataType == HALF;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2009-04-09 14:19:19 UTC (rev 717)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2009-04-11 11:04:48 UTC (rev 718)
@@ -209,6 +209,14 @@
        */
       unsigned int vectorSize() const;
       /**
+       * @return true if the type is an integer type (BOOLEAN, INTEGER8, INTEGER16...)
+       */
+      bool isInteger() const;
+      /**
+       * @return true if the type is a floating point (DOUBLE, FLOAT or HALF)
+       */
+      bool isFloatingPoint() const;
+      /**
        * @return true if the type is a number (this return false if the type is a \ref VECTOR )
        */
       bool isNumber() const;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h	2009-04-09 14:19:19 UTC (rev 717)
+++ trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h	2009-04-11 11:04:48 UTC (rev 718)
@@ -28,6 +28,9 @@
       GTLTEST_CHECK_EQUAL(Type::Float->bitsSize(), 32);
       GTLTEST_CHECK_EQUAL(Type::Float->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Float->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::Float->isNumber());
+      GTLTEST_CHECK(not Type::Float->isInteger());
+      GTLTEST_CHECK(Type::Float->isFloatingPoint());
     }
 };
 
@@ -38,30 +41,61 @@
     }
     virtual void runTest()
     {
+      GTLTEST_CHECK_EQUAL(Type::Boolean->dataType(), Type::BOOLEAN);
+      GTLTEST_CHECK_EQUAL(Type::Boolean->bitsSize(), 1);
+      GTLTEST_CHECK_EQUAL(Type::Boolean->embeddedType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Boolean->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::Boolean->isNumber());
+      GTLTEST_CHECK(Type::Boolean->isInteger());
+      GTLTEST_CHECK(not Type::Boolean->isFloatingPoint());
+      
       GTLTEST_CHECK_EQUAL(Type::Integer8->dataType(), Type::INTEGER8);
       GTLTEST_CHECK_EQUAL(Type::Integer8->bitsSize(), 8);
       GTLTEST_CHECK_EQUAL(Type::Integer8->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer8->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::Integer8->isNumber());
+      GTLTEST_CHECK(Type::Integer8->isInteger());
+      GTLTEST_CHECK(not Type::Integer8->isFloatingPoint());
+      
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->dataType(), Type::UNSIGNED_INTEGER8);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->bitsSize(), 8);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::UnsignedInteger8->isNumber());
+      GTLTEST_CHECK(Type::UnsignedInteger8->isInteger());
+      GTLTEST_CHECK(not Type::UnsignedInteger8->isFloatingPoint());
+      
       GTLTEST_CHECK_EQUAL(Type::Integer16->dataType(), Type::INTEGER16);
       GTLTEST_CHECK_EQUAL(Type::Integer16->bitsSize(), 16);
       GTLTEST_CHECK_EQUAL(Type::Integer16->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer16->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::Integer16->isNumber());
+      GTLTEST_CHECK(Type::Integer16->isInteger());
+      GTLTEST_CHECK(not Type::Integer16->isFloatingPoint());
+      
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->dataType(), Type::UNSIGNED_INTEGER16);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->bitsSize(), 16);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::UnsignedInteger16->isNumber());
+      GTLTEST_CHECK(Type::UnsignedInteger16->isInteger());
+      GTLTEST_CHECK(not Type::UnsignedInteger16->isFloatingPoint());
+      
       GTLTEST_CHECK_EQUAL(Type::Integer32->dataType(), Type::INTEGER32);
       GTLTEST_CHECK_EQUAL(Type::Integer32->bitsSize(), 32);
       GTLTEST_CHECK_EQUAL(Type::Integer32->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer32->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::Integer32->isNumber());
+      GTLTEST_CHECK(Type::Integer32->isInteger());
+      GTLTEST_CHECK(not Type::Integer32->isFloatingPoint());
+      
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->dataType(), Type::UNSIGNED_INTEGER32);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->bitsSize(), 32);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->countStructDataMembers(), 0);
+      GTLTEST_CHECK(Type::UnsignedInteger32->isNumber());
+      GTLTEST_CHECK(Type::UnsignedInteger32->isInteger());
+      GTLTEST_CHECK(not Type::UnsignedInteger32->isFloatingPoint());
     }
 };
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/