001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (http://www.swig.org).
003 * Version 4.0.2
004 *
005 * Do not make changes to this file unless you know what you are doing--modify
006 * the SWIG interface file instead.
007 * ----------------------------------------------------------------------------- */
008
009package com.avpkit.ferry;
010
011/**
012 * Internal only.  Atomic Integer represents Integers than can be updated<br>
013 * atomically from native code.<br>
014 * <p><br>
015 * This object is NOT meant to be called from Java (in fact, that'd be stupid<br>
016 * since you'd just be calling from native code back into Java).  It's<br>
017 * here so that native code inside a JVM can have access to portable<br>
018 * thread-safe objects.<br>
019 * </p>  <br>
020 * <p><br>
021 * And that said, this method is really only Atomic if running inside a<br>
022 * Java JVM (or other virtual machine that can provide the functionality).<br>
023 * If running in a standalone C++ program there<br>
024 * is no current guarantee of Atomicity.<br>
025 * </p><p><br>
026 * The object just forwards to the Java object:<br>
027 * {java.util.concurrent.atomic.AtomicInteger}<br>
028 * </p>
029 */
030public class AtomicInteger {
031  // JNIHelper.swg: Start generated code
032  // >>>>>>>>>>>>>>>>>>>>>>>>>>>
033
034  private volatile long swigCPtr;
035  /**
036   * Internal Only.
037   */
038  protected boolean swigCMemOwn;
039  @SuppressWarnings("unused")
040  private JNINativeFinalizer mUnusedVariableToAllowImports;
041  
042  /**
043   * Internal Only.  
044   * 
045   * DO NOT USE: Do not allocate this method using new.  Not part of public API.
046   * <p>
047   * Unfortunately this constructor is public because the internal
048   * implementation needs it to be, but do not pass in values to this method
049   * as you may end up crashing the virtual machine.
050   * </p>
051   *
052   * @param cPtr A C pointer to direct memory; did we mention don't call this.
053   * @param cMemoryOwn I'm not even going to tell you.  Stop it.  Go away.
054   *
055   */ 
056  protected AtomicInteger(long cPtr, boolean cMemoryOwn) {
057    swigCPtr = cPtr;
058    swigCMemOwn = cMemoryOwn;
059  }
060
061  /**
062   * Internal Only.  Not part of public API.
063   *
064   * Get the raw value of the native object that obj is proxying for.
065   *   
066   * @param obj The java proxy object for a native object.
067   * @return The raw pointer obj is proxying for.
068   */
069  public static long getCPtr(AtomicInteger obj) {
070    if (obj == null) return 0;
071    return obj.getMyCPtr();
072  }
073  
074  /**
075   * Internal Only.  Not part of public API.
076   *
077   * Get the raw value of the native object that we're proxying for.
078   *   
079   * @return The raw pointer we're proxying for.
080   */  
081  public long getMyCPtr() {
082    if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted");
083    return swigCPtr;
084  }
085
086  /**
087   * Compares two values, returning true if the underlying objects in native code are the same object.
088   *
089   * That means you can have two different Java objects, but when you do a comparison, you'll find out
090   * they are the EXACT same object.
091   *
092   * @return True if the underlying native object is the same.  False otherwise.
093   */
094  public boolean equals(Object obj) {
095    boolean equal = false;
096    if (obj instanceof AtomicInteger)
097      equal = (((AtomicInteger)obj).swigCPtr == this.swigCPtr);
098    return equal;
099  }
100  
101  /**
102   * Get a hashable value for this object.
103   *
104   * @return the hashable value.
105   */
106  public int hashCode() {
107     return (int)swigCPtr;
108  }
109  
110  /**
111   * Internal Only.  Finalize this object.  Note this should only exists on non RefCounted objects.
112   */
113  protected void finalize()
114  {
115    delete();
116  }
117
118  // <<<<<<<<<<<<<<<<<<<<<<<<<<<
119  // JNIHelper.swg: End generated code
120  /**
121   * Releases any underlying native memory and marks this object
122   * as invalid.
123   * <p>
124   * Normally Ferry manages when to release native memory.
125   * </p>
126   * <p>
127   * In the unlikely event you want to control EXACTLY when a native 
128   * object is released, each AVPKit object has a {@link #delete()}
129   * method that you can use. Once you call {@link #delete()},
130   * you must ENSURE your object is never referenced again from
131   * that Java object -- Ferry tries to help you avoid crashes if you
132   * accidentally use an object after deletion but on this but we
133   * cannot offer 100% protection (specifically if another thread
134   *  is accessing that object EXACTLY when you {@link #delete()} it). 
135   * </p>
136   */
137  
138
139  public synchronized void delete() {
140    if (swigCPtr != 0) {
141      if (swigCMemOwn) {
142        swigCMemOwn = false;
143        FerryJNI.delete_AtomicInteger(swigCPtr);
144      }
145      swigCPtr = 0;
146    }
147  }
148
149  public AtomicInteger() {
150    this(FerryJNI.new_AtomicInteger__SWIG_0(), true);
151  }
152
153  public AtomicInteger(int arg0) {
154    this(FerryJNI.new_AtomicInteger__SWIG_1(arg0), true);
155  }
156
157  public int get() {
158    return FerryJNI.AtomicInteger_get(swigCPtr, this);
159  }
160
161  public void set(int arg0) {
162    FerryJNI.AtomicInteger_set(swigCPtr, this, arg0);
163  }
164
165  public int getAndSet(int arg0) {
166    return FerryJNI.AtomicInteger_getAndSet(swigCPtr, this, arg0);
167  }
168
169  public int getAndIncrement() {
170    return FerryJNI.AtomicInteger_getAndIncrement(swigCPtr, this);
171  }
172
173  public int getAndDecrement() {
174    return FerryJNI.AtomicInteger_getAndDecrement(swigCPtr, this);
175  }
176
177  public int getAndAdd(int arg0) {
178    return FerryJNI.AtomicInteger_getAndAdd(swigCPtr, this, arg0);
179  }
180
181  public int incrementAndGet() {
182    return FerryJNI.AtomicInteger_incrementAndGet(swigCPtr, this);
183  }
184
185  public int decrementAndGet() {
186    return FerryJNI.AtomicInteger_decrementAndGet(swigCPtr, this);
187  }
188
189  public int addAndGet(int arg0) {
190    return FerryJNI.AtomicInteger_addAndGet(swigCPtr, this, arg0);
191  }
192
193  /**
194   * Compare the current value to expected, and if<br>
195   * they are equal, set the current value to update.<br>
196   * @param expected the value expected<br>
197   * @param update the value to update to<br>
198   * @return true if equal
199   */
200  public boolean compareAndSet(int expected, int update) {
201    return FerryJNI.AtomicInteger_compareAndSet(swigCPtr, this, expected, update);
202  }
203
204  /**
205   * @return true if we're actually able to guarantee<br>
206   * atomicity; false if we can't.
207   */
208  public boolean isAtomic() {
209    return FerryJNI.AtomicInteger_isAtomic(swigCPtr, this);
210  }
211
212}