001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.vmutil.options;
014
015import org.vmmagic.pragma.Uninterruptible;
016import org.vmmagic.unboxed.Address;
017
018/**
019 * An option with a simple integer value.
020 */
021public class AddressOption extends Option {
022  // values
023  protected Address defaultValue;
024  protected Address value;
025
026  /**
027   * Create a new int option.
028   *
029   * @param set The option set this option belongs to.
030   * @param name The space separated name for the option.
031   * @param desc The purpose of the option
032   * @param defaultValue The default value of the option.
033   */
034  protected AddressOption(OptionSet set, String name, String desc, Address defaultValue) {
035    super(set, ADDRESS_OPTION, name, desc);
036    this.value = this.defaultValue = defaultValue;
037  }
038
039  /**
040   * Read the current value of the option.
041   *
042   * @return The option value.
043   */
044  @Uninterruptible
045  public Address getValue() {
046    return this.value;
047  }
048
049  /**
050   * Read the default value of the option.
051   *
052   * @return The default value.
053   */
054  @Uninterruptible
055  public Address getDefaultValue() {
056    return this.defaultValue;
057  }
058
059  /**
060   * Update the value of the option, echoing the change if the echoOptions
061   * option is set. This method also calls the validate method to allow
062   * subclasses to perform any required validation.
063   *
064   * @param value The new value for the option.
065   */
066  public void setValue(int value) {
067    this.value = Address.fromIntZeroExtend(value);
068    validate();
069    set.logChange(this);
070  }
071
072  /**
073   * Modify the default value of the option.
074   *
075   * @param value The new default value for the option.
076   */
077  public void setDefaultValue(Address value) {
078    this.value = this.defaultValue = value;
079  }
080}