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#DOUBLE_INT} datatype.
25 */
26 public final class DoubleInt extends Struct
27 {
28 private final int iOff, iSize;
29
30 /**
31 * The struct object will be created only in MPI class.
32 * @param intOff int offset
33 * @param intSize int size
34 * @see MPI#doubleInt
35 */
36 protected DoubleInt(int intOff, int intSize)
37 {
38 int dOff = addDouble();
39 assert dOff == 0;
40
41 iSize = intSize;
42 setOffset(intOff);
43
44 switch(iSize)
45 {
46 case 4: iOff = addInt(); break;
47 case 8: iOff = addLong(); break;
48 default: throw new AssertionError("Unsupported int size: "+ iSize);
49 }
50
51 assert(intOff == iOff);
52 }
53
54 /**
55 * Creates a Data object.
56 * @return new Data object.
57 */
58 @Override protected DoubleInt.Data newData()
59 {
60 return new DoubleInt.Data();
61 }
62
63 /**
64 * Class for reading/writing data in a struct stored in a byte buffer.
65 */
66 public final class Data extends Struct.Data
67 {
68 /**
69 * Gets the double value.
70 * @return double value
71 */
72 public double getValue()
73 {
74 return getDouble(0);
75 }
76
77 /**
78 * Gets the int value.
79 * @return int value
80 */
81 public int getIndex()
82 {
83 switch(iSize)
84 {
85 case 4: return getInt(iOff);
86 case 8: return (int)getLong(iOff);
87 default: throw new AssertionError();
88 }
89 }
90
91 /**
92 * Puts the double value.
93 * @param v double value
94 */
95 public void putValue(double v)
96 {
97 putDouble(0, v);
98 }
99
100 /**
101 * Puts the int value.
102 * @param v int value
103 */
104 public void putIndex(int v)
105 {
106 switch(iSize)
107 {
108 case 4: putInt(iOff, v); break;
109 case 8: putLong(iOff, v); break;
110 default: throw new AssertionError();
111 }
112 }
113 } // Data
114
115 } // DoubleInt