[go: up one dir, main page]

Menu

[r19]: / trunk / include / core / oof1.h  Maximize  Restore  History

Download this file

2604 lines (2095 with data), 59.7 kB

   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
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
#ifndef H_OOF1
#define H_OOF1
// COPYRIGHT 1994 A.D. Software, All rights reserved
// public layer of OOFILE database
// NOTE inline definitions included at end of this header file
// see misc.txt for code conventions
#ifndef H_OOF0
#include "oof0.h"
#endif
#ifndef H_OOFMSG
#include "oofmsg.h"
#endif
#ifdef _Macintosh
#include <Types.h>
#include <Events.h>
#include <Files.h>
#endif
#if OOF_USE_ANSI_STREAMS && !defined(H_OOFIOS)
#include "oofios.h"
#endif
#ifndef H_OOFSTR
#include "oofstr.h"
#endif
class dbQueryBinaryNofield;
class oofE_Base;
/**
Base class used to refer to main OOFILE classes and provide base reflective API.
Implements member mHidden for marking objects as hidden, eg: so dbField members
may not appear in dbTable::extract().
\ingroup oofDatabase
*/
class OOFILE_EXPORT OOF_PublicBase {
public:
bool hidden() const { return mHidden; };
void hide(bool hideIt=true) { mHidden = hideIt; };
#ifndef OOF_NO_STDLIB
virtual void describe(ostream&) const;
#endif
virtual oofString name() const;
virtual ~OOF_PublicBase() {};
protected:
OOF_PublicBase() : mHidden(false) {};
OOF_PublicBase(const OOF_PublicBase& rhs) : mHidden(rhs.mHidden) {};
bool mHidden;
};
/**
Base class typedef to make dictionaries easier to declare.
\ingroup oofUtils
*/
typedef OOF_PublicBase* OOF_bitPointer;
/**
Mixin for reference counted classes.
\ingroup oofUtils
*/
class OOFILE_EXPORT OOF_mixRefCount {
public:
void incRefs();
void decRefs();
protected:
OOF_mixRefCount(unsigned long initialRefs = 1);
virtual ~OOF_mixRefCount();
// use default copy ctor
unsigned int mReferences;
};
/**
Representation of ref-counted dictionary.
\ingroup oofUtils
*/
class OOFILE_EXPORT OOF_DictRep : public OOF_mixRefCount {
private:
OOF_DictRep(unsigned int numSlots, unsigned int expandBySlots);
OOF_DictRep(const OOF_DictRep*);
~OOF_DictRep();
void operator=(const OOF_DictRep&) {assert(0);};
// access protocol
void Append(OOF_bitPointer);
OOF_bitPointer Pop();
OOF_bitPointer& operator[](unsigned int index);
OOF_bitPointer& operator[](const char *name);
OOF_bitPointer& lookupByAttribute(const char* attributeValue, const char* attributeType=0);
OOF_bitPointer& item(unsigned int index);
OOF_bitPointer value(unsigned int index) const;
void Reset();
void ExpandToInclude(unsigned int indexToCover);
// data storage
enum {kSlotSize=sizeof(OOF_bitPointer)};
OOF_bitPointer *mBits; // owned
unsigned int mExpansionChunk, mNextFreeEntry, mNumSlots;
friend class OOF_Dictionary;
friend class dbView;
friend class dbRelChain;
};
/**
Provides searchable dictionary of common OOFILE classes like dbTable.
a Handle or Envelope class for OOF_DictRep, independently acting as an iterator.
contains list of OOF_PublicBase and allows lookup by name and
\todo lookup by other attributes
\see OOF_Dictionary::lookupByAttribute
\ingroup oofUtils
*/
class OOFILE_EXPORT OOF_Dictionary {
// default constructor, or passing in zero items skips allocating storage
// and storage will be allocated later as necessary.
public:
enum {kDefExpansionChunk=10};
OOF_Dictionary() ;
OOF_Dictionary(const OOF_DictRep* rep);
OOF_Dictionary(unsigned int numSlots);
OOF_Dictionary(unsigned int numSlots, unsigned int expansionChunk, bool inOwnsContents=false);
OOF_Dictionary(const OOF_Dictionary&);
OOF_Dictionary clone() const;
virtual ~OOF_Dictionary();
OOF_Dictionary& operator=(const OOF_Dictionary&);
// access operators
OOF_bitPointer& operator[](unsigned int);
OOF_bitPointer& operator[](const char*); // may return OOF_Dictionary::missingItem() if fails to match name
OOF_bitPointer& lookupByAttribute(const char* attributeValue, const char* attributeType=0);
OOF_bitPointer& item(unsigned int index);
OOF_bitPointer value(unsigned int index) const;
OOF_bitPointer& operator()();
void append(OOF_bitPointer);
OOF_bitPointer pop(); // returns last item, maybe 0
void reset();
// iterator protocol
unsigned int iter() const;
void start();
bool more() const;
void next();
unsigned int count() const;
void startVisible(bool wantVisible=true);
bool moreVisible(bool wantVisible=true);
void nextVisible(bool wantVisible=true);
unsigned int countVisible(bool wantVisible=true);
// other protocol
bool allObjectsMatch(OOF_Dictionary&);
void deleteAll();
#ifndef OOF_NO_STDLIB
virtual void describe(ostream&) const;
virtual void describeVisible(ostream&, bool wantVisible) const;
#endif
void ownsContents(bool ownsFlag=true);
protected:
bool EntryMatchesVisibility(const OOF_PublicBase*, bool) const;
// data storage
OOF_DictRep *mRep; // owned
unsigned int mInternalIter;
bool mOwnsContents;
static OOF_bitPointer sMissingItem;
public:
static OOF_bitPointer& missingItem();
};
/**
type we pass around pretending we have a real OID.
When we move to supporting HUGE Faircom files with 8-byte pointers,
may become a real class
\ingroup oofDatabase
*/
typedef unsigned long oidT;
/**
type used to specify index options for dbField's.
\ingroup oofDatabase
*/
enum OOF_IndexOptions { kNotIndexed=0, kIndexed=1, kIndexNoDups=2, kIndexCaseSensitive=4,
kIndexCompressLeading=8, kIndexCompressPadding=16, kIndexNoNulls=32,
kIndexCompress = kIndexCompressLeading + kIndexCompressPadding,
kIndexNoDupsNoNulls = kIndexNoDups + kIndexNoNulls,
kIndexCompressNoDups = kIndexCompress + kIndexNoDups,
kIndexCompressNoNulls = kIndexCompress + kIndexNoNulls,
kIndexCompressNoDupsNoNulls = kIndexCompress + kIndexNoDups + kIndexNoNulls,
kIndexCompressLeadingNoDups = kIndexCompressLeading + kIndexNoDups,
kIndexCompressLeadingNoDupsNoNulls = kIndexCompressLeadingNoDups + kIndexNoNulls,
kIndexCompressPaddingNoDups = kIndexCompressPadding + kIndexNoDups,
kIndexCompressPaddingNoDupsNoNulls = kIndexCompressPaddingNoDups + kIndexNoNulls
};
/* NEW VERSION
enum OOF_IndexOptions { kNotIndexed=0, kIndexed=1, kIndexedNoDups=2, kIndexedCaseSensitive=4,
kIndexedCompressLeading=8, kIndexedCompressPadding=16,
kIndexedCompress = kIndexedCompressLeading + kIndexedCompressPadding,
kIndexedCompressNoDups = kIndexedCompress + kIndexedNoDups,
kIndexedCompressLeadingNoDups = kIndexedCompressLeading + kIndexedNoDups,
kIndexedCompressPaddingNoDups = kIndexedCompressPadding + kIndexedNoDups
};
*/
// for backwards compatability and to balance things out so we have both a verb and noun form
// (the original one is as follows except for kNotIndexed and kIndexed
/*enum OOF_IndexOptions2 { kNotIndex=0, kIndex=1, kIndexNoDups=2, kIndexCaseSensitive=4,
kIndexCompressLeading=8, kIndexCompressPadding=16,
kIndexCompress = kIndexCompressLeading + kIndexCompressPadding,
kIndexCompressNoDups = kIndexCompress + kIndexNoDups,
kIndexCompressLeadingNoDups = kIndexCompressLeading + kIndexNoDups,
kIndexCompressPaddingNoDups = kIndexCompressPadding + kIndexNoDups
};
*/
OOFILE_EXPORT ostream& operator<<(ostream&, OOF_IndexOptions);
#if defined(_MSC_VER) && !defined(__MWERKS__)
// VC5 considers field(0) ambiguous - sloppy evaluation of overloads!!!
typedef int tableNumT;
typedef int fieldNumT;
#else
typedef unsigned short tableNumT; // never more than 64k classes in database!
typedef unsigned short fieldNumT; // never more than 64k fields in a record!
#endif
class dbQueryClause;
class dbRelRefBase;
class dbField;
class OOF_tableBackend;
class dbContext;
class dbConnect;
class OOF_ExpandableLongArray;
class dbSorter;
class OOF_Selection;
class dbTable;
class dbGUI;
class oofWordParser;
class oofDirectory;
/**
Abstract factory for dbGUI.
\ingroup oofGUI
*/
class OOFILE_EXPORT dbGUIFactory {
public:
dbGUIFactory();
virtual dbGUI* concreteMakeGUI(dbTable*)=0; ///< Abstract factory impl.
static dbGUI* makeGUI(dbTable*); ///< Abstract factory interface
protected:
static dbGUIFactory* sGUIFactory;
};
/**
Envelope class to contain an abstract selection apart from its dbTable.
Useful for set manipulations as a lighter way to temporarily save and
restore a set, or retain for other manipulation.
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbSelection {
// public interface to selections
public:
dbSelection();
dbSelection(const OOF_Selection*);
dbSelection(const dbSelection&);
~dbSelection();
dbSelection& operator=(const dbSelection&);
dbSelection& operator=(dbTable&);
// combinatorial operators
void difference_with(const dbSelection&);
void difference_with(dbTable&);
void difference_with(dbTable*);
void operator -=(const dbSelection&);
void operator -=(dbTable&);
void operator -=(dbTable*);
void operator %=(const dbSelection&);
void operator %=(dbTable&);
void operator %=(dbTable*);
void intersection_with(const dbSelection&);
void intersection_with(dbTable&);
void intersection_with(dbTable*);
void operator &=(const dbSelection&);
void operator &=(dbTable&);
void operator &=(dbTable*);
void union_with(const dbSelection&);
void union_with(dbTable&);
void union_with(dbTable*);
void union_with_no_overlap(const dbSelection&);
void union_with_no_overlap(dbTable&);
void union_with_no_overlap(dbTable*);
void operator +=(const dbSelection&);
void operator +=(dbTable&);
void operator +=(dbTable*);
void operator |=(const dbSelection&);
void operator |=(dbTable&);
void operator |=(dbTable*);
void union_with(oidT);
void operator+=(oidT);
void intersection_with(oidT);
void invert();
void operator~();
void operator!();
// reflective operators
bool isEmpty() const;
bool isAllRecs() const;
bool contains(oidT) const;
unsigned long count() const;
const OOF_Selection* internalSelection() const;
const dbTable* prototypicalTable() const;
private:
void DeleteContents();
// data storage
OOF_Selection* mSelection; // owned
unsigned long* mReferences;
};
/**
Save & restore current database selection on the stack.
\ingroup oofDatabase
*/
class OOFILE_EXPORT stSaveSelection {
public:
stSaveSelection(dbTable*);
stSaveSelection(dbTable&);
~stSaveSelection();
protected:
dbTable* mTable;
dbSelection mSavedSelection;
};
/**
Save and restore state of ignoring duplicates.
Mainly used when importing data.
\ingroup oofDatabase
*/
class OOFILE_EXPORT stIgnoreDuplicateRecords {
public:
stIgnoreDuplicateRecords(dbTable*);
stIgnoreDuplicateRecords(dbTable&);
~stIgnoreDuplicateRecords();
protected:
dbTable* mTable;
};
/**
Helper class for dbTable to easily assign field values;
Provides idiom of
People << "Andy" << "Dent" << "37";
instead of
People.newRecord();
People.FirstName = "Andy";
People.LastName = "Dent";
People.Age = 37;
People.saveRecord();
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbTableAssigner {
public:
dbTableAssigner(dbTable*, const char* inFirstFieldValue);
~dbTableAssigner();
dbTableAssigner& operator<<(const char*);
void setNextFieldString(const char*);
protected:
dbTable* mTable;
fieldNumT mNextFieldNum;
};
/**
Base class for persistent tables.
Must be used in association with a dbConnect subclass to provide persistence.
Contains one or more dbField members either by declaration or attachField().
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbTable : public OOF_PublicBase, public oofBroadcaster {
public:
dbTable(const char *name=0);
dbTable(const dbTable&);
dbTable(const dbTable&, OOF_tableBackend*);
virtual ~dbTable();
void stillCurrentlyConstructing();
dbTable* prototype() const;
enum {kFieldSep = '\t'};
enum {kRecSep = '\n'};
enum selSharingT {selNotShared, selShared, selCopyOnWrite,selNotSharedCacheCopied};
enum saveOptionsT{requireExplicit, autoOnContextChange, requireExplicitAndBuffer, bufferForever};
enum tableValidT {eInvalid=0, eValid, eClosed}; // use invalid=0 so can cope if coerce false
virtual const char* defaultName() const { return ""; }; // gets overridden by the methods generated by ABSTRACT_BASE_METHODS in oofmacro.h
virtual oofString name() const;
void setName(const char*);
virtual dbTable* cloneTableSharingSelection() const;
virtual dbTable* cloneTableWithoutSelection() const;
virtual dbTable* cloneTbleWithCachNoSelection() const;
virtual dbTable* cloneTable(selSharingT selSharing=selCopyOnWrite)=0;
virtual dbTable* cloneTableConst(selSharingT selSharing) const=0;
// pure virtual cloneTable is implemented by macro OOFILE_METHODS, in oofmacro.h, for each user subclass
// abstract to avoid bugs from people missing their OOFILE_METHODS in table declarations
void postCloneTableCleanup();
// operator dbTable*();
virtual dbView* makeView(); // can't be const because the view retains a pointer to us
bool ensureRecordLoaded(bool autoCreateRelated=false, bool failureAborts=true);
void ensureSelectionLoaded();
void relateAllDeletables();
// hiding oid's which may be record offsets or generated unique numbers
oidT currentOID();
oidT oidOfRecord(unsigned long);
// other protocol
bool loadRelatedContextJoiningFromTo(const dbField*, const dbField*);
oofWordParser* getDefaultWordParser();
void setDefaultWordParser(oofWordParser* inParser) ;
void setSaveOption(const saveOptionsT);
void setFileExtensions(const char* dataExt, const char* indexExt);
dbField* field(fieldNumT) const;
dbField* field(const oofString& );
bool pointsToBackend(const OOF_tableBackend*) const;
virtual bool canSaveRecord(); // expect user override in many cases
void attachfield(dbField*);
void buildSchema();
void addIndices(const char* newIDXname);
void suppressIndices();
void rebuild();
void close();
void deleteStorage();
void createTableInConnection(const dbConnect*);
bool openTableInConnection(const dbConnect*, const bool createIfMissing = false);
unsigned int numIndexes() const;
unsigned int numFiles() const;
unsigned long sequenceNumber() const;
void setTableValid(bool isValid=true);
void pack();
// recordwise access
void start();
void next();
void first();
void prev();
void last();
bool more() const;
bool atFirst() const;
bool atLast() const;
bool atRelative(unsigned long) const;
unsigned long count();
unsigned long countAll() const;
/// \name sorting
//@{
void setSortOrder(const dbField&, bool shouldReverse=false);
void setSortOrder(const dbSorter&);
void setReverseSortOrder(const dbField&);
dbSorter* sorter() const;
void sortNow() const;
void unSorted();
void suspendSorting();
void resumeSorting();
//@}
void unloadRecord();
bool reloadRecord();
bool isRecordLoaded() const;
bool isEmpty();
bool isNewRecord() const;
bool isTableValid() const;
tableValidT validStatus() const;
int validatingDepth() const;
bool isDirty() const;
void markDirty();
void ignoreDuplicateRecords();
void noticeDuplicateRecords();
unsigned long recordNumber() const;
unsigned long recordNumberOfOID(oidT inOID);
unsigned long recordNumber(const dbQueryClause* qClause, bool* outFoundIt=0) const;
unsigned long recordNumber(const dbQueryClause& qClause, bool* outFoundIt=0) const;
bool gotoRecord(unsigned long);
/// \name keyword searches
//@{
dbQueryBinaryNofield hasWord(const char* str) const;
dbQueryBinaryNofield hasAnyWordsDelimited(const char*, char delimiter);
dbQueryBinaryNofield hasAllWordsDelimited(const char*, char delimiter);
dbQueryBinaryNofield hasAnyWordsOf(const char **schStrs, unsigned long count);
dbQueryBinaryNofield hasAllWordsOf(const char **schStrs, unsigned long count);
dbQueryBinaryNofield hasAnyWordsOf(oofWordParser*);
dbQueryBinaryNofield hasAllWordsOf(oofWordParser*);
dbQueryBinaryNofield hasWordStartsWith(const char* str) const;
dbQueryBinaryNofield hasAnyWordsStartsWithDelimited(const char*, char delimiter);
dbQueryBinaryNofield hasAllWordsStartsWithDelimited(const char*, char delimiter);
dbQueryBinaryNofield hasAnyWordsStartsWithOf(const char **schStrs, unsigned long count);
dbQueryBinaryNofield hasAllWordsStartsWithOf(const char **schStrs, unsigned long count);
dbQueryBinaryNofield hasAnyWordsStartsWithOf(oofWordParser*);
dbQueryBinaryNofield hasAllWordsStartsWithOf(oofWordParser*);
//@}
/// \name public search functions
//@{
/// \todo bool searchDefaultIndex(const char*);
bool search(const dbQueryClause& query);
bool searchSelection(const dbQueryClause& query);
bool search(const dbQueryClause* query);
bool searchSelection(const dbQueryClause* query);
bool searchSelContainsAnyDelimited(const dbField& schField, const char *schStr, char delim);
bool searchSelContainsAnyOf(const dbField& schField, const char **schStrs, unsigned long count);
bool searchSelContainsAnyOf(const dbField& schField, oofWordParser*);
bool searchSelContainsAllDelimited(const dbField& schField, const char *schStr, char delim);
bool searchSelContainsAllOf(const dbField& schField, const char **schStrs, unsigned long count);
bool searchSelContainsAllOf(const dbField& schField, oofWordParser*);
//@}
/// \name set operations
//@{
void difference_with(dbTable&);
void difference_with(dbTable*);
void difference_with(const dbSelection&);
void operator -=(dbTable&);
void operator -=(dbTable*);
void operator -=(const dbSelection&);
void operator %=(dbTable&);
void operator %=(dbTable*);
void operator %=(const dbSelection&);
void intersection_with(dbTable&);
void intersection_with(dbTable*);
void intersection_with(const dbSelection&);
void operator &=(dbTable&);
void operator &=(dbTable*);
void operator &=(const dbSelection&);
void union_with(dbTable&);
void union_with(dbTable*);
void union_with(const dbSelection&);
void union_with_no_overlap(dbTable&);
void union_with_no_overlap(dbTable*);
void union_with_no_overlap(const dbSelection&);
void operator +=(dbTable&);
void operator +=(dbTable*);
void operator +=(const dbSelection&);
void operator |=(dbTable&);
void operator |=(dbTable*);
void operator |=(const dbSelection&);
void invert();
void operator~();
void operator!();
bool operator+=(oidT);
bool addOIDtoSelection(oidT);
bool contains(oidT);
void dropRecordFromSelection(unsigned long);
//@}
/// \name getting & saving selections as lightweight objects
//@{
dbSelection currentSelection();
dbSelection makeEmptySelection() const;
void setSelection(const dbSelection&);
void setSelection(const OOF_Selection*);
const dbSelection& operator=(const dbSelection& rhs);
//@}
// selection changes that broadcast, eg: to update MN relationship links
/// \name getting & saving selections as lightweight objects
//@{
void appendSelection(const dbSelection&);
void removeSelection(const dbSelection&);
void clearSelection();
//@}
/// \name selection of specific contexts
//@{
void selectAll();
void selectNone();
bool selectJustOID(oidT);
void selectJustCurrent();
bool relateSelectionFrom(dbTable*);
bool selectAllRelated(bool broadcastChange=true);
//@}
/// \name data access
//@{
virtual void newRecord();
virtual void cloneRecord();
virtual void postCloneRecordCleanup();
virtual void saveRecord();
virtual void revertRecord();
virtual void deleteRecord();
void deleteSelection();
void deleteAll();
void copyAllFrom(dbTable*);
dbTableAssigner operator<<(const char*);
void copyRecFrom(const dbTable* rhs, fieldNumT numFields=0);
dbTable& operator=(const dbTable&);
virtual void extract(ostream&);
virtual unsigned long insert(istream&);
virtual void import(const char* ansiFileName);
bool allowsShortImports() const;
void setShortImports(bool);
//@}
/// \name reflective operators
//@{
const oofString& tableName() const;
virtual oofString tableSingularName() const; // eg: returns Student if you have name Students
tableNumT tableNumber() const;
bool tableCachesDirtyRecords() const;
saveOptionsT tableSaveOption() const;
virtual void describe(ostream&) const;
virtual void describeState(ostream&) const;
virtual void stats(ostream&);
bool isCopyCompatibleWith(const dbTable*) const;
fieldNumT numFields() const;
bool allSelected() const;
bool isOpen() const;
bool inDeclarativePhase() const;
//@}
// \name info about relationships
//@{
bool isRelatedClone() const;
dbRelRefBase* controllingRelationship() const;
dbTable* lhsTableInRelationshipSpec() const;
dbTable* baseTableOfRelationChain();
//@}
dbGUI* getGUI();
virtual void generateTestData(unsigned long numRecords, bool generateRandom=true, unsigned long seedOrCount=0);
// \name locking
//@{
void lockRecord(); // no return type - throws exception
void unlockRecord();
bool lockedCurrentRecord() const;
//@}
// \name transactions
//@{
void beginTransaction(short tMode =0);
void abortTransaction(short rMode =0);
void commitTransaction(short rMode =0);
bool transactionDirty();
//@}
#ifndef OOF_DISALLOW_CHANGE_SHIELDING
// change shielding, so field changes don't mark the record as dirty (default is false)
bool changeShielded() const;
void changeShielded(bool setShielding=true);
#endif
void describeInvariant(ostream& os) const; //To pass in an output stream as a parameter
protected:
#ifdef OOF_DEBUG_LOG_NAME
void StandardDebugLog(const char*) const;
void StandardQueryDebugLog(const char*, const dbQueryClause&) const;
#endif
private:
void CompleteField(dbField*);
void ContextChange();
void MakeTableValid();
void LoadRelatedContext();
void SaveLoop();
// data storage
protected:
OOF_tableBackend *mBackend; // owned (the bit that does all the work!!)
OOF_Dictionary mFields;
oofString mTableName;
tableNumT mTableNumber;
fieldNumT mFieldCount;
saveOptionsT mSaveOption;
bool mAllowShortImports;
tableValidT mTableValid;
int mValidatingDepth;
dbGUI* mGUI; // owned
private:
dbRelRefBase* mRelToLHS; // if we are a clone managing a related selection, this is how we get back
oofWordParser* mDefaultPrototypeParser;
dbConnect* mConnection;
dbTable* mPrototype;
bool mLockedCurrentRecord;
bool mInTransaction;
bool mTransactionDirty;
bool mInSaveLoop;
#ifndef OOF_DISALLOW_CHANGE_SHIELDING
bool mChangeShielded;
#endif
static dbGUIFactory* sGUIFactory;
protected:
static dbTable *sCurrentlyConstructing;
friend class dbField;
friend class dbConnect;
friend class dbConnect_ram;
friend class dbConnect_ramp;
friend class dbRelHalf;
friend class dbRelRefBase;
friend class OOF_tableBackend;
friend void dbSelection::difference_with(dbTable&);
friend class oofE_Table;
}; // dbTable
OOFILE_EXPORT ostream& operator<<(ostream& os, dbTable& tbl);
OOFILE_EXPORT ostream& operator<<(ostream& os, dbTable* tbl);
OOFILE_EXPORT istream& operator>>(istream& is, dbTable* tbl);
OOFILE_EXPORT istream& operator>>(istream& is, dbTable& tbl);
/**
use for dynamic creation of fields attached to table.
eg: in oofXMLdb parsing a schema from XML
\todo add OOFILE_METHODS and then can instantiate directly instead of trivial subclasses.
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbTableOwningFields : public dbTable {
private:
void operator=(const dbTableOwningFields&) { ; }; // can't assign
public:
dbTableOwningFields(const char* name=0);
dbTableOwningFields(const dbTable&, OOF_tableBackend*);
dbTableOwningFields(const dbTableOwningFields&);
// uses default dtor
void adoptField(dbField* adoptedField);
protected:
OOF_Dictionary mOwnedFields;
};
/**
Separate out statics from dbTable.
Use separate public class as some old compilers don't support nested decls.
\ingroup oofDatabase
*/
class OOFILE_EXPORT OOF_dbTableStatics {
public: // for convenience but really only update by dbTable or subclasses
static bool sCloning;
static bool sCloningInDifferentConnection;
static dbTable::selSharingT sCloningSelSharing;
};
/**
Base class used mainly when exceptions not available.
\see dbConnect::raise() for calling.
\ingroup oofUtils
*/
class OOFILE_EXPORT oofErrorReporter {
public:
oofErrorReporter();
virtual ~oofErrorReporter();
// default implementations
virtual void raise(ostream&, bool terminateAfterMsg=true);
virtual void raise(const char*, bool terminateAfterMsg=true);
static oofErrorReporter* defaultReporter();
static void setDefaultReporter(oofErrorReporter*);
protected:
virtual void MaybeTerminate(bool terminateAfterMsg);
private:
static oofErrorReporter sDefaultReporter; // concrete default
static unsigned short sNumReporters;
static oofErrorReporter* sUserSpecifiedReporter;
};
/**
Reporter that formats output for HTML responses.
\ingroup oofUtils
*/
class OOFILE_EXPORT oofCGIErrorReporter : public oofErrorReporter {
public:
oofCGIErrorReporter(ostream&);
virtual ~oofCGIErrorReporter();
virtual void raise(ostream&, bool terminateAfterMsg=true);
virtual void raise(const char*, bool terminateAfterMsg=true);
protected:
virtual void Header();
virtual void Footer();
private:
ostream& mStream;
};
/**
Abstraction of common runtime environment stuff you'd call.
Mainly used to identify current runtime environment.
\ingroup oofUtils
*/
class OOFILE_EXPORT oofRuntimeEnv {
public:
enum oofRuntimeEnvT {Macintosh, OS2, Unix, WinNT, Win95, Win98, Win32s, Win3, Win_UNKNOWN};
// NOT YET IMPLEMENTED - tests for OS2
static oofRuntimeEnvT runtimeEnv();
static bool isMacintosh();
static bool isUnix();
static bool isWindows();
static const char* termForLink();
static void spendBackgroundTime();
static void beep();
};
/**
Abstract interface for database.
Subclassed to indicate type of database backend to use.
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbConnect : public OOF_PublicBase {
public:
dbConnect(bool isTemporary=false);
virtual ~dbConnect();
private:
dbConnect(const dbConnect&) { assert(0); }; // NEVER CALLED - MAKE IMPOSSIBLE TO COPY
void operator=(const dbConnect&) { assert(0); }; // MAKE IMPOSSIBLE TO COPY
public:
virtual oofString name() const;
static dbConnect* currentlyConstructing();
virtual void newConnection(const char* connectionName)=0;
virtual void openConnection(const char* connectionName)=0;
#ifdef _Macintosh
virtual void newConnection(const FSSpec&)=0;
virtual void openConnection(const FSSpec&)=0;
#endif
virtual void close()=0;
virtual void deleteStorage();
virtual bool usesSeparateStorageFiles() const;
void gotoDatabaseDir() const;
oofDirectory* databaseDirectory() const;
const oofString& connectionName() const;
void attachTable(dbTable *);
dbTable *table(unsigned int) const;
dbTable *table(const char*);
unsigned int numTables() const;
bool isOpen() const;
bool inDeclarativePhase() const;
// locking
virtual void exitLocking()=0;
virtual void enterWriteLocking()=0;
virtual void enterReadLocking()=0;
// utilities
static bool fileExists(const char * fName); // legacy call - use oofDirectory::fileExists
static bool underConstruction();
virtual void describe(ostream&) const;
virtual void writeOOFSchema();
virtual void readOOFSchema(const oofString& schemaFileName);
virtual void stats(ostream&);
void dumpData(ostream&);
void extract(ostream& os) {dumpData(os);}; // dumpData is old form, extract is more consistent
void copyAllFrom(dbConnect*);
void deleteAll();
void generateTestData(unsigned long maxRecs=10000, bool generateRandom=true, unsigned long seedOrCount=0);
static void raise(ostream&, bool terminateAfterMsg=true);
static void raise(const char*, bool terminateAfterMsg=true);
void schemaFileExt(const oofString&);
#ifndef OOF_USING_EXCEPTIONS
static void raise(const oofE_Base&, bool terminateAfterMsg=true);
#endif
// batch settings
void suspendSorting() const;
void resumeSorting() const;
// settings
static void truncateTrailingSpaces(bool willTruncate=true);
static bool willTruncateTrailingSpaces();
#ifdef OOF_DEBUG_LOG_NAME
static ostream& debugLog();
static void startDebugWrite();
static void logComment(const char*);
static void logComment(ostream&);
static void endDebugWrite();
#endif
oofWordParser* getDefaultWordParser();
void setDefaultWordParser(oofWordParser* inParser) ;
protected:
void MakeAllTablesValid() const;
void InitOpenOrCreateState();
void OpenOrCreateStateTransition(bool inOpenedOrCreated);
enum connectionFileStateT {// has both transition and state
eIdle=0,
eStart=1,
eOpenedFile=2,
eCreatedFile=4,
eInvalidlyOpenInCreation = 8,
eInvalidlyCreationInOpen = 16
};
#ifdef OOF_DEBUG_LOG_NAME
void LogConnection(const char* comment, const char* connectionName);
#endif
virtual void WriteOOFSchemaFile();
virtual oofString MakeSchemaFileName();
oofString MakeOOFSchemaString();
private:
virtual OOF_tableBackend *MakeTableBackend(dbTable*)=0;
// data storage
protected:
OOF_Dictionary mTables;
oofString mConnectionName;
oofString mSchemaFileName;
bool mOpen, mTempDatabase, mInDeclarativePhase;
oofWordParser* mDefaultPrototypeParser; // owned, shared
oofDirectory* mDatabaseDir; // owned
static dbConnect *sCurrentlyConstructing;
static bool sTruncateTrailingSpaces;
connectionFileStateT mFileState;
static oofString sSchemaFileExt;
#ifdef OOF_DEBUG_LOG_NAME
static ofstream sDebugLog;
static oofDirectory sDebugDir;
#endif
// friend dbTable::dbTable(const char*);
// friend dbTable::dbTable(const dbTable& rhs);
// friend class dbRelationship;
};
class dbBLOB;
/**
Abstract interface to database backend.
\ingroup oofDatabase
*/
class OOFILE_EXPORT OOF_tableBackend {
// uses lots of public methods but is only ever accessed by a dbTable or dbField subclass
// so no problems
protected:
OOF_tableBackend(dbTable*);
OOF_tableBackend(const OOF_tableBackend&, dbTable*);
virtual ~OOF_tableBackend() {};
public:
virtual void addIndices(const char* newIDXname)=0;
virtual void suppressIndices()=0;
virtual void rebuild()=0;
virtual void close()=0;
virtual void deleteStorage();
virtual void buildSchema(bool rebuilding=false)=0;
virtual void createTableInConnection(const dbConnect*)=0;
virtual bool openTableInConnection(const dbConnect*, const bool createIfMissing = false)=0;
virtual void setFileExtensions(const char* dataExt, const char* indexExt)=0;
virtual OOF_tableBackend* clone(dbTable::selSharingT, dbTable*) const=0;
virtual void describeState(ostream&) const=0;
virtual void describeInvariant(ostream&) const=0;
/// \name OID access & generation
//@{
virtual oidT currentOID()=0;
virtual oidT oidOfRecord(unsigned long)=0;
//@}
// recordwise access
virtual void start()=0;
virtual void next()=0;
virtual void prev()=0;
virtual bool more() const=0;
virtual bool atFirst() const=0;
virtual bool atLast() const=0;
virtual bool atRelative(unsigned long) const=0;
virtual unsigned long count() const=0;
virtual unsigned long countAll() const=0;
/// \name sorting
//@{
virtual void setSortOrder(dbSorter* adoptSorter)=0;
virtual dbSorter* sorter() const=0;
virtual void sortSelectionNow(fieldNumT)=0;
virtual void sortSelectionInverseNow(fieldNumT)=0;
virtual void sortSelectionNow(const dbSorter*)=0;
//@}
// data access
virtual void newRecord()=0;
virtual void deleteRecord()=0;
virtual void saveRecord()=0;
virtual void revertRecord()=0;
virtual void unloadRecord()=0;
virtual void unloadCache()=0;
virtual bool reloadRecord()=0;
virtual bool isRecordLoaded() const=0;
virtual void *getFieldWriteDest(const dbField*)=0;
virtual void *getFieldReadFrom(fieldNumT)=0;
virtual void setBlobLength(fieldNumT, unsigned long len)=0;
virtual void loadBlob(const dbBLOB*)=0;
bool isDirty() const;
virtual bool isNewRecord() const=0;
void markDirty();
void fieldHasDefaultCalculator(dbField*);
void fieldHasStoredCalculator(dbField*);
virtual void pack()=0;
// reflective operators
virtual unsigned int numIndexes() const=0;
virtual unsigned int numFiles() const=0;
virtual unsigned long fieldDataLen(const dbField*) const=0;
virtual unsigned long blobPointerReferenceSize() const=0;
virtual unsigned long sequenceNumber() const=0;
virtual bool allSelected() const=0;
virtual bool fieldIsDirty(fieldNumT) const=0;
dbTable* table() const;
dbField* field(fieldNumT) const;
virtual void ignoreDuplicateRecords()=0;
virtual void noticeDuplicateRecords()=0;
// public search functions
virtual unsigned long recordNumber() const=0;
virtual unsigned long recordNumberOfOID(oidT inOID)=0;
virtual bool gotoRecord(unsigned long relativeNum)=0;
virtual void selectAll()=0;
virtual void selectNone()=0;
virtual bool search(const dbQueryClause*)=0;
virtual unsigned long recordNumberMatching(const dbQueryClause* qClause, bool* outFoundIt=0) const=0;
virtual bool checkDuplicate(const dbQueryClause*)=0;
virtual bool searchSelection(const dbQueryClause*)=0;
virtual bool searchEqual(const dbField*, const char*, bool matchEntireKey=true)=0;
virtual bool searchEqual(const dbField*, const void*)=0;
virtual bool searchSelContainsAnyDelimited(const dbField* schField, const char *schStr, char delim)=0;
virtual bool searchSelContainsAnyOf(const dbField* schField, const char **schStrs, unsigned long count)=0;
virtual bool searchSelContainsAllDelimited(const dbField* schField, const char *schStr, char delim)=0;
virtual bool searchSelContainsAllOf(const dbField* schField, const char **schStrs, unsigned long count)=0;
virtual bool loadRelatedContextJoiningFromTo(const dbField*, const dbField*)=0;
virtual bool addOIDtoSelection(oidT)=0;
virtual bool contains(oidT) const=0;
virtual void dropRecordFromSelection(unsigned long)=0;
virtual void invert()=0;
virtual void difference_with(const OOF_tableBackend*)=0;
virtual void intersection_with(const OOF_tableBackend*)=0;
virtual void union_with(const OOF_tableBackend*)=0;
virtual void union_with_no_overlap(const OOF_tableBackend*)=0;
virtual void difference_with(const dbSelection&)=0;
virtual void intersection_with(const dbSelection&)=0;
virtual void union_with(const dbSelection&)=0;
virtual void union_with_no_overlap(const dbSelection&)=0;
// getting & saving selections as lightweight objects
virtual dbSelection currentSelection() const=0;
virtual dbSelection makeEmptySelection() const=0;
virtual void setSelection(const dbSelection&)=0;
virtual void setSelection(const OOF_Selection*)=0;
// selection of specific contexts
virtual bool selectJustOID(oidT)=0;
virtual void selectJustCurrent()=0;
// locking
virtual void lockRecord()=0;
virtual void unlockRecord()=0;
// transactions
virtual void beginTransaction(short tMode = 0)=0;
virtual void abortTransaction(short rMode = 0)=0;
virtual void commitTransaction(short rMode = 0)=0;
//debugging
#ifdef OOF_DebugDumpBlobState
virtual void describeBlobs()=0;
#endif
protected:
virtual void CachingContextChange()=0;
virtual void ContextChange()=0;
bool tableCachesDirtyRecords() const;
// data storage
OOF_Dictionary mFields; // copy of dbTable handle object, one representation
dbTable* mTable;
bool mDirty;
bool mHasDefaultCalculators, mHasStoredCalculators;
friend class dbTable;
};
class OOF_Segment;
/**
Mixin for classes allowing you to declare segments based on fields.
\ingroup oofDatabase
*/
class OOFILE_EXPORT OOF_FieldSegOwner {
public:
// constructors
OOF_FieldSegOwner();
OOF_FieldSegOwner(const OOF_FieldSegOwner&);
virtual ~OOF_FieldSegOwner() {};
virtual unsigned short countSegments() const;
virtual void addSegment(dbField&);
OOF_FieldSegOwner& operator<<(dbField&);
OOF_FieldSegOwner& operator>>(dbField&);
void toggleSegmentReversedFlags();
// reflective operators
OOF_Segment* segment(unsigned int) const;
fieldNumT fieldNumberOfSegment(unsigned int) const;
// data storage
private:
OOF_Dictionary mSegments;
};
/**
Specify sort order by one more fields.
Sort object retained by dbTable and possibly others
to provide specification again in future.
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbSorter : public OOF_FieldSegOwner {
public:
dbSorter();
dbSorter(const dbSorter&);
dbSorter(const OOF_FieldSegOwner&);
virtual ~dbSorter() {};
virtual void describe(ostream&) const;
dbSorter& operator<<(dbField&);
dbSorter& operator>>(dbField&);
void setSortOnSaves(bool willSortOnSaves=true);
void suspendSorting();
void resumeSorting();
bool sortingSuspended() const;
// must implement the following in concrete classes
virtual dbSorter* clone() const;
virtual void sortNow(OOF_tableBackend*);
virtual unsigned short sortFieldNo() const;
virtual bool sortsBySingleField() const;
bool operator!=(const dbSorter* rhs) const;
// state changers
void backendSavedRecord(OOF_tableBackend*);
void backendChangedContext(OOF_tableBackend*);
void selectionChanged();
// state getter
virtual unsigned long state() const;
protected:
// data storage
bool mSortOnSaves, mNeedsToSort, mSorting, mSuspended;
};
/**
simple specification class used to declare sort orders.
Also used in expressions defining compound keys.
\ingroup oofDatabase
*/
class OOFILE_EXPORT reversed {
public:
reversed(dbField& fld) : mField(fld) {};
reversed(dbField* fld) : mField(*fld) {};
// use default copy ctor
dbField& Field() const { return mField; }
private:
dbField& mField;
};
// try including these definitions here anyway as complaints from VC6 about above friends
OOFILE_EXPORT dbSorter& operator<<(dbSorter&, const reversed&);
OOFILE_EXPORT OOF_FieldSegOwner& operator<<(OOF_FieldSegOwner&, const reversed&);
/**
dbSorter subclass used when sorting by a single field.
Provides optimal despatching for this common case to
OOF_simpleRecordBackend::sortSelectionNow(fieldNumT)
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbFieldSorter : public dbSorter {
public:
dbFieldSorter(fieldNumT, bool shouldReverse=false);
private:
dbFieldSorter(const dbFieldSorter&) { assert(0); };
public:
virtual ~dbFieldSorter() {};
virtual void describe(ostream&) const;
virtual dbSorter* clone() const;
virtual void sortNow(OOF_tableBackend*);
virtual unsigned short sortFieldNo() const;
bool sortsInReverse() const;
virtual bool sortsBySingleField() const;
void changeSortFieldTo(fieldNumT, bool shouldReverse=false);
protected:
// data storage
fieldNumT mSortFieldNo;
bool mReverseSort;
};
/**
Stack class to temporarily suspend sorting.
\ingroup oofDatabase
*/
class OOFILE_EXPORT stSuspendSort {
public:
stSuspendSort(dbTable*);
~stSuspendSort();
private:
dbTable* mTable;
};
/**
Stack class to combine stSuspendSort and stSaveSelection.
\ingroup oofDatabase
*/
class OOFILE_EXPORT stSaveSelectionAndSuspendSort : public stSaveSelection {
public:
stSaveSelectionAndSuspendSort(dbTable*);
~stSaveSelectionAndSuspendSort();
};
#ifdef OOF_USING_EXCEPTIONS
/**
Stack class to temporarily lock a record.
\ingroup oofDatabase
*/
class stLockRecord {
public:
stLockRecord(dbTable* inTable);
stLockRecord(dbTable& inTable);
~stLockRecord();
private:
void InitLock();
dbTable* mTable;
};
#endif
#ifndef OOF_DISALLOW_CHANGE_SHIELDING
/**
Stack class to enable Change Shielding, so listeners not informed database changed.
Very useful for background manipulation on GUI screens to avoid flicker.
\ingroup oofDatabase
*/
class stChangeShielded {
public:
stChangeShielded(dbTable* inTable);
stChangeShielded(dbTable& inTable);
~stChangeShielded();
private:
dbTable* mTable;
};
#endif
/**
Cleanup after cloning a dbTable to get separate iterator.
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbCloneCleanup : public oofSingleListener {
public:
dbCloneCleanup(dbTable* listensTo);
// use default copy ctor
virtual ~dbCloneCleanup() {};
virtual bool receiveMsg(OOFmsgT msg, unsigned long senderDefined);
// data storage
private:
dbTable* mTable;
};
class OOF_RelMN; // forward
/**
listener for an MN link that adds and deletes records.
Acts in response to OOF_AppendSelection, RemoveSelection, ClearSelection
and is often used in GUI applications where the user can create M:N links
between tables, eg: by drag and drop to indicate an association.
\ingroup oofDatabase
*/
class OOFILE_EXPORT dbRelMaintainer : public oofSingleListener {
public:
dbRelMaintainer(dbRelRefBase* relToRHS, OOF_RelMN* linkWeAlert);
// use default copy ctor
virtual ~dbRelMaintainer();
virtual bool receiveMsg(OOFmsgT msg, unsigned long senderDefined);
// data storage
private:
OOF_RelMN* mLink;
};
// utility functions
bool skipTillDigit(istream&, char fieldSep=dbTable::kFieldSep, char recSep=dbTable::kRecSep);
bool skipRestOfField(istream&, char fieldSep=dbTable::kFieldSep, char recSep=dbTable::kRecSep);
bool skipTillNumber(istream& is, char fieldSep, char recSep, bool canStartWithDecimal=false);
// -------------------------------------------------------
// O O F _ D i c t r e p
// -------------------------------------------------------
inline
OOF_bitPointer& OOF_DictRep::item(unsigned int index)
{
return operator[](index);
}
// -------------------------------------------------------
// O O F _ D i c t i o n a r y
// -------------------------------------------------------
inline unsigned int
OOF_Dictionary::iter() const
{
return mInternalIter;
}
inline unsigned int
OOF_Dictionary::count() const
{
return mRep->mNextFreeEntry;
}
inline void
OOF_Dictionary::start()
{
mInternalIter = 0;
}
inline bool
OOF_Dictionary::more() const
{
return mInternalIter < mRep->mNextFreeEntry;
}
inline void
OOF_Dictionary::next()
{
mInternalIter++;
}
inline bool
OOF_Dictionary::EntryMatchesVisibility(const OOF_PublicBase* entry, bool wantVisible) const
{
bool isVisible = !entry->hidden();
return ((isVisible && wantVisible) || (!isVisible && !wantVisible));
}
inline void
OOF_Dictionary::startVisible(bool wantVisible)
{
start();
moreVisible(wantVisible);
}
inline void
OOF_Dictionary::nextVisible(bool wantVisible)
{
next();
moreVisible(wantVisible);
}
inline void
OOF_Dictionary::append(OOF_bitPointer aBit)
{
mRep->Append(aBit);
}
inline OOF_bitPointer
OOF_Dictionary::pop()
{
return mRep->Pop();
}
inline void
OOF_Dictionary::reset()
{
mRep->Reset();
}
inline OOF_bitPointer&
OOF_Dictionary::operator()() // current value
{
return mRep->operator[](mInternalIter);
}
/*
inline OOF_bitPointer&
OOF_Dictionary::operator[](int index)
{
assert(index>=0);
return mRep->item(index);
}
*/
inline OOF_bitPointer&
OOF_Dictionary::item(unsigned int index)
{
return mRep->item(index);
}
inline OOF_bitPointer
OOF_Dictionary::value(unsigned int index) const
{
return mRep->value(index);
}
inline OOF_bitPointer&
OOF_Dictionary::operator[](const char *name)
{
return mRep->operator[](name);
}
inline OOF_bitPointer&
OOF_Dictionary::operator[](unsigned int index)
{
return mRep->operator[](index);
}
inline OOF_bitPointer&
OOF_Dictionary::lookupByAttribute(const char* attributeValue, const char* attributeType)
{
return mRep->lookupByAttribute(attributeValue, attributeType);
}
inline OOF_bitPointer&
OOF_Dictionary::missingItem()
{
return sMissingItem;
}
// -------------------------------------------------------
// d b C o n n e c t
// -------------------------------------------------------
inline dbConnect*
dbConnect::currentlyConstructing()
{
return sCurrentlyConstructing;
}
inline const oofString&
dbConnect::connectionName() const
{
return mConnectionName;
}
inline unsigned int
dbConnect::numTables() const
{
return mTables.count();
}
inline bool
dbConnect::underConstruction()
{
return sCurrentlyConstructing!=0;
}
inline void
dbConnect::truncateTrailingSpaces(bool willTruncate)
{
sTruncateTrailingSpaces = willTruncate;
}
inline bool
dbConnect::willTruncateTrailingSpaces()
{
return sTruncateTrailingSpaces;
}
#ifdef OOF_DEBUG_LOG_NAME
inline ostream&
dbConnect::debugLog()
{
return sDebugLog;
}
#endif
inline oofDirectory*
dbConnect::databaseDirectory() const
{
return mDatabaseDir;
}
inline bool
dbConnect::isOpen() const
{
return mOpen;
}
/**
Connection has been declared but not opened or created.
Only one connection at a time can be in this state.
\todo cope if declare 2nd connections before opening either, which is legal.
*/
inline bool
dbConnect::inDeclarativePhase() const
{
return sCurrentlyConstructing == this;
}
// -------------------------------------------------------
// O O F _ t a b l e B a c k e n d
// -------------------------------------------------------
inline void
OOF_tableBackend::markDirty()
{
mDirty=true;
}
inline bool
OOF_tableBackend::isDirty() const
{
return mDirty;
}
inline dbTable*
OOF_tableBackend::table() const
{
return mTable;
}
inline dbField*
OOF_tableBackend::field(fieldNumT fieldNum) const
{
return (dbField *) mFields.value(fieldNum); // safe downcast
}
inline void
OOF_tableBackend::fieldHasDefaultCalculator(dbField*)
{
mHasDefaultCalculators = true;
}
inline void
OOF_tableBackend::fieldHasStoredCalculator(dbField*)
{
mHasStoredCalculators = true;
}
// -------------------------------------------------------
// d b T a b l e A s s i g n e r
// -------------------------------------------------------
inline dbTableAssigner&
dbTableAssigner::operator<<(const char* inString)
{
setNextFieldString(inString);
return *this;
}
// -------------------------------------------------------
// d b T a b l e
// -------------------------------------------------------
#if 0
inline dbTable::operator dbTable*()
{
return this;
};
#endif
inline bool
dbTable::isOpen() const
{
return (mTableValid!=eClosed);
}
/**
Has database been opened or are we still potentially declaring tables.
Will be true before newConnection or openConnection has been called.
*/
inline bool
dbTable::inDeclarativePhase() const
{
return (!mConnection || mConnection->inDeclarativePhase());
}
inline bool
dbTable::isTableValid() const
{
return (mTableValid==eValid);
}
inline dbTable::tableValidT
dbTable::validStatus() const
{
return mTableValid;
}
inline int
dbTable::validatingDepth() const
{
return mValidatingDepth;
}
inline dbRelRefBase*
dbTable::controllingRelationship() const
{
return mRelToLHS;
}
inline bool
dbTable::isRecordLoaded() const
{
return mBackend->isRecordLoaded();
}
inline void
dbTable::noticeDuplicateRecords()
{
mBackend->noticeDuplicateRecords();
}
inline void
dbTable::ignoreDuplicateRecords()
{
mBackend->ignoreDuplicateRecords();
}
inline unsigned long
dbTable::sequenceNumber() const
{
return mBackend->sequenceNumber();
}
inline unsigned int
dbTable::numIndexes() const
{
return mBackend->numIndexes();
}
inline unsigned int
dbTable::numFiles() const
{
return mBackend->numFiles();
}
inline fieldNumT
dbTable::numFields() const
{
return mFieldCount;
}
/**
Force current table state to valid.
\warning do not use unless you know what you are doing.
*/
inline void
dbTable::setTableValid(bool validState)
{
#ifdef OOF_DEBUG_LOG_NAME
if (validState)
StandardDebugLog("dbTable::setTableValid(true)");
else
StandardDebugLog("dbTable::setTableValid(false)");
#endif
if (validState)
mTableValid = eValid;
else
mTableValid = eInvalid;
// can't set closed state - side-effect of close()
}
/**
When iterating a selection, are there any more records beyond current.
*/
inline bool
dbTable::more() const
{
return mBackend->more();
}
/**
Does the current selection represent all records or just a subset.
*/
inline bool
dbTable::allSelected() const
{
return mBackend->allSelected();
}
inline bool
dbTable::atFirst() const
{
return mBackend->atFirst();
}
inline bool
dbTable::atLast() const
{
return mBackend->atLast();
}
inline bool
dbTable::atRelative(unsigned long rel) const
{
return mBackend->atRelative(rel);
}
/**
Absolute record address of current record.
Persistent value can be used between application runs.
*/
inline oidT
dbTable::currentOID()
{
if (!isTableValid())
MakeTableValid();
return mBackend->currentOID();
}
/**
Check if current selection contains an OID.
Use with selectAll to see if OID is anywhere in database.
*/
inline bool
dbTable::contains(oidT inOID)
{
if (!isTableValid())
MakeTableValid();
return mBackend->contains(inOID);
}
inline oidT
dbTable::oidOfRecord(unsigned long recno)
{
return mBackend->oidOfRecord(recno);
}
/**
Next record in the selection becomes current.
*/
inline void
dbTable::next()
{
#ifdef OOF_DEBUG_LOG_NAME
StandardDebugLog("dbTable::next()");
#endif
ContextChange();
mBackend->next();
}
/**
First record in the selection becomes current.
*/
inline void
dbTable::first()
{
ContextChange();
mBackend->gotoRecord(0);
}
/**
Previous record in the selection becomes current.
*/
inline void
dbTable::prev()
{
ContextChange();
mBackend->prev();
}
/**
Last record in the selection becomes current.
*/
inline void
dbTable::last()
{
#ifdef OOF_DEBUG_LOG_NAME
StandardDebugLog("dbTable::last()");
#endif
ContextChange();
mBackend->gotoRecord(mBackend->count()-1);
}
inline void
dbTable::ensureSelectionLoaded()
{
if (!isTableValid())
MakeTableValid();
}
/**
Count records in current selection.
Includes current record even if new (ie: it has not had a record pointer saved to disk).
*/
inline unsigned long
dbTable::count()
{
if (!isTableValid())
MakeTableValid();
return mBackend->count();
}
/**
Count records in database regardless of current selection.
*/
inline unsigned long
dbTable::countAll() const
{
return mBackend->countAll();
}
/**
Ordinal record number of current record in selection.
zero-based, will change if selection sorted differently.
currentOID() returns absolute record address.
*/
inline unsigned long
dbTable::recordNumber() const
{
if (isRecordLoaded())
return mBackend->recordNumber();
else
return 0;
}
/**
Find ordinal position in ordered selection of record by OID.
\param oidT identifier (commonly record address) of desired record
\todo decide if should return standard enum value for not found.
*/
inline unsigned long
dbTable::recordNumberOfOID(oidT inOID)
{
return mBackend->recordNumberOfOID(inOID);
}
inline unsigned long
dbTable::recordNumber(const dbQueryClause* qClause, bool* outFoundIt) const
{
return mBackend->recordNumberMatching(qClause, outFoundIt);
}
inline unsigned long
dbTable::recordNumber(const dbQueryClause& qClause, bool* outFoundIt) const
{
return mBackend->recordNumberMatching(&qClause, outFoundIt);
}
inline void
dbTable::difference_with(dbTable* rhs)
{
difference_with(*rhs);
}
/**
Operator performing difference_with set operation.
*/
inline void
dbTable::operator-=(dbTable* rhs)
{
difference_with(*rhs);
}
/**
Operator performing difference_with set operation.
*/
inline void
dbTable::operator-=(dbTable& rhs)
{
difference_with(rhs);
}
/**
Operator performing difference_with set operation.
*/
inline void
dbTable::operator-=(const dbSelection& rhs)
{
difference_with(rhs);
}
/**
Operator performing difference_with set operation.
*/
inline void
dbTable::operator%=(const dbSelection& rhs)
{
difference_with(rhs);
}
/**
Operator performing difference_with set operation.
*/
inline void
dbTable::operator%=(dbTable& rhs)
{
difference_with(rhs);
}
/**
Operator performing difference_with set operation.
*/
inline void
dbTable::operator%=(dbTable* rhs)
{
difference_with(*rhs);
}
inline void
dbTable:: intersection_with(dbTable* rhs)
{
intersection_with(*rhs);
}
/**
Operator performing intersection_with set operation.
*/
inline void
dbTable:: operator&=(dbTable& rhs)
{
intersection_with(rhs);
}
/**
Operator performing intersection_with set operation.
*/
inline void
dbTable:: operator&=(const dbSelection& rhs)
{
intersection_with(rhs);
}
/**
Operator performing intersection_with set operation.
*/
inline void
dbTable:: operator&=(dbTable* rhs)
{
intersection_with(*rhs);
}
/**
Operator performing invert set operation.
*/
inline void
dbTable::operator!()
{
invert();
}
/**
Operator performing invert set operation.
*/
inline void
dbTable::operator~()
{
invert();
}
inline void
dbTable::union_with(dbTable* rhs)
{
union_with(*rhs);
}
inline void
dbTable::union_with_no_overlap(dbTable* rhs)
{
union_with_no_overlap(*rhs);
}
/**
Operator performing union_with set operation.
*/
inline void
dbTable::operator+=(dbTable& rhs)
{
union_with(rhs);
}
/**
Operator performing union_with set operation.
*/
inline void
dbTable::operator+=(const dbSelection& rhs)
{
union_with(rhs);
}
/**
Operator performing union_with set operation.
*/
inline void
dbTable::operator+=(dbTable* rhs)
{
union_with(*rhs);
}
/**
Operator performing union_with set operation.
*/
inline void
dbTable::operator|=(dbTable* rhs)
{
union_with(*rhs);
}
/**
Operator performing union_with set operation.
*/
inline void
dbTable::operator|=(dbTable& rhs)
{
union_with(rhs);
}
/**
Operator performing union_with set operation.
*/
inline void
dbTable::operator|=(const dbSelection& rhs)
{
union_with(rhs);
}
/**
Operator performing addOIDtoSelection set operation like union_with.
*/
inline bool
dbTable::operator+=(oidT rhs)
{
return addOIDtoSelection(rhs);
}
/**
Create dbTableAssigner as fast way to create and set entire record.
Allows you to pass in all fields as text strings, eg:
\code
People << "Andy" << "Dent" << "37";
\endcode
*/
inline dbTableAssigner
dbTable::operator<<(const char* inString)
{
return dbTableAssigner(this, inString);
}
/**
Change the current selection to all records.
This state is explicitly tracked as it allows backends to maintain
an optimal representation, eg: not needing to retain a list of record pointers.
*/
inline void
dbTable::selectAll()
{
#ifdef OOF_DEBUG_LOG_NAME
StandardDebugLog("dbTable::selectAll()");
#endif
mBackend->selectAll();
broadcast(OOFmsg_ChangeSelection);
}
/**
Change the current selection to no records.
This empty set is what would be returned by an unsuccessful search().
\see isEmpty()
*/
inline void
dbTable::selectNone()
{
#ifdef OOF_DEBUG_LOG_NAME
StandardDebugLog("dbTable::selectNone()");
#endif
mBackend->selectNone();
unloadRecord();
broadcast(OOFmsg_ChangeSelection);
}
inline bool
dbTable::isDirty() const
{
return mBackend->isDirty();
}
inline bool
dbTable::isNewRecord() const
{
return mBackend->isNewRecord();
}
inline bool
dbTable::isRelatedClone() const
{
return (mRelToLHS!=0);
}
inline dbField*
dbTable::field(fieldNumT fieldNum) const
{
return (dbField *) mFields.value(fieldNum); // safe downcast
}
inline dbField*
dbTable::field(const oofString& fieldName)
{
return (dbField *) mFields[fieldName];
}
inline const oofString&
dbTable::tableName() const
{
return mTableName;
}
inline tableNumT
dbTable::tableNumber() const
{
return mTableNumber;
}
inline bool
dbTable::tableCachesDirtyRecords() const
{
bool ret = (
(mSaveOption == dbTable::requireExplicitAndBuffer) ||
(mSaveOption == dbTable::bufferForever) )
;
return ret;
}
inline dbTable::saveOptionsT
dbTable::tableSaveOption() const
{
return mSaveOption;
}
inline void
dbTable::setName(const char* name)
{
mTableName = name;
}
inline void
dbTable::setFileExtensions(const char* dataExt, const char* indexExt)
{
mBackend->setFileExtensions(dataExt, indexExt);
}
inline dbSorter*
dbTable::sorter() const
{
return mBackend->sorter();
}
/**
Change the current selection to just the current record.
This makes a selection behave like a single object.
*/
inline void
dbTable::selectJustCurrent()
{
#ifdef OOF_DEBUG_LOG_NAME
StandardDebugLog("dbTable::selectJustCurrent()");
#endif
mBackend->selectJustCurrent();
broadcast(OOFmsg_ChangeSelection);
}
inline void
dbTable::lockRecord()
{
if (!mLockedCurrentRecord)
mBackend->lockRecord(); // may throw OOFE_LockedRecord if already locked
mLockedCurrentRecord = true;
}
inline void
dbTable::unlockRecord()
{
if (mLockedCurrentRecord)
mBackend->unlockRecord();
mLockedCurrentRecord =false;
}
inline bool
dbTable::transactionDirty()
{
return mTransactionDirty;
}
inline void
dbTable::pack()
{
mBackend->pack();
}
inline bool
dbTable::lockedCurrentRecord() const
{
return mLockedCurrentRecord;
}
inline dbTable*
dbTable::prototype() const
{
return mPrototype;
}
#ifndef OOF_DISALLOW_CHANGE_SHIELDING
/**
change shielding, so field changes don't mark the record as dirty.
(default is false)
Used when we don't want operations to propagate, eg: if updating
a field and need to finish some local op before related data updates.
*/
inline bool
dbTable::changeShielded() const
{
return mChangeShielded;
}
inline void
dbTable::changeShielded(bool setShielding)
{
mChangeShielded = setShielding;
}
#endif
inline
void dbTable::describeInvariant(ostream& os) const
{
mBackend->describeInvariant(os);
}
// -------------------------------------------------------
// O O F _ t a b l e B a c k e n d
// -------------------------------------------------------
// just the methods that have to be after dbTable inlines above
inline bool
OOF_tableBackend::tableCachesDirtyRecords() const
{
const bool ret = mTable->tableCachesDirtyRecords();
return ret;
}
// -------------------------------------------------------
// d b S o r t e r
// -------------------------------------------------------
inline bool
dbSorter::sortingSuspended() const
{
return mSuspended;
}
inline void
dbSorter::setSortOnSaves(bool onSaves)
{
mSortOnSaves = onSaves;
}
inline dbSorter&
dbSorter::operator<<(dbField& segField)
{
addSegment(segField);
return *this;
}
// -------------------------------------------------------
// O O F _ D i c t i o n a r y
// -------------------------------------------------------
inline void
OOF_Dictionary::ownsContents(bool ownsFlag)
{
mOwnsContents = ownsFlag;
}
// -------------------------------------------------------
// d b F i e l d S o r t e r
// -------------------------------------------------------
inline bool
dbFieldSorter::sortsInReverse() const
{
return mReverseSort;
}
// -------------------------------------------------------
// O O F _ F i e l d S e g O w n e r
// -------------------------------------------------------
inline unsigned short
OOF_FieldSegOwner::countSegments() const
{
return mSegments.count();
}
inline OOF_FieldSegOwner&
OOF_FieldSegOwner::operator<<(dbField& segField)
{
addSegment(segField);
return *this;
}
inline OOF_Segment*
OOF_FieldSegOwner::segment(unsigned int i) const
{
assert(i<mSegments.count());
return (OOF_Segment*)(mSegments.value(i)); // safe downcast
}
// -------------------------------------------------------
// o o f R u n t i m e E n v
// -------------------------------------------------------
inline bool
oofRuntimeEnv::isMacintosh()
{
#ifdef _Macintosh
return true;
#else
return false;
#endif
}
inline bool
oofRuntimeEnv::isWindows()
{
#ifdef _Windows
return true;
#else
return false;
#endif
}
inline bool
oofRuntimeEnv::isUnix()
{
#ifdef _Unix
return true;
#else
return false;
#endif
}
inline const char*
oofRuntimeEnv::termForLink()
{
#ifdef _Macintosh
return "alias";
#elif defined _Windows
return "shortcut";
#elif defined _Unix
return "link";
#else
error platform unknown
#endif
}
inline void
oofRuntimeEnv::spendBackgroundTime()
{
#ifdef _Macintosh
EventRecord ev;
::WaitNextEvent(everyEvent, &ev, 0x0, NULL);
#elif defined _Windows
// NOT YET IMPLEMENTED
#elif defined _Unix
// don't need to spend background time??
#else
error platform unknown
#endif
}
#endif