root/ompi/mpi/java/java/LongInt.java

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

DEFINITIONS

This source file includes following definitions.
  1. newData
  2. getValue
  3. getIndex
  4. putValue
  5. putIndex

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

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