1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2015 Los Alamos National Security, LLC. All rights
13 * reserved.
14 * $COPYRIGHT$
15 *
16 * Additional copyrights may follow
17 *
18 * $HEADER$
19 */
20
21 package mpi;
22
23 /**
24 * Struct class for {@link MPI#SHORT_INT} datatype.
25 */
26 public final class ShortInt extends Struct
27 {
28 private final int sSize, iOff, iSize;
29
30 /**
31 * The struct object will be created only in MPI class.
32 * @param shortSize short size
33 * @param intOff int offset
34 * @param intSize int size
35 * @see MPI#shortInt
36 */
37 protected ShortInt(int shortSize, int intOff, int intSize)
38 {
39 sSize = shortSize;
40 iSize = intSize;
41 int sOff;
42
43 switch(sSize)
44 {
45 case 2: sOff = addShort(); break;
46 case 4: sOff = addInt(); break;
47 case 8: sOff = addLong(); break;
48 default: throw new AssertionError("Unsupported short size: "+ sSize);
49 }
50
51 assert sOff == 0;
52 setOffset(intOff);
53
54 switch(iSize)
55 {
56 case 4: iOff = addInt(); break;
57 case 8: iOff = addLong(); break;
58 default: throw new AssertionError("Unsupported int size: "+ iSize);
59 }
60
61 assert(intOff == iOff);
62 }
63
64 /**
65 * Creates a Data object.
66 * @return new Data object.
67 */
68 @Override protected Data newData()
69 {
70 return new Data();
71 }
72
73 /**
74 * Class for reading/writing data in a struct stored in a byte buffer.
75 */
76 public final class Data extends Struct.Data
77 {
78 /**
79 * Gets the short value.
80 * @return short value
81 */
82 public short getValue()
83 {
84 switch(sSize)
85 {
86 case 2: return getShort(0);
87 case 4: return (short)getInt(0);
88 case 8: return (short)getLong(0);
89 default: throw new AssertionError();
90 }
91 }
92
93 /**
94 * Gets the int value.
95 * @return int value
96 */
97 public int getIndex()
98 {
99 switch(iSize)
100 {
101 case 4: return getInt(iOff);
102 case 8: return (int)getLong(iOff);
103 default: throw new AssertionError();
104 }
105 }
106
107 /**
108 * Puts the short value.
109 * @param v short value
110 */
111 public void putValue(short v)
112 {
113 switch(sSize)
114 {
115 case 2: putShort(0, v); break;
116 case 4: putInt(0, v); break;
117 case 8: putLong(0, v); break;
118 default: throw new AssertionError();
119 }
120 }
121
122 /**
123 * Puts the int value.
124 * @param v int value
125 */
126 public void putIndex(int v)
127 {
128 switch(iSize)
129 {
130 case 4: putInt(iOff, v); break;
131 case 8: putLong(iOff, v); break;
132 default: throw new AssertionError();
133 }
134 }
135 } // Data
136
137 } // ShortInt