Enabling support for arrays of custom types

Till now it was not possible to use arrays of custom types as parameters.
This support is now added by adding new functionality to the valuefactory
and the value factory code generation.

Change-Id: Id20ec86a55a821289727c7dc00653797ad509129

git-svn-id: https://svn.apache.org/repos/asf/etch/trunk@1578907 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
index fbe056e..dc2cc06 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
@@ -426,3 +426,16 @@
   
   return ETCH_OK;
 }
+
+status_t $vf::getNativeArrayForComponentType(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim) {
+#foreach ( $n in $intf.iterator() )
+#if ($n.isStruct())
+#set( $tname = $n.efqname( $helper ) )
+  if (objectType == $i::${tname}::TYPE()) {
+    nativeArray =  new EtchNativeArray<capu::SmartPointer<$i::${tname}> >(length, dim);
+    return ETCH_OK;
+  }
+#end
+#end
+  return ETCH_ERROR;
+}
\ No newline at end of file
diff --git a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
index ca0062f..726d69d 100644
--- a/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
+++ b/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
@@ -91,6 +91,9 @@
 #end
     static status_t InitImportExport(EtchRuntime* runtime);
 
+    status_t getNativeArrayForComponentType(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim);
+
+
     /**
      * Static Initialization-Helper
      */
diff --git a/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h b/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h
index d8dc8f2..92f8778 100644
--- a/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h
+++ b/binding-cpp/runtime/include/serialization/EtchDefaultValueFactory.h
@@ -182,6 +182,8 @@
 
   status_t getCustomStructType(const EtchObjectType *c, EtchType *& type);
 
+  virtual status_t getNativeArrayForComponentType(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim);
+
   /////////////////////
   // STRING ENCODING //
   /////////////////////
diff --git a/binding-cpp/runtime/include/serialization/EtchValueFactory.h b/binding-cpp/runtime/include/serialization/EtchValueFactory.h
index 7330edd..c9db773 100644
--- a/binding-cpp/runtime/include/serialization/EtchValueFactory.h
+++ b/binding-cpp/runtime/include/serialization/EtchValueFactory.h
@@ -27,6 +27,7 @@
 class EtchStructValue;
 class EtchMessage;
 class EtchType;
+class EtchNativeArrayBase;
 
 /**
  * Interface which defines the value factory which helps
@@ -221,6 +222,17 @@
    */
   virtual EtchLevel setLevel(EtchLevel level) = 0;
 
+  /**
+   * @param objectType the component's objectType of the EtchNativeArray
+   * @param nativeArray the created native array for the given component type
+   * @param length the length of the array
+   * @param dim the dimension of the array
+   * @return ETCH_OK if the type is found correctly.
+   *         ETCH_EUNIMPL if no type information for arrays has been generated
+   *         ETCH_ERROR if the array for the given object type cannot be generated
+   */
+  virtual status_t getNativeArrayForComponentType(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim) = 0;
+
 };
 
 #endif /* ETCHVALUEFACTORY_H */
diff --git a/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp b/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp
index 684ce77..12759af 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchDefaultValueFactory.cpp
@@ -317,6 +317,10 @@
   return ETCH_EINVAL;
 }
 
+status_t EtchDefaultValueFactory::getNativeArrayForComponentType(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim) {
+  return ETCH_EUNIMPL;
+}
+
 EtchString EtchDefaultValueFactory::getStringEncoding() {
   return EtchString("utf-8");
 }
diff --git a/binding-cpp/runtime/src/main/serialization/EtchTaggedData.cpp b/binding-cpp/runtime/src/main/serialization/EtchTaggedData.cpp
index ef6590c..fb2a680 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchTaggedData.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchTaggedData.cpp
@@ -96,10 +96,11 @@
       break;
 
     default:
-      //TODO: user definded types are not support yet. The have to be provided by the value factory
-      //EtchNativeArray<capu::SmartPointer<EtchObject> > * res = new EtchNativeArray<capu::SmartPointer<EtchObject> >(length, dim);
-      //res->mType = componentType;
-      //result = res;
+      status_t status = mVf->getNativeArrayForComponentType(componentType, result, length, dim);
+      if (status != ETCH_OK) {
+        return ETCH_ERROR;
+      }
+
       break;
   }
   return ETCH_OK;
diff --git a/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp
index cc5295a..893db12 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp
@@ -58,6 +58,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
diff --git a/binding-cpp/runtime/src/test/serialization/EtchBinaryTaggedDataInputOutputTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchBinaryTaggedDataInputOutputTest.cpp
index 4cb912e..c11c034 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchBinaryTaggedDataInputOutputTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchBinaryTaggedDataInputOutputTest.cpp
@@ -69,6 +69,8 @@
 

   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType* c, EtchType *& type));

 

+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {

     return LEVEL_FULL;

   }

diff --git a/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp
index e7952ad..c21d262 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp
@@ -58,6 +58,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
diff --git a/binding-cpp/runtime/src/test/serialization/EtchHashTableSerializerTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchHashTableSerializerTest.cpp
index 4fffa49..a9a48e1 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchHashTableSerializerTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchHashTableSerializerTest.cpp
@@ -58,6 +58,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
diff --git a/binding-cpp/runtime/src/test/serialization/EtchListSerializerTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchListSerializerTest.cpp
index 1db4709..d6ffa3c 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchListSerializerTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchListSerializerTest.cpp
@@ -59,6 +59,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
diff --git a/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp
index aee8934..bf0486a 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp
@@ -60,6 +60,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
diff --git a/binding-cpp/runtime/src/test/serialization/EtchSetSerializerTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchSetSerializerTest.cpp
index 2c85f86..4a49f5b 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchSetSerializerTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchSetSerializerTest.cpp
@@ -57,6 +57,8 @@
   MOCK_METHOD0(get_mt__exception, EtchType*());
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
+  
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
 
   EtchLevel getLevel() {
     return LEVEL_FULL;
diff --git a/binding-cpp/runtime/src/test/serialization/EtchStructValueTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchStructValueTest.cpp
index 6de9917..9a3bf27 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchStructValueTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchStructValueTest.cpp
@@ -60,6 +60,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
@@ -104,6 +106,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_MISSING_OK;
   }
@@ -148,6 +152,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_NONE;
   }
diff --git a/binding-cpp/runtime/src/test/serialization/EtchValidatorStructValueTest.cpp b/binding-cpp/runtime/src/test/serialization/EtchValidatorStructValueTest.cpp
index 8847776..478b1ef 100644
--- a/binding-cpp/runtime/src/test/serialization/EtchValidatorStructValueTest.cpp
+++ b/binding-cpp/runtime/src/test/serialization/EtchValidatorStructValueTest.cpp
@@ -66,6 +66,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
diff --git a/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp b/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp
index ae11581..2f81465 100644
--- a/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp
+++ b/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp
@@ -63,6 +63,8 @@
 
   MOCK_METHOD2(getCustomStructType, status_t(const EtchObjectType *c, EtchType *& type));
 
+  MOCK_METHOD4(getNativeArrayForComponentType, status_t(const EtchObjectType *objectType,  capu::SmartPointer<EtchNativeArrayBase> &nativeArray, capu::int32_t length, capu::int32_t dim));
+
   EtchLevel getLevel() {
     return LEVEL_FULL;
   }
diff --git a/examples/helloworld/cpp/src/main/include/ImplHelloWorldServer.h b/examples/helloworld/cpp/src/main/include/ImplHelloWorldServer.h
index b9344dd..88a44e4 100644
--- a/examples/helloworld/cpp/src/main/include/ImplHelloWorldServer.h
+++ b/examples/helloworld/cpp/src/main/include/ImplHelloWorldServer.h
@@ -37,7 +37,7 @@
 
     // TODO insert methods here to provide declarations of HelloWorldServer
     // messages from the mClient.
-    say_helloAsyncResultPtr say_hello(HelloWorld::userPtr to_whom);
+    say_helloAsyncResultPtr say_hello(HelloWorld::EtchNativeArrayuserPtr to_whom);
 
     virtual status_t _sessionNotify(capu::SmartPointer<EtchObject> event ) {
         if (event->getObjectType() == EtchString::TYPE()) {
diff --git a/examples/helloworld/cpp/src/main/src/ImplHelloWorldServer.cpp b/examples/helloworld/cpp/src/main/src/ImplHelloWorldServer.cpp
index e51fbf0..776b184 100644
--- a/examples/helloworld/cpp/src/main/src/ImplHelloWorldServer.cpp
+++ b/examples/helloworld/cpp/src/main/src/ImplHelloWorldServer.cpp
@@ -21,7 +21,7 @@
 
   // TODO insert methods here to provide implementations of HelloWorldServer
   // messages from the mClient.
-  ImplHelloWorldServer::say_helloAsyncResultPtr ImplHelloWorldServer::say_hello(HelloWorld::userPtr to_whom)
+  ImplHelloWorldServer::say_helloAsyncResultPtr ImplHelloWorldServer::say_hello(HelloWorld::EtchNativeArrayuserPtr to_whom)
   {
     say_helloAsyncResultPtr res = new EtchAsyncResult<EtchString>();
     res->setResult(new EtchString("Hi From C++ Server!"));