1/*
2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
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#warn This file is preprocessed before being compiled
27
28class XXX {
29
30#begin
31
32#if[rw]
33
34    private $type$ get$Type$(long a) {
35        $memtype$ x = unsafe.get$Memtype$Unaligned(null, a, bigEndian);
36        return $fromBits$(x);
37    }
38
39    public $type$ get$Type$() {
40        return get$Type$(ix(nextGetIndex($BYTES_PER_VALUE$)));
41    }
42
43    public $type$ get$Type$(int i) {
44        return get$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)));
45    }
46
47#end[rw]
48
49    private ByteBuffer put$Type$(long a, $type$ x) {
50#if[rw]
51        $memtype$ y = $toBits$(x);
52        unsafe.put$Memtype$Unaligned(null, a, y, bigEndian);
53        return this;
54#else[rw]
55        throw new ReadOnlyBufferException();
56#end[rw]
57    }
58
59    public ByteBuffer put$Type$($type$ x) {
60#if[rw]
61        put$Type$(ix(nextPutIndex($BYTES_PER_VALUE$)), x);
62        return this;
63#else[rw]
64        throw new ReadOnlyBufferException();
65#end[rw]
66    }
67
68    public ByteBuffer put$Type$(int i, $type$ x) {
69#if[rw]
70        put$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)), x);
71        return this;
72#else[rw]
73        throw new ReadOnlyBufferException();
74#end[rw]
75    }
76
77    public $Type$Buffer as$Type$Buffer() {
78        int off = this.position();
79        int lim = this.limit();
80        assert (off <= lim);
81        int rem = (off <= lim ? lim - off : 0);
82
83        int size = rem >> $LG_BYTES_PER_VALUE$;
84        if (!unaligned && ((address + off) % $BYTES_PER_VALUE$ != 0)) {
85            return (bigEndian
86                    ? ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$B(this,
87                                                                       -1,
88                                                                       0,
89                                                                       size,
90                                                                       size,
91                                                                       address + off))
92                    : ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$L(this,
93                                                                       -1,
94                                                                       0,
95                                                                       size,
96                                                                       size,
97                                                                       address + off)));
98        } else {
99            return (nativeByteOrder
100                    ? ($Type$Buffer)(new Direct$Type$Buffer$RW$U(this,
101                                                                 -1,
102                                                                 0,
103                                                                 size,
104                                                                 size,
105                                                                 off))
106                    : ($Type$Buffer)(new Direct$Type$Buffer$RW$S(this,
107                                                                 -1,
108                                                                 0,
109                                                                 size,
110                                                                 size,
111                                                                 off)));
112        }
113    }
114
115#end
116
117}
118