9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
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 java.lang.foreign;
27
28 import jdk.internal.foreign.layout.SequenceLayoutImpl;
29 import jdk.internal.javac.PreviewFeature;
30
31 /**
32 * A compound layout that denotes a homogeneous repetition of a given <em>element layout</em>.
33 * The repetition count is said to be the sequence layout's <em>element count</em>. A sequence layout can be thought of as a
34 * struct layout where the sequence layout's element layout is repeated a number of times that is equal to the sequence
35 * layout's element count. In other words this layout:
36 *
37 * {@snippet lang=java :
38 * MemoryLayout.sequenceLayout(3, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN));
39 * }
40 *
41 * is equivalent to the following layout:
42 *
43 * {@snippet lang=java :
44 * MemoryLayout.structLayout(
45 * ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN),
46 * ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN),
47 * ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN));
48 * }
49 *
50 * @implSpec
51 * This class is immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
52 *
53 * @since 19
54 */
55 @PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
56 public sealed interface SequenceLayout extends MemoryLayout permits SequenceLayoutImpl {
57
58
59 /**
60 * {@return the element layout of this sequence layout}
61 */
62 MemoryLayout elementLayout();
63
64 /**
65 * {@return the element count of this sequence layout}
66 */
67 long elementCount();
68
69 /**
70 * {@return a sequence layout with the same characteristics of this layout, but with the given element count}
71 * @param elementCount the new element count.
72 * @throws IllegalArgumentException if {@code elementCount} is negative.
73 * @throws IllegalArgumentException if {@code elementLayout.bitSize() * elementCount} overflows.
74 */
75 SequenceLayout withElementCount(long elementCount);
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
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 java.lang.foreign;
27
28 import jdk.internal.foreign.layout.SequenceLayoutImpl;
29
30 /**
31 * A compound layout that denotes a homogeneous repetition of a given <em>element layout</em>.
32 * The repetition count is said to be the sequence layout's <em>element count</em>. A sequence layout can be thought of as a
33 * struct layout where the sequence layout's element layout is repeated a number of times that is equal to the sequence
34 * layout's element count. In other words this layout:
35 *
36 * {@snippet lang=java :
37 * MemoryLayout.sequenceLayout(3, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN));
38 * }
39 *
40 * is equivalent to the following layout:
41 *
42 * {@snippet lang=java :
43 * MemoryLayout.structLayout(
44 * ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN),
45 * ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN),
46 * ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN));
47 * }
48 *
49 * @implSpec
50 * This class is immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
51 *
52 * @since 22
53 */
54 public sealed interface SequenceLayout extends MemoryLayout permits SequenceLayoutImpl {
55
56
57 /**
58 * {@return the element layout of this sequence layout}
59 */
60 MemoryLayout elementLayout();
61
62 /**
63 * {@return the element count of this sequence layout}
64 */
65 long elementCount();
66
67 /**
68 * {@return a sequence layout with the same characteristics of this layout, but with the given element count}
69 * @param elementCount the new element count.
70 * @throws IllegalArgumentException if {@code elementCount} is negative.
71 * @throws IllegalArgumentException if {@code elementLayout.bitSize() * elementCount} overflows.
72 */
73 SequenceLayout withElementCount(long elementCount);
|