Logo
Distributed Genetic Programming Framework
print print

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

Here you can find all the information about the file org.dgpf.gp.vm.instructions.base.MemInstr1.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.MemInstr1.java
 * Version          : 1.0.0
 * Last modification: 2006-06-26
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    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 02111-1307, 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.Instruction;
import org.dgpf.gp.vm.base.VM;

/**
 * This instruction accesses one memory cell.
 *
 * @author Thomas Weise
 */

public abstract class MemInstr1  extends Instruction
  {
/**
 * The comma char array.
 */

  static  final char[]  COMMA = ", ".toCharArray();
  
/**
 * The address to be accessed.
 */

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

                boolean m_relative_1  ;
  
/**
 * Create a new single memory access instruction.
 * @param p_addr_1      The address.
 * @param p_relative_1  <code>true</code> for relative memory access,
 *                      <code>false</code> for direct access.
 */

  protected MemInstr1 (final int      p_addr_1,
                       final boolean  p_relative_1)
    {
    super();
    this.m_addr_1     = p_addr_1;
    this.m_relative_1 = p_relative_1;
    }
  
/**
 * Get the address of the (first) memory cell used by this instruction.
 * @return The address of the (first) memory cell used by this instruction.
 */

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

  public  final boolean is_relative_1()
    {
    return this.m_relative_1;
    }
  
/**
 * Perform the (first) 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_1  (final VM p_vm)
    {
    return (this.m_relative_1 ? p_vm.read_rel(this.m_addr_1)
                              : p_vm.read(this.m_addr_1)); 
    }

/**
 * Perform the (first) 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_1 (final VM  p_vm,
                                 final int p_value)
    {
    if(this.m_relative_1) p_vm.write_rel(this.m_addr_1, p_value);
    else                  p_vm.write(this.m_addr_1, p_value);
    }
  
/**
 * Obtain the first memory expression.
 * @param p_sb  The target string builder.
 */

  protected final void  mem_1_str (final StringBuilder p_sb)
    {
    Conventions.mem_to_string(this.m_addr_1, this.m_relative_1, p_sb);
    }
  
/**
 * Obtain the highest directly accessed address.
 * @return The highest directly accessed address.
 */

  @Override
  public     int   get_highest_address()
    {
    return this.m_addr_1;
    }
  
/**
 * Obtain the lowest directly accessed address.
 * @return The lowest directly accessed address.
 */

  @Override
  public      int   get_lowest_address()
    {
    return this.m_addr_1;
    }
  

/**
 * 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)
    {
    MemInstr1 l_m;
    
    l_m = ((MemInstr1)p_o);
    return ( (l_m.m_relative_1 == this.m_relative_1) &&
             (l_m.m_addr_1     == 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.
 */

  protected abstract  int get_access (final int p_index);
  
/**
 * 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. 
 */

  public @Override void    to_creation_string (final StringBuilder p_b)
    {
    p_b.append(this.m_addr_1);
    p_b.append(COMMA);
    p_b.append(this.m_relative_1);
    }
  }

File Information:

file name:MemInstr1.java
package:org.dgpf.gp.vm.instructions.base
qualified name:org.dgpf.gp.vm.instructions.base.MemInstr1.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/vm/instructions/base/MemInstr1.java
size:5.367 KB (5496 B)
uploaded: 2015-07-22 04:10:58 GMT+0000
last update: 2006-07-24 11:31:27 GMT+0000
last access: 2017-11-20 18:45:03 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-20 18:45:03 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo