2016-07-15 1 views
1

, 내가 가지고있는 다음과 같은 C++ 구조는 ...JNA : 어떻게 사용자 정의 비트 크기의 필드가있는 구조를 정의 할 수 있습니까? 예를 들어

struct dleaf_t 
{ 
    int     contents;   // OR of all brushes (not needed?) 
    short    cluster;   // cluster this leaf is in 
    short    area : 9;   // area this leaf is in 
    short    flags : 7;   // flags 
    short    mins[ 3 ];   // for frustum culling 
    short    maxs[ 3 ]; 
    unsigned short  firstleafface;  // index into leaffaces 
    unsigned short  numleaffaces; 
    unsigned short  firstleafbrush;  // index into leafbrushes 
    unsigned short  numleafbrushes; 
    short    leafWaterDataID; // -1 for not in water 

    //!!! NOTE: for maps of version 19 or lower uncomment this block 
    /* 
    CompressedLightCube ambientLighting; // Precaculated light info for entities. 
    short   padding;  // padding to 4-byte boundary 
    */ 
}; 

은 일반적으로 내가 JNA와 자바에서 쉽게 구조를 나타낼 수 있지만,이 구조는 내가 틀리지 않는 경우 (데이터 유형에 대한 사용자 지정 비트 양을 사용). 예컨대

area 오히려 평소처럼 16 비트보다, 9 비트 short이다. flags은 비트 ... 등등입니다.

맞춤 비트 크기의 데이터 유형으로 JNA 구조를 어떻게 정의 할 수 있습니까?

답변

1

두 비트 필드를 단일 int 필드에 병합 한 다음 결합 된 개별 필드의 값을 추출하는 멤버 메소드를 작성하십시오.

public int area_flags; 
public int getArea() { return area_flags & 0x1FF; } 
public int getFlags() { return (area_flags >> 9) & 0x3F; } 

컴파일러가 비트를 어떻게 포장하는지에 따라 약간의 차이가있을 수 있습니다.

1

이것이 JNA에서 가능한지 여부는 알 수 없습니다. 문서를보고 문제에 관한 정보를 찾을 수 있는지 확인하십시오.

관련 문제