This file is indexed.

/usr/include/deal.II/base/parameter_handler.h is in libdeal.ii-dev 8.1.0-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
// ---------------------------------------------------------------------
// $Id: parameter_handler.h 31584 2013-11-08 05:08:26Z bangerth $
//
// Copyright (C) 1998 - 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------

#ifndef __deal2__parameter_handler_h
#define __deal2__parameter_handler_h


#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/subscriptor.h>
#include <deal.II/base/std_cxx1x/shared_ptr.h>

#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/serialization/split_member.hpp>

#include <map>
#include <vector>
#include <string>
#include <memory>

DEAL_II_NAMESPACE_OPEN

//TODO: Allow long input lines to be broken by appending a backslash character


// public classes; to be declared below
class ParameterHandler;
class MultipleParameterLoop;



// forward declaration
class LogStream;



/**
 * Namespace for a few classes that act as patterns for the ParameterHandler
 * class. These classes implement an interface that checks whether a parameter
 * in an input file matches a certain pattern, such as "being boolean", "an
 * integer value", etc.
 *
 * @ingroup input
 */
namespace Patterns
{

  /**
   * Base class to declare common interface. The purpose of this class is
   * mostly to define the interface of patterns, and to force derived
   * classes to have a <tt>clone</tt> function. It is thus, in the
   * languages of the "Design Patterns" book (Gamma et al.), a "prototype".
   */
  class PatternBase
  {
  public:
    /**
     * Make destructor of this and all derived classes virtual.
     */
    virtual ~PatternBase ();

    /**
     * Return <tt>true</tt> if the given string matches the pattern.
     */
    virtual bool match (const std::string &test_string) const = 0;

    /**
     * Return a string describing the pattern.
     */
    virtual std::string description () const = 0;

    /**
     * Return a pointer to an exact copy of the object. This is necessary
     * since we want to store objects of this type in containers, were we
     * need to copy objects without knowledge of their actual data type (we
     * only have pointers to the base class).
     *
     * Ownership of the objects returned by this function is passed to the
     * caller of this function.
     */
    virtual PatternBase *clone () const = 0;

    /**
     * Determine an estimate for the memory consumption (in bytes) of this
     * object. To avoid unnecessary overhead, we do not force derived
     * classes to provide this function as a virtual overloaded one, but
     * rather try to cast the present object to one of the known derived
     * classes and if that fails then take the size of this base class
     * instead and add 32 byte (this value is arbitrary, it should account
     * for virtual function tables, and some possible data elements). Since
     * there are usually not many thousands of objects of this type around,
     * and since the memory_consumption mechanism is used to find out where
     * memory in the range of many megabytes is, this seems like a
     * reasonable approximation.
     *
     * On the other hand, if you know that your class deviates from this
     * assumption significantly, you can still overload this function.
     */
    virtual std::size_t memory_consumption () const;
  };

  /**
  * Returns pointer to the correct derived class based on description.
  */
  PatternBase *pattern_factory (const std::string &description);

  /**
   * Test for the string being an integer. If bounds are given to the
   * constructor, then the integer given also needs to be within the
   * interval specified by these bounds. Note that unlike common convention
   * in the C++ standard library, both bounds of this interval are
   * inclusive; the reason is that in practice in most cases, one needs
   * closed intervals, but these can only be realized with inclusive bounds
   * for non-integer values. We thus stay consistent by always using closed
   * intervals.
   *
   * If the upper bound given to the constructor is smaller than the lower
   * bound, then the infinite interval is implied, i.e. every integer is
   * allowed.
   *
   * Giving bounds may be useful if for example a value can only be
   * positive and less than a reasonable upper bound (for example the
   * number of refinement steps to be performed), or in many other cases.
   */
  class Integer : public PatternBase
  {
  public:
    /**
     * Minimal integer value. If the numeric_limits class is available use
     * this information to obtain the extremal values, otherwise set it so
     * that this class understands that all values are allowed.
     */
    static const int min_int_value;

    /**
     * Maximal integer value. If the numeric_limits class is available use
     * this information to obtain the extremal values, otherwise set it so
     * that this class understands that all values are allowed.
     */
    static const int max_int_value;

    /**
     * Constructor. Bounds can be specified within which a valid parameter
     * has to be. If the upper bound is smaller than the lower bound, then
     * the infinite interval is meant. The default values are chosen such
     * that no bounds are enforced on parameters.
     */
    Integer (const int lower_bound = min_int_value,
             const int upper_bound = max_int_value);

    /**
     * Return <tt>true</tt> if the string is an integer and its value is
     * within the specified range.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match. If bounds were specified to the constructor, then include
     * them into this description.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static Integer *create (const std::string &description);

  private:
    /**
     * Value of the lower bound. A number that satisfies the @ref match
     * operation of this class must be equal to this value or larger, if
     * the bounds of the interval for a valid range.
     */
    const int lower_bound;

    /**
     * Value of the upper bound. A number that satisfies the @ref match
     * operation of this class must be equal to this value or less, if the
     * bounds of the interval for a valid range.
     */
    const int upper_bound;

    /**
     * Initial part of description
     */
    static const char *description_init;
  };

  /**
   * Test for the string being a <tt>double</tt>. If bounds are given to
   * the constructor, then the integer given also needs to be within the
   * interval specified by these bounds. Note that unlike common convention
   * in the C++ standard library, both bounds of this interval are
   * inclusive; the reason is that in practice in most cases, one needs
   * closed intervals, but these can only be realized with inclusive bounds
   * for non-integer values. We thus stay consistent by always using closed
   * intervals.
   *
   * If the upper bound given to the constructor is smaller than the lower
   * bound, then the infinite interval is implied, i.e. every integer is
   * allowed.
   *
   * Giving bounds may be useful if for example a value can only be
   * positive and less than a reasonable upper bound (for example damping
   * parameters are frequently only reasonable if between zero and one), or
   * in many other cases.
   */
  class Double : public PatternBase
  {
  public:
    /**
     * Minimal double value. If the <tt>std::numeric_limits</tt> class is
     * available use this information to obtain the extremal values,
     * otherwise set it so that this class understands that all values are
     * allowed.
     */
    static const double min_double_value;

    /**
     * Maximal double value. If the numeric_limits class is available use
     * this information to obtain the extremal values, otherwise set it so
     * that this class understands that all values are allowed.
     */
    static const double max_double_value;

    /**
     * Constructor. Bounds can be specified within which a valid parameter
     * has to be. If the upper bound is smaller than the lower bound, then
     * the infinite interval is meant. The default values are chosen such
     * that no bounds are enforced on parameters.
     */
    Double (const double lower_bound = min_double_value,
            const double upper_bound = max_double_value);

    /**
     * Return <tt>true</tt> if the string is a number and its value is
     * within the specified range.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match. If bounds were specified to the constructor, then include
     * them into this description.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static Double *create (const std::string &description);

  private:
    /**
     * Value of the lower bound. A number that satisfies the @ref match
     * operation of this class must be equal to this value or larger, if
     * the bounds of the interval for a valid range.
     */
    const double lower_bound;

    /**
     * Value of the upper bound. A number that satisfies the @ref match
     * operation of this class must be equal to this value or less, if the
     * bounds of the interval for a valid range.
     */
    const double upper_bound;

    /**
     * Initial part of description
     */
    static const char *description_init;
  };

  /**
   * Test for the string being one of a sequence of values given like a
   * regular expression. For example, if the string given to the
   * constructor is <tt>"red|blue|black"</tt>, then the @ref match function
   * returns <tt>true</tt> exactly if the string is either "red" or "blue"
   * or "black". Spaces around the pipe signs do not matter and are
   * eliminated.
   */
  class Selection : public PatternBase
  {
  public:
    /**
     * Constructor. Take the given parameter as the specification of valid
     * strings.
     */
    Selection (const std::string &seq);

    /**
     * Return <tt>true</tt> if the string is an element of the description
     * list passed to the constructor.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match. Here, this is the list of valid strings passed to the
     * constructor.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Determine an estimate for the memory consumption (in bytes) of this
     * object.
     */
    std::size_t memory_consumption () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static Selection *create (const std::string &description);

  private:
    /**
     * List of valid strings as passed to the constructor. We don't make
     * this string constant, as we process it somewhat in the constructor.
     */
    std::string sequence;

    /**
     * Initial part of description
     */
    static const char *description_init;
  };


  /**
   * This pattern matches a list of values separated by commas (or another
   * string), each of which
   * have to match a pattern given to the constructor. With two additional
   * parameters, the number of elements this list has to have can be
   * specified. If none is specified, the list may have zero or more
   * entries.
   */
  class List : public PatternBase
  {
  public:
    /**
     * Maximal integer value. If the numeric_limits class is available use
     * this information to obtain the extremal values, otherwise set it so
     * that this class understands that all values are allowed.
     */
    static const unsigned int max_int_value;

    /**
     * Constructor. Take the given parameter as the specification of valid
     * elements of the list.
     *
     * The three other arguments can be used to denote minimal and maximal
     * allowable lengths of the list, and the string that is used as a
     * separator between elements of the list.
     */
    List (const PatternBase  &base_pattern,
          const unsigned int  min_elements = 0,
          const unsigned int  max_elements = max_int_value,
          const std::string  &separator = ",");

    /**
     * Destructor.
     */
    virtual ~List ();

    /**
     * Return <tt>true</tt> if the
     * string is a comma-separated list of strings each of which match the
     * pattern given to the constructor.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static List *create (const std::string &description);

    /**
     * Determine an estimate for the memory consumption (in bytes) of this
     * object.
     */
    std::size_t memory_consumption () const;

    /** @addtogroup Exceptions
     * @{ */

    /**
     * Exception.
     */
    DeclException2 (ExcInvalidRange,
                    int, int,
                    << "The values " << arg1 << " and " << arg2
                    << " do not form a valid range.");
    //@}
  private:
    /**
     * Copy of the pattern that each element of the list has to satisfy.
     */
    PatternBase *pattern;

    /**
     * Minimum number of elements the list must have.
     */
    const unsigned int min_elements;

    /**
     * Maximum number of elements the list must have.
     */
    const unsigned int max_elements;

    /**
     * Separator between elements of the list.
     */
    const std::string separator;

    /**
     * Initial part of description
     */
    static const char *description_init;
  };


  /**
   * This pattern matches a list of comma-separated values each of which
   * denotes a pair of key and value. Both key and value have to match a
   * pattern given to the constructor. For each entry of the map,
   * parameters have to be entered in the form <code>key: value</code>. In
   * other words, a map is described in the form
   * <code>key1: value1, key2: value2, key3: value3, ...</code>. A constructor
   * argument allows to choose a delimiter between pairs other than the comma.
   *
   * With two additional parameters, the number of elements this list has
   * to have can be specified. If none is specified, the map may have zero
   * or more entries.
   */
  class Map : public PatternBase
  {
  public:
    /**
     * Maximal integer value. If the numeric_limits class is available use
     * this information to obtain the extremal values, otherwise set it so
     * that this class understands that all values are allowed.
     */
    static const unsigned int max_int_value;

    /**
     * Constructor. Take the given parameter as the specification of valid
     * elements of the list.
     *
     * The three other arguments can be used to denote minimal and maximal
     * allowable lengths of the list as well as the separator used to delimit
     * pairs of the map.
     */
    Map (const PatternBase  &key_pattern,
         const PatternBase  &value_pattern,
         const unsigned int  min_elements = 0,
         const unsigned int  max_elements = max_int_value,
         const std::string  &separator = ",");

    /**
     * Destructor.
     */
    virtual ~Map ();

    /**
     * Return <tt>true</tt> if the string is a comma-separated list of
     * strings each of which match the pattern given to the constructor.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static Map *create (const std::string &description);

    /**
     * Determine an estimate for the memory consumption (in bytes) of this
     * object.
     */
    std::size_t memory_consumption () const;

    /** @addtogroup Exceptions
     * @{ */

    /**
     * Exception.
     */
    DeclException2 (ExcInvalidRange,
                    int, int,
                    << "The values " << arg1 << " and " << arg2
                    << " do not form a valid range.");
    //@}
  private:
    /**
     * Copy of the patterns that each key and each value of the map has to
     * satisfy.
     */
    PatternBase *key_pattern;
    PatternBase *value_pattern;

    /**
     * Minimum number of elements the list must have.
     */
    const unsigned int min_elements;

    /**
     * Maximum number of elements the list must have.
     */
    const unsigned int max_elements;

    /**
     * Separator between elements of the list.
     */
    const std::string separator;

    /**
     * Initial part of description
     */
    static const char *description_init;
  };


  /**
   * This class is much like the Selection class, but it allows the input
   * to be a comma-separated list of values which each have to be given in
   * the constructor argument. Alternatively, it could be viewed as a
   * specialization of the List class. For example, if the string to the
   * constructor was <tt>"ucd|gmv|eps"</tt>, then the following would be
   * legal input: <tt>eps</tt>, <tt>gmv</tt>. You may give an arbitrarily
   * long list of values, where there may be as many spaces around commas
   * as you like.  However, commas are not allowed inside the values given
   * to the constructor.
   */
  class MultipleSelection : public PatternBase
  {
  public:
    /**
     * Constructor. Take the given parameter as the specification of valid
     * strings.
     */
    MultipleSelection (const std::string &seq);

    /**
     * Return <tt>true</tt> if the string is an element of the description
     * list passed to the constructor.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match. Here, this is the list of valid strings passed to the
     * constructor.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static MultipleSelection *create (const std::string &description);

    /**
     * Determine an estimate for the memory consumption (in bytes) of this
     * object.
     */
    std::size_t memory_consumption () const;

    /** @addtogroup Exceptions
     * @{ */

    /**
     * Exception.
     */
    DeclException1 (ExcCommasNotAllowed,
                    int,
                    << "A comma was found at position " << arg1
                    << " of your input string, but commas are not allowed here.");
    //@}
  private:
    /**
     * List of valid strings as passed to the constructor. We don't make
     * this string constant, as we process it somewhat in the constructor.
     */
    std::string sequence;

    /**
     * Initial part of description
     */
    static const char *description_init;
  };

  /**
   * Test for the string being either "true" or "false". This is mapped to
   * the Selection class.
   */
  class Bool : public Selection
  {
  public:
    /**
     * Constructor.
     */
    Bool ();

    /**
     * Return a description of the pattern that valid strings are expected
     * to match.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static Bool *create (const std::string &description);

  private:
    /**
     * Initial part of description
     */
    static const char *description_init;
  };

  /**
   * Always returns <tt>true</tt> when testing a string.
   */
  class Anything : public PatternBase
  {
  public:
    /**
     * Constructor. (Allow for at least one non-virtual function in this
     * class, as otherwise sometimes no virtual table is emitted.)
     */
    Anything ();

    /**
     * Return <tt>true</tt> if the string matches its constraints, i.e.
     * always.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match. Here, this is the string <tt>"[Anything]"</tt>.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static Anything *create (const std::string &description);

  private:
    /**
     * Initial part of description
     */
    static const char *description_init;
  };


  /**
   * A pattern that can be used to indicate when a parameter is intended to
   * be the name of a file. By itself, this class does not check whether
   * the string that is given in a parameter file actually corresponds to
   * an existing file (it could, for example, be the name of a file to
   * which you want to write output). Functionally, the class is therefore
   * equivalent to the Anything class. However, it allows to specify the
   * <i>intent</i> of a parameter. The flag given to the constructor also
   * allows to specify whether the file is supposed to be an input or
   * output file.
   *
   * The reason for the existence of this class is to support graphical
   * user interfaces for editing parameter files. These may open a file
   * selection dialog if the filename is supposed to represent an input
   * file.
   */
  class FileName : public PatternBase
  {
  public:
    /**
     * Files can be used for input or output. This can be specified in the
     * constructor by choosing the flag <tt>type</tt>.
     */
    enum FileType {input = 0, output = 1};

    /**
     * Constructor.  The type of the file can be specified by choosing the
     * flag.
     */
    FileName (const FileType type = input);

    /**
     * Return <tt>true</tt> if the string matches its constraints, i.e.
     * always.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match. Here, this is the string <tt>"[Filename]"</tt>.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * file type flag
     */
    FileType  file_type;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static FileName *create (const std::string &description);

  private:
    /**
     * Initial part of description
     */
    static const char *description_init;
  };


  /**
   * A pattern that can be used to indicate when a parameter is intended to
   * be the name of a directory. By itself, this class does not check
   * whether the string that is given in a parameter file actually
   * corresponds to an existing directory. Functionally, the class is
   * therefore equivalent to the Anything class. However, it allows to
   * specify the <i>intent</i> of a parameter.
   *
   * The reason for the existence of this class is to support graphical
   * user interfaces for editing parameter files. These may open a file
   * selection dialog to select or create a directory.
   */
  class DirectoryName : public PatternBase
  {
  public:
    /**
     * Constructor.
     */
    DirectoryName ();

    /**
     * Return <tt>true</tt> if the string matches its constraints, i.e.
     * always.
     */
    virtual bool match (const std::string &test_string) const;

    /**
     * Return a description of the pattern that valid strings are expected
     * to match. Here, this is the string <tt>"[Filename]"</tt>.
     */
    virtual std::string description () const;

    /**
     * Return a copy of the present object, which is newly allocated on the
     * heap. Ownership of that object is transferred to the caller of this
     * function.
     */
    virtual PatternBase *clone () const;

    /**
     * Creates new object if the start of description matches
     * description_init.  Ownership of that object is transferred to the
     * caller of this function.
     */
    static DirectoryName *create (const std::string &description);

  private:
    /**
     * Initial part of description
     */
    static const char *description_init;
  };
}


/**
 *   The ParameterHandler class provides a standard interface to an input
 *   file which provides at run-time for program parameters such as time
 *   step sizes, geometries, right hand sides etc. The input for the
 *   program is given in files, streams or strings in memory using text
 *   like
 *   @code
 *     set Time step size = 0.3
 *     set Geometry       = [0,1]x[0,3]
 *   @endcode
 *   Input may be sorted into subsection trees in order to give the input a
 *   logical structure, and input files may include other files.
 *
 *   The ParameterHandler class is discussed in detail in the @ref step_19
 *   "step-19" example program, and is used in more realistic situations in
 *   step-29, step-33 and step-34.
 *
 *   <h3>Declaring entries</h3>
 *
 *   In order to use the facilities of a ParameterHandler object, one first
 *   has to make known the different entries the input file may or may not
 *   contain. This is done in the following way:
 *
 *   @code
 *     ...
 *     ParameterHandler prm;
 *     prm.declare_entry ("Time step size",
 *                       "0.2",
 *                       Patterns::Double(),
 *                       "Some documentation");
 *     prm.declare_entry ("Geometry",
 *                       "[0,1]x[0,1]",
 *                       Patterns::Anything());
 *     ...
 *   @endcode
 *   Each entry is declared using the function declare_entry(). The first
 *   parameter is the name of the entry (in short: the entry). The second
 *   is the default answer to be taken in case the entry is not specified
 *   in the input file. The third parameter is a regular expression which
 *   the input (and the default answer) has to match.  Several such regular
 *   expressions are defined in Patterns. This parameter can be omitted, in
 *   which case it will default to Patterns::Anything, i.e. a pattern that
 *   matches every input string. The fourth parameter can be used to
 *   document the intent or expected format of an entry; its value is
 *   printed as a comment when writing all entries of a ParameterHandler
 *   object using the print_parameters() function to allow for easier
 *   understanding of a parameter file. It can be omitted as well, in which
 *   case no such documentation will be printed.
 *
 *   Entries may be located in subsections which form a kind of input tree.
 *   For example input parameters for linear solver routines should be
 *   classified in a subsection named <tt>Linear solver</tt> or any other
 *   suitable name. This is accomplished in the following way:
 *   @code
 *     ...
 *       LinEq eq;
 *       eq.declare_parameters (prm);
 *     ...
 *
 *     void LinEq::declare_parameters (ParameterHandler &prm) {
 *       prm.enter_subsection("Linear solver");
 *       {
 *         prm.declare_entry ("Solver",
 *                            "CG",
 *                            Patterns::Selection("CG|GMRES|GaussElim"),
 *                            "Name of a linear solver for the inner iteration");
 *         prm.declare_entry ("Maximum number of iterations",
 *                            "20",
 *                            ParameterHandler::RegularExpressions::Integer());
 *         ...
 *       }
 *       prm.leave_subsection ();
 *     }
 *   @endcode
 *
 *   Subsections may be nested. For example a nonlinear solver may have a
 *   linear solver as member object. Then the function call tree would be
 *   something like (if the class <tt>NonLinEq</tt> has a member variables
 *   <tt>eq</tt> of type <tt>LinEq</tt>):
 *   @code
 *     void NonLinEq::declare_parameters (ParameterHandler &prm) {
 *       prm.enter_subsection ("Nonlinear solver");
 *       {
 *         prm.declare_entry ("Nonlinear method",
 *                            "Newton-Raphson",
 *                            ParameterHandler::RegularExpressions::Anything());
 *         eq.declare_parameters (prm);
 *       }
 *       prm.leave_subsection ();
 *     }
 *   @endcode
 *
 *   For class member functions which declare the different entries we
 *   propose to use the common name <tt>declare_parameters</tt>. In normal
 *   cases this method can be <tt>static</tt> since the entries will not
 *   depend on any previous knowledge. Classes for which entries should
 *   logically be grouped into subsections should declare these subsections
 *   themselves. If a class has two or more member variables of the same
 *   type both of which should have their own parameters, this parent
 *   class' method <tt>declare_parameters</tt> is responsible to group them
 *   into different subsections:
 *   @code
 *     void NonLinEq::declare_parameters (ParameterHandler &prm) {
 *       prm.enter_subsection ("Nonlinear solver");
 *       {
 *         prm.enter_subsection ("Linear solver 1");
 *         {
 *           eq1.declare_parameters (prm);
 *         }
 *         prm.leave_subsection ();
 *
 *         prm.enter_subsection ("Linear solver 2");
 *         {
 *           eq2.declare_parameters (prm);
 *         }
 *         prm.leave_subsection ();
 *       }
 *       prm.leave_subsection ();
 *     }
 *   @endcode
 *
 *
 *   <h3>Input files and special characters</h3>
 *
 *   For the first example above the input file would look like the following:
 *   @code
 *     ...
 *     subsection Nonlinear solver
 *       set Nonlinear method = Gradient
 *       # this is a comment
 *       subsection Linear solver
 *         set Solver                        = CG
 *         set Maxmimum number of iterations = 30
 *       end
 *     end
 *     ...                       # other stuff
 *   @endcode
 *   The words <tt>subsection</tt>, <tt>set</tt> and <tt>end</tt> may be
 *   either written in lowercase or uppercase letters. Leading and trailing
 *   whitespace is removed, multiple whitespace is condensed into only one.
 *   Since the latter applies also to the name of an entry, an entry name
 *   will not be recognized if in the declaration multiple whitespace is
 *   used.
 *
 *   In entry names and values the following characters are not allowed:
 *   <tt>\#</tt>, <tt>{</tt>, <tt>}</tt>, <tt>|</tt>. Their use is reserved
 *   for the MultipleParameterLoop class.
 *
 *   Comments starting with \# are skipped.
 *
 *   We propose to use the following scheme to name entries: start the
 *   first word with a capital letter and use lowercase letters further on.
 *   The same applies to the possible entry values to the right of the
 *   <tt>=</tt> sign.
 *
 *
 *   <h3>Including other input files</h3>
 *
 *   An input file can include other include files using the syntax
 *   @code
 *     ...
 *     include some_other_file.prm
 *     ...
 *   @endcode
 *   The file so referenced is searched for relative to the current
 *   directory (not relative to the directory in which the including
 *   parameter file is located, since this is not known to all three
 *   versions of the read_input() function).
 *
 *
 *   <h3>Reading data from input sources</h3>
 *
 *   In order to read input there are three possibilities: reading from
 *   an <tt>std::istream</tt> object, reading from a file of which the name
 *   is given and reading from a string in memory in which the lines are
 *   separated by <tt>@\n</tt> characters. These possibilities are used as
 *   follows:
 *   @code
 *     ParameterHandler prm;
 *     ...
 *     // declaration of entries
 *     ...
 *     prm.read_input (cin);         // read input from standard in,
 *     // or
 *     prm.read_input ("simulation.in");
 *     // or
 *     char *in = "set Time step size = 0.3 \n ...";
 *     prm.read_input_from_string (in);
 *     ...
 *   @endcode
 *   You can use several sources of input successively. Entries which are
 *   changed more than once will be overwritten every time they are used.
 *
 *   You should not try to declare entries using declare_entry() and
 *   enter_subsection() with as yet unknown subsection names after
 *   using read_input(). The results in this case are unspecified.
 *
 *   If an error occurs upon reading the input, error messages are written
 *   to <tt>std::cerr</tt> and the reader function returns with a return
 *   value of <code>false</code>. This is opposed to almost all other
 *   functions in deal.II, which would normally throw an exception if an
 *   error occurs; this difference in behavior is a relic of the fact that
 *   this class predates deal.II and had previously been written for a
 *   different project.
 *
 *
 *   <h3>Using the %ParameterHandler Graphical User Interface</h3>
 *
 *   An alternative to using the hand-written input files shown above is to
 *   use the graphical user interface (GUI) that accompanies this class.
 *   For this, you first need to write a description of all the parameters,
 *   their default values, patterns and documentation strings into a file
 *   in a format that the GUI can understand; this is done using the
 *   ParameterHandler::print_parameters() function with
 *   ParameterHandler::XML as second argument, as discussed in more detail
 *   below in the <i>Representation of Parameters</i> section. This file
 *   can then be loaded using the executable for the GUI, which should be
 *   located in <code>lib/bin/dealii_parameter_gui</code> of your deal.II
 *   installation, assuming that you have a sufficiently recent version of
 *   the <a href="http://qt.nokia.com/">Qt toolkit</a> installed.
 *
 *   Once loaded, the GUI displays subsections and individual parameters in
 *   tree form (see also the discussion in the <i>Representation of
 *   Parameters</i> section below). Here is a screen shot
 *   with some sub-sections expanded and one parameter selected for
 *   editing:
 *
 *   @image html parameter_gui.png "Parameter GUI"
 *
 *   Using the GUI, you can edit the values of individual parameters and
 *   save the result in the same format as before. It can then be read in
 *   using the ParameterHandler::read_input_from_xml() function.
 *
 *
 *   <h3>Getting entry values out of a %ParameterHandler object</h3>
 *
 *   Each class gets its data out of a ParameterHandler object by
 *   calling the get()  member functions like this:
 *   @code
 *      void NonLinEq::get_parameters (ParameterHandler &prm) {
 *       prm.enter_subsection ("Nonlinear solver");
 *       std::string method = prm.get ("Nonlinear method");
 *       eq.get_parameters (prm);
 *       prm.leave_subsection ();
 *     }
 *   @endcode
 *   get() returns the value of the given entry. If the entry was not
 *   specified in the input source(s), the default value is returned. You
 *   have to enter and leave subsections exactly as you did when declaring
 *   subsection. You may chose the order in which to transverse the
 *   subsection tree.
 *
 *   It is guaranteed that only entries matching the given regular
 *   expression are returned, i.e. an input entry value which does not
 *   match the regular expression is not stored.
 *
 *   You can use get() to retrieve the parameter in text form,
 *   get_integer() to get an integer or get_double() to get a double. You
 *   can also use get_bool(). It will cause an internal error if the string
 *   could not be converted to an integer, double or a bool. This should,
 *   though, not happen if you correctly specified the regular expression
 *   for this entry; you should not try to get out an integer or a double
 *   from an entry for which no according regular expression was set. The
 *   internal error is raised through the Assert() macro family which only
 *   works in debug mode.
 *
 *   If you want to print out all user selectable features, use the
 *   print_parameters() function. It is generally a good idea to print all
 *   parameters at the beginning of a log file, since this way input and
 *   output are together in one file which makes matching at a later time
 *   easier. Additionally, the function also print those entries which have
 *   not been modified in the input file und are thus set to default
 *   values; since default values may change in the process of program
 *   development, you cannot know the values of parameters not specified in
 *   the input file.
 *
 *
 *   <h3>Style guide for data retrieval</h3>
 *
 *   We propose that every class which gets data out of a ParameterHandler
 *   object provides a function named <tt>get_parameters</tt>. This should
 *   be declared <tt>virtual</tt>. <tt>get_parameters</tt> functions in
 *   derived classes should call the <tt>BaseClass::get_parameters</tt>
 *   function.
 *
 *
 *   <h3>Experience with large parameter lists</h3>
 *
 *   Experience has shown that in programs defining larger numbers of
 *   parameters (more than, say, fifty) it is advantageous to define an
 *   additional class holding these parameters. This class is more like a
 *   C-style structure, having a large number of variables, usually public.
 *   It then has at least two functions, which declare and parse the
 *   parameters. In the main program, the main class has an object of this
 *   parameter class and delegates declaration and parsing of parameters to
 *   this object.
 *
 *   The advantage of this approach is that you can keep out the technical
 *   details (declaration and parsing) out of the main class and
 *   additionally don't clutter up your main class with dozens or more
 *   variables denoting the parameters.
 *
 *
 *
 *   <h3>Worked Example</h3>
 *
 *   This is the code:
 *   @code
 *     #include <iostream>
 *     #include "../include/parameter_handler.h"
 *
 *     using namespace dealii;
 *
 *     class LinEq {
 *       public:
 *         static void declare_parameters (ParameterHandler &prm);
 *         void get_parameters (ParameterHandler &prm);
 *       private:
 *         std::string Method;
 *         int    MaxIterations;
 *     };
 *
 *
 *     class Problem {
 *       private:
 *         LinEq eq1, eq2;
 *         std::string Matrix1, Matrix2;
 *         std::string outfile;
 *       public:
 *         static void declare_parameters (ParameterHandler &prm);
 *         void get_parameters (ParameterHandler &prm);
 *     };
 *
 *
 *
 *     void LinEq::declare_parameters (ParameterHandler &prm) {
 *                                        // declare parameters for the linear
 *                                        // solver in a subsection
 *       prm.enter_subsection ("Linear solver");
 *       prm.declare_entry ("Solver",
 *                          "CG",
 *                          Patterns::Selection("CG|BiCGStab|GMRES"),
 *                          "Name of a linear solver for the inner iteration");
 *       prm.declare_entry ("Maximum number of iterations",
 *                          "20",
 *                          Patterns::Integer());
 *       prm.leave_subsection ();
 *     }
 *
 *
 *     void LinEq::get_parameters (ParameterHandler &prm) {
 *       prm.enter_subsection ("Linear solver");
 *       Method        = prm.get ("Solver");
 *       MaxIterations = prm.get_integer ("Maximum number of iterations");
 *       prm.leave_subsection ();
 *       std::cout << "  LinEq: Method=" << Method << ", MaxIterations=" << MaxIterations << std::endl;
 *     }
 *
 *
 *
 *     void Problem::declare_parameters (ParameterHandler &prm) {
 *                                        // first some global parameter entries
 *       prm.declare_entry ("Output file",
 *                          "out",
 *                          Patterns::Anything(),
 *                          "Name of the output file, either relative to the present"
 *                          "path or absolute");
 *       prm.declare_entry ("Equation 1",
 *                          "Laplace",
 *                          Patterns::Anything(),
 *                          "String identifying the equation we want to solve");
 *       prm.declare_entry ("Equation 2",
 *                          "Elasticity",
 *                          Patterns::Anything());
 *
 *                                        // declare parameters for the
 *                                        // first equation
 *       prm.enter_subsection ("Equation 1");
 *       prm.declare_entry ("Matrix type",
 *                          "Sparse",
 *                          Patterns::Selection("Full|Sparse|Diagonal"),
 *                          "Type of the matrix to be used, either full,"
 *                          "sparse, or diagonal");
 *       LinEq::declare_parameters (prm);  // for eq1
 *       prm.leave_subsection ();
 *
 *                                        // declare parameters for the
 *                                        // second equation
 *       prm.enter_subsection ("Equation 2");
 *       prm.declare_entry ("Matrix type",
 *                          "Sparse",
 *                          Patterns::Selection("Full|Sparse|Diagonal"));
 *       LinEq::declare_parameters (prm);  // for eq2
 *       prm.leave_subsection ();
 *     }
 *
 *
 *     void Problem::get_parameters (ParameterHandler &prm) {
 *                                        // entries of the problem class
 *       outfile = prm.get ("Output file");
 *
 *       std::string equation1 = prm.get ("Equation 1"),
 *              equation2 = prm.get ("Equation 2");
 *
 *                                        // get parameters for the
 *                                        // first equation
 *       prm.enter_subsection ("Equation 1");
 *       Matrix1 = prm.get ("Matrix type");
 *       eq1.get_parameters (prm);         // for eq1
 *       prm.leave_subsection ();
 *
 *                                        // get parameters for the
 *                                        // second equation
 *       prm.enter_subsection ("Equation 2");
 *       Matrix2 = prm.get ("Matrix type");
 *       eq2.get_parameters (prm);         // for eq2
 *       prm.leave_subsection ();
 *
 *       std::cout << "  Problem: outfile=" << outfile << std::endl
 *            << "           eq1="     << equation1 << ", eq2=" << equation2 << std::endl
 *            << "           Matrix1=" << Matrix1 << ", Matrix2=" << Matrix2 << std::endl;
 *     }
 *
 *
 *
 *
 *     void main () {
 *       ParameterHandler prm;
 *       Problem p;
 *
 *       p.declare_parameters (prm);
 *
 *                                        // read input from "prmtest.prm"; giving
 *                                        // argv[1] would also be a good idea
 *       prm.read_input ("prmtest.prm");
 *
 *                                        // print parameters to std::cout as ASCII text
 *       std::cout << std::endl << std::endl;
 *       prm.print_parameters (std::cout, ParameterHandler::Text);
 *
 *                                        // get parameters into the program
 *       std::cout << std::endl << std::endl
 *                 << "Getting parameters:" << std::endl;
 *       p.get_parameters (prm);
 *
 *                                        // now run the program with these
 *                                        // input parameters
 *       p.do_something ();
 *     }
 *   @endcode
 *
 *
 *   This is the input file (named "prmtest.prm"):
 *   @code
 *                                 # first declare the types of equations
 *     set Equation 1 = Poisson
 *     set Equation 2 = Navier-Stokes
 *
 *     subsection Equation 1
 *       set Matrix type = Sparse
 *       subsection Linear solver    # parameters for linear solver 1
 *         set Solver                       = Gauss-Seidel
 *         set Maximum number of iterations = 40
 *       end
 *     end
 *
 *     subsection Equation 2
 *       set Matrix type = Full
 *       subsection Linear solver
 *         set Solver                       = CG
 *         set Maximum number of iterations = 100
 *       end
 *     end
 *   @endcode
 *
 *   And here is the output of the program:
 *   @code
 *     Line 8:
 *         The entry value
 *             Gauss-Seidel
 *         for the entry named
 *             Solver
 *         does not match the given regular expression
 *             CG|BiCGStab|GMRES
 *
 *
 *     Listing of Parameters
 *     ---------------------
 *       set Equation 1  = Poisson  # Laplace
 *       set Equation 2  = Navier-Stokes  # Elasticity
 *       set Output file = out
 *       subsection Equation 1
 *         set Matrix type = Sparse  # Sparse
 *         subsection Linear solver
 *           set Maximum number of iterations = 40  # 20
 *           set Solver                       = CG
 *         end
 *       end
 *       subsection Equation 2
 *         set Matrix type = Full  # Sparse
 *         subsection Linear solver
 *           set Maximum number of iterations = 100  # 20
 *           set Solver                       = CG   # CG
 *         end
 *       end
 *
 *
 *     Getting parameters:
 *       LinEq: Method=CG, MaxIterations=40
 *       LinEq: Method=CG, MaxIterations=100
 *       Problem: outfile=out
 *                eq1=Poisson, eq2=Navier-Stokes
 *                Matrix1=Sparse, Matrix2=Full
 *   @endcode
 *
 *
 *
 *   <h3>Representation of Parameters</h3>
 *
 *   Here is some more internal information about the repesentation of
 *   parameters:
 *
 *   Logically, parameters and the nested sections they are arranged in can be
 *   thought of as a hierarchical directory structure, or a tree. Take, for
 *   example, the following code declaring a set of parameters and sections
 *   they live in:
 *   @code
 *     ParameterHandler prm;
 *
 *     prm.declare_entry ("Maximal number of iterations",
 *                        "10",
 *                        Patterns::Integer (1, 1000),
 *                        "A parameter that describes the maximal number of "
 *                        "iterations the CG method is to take before giving "
 *                        "up on a matrix.");
 *     prm.enter_subsection ("Preconditioner");
 *     {
 *       prm.declare_entry ("Kind",
 *                          "SSOR",
 *                          Patterns::Selection ("SSOR|Jacobi"),
 *                          "A string that describes the kind of preconditioner "
 *                          "to use.");
 *       prm.declare_entry ("Relaxation factor",
 *                          "1.0",
 *                          Patterns::Double (0, 1),
 *                          "The numerical value (between zero and one) for the "
 *                          "relaxation factor to use in the preconditioner.");
 *     }
 *     prm.leave_subsection ();
 *   @endcode
 *
 *   We can think of the parameters so arranged as a file system in which
 *   every parameter is a directory. The name of this directory is the name
 *   of the parameter, and in this directory lie files that describe the
 *   parameter. These files are:
 *   - <code>value</code>: The content of this file is the current value of this
 *     parameter; initially, the content of the file equals the default value of
 *     the parameter.
 *   - <code>default_value</code>: The content of this file is the default value
 *     value of the parameter.
 *   - <code>pattern</code>: A textual representation of the pattern that describes
 *     the parameter's possible values.
 *   - <code>pattern_index</code>: A number that indexes the Patterns::PatternBase
 *     object that is used to describe the parameter.
 *   - <code>documentation</code>: The content of this file is the documentation
 *     given for a parameter as the last argument of the
 *     ParameterHandler::declare_entry call.
 *   With the exception of the <code>value</code> file, the contents of files
 *   are never changed after declaration of a parameter.
 *
 *   Alternatively, a directory in this file system may not have a file
 *   called <code>value</code> in it. In that case, the directory
 *   represents a subsection as declared above, and the directory's name
 *   will correspond to the name of the subsection. It will then have no
 *   files in it at all, but it may have further directories in it: some of
 *   these directories will be parameters (indicates by the presence of
 *   files) or further nested subsections.
 *
 *   Given this explanation, the code above will lead to a hierarchical
 *   representation of data that looks like this (the content of files is
 *   indicated at the right in a different font):
 *     @image html parameter_handler.png
 *   Once parameters have been read in, the contents of the <code>value</code>
 *   "files" may be different while the other files remain untouched.
 *
 *   Using the ParameterHandler::print_parameters() function with
 *   ParameterHandler::XML as second argument, we can get a complete
 *   representation of this data structure in XML. It will look like
 *   this:
 *   @code
 *   <?xml version="1.0" encoding="utf-8"?>
 *   <ParameterHandler>
 *     <Maximal_20number_20of_20iterations>
 *       <value>10</value>
 *       <default_value>10</default_value>
 *       <documentation>A parameter that describes the maximal number of iterations the CG method is to take before giving up on a matrix.</documentation>
 *       <pattern>0</pattern>
 *       <pattern_description>[Integer range 1...1000 (inclusive)]</pattern_description>
 *     </Maximal_20number_20of_20iterations>
 *     <Preconditioner>
 *       <Kind><value>SSOR</value>
 *         <default_value>SSOR</default_value>
 *         <documentation>A string that describes the kind of preconditioner to use.</documentation>
 *         <pattern>1</pattern>
 *         <pattern_description>SSOR|Jacobi</pattern_description>
 *       </Kind>
 *       <Relaxation_20factor>
 *         <value>1.0</value>
 *         <default_value>1.0</default_value>
 *         <documentation>The numerical value (between zero and one) for the relaxation factor to use in the preconditioner.</documentation>
 *         <pattern>2</pattern>
 *         <pattern_description>[Floating point range 0...1 (inclusive)]</pattern_description>
 *       </Relaxation_20factor>
 *     </Preconditioner>
 *   <ParameterHandler>
 *   @endcode
 *   This representation closely resembles the directory/file structure
 *   discussed above. The only difference is that directory and file
 *   names are mangled: since they should only contain letters and
 *   numbers, every character in their names that is not a letter or number
 *   is replaced
 *   by an underscore followed by its two-digit hexadecimal representation.
 *   In addition, the special name "value" is mangled when used as the
 *   name of a parameter, given that this name is also used to name
 *   special files in the hierarchy structure.
 *   Finally, the entire tree is wrapped into a tag
 *   <code>%ParameterHandler</code> to satisfy the XML requirement that there
 *   be only a single top-level construct in each file.
 *
 *   The tree structure (and its XML representation) is what the graphical
 *   user interface (see above) uses to represent parameters like a
 *   directory/file collection.
 *
 *
 *   @ingroup input
 *   @author Wolfgang Bangerth, October 1997, revised February 1998, 2010, 2011
 */
class ParameterHandler : public Subscriptor
{
private:
  /**
   * Inhibit automatic CopyConstructor.
   */
  ParameterHandler (const ParameterHandler &);

  /**
   * Inhibit automatic assignment operator.
   */
  ParameterHandler &operator= (const ParameterHandler &);

public:
  /**
   * List of possible output formats.
   *
   * The formats down the list with prefix <em>Short</em> and bit 6 and 7
   * set reproduce the old behavior of not writing comments or original
   * values to the files.
   */
  enum OutputStyle
  {
    /**
     * Write human readable output suitable to be read by ParameterHandler
     * again.
     */
    Text = 1,
    /**
     * Write parameters as a LaTeX table.
     */
    LaTeX = 2,
    /**
     * Write out declared parameters with description and possible values.
     */
    Description = 3,

    /**
     * Write out everything as an <a
     * href="http://en.wikipedia.org/wiki/XML">XML</a> file.
     *
     * See the general documentation of this class for an example of
     * output.
     */
    XML = 4,

    /**
     * Write out everything as a <a
     * href="http://en.wikipedia.org/wiki/JSON">JSON</a> file.
     */
    JSON = 5,

    /**
     * Write input for ParameterHandler without comments or changed default
     * values.
     */
    ShortText = 193
  };



  /**
   * Constructor.
   */
  ParameterHandler ();

  /**
   * Destructor. Declare this only to have a virtual destructor, which is
   * safer as we have virtual functions.  It actually does nothing
   * spectacular.
   */
  virtual ~ParameterHandler ();

  /**
   * Read input from a stream until the stream returns the <tt>eof</tt> condition
   * or error. The second argument can be used to denote the name of the file
   * (if that's what the input stream represents) we are reading from; this
   * is only used when creating output for error messages.
   *
   * Return whether the read was successful.
   */
  virtual bool read_input (std::istream &input,
                           const std::string &filename = "input file");

  /**
   * Read input from a file the name of which is given. The PathSearch
   * class "PARAMETERS" is used to find the file.
   *
   * Return whether the read was successful.
   *
   * Unless <tt>optional</tt> is <tt>true</tt>, this function will
   * automatically generate the requested file with default values if the
   * file did not exist. This file will not contain additional comments if
   * <tt>write_stripped_file</tt> is <tt>true</tt>.
   */
  virtual bool read_input (const std::string &filename,
                           const bool optional = false,
                           const bool write_stripped_file = false);

  /**
   * Read input from a string in memory. The lines in memory have to be
   * separated by <tt>@\n</tt> characters.
   *
   * Return whether the read was successful.
   */
  virtual bool read_input_from_string (const char *s);

  /**
   * Read a parameter file in XML format. This could be from a file
   * originally written by the print_parameters() function using the XML
   * output style and then modified by hand as necessary; or from a file
   * written using this method and then modified by the graphical parameter
   * GUI (see the general documentation of this class).
   *
   * Return whether the read was successful.
   */
  virtual bool read_input_from_xml (std::istream &input);

  /**
   * Clear all contents.
   */
  void clear ();


  /**
   * Declare a new entry with name <tt>entry</tt>, default and for which
   * any input has to match the <tt>pattern</tt> (default: any pattern).
   *
   * The last parameter defaulting to an empty string is used to add a
   * documenting text to each entry which will be printed as a comment when
   * this class is asked to write out all declarations to a stream using
   * the print_parameters() function.
   *
   * The function generates an exception of type ExcValueDoesNotMatchPattern
   * if the default value doesn't match the given pattern, using the C++
   * throw mechanism. However, this exception is only generated <i>after</i>
   * the entry has been created; if you have code where no sensible default
   * value for a parameter is possible, you can then catch and ignore this
   * exception.
   *
   * @note An entry can be declared more than once without
   * generating an error, for example to override an earlier default value.
   */
  void declare_entry (const std::string           &entry,
                      const std::string           &default_value,
                      const Patterns::PatternBase &pattern = Patterns::Anything(),
                      const std::string           &documentation = std::string());

  /**
   * Enter a subsection; if not yet existent, declare it.
   */
  void enter_subsection (const std::string &subsection);

  /**
   * Leave present subsection. Return <tt>false</tt> if there is no
   * subsection to leave; <tt>true</tt> otherwise.
   */
  bool leave_subsection ();

  /**
   * Return value of entry <tt>entry_string</tt>.  If the entry was
   * changed, then the changed value is returned, otherwise the default
   * value. If the value of an undeclared entry is required, an exception
   * will be thrown.
   */
  std::string get (const std::string &entry_string) const;

  /**
   * Return value of entry <tt>entry_string</tt> as <tt>long int</tt>. (A
   * long int is chosen so that even very large unsigned values can be
   * returned by this function).
   */
  long int       get_integer (const std::string &entry_string) const;

  /**
   * Return value of entry <tt>entry_name</tt> as <tt>double</tt>.
   */
  double         get_double (const std::string &entry_name) const;

  /**
   * Return value of entry <tt>entry_name</tt> as <tt>bool</tt>. The entry
   * may be "true" or "yes" for <tt>true</tt>, "false" or "no" for
   * <tt>false</tt> respectively.
   */
  bool           get_bool (const std::string &entry_name) const;

  /**
   * Change the value presently stored for <tt>entry_name</tt> to the one
   * given in the second argument.
   *
   * The parameter must already exist in the present subsection.
   *
   * The function throws an exception of type ExcValueDoesNotMatchPattern
   * if the new value does not conform to the pattern for this entry.
   */
  void           set (const std::string &entry_name,
                      const std::string &new_value);

  /**
   * Same as above, but an overload where the second argument is a
   * character pointer. This is necessary, since otherwise the call to
   * <tt>set("abc","def")</code> will be mapped to the function taking one
   * string and a bool as arguments, which is certainly not what is most
   * often intended.
   *
   * The function throws an exception of type ExcValueDoesNotMatchPattern
   * if the new value does not conform to the pattern for this entry.
   */
  void           set (const std::string &entry_name,
                      const char        *new_value);

  /**
   * Change the value presently stored for <tt>entry_name</tt> to the one
   * given in the second argument.
   *
   * The parameter must already exist in the present subsection.
   *
   * The function throws an exception of type ExcValueDoesNotMatchPattern
   * if the new value does not conform to the pattern for this entry.
   */
  void           set (const std::string &entry_name,
                      const long int    &new_value);

  /**
   * Change the value presently stored for <tt>entry_name</tt> to the one
   * given in the second argument.
   *
   * The parameter must already exist in the present subsection.
   *
   * For internal purposes, the new value needs to be converted to a
   * string. This is done using 16 digits of accuracy, so the set value and
   * the one you can get back out using get_double() may differ in the 16th
   * digit.
   *
   * The function throws an exception of type ExcValueDoesNotMatchPattern
   * if the new value does not conform to the pattern for this entry.
   */
  void           set (const std::string &entry_name,
                      const double      &new_value);

  /**
   * Change the value presently stored for <tt>entry_name</tt> to the one
   * given in the second argument.
   *
   * The parameter must already exist in the present subsection.
   *
   * The function throws an exception of type ExcValueDoesNotMatchPattern
   * if the new value does not conform to the pattern for this entry.
   */
  void           set (const std::string &entry_name,
                      const bool        &new_value);


  /**
   * Print all parameters with the given style to <tt>out</tt>. Presently
   * only <tt>Text</tt> and <tt>LaTeX</tt> are implemented.
   *
   * In <tt>Text</tt> format, the output is formatted in such a way that it
   * is possible to use it for later input again. This is most useful to
   * record the parameters for a specific run, since if you output the
   * parameters using this function into a log file, you can always recover
   * the results by simply copying the output to your input file.
   *
   * Besides the name and value of each entry, the output also contains the
   * default value of entries if it is different from the actual value, as
   * well as the documenting string given to the declare_entry() function
   * if available.
   *
   * In <tt>Text</tt> format, the output contains the same information but
   * in a format so that the resulting file can be input into a latex
   * document such as a manual for the code for which this object handles
   * run-time parameters. The various sections of parameters are then
   * represented by latex section and subsection commands as well as by
   * nested enumerations.
   *
   * In addition, all parameter names are listed with <code>@\index</code>
   * statements in two indices called <code>prmindex</code> (where the name
   * of each parameter is listed in the index) and
   * <code>prmindexfull</code> where parameter names are listed sorted by
   * the section in which they exist. By default, the LaTeX program ignores
   * these <code>@\index</code> commands, but they can be used to generate
   * an index by using the following commands in the preamble of the latex
   * file:
   * @code
   * \usepackage{imakeidx}
   * \makeindex[name=prmindex, title=Index of run-time parameter entries]
   * \makeindex[name=prmindexfull, title=Index of run-time parameters with section names]
   * @endcode
   * and at the end of the file this:
   * @code
   * \printindex[prmindex]
   * \printindex[prmindexfull]
   * @endcode
   */
  std::ostream &print_parameters (std::ostream      &out,
                                  const OutputStyle  style);

  /**
   * Print out the parameters of the present subsection as given by the
   * <tt>subsection_path</tt> member variable. This variable is controlled
   * by entering and leaving subsections through the enter_subsection() and
   * leave_subsection() functions.
   *
   * In most cases, you will not want to use this function directly, but
   * have it called recursively by the previous function.
   */
  void print_parameters_section (std::ostream       &out,
                                 const OutputStyle   style,
                                 const unsigned int  indent_level);

  /**
   * Print parameters to a logstream. This function allows to print all
   * parameters into a log-file. Sections will be indented in the usual
   * log-file style.
   */
  void log_parameters (LogStream &out);

  /**
   * Log parameters in the present subsection. The subsection is determined
   * by the <tt>subsection_path</tt> member variable. This variable is
   * controlled by entering and leaving subsections through the
   * enter_subsection() and leave_subsection() functions.
   *
   * In most cases, you will not want to use this function directly, but
   * have it called recursively by the previous function.
   */
  void log_parameters_section (LogStream &out);

  /**
   * Determine an estimate for the memory consumption (in bytes) of this
   * object.
   */
  std::size_t memory_consumption () const;

  /**
   * Write the data of this object to a stream for the purpose of
   * serialization.
   */
  template <class Archive>
  void save (Archive &ar, const unsigned int version) const;

  /**
   * Read the data of this object from a stream for the purpose of
   * serialization.
   */
  template <class Archive>
  void load (Archive &ar, const unsigned int version);

  BOOST_SERIALIZATION_SPLIT_MEMBER()

  /**
   * Test for equality.
   */
  bool operator == (const ParameterHandler &prm2)  const;

  /** @addtogroup Exceptions
   * @{ */

  /**
   * Exception
   */
  DeclException1 (ExcEntryAlreadyExists,
                  std::string,
                  << "The following entry already exists: " << arg1);
  /**
   * Exception
   */
  DeclException2 (ExcValueDoesNotMatchPattern,
                  std::string, std::string,
                  << "The string <" << arg1
                  << "> does not match the given pattern <" << arg2 << ">");
  /**
   * Exception
   */
  DeclException0 (ExcAlreadyAtTopLevel);
  /**
   * Exception
   */
  DeclException1 (ExcEntryUndeclared,
                  std::string,
                  << "You can't ask for entry <" << arg1 << "> you have not yet declared");
  /**
   * Exception
   */
  DeclException1 (ExcConversionError,
                  std::string,
                  << "Error when trying to convert the following string: " << arg1);
  //@}
private:
  /**
   * The separator used when accessing elements of a path into the
   * parameter tree.
   */
  static const char path_separator = '.';

  /**
   * The complete tree of sections and entries. See the general
   * documentation of this class for a description how data is stored in
   * this variable.
   *
   * The variable is a pointer so that we can use an incomplete type,
   * rather than having to include all of the property_tree stuff from
   * boost. This works around a problem with gcc 4.5.
   */
  std::auto_ptr<boost::property_tree::ptree> entries;

  /**
   * A list of patterns that are used to describe the parameters of this
   * object. The are indexed by nodes in the property tree.
   */
  std::vector<std_cxx1x::shared_ptr<const Patterns::PatternBase> > patterns;

  /**
   * Mangle a string so that it doesn't contain any special characters or
   * spaces.
   */
  static std::string mangle (const std::string &s);

  /**
   * Unmangle a string into its original form.
   */
  static std::string demangle (const std::string &s);

  /**
   * Return whether a given node is a parameter node or a subsection node.
   */
  static bool is_parameter_node (const boost::property_tree::ptree &);

  /**
   * Path of presently selected subsections; empty list means top level
   */
  std::vector<std::string> subsection_path;

  /**
   * Return the string that identifies the current path into the property
   * tree. This is only a path, i.e. it is not terminated by the
   * path_separator character.
   */
  std::string get_current_path () const;

  /**
   * Given the name of an entry as argument, the function computes a full
   * path into the parameter tree using the current subsection.
   */
  std::string get_current_full_path (const std::string &name) const;

  /**
   * Scan one line of input. <tt>input_filename</tt> and <tt>lineno</tt>
   * are the name of the input file and the current number of the line
   * presently scanned (for the logs if there are messages). Return
   * <tt>false</tt> if line contained stuff that could not be understood,
   * the uppermost subsection was to be left by an <tt>END</tt> or
   * <tt>end</tt> statement, a value for a non-declared entry was given or
   * the entry value did not match the regular expression. <tt>true</tt>
   * otherwise.
   *
   * The function modifies its argument, but also takes it by value, so the
   * caller's variable is not changed.
   */
  bool scan_line (std::string         line,
                  const std::string  &input_filename,
                  const unsigned int  lineno);

  friend class MultipleParameterLoop;
};



/**
 *   The class MultipleParameterLoop offers an easy possibility to test
 *   several parameter sets during one run of the program. For this it uses
 *   the ParameterHandler class to read in data in a standardized form,
 *   searches for variant entry values and performs a loop over all
 *   combinations of parameters.
 *
 *   Variant entry values are given like this:
 *   @verbatim
 *     set Time step size = { 0.1 | 0.2 | 0.3 }
 *   @endverbatim
 *   The loop will then perform three runs of the program, one for each
 *   value of <tt>Time step size</tt>, while all other parameters are as
 *   specified or with their default value. If there are several variant
 *   entry values in the input, a loop is performed for each combination of
 *   variant values:
 *   @verbatim
 *     set Time step size = { 0.1 | 0.2 }
 *     set Solver         = { CG  | GMRES }
 *   @endverbatim
 *   will result in four runs of the programs, with time step 0.1 and 0.2
 *   for each of the two solvers.
 *
 *   In addition to variant entries, this class also supports <i>array
 *   entries</i> that look like this:
 *   @verbatim
 *     set Output file = ofile.{{ 1 | 2 | 3 | 4 }}
 *   @endverbatim
 *   This indicates that if there are variant entries producing a total of
 *   four different runs, then we will write their results to the files
 *   <tt>ofile.1</tt>, <tt>ofile.2</tt>, <tt>ofile.3</tt> and
 *   <tt>ofile.4</tt>, respectively. Array entries do not generate multiple
 *   runs of the main loop themselves, but if there are variant entries,
 *   then in the <i>n</i>th run of the main loop, also the <i>n</i>th value
 *   of an array is returned.
 *
 *   Since the different variants are constructed in the order of
 *   declaration, not in the order in which the variant entries appear in
 *   the input file, it may be difficult to guess the mapping between the
 *   different variants and the appropriate entry in an array. You will
 *   have to check the order of declaration, or use only one variant entry.
 *
 *   It is guaranteed that only selections which match the regular
 *   expression (pattern) given upon declaration of an entry are given back
 *   to the program. If a variant value does not match the regular
 *   expression, the default value is stored and an error is issued. Before
 *   the first run of the loop, all possible values are checked for their
 *   conformance, so that the error is issued at the very beginning of the
 *   program.
 *
 *
 *   <h3>Usage</h3>
 *
 *   The usage of this class is similar to the ParameterHandler class.
 *   First the entries and subsections have to be declared, then a loop is
 *   performed in which the different parameter sets are set, a new
 *   instance of a user class is created which is then called. Taking the
 *   classes of the example for the ParameterHandler class, the extended
 *   program would look like this:
 *   @code
 *     class HelperClass : public MultipleParameterLoop::UserClass {
 *       public:
 *         HelperClass ();
 *
 *         virtual void create_new (const unsigned int run_no);
 *         virtual void declare_parameters (ParameterHandler &prm);
 *         virtual void run (ParameterHandler &prm);
 *       private:
 *         Problem *p;
 *     };
 *
 *
 *     HelperClass::HelperClass () : p(0) {}
 *
 *
 *     void HelperClass::create_new (const unsigned int run_no) {
 *       if (p) delete p;
 *       p = new Problem;
 *     }
 *
 *
 *     void HelperClass::declare_parameters (ParameterHandler &prm) {
 *                                         // entries of the problem class
 *                                 // note: must be static member!
 *       Problem::declare_parameters (prm);
 *     }
 *
 *
 *     void HelperClass::run (ParameterHandler &prm) {
 *       p->get_parameters (prm);
 *       p->do_useful_work ();
 *     }
 *
 *
 *
 *     void main () {
 *       class MultipleParameterLoop prm;
 *       HelperClass h;
 *
 *       h.declare_parameters (prm);
 *       prm.read_input ("prmtest.prm");
 *       prm.loop (h);
 *     }
 *   @endcode
 *
 *   As can be seen, first a new helper class has to be set up. This must
 *   contain a virtual constructor for a problem class. You can also derive
 *   your problem class from MultipleParameterLoop::UserClass and let
 *   <tt>create_new</tt> clear all member variables. If you have access to
 *   all inherited member variables in some way this is the recommended
 *   procedure. A third possibility is to use multiple inheritance and
 *   derive a helper class from both the MultipleParameterLoop::UserClass
 *   and the problem class. In any case, <tt>create_new</tt> has to provide
 *   a clean problem object which is the problem in the second and third
 *   possibility.
 *
 *   The derived class also has to provide for member functions which
 *   declare the entries and which run the program. Running the program
 *   includes getting the parameters out of the ParameterHandler object.
 *
 *   After defining an object of this helper class and an object of the
 *   MultipleParameterLoop class, the entries have to be declared in the
 *   same way as for the ParameterHandler class. Then the input has to be
 *   read. Finally the loop is called. This executes the following steps:
 *   @code
 *     for (each combination)
 *       {
 *         UserObject.create_new (run_no);
 *
 *         // set parameters for this run
 *
 *         UserObject.run (*this);
 *       }
 *   @endcode
 *   <tt>UserObject</tt> is the parameter to the <tt>loop</tt> function.
 *   <tt>create_new</tt> is given the number of the run (starting from one)
  *   to enable naming output files differently for each run.
 *
 *
 *   <h3>Syntax for variant and array entry values</h3>
 *
 *   Variant values are specified like <tt>prefix{ v1 | v2 | v3 | ... }postfix</tt>. Whitespace
 *   to the right of the opening brace <tt>{</tt> is ignored as well as to the left of the
 *   closing brace <tt>}</tt> while whitespace on the respectively other side is not ignored.
 *   Whitespace around the mid symbols <tt>|</tt> is also ignored. The empty selection
 *   <tt>prefix{ v1 | }postfix</tt> is also allowed and produces the strings <tt>prefixv1postfix</tt> and
 *   <tt>prefixpostfix</tt>.
 *
 *   The syntax for array values is equal, apart from the double braces:
 *   <tt>prefix{{ v1 | v2 | v3 }}postfix</tt>.
 *
 *
 *   <h3>Worked example</h3>
 *
 *   Given the above extensions to the example program for the
 *   ParameterHandler and the following input file
 *   @verbatim
 *     set Equation 1 = Poisson
 *     set Equation 2 = Navier-Stokes
 *     set Output file= results.{{ 1 | 2 | 3 | 4 | 5 | 6 }}
 *
 *     subsection Equation 1
 *       set Matrix type = Sparse
 *       subsection Linear solver
 *         set Solver                       = CG
 *         set Maximum number of iterations = { 10 | 20 | 30 }
 *       end
 *     end
 *
 *     subsection Equation 2
 *       set Matrix type = Full
 *       subsection Linear solver
 *         set Solver                       = { BiCGStab | GMRES }
 *         set Maximum number of iterations = 100
 *       end
 *     end
 *   @endverbatim
 *   this is the output:
 *   @verbatim
 *     LinEq: Method=CG, MaxIterations=10
 *     LinEq: Method=BiCGStab, MaxIterations=100
 *     Problem: outfile=results.1
 *              eq1=Poisson, eq2=Navier-Stokes
 *              Matrix1=Sparse, Matrix2=Full
 *     LinEq: Method=CG, MaxIterations=20
 *     LinEq: Method=BiCGStab, MaxIterations=100
 *     Problem: outfile=results.2
 *              eq1=Poisson, eq2=Navier-Stokes
 *              Matrix1=Sparse, Matrix2=Full
 *     LinEq: Method=CG, MaxIterations=30
 *     LinEq: Method=BiCGStab, MaxIterations=100
 *     Problem: outfile=results.3
 *              eq1=Poisson, eq2=Navier-Stokes
 *              Matrix1=Sparse, Matrix2=Full
 *     LinEq: Method=CG, MaxIterations=10
 *     LinEq: Method=GMRES, MaxIterations=100
 *     Problem: outfile=results.4
 *              eq1=Poisson, eq2=Navier-Stokes
 *              Matrix1=Sparse, Matrix2=Full
 *     LinEq: Method=CG, MaxIterations=20
 *     LinEq: Method=GMRES, MaxIterations=100
 *     Problem: outfile=results.5
 *              eq1=Poisson, eq2=Navier-Stokes
 *              Matrix1=Sparse, Matrix2=Full
 *     LinEq: Method=CG, MaxIterations=30
 *     LinEq: Method=GMRES, MaxIterations=100
 *     Problem: outfile=results.6
 *              eq1=Poisson, eq2=Navier-Stokes
 *              Matrix1=Sparse, Matrix2=Full
 *   @endverbatim
 *   Since <tt>create_new</tt> gets the number of the run it would also be
 *   possible to output the number of the run.
 *
 *
 *   @ingroup input
 *   @author Wolfgang Bangerth, October 1997, 2010
 */
class MultipleParameterLoop : public ParameterHandler
{
public:
  /**
   * This is the class the helper class or the problem class has to be
   * derived of.
   */
  class UserClass
  {
  public:
    /**
     * Destructor. It doesn't actually do anything, but is declared to
     * force derived classes to have a virtual destructor.
     */
    virtual ~UserClass ();

    /**
     * <tt>create_new</tt> must provide a clean object, either by creating
     * a new one or by cleaning an old one.
     */
    virtual void create_new (const unsigned int run_no) = 0;

    /**
     * This should declare parameters and call the
     * <tt>declare_parameters</tt> function of the problem class.
     */
    virtual void declare_parameters (ParameterHandler &prm) = 0;

    /**
     * Get the parameters and run any necessary action.
     */
    virtual void run (ParameterHandler &prm) = 0;
  };

  /**
   * Constructor
   */
  MultipleParameterLoop ();

  /**
   * Destructor. Declare this only to have a virtual destructor, which is
   * safer as we have virtual functions. It actually does nothing
   * spectacular.
   */
  virtual ~MultipleParameterLoop ();

  /**
   * Read input from a stream until the stream returns the <tt>eof</tt> condition
   * or error. The second argument can be used to denote the name of the file
   * (if that's what the input stream represents) we are reading from; this
   * is only used when creating output for error messages.
   *
   * Return whether the read was successful.
   */
  virtual bool read_input (std::istream &input,
                           const std::string &filename = "input file");

  /**
   * Read input from a file the name of which is given. The PathSearch
   * class "PARAMETERS" is used to find the file.
   *
   * Return whether the read was successful.
   *
   * Unless <tt>optional</tt> is <tt>true</tt>, this function will
   * automatically generate the requested file with default values if the
   * file did not exist. This file will not contain additional comments if
   * <tt>write_stripped_file</tt> is <tt>true</tt>.
   */
  virtual bool read_input (const std::string &FileName,
                           const bool optional = false,
                           const bool write_stripped_file = false);

  /**
   * Read input from a string in memory. The lines in memory have to be
   * separated by <tt>@\n</tt> characters.
   */
  virtual bool read_input_from_string (const char *s);

  /**
   * run the central loop.
   */
  void loop (UserClass &uc);

  /**
   * Determine an estimate for the memory consumption (in bytes) of this
   * object.
   */
  std::size_t memory_consumption () const;

private:

  /**
   * An object in the list of entries with multiple values.
   */
  class Entry
  {
  public:
    /**
     * Declare what a multiple entry is: a variant * entry (in curly braces
     * <tt>{</tt>, <tt>}</tt>) or an array (in double curly braces
     * <tt>{{</tt>, <tt>}}</tt>).
     */
    enum MultipleEntryType
    {
      variant, array
    };

    /**
     * Constructor
     */
    Entry () : type (array) {}

    /**
     * Construct an object with given subsection path, name and value. The
     * splitting up into the different variants is done later by
     * <tt>split_different_values</tt>.
     */
    Entry (const std::vector<std::string> &Path,
           const std::string              &Name,
           const std::string              &Value);

    /**
     * Split the entry value into the different branches.
     */
    void split_different_values ();

    /**
     * Path to variant entry.
     */
    std::vector<std::string> subsection_path;

    /**
     * Name of entry.
     */
    std::string         entry_name;

    /**
     * Original variant value.
     */
    std::string         entry_value;

    /**
     * List of entry values constructed out of what was given in the input
     * file (that is stored in EntryValue.
     */
    std::vector<std::string> different_values;

    /**
     * Store whether this entry is a variant entry or an array.
     */
    MultipleEntryType      type;

    /**
     * Determine an estimate for the memory consumption (in bytes) of this
     * object.
     */
    std::size_t memory_consumption () const;
  };

  /**
   * List of variant entry values.
   */
  std::vector<Entry> multiple_choices;

  /**
   * Number of branches constructed from the different combinations of the
   * variants. This obviously equals the number of runs to be performed.
   */
  unsigned int n_branches;

  /**
   * Initialize the different branches, i.e.  construct the combinations.
   */
  void init_branches ();

  /**
   * Traverse the section currently set by
   * enter_subsection()/leave_subsection() and see which of the entries are
   * variante/array entries. Then fill the multiple_choices variable using
   * this information.
   */
  void init_branches_current_section ();

  /**
   * Transfer the entry values for one run to the entry tree.
   */
  void fill_entry_values (const unsigned int run_no);
};


template <class Archive>
inline
void
ParameterHandler::save (Archive &ar, const unsigned int) const
{
  // Forward to serialization
  // function in the base class.
  ar   &static_cast<const Subscriptor &>(*this);

  ar & *entries.get();

  std::vector<std::string> descriptions;

  for (unsigned int j=0; j<patterns.size(); ++j)
    descriptions.push_back (patterns[j]->description());

  ar &descriptions;
}


template <class Archive>
inline
void
ParameterHandler::load (Archive &ar, const unsigned int)
{
  // Forward to serialization
  // function in the base class.
  ar   &static_cast<Subscriptor &>(*this);

  ar & *entries.get();

  std::vector<std::string> descriptions;
  ar &descriptions;

  patterns.clear ();
  for (unsigned int j=0; j<descriptions.size(); ++j)
    patterns.push_back (std_cxx1x::shared_ptr<const Patterns::PatternBase>(Patterns::pattern_factory(descriptions[j])));
}


DEAL_II_NAMESPACE_CLOSE

#endif