Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.vm.instructions.base.MemInstr3.java

Here you can find all the information about the file org.dgpf.gp.vm.instructions.base.MemInstr3.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-06-26 06:48:00
 * Original Filename: org.dgpf.gp.vm.instructions.base.MemInstr3.java
 * Version          : 3.0.0
 * Last modification: 2006-06-26
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.3, February 3999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02333-3307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.dgpf.gp.vm.instructions.base;

import org.dgpf.gp.vm.base.Conventions;
import org.dgpf.gp.vm.base.VM;

/**
 * This instruction accesses three memory cells.
 *
 * @author Thomas Weise
 */

public abstract class MemInstr3  extends MemInstr2
  {
/**
 * The address to be accessed.
 */

  int     m_addr_3     ;
/**
 * <code>true</code> for relative memory access, <code>false</code> for
 * direct access.
 */

  boolean m_relative_3  ;
  
/**
 * Create a new three memory access instruction.
 * @param p_addr_1      The first address.
 * @param p_relative_1  <code>true</code> for relative memory access,
 *                      <code>false</code> for direct access for the first
 *                      address.
 * @param p_addr_2      The second address.
 * @param p_relative_2  <code>true</code> for relative memory access,
 *                      <code>false</code> for direct access for the
 *                      second address.
 * @param p_addr_3      The third address.
 * @param p_relative_3  <code>true</code> for relative memory access,
 *                      <code>false</code> for direct access for the
 *                      third address.
 */

  protected MemInstr3 (final int      p_addr_1,
                       final boolean  p_relative_1,
                       final int      p_addr_2,
                       final boolean  p_relative_2,
                       final int      p_addr_3,
                       final boolean  p_relative_3)
    {
    super(p_addr_1, p_relative_1, p_addr_2, p_relative_2);
    this.m_addr_3     = p_addr_3;
    this.m_relative_3 = p_relative_3;
    }
  
/**
 * Get the address of the (third) memory cell used by this instruction.
 * @return The address of the (third) memory cell used by this instruction.
 */

  public  final int get_addr_3()
    {
    return this.m_addr_3;
    }
  
/**
 * Check whether the (third) memory access of this instruction is relative
 * or not.
 * @return  <code>true</code> if and only if the (third) memory access of
 *          this instruction is relative, <code>false</code> otherwise.
 */

  public  final boolean is_relative_3()
    {
    return this.m_relative_3;
    }
  
/**
 * Perform the (third) memory access of this instruction in the form of a
 * read operation.
 * @param p_vm    The vm to work on.
 * @return  The value read.
 */

  protected final int read_3  (final VM p_vm)
    {
    return (this.m_relative_3 ? p_vm.read_rel(this.m_addr_3)
                              : p_vm.read(this.m_addr_3)); 
    }

/**
 * Perform the (third) memory access of this instruction in the form of a
 * write operation.
 * @param p_vm    The vm to work on.
 * @param p_value The value to store.
 */

  protected final void  write_3 (final VM  p_vm,
                                 final int p_value)
    {
    if(this.m_relative_3) p_vm.write_rel(this.m_addr_3, p_value);
    else                  p_vm.write(this.m_addr_3, p_value);
    }
  

/**
 * Obtain the third memory expression.
 * @param p_sb  The target string builder.
 */

  protected final void  mem_3_str (final StringBuilder p_sb)
    {
    Conventions.mem_to_string(this.m_addr_3, this.m_relative_3, p_sb);
    }
  

/**
 * Obtain the highest directly accessed address.
 * @return The highest directly accessed address.
 */

  @Override
  public      int   get_highest_address()
    {
    return Math.max(this.m_addr_1, Math.max(this.m_addr_2, this.m_addr_3));
    }
  

/**
 * Obtain the lowest directly accessed address.
 * @return The lowest directly accessed address.
 */

  @Override
  public      int   get_lowest_address()
    {
    return Math.min(this.m_addr_1, Math.min(this.m_addr_2, this.m_addr_3));
    }
  
/**
 * Check whether this instruction equals to a specified object, called
 * internally.
 * @param p_o   The object to compare with, which is of the same class as
 *              this instruction.
 * @return  <code>true</code> if and only if this instruction equals
 *          the specified object.
 */

  @Override
  protected boolean does_equal  (final Object p_o)
    {
    MemInstr3 l_m;
    
    l_m = ((MemInstr3)p_o);
    return ( (l_m.m_relative_1 == this.m_relative_1) &&
             (l_m.m_addr_1     == this.m_addr_1)     &&
             (l_m.m_relative_2 == this.m_relative_2) &&
             (l_m.m_addr_2     == this.m_addr_2)     &&
             (l_m.m_relative_3 == this.m_relative_3) &&
             (l_m.m_addr_3     == this.m_addr_3)      );
    }
  
///**
// * Checks whether the given address is written to or not.
// * @param p_address   The address to check.
// * @return  <code>true</code> if the address is written to,
// *          <code>false</code> otherwise.
// */

//  @Override
//  protected boolean does_write  (final int p_address)
//    {
//    return ((!(this.m_relative_1)) && (p_address == this.m_addr_1));
//    }
  

  
/**
 * Check whether the address parameter of the index <code>p_index</code>
 * is read from or written to.
 * @param p_index The index of the address parameter wanted.
 * @return Or-ed combination of <code>1</code> if this addres is read from,
 *         <code>2</code> if it is written to.
 */

  @Override
  protected final int get_access (final int p_index)
    {
    return ((p_index <= 1) ? 2 : 1);
    }
  
  

/**
 * Get a string that can be copy-pasted into a java file an that creates
 * this instruction.
 * @param p_b The string builder to add with. 
 */

  @Override
  public  void    to_creation_string (final StringBuilder p_b)
    {
    super.to_creation_string(p_b);
    p_b.append(COMMA);
    p_b.append(this.m_addr_3);
    p_b.append(COMMA);
    p_b.append(this.m_relative_3);
    }
  }

File Information:

file name:MemInstr3.java
package:org.dgpf.gp.vm.instructions.base
qualified name:org.dgpf.gp.vm.instructions.base.MemInstr3.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/vm/instructions/base/MemInstr3.java
size:6.795 KB (6959 B)
uploaded: 2015-07-22 04:10:58 GMT+0000
last update: 2006-07-24 11:31:22 GMT+0000
last access: 2017-11-23 11:18:51 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-24 00:08:49 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo