src/Pure/System/options.scala
author wenzelm
Mon Sep 05 22:09:52 2016 +0200 (2016-09-05)
changeset 63805 c272680df665
parent 63441 4c3fa4dba79f
child 64118 0996fab2ec03
permissions -rw-r--r--
clarified modules;
wenzelm@48365
     1
/*  Title:      Pure/System/options.scala
wenzelm@48365
     2
    Author:     Makarius
wenzelm@48365
     3
wenzelm@51945
     4
System options with external string representation.
wenzelm@48365
     5
*/
wenzelm@48365
     6
wenzelm@48365
     7
package isabelle
wenzelm@48365
     8
wenzelm@48365
     9
wenzelm@48807
    10
import java.util.Calendar
wenzelm@48807
    11
wenzelm@48807
    12
wenzelm@48365
    13
object Options
wenzelm@48365
    14
{
wenzelm@48421
    15
  type Spec = (String, Option[String])
wenzelm@48421
    16
wenzelm@48421
    17
  val empty: Options = new Options()
wenzelm@48421
    18
wenzelm@48421
    19
wenzelm@48421
    20
  /* representation */
wenzelm@48421
    21
wenzelm@48421
    22
  sealed abstract class Type
wenzelm@48365
    23
  {
wenzelm@56599
    24
    def print: String = Word.lowercase(toString)
wenzelm@48365
    25
  }
wenzelm@49246
    26
  case object Bool extends Type
wenzelm@49246
    27
  case object Int extends Type
wenzelm@49246
    28
  case object Real extends Type
wenzelm@49246
    29
  case object String extends Type
wenzelm@49246
    30
  case object Unknown extends Type
wenzelm@48365
    31
wenzelm@56465
    32
  case class Opt(
wenzelm@56465
    33
    public: Boolean,
wenzelm@56465
    34
    pos: Position.T,
wenzelm@56465
    35
    name: String,
wenzelm@56465
    36
    typ: Type,
wenzelm@56465
    37
    value: String,
wenzelm@56465
    38
    default_value: String,
wenzelm@56465
    39
    description: String,
wenzelm@56465
    40
    section: String)
wenzelm@48860
    41
  {
wenzelm@49289
    42
    private def print(default: Boolean): String =
wenzelm@49289
    43
    {
wenzelm@49289
    44
      val x = if (default) default_value else value
wenzelm@49247
    45
      "option " + name + " : " + typ.print + " = " +
wenzelm@49289
    46
        (if (typ == Options.String) quote(x) else x) +
wenzelm@49289
    47
        (if (description == "") "" else "\n  -- " + quote(description))
wenzelm@49289
    48
    }
wenzelm@49289
    49
wenzelm@49289
    50
    def print: String = print(false)
wenzelm@49289
    51
    def print_default: String = print(true)
wenzelm@49247
    52
wenzelm@56559
    53
    def title(strip: String = ""): String =
wenzelm@49270
    54
    {
wenzelm@56600
    55
      val words = Word.explode('_', name)
wenzelm@49270
    56
      val words1 =
wenzelm@49270
    57
        words match {
wenzelm@49270
    58
          case word :: rest if word == strip => rest
wenzelm@49270
    59
          case _ => words
wenzelm@49270
    60
        }
wenzelm@56609
    61
      Word.implode(words1.map(Word.perhaps_capitalize(_)))
wenzelm@49270
    62
    }
wenzelm@49270
    63
wenzelm@48860
    64
    def unknown: Boolean = typ == Unknown
wenzelm@48860
    65
  }
wenzelm@48365
    66
wenzelm@48365
    67
wenzelm@48365
    68
  /* parsing */
wenzelm@48365
    69
wenzelm@49270
    70
  private val SECTION = "section"
wenzelm@52065
    71
  private val PUBLIC = "public"
wenzelm@48795
    72
  private val OPTION = "option"
wenzelm@48807
    73
  private val OPTIONS = Path.explode("etc/options")
wenzelm@50793
    74
  private val PREFS_DIR = Path.explode("$ISABELLE_HOME_USER/etc")
wenzelm@50793
    75
  private val PREFS = PREFS_DIR + Path.basic("preferences")
wenzelm@48713
    76
wenzelm@49270
    77
  lazy val options_syntax =
wenzelm@61579
    78
    Outer_Syntax.init() + ":" + "=" + "--" + Symbol.comment + Symbol.comment_decoded +
wenzelm@63441
    79
      (SECTION, Keyword.DOCUMENT_HEADING) +
wenzelm@63441
    80
      (PUBLIC, Keyword.BEFORE_COMMAND) +
wenzelm@63441
    81
      (OPTION, Keyword.THY_DECL)
wenzelm@49270
    82
wenzelm@48807
    83
  lazy val prefs_syntax = Outer_Syntax.init() + "="
wenzelm@48713
    84
wenzelm@62968
    85
  trait Parser extends Parse.Parser
wenzelm@48365
    86
  {
wenzelm@62968
    87
    val option_name = atom("option name", _.is_name)
wenzelm@62968
    88
    val option_type = atom("option type", _.is_name)
wenzelm@48807
    89
    val option_value =
wenzelm@48807
    90
      opt(token("-", tok => tok.is_sym_ident && tok.content == "-")) ~ atom("nat", _.is_nat) ^^
wenzelm@48807
    91
        { case s ~ n => if (s.isDefined) "-" + n else n } |
wenzelm@48807
    92
      atom("option value", tok => tok.is_name || tok.is_float)
wenzelm@62968
    93
  }
wenzelm@48807
    94
wenzelm@62968
    95
  object Parser extends Parse.Parser with Parser
wenzelm@62968
    96
  {
wenzelm@61579
    97
    def comment_marker: Parser[String] =
wenzelm@61579
    98
      $$$("--") | $$$(Symbol.comment) | $$$(Symbol.comment_decoded)
wenzelm@61579
    99
wenzelm@48807
   100
    val option_entry: Parser[Options => Options] =
wenzelm@48365
   101
    {
wenzelm@49270
   102
      command(SECTION) ~! text ^^
wenzelm@49295
   103
        { case _ ~ a => (options: Options) => options.set_section(a) } |
wenzelm@60133
   104
      opt($$$(PUBLIC)) ~ command(OPTION) ~! (position(option_name) ~ $$$(":") ~ option_type ~
wenzelm@61579
   105
      $$$("=") ~ option_value ~ (comment_marker ~! text ^^ { case _ ~ x => x } | success(""))) ^^
wenzelm@59811
   106
        { case a ~ _ ~ ((b, pos) ~ _ ~ c ~ _ ~ d ~ e) =>
wenzelm@56465
   107
            (options: Options) => options.declare(a.isDefined, pos, b, c, d, e) }
wenzelm@48365
   108
    }
wenzelm@48365
   109
wenzelm@48807
   110
    val prefs_entry: Parser[Options => Options] =
wenzelm@48807
   111
    {
wenzelm@58908
   112
      option_name ~ ($$$("=") ~! option_value) ^^
wenzelm@48860
   113
      { case a ~ (_ ~ b) => (options: Options) => options.add_permissive(a, b) }
wenzelm@48807
   114
    }
wenzelm@48807
   115
wenzelm@48807
   116
    def parse_file(syntax: Outer_Syntax, parser: Parser[Options => Options],
wenzelm@48807
   117
      options: Options, file: Path): Options =
wenzelm@48365
   118
    {
wenzelm@59083
   119
      val toks = Token.explode(syntax.keywords, File.read(file))
wenzelm@48807
   120
      val ops =
wenzelm@59705
   121
        parse_all(rep(parser), Token.reader(toks, Token.Pos.file(file.implode))) match {
wenzelm@48807
   122
          case Success(result, _) => result
wenzelm@48807
   123
          case bad => error(bad.toString)
wenzelm@48807
   124
        }
wenzelm@49270
   125
      try { (options.set_section("") /: ops) { case (opts, op) => op(opts) } }
wenzelm@48992
   126
      catch { case ERROR(msg) => error(msg + Position.here(file.position)) }
wenzelm@48365
   127
    }
wenzelm@48365
   128
  }
wenzelm@48365
   129
wenzelm@48807
   130
  def init_defaults(): Options =
wenzelm@48365
   131
  {
wenzelm@48365
   132
    var options = empty
wenzelm@48365
   133
    for {
wenzelm@48365
   134
      dir <- Isabelle_System.components()
wenzelm@48548
   135
      file = dir + OPTIONS if file.is_file
wenzelm@48807
   136
    } { options = Parser.parse_file(options_syntax, Parser.option_entry, options, file) }
wenzelm@48365
   137
    options
wenzelm@48365
   138
  }
wenzelm@48457
   139
wenzelm@48807
   140
  def init(): Options = init_defaults().load_prefs()
wenzelm@48807
   141
wenzelm@48457
   142
wenzelm@48457
   143
  /* encode */
wenzelm@48457
   144
wenzelm@48457
   145
  val encode: XML.Encode.T[Options] = (options => options.encode)
wenzelm@48693
   146
wenzelm@48693
   147
wenzelm@62832
   148
  /* Isabelle tool wrapper */
wenzelm@48693
   149
wenzelm@62832
   150
  val isabelle_tool = Isabelle_Tool("option", "print Isabelle system options", args =>
wenzelm@48693
   151
  {
wenzelm@62832
   152
    var build_options = false
wenzelm@62832
   153
    var get_option = ""
wenzelm@62832
   154
    var list_options = false
wenzelm@62832
   155
    var export_file = ""
wenzelm@62437
   156
wenzelm@62832
   157
    val getopts = Getopts("""
wenzelm@62437
   158
Usage: isabelle options [OPTIONS] [MORE_OPTIONS ...]
wenzelm@48693
   159
wenzelm@62437
   160
  Options are:
wenzelm@62437
   161
    -b           include $ISABELLE_BUILD_OPTIONS
wenzelm@62437
   162
    -g OPTION    get value of OPTION
wenzelm@62437
   163
    -l           list options
wenzelm@62437
   164
    -x FILE      export options to FILE in YXML format
wenzelm@62437
   165
wenzelm@62437
   166
  Report Isabelle system options, augmented by MORE_OPTIONS given as
wenzelm@62437
   167
  arguments NAME=VAL or NAME.
wenzelm@62437
   168
""",
wenzelm@62832
   169
      "b" -> (_ => build_options = true),
wenzelm@62832
   170
      "g:" -> (arg => get_option = arg),
wenzelm@62832
   171
      "l" -> (_ => list_options = true),
wenzelm@62832
   172
      "x:" -> (arg => export_file = arg))
wenzelm@52737
   173
wenzelm@62832
   174
    val more_options = getopts(args)
wenzelm@62832
   175
    if (get_option == "" && !list_options && export_file == "") getopts.usage()
wenzelm@52737
   176
wenzelm@62832
   177
    val options =
wenzelm@62832
   178
    {
wenzelm@62832
   179
      val options0 = Options.init()
wenzelm@62832
   180
      val options1 =
wenzelm@62832
   181
        if (build_options)
wenzelm@62832
   182
          (options0 /: Word.explode(Isabelle_System.getenv("ISABELLE_BUILD_OPTIONS")))(_ + _)
wenzelm@62832
   183
        else options0
wenzelm@62832
   184
      (options1 /: more_options)(_ + _)
wenzelm@62832
   185
    }
wenzelm@48693
   186
wenzelm@62832
   187
    if (get_option != "")
wenzelm@62832
   188
      Console.println(options.check_name(get_option).value)
wenzelm@62437
   189
wenzelm@62832
   190
    if (export_file != "")
wenzelm@62832
   191
      File.write(Path.explode(export_file), YXML.string_of_body(options.encode))
wenzelm@62437
   192
wenzelm@62832
   193
    if (get_option == "" && export_file == "")
wenzelm@62832
   194
      Console.println(options.print)
wenzelm@62832
   195
  })
wenzelm@48365
   196
}
wenzelm@48365
   197
wenzelm@48365
   198
wenzelm@49270
   199
final class Options private(
wenzelm@49296
   200
  val options: Map[String, Options.Opt] = Map.empty,
wenzelm@49270
   201
  val section: String = "")
wenzelm@48365
   202
{
wenzelm@48365
   203
  override def toString: String = options.iterator.mkString("Options (", ",", ")")
wenzelm@48365
   204
wenzelm@54347
   205
  private def print_opt(opt: Options.Opt): String =
wenzelm@54347
   206
    if (opt.public) "public " + opt.print else opt.print
wenzelm@54347
   207
wenzelm@54347
   208
  def print: String = cat_lines(options.toList.sortBy(_._1).map(p => print_opt(p._2)))
wenzelm@48693
   209
wenzelm@49245
   210
  def description(name: String): String = check_name(name).description
wenzelm@49245
   211
wenzelm@48365
   212
wenzelm@48370
   213
  /* check */
wenzelm@48365
   214
wenzelm@49246
   215
  def check_name(name: String): Options.Opt =
wenzelm@48365
   216
    options.get(name) match {
wenzelm@48860
   217
      case Some(opt) if !opt.unknown => opt
wenzelm@48860
   218
      case _ => error("Unknown option " + quote(name))
wenzelm@48365
   219
    }
wenzelm@48365
   220
wenzelm@48365
   221
  private def check_type(name: String, typ: Options.Type): Options.Opt =
wenzelm@48365
   222
  {
wenzelm@48365
   223
    val opt = check_name(name)
wenzelm@48365
   224
    if (opt.typ == typ) opt
wenzelm@48365
   225
    else error("Ill-typed option " + quote(name) + " : " + opt.typ.print + " vs. " + typ.print)
wenzelm@48365
   226
  }
wenzelm@48365
   227
wenzelm@48370
   228
wenzelm@48370
   229
  /* basic operations */
wenzelm@48370
   230
wenzelm@48370
   231
  private def put[A](name: String, typ: Options.Type, value: String): Options =
wenzelm@48370
   232
  {
wenzelm@48370
   233
    val opt = check_type(name, typ)
wenzelm@49270
   234
    new Options(options + (name -> opt.copy(value = value)), section)
wenzelm@48370
   235
  }
wenzelm@48370
   236
wenzelm@48365
   237
  private def get[A](name: String, typ: Options.Type, parse: String => Option[A]): A =
wenzelm@48365
   238
  {
wenzelm@48365
   239
    val opt = check_type(name, typ)
wenzelm@48365
   240
    parse(opt.value) match {
wenzelm@48365
   241
      case Some(x) => x
wenzelm@48365
   242
      case None =>
wenzelm@48365
   243
        error("Malformed value for option " + quote(name) +
wenzelm@48365
   244
          " : " + typ.print + " =\n" + quote(opt.value))
wenzelm@48365
   245
    }
wenzelm@48365
   246
  }
wenzelm@48365
   247
wenzelm@48365
   248
wenzelm@48365
   249
  /* internal lookup and update */
wenzelm@48365
   250
wenzelm@49954
   251
  class Bool_Access
wenzelm@48365
   252
  {
wenzelm@63805
   253
    def apply(name: String): Boolean = get(name, Options.Bool, Value.Boolean.unapply)
wenzelm@48365
   254
    def update(name: String, x: Boolean): Options =
wenzelm@63805
   255
      put(name, Options.Bool, Value.Boolean(x))
wenzelm@48365
   256
  }
wenzelm@49954
   257
  val bool = new Bool_Access
wenzelm@48365
   258
wenzelm@49954
   259
  class Int_Access
wenzelm@48365
   260
  {
wenzelm@63805
   261
    def apply(name: String): Int = get(name, Options.Int, Value.Int.unapply)
wenzelm@48365
   262
    def update(name: String, x: Int): Options =
wenzelm@63805
   263
      put(name, Options.Int, Value.Int(x))
wenzelm@48365
   264
  }
wenzelm@49954
   265
  val int = new Int_Access
wenzelm@48365
   266
wenzelm@49954
   267
  class Real_Access
wenzelm@48365
   268
  {
wenzelm@63805
   269
    def apply(name: String): Double = get(name, Options.Real, Value.Double.unapply)
wenzelm@48365
   270
    def update(name: String, x: Double): Options =
wenzelm@63805
   271
      put(name, Options.Real, Value.Double(x))
wenzelm@48365
   272
  }
wenzelm@49954
   273
  val real = new Real_Access
wenzelm@48365
   274
wenzelm@49954
   275
  class String_Access
wenzelm@48365
   276
  {
wenzelm@48365
   277
    def apply(name: String): String = get(name, Options.String, s => Some(s))
wenzelm@48365
   278
    def update(name: String, x: String): Options = put(name, Options.String, x)
wenzelm@48365
   279
  }
wenzelm@49954
   280
  val string = new String_Access
wenzelm@48370
   281
wenzelm@50207
   282
  class Seconds_Access
wenzelm@50207
   283
  {
wenzelm@50207
   284
    def apply(name: String): Time = Time.seconds(real(name))
wenzelm@50207
   285
  }
wenzelm@50207
   286
  val seconds = new Seconds_Access
wenzelm@50207
   287
wenzelm@48370
   288
wenzelm@48807
   289
  /* external updates */
wenzelm@48370
   290
wenzelm@48370
   291
  private def check_value(name: String): Options =
wenzelm@48370
   292
  {
wenzelm@48370
   293
    val opt = check_name(name)
wenzelm@48370
   294
    opt.typ match {
wenzelm@48370
   295
      case Options.Bool => bool(name); this
wenzelm@48370
   296
      case Options.Int => int(name); this
wenzelm@48370
   297
      case Options.Real => real(name); this
wenzelm@48370
   298
      case Options.String => string(name); this
wenzelm@48860
   299
      case Options.Unknown => this
wenzelm@48370
   300
    }
wenzelm@48370
   301
  }
wenzelm@48370
   302
wenzelm@56465
   303
  def declare(
wenzelm@56465
   304
    public: Boolean,
wenzelm@56465
   305
    pos: Position.T,
wenzelm@56465
   306
    name: String,
wenzelm@56465
   307
    typ_name: String,
wenzelm@56465
   308
    value: String,
wenzelm@56465
   309
    description: String): Options =
wenzelm@48370
   310
  {
wenzelm@48370
   311
    options.get(name) match {
wenzelm@56465
   312
      case Some(other) =>
wenzelm@56465
   313
        error("Duplicate declaration of option " + quote(name) + Position.here(pos) +
wenzelm@56465
   314
          Position.here(other.pos))
wenzelm@48370
   315
      case None =>
wenzelm@48370
   316
        val typ =
wenzelm@48370
   317
          typ_name match {
wenzelm@48370
   318
            case "bool" => Options.Bool
wenzelm@48370
   319
            case "int" => Options.Int
wenzelm@48370
   320
            case "real" => Options.Real
wenzelm@48370
   321
            case "string" => Options.String
wenzelm@56465
   322
            case _ =>
wenzelm@56465
   323
              error("Unknown type for option " + quote(name) + " : " + quote(typ_name) +
wenzelm@56465
   324
                Position.here(pos))
wenzelm@48370
   325
          }
wenzelm@56465
   326
        val opt = Options.Opt(public, pos, name, typ, value, value, description, section)
wenzelm@49270
   327
        (new Options(options + (name -> opt), section)).check_value(name)
wenzelm@48370
   328
    }
wenzelm@48370
   329
  }
wenzelm@48370
   330
wenzelm@48860
   331
  def add_permissive(name: String, value: String): Options =
wenzelm@48860
   332
  {
wenzelm@48860
   333
    if (options.isDefinedAt(name)) this + (name, value)
wenzelm@56465
   334
    else {
wenzelm@56465
   335
      val opt = Options.Opt(false, Position.none, name, Options.Unknown, value, value, "", "")
wenzelm@56465
   336
      new Options(options + (name -> opt), section)
wenzelm@56465
   337
    }
wenzelm@48860
   338
  }
wenzelm@48860
   339
wenzelm@48807
   340
  def + (name: String, value: String): Options =
wenzelm@48370
   341
  {
wenzelm@48370
   342
    val opt = check_name(name)
wenzelm@49270
   343
    (new Options(options + (name -> opt.copy(value = value)), section)).check_value(name)
wenzelm@48370
   344
  }
wenzelm@48370
   345
wenzelm@48807
   346
  def + (name: String, opt_value: Option[String]): Options =
wenzelm@48370
   347
  {
wenzelm@48370
   348
    val opt = check_name(name)
wenzelm@48370
   349
    opt_value match {
wenzelm@48807
   350
      case Some(value) => this + (name, value)
wenzelm@48807
   351
      case None if opt.typ == Options.Bool => this + (name, "true")
wenzelm@48370
   352
      case None => error("Missing value for option " + quote(name) + " : " + opt.typ.print)
wenzelm@48370
   353
    }
wenzelm@48370
   354
  }
wenzelm@48370
   355
wenzelm@48807
   356
  def + (str: String): Options =
wenzelm@48370
   357
  {
wenzelm@48370
   358
    str.indexOf('=') match {
wenzelm@48807
   359
      case -1 => this + (str, None)
wenzelm@48807
   360
      case i => this + (str.substring(0, i), str.substring(i + 1))
wenzelm@48370
   361
    }
wenzelm@48370
   362
  }
wenzelm@48456
   363
wenzelm@48807
   364
  def ++ (specs: List[Options.Spec]): Options =
wenzelm@48807
   365
    (this /: specs)({ case (x, (y, z)) => x + (y, z) })
wenzelm@48807
   366
wenzelm@48456
   367
wenzelm@49270
   368
  /* sections */
wenzelm@49270
   369
wenzelm@49270
   370
  def set_section(new_section: String): Options =
wenzelm@49270
   371
    new Options(options, new_section)
wenzelm@49270
   372
wenzelm@49270
   373
  def sections: List[(String, List[Options.Opt])] =
wenzelm@49270
   374
    options.groupBy(_._2.section).toList.map({ case (a, opts) => (a, opts.toList.map(_._2)) })
wenzelm@49270
   375
wenzelm@49270
   376
wenzelm@48456
   377
  /* encode */
wenzelm@48456
   378
wenzelm@48456
   379
  def encode: XML.Body =
wenzelm@48456
   380
  {
wenzelm@48860
   381
    val opts =
wenzelm@56465
   382
      for ((_, opt) <- options.toList; if !opt.unknown)
wenzelm@56465
   383
        yield (opt.pos, (opt.name, (opt.typ.print, opt.value)))
wenzelm@48860
   384
wenzelm@56465
   385
    import XML.Encode.{string => string_, _}
wenzelm@56465
   386
    list(pair(properties, pair(string_, pair(string_, string_))))(opts)
wenzelm@48456
   387
  }
wenzelm@48807
   388
wenzelm@48807
   389
wenzelm@48807
   390
  /* user preferences */
wenzelm@48807
   391
wenzelm@48807
   392
  def load_prefs(): Options =
wenzelm@48807
   393
    if (Options.PREFS.is_file)
wenzelm@48807
   394
      Options.Parser.parse_file(
wenzelm@48807
   395
        Options.prefs_syntax, Options.Parser.prefs_entry, this, Options.PREFS)
wenzelm@48807
   396
    else this
wenzelm@48807
   397
wenzelm@48807
   398
  def save_prefs()
wenzelm@48807
   399
  {
wenzelm@48860
   400
    val defaults = Options.init_defaults()
wenzelm@48807
   401
    val changed =
wenzelm@48807
   402
      (for {
wenzelm@48860
   403
        (name, opt2) <- options.iterator
wenzelm@48860
   404
        opt1 = defaults.options.get(name)
wenzelm@60215
   405
        if opt1.isEmpty || opt1.get.value != opt2.value
wenzelm@48860
   406
      } yield (name, opt2.value, if (opt1.isEmpty) "  (* unknown *)" else "")).toList
wenzelm@48860
   407
wenzelm@48807
   408
    val prefs =
wenzelm@48807
   409
      changed.sortBy(_._1)
wenzelm@48860
   410
        .map({ case (x, y, z) => x + " = " + Outer_Syntax.quote_string(y) + z + "\n" }).mkString
wenzelm@48807
   411
wenzelm@50893
   412
    Isabelle_System.mkdirs(Options.PREFS_DIR)
wenzelm@53336
   413
    File.write_backup(Options.PREFS,
wenzelm@48807
   414
      "(* generated by Isabelle " + Calendar.getInstance.getTime + " *)\n\n" + prefs)
wenzelm@48807
   415
  }
wenzelm@48365
   416
}
wenzelm@49245
   417
wenzelm@49245
   418
wenzelm@49245
   419
class Options_Variable
wenzelm@49245
   420
{
wenzelm@62227
   421
  private var options: Option[Options] = None
wenzelm@62227
   422
wenzelm@62227
   423
  def store(new_options: Options): Unit = synchronized { options = Some(new_options) }
wenzelm@49245
   424
wenzelm@62227
   425
  def value: Options = synchronized {
wenzelm@62227
   426
    options match {
wenzelm@62227
   427
      case Some(opts) => opts
wenzelm@62227
   428
      case None => error("Uninitialized Isabelle system options")
wenzelm@62227
   429
    }
wenzelm@62227
   430
  }
wenzelm@49245
   431
wenzelm@62227
   432
  private def upd(f: Options => Options): Unit = synchronized { options = Some(f(value)) }
wenzelm@62227
   433
wenzelm@62227
   434
  def + (name: String, x: String): Unit = upd(opts => opts + (name, x))
wenzelm@49245
   435
wenzelm@49954
   436
  class Bool_Access
wenzelm@49245
   437
  {
wenzelm@62227
   438
    def apply(name: String): Boolean = value.bool(name)
wenzelm@62227
   439
    def update(name: String, x: Boolean): Unit = upd(opts => opts.bool.update(name, x))
wenzelm@49245
   440
  }
wenzelm@49954
   441
  val bool = new Bool_Access
wenzelm@49245
   442
wenzelm@49954
   443
  class Int_Access
wenzelm@49245
   444
  {
wenzelm@62227
   445
    def apply(name: String): Int = value.int(name)
wenzelm@62227
   446
    def update(name: String, x: Int): Unit = upd(opts => opts.int.update(name, x))
wenzelm@49245
   447
  }
wenzelm@49954
   448
  val int = new Int_Access
wenzelm@49245
   449
wenzelm@49954
   450
  class Real_Access
wenzelm@49245
   451
  {
wenzelm@62227
   452
    def apply(name: String): Double = value.real(name)
wenzelm@62227
   453
    def update(name: String, x: Double): Unit = upd(opts => opts.real.update(name, x))
wenzelm@49245
   454
  }
wenzelm@49954
   455
  val real = new Real_Access
wenzelm@49245
   456
wenzelm@49954
   457
  class String_Access
wenzelm@49245
   458
  {
wenzelm@62227
   459
    def apply(name: String): String = value.string(name)
wenzelm@62227
   460
    def update(name: String, x: String): Unit = upd(opts => opts.string.update(name, x))
wenzelm@49245
   461
  }
wenzelm@49954
   462
  val string = new String_Access
wenzelm@50207
   463
wenzelm@50207
   464
  class Seconds_Access
wenzelm@50207
   465
  {
wenzelm@62227
   466
    def apply(name: String): Time = value.seconds(name)
wenzelm@50207
   467
  }
wenzelm@50207
   468
  val seconds = new Seconds_Access
wenzelm@49245
   469
}