/*
 * Copyright 2007 - 2018 ETH Zuerich, CISD and SIS.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ch.systemsx.cisd.hdf5;

/**
 * A class with basic information about the types of compound members in an HDF5 file.
 * 
 * @author Bernd Rinn
 */
final class CompoundTypeInformation
{
    final String name;

    final long compoundDataTypeId;

    final long nativeCompoundDataTypeId;

    private final HDF5CompoundMemberInformation[] members;

    final long[] dataTypeIds;
    
    final HDF5EnumerationType[] enumTypes;

    final int recordSizeOnDisk;
    
    final int recordSizeInMemory;
    
    private int numberOfVLMembers;

    CompoundTypeInformation(String name, long compoundDataTypeId, long nativeCompoundDataTypeId,
            int numberOfElements, int recordSizeOnDisk, int recordSizeInMemory)
    {
        this.name = name;
        this.compoundDataTypeId = compoundDataTypeId;
        this.nativeCompoundDataTypeId = nativeCompoundDataTypeId;
        this.members = new HDF5CompoundMemberInformation[numberOfElements];
        this.dataTypeIds = new long[numberOfElements];
        this.enumTypes = new HDF5EnumerationType[numberOfElements];
        this.recordSizeOnDisk = recordSizeOnDisk;
        this.recordSizeInMemory = recordSizeInMemory;
    }
    
    private void calcNumberOfVLMembers()
    {
        int countOfVLMembers = 0;
        for (HDF5CompoundMemberInformation m : members)
        {
            if (m != null && m.getType().isVariableLengthString())
            {
                ++countOfVLMembers;
            }
        }
        this.numberOfVLMembers = countOfVLMembers;
    }
    
    int getNumberOfMembers()
    {
        return members.length;
    }

    HDF5CompoundMemberInformation getMember(int i)
    {
        return members[i];
    }
    
    HDF5CompoundMemberInformation[] getCopyOfMembers()
    {
        return members.clone();
    }
    
    void setMember(int i, HDF5CompoundMemberInformation member)
    {
        members[i] = member;
        calcNumberOfVLMembers();
    }
    
    int getNumberOfVLMembers()
    {
        return numberOfVLMembers;
    }

}
