1 // ****************************************************************************** 2 // 3 // Title: Force Field X. 4 // Description: Force Field X - Software for Molecular Biophysics. 5 // Copyright: Copyright (c) Michael J. Schnieders 2001-2025. 6 // 7 // This file is part of Force Field X. 8 // 9 // Force Field X is free software; you can redistribute it and/or modify it 10 // under the terms of the GNU General Public License version 3 as published by 11 // the Free Software Foundation. 12 // 13 // Force Field X is distributed in the hope that it will be useful, but WITHOUT 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 // details. 17 // 18 // You should have received a copy of the GNU General Public License along with 19 // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple 20 // Place, Suite 330, Boston, MA 02111-1307 USA 21 // 22 // Linking this library statically or dynamically with other modules is making a 23 // combined work based on this library. Thus, the terms and conditions of the 24 // GNU General Public License cover the whole combination. 25 // 26 // As a special exception, the copyright holders of this library give you 27 // permission to link this library with independent modules to produce an 28 // executable, regardless of the license terms of these independent modules, and 29 // to copy and distribute the resulting executable under terms of your choice, 30 // provided that you also meet, for each linked independent module, the terms 31 // and conditions of the license of that module. An independent module is a 32 // module which is not derived from or based on this library. If you modify this 33 // library, you may extend this exception to your version of the library, but 34 // you are not obligated to do so. If you do not wish to do so, delete this 35 // exception statement from your version. 36 // 37 // ****************************************************************************** 38 package ffx.openmm; 39 40 import com.sun.jna.Pointer; 41 import com.sun.jna.ptr.PointerByReference; 42 43 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_StringArray_append; 44 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_StringArray_create; 45 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_StringArray_destroy; 46 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_StringArray_get; 47 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_StringArray_getSize; 48 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_StringArray_resize; 49 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_StringArray_set; 50 51 /** 52 * String Array. 53 */ 54 public class StringArray { 55 56 /** 57 * String Array Platform pointer. 58 */ 59 private PointerByReference pointer; 60 61 /** 62 * OpenMM String Array constructor. 63 * 64 * @param size The size of the String Array. 65 */ 66 public StringArray(int size) { 67 pointer = OpenMM_StringArray_create(size); 68 } 69 70 /** 71 * OpenMM String Array constructor. 72 * 73 * @param pointer The String Array pointer. 74 */ 75 public StringArray(PointerByReference pointer) { 76 this.pointer = pointer; 77 } 78 79 /** 80 * Append a String to the String Array. 81 * 82 * @param string The String to append. 83 */ 84 public void append(String string) { 85 OpenMM_StringArray_append(pointer, string); 86 } 87 88 /** 89 * Destroy the String Array. 90 */ 91 public void destroy() { 92 if (pointer != null) { 93 OpenMM_StringArray_destroy(pointer); 94 pointer = null; 95 } 96 } 97 98 /** 99 * Return the String at index i. 100 * 101 * @param i The index of the String to return. 102 * @return String The requested String. 103 */ 104 public String get(int i) { 105 int size = getSize(); 106 if (i < 0 || i >= size) { 107 return null; 108 } 109 Pointer string = OpenMM_StringArray_get(pointer, i); 110 if (string == null) { 111 return null; 112 } 113 return string.getString(0); 114 } 115 116 /** 117 * Get the pointer to the String Array. 118 * 119 * @return The pointer to the String Array. 120 */ 121 public PointerByReference getPointer() { 122 return pointer; 123 } 124 125 /** 126 * Get the number of strings in the String Array. 127 * 128 * @return The number of strings in the String Array. 129 */ 130 public int getSize() { 131 return OpenMM_StringArray_getSize(pointer); 132 } 133 134 /** 135 * Resize the String Array. 136 * 137 * @param size The new size of the String Array. 138 */ 139 public void resize(int size) { 140 OpenMM_StringArray_resize(pointer, size); 141 } 142 143 /** 144 * Set the String at index i. 145 * 146 * @param i The index of the String to set. 147 * @param string The String to set. 148 */ 149 public void set(int i, String string) { 150 OpenMM_StringArray_set(pointer, i, string); 151 } 152 153 }