陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Quintiq file version 2.0
#parent: #root
Method GenerateNVT (structured_Object data_i, Boolean deleteData_i) as owning NamedValueTree
{
  Description:
  [*
    Transform the data into the format that is implemented in the Channel Library and put in an a NamedValueTree.
    (1) In some cases, we want to delete the input data, in others we wish to keep it
  *]
  TextBody:
  [*
    genericObject := null( Object );
    isDataManager := this.CommunicationChannelRoot().IsDataManager();
    
    // Data will be null if the message is for notification only
    dataSize := guard( data_i.Size(), 0 );
    
    // If there is no data then use a Message, otherwise use a Batch.
    // Using a Batch when there is not data results in an error when the QIntegrator is used.
    nvt := null( NamedValueTree );
    
    if( dataSize = 0 )
    {
      nvt := LibInt_MessageAccessor::CreateEmptyMessage();
    }
    else
    {
      nvt := LibInt_BatchAccessor::CreateEmptyBatch( dataSize );
    
      //Fill each of the Children with the values of an object.
      batchBody := LibInt_NvtAccessor::FirstChildNamed( nvt, nvt.Root(), 'Body' );
      idx := 0;
    
      traverse( batchBody.Children(), Elements, child )
      {
        dataElement := data_i.Element( idx );
        if( not isDataManager )
        {
          // Transform the data to the generic structure.
          genericObject := this.DataTransformToGeneric( dataElement );
        }
        else
        {
          // The data is already in the generic structure.
          genericObject := dataElement;
        }
    
        childBody := LibInt_NvtAccessor::FirstChildNamed( nvt, child, 'Body' );
    
        // Put the object in the NVT.
        NamedValueTreeIO::Export( genericObject, nvt, childBody, false );
    
        if( not isDataManager )
        {
          // The temporary created genericObject can be deleted again.
          genericObject.Delete();
        }
    
        idx++;
      }
    }
    
    return &nvt;
  *]
}