root/ompi/mpi/java/java/Int2.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. addIntField
  2. newData
  3. getValue
  4. getIndex
  5. putValue
  6. putIndex
  7. get
  8. put

   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#INT2} datatype.
  25  */
  26 public final class Int2 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#int2
  35          */
  36         protected Int2(int intOff, int intSize)
  37         {
  38                 iSize = intSize;
  39                 int off = addIntField();
  40                 assert off == 0;
  41                 setOffset(intOff);
  42                 iOff = addIntField();
  43                 assert intOff == iOff;
  44         }
  45 
  46         private int addIntField()
  47         {
  48                 switch(iSize)
  49                 {
  50                 case 4: return addInt();
  51                 case 8: return addLong();
  52                 default: throw new AssertionError("Unsupported int size: "+ iSize);
  53                 }
  54         }
  55 
  56         /**
  57          * Creates a Data object.
  58          * @return new Data object.
  59          */
  60         @Override protected Int2.Data newData()
  61         {
  62                 return new Int2.Data();
  63         }
  64 
  65         /**
  66          * Class for reading/writing data in a struct stored in a byte buffer.
  67          */
  68         public final class Data extends Struct.Data
  69         {
  70                 /**
  71                  * Gets the first int.
  72                  * @return first int
  73                  */
  74                 public int getValue()
  75                 {
  76                         return get(0);
  77                 }
  78 
  79                 /**
  80                  * Gets the second int.
  81                  * @return second int
  82                  */
  83                 public int getIndex()
  84                 {
  85                         return get(iOff);
  86                 }
  87 
  88                 /**
  89                  * Puts the first int.
  90                  * @param v first value
  91                  */
  92                 public void putValue(int v)
  93                 {
  94                         put(0, v);
  95                 }
  96 
  97                 /**
  98                  * Puts the second int.
  99                  * @param v second int
 100                  */
 101                 public void putIndex(int v)
 102                 {
 103                         put(iOff, v);
 104                 }
 105 
 106                 private int get(int off)
 107                 {
 108                         switch(iSize)
 109                         {
 110                         case 4: return getInt(off);
 111                         case 8: return (int)getLong(off);
 112                         default: throw new AssertionError();
 113                         }
 114                 }
 115 
 116                 private void put(int off, int v)
 117                 {
 118                         switch(iSize)
 119                         {
 120                         case 4: putInt(off, v);  break;
 121                         case 8: putLong(off, v); break;
 122                         default: throw new AssertionError();
 123                         }
 124                 }
 125         } // Data
 126 
 127 } // Int2

/* [<][>][^][v][top][bottom][index][help] */