-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move BufferDataAccessFactory to separate class
- Loading branch information
Showing
2 changed files
with
81 additions
and
75 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/main/java/net/imglib2/img/basictypeaccess/nio/BufferDataAccessFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package net.imglib2.img.basictypeaccess.nio; | ||
|
||
import static net.imglib2.img.basictypeaccess.AccessFlags.DIRTY; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Set; | ||
|
||
import net.imglib2.img.basictypeaccess.AccessFlags; | ||
import net.imglib2.img.basictypeaccess.array.ArrayDataAccess; | ||
import net.imglib2.type.NativeType; | ||
import net.imglib2.type.NativeTypeFactory; | ||
import net.imglib2.type.PrimitiveType; | ||
|
||
|
||
/** | ||
* TODO javadoc | ||
*/ | ||
public class BufferDataAccessFactory | ||
{ | ||
public static < T extends NativeType< T >, A extends BufferAccess< A > > A get( | ||
final T type ) | ||
{ | ||
return get( type, AccessFlags.setOf() ); | ||
} | ||
|
||
public static < T extends NativeType< T >, A extends BufferAccess< A > > A get( | ||
final T type, | ||
final Set< AccessFlags > flags ) | ||
{ | ||
return get( type.getNativeTypeFactory().getPrimitiveType(), flags ); | ||
} | ||
|
||
public static < A extends BufferAccess< A > > A get( | ||
final NativeTypeFactory< ?, ? > typeFactory ) | ||
{ | ||
return get( typeFactory.getPrimitiveType(), AccessFlags.setOf() ); | ||
} | ||
|
||
public static < A extends BufferAccess< A > > A get( | ||
final NativeTypeFactory< ?, ? > typeFactory, | ||
final Set< AccessFlags > flags ) | ||
{ | ||
return get( typeFactory.getPrimitiveType(), flags ); | ||
} | ||
|
||
@SuppressWarnings( "unchecked" ) | ||
public static < A extends BufferAccess< A > > A get( | ||
final PrimitiveType primitiveType, | ||
final Set< AccessFlags > flags ) | ||
{ | ||
final boolean dirty = flags.contains( DIRTY ); | ||
if ( dirty ) | ||
// TODO: implement DirtyByteBufferAccess etc. | ||
throw new UnsupportedOperationException( "TODO: implement DirtyByteBufferAccess etc." ); | ||
final ByteBuffer buf = ByteBuffer.allocateDirect( 8 ); | ||
switch ( primitiveType ) | ||
{ | ||
case BOOLEAN: | ||
throw new UnsupportedOperationException( "TODO: so far, no Boolean BufferAccess exists." ); | ||
case BYTE: | ||
return ( A ) ByteBufferAccess.fromByteBuffer( buf, true ); | ||
case CHAR: | ||
return ( A ) CharBufferAccess.fromByteBuffer( buf, true ); | ||
case DOUBLE: | ||
return ( A ) DoubleBufferAccess.fromByteBuffer( buf, true ); | ||
case FLOAT: | ||
return ( A ) FloatBufferAccess.fromByteBuffer( buf, true ); | ||
case INT: | ||
return ( A ) IntBufferAccess.fromByteBuffer( buf, true ); | ||
case LONG: | ||
return ( A ) LongBufferAccess.fromByteBuffer( buf, true ); | ||
case SHORT: | ||
return ( A ) ShortBufferAccess.fromByteBuffer( buf, true ); | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters