< prev index next >

src/java.base/share/classes/jdk/internal/nicl/types/References.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.nicl.types;
  27 
  28 import jdk.internal.nicl.LibrariesHelper;
  29 import jdk.internal.nicl.Util;
  30 
  31 import java.nicl.Libraries;
  32 import java.nicl.metadata.NativeType;
  33 import java.nicl.layout.Address;
  34 import java.nicl.layout.Sequence;
  35 import java.nicl.layout.Value;
  36 import java.nicl.layout.Value.Kind;
  37 import java.nicl.types.*;
  38 
  39 import java.lang.invoke.MethodHandle;
  40 import java.lang.invoke.MethodHandles;
  41 import java.lang.invoke.MethodType;
  42 
  43 /**
  44  * Helper class for references. Defines several reference subclasses, specialized in well-known Java carrier
  45  * types (both primitive and reference types). It also provides factories for common reference types.
  46  */
  47 public final class References {
  48 
  49     private References() {}
  50 
  51     /**
  52      * Reference for primitive carriers. It exposes specialized accessors for getting/setting


 636     public static OfDouble ofDouble = new OfDouble();
 637 
 638     public static <X> OfPointer<X> ofPointer(LayoutType<X> pointeeType) {
 639         return new OfPointer<>(pointeeType);
 640     }
 641 
 642     /**
 643      * Create an array reference factory from a given carrier class.
 644      * @param elementType the array carrier.
 645      * @param <T> the array type.
 646      * @return a reference factory for array references.
 647      * @throws IllegalArgumentException if the carrier is not an array type.
 648      */
 649     public static <T> OfArray<T> ofArray(LayoutType<T> elementType) { return new OfArray<>(elementType); }
 650 
 651     /**
 652      * Create a struct reference factory from a given carrier class.
 653      * @param clazz the native struct carrier.
 654      * @param <T> the native struct type.
 655      * @return a reference factory for native struct references.
 656      * @throws IllegalArgumentException if the carrier is not annotated with the {@link NativeType} annotation.
 657      */
 658     public static <T extends Struct<T>> OfStruct<T> ofStruct(Class<T> clazz) throws IllegalArgumentException {
 659         if (!clazz.isAnnotationPresent(NativeType.class)) {
 660             throw new IllegalArgumentException("Not a native type carrier!");
 661         }
 662         return new OfStruct<>(clazz);
 663     }
 664 }


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.nicl.types;
  27 
  28 import jdk.internal.nicl.LibrariesHelper;
  29 import jdk.internal.nicl.Util;
  30 
  31 import java.nicl.Libraries;
  32 import java.nicl.metadata.NativeStruct;
  33 import java.nicl.layout.Address;
  34 import java.nicl.layout.Sequence;
  35 import java.nicl.layout.Value;
  36 import java.nicl.layout.Value.Kind;
  37 import java.nicl.types.*;
  38 
  39 import java.lang.invoke.MethodHandle;
  40 import java.lang.invoke.MethodHandles;
  41 import java.lang.invoke.MethodType;
  42 
  43 /**
  44  * Helper class for references. Defines several reference subclasses, specialized in well-known Java carrier
  45  * types (both primitive and reference types). It also provides factories for common reference types.
  46  */
  47 public final class References {
  48 
  49     private References() {}
  50 
  51     /**
  52      * Reference for primitive carriers. It exposes specialized accessors for getting/setting


 636     public static OfDouble ofDouble = new OfDouble();
 637 
 638     public static <X> OfPointer<X> ofPointer(LayoutType<X> pointeeType) {
 639         return new OfPointer<>(pointeeType);
 640     }
 641 
 642     /**
 643      * Create an array reference factory from a given carrier class.
 644      * @param elementType the array carrier.
 645      * @param <T> the array type.
 646      * @return a reference factory for array references.
 647      * @throws IllegalArgumentException if the carrier is not an array type.
 648      */
 649     public static <T> OfArray<T> ofArray(LayoutType<T> elementType) { return new OfArray<>(elementType); }
 650 
 651     /**
 652      * Create a struct reference factory from a given carrier class.
 653      * @param clazz the native struct carrier.
 654      * @param <T> the native struct type.
 655      * @return a reference factory for native struct references.
 656      * @throws IllegalArgumentException if the carrier is not annotated with the {@link NativeStruct} annotation.
 657      */
 658     public static <T extends Struct<T>> OfStruct<T> ofStruct(Class<T> clazz) throws IllegalArgumentException {
 659         if (!clazz.isAnnotationPresent(NativeStruct.class)) {
 660             throw new IllegalArgumentException("Not a native struct!");
 661         }
 662         return new OfStruct<>(clazz);
 663     }
 664 }
< prev index next >