[opengtl-commits] [502] support for array in Value

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


Revision: 502
Author:   cyrille
Date:     2008-11-27 00:09:40 +0100 (Thu, 27 Nov 2008)

Log Message:
-----------
support for array in Value

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Value.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp	2008-11-26 23:09:28 UTC (rev 501)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Value.cpp	2008-11-26 23:09:40 UTC (rev 502)
@@ -21,6 +21,7 @@
 
 #include "Debug.h"
 #include "Type.h"
+#include "TypeManager_p.h"
 
 using namespace GTLCore;
 
@@ -30,6 +31,7 @@
     float f;
     int i;
     unsigned int ui;
+    std::vector< Value >* array;
   } value;
   const Type* type;
 };
@@ -63,6 +65,11 @@
   d->type = Type::UnsignedInteger32;
 }
 
+Value::Value(const std::vector< Value >& v) : d(new Private)
+{
+  d->value.array = new std::vector< Value >( v );
+  d->type = TypeManager::getArray( v[0].type() );
+}
 
 Value::Value(const Value& rhs) : d(new Private(*rhs.d))
 {
@@ -74,6 +81,10 @@
 }
 Value::~Value()
 {
+  if( d->type->dataType() == Type::ARRAY )
+  {
+    delete d->value.array;
+  }
   delete d;
 }
 
@@ -98,6 +109,12 @@
   RETURN_AS(float);
 }
 
+void Value::setFloat( float _v )
+{
+  d->value.f = _v;
+  d->type = Type::Float;
+}
+
 bool Value::asBoolean() const
 {
   RETURN_AS(bool);
@@ -123,3 +140,13 @@
   d->value.i = v;
   d->type = Type::Integer32;
 }
+
+const std::vector< Value >* Value::asArray() const
+{
+  if( d->type->dataType() == Type::ARRAY )
+  {
+    return d->value.array;
+  } else {
+    return 0;
+  }
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Value.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Value.h	2008-11-26 23:09:28 UTC (rev 501)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Value.h	2008-11-26 23:09:40 UTC (rev 502)
@@ -20,6 +20,8 @@
 #ifndef _GTLCORE_VALUE_H_
 #define _GTLCORE_VALUE_H_
 
+#include <vector>
+
 namespace GTLCore {
   class Type;
   /**
@@ -33,6 +35,7 @@
       Value(bool v);
       Value(int v);
       Value(unsigned int v);
+      Value(const std::vector< Value >& v);
       Value(const Value& v);
       Value operator=(const Value& rhs);
       ~Value();
@@ -42,6 +45,10 @@
        */
       float asFloat() const;
       /**
+       * Set the value to be a float.
+       */
+      void setFloat( float _v );
+      /**
        * @return the value as a boolean
        */
       bool asBoolean() const;
@@ -58,6 +65,10 @@
        */
       unsigned int asUnsignedInt32() const;
       /**
+       * @return the value as an array, or 0 if not an array
+       */
+      const std::vector< Value >* asArray() const;
+      /**
        * @return the type of the value.
        */
       const Type* type() const;


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