Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Make copies of datas



It is possible to make copies of datas. Two methods allow to make copies from one data to another, regardless of their service:
  • The Data.copy(Data, boolean) method allow to make a copy, specifying if the copy must take care of the corrrsponding type of the datas
  • The Data.copy(Data, boolean) method is a shortcut to the copy(Data fromData, true) version of the previous method

Copying a data without checking the type

In that case, the type checking between the types of the datas is minimal:
  • For a simple type data to which to copy is performed, the method will check that the from data is also of a simple type and will check the compatibility of these types
  • For an array type data to which to copy is performed, the method will only check that the from data is also an array, and the size of the array
  • For an structure type data to which to copy is performed, the method will only check that the from data is also a structure

You must be warned that the type checking in this case is minimal.

Example

      Data data1 = service1.getData("myData");
      Data data2 = service2.getData("myOtherData");
      data2.copy(data1, false);

Copying a data with checking the type

In that case, the type checking between the types of the datas is complete:
  • For a simple type data to which to copy is performed, the method will check that the from data is also of a simple type and will check the compatibility of these types
  • For an structure type data to which to copy is performed, the method will only copy the fields which exist in the two structures, and will also check their type compatibility
  • For an structure type data to which to copy is performed, the method check every element in the array

The checking is recursive, so you are sure that if you copy a complex structure, the method will check as much content it can.

Example

      Data data1 = service1.getData("myData");
      Data data2 = service2.getData("myOtherData");
      data2.copy(data1, true);
      // or 
      data2.copy(data1); // this is equivalent    

Example

Suppose the following types definition:
      <simpleType name="bool" baseType="boolean" />
      <simpleType name="int" baseType="int" />
      <enumType name="intEnum" >
         <enumValue name="ONE" />
         <enumValue name="TWO" />
         <enumValue name="THREE" />
      </enumType>
      <structType name="struct1">
         <field name="enum" type="intEnum" />
         <field name="int" type="int" />
      </structType>
      <structType name="struct2">
         <extends name="struct1" />
         <field name="int2" type="int" />
         <field name="bool" type="bool" />
      </structType>
And the following services definition:
      <services>
         <publish name="service1">
            <data name="data1" type="struct1" />
         </publish>
         <publish name="service2">
            <data name="data2" type="struct2" />
         </publish>   
      </services>
Suppose that we have the following value for data2:
  • {THREE, 5, 10, true}
The after calling data1.copy(data2), we will have the following value for data1:
  • {THREE, 5}

See also


Categories: concepts

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence