Module dev.civl.gmc
Package dev.civl.gmc

Class GMCConfiguration

java.lang.Object
dev.civl.gmc.GMCConfiguration
All Implemented Interfaces:
Serializable

public class GMCConfiguration extends Object implements Serializable

A GMCConfiguration is composed of a number of GMCSection's, each of which encapsulates a set of key-value pairs, where the keys correspond to commandline parameters and the value is the value assigned to that parameter. In addition, there can be any number of "free arguments" that are not assigned to any parameter. The free arguments are always strings.

A configuration is typically generated by parsing a command line, or at least the suffix of a command line after the initial command(s). The command line suffix -verbose -errBound=10 filename.c, for example, would yield a configuration with an anonymous GMCSection in which "verbose" is mapped to true, "errBound" is mapped to the integer 10, and with one free argument "fileName.c".

A configuration has associated to it a set of options, which are specified when the configuration is instantiated. And each GMCSection has associated to it a configuration.

Each option is an instance of class Option. An option has a name and a type. The type is one of STRING, INTEGER, DOUBLE, BOOLEAN, or MAP. The type determines the kind of value that can be assigned to an option. The first four are "scalar" types and take values of type String, Integer, Double, and Boolean, respectively.

An option of MAP type may be assigned a value of type Mapinvalid input: '<'String,Object>. This kind of option is provided for command line arguments such as -inputX=10 -inputB=true -inputZ="hello". This constructs a map from String to Object which maps "X" to the Integer 10, "B" to the Boolean true, and "Z" to the String "hello". This map is the value that is assigned to the option named "input". In general, the values of the map can be any scalar values, and their types will be inferred from their format. For example 1.0 will be interpreted as a Double, 1 as an Integer, "1" (with quotes) a String.

See Also:
  • Field Details

    • ANONYMOUS_SECTION

      public static final String ANONYMOUS_SECTION
      The reserved name of the anonymous GMCSection of a configuration.
      See Also:
    • out

      public PrintStream out
  • Constructor Details

    • GMCConfiguration

      public GMCConfiguration(Collection<Option> options)
      Constructs new configuration with the set of options obtained from the given collection. The set of options associated to this configuration is determined from the given collection. Duplicates in the collection will be ignored. The new configuration will be empty: i.e., it will have no entries, i.e., nothing will be assigned to any option.
      Parameters:
      options - a collection of non-null options; duplicates will be ignored. The options must have distinct names
      Throws:
      IllegalArgumentException - if two options in the collection have the same name
  • Method Details

    • getOptions

      public Collection<Option> getOptions()
      Returns the set of options associated to this configuration. This returns all options associated to this configuration, not just those that have a value assigned to them.
      Returns:
      the set of options
    • getOption

      public Option getOption(String name)
      Returns the option with the given name associated to this configuration, or null if there is none.
      Parameters:
      name - the name of an option
      Returns:
      the option with that name
    • getSection

      public GMCSection getSection(String name)
      Returns the section with the given name, or null if there is none.
      Parameters:
      name - the name of the section
      Returns:
      the section with that name
    • getAnonymousSection

      public GMCSection getAnonymousSection()
      Returns the anonymous section
      Returns:
      the anonymous sections
    • getNumSections

      public int getNumSections()
      Returns the number of NON-anonymous sections.
      Returns:
      the number of NON-anonymous sections.
    • setAnonymousSection

      public void setAnonymousSection(GMCSection section)
      Updates the anonymous section with the given section. Also updates the configuration associates with the given section to be this configuration.
      Parameters:
      section - The section to be used as the anonymous section of this configuration.
    • isQuiet

      public boolean isQuiet()
    • setQuiet

      public void setQuiet(boolean isQuiet)
    • addSection

      public void addSection(GMCSection section)
      Adds a section to the NON-anonymous section map. Also updates the configuration associates with the given section to be this configuration.
      Precondition: !section.getName().equals(DEFAULT_SECTION).
      Parameters:
      section - The section to be added
    • clone

      public GMCConfiguration clone()
      Returns a deep copy of this configuration. The two configurations will share references to the same options, and to the same Strings, but not to anything else. As options and strings are immutable, this should not be a problem.
      Returns:
      deep copy of this configuration
    • getSections

      public Iterable<GMCSection> getSections()
      Returns an iterable object of the NON-anonymous sections.
      Returns:
      the iterable object of the NON-anonymous sections.
    • read

      public void read(GMCConfiguration that)
      Modifies this configuration by reading in the values of the given configuration and using those to set values of this one. Existing entries in this one may be overwritten in the process.
      Parameters:
      that - another configuration; the set of options associated to that should be a subset of the set of options associated to this
    • print

      public void print(PrintStream out)
      Prints the current state of this configuration in a manner similar to what would appear on a commandline. Each scalar assignment appears on one line. At the end the free arguments are printed, one on each line.
      Parameters:
      out - print stream to which to print
    • printTransitions

      public boolean printTransitions()
    • setPrintTransition

      public void setPrintTransition(boolean printTransitions)
    • setPrintStream

      public void setPrintStream(PrintStream out)
    • setSaveStates

      public void setSaveStates(boolean saveStates)
    • getSaveStates

      public boolean getSaveStates()