Javolution 6.0.0 java
javolution.io.Struct.Member Class Reference
Inheritance diagram for javolution.io.Struct.Member:
[legend]
Collaboration diagram for javolution.io.Struct.Member:
[legend]

Public Member Functions

final Struct struct ()
 
final int offset ()
 
final int bitIndex ()
 
final int bitLength ()
 

Protected Member Functions

 Member (int bitLength, int wordSize)
 

Package Functions

final int get (int wordSize, int word)
 
final int set (int value, int wordSize, int word)
 
final long get (int wordSize, long word)
 
final long set (long value, int wordSize, long word)
 

Private Attributes

final int _offset
 
final int _bitIndex
 
final int _bitLength
 

Detailed Description

This inner class represents the base class for all Struct members. It allows applications to define additional member types. For example:[code] public class MyStruct extends Struct { BitSet bits = new BitSet(256); ... public BitSet extends Member { public BitSet(int nbrBits) { super(nbrBits, 0); // Direct bit access. } public boolean get(int i) { ... } public void set(int i, boolean value) { ...} } }[/code]

Definition at line 894 of file Struct.java.

Constructor & Destructor Documentation

◆ Member()

javolution.io.Struct.Member.Member ( int  bitLength,
int  wordSize 
)
protected

Base constructor for custom member types.

The word size can be zero, in which case the offset of the member does not change, only bitIndex is incremented.

Parameters
bitLengththe number of bits or 0 to force next member on next word boundary.
wordSizethe word size in bytes used when accessing this member data or 0 if the data is accessed at the bit level.

Definition at line 922 of file Struct.java.

922  {
924 
925  // Resets index if union.
926  if (_resetIndex) {
927  _index = 0;
928  }
929 
930  // Check if we can merge bitfields (always true if no word boundary).
931  if ((wordSize == 0)
932  || ((bitLength != 0) && (wordSize == _wordSize) && ((_bitsUsed + bitLength) <= (wordSize << 3)))) {
933 
936  _bitsUsed += bitLength;
937 
938  // Straddling word boundary only possible if (wordSize == 0)
939  while (_bitsUsed > (_wordSize << 3)) {
940  _index++;
941  _wordSize++;
942  _length = MathLib.max(_length, _index);
943  }
944  return; // Bit field merge done.
945  }
946 
947  // Check alignment.
948  if (!isPacked()) {
949 
950  // Updates struct's alignment constraint, based on largest word size.
951  if ((_alignment < wordSize)) {
952  _alignment = wordSize;
953  }
954 
955  // Adds padding if misaligned.
956  int misaligned = _index % wordSize;
957  if (misaligned != 0) {
958  _index += wordSize - misaligned;
959  }
960  }
961 
962  // Sets member indices.
963  _offset = _index;
964  _bitIndex = 0;
965 
966  // Update struct indices.
967  _index += MathLib.max(wordSize, (bitLength + 7) >> 3);
968  _wordSize = wordSize;
970  _length = MathLib.max(_length, _index);
971  // size and index may differ because of {@link Union}
972  }

References javolution.io.Struct._alignment, javolution.io.Struct.Member._bitIndex, javolution.io.Struct.Member._bitLength, javolution.io.Struct._bitsUsed, javolution.io.Struct._index, javolution.io.Struct._length, javolution.io.Struct.Member._offset, javolution.io.Struct._resetIndex, javolution.io.Struct._wordSize, javolution.io.Struct.Member.bitLength(), javolution.io.Struct.isPacked(), and javolution.lang.MathLib.max().

Here is the call graph for this function:

Member Function Documentation

◆ bitIndex()

final int javolution.io.Struct.Member.bitIndex ( )

Holds the bit offset of this member (if any). The actual position of the bits data depends upon the endianess and the word size.

Definition at line 998 of file Struct.java.

998  {
999  return _bitIndex;
1000  }

References javolution.io.Struct.Member._bitIndex.

Referenced by javolution.io.Struct.Member.get(), javolution.io.Struct.BitField.longValue(), javolution.io.Struct.Member.set(), and javolution.io.Struct.BitField.set().

Here is the caller graph for this function:

◆ bitLength()

◆ get() [1/2]

final int javolution.io.Struct.Member.get ( int  wordSize,
int  word 
)
package

Definition at line 1013 of file Struct.java.

1013  {
1014  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1015  - bitIndex() - bitLength()
1016  : bitIndex();
1017  word >>= shift;
1018  int mask = 0xFFFFFFFF >>> (32 - bitLength());
1019  return word & mask;
1020  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ get() [2/2]

final long javolution.io.Struct.Member.get ( int  wordSize,
long  word 
)
package

Definition at line 1034 of file Struct.java.

1034  {
1035  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1036  - bitIndex() - bitLength()
1037  : bitIndex();
1038  word >>= shift;
1039  long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
1040  return word & mask;
1041  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ offset()

final int javolution.io.Struct.Member.offset ( )

Returns the byte offset of this member in its struct. Equivalent to C/C++ offsetof(struct(), this)

Returns
the offset of this member in the Struct.

Definition at line 989 of file Struct.java.

989  {
990  return _offset;
991  }

References javolution.io.Struct.Member._offset.

Referenced by javolution.io.Struct.UTF8String.get(), javolution.io.Struct.Bool.get(), javolution.io.Struct.Signed8.get(), javolution.io.Struct.Unsigned8.get(), javolution.io.Struct.Signed16.get(), javolution.io.Struct.Unsigned16.get(), javolution.io.Struct.Signed32.get(), javolution.io.Struct.Unsigned32.get(), javolution.io.Struct.Signed64.get(), javolution.io.Struct.Float32.get(), javolution.io.Struct.Float64.get(), javolution.io.Struct.Enum8< T extends Enum< T >.get(), javolution.io.Struct.Enum16< T extends Enum< T >.get(), javolution.io.Struct.Enum32< T extends Enum< T >.get(), javolution.io.Struct.Enum64< T extends Enum< T >.get(), javolution.io.Struct.Reference32< S extends Struct >.isUpToDate(), javolution.io.Struct.Reference64< S extends Struct >.isUpToDate(), javolution.io.Struct.BitField.longValue(), javolution.io.Struct.UTF8String.set(), javolution.io.Struct.Bool.set(), javolution.io.Struct.Signed8.set(), javolution.io.Struct.Unsigned8.set(), javolution.io.Struct.Signed16.set(), javolution.io.Struct.Unsigned16.set(), javolution.io.Struct.Signed32.set(), javolution.io.Struct.Unsigned32.set(), javolution.io.Struct.Signed64.set(), javolution.io.Struct.BitField.set(), javolution.io.Struct.Float32.set(), javolution.io.Struct.Float64.set(), javolution.io.Struct.Reference32< S extends Struct >.set(), javolution.io.Struct.Reference64< S extends Struct >.set(), javolution.io.Struct.Enum8< T extends Enum< T >.set(), javolution.io.Struct.Enum16< T extends Enum< T >.set(), javolution.io.Struct.Enum32< T extends Enum< T >.set(), javolution.io.Struct.Enum64< T extends Enum< T >.set(), javolution.io.Struct.Reference32< S extends Struct >.value(), and javolution.io.Struct.Reference64< S extends Struct >.value().

Here is the caller graph for this function:

◆ set() [1/2]

final int javolution.io.Struct.Member.set ( int  value,
int  wordSize,
int  word 
)
package

Definition at line 1023 of file Struct.java.

1023  {
1024  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1025  - bitIndex() - bitLength()
1026  : bitIndex();
1027  int mask = 0xFFFFFFFF >>> (32 - bitLength());
1028  mask <<= shift;
1029  value <<= shift;
1030  return (word & ~mask) | (value & mask);
1031  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ set() [2/2]

final long javolution.io.Struct.Member.set ( long  value,
int  wordSize,
long  word 
)
package

Definition at line 1044 of file Struct.java.

1044  {
1045  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1046  - bitIndex() - bitLength()
1047  : bitIndex();
1048  long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
1049  mask <<= shift;
1050  value <<= shift;
1051  return (word & ~mask) | (value & mask);
1052  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ struct()

final Struct javolution.io.Struct.Member.struct ( )

Returns the outer struct container.

Returns
the outer struct.

Definition at line 979 of file Struct.java.

979  {
980  return Struct.this;
981  }

Member Data Documentation

◆ _bitIndex

final int javolution.io.Struct.Member._bitIndex
private

Holds the relative bit offset of this member to its struct offset.

Definition at line 903 of file Struct.java.

Referenced by javolution.io.Struct.Member.bitIndex(), and javolution.io.Struct.Member.Member().

◆ _bitLength

final int javolution.io.Struct.Member._bitLength
private

Holds the bit length of this member.

Definition at line 907 of file Struct.java.

Referenced by javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.Member.Member().

◆ _offset

final int javolution.io.Struct.Member._offset
private

Holds the relative offset (in bytes) of this member within its struct.

Definition at line 899 of file Struct.java.

Referenced by javolution.io.Struct.Member.Member(), and javolution.io.Struct.Member.offset().


The documentation for this class was generated from the following file:
javolution.io.Struct._length
int _length
Definition: Struct.java:185
javolution.io.Struct.Member._offset
final int _offset
Definition: Struct.java:899
javolution.io.Struct._wordSize
int _wordSize
Definition: Struct.java:195
javolution.io.Struct._index
int _index
Definition: Struct.java:190
javolution.io.Struct.Member._bitLength
final int _bitLength
Definition: Struct.java:907
javolution.io.Struct._alignment
int _alignment
Definition: Struct.java:181
javolution.io.Struct.Struct
Struct()
Definition: Struct.java:214
javolution.io.Struct._resetIndex
boolean _resetIndex
Definition: Struct.java:205
javolution.io.Struct.isPacked
boolean isPacked()
Definition: Struct.java:501
javolution.io.Struct._bitsUsed
int _bitsUsed
Definition: Struct.java:200
javolution.io.Struct.Member._bitIndex
final int _bitIndex
Definition: Struct.java:903
javolution.io.Struct.byteOrder
ByteOrder byteOrder()
Definition: Struct.java:480
javolution.io.Struct.Member.bitIndex
final int bitIndex()
Definition: Struct.java:998
javolution.io.Struct.Member.bitLength
final int bitLength()
Definition: Struct.java:1008