Compare commits
683 Commits
wagic-v0.1
...
SDL_build
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25c844c1f5 | ||
|
|
34492d9096 | ||
|
|
30d92eb68c | ||
|
|
6e6a0fd5c2 | ||
|
|
cd4a980182 | ||
|
|
aad54fd98d | ||
|
|
6b7a49506c | ||
|
|
7ecf67c176 | ||
|
|
77aeb2d0ac | ||
|
|
7a9f989104 | ||
|
|
ae06bebd24 | ||
|
|
042fb7b376 | ||
|
|
c3583ade01 | ||
|
|
f97d9805dd | ||
|
|
1d33de59a9 | ||
|
|
0c4b09891b | ||
|
|
25955303e7 | ||
|
|
27b75eecb0 | ||
|
|
e40921cf13 | ||
|
|
083cebcc7e | ||
|
|
a722736335 | ||
|
|
c483c20c81 | ||
|
|
dec1caa43c | ||
|
|
9526e22118 | ||
|
|
d9816c7ad0 | ||
|
|
8e327a27df | ||
|
|
43fe67d7d8 | ||
|
|
a63991bb4e | ||
|
|
b09db0c60f | ||
|
|
928ca3497a | ||
|
|
60219411f6 | ||
|
|
642f5bb515 | ||
|
|
20e878a102 | ||
|
|
da31371d86 | ||
|
|
0df408793a | ||
|
|
9630bcd56b | ||
|
|
3c38e21b25 | ||
|
|
caec886e22 | ||
|
|
927f8955e9 | ||
|
|
d4e0296d2b | ||
|
|
8eb664f93d | ||
|
|
b180c3d1a7 | ||
|
|
db9f18a644 | ||
|
|
95805ea387 | ||
|
|
4765890d0a | ||
|
|
2e13f29945 | ||
|
|
22b1c3b5d8 | ||
|
|
c7bae65697 | ||
|
|
2381f0306c | ||
|
|
b12e15e4ff | ||
|
|
9e21751e12 | ||
|
|
db60c38eda | ||
|
|
1a4327a2e6 | ||
|
|
88095c67b8 | ||
|
|
ec34380668 | ||
|
|
89dcd6c71d | ||
|
|
fd3cf574cf | ||
|
|
f21452feec | ||
|
|
0f85471216 | ||
|
|
5d92553017 | ||
|
|
f0e6d820c7 | ||
|
|
545fc21260 | ||
|
|
8b68568106 | ||
|
|
739a5d9e2b | ||
|
|
4c627f74b6 | ||
|
|
1e610ff653 | ||
|
|
5d6557a49f | ||
|
|
7528329a58 | ||
|
|
c62597dce5 | ||
|
|
d8dfcdba67 | ||
|
|
7b5f00260b | ||
|
|
f9dc551942 | ||
|
|
718ceca919 | ||
|
|
89fb76a8e7 | ||
|
|
1cc65ab611 | ||
|
|
3b22354ad9 | ||
|
|
2b9977a334 | ||
|
|
12c5f31562 | ||
|
|
8cfd887375 | ||
|
|
292bf7b1d2 | ||
|
|
4041fe690b | ||
|
|
cb73e2b90d | ||
|
|
a1fa36a934 | ||
|
|
bdd0e6c042 | ||
|
|
ee217e94a8 | ||
|
|
38e19f7d35 | ||
|
|
0bbfd00d15 | ||
|
|
aaceb3c038 | ||
|
|
5efa7e10bd | ||
|
|
14c164364e | ||
|
|
4514725aba | ||
|
|
2b0f50bb88 | ||
|
|
a65fc0c0f0 | ||
|
|
99db363253 | ||
|
|
c25dfec67e | ||
|
|
dd7210d187 | ||
|
|
904b7a6d86 | ||
|
|
31b353c5ec | ||
|
|
0d350af1b6 | ||
|
|
3bc9c93bab | ||
|
|
2002bb4e16 | ||
|
|
7e9c4ddbdd | ||
|
|
12b71de63c | ||
|
|
15011961f4 | ||
|
|
b851103711 | ||
|
|
67b8af8d15 | ||
|
|
8100e390b1 | ||
|
|
72e6876001 | ||
|
|
96aeaffa1b | ||
|
|
74faa35b91 | ||
|
|
8bb58ca3b1 | ||
|
|
93d1a637b6 | ||
|
|
30e86ffcd8 | ||
|
|
cbe6c0c842 | ||
|
|
77eb7f2777 | ||
|
|
077ab10c05 | ||
|
|
1194463349 | ||
|
|
8de50532f2 | ||
|
|
334454655d | ||
|
|
d8d52e185d | ||
|
|
9f1d225259 | ||
|
|
0c72bfd4c4 | ||
|
|
55e0366f19 | ||
|
|
667b95f2b8 | ||
|
|
e90f6fe224 | ||
|
|
2289fffb8d | ||
|
|
826403a512 | ||
|
|
35fec3d9a0 | ||
|
|
e9eb86488e | ||
|
|
ae97abbf96 | ||
|
|
a8391112b0 | ||
|
|
4257592568 | ||
|
|
657479e0e4 | ||
|
|
9e969881fd | ||
|
|
2b434a7182 | ||
|
|
d2e41f98c3 | ||
|
|
318fc98a39 | ||
|
|
b7a4b7f6b9 | ||
|
|
ed03fb744d | ||
|
|
02be213d1e | ||
|
|
0d4db9ee54 | ||
|
|
ae927576c5 | ||
|
|
f08ddac77b | ||
|
|
9effa7c975 | ||
|
|
a70259b5ba | ||
|
|
bf0a0a1580 | ||
|
|
eb8b22b2d5 | ||
|
|
4095676b6b | ||
|
|
bedd1e8da8 | ||
|
|
965d4f6d45 | ||
|
|
0db2925e7a | ||
|
|
031f2dbffb | ||
|
|
dbece750f8 | ||
|
|
6699902c24 | ||
|
|
e8407caa2a | ||
|
|
69c6745f53 | ||
|
|
6f083389c2 | ||
|
|
9ee44ca091 | ||
|
|
3f0dd987f0 | ||
|
|
672b0be7bd | ||
|
|
9d5a83d588 | ||
|
|
5d0d130587 | ||
|
|
c85d857604 | ||
|
|
f68568cc1e | ||
|
|
89206b3a6b | ||
|
|
dc118c64b8 | ||
|
|
a43854420d | ||
|
|
a695323bc7 | ||
|
|
02a65ecd82 | ||
|
|
9ff087ecde | ||
|
|
47685f4892 | ||
|
|
7aaebdc661 | ||
|
|
8aa0b8cea0 | ||
|
|
fac44c4b48 | ||
|
|
9889186eab | ||
|
|
73f9319b92 | ||
|
|
fd6bc95539 | ||
|
|
0bb211a581 | ||
|
|
e0428ac7b0 | ||
|
|
3e94de985f | ||
|
|
9f0b70d1c9 | ||
|
|
1e8fc81aa3 | ||
|
|
352e3c2daa | ||
|
|
678a4734bb | ||
|
|
052e3abdb8 | ||
|
|
73c2d17080 | ||
|
|
ffbb228d2d | ||
|
|
306765c6b6 | ||
|
|
3cee80e3bc | ||
|
|
8209716fc9 | ||
|
|
e76c57d747 | ||
|
|
9c282aeb56 | ||
|
|
bbc310dec7 | ||
|
|
a37af1776a | ||
|
|
35697a65b4 | ||
|
|
6bed1666be | ||
|
|
f021866368 | ||
|
|
d7e527166c | ||
|
|
071a487100 | ||
|
|
f370899a8a | ||
|
|
331e126787 | ||
|
|
6c41e5c92c | ||
|
|
82e3ab3977 | ||
|
|
f2314ca673 | ||
|
|
94c3ac9ad9 | ||
|
|
5419d87e4e | ||
|
|
e1213d1c1f | ||
|
|
446ed20758 | ||
|
|
7a48c5e087 | ||
|
|
3ca2f1c1ed | ||
|
|
146872797b | ||
|
|
c6dc51c7d3 | ||
|
|
0ef92d154a | ||
|
|
2835bdf767 | ||
|
|
afc903e31b | ||
|
|
6294bb1eed | ||
|
|
9f16b2208d | ||
|
|
0a765b702b | ||
|
|
82de6f2840 | ||
|
|
90652fa73d | ||
|
|
e8c73aaf9d | ||
|
|
f95094a429 | ||
|
|
7a57de6608 | ||
|
|
14c2d522c2 | ||
|
|
6bf2147d94 | ||
|
|
fea5b04a77 | ||
|
|
ea98b769a7 | ||
|
|
017f6dd1ed | ||
|
|
784d127a6e | ||
|
|
f6c47b85e3 | ||
|
|
dac31994b6 | ||
|
|
74280aef1d | ||
|
|
8013d09e4f | ||
|
|
6bbe290762 | ||
|
|
57c9940244 | ||
|
|
db1c552321 | ||
|
|
f08f0ad3b9 | ||
|
|
a3a1bc2b79 | ||
|
|
9037699281 | ||
|
|
8d66f82179 | ||
|
|
eeb4a4e755 | ||
|
|
38725aaeac | ||
|
|
ed474d6b5d | ||
|
|
b17d9d3f85 | ||
|
|
c5190a62cd | ||
|
|
89472eeccd | ||
|
|
2b4404f352 | ||
|
|
84ca7457b5 | ||
|
|
4eb1fd35e0 | ||
|
|
362cc1b4c2 | ||
|
|
82171773fe | ||
|
|
224c94e890 | ||
|
|
7a7bc70773 | ||
|
|
1401fef37e | ||
|
|
cf50b7d403 | ||
|
|
b8b6153cc5 | ||
|
|
461eedd626 | ||
|
|
f0977ebc04 | ||
|
|
e38f42d854 | ||
|
|
4ac376b5f2 | ||
|
|
1f0485ff8e | ||
|
|
98861dd916 | ||
|
|
b5794ad328 | ||
|
|
38b4213f9c | ||
|
|
f1a9f0d162 | ||
|
|
e62feddaf4 | ||
|
|
5c3eb2c405 | ||
|
|
f7eded7417 | ||
|
|
d5b089f86b | ||
|
|
1d3c4bcd69 | ||
|
|
9d2a2454b2 | ||
|
|
173f787fac | ||
|
|
0ac6057ee9 | ||
|
|
8b16074647 | ||
|
|
62dad30f6b | ||
|
|
43ba9aa13d | ||
|
|
ea217fdba1 | ||
|
|
eea88cdeb5 | ||
|
|
0c6d77daa0 | ||
|
|
4341e23210 | ||
|
|
80be19db86 | ||
|
|
1da9f5a4af | ||
|
|
fa5aedfe64 | ||
|
|
17fdedb648 | ||
|
|
da7c336dc2 | ||
|
|
be76c8a4f1 | ||
|
|
490752e9da | ||
|
|
7894ca3ace | ||
|
|
d4268f18af | ||
|
|
3761684816 | ||
|
|
f10eb609d7 | ||
|
|
00ebc8c8eb | ||
|
|
36cfe84445 | ||
|
|
54d1126c58 | ||
|
|
11f541a627 | ||
|
|
93ebca3041 | ||
|
|
ce7689c8c6 | ||
|
|
de8309a7c2 | ||
|
|
ec11bf917d | ||
|
|
8626451977 | ||
|
|
4aa5dec51a | ||
|
|
3c3fcfc655 | ||
|
|
bd25b12fb2 | ||
|
|
7b8189bd13 | ||
|
|
a2d020b2ae | ||
|
|
20eda1560b | ||
|
|
7917a70b1b | ||
|
|
2fa3f468b4 | ||
|
|
1851f3c7a6 | ||
|
|
45711bb504 | ||
|
|
f1d88611cb | ||
|
|
b61cd2f69a | ||
|
|
ece78395f4 | ||
|
|
95bbe06c7e | ||
|
|
b3f81e95bb | ||
|
|
3c63b152a6 | ||
|
|
26ab65860e | ||
|
|
7990540096 | ||
|
|
1442b73029 | ||
|
|
fee9ee756c | ||
|
|
a400cabfc7 | ||
|
|
8a7d5f4490 | ||
|
|
b0a1e670ba | ||
|
|
b5906a4299 | ||
|
|
b7324280aa | ||
|
|
f0de00086b | ||
|
|
a055044281 | ||
|
|
4b167c3776 | ||
|
|
cf74c3480e | ||
|
|
ba5debad05 | ||
|
|
4f915b38c8 | ||
|
|
c286aa02a6 | ||
|
|
3171c62089 | ||
|
|
819ddd0496 | ||
|
|
c15d0ec523 | ||
|
|
5da2033d74 | ||
|
|
f449ec5fdd | ||
|
|
ee310b7bb3 | ||
|
|
b50eaf83a1 | ||
|
|
79fca90db9 | ||
|
|
d8b77bf796 | ||
|
|
fa07242370 | ||
|
|
6626b52e3a | ||
|
|
86d748bc43 | ||
|
|
4f8d5b3300 | ||
|
|
0908c76434 | ||
|
|
1edd1546a2 | ||
|
|
c2abc6e4a8 | ||
|
|
7905ed1533 | ||
|
|
f6f75ca660 | ||
|
|
9f6a728150 | ||
|
|
54021a7f75 | ||
|
|
9f89353b4b | ||
|
|
9fa9e1eb81 | ||
|
|
e54d212418 | ||
|
|
07fdf735f5 | ||
|
|
a7e9fe6699 | ||
|
|
f3df94b319 | ||
|
|
aa51083b2b | ||
|
|
0c8f1e1573 | ||
|
|
386fc08e3a | ||
|
|
a40c677f1e | ||
|
|
38a203aac8 | ||
|
|
2349908f66 | ||
|
|
30d3b52a9e | ||
|
|
107874d88e | ||
|
|
f0a6770948 | ||
|
|
14c605f2a6 | ||
|
|
8dcd261258 | ||
|
|
537f994ae4 | ||
|
|
6403f75769 | ||
|
|
e076e64d97 | ||
|
|
8deb0537a8 | ||
|
|
83ef3aa08c | ||
|
|
305bdb386b | ||
|
|
ad855ce8d1 | ||
|
|
150c28ae72 | ||
|
|
2a25db403d | ||
|
|
80501edc2a | ||
|
|
d7c1868de3 | ||
|
|
7b11ede1d5 | ||
|
|
e8ee356892 | ||
|
|
dd68023249 | ||
|
|
96adbabea8 | ||
|
|
89ae87cc3d | ||
|
|
8c80efbe2a | ||
|
|
9ffe7349e2 | ||
|
|
f9410f695a | ||
|
|
7c8d3cedbd | ||
|
|
49b6b028c5 | ||
|
|
1bea0736a5 | ||
|
|
1c61ebddae | ||
|
|
6727c1af52 | ||
|
|
ce656adeba | ||
|
|
2a7bcb2170 | ||
|
|
5789d0cae4 | ||
|
|
80e36c2b92 | ||
|
|
c9360eb005 | ||
|
|
734b142879 | ||
|
|
bfb88f1bb5 | ||
|
|
802c970ec3 | ||
|
|
b38d6c6bc5 | ||
|
|
701ca64e8a | ||
|
|
810c3967d6 | ||
|
|
c994886ca8 | ||
|
|
2c0e0c7251 | ||
|
|
b6a4197d88 | ||
|
|
e2f4dd7095 | ||
|
|
0578ebde80 | ||
|
|
9b44d627a3 | ||
|
|
8b626b378f | ||
|
|
b436550150 | ||
|
|
c2132ab97f | ||
|
|
22640130dc | ||
|
|
90a0f5c86f | ||
|
|
3cb0a6c091 | ||
|
|
1818a8be82 | ||
|
|
9c0ce5f7bf | ||
|
|
31ee6d2b90 | ||
|
|
d4ff6d1453 | ||
|
|
a7aeb7efe5 | ||
|
|
cd54ad7012 | ||
|
|
04dce1ad50 | ||
|
|
ef18f376b1 | ||
|
|
f9bd6e1c44 | ||
|
|
e8f8aae43f | ||
|
|
b4d4515e01 | ||
|
|
9a52ae28a2 | ||
|
|
2330e6a613 | ||
|
|
620c5595d9 | ||
|
|
a5ea3275cd | ||
|
|
bf677b7bdd | ||
|
|
026600c084 | ||
|
|
a1a16fce57 | ||
|
|
defb8e32c6 | ||
|
|
8aef74e32a | ||
|
|
fbc1b14dca | ||
|
|
e24f269c36 | ||
|
|
3c15357c38 | ||
|
|
2b4c3a51aa | ||
|
|
f0405342be | ||
|
|
d2f14897a6 | ||
|
|
8b7c0e6b83 | ||
|
|
f7116a84b4 | ||
|
|
dff6302773 | ||
|
|
b88b217c46 | ||
|
|
13c10ec856 | ||
|
|
54780d3ef0 | ||
|
|
cea9f0d8ae | ||
|
|
3daa0eec7d | ||
|
|
101dd163a3 | ||
|
|
c33ae31895 | ||
|
|
cbe6028a52 | ||
|
|
e424c3ab27 | ||
|
|
1d06a74fd9 | ||
|
|
81294a0d2b | ||
|
|
ae8893617f | ||
|
|
38895dfcd3 | ||
|
|
90c0b42a07 | ||
|
|
7e16b50fd3 | ||
|
|
5a9b7eefc0 | ||
|
|
5c25189aef | ||
|
|
452ae08593 | ||
|
|
b85f2240a7 | ||
|
|
6928df6819 | ||
|
|
6fa633f822 | ||
|
|
2b9fdc41dc | ||
|
|
ef4a8c6d84 | ||
|
|
44fa0e9015 | ||
|
|
a8ebaee527 | ||
|
|
cca8f1ce4e | ||
|
|
a8c6da03a8 | ||
|
|
6a1591d72b | ||
|
|
fa5e3ad9b4 | ||
|
|
0095dcceb5 | ||
|
|
6c86c276d2 | ||
|
|
0bd769d3c0 | ||
|
|
94955088c8 | ||
|
|
7de5cfbd37 | ||
|
|
ea0a3efc38 | ||
|
|
6e7c57151c | ||
|
|
2ef93bc722 | ||
|
|
21897f2f63 | ||
|
|
de16c53534 | ||
|
|
a83e029ca6 | ||
|
|
aadd0c56b2 | ||
|
|
29c50becf0 | ||
|
|
dffecf7ee0 | ||
|
|
eab782c32f | ||
|
|
1b689adf05 | ||
|
|
c078af5f24 | ||
|
|
d07951fbdf | ||
|
|
415e8dbcb2 | ||
|
|
f8800b8bbd | ||
|
|
b7a2c000be | ||
|
|
12620e5d22 | ||
|
|
0a8c846f9a | ||
|
|
c7e1dfb72f | ||
|
|
47cfc5bdeb | ||
|
|
73131c8064 | ||
|
|
48d45f2a65 | ||
|
|
faff7724d6 | ||
|
|
f1fa655306 | ||
|
|
313598fab0 | ||
|
|
da186a6225 | ||
|
|
3ac3836538 | ||
|
|
2b9cae8950 | ||
|
|
a32a58f621 | ||
|
|
eaf4d94a2e | ||
|
|
dac14020a2 | ||
|
|
5fa1cc915b | ||
|
|
2fcd031a7d | ||
|
|
822c3bc9c8 | ||
|
|
b7c13825c5 | ||
|
|
534d87e3bd | ||
|
|
c1c6296c9c | ||
|
|
79d9ad865e | ||
|
|
d8da70361a | ||
|
|
f6e95af995 | ||
|
|
892c7d34c0 | ||
|
|
975445d3d5 | ||
|
|
eec9bb44a8 | ||
|
|
5b0f5bd90f | ||
|
|
3443c8d075 | ||
|
|
f45c8e1d41 | ||
|
|
db0f401ba5 | ||
|
|
f59b8db91f | ||
|
|
ed77b40a29 | ||
|
|
365fe10765 | ||
|
|
da2098368b | ||
|
|
2ba5eb0022 | ||
|
|
4bf419fbaf | ||
|
|
84950ad1f8 | ||
|
|
0db78c0444 | ||
|
|
f1032c64b5 | ||
|
|
78797356ea | ||
|
|
2c00d99563 | ||
|
|
798258798c | ||
|
|
fccedcaaab | ||
|
|
80cdd56971 | ||
|
|
ba682e4802 | ||
|
|
db0dae7f8d | ||
|
|
9db8478dfe | ||
|
|
ada0a1555d | ||
|
|
782a8305fe | ||
|
|
f04dfac4b5 | ||
|
|
0b4ebc6e51 | ||
|
|
cae9ff79d6 | ||
|
|
32d06d1148 | ||
|
|
1b7b1e2cf1 | ||
|
|
ca3dc49d71 | ||
|
|
0709aaefb8 | ||
|
|
69af807510 | ||
|
|
a9352a3b69 | ||
|
|
e67084afb9 | ||
|
|
fda7166752 | ||
|
|
5f90d1ee9f | ||
|
|
a26f872ff3 | ||
|
|
9201860744 | ||
|
|
a608de3b73 | ||
|
|
0a8a88f817 | ||
|
|
e1d2bf56c5 | ||
|
|
98ea63485d | ||
|
|
598ffb1f9b | ||
|
|
c3586126a5 | ||
|
|
cbcc5a57ca | ||
|
|
9b47a64fd9 | ||
|
|
83c0ee2c28 | ||
|
|
4be2c39566 | ||
|
|
1f8e1179cc | ||
|
|
2d11392e47 | ||
|
|
0fcfb43d3a | ||
|
|
2a1f29aebc | ||
|
|
e7dd2e02d6 | ||
|
|
da15bb7427 | ||
|
|
6410e25bcc | ||
|
|
14e0093eaf | ||
|
|
3b08a05421 | ||
|
|
f74e2019cc | ||
|
|
93c9f12eff | ||
|
|
80a3e37961 | ||
|
|
4e9dc2c3b1 | ||
|
|
b78c8084be | ||
|
|
8119f3bc05 | ||
|
|
0e4994c22c | ||
|
|
c6117fdfb3 | ||
|
|
1ff10ed4c7 | ||
|
|
d83415ed3b | ||
|
|
e69e002c1a | ||
|
|
e5b56cfffb | ||
|
|
eeb5a4235b | ||
|
|
2aed88a44f | ||
|
|
b007190d98 | ||
|
|
510a8c4222 | ||
|
|
e2be750780 | ||
|
|
38ebdde6ed | ||
|
|
579a651e3d | ||
|
|
a95a2c4dc2 | ||
|
|
edb3295af0 | ||
|
|
3b07ad6b7f | ||
|
|
5c0a69ea54 | ||
|
|
747eec8692 | ||
|
|
972e2b1ec2 | ||
|
|
4960969640 | ||
|
|
2fa626b80e | ||
|
|
1049f90aa2 | ||
|
|
a3017c215f | ||
|
|
ad50ce1d48 | ||
|
|
153203fba6 | ||
|
|
780afb6e0c | ||
|
|
0ebb151a66 | ||
|
|
0b1a88e3d7 | ||
|
|
1ad4948594 | ||
|
|
227cfc93f1 | ||
|
|
d9ec37e096 | ||
|
|
fd1becf59c | ||
|
|
b3195d6111 | ||
|
|
755a43bb2a | ||
|
|
08a7df0f19 | ||
|
|
02a7a7670a | ||
|
|
2aae7d2c17 | ||
|
|
35d32ff8fe | ||
|
|
05b775f50e | ||
|
|
76efffb295 | ||
|
|
fa5da87a98 | ||
|
|
238cd124ae | ||
|
|
123a6aa21f | ||
|
|
651d0b4623 | ||
|
|
2b4df1cc68 | ||
|
|
4ad4689603 | ||
|
|
a87377b25a | ||
|
|
ca446adf75 | ||
|
|
92a8ccebd8 | ||
|
|
8ac44677b8 | ||
|
|
a60a8af2b0 | ||
|
|
e809190a82 | ||
|
|
901abd688a | ||
|
|
ad055ad0b7 | ||
|
|
3b447135fb | ||
|
|
7583e61510 | ||
|
|
8035d0f3fc | ||
|
|
38cdec5126 | ||
|
|
78f5b11919 | ||
|
|
f5403b0e03 | ||
|
|
a42c6b00a8 | ||
|
|
68f76fbaff | ||
|
|
14695e7e5b | ||
|
|
63ea7f88e2 | ||
|
|
0b89f0571e | ||
|
|
0f5754c75a | ||
|
|
101582e37e | ||
|
|
fffe739ec1 | ||
|
|
d078872dfc | ||
|
|
6d4e677711 | ||
|
|
4c74ae06fd | ||
|
|
db2d3b895e | ||
|
|
51a6ac54f4 | ||
|
|
1454550a7b | ||
|
|
c85d07f890 | ||
|
|
23e4002a9a | ||
|
|
e38582a89a | ||
|
|
cf5a6f9059 | ||
|
|
bbf1de5134 | ||
|
|
ecdc1481b0 | ||
|
|
b3d28744c4 | ||
|
|
6172a0ade6 | ||
|
|
0dbcd86b89 | ||
|
|
7024d195fa | ||
|
|
591b1535a6 | ||
|
|
e29f95cb6c | ||
|
|
973a835181 | ||
|
|
a8492b7c5a | ||
|
|
6dafc098cb | ||
|
|
f87a81f7ea | ||
|
|
e14ec67a84 | ||
|
|
4540499b38 | ||
|
|
c10b5ce220 | ||
|
|
298231add1 | ||
|
|
113e5ba2b4 | ||
|
|
f9795661b8 | ||
|
|
a5195409c4 | ||
|
|
d37f44724b | ||
|
|
0d5e8e39c5 |
243
.gitignore
vendored
Normal file
243
.gitignore
vendored
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
#################
|
||||||
|
## Eclipse
|
||||||
|
#################
|
||||||
|
|
||||||
|
*.pydevproject
|
||||||
|
.project
|
||||||
|
.metadata
|
||||||
|
bin/
|
||||||
|
tmp/
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.classpath
|
||||||
|
.settings/
|
||||||
|
.loadpath
|
||||||
|
|
||||||
|
# External tool builders
|
||||||
|
.externalToolBuilders/
|
||||||
|
|
||||||
|
# Locally stored "Eclipse launch configurations"
|
||||||
|
*.launch
|
||||||
|
|
||||||
|
# CDT-specific
|
||||||
|
.cproject
|
||||||
|
|
||||||
|
# PDT-specific
|
||||||
|
.buildpath
|
||||||
|
|
||||||
|
|
||||||
|
#################
|
||||||
|
## Visual Studio
|
||||||
|
#################
|
||||||
|
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
|
||||||
|
[Dd]ebug/
|
||||||
|
[Rr]elease/
|
||||||
|
x64/
|
||||||
|
build/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlog
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.log
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
*.ncrunch*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.Publish.xml
|
||||||
|
*.pubxml
|
||||||
|
|
||||||
|
# NuGet Packages Directory
|
||||||
|
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||||
|
#packages/
|
||||||
|
|
||||||
|
# Windows Azure Build Output
|
||||||
|
csx
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Windows Store app package directory
|
||||||
|
AppPackages/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
sql/
|
||||||
|
*.Cache
|
||||||
|
ClientBin/
|
||||||
|
[Ss]tyle[Cc]op.*
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file to a newer
|
||||||
|
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
App_Data/*.mdf
|
||||||
|
App_Data/*.ldf
|
||||||
|
|
||||||
|
#############
|
||||||
|
## Windows detritus
|
||||||
|
#############
|
||||||
|
|
||||||
|
# Windows image file caches
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Mac crap
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
|
||||||
|
#############
|
||||||
|
## Python
|
||||||
|
#############
|
||||||
|
|
||||||
|
*.py[co]
|
||||||
|
|
||||||
|
# Packages
|
||||||
|
*.egg
|
||||||
|
*.egg-info
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
eggs/
|
||||||
|
parts/
|
||||||
|
var/
|
||||||
|
sdist/
|
||||||
|
develop-eggs/
|
||||||
|
.installed.cfg
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
.coverage
|
||||||
|
.tox
|
||||||
|
|
||||||
|
#Translations
|
||||||
|
*.mo
|
||||||
|
|
||||||
|
#Mr Developer
|
||||||
|
.mr.developer.cfg
|
||||||
|
|
||||||
|
|
||||||
|
#for XCode and MacOS
|
||||||
|
## Mac OS X
|
||||||
|
*.DS_Store
|
||||||
|
|
||||||
|
# Xcode
|
||||||
|
*.pbxuser
|
||||||
|
*.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
*.perspectivev3
|
||||||
|
*.xcuserstate
|
||||||
|
project.xcworkspace/
|
||||||
|
xcuserdata/
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
*.o
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
|
||||||
|
#Python modules
|
||||||
|
MANIFEST
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Backup files
|
||||||
|
*~.nib
|
||||||
30
.travis.yml
Normal file
30
.travis.yml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
language: cpp
|
||||||
|
branches:
|
||||||
|
except:
|
||||||
|
- latest-master
|
||||||
|
before_install:
|
||||||
|
- export PSPDEV="$TRAVIS_BUILD_DIR/opt/pspsdk"
|
||||||
|
- export PSPSDK="$PSPDEV/psp/sdk"
|
||||||
|
- export PATH="$PATH:$PSPDEV/bin:$PSPSDK/bin"
|
||||||
|
- export ANDROID="android-sdk-linux/tools/android"
|
||||||
|
install:
|
||||||
|
- sudo add-apt-repository ppa:tobydox/mingw -y
|
||||||
|
- sudo apt-get update -qq
|
||||||
|
- if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch jq mingw32-x-gcc mingw32-x-qt; fi
|
||||||
|
- sudo ln -s /opt/mingw32/bin/moc /opt/mingw32/bin/i686-w64-mingw32-moc
|
||||||
|
- wget -O sdk.lzma http://sourceforge.net/projects/minpspw/files/SDK%20%2B%20devpak/pspsdk%200.11.2/minpspw_0.11.2-amd64.tar.lzma/download
|
||||||
|
- tar -x --xz -f sdk.lzma
|
||||||
|
- wget http://dl.google.com/android/ndk/android-ndk-r9-linux-x86_64.tar.bz2 -nv
|
||||||
|
- wget http://dl.google.com/android/android-sdk_r22-linux.tgz -nv
|
||||||
|
- tar --absolute-names -jxf android-ndk-r9-linux-x86_64.tar.bz2
|
||||||
|
- tar -zxf android-sdk_r22-linux.tgz
|
||||||
|
- $ANDROID list sdk --extended -a
|
||||||
|
- echo yes | $ANDROID update sdk -a --filter "tools","platform-tools","build-tools-19.0.1","android-10" --no-ui --force > log.txt
|
||||||
|
- sudo pip install pyjavaproperties
|
||||||
|
script: ./travis-script.sh
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
secure: "fJgWlCFbde96OSQNGKUmowGX+ERPeqP+n1EOMf1+FJzOU4DdkTLRAlV5+5qnEX9jB/3mWN6iPpmG1qEz/SdDG3KHxJYs4ZU/Lu485O24zZ/+GdYBNsrvhPD9ckPGEMLDa1foEVTDnW0Dlkz3BCFcszjhtXGUJv7v6Pj6LRk1Mg8="
|
||||||
|
|
||||||
|
script: "./travis-script.sh"
|
||||||
|
after_success: ./upload-binaries.sh
|
||||||
@@ -71,7 +71,7 @@ namespace boost {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename InputT, typename FindResultT>
|
template<typename InputT, typename FindResultT>
|
||||||
bool check_find_result(InputT& Input, FindResultT& FindResult)
|
bool check_find_result(InputT&, FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
typedef BOOST_STRING_TYPENAME
|
typedef BOOST_STRING_TYPENAME
|
||||||
range_const_iterator<InputT>::type input_iterator_type;
|
range_const_iterator<InputT>::type input_iterator_type;
|
||||||
|
|||||||
84
Boost/boost/random.hpp
Normal file
84
Boost/boost/random.hpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/* boost random.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org/libs/random for documentation.
|
||||||
|
*
|
||||||
|
* $Id: random.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2000-02-18 portability fixes (thanks to Beman Dawes)
|
||||||
|
* 2000-02-21 shuffle_output, inversive_congruential_schrage,
|
||||||
|
* generator_iterator, uniform_smallint
|
||||||
|
* 2000-02-23 generic modulus arithmetic helper, removed *_schrage classes,
|
||||||
|
* implemented Streamable and EqualityComparable concepts for
|
||||||
|
* generators, added Bernoulli distribution and Box-Muller
|
||||||
|
* transform
|
||||||
|
* 2000-03-01 cauchy, lognormal, triangle distributions; fixed
|
||||||
|
* uniform_smallint; renamed gaussian to normal distribution
|
||||||
|
* 2000-03-05 implemented iterator syntax for distribution functions
|
||||||
|
* 2000-04-21 removed some optimizations for better BCC/MSVC compatibility
|
||||||
|
* 2000-05-10 adapted to BCC and MSVC
|
||||||
|
* 2000-06-13 incorporated review results
|
||||||
|
* 2000-07-06 moved basic templates from namespace detail to random
|
||||||
|
* 2000-09-23 warning removals and int64 fixes (Ed Brey)
|
||||||
|
* 2000-09-24 added lagged_fibonacci generator (Matthias Troyer)
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_HPP
|
||||||
|
#define BOOST_RANDOM_HPP
|
||||||
|
|
||||||
|
// generators
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
#include <boost/random/additive_combine.hpp>
|
||||||
|
#include <boost/random/inversive_congruential.hpp>
|
||||||
|
#include <boost/random/shuffle_output.hpp>
|
||||||
|
#include <boost/random/mersenne_twister.hpp>
|
||||||
|
#include <boost/random/lagged_fibonacci.hpp>
|
||||||
|
#include <boost/random/ranlux.hpp>
|
||||||
|
#include <boost/random/linear_feedback_shift.hpp>
|
||||||
|
#include <boost/random/xor_combine.hpp>
|
||||||
|
#include <boost/random/discard_block.hpp>
|
||||||
|
#include <boost/random/subtract_with_carry.hpp>
|
||||||
|
#include <boost/random/variate_generator.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
/**
|
||||||
|
* The specialization taus88 was suggested in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Maximally Equidistributed Combined Tausworthe Generators",
|
||||||
|
* Pierre L'Ecuyer, Mathematics of Computation, Volume 65,
|
||||||
|
* Number 213, January 1996, Pages 203-213
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::xor_combine<random::xor_combine<random::linear_feedback_shift<uint32_t, 32, 31, 13, 12, 0>, 0,
|
||||||
|
random::linear_feedback_shift<uint32_t, 32, 29, 2, 4, 0>, 0, 0>, 0,
|
||||||
|
random::linear_feedback_shift<uint32_t, 32, 28, 3, 17, 0>, 0, 0> taus88;
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
// misc
|
||||||
|
#include <boost/random/random_number_generator.hpp>
|
||||||
|
|
||||||
|
// distributions
|
||||||
|
#include <boost/random/uniform_smallint.hpp>
|
||||||
|
#include <boost/random/uniform_int.hpp>
|
||||||
|
#include <boost/random/uniform_01.hpp>
|
||||||
|
#include <boost/random/uniform_real.hpp>
|
||||||
|
#include <boost/random/triangle_distribution.hpp>
|
||||||
|
#include <boost/random/bernoulli_distribution.hpp>
|
||||||
|
#include <boost/random/cauchy_distribution.hpp>
|
||||||
|
#include <boost/random/exponential_distribution.hpp>
|
||||||
|
#include <boost/random/geometric_distribution.hpp>
|
||||||
|
#include <boost/random/normal_distribution.hpp>
|
||||||
|
#include <boost/random/lognormal_distribution.hpp>
|
||||||
|
#include <boost/random/poisson_distribution.hpp>
|
||||||
|
#include <boost/random/gamma_distribution.hpp>
|
||||||
|
#include <boost/random/binomial_distribution.hpp>
|
||||||
|
#include <boost/random/uniform_on_sphere.hpp>
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_HPP
|
||||||
234
Boost/boost/random/additive_combine.hpp
Normal file
234
Boost/boost/random/additive_combine.hpp
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
/* boost random/additive_combine.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: additive_combine.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_ADDITIVE_COMBINE_HPP
|
||||||
|
#define BOOST_RANDOM_ADDITIVE_COMBINE_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm> // for std::min and std::max
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An instantiation of class template \additive_combine model a
|
||||||
|
* \pseudo_random_number_generator. It combines two multiplicative
|
||||||
|
* \linear_congruential number generators, i.e. those with @c c = 0.
|
||||||
|
* It is described in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Efficient and Portable Combined Random Number Generators", Pierre L'Ecuyer,
|
||||||
|
* Communications of the ACM, Vol. 31, No. 6, June 1988, pp. 742-749, 774
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* The template parameters MLCG1 and MLCG2 shall denote two different
|
||||||
|
* \linear_congruential number generators, each with c = 0. Each invocation
|
||||||
|
* returns a random number X(n) := (MLCG1(n) - MLCG2(n)) mod (m1 - 1), where
|
||||||
|
* m1 denotes the modulus of MLCG1.
|
||||||
|
*
|
||||||
|
* The template parameter @c val is the validation value checked by validation.
|
||||||
|
*/
|
||||||
|
template<class MLCG1, class MLCG2,
|
||||||
|
#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
|
||||||
|
typename MLCG1::result_type
|
||||||
|
#else
|
||||||
|
int32_t
|
||||||
|
#endif
|
||||||
|
val>
|
||||||
|
class additive_combine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef MLCG1 first_base;
|
||||||
|
typedef MLCG2 second_base;
|
||||||
|
typedef typename MLCG1::result_type result_type;
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
static const bool has_fixed_range = true;
|
||||||
|
static const result_type min_value = 1;
|
||||||
|
static const result_type max_value = MLCG1::max_value-1;
|
||||||
|
#else
|
||||||
|
enum { has_fixed_range = false };
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Returns: The smallest value that the generator can produce
|
||||||
|
*/
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 1; }
|
||||||
|
/**
|
||||||
|
* Returns: The largest value that the generator can produce
|
||||||
|
*/
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_mlcg1.max)()-1; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an \additive_combine generator using the
|
||||||
|
* default constructors of the two base generators.
|
||||||
|
*/
|
||||||
|
additive_combine() : _mlcg1(), _mlcg2() { }
|
||||||
|
/**
|
||||||
|
* Constructs an \additive_combine generator, using aseed as
|
||||||
|
* the constructor argument for both base generators.
|
||||||
|
*/
|
||||||
|
explicit additive_combine(result_type aseed)
|
||||||
|
: _mlcg1(aseed), _mlcg2(aseed) { }
|
||||||
|
/**
|
||||||
|
* Constructs an \additive_combine generator, using
|
||||||
|
* @c seed1 and @c seed2 as the constructor argument to
|
||||||
|
* the first and second base generators, respectively.
|
||||||
|
*/
|
||||||
|
additive_combine(typename MLCG1::result_type seed1,
|
||||||
|
typename MLCG2::result_type seed2)
|
||||||
|
: _mlcg1(seed1), _mlcg2(seed2) { }
|
||||||
|
/**
|
||||||
|
* Contructs an \additive_combine generator with
|
||||||
|
* values from the range defined by the input iterators first
|
||||||
|
* and last. first will be modified to point to the element
|
||||||
|
* after the last one used.
|
||||||
|
*
|
||||||
|
* Throws: @c std::invalid_argument if the input range is too small.
|
||||||
|
*
|
||||||
|
* Exception Safety: Basic
|
||||||
|
*/
|
||||||
|
template<class It> additive_combine(It& first, It last)
|
||||||
|
: _mlcg1(first, last), _mlcg2(first, last) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seeds an \additive_combine generator using the default
|
||||||
|
* seeds of the two base generators.
|
||||||
|
*/
|
||||||
|
void seed()
|
||||||
|
{
|
||||||
|
_mlcg1.seed();
|
||||||
|
_mlcg2.seed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seeds an \additive_combine generator, using @c aseed as the
|
||||||
|
* seed for both base generators.
|
||||||
|
*/
|
||||||
|
void seed(result_type aseed)
|
||||||
|
{
|
||||||
|
_mlcg1.seed(aseed);
|
||||||
|
_mlcg2.seed(aseed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seeds an \additive_combine generator, using @c seed1 and @c seed2 as
|
||||||
|
* the seeds to the first and second base generators, respectively.
|
||||||
|
*/
|
||||||
|
void seed(typename MLCG1::result_type seed1,
|
||||||
|
typename MLCG2::result_type seed2)
|
||||||
|
{
|
||||||
|
_mlcg1.seed(seed1);
|
||||||
|
_mlcg2.seed(seed2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seeds an \additive_combine generator with
|
||||||
|
* values from the range defined by the input iterators first
|
||||||
|
* and last. first will be modified to point to the element
|
||||||
|
* after the last one used.
|
||||||
|
*
|
||||||
|
* Throws: @c std::invalid_argument if the input range is too small.
|
||||||
|
*
|
||||||
|
* Exception Safety: Basic
|
||||||
|
*/
|
||||||
|
template<class It> void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
_mlcg1.seed(first, last);
|
||||||
|
_mlcg2.seed(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: the next value of the generator
|
||||||
|
*/
|
||||||
|
result_type operator()() {
|
||||||
|
result_type z = _mlcg1() - _mlcg2();
|
||||||
|
if(z < 1)
|
||||||
|
z += MLCG1::modulus-1;
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validation(result_type x) { return val == x; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
/**
|
||||||
|
* Writes the state of an \additive_combine generator to a @c
|
||||||
|
* std::ostream. The textual representation of an \additive_combine
|
||||||
|
* generator is the textual representation of the first base
|
||||||
|
* generator followed by the textual representation of the
|
||||||
|
* second base generator.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const additive_combine& r)
|
||||||
|
{ os << r._mlcg1 << " " << r._mlcg2; return os; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the state of an \additive_combine generator from a
|
||||||
|
* @c std::istream.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, additive_combine& r)
|
||||||
|
{ is >> r._mlcg1 >> std::ws >> r._mlcg2; return is; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: true iff the two \additive_combine generators will
|
||||||
|
* produce the same sequence of values.
|
||||||
|
*/
|
||||||
|
friend bool operator==(const additive_combine& x, const additive_combine& y)
|
||||||
|
{ return x._mlcg1 == y._mlcg1 && x._mlcg2 == y._mlcg2; }
|
||||||
|
/**
|
||||||
|
* Returns: true iff the two \additive_combine generators will
|
||||||
|
* produce different sequences of values.
|
||||||
|
*/
|
||||||
|
friend bool operator!=(const additive_combine& x, const additive_combine& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const additive_combine& rhs) const
|
||||||
|
{ return _mlcg1 == rhs._mlcg1 && _mlcg2 == rhs._mlcg2; }
|
||||||
|
bool operator!=(const additive_combine& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
MLCG1 _mlcg1;
|
||||||
|
MLCG2 _mlcg2;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The specialization \ecuyer1988 was suggested in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Efficient and Portable Combined Random Number Generators", Pierre L'Ecuyer,
|
||||||
|
* Communications of the ACM, Vol. 31, No. 6, June 1988, pp. 742-749, 774
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::additive_combine<
|
||||||
|
random::linear_congruential<int32_t, 40014, 0, 2147483563, 0>,
|
||||||
|
random::linear_congruential<int32_t, 40692, 0, 2147483399, 0>,
|
||||||
|
2060321752> ecuyer1988;
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_ADDITIVE_COMBINE_HPP
|
||||||
109
Boost/boost/random/bernoulli_distribution.hpp
Normal file
109
Boost/boost/random/bernoulli_distribution.hpp
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
/* boost random/bernoulli_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: bernoulli_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template \bernoulli_distribution model a
|
||||||
|
* \random_distribution. Such a random distribution produces bool values
|
||||||
|
* distributed with probabilities P(true) = p and P(false) = 1-p. p is
|
||||||
|
* the parameter of the distribution.
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class bernoulli_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// In principle, this could work with both integer and floating-point
|
||||||
|
// types. Generating floating-point random numbers in the first
|
||||||
|
// place is probably more expensive, so use integer as input.
|
||||||
|
typedef int input_type;
|
||||||
|
typedef bool result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a \bernoulli_distribution object.
|
||||||
|
* p is the parameter of the distribution.
|
||||||
|
*
|
||||||
|
* Requires: 0 <= p <= 1
|
||||||
|
*/
|
||||||
|
explicit bernoulli_distribution(const RealType& p_arg = RealType(0.5))
|
||||||
|
: _p(p_arg)
|
||||||
|
{
|
||||||
|
assert(_p >= 0);
|
||||||
|
assert(_p <= 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: The "p" parameter of the distribution.
|
||||||
|
*/
|
||||||
|
RealType p() const { return _p; }
|
||||||
|
/**
|
||||||
|
* Effects: Subsequent uses of the distribution do not depend
|
||||||
|
* on values produced by any engine prior to invoking reset.
|
||||||
|
*/
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: a random variate distributed according to the
|
||||||
|
* \bernoulli_distribution.
|
||||||
|
*/
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
if(_p == RealType(0))
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return RealType(eng() - (eng.min)()) <= _p * RealType((eng.max)()-(eng.min)());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
/**
|
||||||
|
* Writes the parameters of the distribution to a @c std::ostream.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const bernoulli_distribution& bd)
|
||||||
|
{
|
||||||
|
os << bd._p;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the parameters of the distribution from a @c std::istream.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, bernoulli_distribution& bd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> bd._p;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
RealType _p;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP
|
||||||
111
Boost/boost/random/binomial_distribution.hpp
Normal file
111
Boost/boost/random/binomial_distribution.hpp
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/* boost random/binomial_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: binomial_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/bernoulli_distribution.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The binomial distribution is an integer valued distribution with
|
||||||
|
* two parameters, @c t and @c p. The values of the distribution
|
||||||
|
* are within the range [0,t].
|
||||||
|
*
|
||||||
|
* The probability that the distribution produces a value k is
|
||||||
|
* \f${t \choose k}p^k(1-p)^{t-k}\f$.
|
||||||
|
*/
|
||||||
|
template<class IntType = int, class RealType = double>
|
||||||
|
class binomial_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename bernoulli_distribution<RealType>::input_type input_type;
|
||||||
|
typedef IntType result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an @c binomial_distribution object. @c t and @c p
|
||||||
|
* are the parameters of the distribution.
|
||||||
|
*
|
||||||
|
* Requires: t >=0 && 0 <= p <= 1
|
||||||
|
*/
|
||||||
|
explicit binomial_distribution(IntType t = 1,
|
||||||
|
const RealType& p = RealType(0.5))
|
||||||
|
: _bernoulli(p), _t(t)
|
||||||
|
{
|
||||||
|
assert(_t >= 0);
|
||||||
|
assert(RealType(0) <= p && p <= RealType(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/** Returns: the @c t parameter of the distribution */
|
||||||
|
IntType t() const { return _t; }
|
||||||
|
/** Returns: the @c p parameter of the distribution */
|
||||||
|
RealType p() const { return _bernoulli.p(); }
|
||||||
|
/**
|
||||||
|
* Effects: Subsequent uses of the distribution do not depend
|
||||||
|
* on values produced by any engine prior to invoking reset.
|
||||||
|
*/
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: a random variate distributed according to the
|
||||||
|
* binomial distribution.
|
||||||
|
*/
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
// TODO: This is O(_t), but it should be O(log(_t)) for large _t
|
||||||
|
result_type n = 0;
|
||||||
|
for(IntType i = 0; i < _t; ++i)
|
||||||
|
if(_bernoulli(eng))
|
||||||
|
++n;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
/**
|
||||||
|
* Writes the parameters of the distribution to a @c std::ostream.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const binomial_distribution& bd)
|
||||||
|
{
|
||||||
|
os << bd._bernoulli << " " << bd._t;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the parameters of the distribution from a @c std::istream.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, binomial_distribution& bd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> bd._bernoulli >> std::ws >> bd._t;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
bernoulli_distribution<RealType> _bernoulli;
|
||||||
|
IntType _t;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP
|
||||||
121
Boost/boost/random/cauchy_distribution.hpp
Normal file
121
Boost/boost/random/cauchy_distribution.hpp
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/* boost random/cauchy_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: cauchy_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && (__GNUC__ < 3)
|
||||||
|
// Special gcc workaround: gcc 2.95.x ignores using-declarations
|
||||||
|
// in template classes (confirmed by gcc author Martin v. Loewis)
|
||||||
|
using std::tan;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Cauchy distribution:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cauchy distribution is a continuous distribution with two
|
||||||
|
* parameters, sigma and median.
|
||||||
|
*
|
||||||
|
* It has \f$p(x) = \frac{\sigma}{\pi(\sigma^2 + (x-m)^2)}\f$
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class cauchy_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a \cauchy_distribution with the paramters @c median
|
||||||
|
* and @c sigma.
|
||||||
|
*/
|
||||||
|
explicit cauchy_distribution(result_type median_arg = result_type(0),
|
||||||
|
result_type sigma_arg = result_type(1))
|
||||||
|
: _median(median_arg), _sigma(sigma_arg) { }
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: the "median" parameter of the distribution
|
||||||
|
*/
|
||||||
|
result_type median() const { return _median; }
|
||||||
|
/**
|
||||||
|
* Returns: the "sigma" parameter of the distribution
|
||||||
|
*/
|
||||||
|
result_type sigma() const { return _sigma; }
|
||||||
|
/**
|
||||||
|
* Effects: Subsequent uses of the distribution do not depend
|
||||||
|
* on values produced by any engine prior to invoking reset.
|
||||||
|
*/
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: A random variate distributed according to the
|
||||||
|
* cauchy distribution.
|
||||||
|
*/
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
// Can we have a boost::mathconst please?
|
||||||
|
const result_type pi = result_type(3.14159265358979323846);
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
using std::tan;
|
||||||
|
#endif
|
||||||
|
return _median + _sigma * tan(pi*(eng()-result_type(0.5)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
/**
|
||||||
|
* Writes the parameters of the distribution to a @c std::ostream.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const cauchy_distribution& cd)
|
||||||
|
{
|
||||||
|
os << cd._median << " " << cd._sigma;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the parameters of the distribution from a @c std::istream.
|
||||||
|
*/
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, cauchy_distribution& cd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> cd._median >> std::ws >> cd._sigma;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
result_type _median, _sigma;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
|
||||||
42
Boost/boost/random/detail/auto_link.hpp
Normal file
42
Boost/boost/random/detail/auto_link.hpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* boost random auto_link.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Steven Watanabe 2010
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* $Id: auto_link.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DETAIL_AUTO_LINK_HPP
|
||||||
|
#define BOOST_RANDOM_DETAIL_AUTO_LINK_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
#ifdef BOOST_HAS_DECLSPEC
|
||||||
|
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_RANDOM_DYN_LINK)
|
||||||
|
#if defined(BOOST_RANDOM_SOURCE)
|
||||||
|
#define BOOST_RANDOM_DECL __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define BOOST_RANDOM_DECL __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DECL
|
||||||
|
#define BOOST_RANDOM_DECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(BOOST_RANDOM_NO_LIB) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_RANDOM_SOURCE)
|
||||||
|
|
||||||
|
#define BOOST_LIB_NAME boost_random
|
||||||
|
|
||||||
|
#if defined(BOOST_RANDOM_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
|
||||||
|
#define BOOST_DYN_LINK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/config/auto_link.hpp>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
18
Boost/boost/random/detail/config.hpp
Normal file
18
Boost/boost/random/detail/config.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* boost random/detail/config.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Steven Watanabe 2009
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: config.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
#if (defined(BOOST_NO_OPERATORS_IN_NAMESPACE) || defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)) \
|
||||||
|
&& !defined(BOOST_MSVC)
|
||||||
|
#define BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
#endif
|
||||||
363
Boost/boost/random/detail/const_mod.hpp
Normal file
363
Boost/boost/random/detail/const_mod.hpp
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
/* boost random/detail/const_mod.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: const_mod.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_CONST_MOD_HPP
|
||||||
|
#define BOOST_RANDOM_CONST_MOD_HPP
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
#include <boost/integer_traits.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
|
||||||
|
#include <boost/random/detail/disable_warnings.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some random number generators require modular arithmetic. Put
|
||||||
|
* everything we need here.
|
||||||
|
* IntType must be an integral type.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<bool is_signed>
|
||||||
|
struct do_add
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct do_add<true>
|
||||||
|
{
|
||||||
|
template<class IntType>
|
||||||
|
static IntType add(IntType m, IntType x, IntType c)
|
||||||
|
{
|
||||||
|
if (x < m - c)
|
||||||
|
return x + c;
|
||||||
|
else
|
||||||
|
return x - (m-c);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct do_add<false>
|
||||||
|
{
|
||||||
|
template<class IntType>
|
||||||
|
static IntType add(IntType, IntType, IntType)
|
||||||
|
{
|
||||||
|
// difficult
|
||||||
|
assert(!"const_mod::add with c too large");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
#if !(defined(__BORLANDC__) && (__BORLANDC__ == 0x560))
|
||||||
|
|
||||||
|
template<class IntType, IntType m>
|
||||||
|
class const_mod
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static IntType add(IntType x, IntType c)
|
||||||
|
{
|
||||||
|
if(c == 0)
|
||||||
|
return x;
|
||||||
|
else if(c <= traits::const_max - m) // i.e. m+c < max
|
||||||
|
return add_small(x, c);
|
||||||
|
else
|
||||||
|
return detail::do_add<traits::is_signed>::add(m, x, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult(IntType a, IntType x)
|
||||||
|
{
|
||||||
|
if(a == 1)
|
||||||
|
return x;
|
||||||
|
else if(m <= traits::const_max/a) // i.e. a*m <= max
|
||||||
|
return mult_small(a, x);
|
||||||
|
else if(traits::is_signed && (m%a < m/a))
|
||||||
|
return mult_schrage(a, x);
|
||||||
|
else {
|
||||||
|
// difficult
|
||||||
|
assert(!"const_mod::mult with a too large");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult_add(IntType a, IntType x, IntType c)
|
||||||
|
{
|
||||||
|
if(m <= (traits::const_max-c)/a) // i.e. a*m+c <= max
|
||||||
|
return (a*x+c) % m;
|
||||||
|
else
|
||||||
|
return add(mult(a, x), c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType invert(IntType x)
|
||||||
|
{ return x == 0 ? 0 : invert_euclidian(x); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef integer_traits<IntType> traits;
|
||||||
|
|
||||||
|
const_mod(); // don't instantiate
|
||||||
|
|
||||||
|
static IntType add_small(IntType x, IntType c)
|
||||||
|
{
|
||||||
|
x += c;
|
||||||
|
if(x >= m)
|
||||||
|
x -= m;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult_small(IntType a, IntType x)
|
||||||
|
{
|
||||||
|
return a*x % m;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult_schrage(IntType a, IntType value)
|
||||||
|
{
|
||||||
|
const IntType q = m / a;
|
||||||
|
const IntType r = m % a;
|
||||||
|
|
||||||
|
assert(r < q); // check that overflow cannot happen
|
||||||
|
|
||||||
|
value = a*(value%q) - r*(value/q);
|
||||||
|
// An optimizer bug in the SGI MIPSpro 7.3.1.x compiler requires this
|
||||||
|
// convoluted formulation of the loop (Synge Todo)
|
||||||
|
for(;;) {
|
||||||
|
if (value > 0)
|
||||||
|
break;
|
||||||
|
value += m;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// invert c in the finite field (mod m) (m must be prime)
|
||||||
|
static IntType invert_euclidian(IntType c)
|
||||||
|
{
|
||||||
|
// we are interested in the gcd factor for c, because this is our inverse
|
||||||
|
BOOST_STATIC_ASSERT(m > 0);
|
||||||
|
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
|
||||||
|
assert(boost::integer_traits<IntType>::is_signed);
|
||||||
|
#elif !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS)
|
||||||
|
BOOST_STATIC_ASSERT(boost::integer_traits<IntType>::is_signed);
|
||||||
|
#endif
|
||||||
|
assert(c > 0);
|
||||||
|
IntType l1 = 0;
|
||||||
|
IntType l2 = 1;
|
||||||
|
IntType n = c;
|
||||||
|
IntType p = m;
|
||||||
|
for(;;) {
|
||||||
|
IntType q = p / n;
|
||||||
|
l1 -= q * l2; // this requires a signed IntType!
|
||||||
|
p -= q * n;
|
||||||
|
if(p == 0)
|
||||||
|
return (l2 < 1 ? l2 + m : l2);
|
||||||
|
IntType q2 = n / p;
|
||||||
|
l2 -= q2 * l1;
|
||||||
|
n -= q2 * p;
|
||||||
|
if(n == 0)
|
||||||
|
return (l1 < 1 ? l1 + m : l1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// The modulus is exactly the word size: rely on machine overflow handling.
|
||||||
|
// Due to a GCC bug, we cannot partially specialize in the presence of
|
||||||
|
// template value parameters.
|
||||||
|
template<>
|
||||||
|
class const_mod<unsigned int, 0>
|
||||||
|
{
|
||||||
|
typedef unsigned int IntType;
|
||||||
|
public:
|
||||||
|
static IntType add(IntType x, IntType c) { return x+c; }
|
||||||
|
static IntType mult(IntType a, IntType x) { return a*x; }
|
||||||
|
static IntType mult_add(IntType a, IntType x, IntType c) { return a*x+c; }
|
||||||
|
|
||||||
|
// m is not prime, thus invert is not useful
|
||||||
|
private: // don't instantiate
|
||||||
|
const_mod();
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class const_mod<unsigned long, 0>
|
||||||
|
{
|
||||||
|
typedef unsigned long IntType;
|
||||||
|
public:
|
||||||
|
static IntType add(IntType x, IntType c) { return x+c; }
|
||||||
|
static IntType mult(IntType a, IntType x) { return a*x; }
|
||||||
|
static IntType mult_add(IntType a, IntType x, IntType c) { return a*x+c; }
|
||||||
|
|
||||||
|
// m is not prime, thus invert is not useful
|
||||||
|
private: // don't instantiate
|
||||||
|
const_mod();
|
||||||
|
};
|
||||||
|
|
||||||
|
// the modulus is some power of 2: rely partly on machine overflow handling
|
||||||
|
// we only specialize for rand48 at the moment
|
||||||
|
#ifndef BOOST_NO_INT64_T
|
||||||
|
template<>
|
||||||
|
class const_mod<uint64_t, uint64_t(1) << 48>
|
||||||
|
{
|
||||||
|
typedef uint64_t IntType;
|
||||||
|
public:
|
||||||
|
static IntType add(IntType x, IntType c) { return c == 0 ? x : mod(x+c); }
|
||||||
|
static IntType mult(IntType a, IntType x) { return mod(a*x); }
|
||||||
|
static IntType mult_add(IntType a, IntType x, IntType c)
|
||||||
|
{ return mod(a*x+c); }
|
||||||
|
static IntType mod(IntType x) { return x &= ((uint64_t(1) << 48)-1); }
|
||||||
|
|
||||||
|
// m is not prime, thus invert is not useful
|
||||||
|
private: // don't instantiate
|
||||||
|
const_mod();
|
||||||
|
};
|
||||||
|
#endif /* !BOOST_NO_INT64_T */
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
//
|
||||||
|
// for some reason Borland C++ Builder 6 has problems with
|
||||||
|
// the full specialisations of const_mod, define a generic version
|
||||||
|
// instead, the compiler will optimise away the const-if statements:
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class IntType, IntType m>
|
||||||
|
class const_mod
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static IntType add(IntType x, IntType c)
|
||||||
|
{
|
||||||
|
if(0 == m)
|
||||||
|
{
|
||||||
|
return x+c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(c == 0)
|
||||||
|
return x;
|
||||||
|
else if(c <= traits::const_max - m) // i.e. m+c < max
|
||||||
|
return add_small(x, c);
|
||||||
|
else
|
||||||
|
return detail::do_add<traits::is_signed>::add(m, x, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult(IntType a, IntType x)
|
||||||
|
{
|
||||||
|
if(x == 0)
|
||||||
|
{
|
||||||
|
return a*x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(a == 1)
|
||||||
|
return x;
|
||||||
|
else if(m <= traits::const_max/a) // i.e. a*m <= max
|
||||||
|
return mult_small(a, x);
|
||||||
|
else if(traits::is_signed && (m%a < m/a))
|
||||||
|
return mult_schrage(a, x);
|
||||||
|
else {
|
||||||
|
// difficult
|
||||||
|
assert(!"const_mod::mult with a too large");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult_add(IntType a, IntType x, IntType c)
|
||||||
|
{
|
||||||
|
if(m == 0)
|
||||||
|
{
|
||||||
|
return a*x+c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(m <= (traits::const_max-c)/a) // i.e. a*m+c <= max
|
||||||
|
return (a*x+c) % m;
|
||||||
|
else
|
||||||
|
return add(mult(a, x), c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType invert(IntType x)
|
||||||
|
{ return x == 0 ? 0 : invert_euclidian(x); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef integer_traits<IntType> traits;
|
||||||
|
|
||||||
|
const_mod(); // don't instantiate
|
||||||
|
|
||||||
|
static IntType add_small(IntType x, IntType c)
|
||||||
|
{
|
||||||
|
x += c;
|
||||||
|
if(x >= m)
|
||||||
|
x -= m;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult_small(IntType a, IntType x)
|
||||||
|
{
|
||||||
|
return a*x % m;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntType mult_schrage(IntType a, IntType value)
|
||||||
|
{
|
||||||
|
const IntType q = m / a;
|
||||||
|
const IntType r = m % a;
|
||||||
|
|
||||||
|
assert(r < q); // check that overflow cannot happen
|
||||||
|
|
||||||
|
value = a*(value%q) - r*(value/q);
|
||||||
|
while(value <= 0)
|
||||||
|
value += m;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// invert c in the finite field (mod m) (m must be prime)
|
||||||
|
static IntType invert_euclidian(IntType c)
|
||||||
|
{
|
||||||
|
// we are interested in the gcd factor for c, because this is our inverse
|
||||||
|
BOOST_STATIC_ASSERT(m > 0);
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(boost::integer_traits<IntType>::is_signed);
|
||||||
|
#endif
|
||||||
|
assert(c > 0);
|
||||||
|
IntType l1 = 0;
|
||||||
|
IntType l2 = 1;
|
||||||
|
IntType n = c;
|
||||||
|
IntType p = m;
|
||||||
|
for(;;) {
|
||||||
|
IntType q = p / n;
|
||||||
|
l1 -= q * l2; // this requires a signed IntType!
|
||||||
|
p -= q * n;
|
||||||
|
if(p == 0)
|
||||||
|
return (l2 < 1 ? l2 + m : l2);
|
||||||
|
IntType q2 = n / p;
|
||||||
|
l2 -= q2 * l1;
|
||||||
|
n -= q2 * p;
|
||||||
|
if(n == 0)
|
||||||
|
return (l1 < 1 ? l1 + m : l1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#include <boost/random/detail/enable_warnings.hpp>
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_CONST_MOD_HPP
|
||||||
23
Boost/boost/random/detail/disable_warnings.hpp
Normal file
23
Boost/boost/random/detail/disable_warnings.hpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* boost random/detail/disable_warnings.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Steven Watanabe 2009
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: disable_warnings.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// No #include guard. This header is intended to be included multiple times.
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable:4512)
|
||||||
|
#pragma warning(disable:4127)
|
||||||
|
#pragma warning(disable:4724)
|
||||||
|
#endif
|
||||||
18
Boost/boost/random/detail/enable_warnings.hpp
Normal file
18
Boost/boost/random/detail/enable_warnings.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* boost random/detail/enable_warnings.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Steven Watanabe 2009
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: enable_warnings.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// No #include guard. This header is intended to be included multiple times.
|
||||||
|
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
45
Boost/boost/random/detail/iterator_mixin.hpp
Normal file
45
Boost/boost/random/detail/iterator_mixin.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* boost random/detail/iterator_mixin.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_ITERATOR_MIXIN_HPP
|
||||||
|
#define BOOST_ITERATOR_MIXIN_HPP
|
||||||
|
|
||||||
|
#include <boost/operators.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
// must be in boost namespace, otherwise the inline friend trick fails
|
||||||
|
template<class Generator, class ResultType>
|
||||||
|
class generator_iterator_mixin_adapter
|
||||||
|
: incrementable<Generator>, equality_comparable<Generator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::input_iterator_tag iterator_category;
|
||||||
|
typedef ResultType value_type;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef const value_type * pointer;
|
||||||
|
typedef const value_type & reference;
|
||||||
|
Generator& operator++() { v = cast()(); return cast(); }
|
||||||
|
const value_type& operator*() const { return v; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// instantiate from derived classes only
|
||||||
|
generator_iterator_mixin_adapter() { }
|
||||||
|
void iterator_init() { operator++(); }
|
||||||
|
private:
|
||||||
|
Generator & cast() { return static_cast<Generator&>(*this); }
|
||||||
|
value_type v;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_ITERATOR_MIXIN_HPP
|
||||||
100
Boost/boost/random/detail/pass_through_engine.hpp
Normal file
100
Boost/boost/random/detail/pass_through_engine.hpp
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/* boost random/detail/uniform_int_float.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: pass_through_engine.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
|
||||||
|
#define BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/random/detail/ptr_helper.hpp>
|
||||||
|
#include <boost/random/detail/disable_warnings.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator>
|
||||||
|
class pass_through_engine
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
typedef ptr_helper<UniformRandomNumberGenerator> helper_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename helper_type::value_type base_type;
|
||||||
|
typedef typename base_type::result_type result_type;
|
||||||
|
|
||||||
|
explicit pass_through_engine(UniformRandomNumberGenerator rng)
|
||||||
|
// make argument an rvalue to avoid matching Generator& constructor
|
||||||
|
: _rng(static_cast<typename helper_type::rvalue_type>(rng))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().min)(); }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().max)(); }
|
||||||
|
base_type& base() { return helper_type::ref(_rng); }
|
||||||
|
const base_type& base() const { return helper_type::ref(_rng); }
|
||||||
|
|
||||||
|
result_type operator()() { return base()(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
UniformRandomNumberGenerator _rng;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_STD_LOCALE
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator, class CharT, class Traits>
|
||||||
|
std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(
|
||||||
|
std::basic_ostream<CharT,Traits>& os
|
||||||
|
, const pass_through_engine<UniformRandomNumberGenerator>& ud
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return os << ud.base();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator, class CharT, class Traits>
|
||||||
|
std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(
|
||||||
|
std::basic_istream<CharT,Traits>& is
|
||||||
|
, const pass_through_engine<UniformRandomNumberGenerator>& ud
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return is >> ud.base();
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // no new streams
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator>
|
||||||
|
inline std::ostream&
|
||||||
|
operator<<(std::ostream& os,
|
||||||
|
const pass_through_engine<UniformRandomNumberGenerator>& ud)
|
||||||
|
{
|
||||||
|
return os << ud.base();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator>
|
||||||
|
inline std::istream&
|
||||||
|
operator>>(std::istream& is,
|
||||||
|
const pass_through_engine<UniformRandomNumberGenerator>& ud)
|
||||||
|
{
|
||||||
|
return is >> ud.base();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#include <boost/random/detail/enable_warnings.hpp>
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
|
||||||
|
|
||||||
94
Boost/boost/random/detail/ptr_helper.hpp
Normal file
94
Boost/boost/random/detail/ptr_helper.hpp
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/* boost random/detail/ptr_helper.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: ptr_helper.hpp 24096 2004-07-27 03:43:34Z dgregor $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
|
||||||
|
#define BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
// type_traits could help here, but I don't want to depend on type_traits.
|
||||||
|
template<class T>
|
||||||
|
struct ptr_helper
|
||||||
|
{
|
||||||
|
typedef T value_type;
|
||||||
|
typedef T& reference_type;
|
||||||
|
typedef const T& rvalue_type;
|
||||||
|
static reference_type ref(T& r) { return r; }
|
||||||
|
static const T& ref(const T& r) { return r; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
template<class T>
|
||||||
|
struct ptr_helper<T&>
|
||||||
|
{
|
||||||
|
typedef T value_type;
|
||||||
|
typedef T& reference_type;
|
||||||
|
typedef T& rvalue_type;
|
||||||
|
static reference_type ref(T& r) { return r; }
|
||||||
|
static const T& ref(const T& r) { return r; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct ptr_helper<T*>
|
||||||
|
{
|
||||||
|
typedef T value_type;
|
||||||
|
typedef T& reference_type;
|
||||||
|
typedef T* rvalue_type;
|
||||||
|
static reference_type ref(T * p) { return *p; }
|
||||||
|
static const T& ref(const T * p) { return *p; }
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
//
|
||||||
|
// BOOST_RANDOM_PTR_HELPER_SPEC --
|
||||||
|
//
|
||||||
|
// Helper macro for broken compilers defines specializations of
|
||||||
|
// ptr_helper.
|
||||||
|
//
|
||||||
|
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
# define BOOST_RANDOM_PTR_HELPER_SPEC(T) \
|
||||||
|
namespace boost { namespace random { namespace detail { \
|
||||||
|
template<> \
|
||||||
|
struct ptr_helper<T&> \
|
||||||
|
{ \
|
||||||
|
typedef T value_type; \
|
||||||
|
typedef T& reference_type; \
|
||||||
|
typedef T& rvalue_type; \
|
||||||
|
static reference_type ref(T& r) { return r; } \
|
||||||
|
static const T& ref(const T& r) { return r; } \
|
||||||
|
}; \
|
||||||
|
\
|
||||||
|
template<> \
|
||||||
|
struct ptr_helper<T*> \
|
||||||
|
{ \
|
||||||
|
typedef T value_type; \
|
||||||
|
typedef T& reference_type; \
|
||||||
|
typedef T* rvalue_type; \
|
||||||
|
static reference_type ref(T * p) { return *p; } \
|
||||||
|
static const T& ref(const T * p) { return *p; } \
|
||||||
|
}; \
|
||||||
|
}}}
|
||||||
|
#else
|
||||||
|
# define BOOST_RANDOM_PTR_HELPER_SPEC(T)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
|
||||||
89
Boost/boost/random/detail/seed.hpp
Normal file
89
Boost/boost/random/detail/seed.hpp
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/* boost random/detail/seed.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Steven Watanabe 2009
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: seed.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DETAIL_SEED_HPP
|
||||||
|
#define BOOST_RANDOM_DETAIL_SEED_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
// Sun seems to have trouble with the use of SFINAE for the
|
||||||
|
// templated constructor. So does Borland.
|
||||||
|
#if !defined(BOOST_NO_SFINAE) && !defined(__SUNPRO_CC) && !defined(__BORLANDC__)
|
||||||
|
|
||||||
|
#include <boost/utility/enable_if.hpp>
|
||||||
|
#include <boost/type_traits/is_arithmetic.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {};
|
||||||
|
|
||||||
|
template<class Engine, class T>
|
||||||
|
struct disable_constructor : disable_seed<T> {};
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
struct disable_constructor<Engine, Engine> {};
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
|
||||||
|
template<class Generator> \
|
||||||
|
explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0)
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
|
||||||
|
template<class Generator> \
|
||||||
|
void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0)
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
|
||||||
|
explicit Self(const T& x)
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
|
||||||
|
void seed(const T& x)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/type_traits/is_arithmetic.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
|
||||||
|
Self(Self& other) { *this = other; } \
|
||||||
|
Self(const Self& other) { *this = other; } \
|
||||||
|
template<class Generator> \
|
||||||
|
explicit Self(Generator& gen) { \
|
||||||
|
boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\
|
||||||
|
} \
|
||||||
|
template<class Generator> \
|
||||||
|
void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_)
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
|
||||||
|
template<class Generator> \
|
||||||
|
void seed(Generator& gen) { \
|
||||||
|
boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\
|
||||||
|
}\
|
||||||
|
template<class Generator>\
|
||||||
|
void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_)
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
|
||||||
|
explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\
|
||||||
|
void boost_random_constructor_impl(const T& x, ::boost::mpl::true_)
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
|
||||||
|
void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\
|
||||||
|
void boost_random_seed_impl(const T& x, ::boost::mpl::true_)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
89
Boost/boost/random/detail/signed_unsigned_tools.hpp
Normal file
89
Boost/boost/random/detail/signed_unsigned_tools.hpp
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/* boost random/detail/signed_unsigned_tools.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2006
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
|
||||||
|
#define BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
|
||||||
|
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/type_traits/make_unsigned.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compute x - y, we know that x >= y, return an unsigned value.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class T, bool sgn = std::numeric_limits<T>::is_signed>
|
||||||
|
struct subtract { };
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct subtract<T, /* signed */ false>
|
||||||
|
{
|
||||||
|
typedef T result_type;
|
||||||
|
result_type operator()(T x, T y) { return x - y; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct subtract<T, /* signed */ true>
|
||||||
|
{
|
||||||
|
typedef typename make_unsigned<T>::type result_type;
|
||||||
|
result_type operator()(T x, T y)
|
||||||
|
{
|
||||||
|
if (y >= 0) // because x >= y, it follows that x >= 0, too
|
||||||
|
return result_type(x) - result_type(y);
|
||||||
|
if (x >= 0) // y < 0
|
||||||
|
// avoid the nasty two's complement case for y == min()
|
||||||
|
return result_type(x) + result_type(-(y+1)) + 1;
|
||||||
|
// both x and y are negative: no signed overflow
|
||||||
|
return result_type(x - y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compute x + y, x is unsigned, result fits in type of "y".
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class T1, class T2, bool sgn = std::numeric_limits<T2>::is_signed>
|
||||||
|
struct add { };
|
||||||
|
|
||||||
|
template<class T1, class T2>
|
||||||
|
struct add<T1, T2, /* signed */ false>
|
||||||
|
{
|
||||||
|
typedef T2 result_type;
|
||||||
|
result_type operator()(T1 x, T2 y) { return T2(x) + y; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T1, class T2>
|
||||||
|
struct add<T1, T2, /* signed */ true>
|
||||||
|
{
|
||||||
|
typedef T2 result_type;
|
||||||
|
result_type operator()(T1 x, T2 y)
|
||||||
|
{
|
||||||
|
if (y >= 0)
|
||||||
|
return T2(x) + y;
|
||||||
|
// y < 0
|
||||||
|
if (x >= T1(-(y+1))) // result >= 0 after subtraction
|
||||||
|
// avoid the nasty two's complement edge case for y == min()
|
||||||
|
return T2(x - T1(-(y+1)) - 1);
|
||||||
|
// abs(x) < abs(y), thus T2 able to represent x
|
||||||
|
return T2(x) + y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
|
||||||
|
|
||||||
85
Boost/boost/random/detail/uniform_int_float.hpp
Normal file
85
Boost/boost/random/detail/uniform_int_float.hpp
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/* boost random/detail/uniform_int_float.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: uniform_int_float.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
|
||||||
|
#define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/uniform_01.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator, class IntType = unsigned long>
|
||||||
|
class uniform_int_float
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef UniformRandomNumberGenerator base_type;
|
||||||
|
typedef IntType result_type;
|
||||||
|
|
||||||
|
uniform_int_float(base_type rng, IntType min_arg = 0, IntType max_arg = 0xffffffff)
|
||||||
|
: _rng(rng), _min(min_arg), _max(max_arg)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
|
||||||
|
base_type& base() { return _rng.base(); }
|
||||||
|
const base_type& base() const { return _rng.base(); }
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
return static_cast<IntType>(_rng() * _range) + _min;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_int_float& ud)
|
||||||
|
{
|
||||||
|
os << ud._min << " " << ud._max;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, uniform_int_float& ud)
|
||||||
|
{
|
||||||
|
is >> std::ws >> ud._min >> std::ws >> ud._max;
|
||||||
|
ud.init();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
_range = static_cast<base_result>(_max-_min)+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef typename base_type::result_type base_result;
|
||||||
|
uniform_01<base_type> _rng;
|
||||||
|
result_type _min, _max;
|
||||||
|
base_result _range;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
|
||||||
132
Boost/boost/random/discard_block.hpp
Normal file
132
Boost/boost/random/discard_block.hpp
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
/* boost random/discard_block.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: discard_block.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-03-02 created
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_DISCARD_BLOCK_HPP
|
||||||
|
#define BOOST_RANDOM_DISCARD_BLOCK_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class template \discard_block is a model of
|
||||||
|
* \pseudo_random_number_generator. It modifies
|
||||||
|
* another generator by discarding parts of its output.
|
||||||
|
* Out of every block of @c r results, the first @c p
|
||||||
|
* will be returned and the rest discarded.
|
||||||
|
*
|
||||||
|
* Requires: 0 < p <= r
|
||||||
|
*/
|
||||||
|
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
|
||||||
|
class discard_block
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef UniformRandomNumberGenerator base_type;
|
||||||
|
typedef typename base_type::result_type result_type;
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, total_block = p);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, returned_block = r);
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(total_block >= returned_block);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
discard_block() : _rng(), _n(0) { }
|
||||||
|
explicit discard_block(const base_type & rng) : _rng(rng), _n(0) { }
|
||||||
|
template<class T> explicit discard_block(T s) : _rng(s), _n(0) {}
|
||||||
|
template<class It> discard_block(It& first, It last)
|
||||||
|
: _rng(first, last), _n(0) { }
|
||||||
|
void seed() { _rng.seed(); _n = 0; }
|
||||||
|
template<class T> void seed(T s) { _rng.seed(s); _n = 0; }
|
||||||
|
template<class It> void seed(It& first, It last)
|
||||||
|
{ _n = 0; _rng.seed(first, last); }
|
||||||
|
|
||||||
|
const base_type& base() const { return _rng; }
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
if(_n >= returned_block) {
|
||||||
|
// discard values of random number generator
|
||||||
|
for( ; _n < total_block; ++_n)
|
||||||
|
_rng();
|
||||||
|
_n = 0;
|
||||||
|
}
|
||||||
|
++_n;
|
||||||
|
return _rng();
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); }
|
||||||
|
static bool validation(result_type x) { return true; } // dummy
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const discard_block& s)
|
||||||
|
{
|
||||||
|
os << s._rng << " " << s._n << " ";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, discard_block& s)
|
||||||
|
{
|
||||||
|
is >> s._rng >> std::ws >> s._n >> std::ws;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const discard_block& x, const discard_block& y)
|
||||||
|
{ return x._rng == y._rng && x._n == y._n; }
|
||||||
|
friend bool operator!=(const discard_block& x, const discard_block& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const discard_block& rhs) const
|
||||||
|
{ return _rng == rhs._rng && _n == rhs._n; }
|
||||||
|
bool operator!=(const discard_block& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
base_type _rng;
|
||||||
|
unsigned int _n;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
|
||||||
|
const bool discard_block<UniformRandomNumberGenerator, p, r>::has_fixed_range;
|
||||||
|
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
|
||||||
|
const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::total_block;
|
||||||
|
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
|
||||||
|
const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::returned_block;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_DISCARD_BLOCK_HPP
|
||||||
86
Boost/boost/random/exponential_distribution.hpp
Normal file
86
Boost/boost/random/exponential_distribution.hpp
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/* boost random/exponential_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: exponential_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exponential distribution has a single parameter lambda.
|
||||||
|
*
|
||||||
|
* It has \f$p(x) = \lambda e^{-\lambda x}\f$
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class exponential_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
explicit exponential_distribution(result_type lambda_arg = result_type(1))
|
||||||
|
: _lambda(lambda_arg) { assert(_lambda > result_type(0)); }
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
result_type lambda() const { return _lambda; }
|
||||||
|
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
using std::log;
|
||||||
|
#endif
|
||||||
|
return -result_type(1) / _lambda * log(result_type(1)-eng());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const exponential_distribution& ed)
|
||||||
|
{
|
||||||
|
os << ed._lambda;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, exponential_distribution& ed)
|
||||||
|
{
|
||||||
|
is >> std::ws >> ed._lambda;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
result_type _lambda;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
|
||||||
143
Boost/boost/random/gamma_distribution.hpp
Normal file
143
Boost/boost/random/gamma_distribution.hpp
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
/* boost random/gamma_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: gamma_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/exponential_distribution.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
// The algorithm is taken from Knuth
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The gamma distribution is a continuous distribution with a single
|
||||||
|
* parameter alpha.
|
||||||
|
*
|
||||||
|
* It has \f$p(x) = x^{\alpha-1}\frac{e^{-x}}{\Gamma(\alpha)}\f$.
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class gamma_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
explicit gamma_distribution(const result_type& alpha_arg = result_type(1))
|
||||||
|
: _exp(result_type(1)), _alpha(alpha_arg)
|
||||||
|
{
|
||||||
|
assert(_alpha > result_type(0));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
RealType alpha() const { return _alpha; }
|
||||||
|
|
||||||
|
void reset() { _exp.reset(); }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::tan; using std::sqrt; using std::exp; using std::log;
|
||||||
|
using std::pow;
|
||||||
|
#endif
|
||||||
|
if(_alpha == result_type(1)) {
|
||||||
|
return _exp(eng);
|
||||||
|
} else if(_alpha > result_type(1)) {
|
||||||
|
// Can we have a boost::mathconst please?
|
||||||
|
const result_type pi = result_type(3.14159265358979323846);
|
||||||
|
for(;;) {
|
||||||
|
result_type y = tan(pi * eng());
|
||||||
|
result_type x = sqrt(result_type(2)*_alpha-result_type(1))*y
|
||||||
|
+ _alpha-result_type(1);
|
||||||
|
if(x <= result_type(0))
|
||||||
|
continue;
|
||||||
|
if(eng() >
|
||||||
|
(result_type(1)+y*y) * exp((_alpha-result_type(1))
|
||||||
|
*log(x/(_alpha-result_type(1)))
|
||||||
|
- sqrt(result_type(2)*_alpha
|
||||||
|
-result_type(1))*y))
|
||||||
|
continue;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
} else /* alpha < 1.0 */ {
|
||||||
|
for(;;) {
|
||||||
|
result_type u = eng();
|
||||||
|
result_type y = _exp(eng);
|
||||||
|
result_type x, q;
|
||||||
|
if(u < _p) {
|
||||||
|
x = exp(-y/_alpha);
|
||||||
|
q = _p*exp(-x);
|
||||||
|
} else {
|
||||||
|
x = result_type(1)+y;
|
||||||
|
q = _p + (result_type(1)-_p) * pow(x, _alpha-result_type(1));
|
||||||
|
}
|
||||||
|
if(u >= q)
|
||||||
|
continue;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const gamma_distribution& gd)
|
||||||
|
{
|
||||||
|
os << gd._alpha;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, gamma_distribution& gd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> gd._alpha;
|
||||||
|
gd.init();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::exp;
|
||||||
|
#endif
|
||||||
|
_p = exp(result_type(1)) / (_alpha + exp(result_type(1)));
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
exponential_distribution<RealType> _exp;
|
||||||
|
result_type _alpha;
|
||||||
|
// some data precomputed from the parameters
|
||||||
|
result_type _p;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP
|
||||||
118
Boost/boost/random/geometric_distribution.hpp
Normal file
118
Boost/boost/random/geometric_distribution.hpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/* boost random/geometric_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: geometric_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp> // std::log
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/uniform_01.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && (__GNUC__ < 3)
|
||||||
|
// Special gcc workaround: gcc 2.95.x ignores using-declarations
|
||||||
|
// in template classes (confirmed by gcc author Martin v. Loewis)
|
||||||
|
using std::log;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An instantiation of the class template @c geometric_distribution models
|
||||||
|
* a \random_distribution. The distribution produces positive
|
||||||
|
* integers which are the number of bernoulli trials
|
||||||
|
* with probability @c p required to get one that fails.
|
||||||
|
*
|
||||||
|
* For the geometric distribution, \f$p(i) = (1-p) p^{i-1}\f$.
|
||||||
|
*/
|
||||||
|
template<class IntType = int, class RealType = double>
|
||||||
|
class geometric_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef IntType result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contructs a new geometric_distribution with the paramter @c p.
|
||||||
|
*
|
||||||
|
* Requires: 0 < p < 1
|
||||||
|
*/
|
||||||
|
explicit geometric_distribution(const RealType& p = RealType(0.5))
|
||||||
|
: _p(p)
|
||||||
|
{
|
||||||
|
assert(RealType(0) < _p && _p < RealType(1));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: the distribution parameter @c p
|
||||||
|
*/
|
||||||
|
RealType p() const { return _p; }
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
using std::log;
|
||||||
|
using std::floor;
|
||||||
|
#endif
|
||||||
|
return IntType(floor(log(RealType(1)-eng()) / _log_p)) + IntType(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const geometric_distribution& gd)
|
||||||
|
{
|
||||||
|
os << gd._p;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, geometric_distribution& gd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> gd._p;
|
||||||
|
gd.init();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/// \cond hide_private_functions
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
using std::log;
|
||||||
|
#endif
|
||||||
|
_log_p = log(_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
RealType _p;
|
||||||
|
RealType _log_p;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
|
||||||
|
|
||||||
173
Boost/boost/random/inversive_congruential.hpp
Normal file
173
Boost/boost/random/inversive_congruential.hpp
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
/* boost random/inversive_congruential.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: inversive_congruential.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
|
||||||
|
#define BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/detail/const_mod.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
// Eichenauer and Lehn 1986
|
||||||
|
/**
|
||||||
|
* Instantiations of class template @c inversive_congruential model a
|
||||||
|
* \pseudo_random_number_generator. It uses the inversive congruential
|
||||||
|
* algorithm (ICG) described in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Inversive pseudorandom number generators: concepts, results and links",
|
||||||
|
* Peter Hellekalek, In: "Proceedings of the 1995 Winter Simulation
|
||||||
|
* Conference", C. Alexopoulos, K. Kang, W.R. Lilegdon, and D. Goldsman
|
||||||
|
* (editors), 1995, pp. 255-262. ftp://random.mat.sbg.ac.at/pub/data/wsc95.ps
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* The output sequence is defined by x(n+1) = (a*inv(x(n)) - b) (mod p),
|
||||||
|
* where x(0), a, b, and the prime number p are parameters of the generator.
|
||||||
|
* The expression inv(k) denotes the multiplicative inverse of k in the
|
||||||
|
* field of integer numbers modulo p, with inv(0) := 0.
|
||||||
|
*
|
||||||
|
* The template parameter IntType shall denote a signed integral type large
|
||||||
|
* enough to hold p; a, b, and p are the parameters of the generators. The
|
||||||
|
* template parameter val is the validation value checked by validation.
|
||||||
|
*
|
||||||
|
* @xmlnote
|
||||||
|
* The implementation currently uses the Euclidian Algorithm to compute
|
||||||
|
* the multiplicative inverse. Therefore, the inversive generators are about
|
||||||
|
* 10-20 times slower than the others (see section"performance"). However,
|
||||||
|
* the paper talks of only 3x slowdown, so the Euclidian Algorithm is probably
|
||||||
|
* not optimal for calculating the multiplicative inverse.
|
||||||
|
* @endxmlnote
|
||||||
|
*/
|
||||||
|
template<class IntType, IntType a, IntType b, IntType p, IntType val>
|
||||||
|
class inversive_congruential
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef IntType result_type;
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
static const bool has_fixed_range = true;
|
||||||
|
static const result_type min_value = (b == 0 ? 1 : 0);
|
||||||
|
static const result_type max_value = p-1;
|
||||||
|
#else
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
#endif
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, multiplier = a);
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, increment = b);
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, modulus = p);
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return b == 0 ? 1 : 0; }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return p-1; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an inversive_congruential generator with
|
||||||
|
* @c y0 as the initial state.
|
||||||
|
*/
|
||||||
|
explicit inversive_congruential(IntType y0 = 1) : value(y0)
|
||||||
|
{
|
||||||
|
BOOST_STATIC_ASSERT(b >= 0);
|
||||||
|
BOOST_STATIC_ASSERT(p > 1);
|
||||||
|
BOOST_STATIC_ASSERT(a >= 1);
|
||||||
|
if(b == 0)
|
||||||
|
assert(y0 > 0);
|
||||||
|
}
|
||||||
|
template<class It> inversive_congruential(It& first, It last)
|
||||||
|
{ seed(first, last); }
|
||||||
|
|
||||||
|
/** Changes the current state to y0. */
|
||||||
|
void seed(IntType y0 = 1) { value = y0; if(b == 0) assert(y0 > 0); }
|
||||||
|
template<class It> void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
if(first == last)
|
||||||
|
throw std::invalid_argument("inversive_congruential::seed");
|
||||||
|
value = *first++;
|
||||||
|
}
|
||||||
|
IntType operator()()
|
||||||
|
{
|
||||||
|
typedef const_mod<IntType, p> do_mod;
|
||||||
|
value = do_mod::mult_add(a, do_mod::invert(value), b);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validation(result_type x) { return val == x; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, inversive_congruential x)
|
||||||
|
{ os << x.value; return os; }
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, inversive_congruential& x)
|
||||||
|
{ is >> x.value; return is; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(inversive_congruential x, inversive_congruential y)
|
||||||
|
{ return x.value == y.value; }
|
||||||
|
friend bool operator!=(inversive_congruential x, inversive_congruential y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(inversive_congruential rhs) const
|
||||||
|
{ return value == rhs.value; }
|
||||||
|
bool operator!=(inversive_congruential rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
private:
|
||||||
|
IntType value;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class IntType, IntType a, IntType b, IntType p, IntType val>
|
||||||
|
const bool inversive_congruential<IntType, a, b, p, val>::has_fixed_range;
|
||||||
|
template<class IntType, IntType a, IntType b, IntType p, IntType val>
|
||||||
|
const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::min_value;
|
||||||
|
template<class IntType, IntType a, IntType b, IntType p, IntType val>
|
||||||
|
const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::max_value;
|
||||||
|
template<class IntType, IntType a, IntType b, IntType p, IntType val>
|
||||||
|
const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::multiplier;
|
||||||
|
template<class IntType, IntType a, IntType b, IntType p, IntType val>
|
||||||
|
const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::increment;
|
||||||
|
template<class IntType, IntType a, IntType b, IntType p, IntType val>
|
||||||
|
const typename inversive_congruential<IntType, a, b, p, val>::result_type inversive_congruential<IntType, a, b, p, val>::modulus;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The specialization hellekalek1995 was suggested in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Inversive pseudorandom number generators: concepts, results and links",
|
||||||
|
* Peter Hellekalek, In: "Proceedings of the 1995 Winter Simulation
|
||||||
|
* Conference", C. Alexopoulos, K. Kang, W.R. Lilegdon, and D. Goldsman
|
||||||
|
* (editors), 1995, pp. 255-262. ftp://random.mat.sbg.ac.at/pub/data/wsc95.ps
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::inversive_congruential<int32_t, 9102, 2147483647-36884165,
|
||||||
|
2147483647, 0> hellekalek1995;
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
|
||||||
605
Boost/boost/random/lagged_fibonacci.hpp
Normal file
605
Boost/boost/random/lagged_fibonacci.hpp
Normal file
@@ -0,0 +1,605 @@
|
|||||||
|
/* boost random/lagged_fibonacci.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: lagged_fibonacci.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_LAGGED_FIBONACCI_HPP
|
||||||
|
#define BOOST_RANDOM_LAGGED_FIBONACCI_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm> // std::max
|
||||||
|
#include <iterator>
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp> // std::pow
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
#include <boost/random/uniform_01.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/detail/seed.hpp>
|
||||||
|
#include <boost/random/detail/pass_through_engine.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300
|
||||||
|
# define BOOST_RANDOM_EXTRACT_LF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE_CC__) && defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ <= 3)
|
||||||
|
# define BOOST_RANDOM_EXTRACT_LF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# ifdef BOOST_RANDOM_EXTRACT_LF
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<class IStream, class F, class RealType>
|
||||||
|
IStream&
|
||||||
|
extract_lagged_fibonacci_01(
|
||||||
|
IStream& is
|
||||||
|
, F const& f
|
||||||
|
, unsigned int& i
|
||||||
|
, RealType* x
|
||||||
|
, RealType modulus)
|
||||||
|
{
|
||||||
|
is >> i >> std::ws;
|
||||||
|
for(unsigned int i = 0; i < f.long_lag; ++i)
|
||||||
|
{
|
||||||
|
RealType value;
|
||||||
|
is >> value >> std::ws;
|
||||||
|
x[i] = value / modulus;
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class IStream, class F, class UIntType>
|
||||||
|
IStream&
|
||||||
|
extract_lagged_fibonacci(
|
||||||
|
IStream& is
|
||||||
|
, F const& f
|
||||||
|
, unsigned int& i
|
||||||
|
, UIntType* x)
|
||||||
|
{
|
||||||
|
is >> i >> std::ws;
|
||||||
|
for(unsigned int i = 0; i < f.long_lag; ++i)
|
||||||
|
is >> x[i] >> std::ws;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template \lagged_fibonacci model a
|
||||||
|
* \pseudo_random_number_generator. It uses a lagged Fibonacci
|
||||||
|
* algorithm with two lags @c p and @c q:
|
||||||
|
* x(i) = x(i-p) + x(i-q) (mod 2<sup>w</sup>) with p > q.
|
||||||
|
*/
|
||||||
|
template<class UIntType, int w, unsigned int p, unsigned int q,
|
||||||
|
UIntType val = 0>
|
||||||
|
class lagged_fibonacci
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef UIntType result_type;
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
BOOST_STATIC_CONSTANT(int, word_size = w);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: the smallest value that the generator can produce
|
||||||
|
*/
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
|
||||||
|
/**
|
||||||
|
* Returns: the largest value that the generator can produce
|
||||||
|
*/
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return wordmask; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new @c lagged_fibonacci generator and calls @c seed()
|
||||||
|
*/
|
||||||
|
lagged_fibonacci() { init_wordmask(); seed(); }
|
||||||
|
/**
|
||||||
|
* Creates a new @c lagged_fibonacci generator and calls @c seed(value)
|
||||||
|
*/
|
||||||
|
explicit lagged_fibonacci(uint32_t value) { init_wordmask(); seed(value); }
|
||||||
|
/**
|
||||||
|
* Creates a new @c lagged_fibonacci generator and calls @c seed(first, last)
|
||||||
|
*/
|
||||||
|
template<class It> lagged_fibonacci(It& first, It last)
|
||||||
|
{ init_wordmask(); seed(first, last); }
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void init_wordmask()
|
||||||
|
{
|
||||||
|
wordmask = 0;
|
||||||
|
for(int j = 0; j < w; ++j)
|
||||||
|
wordmask |= (1u << j);
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Sets the state of the generator to values produced by
|
||||||
|
* a \minstd_rand generator.
|
||||||
|
*/
|
||||||
|
void seed(uint32_t value = 331u)
|
||||||
|
{
|
||||||
|
minstd_rand0 gen(value);
|
||||||
|
for(unsigned int j = 0; j < long_lag; ++j)
|
||||||
|
x[j] = gen() & wordmask;
|
||||||
|
i = long_lag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the state of the generator to values from the iterator
|
||||||
|
* range [first, last). If there are not enough elements in the
|
||||||
|
* range [first, last) throws @c std::invalid_argument.
|
||||||
|
*/
|
||||||
|
template<class It>
|
||||||
|
void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
// word size could be smaller than the seed values
|
||||||
|
unsigned int j;
|
||||||
|
for(j = 0; j < long_lag && first != last; ++j, ++first)
|
||||||
|
x[j] = *first & wordmask;
|
||||||
|
i = long_lag;
|
||||||
|
if(first == last && j < long_lag)
|
||||||
|
throw std::invalid_argument("lagged_fibonacci::seed");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: the next value of the generator
|
||||||
|
*/
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
if(i >= long_lag)
|
||||||
|
fill();
|
||||||
|
return x[i++];
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validation(result_type x)
|
||||||
|
{
|
||||||
|
return x == val;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const lagged_fibonacci& f)
|
||||||
|
{
|
||||||
|
os << f.i << " ";
|
||||||
|
for(unsigned int i = 0; i < f.long_lag; ++i)
|
||||||
|
os << f.x[i] << " ";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT, Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT, Traits>& is, lagged_fibonacci& f)
|
||||||
|
{
|
||||||
|
# ifdef BOOST_RANDOM_EXTRACT_LF
|
||||||
|
return detail::extract_lagged_fibonacci(is, f, f.i, f.x);
|
||||||
|
# else
|
||||||
|
is >> f.i >> std::ws;
|
||||||
|
for(unsigned int i = 0; i < f.long_lag; ++i)
|
||||||
|
is >> f.x[i] >> std::ws;
|
||||||
|
return is;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const lagged_fibonacci& x, const lagged_fibonacci& y)
|
||||||
|
{ return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); }
|
||||||
|
friend bool operator!=(const lagged_fibonacci& x,
|
||||||
|
const lagged_fibonacci& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const lagged_fibonacci& rhs) const
|
||||||
|
{ return i == rhs.i && std::equal(x, x+long_lag, rhs.x); }
|
||||||
|
bool operator!=(const lagged_fibonacci& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void fill();
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
UIntType wordmask;
|
||||||
|
unsigned int i;
|
||||||
|
UIntType x[long_lag];
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
|
||||||
|
const bool lagged_fibonacci<UIntType, w, p, q, val>::has_fixed_range;
|
||||||
|
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
|
||||||
|
const unsigned int lagged_fibonacci<UIntType, w, p, q, val>::long_lag;
|
||||||
|
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
|
||||||
|
const unsigned int lagged_fibonacci<UIntType, w, p, q, val>::short_lag;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
|
||||||
|
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
|
||||||
|
void lagged_fibonacci<UIntType, w, p, q, val>::fill()
|
||||||
|
{
|
||||||
|
// two loops to avoid costly modulo operations
|
||||||
|
{ // extra scope for MSVC brokenness w.r.t. for scope
|
||||||
|
for(unsigned int j = 0; j < short_lag; ++j)
|
||||||
|
x[j] = (x[j] + x[j+(long_lag-short_lag)]) & wordmask;
|
||||||
|
}
|
||||||
|
for(unsigned int j = short_lag; j < long_lag; ++j)
|
||||||
|
x[j] = (x[j] + x[j-short_lag]) & wordmask;
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// lagged Fibonacci generator for the range [0..1)
|
||||||
|
// contributed by Matthias Troyer
|
||||||
|
// for p=55, q=24 originally by G. J. Mitchell and D. P. Moore 1958
|
||||||
|
|
||||||
|
template<class T, unsigned int p, unsigned int q>
|
||||||
|
struct fibonacci_validation
|
||||||
|
{
|
||||||
|
BOOST_STATIC_CONSTANT(bool, is_specialized = false);
|
||||||
|
static T value() { return 0; }
|
||||||
|
static T tolerance() { return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class T, unsigned int p, unsigned int q>
|
||||||
|
const bool fibonacci_validation<T, p, q>::is_specialized;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_RANDOM_FIBONACCI_VAL(T,P,Q,V,E) \
|
||||||
|
template<> \
|
||||||
|
struct fibonacci_validation<T, P, Q> \
|
||||||
|
{ \
|
||||||
|
BOOST_STATIC_CONSTANT(bool, is_specialized = true); \
|
||||||
|
static T value() { return V; } \
|
||||||
|
static T tolerance() \
|
||||||
|
{ return (std::max)(E, static_cast<T>(5*std::numeric_limits<T>::epsilon())); } \
|
||||||
|
};
|
||||||
|
// (The extra static_cast<T> in the std::max call above is actually
|
||||||
|
// unnecessary except for HP aCC 1.30, which claims that
|
||||||
|
// numeric_limits<double>::epsilon() doesn't actually return a double.)
|
||||||
|
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 607, 273, 0.4293817707235914, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 1279, 418, 0.9421630240437659, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 2281, 1252, 0.1768114046909004, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 3217, 576, 0.1956232694868209, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 4423, 2098, 0.9499762202147172, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 9689, 5502, 0.05737836943695162, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 19937, 9842, 0.5076528587449834, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 23209, 13470, 0.5414473810619185, 1e-14)
|
||||||
|
BOOST_RANDOM_FIBONACCI_VAL(double, 44497,21034, 0.254135073399297, 1e-14)
|
||||||
|
|
||||||
|
#undef BOOST_RANDOM_FIBONACCI_VAL
|
||||||
|
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template @c lagged_fibonacci_01 model a
|
||||||
|
* \pseudo_random_number_generator. It uses a lagged Fibonacci
|
||||||
|
* algorithm with two lags @c p and @c q, evaluated in floating-point
|
||||||
|
* arithmetic: x(i) = x(i-p) + x(i-q) (mod 1) with p > q. See
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Uniform random number generators for supercomputers", Richard Brent,
|
||||||
|
* Proc. of Fifth Australian Supercomputer Conference, Melbourne,
|
||||||
|
* Dec. 1992, pp. 704-706.
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* @xmlnote
|
||||||
|
* The quality of the generator crucially depends on the choice
|
||||||
|
* of the parameters. User code should employ one of the sensibly
|
||||||
|
* parameterized generators such as \lagged_fibonacci607 instead.
|
||||||
|
* @endxmlnote
|
||||||
|
*
|
||||||
|
* The generator requires considerable amounts of memory for the storage
|
||||||
|
* of its state array. For example, \lagged_fibonacci607 requires about
|
||||||
|
* 4856 bytes and \lagged_fibonacci44497 requires about 350 KBytes.
|
||||||
|
*/
|
||||||
|
template<class RealType, int w, unsigned int p, unsigned int q>
|
||||||
|
class lagged_fibonacci_01
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType result_type;
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
BOOST_STATIC_CONSTANT(int, word_size = w);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
|
||||||
|
|
||||||
|
/** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(). */
|
||||||
|
lagged_fibonacci_01() { init_modulus(); seed(); }
|
||||||
|
/** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(value). */
|
||||||
|
BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_01, uint32_t, value)
|
||||||
|
{ init_modulus(); seed(value); }
|
||||||
|
/** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(gen). */
|
||||||
|
BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(lagged_fibonacci_01, Generator, gen)
|
||||||
|
{ init_modulus(); seed(gen); }
|
||||||
|
template<class It> lagged_fibonacci_01(It& first, It last)
|
||||||
|
{ init_modulus(); seed(first, last); }
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void init_modulus()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::pow;
|
||||||
|
#endif
|
||||||
|
_modulus = pow(RealType(2), word_size);
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** Calls seed(331u). */
|
||||||
|
void seed() { seed(331u); }
|
||||||
|
/**
|
||||||
|
* Constructs a \minstd_rand0 generator with the constructor parameter
|
||||||
|
* value and calls seed with it. Distinct seeds in the range
|
||||||
|
* [1, 2147483647) will produce generators with different states. Other
|
||||||
|
* seeds will be equivalent to some seed within this range. See
|
||||||
|
* \linear_congruential for details.
|
||||||
|
*/
|
||||||
|
BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(lagged_fibonacci_01, uint32_t, value)
|
||||||
|
{
|
||||||
|
minstd_rand0 intgen(value);
|
||||||
|
seed(intgen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the state of this @c lagged_fibonacci_01 to the values returned
|
||||||
|
* by p invocations of \uniform_01<code>\<RealType\>()(gen)</code>.
|
||||||
|
*
|
||||||
|
* Complexity: Exactly p invocations of gen.
|
||||||
|
*/
|
||||||
|
BOOST_RANDOM_DETAIL_GENERATOR_SEED(lagged_fibonacci, Generator, gen)
|
||||||
|
{
|
||||||
|
// use pass-by-reference, but wrap argument in pass_through_engine
|
||||||
|
typedef detail::pass_through_engine<Generator&> ref_gen;
|
||||||
|
uniform_01<ref_gen, RealType> gen01 =
|
||||||
|
uniform_01<ref_gen, RealType>(ref_gen(gen));
|
||||||
|
// I could have used std::generate_n, but it takes "gen" by value
|
||||||
|
for(unsigned int j = 0; j < long_lag; ++j)
|
||||||
|
x[j] = gen01();
|
||||||
|
i = long_lag;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class It>
|
||||||
|
void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::fmod;
|
||||||
|
using std::pow;
|
||||||
|
#endif
|
||||||
|
unsigned long mask = ~((~0u) << (w%32)); // now lowest w bits set
|
||||||
|
RealType two32 = pow(RealType(2), 32);
|
||||||
|
unsigned int j;
|
||||||
|
for(j = 0; j < long_lag && first != last; ++j) {
|
||||||
|
x[j] = RealType(0);
|
||||||
|
for(int k = 0; k < w/32 && first != last; ++k, ++first)
|
||||||
|
x[j] += *first / pow(two32,k+1);
|
||||||
|
if(first != last && mask != 0) {
|
||||||
|
x[j] += fmod((*first & mask) / _modulus, RealType(1));
|
||||||
|
++first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i = long_lag;
|
||||||
|
if(first == last && j < long_lag)
|
||||||
|
throw std::invalid_argument("lagged_fibonacci_01::seed");
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
if(i >= long_lag)
|
||||||
|
fill();
|
||||||
|
return x[i++];
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validation(result_type x)
|
||||||
|
{
|
||||||
|
result_type v = fibonacci_validation<result_type, p, q>::value();
|
||||||
|
result_type epsilon = fibonacci_validation<result_type, p, q>::tolerance();
|
||||||
|
// std::abs is a source of trouble: sometimes, it's not overloaded
|
||||||
|
// for double, plus the usual namespace std noncompliance -> avoid it
|
||||||
|
// using std::abs;
|
||||||
|
// return abs(x - v) < 5 * epsilon
|
||||||
|
return x > v - epsilon && x < v + epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const lagged_fibonacci_01&f)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::pow;
|
||||||
|
#endif
|
||||||
|
os << f.i << " ";
|
||||||
|
std::ios_base::fmtflags oldflags = os.flags(os.dec | os.fixed | os.left);
|
||||||
|
for(unsigned int i = 0; i < f.long_lag; ++i)
|
||||||
|
os << f.x[i] * f._modulus << " ";
|
||||||
|
os.flags(oldflags);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT, Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT, Traits>& is, lagged_fibonacci_01& f)
|
||||||
|
{
|
||||||
|
# ifdef BOOST_RANDOM_EXTRACT_LF
|
||||||
|
return detail::extract_lagged_fibonacci_01(is, f, f.i, f.x, f._modulus);
|
||||||
|
# else
|
||||||
|
is >> f.i >> std::ws;
|
||||||
|
for(unsigned int i = 0; i < f.long_lag; ++i) {
|
||||||
|
typename lagged_fibonacci_01::result_type value;
|
||||||
|
is >> value >> std::ws;
|
||||||
|
f.x[i] = value / f._modulus;
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const lagged_fibonacci_01& x,
|
||||||
|
const lagged_fibonacci_01& y)
|
||||||
|
{ return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); }
|
||||||
|
friend bool operator!=(const lagged_fibonacci_01& x,
|
||||||
|
const lagged_fibonacci_01& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const lagged_fibonacci_01& rhs) const
|
||||||
|
{ return i == rhs.i && std::equal(x, x+long_lag, rhs.x); }
|
||||||
|
bool operator!=(const lagged_fibonacci_01& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void fill();
|
||||||
|
/// \endcond
|
||||||
|
unsigned int i;
|
||||||
|
RealType x[long_lag];
|
||||||
|
RealType _modulus;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class RealType, int w, unsigned int p, unsigned int q>
|
||||||
|
const bool lagged_fibonacci_01<RealType, w, p, q>::has_fixed_range;
|
||||||
|
template<class RealType, int w, unsigned int p, unsigned int q>
|
||||||
|
const unsigned int lagged_fibonacci_01<RealType, w, p, q>::long_lag;
|
||||||
|
template<class RealType, int w, unsigned int p, unsigned int q>
|
||||||
|
const unsigned int lagged_fibonacci_01<RealType, w, p, q>::short_lag;
|
||||||
|
template<class RealType, int w, unsigned int p, unsigned int q>
|
||||||
|
const int lagged_fibonacci_01<RealType,w,p,q>::word_size;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
template<class RealType, int w, unsigned int p, unsigned int q>
|
||||||
|
void lagged_fibonacci_01<RealType, w, p, q>::fill()
|
||||||
|
{
|
||||||
|
// two loops to avoid costly modulo operations
|
||||||
|
{ // extra scope for MSVC brokenness w.r.t. for scope
|
||||||
|
for(unsigned int j = 0; j < short_lag; ++j) {
|
||||||
|
RealType t = x[j] + x[j+(long_lag-short_lag)];
|
||||||
|
if(t >= RealType(1))
|
||||||
|
t -= RealType(1);
|
||||||
|
x[j] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(unsigned int j = short_lag; j < long_lag; ++j) {
|
||||||
|
RealType t = x[j] + x[j-short_lag];
|
||||||
|
if(t >= RealType(1))
|
||||||
|
t -= RealType(1);
|
||||||
|
x[j] = t;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
#ifdef BOOST_RANDOM_DOXYGEN
|
||||||
|
namespace detail {
|
||||||
|
/**
|
||||||
|
* The specializations lagged_fibonacci607 ... lagged_fibonacci44497
|
||||||
|
* use well tested lags.
|
||||||
|
*
|
||||||
|
* See
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "On the Periods of Generalized Fibonacci Recurrences", Richard P. Brent
|
||||||
|
* Computer Sciences Laboratory Australian National University, December 1992
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* The lags used here can be found in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Uniform random number generators for supercomputers", Richard Brent,
|
||||||
|
* Proc. of Fifth Australian Supercomputer Conference, Melbourne,
|
||||||
|
* Dec. 1992, pp. 704-706.
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
struct lagged_fibonacci_doc {};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 607, 273> lagged_fibonacci607;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 1279, 418> lagged_fibonacci1279;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 2281, 1252> lagged_fibonacci2281;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 3217, 576> lagged_fibonacci3217;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 4423, 2098> lagged_fibonacci4423;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 9689, 5502> lagged_fibonacci9689;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 19937, 9842> lagged_fibonacci19937;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 23209, 13470> lagged_fibonacci23209;
|
||||||
|
/**
|
||||||
|
* @copydoc boost::detail::lagged_fibonacci_doc
|
||||||
|
*/
|
||||||
|
typedef random::lagged_fibonacci_01<double, 48, 44497, 21034> lagged_fibonacci44497;
|
||||||
|
|
||||||
|
|
||||||
|
// It is possible to partially specialize uniform_01<> on lagged_fibonacci_01<>
|
||||||
|
// to help the compiler generate efficient code. For GCC, this seems useless,
|
||||||
|
// because GCC optimizes (x-0)/(1-0) to (x-0). This is good enough for now.
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_LAGGED_FIBONACCI_HPP
|
||||||
403
Boost/boost/random/linear_congruential.hpp
Normal file
403
Boost/boost/random/linear_congruential.hpp
Normal file
@@ -0,0 +1,403 @@
|
|||||||
|
/* boost random/linear_congruential.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: linear_congruential.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
|
||||||
|
#define BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/detail/const_mod.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
|
||||||
|
#include <boost/random/detail/disable_warnings.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template linear_congruential model a
|
||||||
|
* \pseudo_random_number_generator. Linear congruential pseudo-random
|
||||||
|
* number generators are described in:
|
||||||
|
*
|
||||||
|
* "Mathematical methods in large-scale computing units", D. H. Lehmer,
|
||||||
|
* Proc. 2nd Symposium on Large-Scale Digital Calculating Machines,
|
||||||
|
* Harvard University Press, 1951, pp. 141-146
|
||||||
|
*
|
||||||
|
* Let x(n) denote the sequence of numbers returned by some pseudo-random
|
||||||
|
* number generator. Then for the linear congruential generator,
|
||||||
|
* x(n+1) := (a * x(n) + c) mod m. Parameters for the generator are
|
||||||
|
* x(0), a, c, m. The template parameter IntType shall denote an integral
|
||||||
|
* type. It must be large enough to hold values a, c, and m. The template
|
||||||
|
* parameters a and c must be smaller than m.
|
||||||
|
*
|
||||||
|
* Note: The quality of the generator crucially depends on the choice of
|
||||||
|
* the parameters. User code should use one of the sensibly parameterized
|
||||||
|
* generators such as minstd_rand instead.
|
||||||
|
*/
|
||||||
|
template<class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
class linear_congruential
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef IntType result_type;
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
static const bool has_fixed_range = true;
|
||||||
|
static const result_type min_value = ( c == 0 ? 1 : 0 );
|
||||||
|
static const result_type max_value = m-1;
|
||||||
|
#else
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
#endif
|
||||||
|
BOOST_STATIC_CONSTANT(IntType, multiplier = a);
|
||||||
|
BOOST_STATIC_CONSTANT(IntType, increment = c);
|
||||||
|
BOOST_STATIC_CONSTANT(IntType, modulus = m);
|
||||||
|
|
||||||
|
// MSVC 6 and possibly others crash when encountering complicated integral
|
||||||
|
// constant expressions. Avoid the check for now.
|
||||||
|
// BOOST_STATIC_ASSERT(m == 0 || a < m);
|
||||||
|
// BOOST_STATIC_ASSERT(m == 0 || c < m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a linear_congruential generator, seeding it with @c x0.
|
||||||
|
*/
|
||||||
|
explicit linear_congruential(IntType x0 = 1)
|
||||||
|
{
|
||||||
|
seed(x0);
|
||||||
|
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c linear_congruential generator and seeds it
|
||||||
|
* with values taken from the itrator range [first, last)
|
||||||
|
* and adjusts first to point to the element after the last one
|
||||||
|
* used. If there are not enough elements, throws @c std::invalid_argument.
|
||||||
|
*
|
||||||
|
* first and last must be input iterators.
|
||||||
|
*/
|
||||||
|
template<class It>
|
||||||
|
linear_congruential(It& first, It last)
|
||||||
|
{
|
||||||
|
seed(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy constructor and assignment operator are fine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If c mod m is zero and x0 mod m is zero, changes the current value of
|
||||||
|
* the generator to 1. Otherwise, changes it to x0 mod m. If c is zero,
|
||||||
|
* distinct seeds in the range [1,m) will leave the generator in distinct
|
||||||
|
* states. If c is not zero, the range is [0,m).
|
||||||
|
*/
|
||||||
|
void seed(IntType x0 = 1)
|
||||||
|
{
|
||||||
|
// wrap _x if it doesn't fit in the destination
|
||||||
|
if(modulus == 0) {
|
||||||
|
_x = x0;
|
||||||
|
} else {
|
||||||
|
_x = x0 % modulus;
|
||||||
|
}
|
||||||
|
// handle negative seeds
|
||||||
|
if(_x <= 0 && _x != 0) {
|
||||||
|
_x += modulus;
|
||||||
|
}
|
||||||
|
// adjust to the correct range
|
||||||
|
if(increment == 0 && _x == 0) {
|
||||||
|
_x = 1;
|
||||||
|
}
|
||||||
|
assert(_x >= (min)());
|
||||||
|
assert(_x <= (max)());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* seeds a @c linear_congruential generator with values taken
|
||||||
|
* from the itrator range [first, last) and adjusts @c first to
|
||||||
|
* point to the element after the last one used. If there are
|
||||||
|
* not enough elements, throws @c std::invalid_argument.
|
||||||
|
*
|
||||||
|
* @c first and @c last must be input iterators.
|
||||||
|
*/
|
||||||
|
template<class It>
|
||||||
|
void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
if(first == last)
|
||||||
|
throw std::invalid_argument("linear_congruential::seed");
|
||||||
|
seed(*first++);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the smallest value that the @c linear_congruential generator
|
||||||
|
* can produce.
|
||||||
|
*/
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return c == 0 ? 1 : 0; }
|
||||||
|
/**
|
||||||
|
* Returns the largest value that the @c linear_congruential generator
|
||||||
|
* can produce.
|
||||||
|
*/
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return modulus-1; }
|
||||||
|
|
||||||
|
/** Returns the next value of the @c linear_congruential generator. */
|
||||||
|
IntType operator()()
|
||||||
|
{
|
||||||
|
_x = const_mod<IntType, m>::mult_add(a, _x, c);
|
||||||
|
return _x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validation(IntType x) { return val == x; }
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const linear_congruential& rhs) const
|
||||||
|
{ return _x == rhs._x; }
|
||||||
|
bool operator!=(const linear_congruential& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
|
||||||
|
#else
|
||||||
|
friend bool operator==(const linear_congruential& x,
|
||||||
|
const linear_congruential& y)
|
||||||
|
{ return x._x == y._x; }
|
||||||
|
friend bool operator!=(const linear_congruential& x,
|
||||||
|
const linear_congruential& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
|
||||||
|
#if !defined(BOOST_RANDOM_NO_STREAM_OPERATORS) && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os,
|
||||||
|
const linear_congruential& lcg)
|
||||||
|
{
|
||||||
|
return os << lcg._x;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is,
|
||||||
|
linear_congruential& lcg)
|
||||||
|
{
|
||||||
|
return is >> lcg._x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IntType _x;
|
||||||
|
};
|
||||||
|
|
||||||
|
// probably needs the "no native streams" caveat for STLPort
|
||||||
|
#if !defined(__SGI_STL_PORT) && BOOST_WORKAROUND(__GNUC__, == 2)
|
||||||
|
template<class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
std::ostream&
|
||||||
|
operator<<(std::ostream& os,
|
||||||
|
const linear_congruential<IntType,a,c,m,val>& lcg)
|
||||||
|
{
|
||||||
|
return os << lcg._x;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
std::istream&
|
||||||
|
operator>>(std::istream& is,
|
||||||
|
linear_congruential<IntType,a,c,m,val>& lcg)
|
||||||
|
{
|
||||||
|
return is >> lcg._x;
|
||||||
|
}
|
||||||
|
#elif defined(BOOST_RANDOM_NO_STREAM_OPERATORS) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||||
|
template<class CharT, class Traits, class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os,
|
||||||
|
const linear_congruential<IntType,a,c,m,val>& lcg)
|
||||||
|
{
|
||||||
|
return os << lcg._x;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits, class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is,
|
||||||
|
linear_congruential<IntType,a,c,m,val>& lcg)
|
||||||
|
{
|
||||||
|
return is >> lcg._x;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
const bool linear_congruential<IntType, a, c, m, val>::has_fixed_range;
|
||||||
|
template<class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
const typename linear_congruential<IntType, a, c, m, val>::result_type linear_congruential<IntType, a, c, m, val>::min_value;
|
||||||
|
template<class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
const typename linear_congruential<IntType, a, c, m, val>::result_type linear_congruential<IntType, a, c, m, val>::max_value;
|
||||||
|
template<class IntType, IntType a, IntType c, IntType m, IntType val>
|
||||||
|
const IntType linear_congruential<IntType,a,c,m,val>::modulus;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
// validation values from the publications
|
||||||
|
/**
|
||||||
|
* The specialization \minstd_rand0 was originally suggested in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* A pseudo-random number generator for the System/360, P.A. Lewis,
|
||||||
|
* A.S. Goodman, J.M. Miller, IBM Systems Journal, Vol. 8, No. 2,
|
||||||
|
* 1969, pp. 136-146
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* It is examined more closely together with \minstd_rand in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Random Number Generators: Good ones are hard to find",
|
||||||
|
* Stephen K. Park and Keith W. Miller, Communications of
|
||||||
|
* the ACM, Vol. 31, No. 10, October 1988, pp. 1192-1201
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::linear_congruential<int32_t, 16807, 0, 2147483647,
|
||||||
|
1043618065> minstd_rand0;
|
||||||
|
|
||||||
|
/** The specialization \minstd_rand was suggested in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Random Number Generators: Good ones are hard to find",
|
||||||
|
* Stephen K. Park and Keith W. Miller, Communications of
|
||||||
|
* the ACM, Vol. 31, No. 10, October 1988, pp. 1192-1201
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::linear_congruential<int32_t, 48271, 0, 2147483647,
|
||||||
|
399268537> minstd_rand;
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
|
||||||
|
/** Class @c rand48 models a \pseudo_random_number_generator. It uses
|
||||||
|
* the linear congruential algorithm with the parameters a = 0x5DEECE66D,
|
||||||
|
* c = 0xB, m = 2**48. It delivers identical results to the @c lrand48()
|
||||||
|
* function available on some systems (assuming lcong48 has not been called).
|
||||||
|
*
|
||||||
|
* It is only available on systems where @c uint64_t is provided as an
|
||||||
|
* integral type, so that for example static in-class constants and/or
|
||||||
|
* enum definitions with large @c uint64_t numbers work.
|
||||||
|
*/
|
||||||
|
class rand48
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef int32_t result_type;
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
static const bool has_fixed_range = true;
|
||||||
|
static const int32_t min_value = 0;
|
||||||
|
static const int32_t max_value = integer_traits<int32_t>::const_max;
|
||||||
|
#else
|
||||||
|
enum { has_fixed_range = false };
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Returns the smallest value that the generator can produce
|
||||||
|
*/
|
||||||
|
int32_t min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
|
||||||
|
/**
|
||||||
|
* Returns the largest value that the generator can produce
|
||||||
|
*/
|
||||||
|
int32_t max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::numeric_limits<int32_t>::max BOOST_PREVENT_MACRO_SUBSTITUTION (); }
|
||||||
|
|
||||||
|
#ifdef BOOST_RANDOM_DOXYGEN
|
||||||
|
/**
|
||||||
|
* If T is an integral type smaller than int46_t, constructs
|
||||||
|
* a \rand48 generator with x(0) := (x0 << 16) | 0x330e. Otherwise
|
||||||
|
* constructs a \rand48 generator with x(0) = x0.
|
||||||
|
*/
|
||||||
|
template<class T> explicit rand48(T x0 = 1);
|
||||||
|
#else
|
||||||
|
rand48() : lcf(cnv(static_cast<int32_t>(1))) {}
|
||||||
|
template<class T> explicit rand48(T x0) : lcf(cnv(x0)) { }
|
||||||
|
#endif
|
||||||
|
template<class It> rand48(It& first, It last) : lcf(first, last) { }
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
#ifdef BOOST_RANDOM_DOXYGEN
|
||||||
|
/**
|
||||||
|
* If T is an integral type smaller than int46_t, changes
|
||||||
|
* the current value x(n) of the generator to (x0 << 16) | 0x330e.
|
||||||
|
* Otherwise changes the current value x(n) to x0.
|
||||||
|
*/
|
||||||
|
template<class T> void seed(T x0 = 1);
|
||||||
|
#else
|
||||||
|
void seed() { seed(static_cast<int32_t>(1)); }
|
||||||
|
template<class T> void seed(T x0) { lcf.seed(cnv(x0)); }
|
||||||
|
#endif
|
||||||
|
template<class It> void seed(It& first, It last) { lcf.seed(first,last); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next value of the generator.
|
||||||
|
*/
|
||||||
|
int32_t operator()() { return static_cast<int32_t>(lcf() >> 17); }
|
||||||
|
// by experiment from lrand48()
|
||||||
|
static bool validation(int32_t x) { return x == 1993516219; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT,class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const rand48& r)
|
||||||
|
{ os << r.lcf; return os; }
|
||||||
|
|
||||||
|
template<class CharT,class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, rand48& r)
|
||||||
|
{ is >> r.lcf; return is; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const rand48& x, const rand48& y)
|
||||||
|
{ return x.lcf == y.lcf; }
|
||||||
|
friend bool operator!=(const rand48& x, const rand48& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const rand48& rhs) const
|
||||||
|
{ return lcf == rhs.lcf; }
|
||||||
|
bool operator!=(const rand48& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
random::linear_congruential<uint64_t,
|
||||||
|
uint64_t(0xDEECE66DUL) | (uint64_t(0x5) << 32), // xxxxULL is not portable
|
||||||
|
0xB, uint64_t(1)<<48, /* unknown */ 0> lcf;
|
||||||
|
template<class T>
|
||||||
|
static uint64_t cnv(T x)
|
||||||
|
{
|
||||||
|
if(sizeof(T) < sizeof(uint64_t)) {
|
||||||
|
return (static_cast<uint64_t>(x) << 16) | 0x330e;
|
||||||
|
} else {
|
||||||
|
return(static_cast<uint64_t>(x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static uint64_t cnv(float x) { return(static_cast<uint64_t>(x)); }
|
||||||
|
static uint64_t cnv(double x) { return(static_cast<uint64_t>(x)); }
|
||||||
|
static uint64_t cnv(long double x) { return(static_cast<uint64_t>(x)); }
|
||||||
|
/// \endcond
|
||||||
|
};
|
||||||
|
#endif /* !BOOST_NO_INT64_T && !BOOST_NO_INTEGRAL_INT64_T */
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#include <boost/random/detail/enable_warnings.hpp>
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
|
||||||
160
Boost/boost/random/linear_feedback_shift.hpp
Normal file
160
Boost/boost/random/linear_feedback_shift.hpp
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
/* boost random/tausworthe.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: linear_feedback_shift.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
|
||||||
|
#define BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instatiation of @c linear_feedback_shift model a
|
||||||
|
* \pseudo_random_number_generator. It was originally
|
||||||
|
* proposed in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Random numbers generated by linear recurrence modulo two.",
|
||||||
|
* Tausworthe, R. C.(1965), Mathematics of Computation 19, 201-209.
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
template<class UIntType, int w, int k, int q, int s, UIntType val>
|
||||||
|
class linear_feedback_shift
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef UIntType result_type;
|
||||||
|
// avoid the warning trouble when using (1<<w) on 32 bit machines
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
BOOST_STATIC_CONSTANT(int, word_size = w);
|
||||||
|
BOOST_STATIC_CONSTANT(int, exponent1 = k);
|
||||||
|
BOOST_STATIC_CONSTANT(int, exponent2 = q);
|
||||||
|
BOOST_STATIC_CONSTANT(int, step_size = s);
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return wordmask; }
|
||||||
|
|
||||||
|
// MSVC 6 and possibly others crash when encountering complicated integral
|
||||||
|
// constant expressions. Avoid the checks for now.
|
||||||
|
// BOOST_STATIC_ASSERT(w > 0);
|
||||||
|
// BOOST_STATIC_ASSERT(q > 0);
|
||||||
|
// BOOST_STATIC_ASSERT(k < w);
|
||||||
|
// BOOST_STATIC_ASSERT(0 < 2*q && 2*q < k);
|
||||||
|
// BOOST_STATIC_ASSERT(0 < s && s <= k-q);
|
||||||
|
|
||||||
|
explicit linear_feedback_shift(UIntType s0 = 341) : wordmask(0)
|
||||||
|
{
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_integer);
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<UIntType>::is_signed);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// avoid "left shift count >= with of type" warning
|
||||||
|
for(int i = 0; i < w; ++i)
|
||||||
|
wordmask |= (1u << i);
|
||||||
|
seed(s0);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class It> linear_feedback_shift(It& first, It last) : wordmask(0)
|
||||||
|
{
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_integer);
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<UIntType>::is_signed);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// avoid "left shift count >= with of type" warning
|
||||||
|
for(int i = 0; i < w; ++i)
|
||||||
|
wordmask |= (1u << i);
|
||||||
|
seed(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
|
void seed(UIntType s0 = 341) {
|
||||||
|
if(s0 < (1 << (w-k))) {
|
||||||
|
s0 += 1 << (w-k);
|
||||||
|
}
|
||||||
|
value = s0;
|
||||||
|
}
|
||||||
|
template<class It> void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
if(first == last)
|
||||||
|
throw std::invalid_argument("linear_feedback_shift::seed");
|
||||||
|
value = *first++;
|
||||||
|
assert(value >= (1 << (w-k)));
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
const UIntType b = (((value << q) ^ value) & wordmask) >> (k-s);
|
||||||
|
const UIntType mask = ( (~static_cast<UIntType>(0)) << (w-k) ) & wordmask;
|
||||||
|
value = ((value & mask) << s) ^ b;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
static bool validation(result_type x) { return val == x; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, linear_feedback_shift x)
|
||||||
|
{ os << x.value; return os; }
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, linear_feedback_shift& x)
|
||||||
|
{ is >> x.value; return is; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(linear_feedback_shift x, linear_feedback_shift y)
|
||||||
|
{ return x.value == y.value; }
|
||||||
|
friend bool operator!=(linear_feedback_shift x, linear_feedback_shift y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(linear_feedback_shift rhs) const
|
||||||
|
{ return value == rhs.value; }
|
||||||
|
bool operator!=(linear_feedback_shift rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
UIntType wordmask; // avoid "left shift count >= width of type" warnings
|
||||||
|
UIntType value;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class UIntType, int w, int k, int q, int s, UIntType val>
|
||||||
|
const bool linear_feedback_shift<UIntType, w, k, q, s, val>::has_fixed_range;
|
||||||
|
template<class UIntType, int w, int k, int q, int s, UIntType val>
|
||||||
|
const int linear_feedback_shift<UIntType, w, k, q, s, val>::word_size;
|
||||||
|
template<class UIntType, int w, int k, int q, int s, UIntType val>
|
||||||
|
const int linear_feedback_shift<UIntType, w, k, q, s, val>::exponent1;
|
||||||
|
template<class UIntType, int w, int k, int q, int s, UIntType val>
|
||||||
|
const int linear_feedback_shift<UIntType, w, k, q, s, val>::exponent2;
|
||||||
|
template<class UIntType, int w, int k, int q, int s, UIntType val>
|
||||||
|
const int linear_feedback_shift<UIntType, w, k, q, s, val>::step_size;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
|
||||||
129
Boost/boost/random/lognormal_distribution.hpp
Normal file
129
Boost/boost/random/lognormal_distribution.hpp
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
/* boost random/lognormal_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: lognormal_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp> // std::exp, std::sqrt
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/normal_distribution.hpp>
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||||
|
namespace std {
|
||||||
|
using ::log;
|
||||||
|
using ::sqrt;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && (__GNUC__ < 3)
|
||||||
|
// Special gcc workaround: gcc 2.95.x ignores using-declarations
|
||||||
|
// in template classes (confirmed by gcc author Martin v. Loewis)
|
||||||
|
using std::sqrt;
|
||||||
|
using std::exp;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template lognormal_distribution model a
|
||||||
|
* \random_distribution. Such a distribution produces random numbers
|
||||||
|
* with \f$p(x) = \frac{1}{x \sigma_N \sqrt{2\pi}} e^{\frac{-\left(\log(x)-\mu_N\right)^2}{2\sigma_N^2}}\f$
|
||||||
|
* for x > 0, where \f$\mu_N = \log\left(\frac{\mu^2}{\sqrt{\sigma^2 + \mu^2}}\right)\f$ and
|
||||||
|
* \f$\sigma_N = \sqrt{\log\left(1 + \frac{\sigma^2}{\mu^2}\right)}\f$.
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class lognormal_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename normal_distribution<RealType>::input_type input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a lognormal_distribution. @c mean and @c sigma are the
|
||||||
|
* mean and standard deviation of the lognormal distribution.
|
||||||
|
*/
|
||||||
|
explicit lognormal_distribution(result_type mean_arg = result_type(1),
|
||||||
|
result_type sigma_arg = result_type(1))
|
||||||
|
: _mean(mean_arg), _sigma(sigma_arg)
|
||||||
|
{
|
||||||
|
assert(_mean > result_type(0));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
RealType mean() const { return _mean; }
|
||||||
|
RealType sigma() const { return _sigma; }
|
||||||
|
void reset() { _normal.reset(); }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::exp;
|
||||||
|
#endif
|
||||||
|
return exp(_normal(eng) * _nsigma + _nmean);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const lognormal_distribution& ld)
|
||||||
|
{
|
||||||
|
os << ld._normal << " " << ld._mean << " " << ld._sigma;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, lognormal_distribution& ld)
|
||||||
|
{
|
||||||
|
is >> std::ws >> ld._normal >> std::ws >> ld._mean >> std::ws >> ld._sigma;
|
||||||
|
ld.init();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::exp; using std::log; using std::sqrt;
|
||||||
|
#endif
|
||||||
|
_nmean = log(_mean*_mean/sqrt(_sigma*_sigma + _mean*_mean));
|
||||||
|
_nsigma = sqrt(log(_sigma*_sigma/_mean/_mean+result_type(1)));
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
RealType _mean, _sigma;
|
||||||
|
RealType _nmean, _nsigma;
|
||||||
|
normal_distribution<result_type> _normal;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
|
||||||
367
Boost/boost/random/mersenne_twister.hpp
Normal file
367
Boost/boost/random/mersenne_twister.hpp
Normal file
@@ -0,0 +1,367 @@
|
|||||||
|
/* boost random/mersenne_twister.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: mersenne_twister.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_MERSENNE_TWISTER_HPP
|
||||||
|
#define BOOST_RANDOM_MERSENNE_TWISTER_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm> // std::copy
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/integer_traits.hpp>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/detail/ptr_helper.hpp>
|
||||||
|
#include <boost/random/detail/seed.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template mersenne_twister model a
|
||||||
|
* \pseudo_random_number_generator. It uses the algorithm described in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Mersenne Twister: A 623-dimensionally equidistributed uniform
|
||||||
|
* pseudo-random number generator", Makoto Matsumoto and Takuji Nishimura,
|
||||||
|
* ACM Transactions on Modeling and Computer Simulation: Special Issue on
|
||||||
|
* Uniform Random Number Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* @xmlnote
|
||||||
|
* The boost variant has been implemented from scratch and does not
|
||||||
|
* derive from or use mt19937.c provided on the above WWW site. However, it
|
||||||
|
* was verified that both produce identical output.
|
||||||
|
* @endxmlnote
|
||||||
|
*
|
||||||
|
* The seeding from an integer was changed in April 2005 to address a
|
||||||
|
* <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html">weakness</a>.
|
||||||
|
*
|
||||||
|
* The quality of the generator crucially depends on the choice of the
|
||||||
|
* parameters. User code should employ one of the sensibly parameterized
|
||||||
|
* generators such as \mt19937 instead.
|
||||||
|
*
|
||||||
|
* The generator requires considerable amounts of memory for the storage of
|
||||||
|
* its state array. For example, \mt11213b requires about 1408 bytes and
|
||||||
|
* \mt19937 requires about 2496 bytes.
|
||||||
|
*/
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
class mersenne_twister
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef UIntType result_type;
|
||||||
|
BOOST_STATIC_CONSTANT(int, word_size = w);
|
||||||
|
BOOST_STATIC_CONSTANT(int, state_size = n);
|
||||||
|
BOOST_STATIC_CONSTANT(int, shift_size = m);
|
||||||
|
BOOST_STATIC_CONSTANT(int, mask_bits = r);
|
||||||
|
BOOST_STATIC_CONSTANT(UIntType, parameter_a = a);
|
||||||
|
BOOST_STATIC_CONSTANT(int, output_u = u);
|
||||||
|
BOOST_STATIC_CONSTANT(int, output_s = s);
|
||||||
|
BOOST_STATIC_CONSTANT(UIntType, output_b = b);
|
||||||
|
BOOST_STATIC_CONSTANT(int, output_t = t);
|
||||||
|
BOOST_STATIC_CONSTANT(UIntType, output_c = c);
|
||||||
|
BOOST_STATIC_CONSTANT(int, output_l = l);
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c mersenne_twister and calls @c seed().
|
||||||
|
*/
|
||||||
|
mersenne_twister() { seed(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c mersenne_twister and calls @c seed(value).
|
||||||
|
*/
|
||||||
|
BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister, UIntType, value)
|
||||||
|
{ seed(value); }
|
||||||
|
template<class It> mersenne_twister(It& first, It last) { seed(first,last); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a mersenne_twister and calls @c seed(gen).
|
||||||
|
*
|
||||||
|
* @xmlnote
|
||||||
|
* The copy constructor will always be preferred over
|
||||||
|
* the templated constructor.
|
||||||
|
* @endxmlnote
|
||||||
|
*/
|
||||||
|
BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(mersenne_twister, Generator, gen)
|
||||||
|
{ seed(gen); }
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/** Calls @c seed(result_type(5489)). */
|
||||||
|
void seed() { seed(UIntType(5489)); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the state x(0) to v mod 2w. Then, iteratively,
|
||||||
|
* sets x(i) to (i + 1812433253 * (x(i-1) xor (x(i-1) rshift w-2))) mod 2<sup>w</sup>
|
||||||
|
* for i = 1 .. n-1. x(n) is the first value to be returned by operator().
|
||||||
|
*/
|
||||||
|
BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister, UIntType, value)
|
||||||
|
{
|
||||||
|
// New seeding algorithm from
|
||||||
|
// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
|
||||||
|
// In the previous versions, MSBs of the seed affected only MSBs of the
|
||||||
|
// state x[].
|
||||||
|
const UIntType mask = ~0u;
|
||||||
|
x[0] = value & mask;
|
||||||
|
for (i = 1; i < n; i++) {
|
||||||
|
// See Knuth "The Art of Computer Programming" Vol. 2, 3rd ed., page 106
|
||||||
|
x[i] = (1812433253UL * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the state of this mersenne_twister to the values
|
||||||
|
* returned by n invocations of gen.
|
||||||
|
*
|
||||||
|
* Complexity: Exactly n invocations of gen.
|
||||||
|
*/
|
||||||
|
BOOST_RANDOM_DETAIL_GENERATOR_SEED(mersenne_twister, Generator, gen)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<result_type>::is_signed);
|
||||||
|
#endif
|
||||||
|
// I could have used std::generate_n, but it takes "gen" by value
|
||||||
|
for(int j = 0; j < n; j++)
|
||||||
|
x[j] = gen();
|
||||||
|
i = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class It>
|
||||||
|
void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
for(j = 0; j < n && first != last; ++j, ++first)
|
||||||
|
x[j] = *first;
|
||||||
|
i = n;
|
||||||
|
if(first == last && j < n)
|
||||||
|
throw std::invalid_argument("mersenne_twister::seed");
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const
|
||||||
|
{
|
||||||
|
// avoid "left shift count >= with of type" warning
|
||||||
|
result_type res = 0;
|
||||||
|
for(int j = 0; j < w; ++j)
|
||||||
|
res |= (1u << j);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type operator()();
|
||||||
|
static bool validation(result_type v) { return val == v; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const mersenne_twister& mt)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < mt.state_size; ++j)
|
||||||
|
os << mt.compute(j) << " ";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, mersenne_twister& mt)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < mt.state_size; ++j)
|
||||||
|
is >> mt.x[j] >> std::ws;
|
||||||
|
// MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template
|
||||||
|
// value parameter "n" available from the class template scope, so use
|
||||||
|
// the static constant with the same value
|
||||||
|
mt.i = mt.state_size;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const mersenne_twister& x, const mersenne_twister& y)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < state_size; ++j)
|
||||||
|
if(x.compute(j) != y.compute(j))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator!=(const mersenne_twister& x, const mersenne_twister& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const mersenne_twister& rhs) const
|
||||||
|
{
|
||||||
|
for(int j = 0; j < state_size; ++j)
|
||||||
|
if(compute(j) != rhs.compute(j))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const mersenne_twister& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
// returns x(i-n+index), where index is in 0..n-1
|
||||||
|
UIntType compute(unsigned int index) const
|
||||||
|
{
|
||||||
|
// equivalent to (i-n+index) % 2n, but doesn't produce negative numbers
|
||||||
|
return x[ (i + n + index) % (2*n) ];
|
||||||
|
}
|
||||||
|
void twist(int block);
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
// state representation: next output is o(x(i))
|
||||||
|
// x[0] ... x[k] x[k+1] ... x[n-1] x[n] ... x[2*n-1] represents
|
||||||
|
// x(i-k) ... x(i) x(i+1) ... x(i-k+n-1) x(i-k-n) ... x[i(i-k-1)]
|
||||||
|
// The goal is to always have x(i-n) ... x(i-1) available for
|
||||||
|
// operator== and save/restore.
|
||||||
|
|
||||||
|
UIntType x[2*n];
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const bool mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::has_fixed_range;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::state_size;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::shift_size;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::mask_bits;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::parameter_a;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_u;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_s;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_b;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_t;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_c;
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_l;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
void mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::twist(int block)
|
||||||
|
{
|
||||||
|
const UIntType upper_mask = (~0u) << r;
|
||||||
|
const UIntType lower_mask = ~upper_mask;
|
||||||
|
|
||||||
|
if(block == 0) {
|
||||||
|
for(int j = n; j < 2*n; j++) {
|
||||||
|
UIntType y = (x[j-n] & upper_mask) | (x[j-(n-1)] & lower_mask);
|
||||||
|
x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
|
||||||
|
}
|
||||||
|
} else if (block == 1) {
|
||||||
|
// split loop to avoid costly modulo operations
|
||||||
|
{ // extra scope for MSVC brokenness w.r.t. for scope
|
||||||
|
for(int j = 0; j < n-m; j++) {
|
||||||
|
UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
|
||||||
|
x[j] = x[j+n+m] ^ (y >> 1) ^ (y&1 ? a : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int j = n-m; j < n-1; j++) {
|
||||||
|
UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
|
||||||
|
x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
|
||||||
|
}
|
||||||
|
// last iteration
|
||||||
|
UIntType y = (x[2*n-1] & upper_mask) | (x[0] & lower_mask);
|
||||||
|
x[n-1] = x[m-1] ^ (y >> 1) ^ (y&1 ? a : 0);
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
|
||||||
|
int s, UIntType b, int t, UIntType c, int l, UIntType val>
|
||||||
|
inline typename mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::result_type
|
||||||
|
mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::operator()()
|
||||||
|
{
|
||||||
|
if(i == n)
|
||||||
|
twist(0);
|
||||||
|
else if(i >= 2*n)
|
||||||
|
twist(1);
|
||||||
|
// Step 4
|
||||||
|
UIntType z = x[i];
|
||||||
|
++i;
|
||||||
|
z ^= (z >> u);
|
||||||
|
z ^= ((z << s) & b);
|
||||||
|
z ^= ((z << t) & c);
|
||||||
|
z ^= (z >> l);
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The specializations \mt11213b and \mt19937 are from
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Mersenne Twister: A 623-dimensionally equidistributed
|
||||||
|
* uniform pseudo-random number generator", Makoto Matsumoto
|
||||||
|
* and Takuji Nishimura, ACM Transactions on Modeling and
|
||||||
|
* Computer Simulation: Special Issue on Uniform Random Number
|
||||||
|
* Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::mersenne_twister<uint32_t,32,351,175,19,0xccab8ee7,11,
|
||||||
|
7,0x31b6ab00,15,0xffe50000,17, 0xa37d3c92> mt11213b;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The specializations \mt11213b and \mt19937 are from
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Mersenne Twister: A 623-dimensionally equidistributed
|
||||||
|
* uniform pseudo-random number generator", Makoto Matsumoto
|
||||||
|
* and Takuji Nishimura, ACM Transactions on Modeling and
|
||||||
|
* Computer Simulation: Special Issue on Uniform Random Number
|
||||||
|
* Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::mersenne_twister<uint32_t,32,624,397,31,0x9908b0df,11,
|
||||||
|
7,0x9d2c5680,15,0xefc60000,18, 3346425566U> mt19937;
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937)
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_MERSENNE_TWISTER_HPP
|
||||||
131
Boost/boost/random/normal_distribution.hpp
Normal file
131
Boost/boost/random/normal_distribution.hpp
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
/* boost random/normal_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: normal_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template normal_distribution model a
|
||||||
|
* \random_distribution. Such a distribution produces random numbers
|
||||||
|
* @c x distributed with probability density function
|
||||||
|
* \f$p(x) = \frac{1}{\sqrt{2\pi\sigma}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}\f$,
|
||||||
|
* where mean and sigma are the parameters of the distribution.
|
||||||
|
*/
|
||||||
|
// deterministic Box-Muller method, uses trigonometric functions
|
||||||
|
template<class RealType = double>
|
||||||
|
class normal_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a normal_distribution object. @c mean and @c sigma are
|
||||||
|
* the parameters for the distribution.
|
||||||
|
*
|
||||||
|
* Requires: sigma > 0
|
||||||
|
*/
|
||||||
|
explicit normal_distribution(const result_type& mean_arg = result_type(0),
|
||||||
|
const result_type& sigma_arg = result_type(1))
|
||||||
|
: _mean(mean_arg), _sigma(sigma_arg), _valid(false)
|
||||||
|
{
|
||||||
|
assert(_sigma >= result_type(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy constructor is NOT fine, need to purge cache
|
||||||
|
normal_distribution(const normal_distribution& other)
|
||||||
|
: _mean(other._mean), _sigma(other._sigma), _valid(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: The "mean" parameter of the distribution.
|
||||||
|
*/
|
||||||
|
RealType mean() const { return _mean; }
|
||||||
|
/**
|
||||||
|
* Returns: The "sigma" parameter of the distribution.
|
||||||
|
*/
|
||||||
|
RealType sigma() const { return _sigma; }
|
||||||
|
|
||||||
|
void reset() { _valid = false; }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::sqrt; using std::log; using std::sin; using std::cos;
|
||||||
|
#endif
|
||||||
|
if(!_valid) {
|
||||||
|
_r1 = eng();
|
||||||
|
_r2 = eng();
|
||||||
|
_cached_rho = sqrt(-result_type(2) * log(result_type(1)-_r2));
|
||||||
|
_valid = true;
|
||||||
|
} else {
|
||||||
|
_valid = false;
|
||||||
|
}
|
||||||
|
// Can we have a boost::mathconst please?
|
||||||
|
const result_type pi = result_type(3.14159265358979323846);
|
||||||
|
|
||||||
|
return _cached_rho * (_valid ?
|
||||||
|
cos(result_type(2)*pi*_r1) :
|
||||||
|
sin(result_type(2)*pi*_r1))
|
||||||
|
* _sigma + _mean;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const normal_distribution& nd)
|
||||||
|
{
|
||||||
|
os << nd._mean << " " << nd._sigma << " "
|
||||||
|
<< nd._valid << " " << nd._cached_rho << " " << nd._r1;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, normal_distribution& nd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> nd._mean >> std::ws >> nd._sigma
|
||||||
|
>> std::ws >> nd._valid >> std::ws >> nd._cached_rho
|
||||||
|
>> std::ws >> nd._r1;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
private:
|
||||||
|
result_type _mean, _sigma;
|
||||||
|
result_type _r1, _r2, _cached_rho;
|
||||||
|
bool _valid;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP
|
||||||
116
Boost/boost/random/poisson_distribution.hpp
Normal file
116
Boost/boost/random/poisson_distribution.hpp
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/* boost random/poisson_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: poisson_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
// Knuth
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An instantiation of the class template @c poisson_distribution is a
|
||||||
|
* model of \random_distribution. The poisson distribution has
|
||||||
|
* \f$p(i) = \frac{e^{-\lambda}\lambda^i}{i!}\f$
|
||||||
|
*/
|
||||||
|
template<class IntType = int, class RealType = double>
|
||||||
|
class poisson_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef IntType result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c poisson_distribution with the parameter @c mean.
|
||||||
|
*
|
||||||
|
* Requires: mean > 0
|
||||||
|
*/
|
||||||
|
explicit poisson_distribution(const RealType& mean_arg = RealType(1))
|
||||||
|
: _mean(mean_arg)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
assert(_mean > RealType(0));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: the "mean" parameter of the distribution.
|
||||||
|
*/
|
||||||
|
RealType mean() const { return _mean; }
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
// TODO: This is O(_mean), but it should be O(log(_mean)) for large _mean
|
||||||
|
RealType product = RealType(1);
|
||||||
|
for(result_type m = 0; ; ++m) {
|
||||||
|
product *= eng();
|
||||||
|
if(product <= _exp_mean)
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const poisson_distribution& pd)
|
||||||
|
{
|
||||||
|
os << pd._mean;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, poisson_distribution& pd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> pd._mean;
|
||||||
|
pd.init();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::exp;
|
||||||
|
#endif
|
||||||
|
_exp_mean = exp(-_mean);
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
RealType _mean;
|
||||||
|
// some precomputed data from the parameters
|
||||||
|
RealType _exp_mean;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
|
||||||
71
Boost/boost/random/random_number_generator.hpp
Normal file
71
Boost/boost/random/random_number_generator.hpp
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/* boost random/random_number_generator.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: random_number_generator.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
|
||||||
|
#define BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/uniform_int.hpp>
|
||||||
|
#include <boost/random/variate_generator.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template random_number_generator model a
|
||||||
|
* RandomNumberGenerator (std:25.2.11 [lib.alg.random.shuffle]). On
|
||||||
|
* each invocation, it returns a uniformly distributed integer in
|
||||||
|
* the range [0..n).
|
||||||
|
*
|
||||||
|
* The template parameter IntType shall denote some integer-like value type.
|
||||||
|
*/
|
||||||
|
template<class UniformRandomNumberGenerator, class IntType = long>
|
||||||
|
class random_number_generator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef UniformRandomNumberGenerator base_type;
|
||||||
|
typedef IntType argument_type;
|
||||||
|
typedef IntType result_type;
|
||||||
|
/**
|
||||||
|
* Constructs a random_number_generator functor with the given
|
||||||
|
* \uniform_random_number_generator as the underlying source of
|
||||||
|
* random numbers.
|
||||||
|
*/
|
||||||
|
random_number_generator(base_type& rng) : _rng(rng)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
// compiler-generated copy ctor is fine
|
||||||
|
// assignment is disallowed because there is a reference member
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value in the range [0, n)
|
||||||
|
*/
|
||||||
|
result_type operator()(argument_type n)
|
||||||
|
{
|
||||||
|
typedef uniform_int<IntType> dist_type;
|
||||||
|
return variate_generator<base_type&, dist_type>(_rng, dist_type(0, n-1))();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
base_type& _rng;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
|
||||||
81
Boost/boost/random/ranlux.hpp
Normal file
81
Boost/boost/random/ranlux.hpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/* boost random/ranlux.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: ranlux.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 created
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_RANLUX_HPP
|
||||||
|
#define BOOST_RANDOM_RANLUX_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/random/subtract_with_carry.hpp>
|
||||||
|
#include <boost/random/discard_block.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
namespace random {
|
||||||
|
typedef subtract_with_carry<int, (1<<24), 10, 24, 0> ranlux_base;
|
||||||
|
typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01;
|
||||||
|
typedef subtract_with_carry_01<double, 48, 10, 24> ranlux64_base_01;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace random {
|
||||||
|
namespace detail {
|
||||||
|
/**
|
||||||
|
* The ranlux family of generators are described in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "A portable high-quality random number generator for lattice field theory
|
||||||
|
* calculations", M. Luescher, Computer Physics Communications, 79 (1994)
|
||||||
|
* pp 100-110.
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* The levels are given in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "RANLUX: A Fortran implementation ofthe high-quality
|
||||||
|
* pseudorandom number generator of Luescher", F. James,
|
||||||
|
* Computer Physics Communications 79 (1994) 111-114
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
class ranlux_documentation {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux_base, 223, 24> ranlux3;
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux_base, 389, 24> ranlux4;
|
||||||
|
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux_base_01, 223, 24> ranlux3_01;
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux_base_01, 389, 24> ranlux4_01;
|
||||||
|
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux64_base_01, 223, 24> ranlux64_3_01;
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux64_base_01, 389, 24> ranlux64_4_01;
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
|
||||||
|
namespace random {
|
||||||
|
typedef random::subtract_with_carry<int64_t, (int64_t(1)<<48), 10, 24, 0> ranlux64_base;
|
||||||
|
}
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux64_base, 223, 24> ranlux64_3;
|
||||||
|
/** @copydoc boost::random::detail::ranlux_documentation */
|
||||||
|
typedef random::discard_block<random::ranlux64_base, 389, 24> ranlux64_4;
|
||||||
|
#endif /* !BOOST_NO_INT64_T && !BOOST_NO_INTEGRAL_INT64_T */
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
|
||||||
234
Boost/boost/random/shuffle_output.hpp
Normal file
234
Boost/boost/random/shuffle_output.hpp
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
/* boost random/shuffle_output.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: shuffle_output.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_SHUFFLE_OUTPUT_HPP
|
||||||
|
#define BOOST_RANDOM_SHUFFLE_OUTPUT_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm> // std::copy
|
||||||
|
#include <cassert>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instatiations of class template shuffle_output model a
|
||||||
|
* \pseudo_random_number_generator. It mixes the output
|
||||||
|
* of some (usually \linear_congruential) \uniform_random_number_generator
|
||||||
|
* to get better statistical properties.
|
||||||
|
* The algorithm is described in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "Improving a poor random number generator", Carter Bays
|
||||||
|
* and S.D. Durham, ACM Transactions on Mathematical Software,
|
||||||
|
* Vol 2, No. 1, March 1976, pp. 59-64.
|
||||||
|
* http://doi.acm.org/10.1145/355666.355670
|
||||||
|
* @endblockquote
|
||||||
|
*
|
||||||
|
* The output of the base generator is buffered in an array of
|
||||||
|
* length k. Every output X(n) has a second role: It gives an
|
||||||
|
* index into the array where X(n+1) will be retrieved. Used
|
||||||
|
* array elements are replaced with fresh output from the base
|
||||||
|
* generator.
|
||||||
|
*
|
||||||
|
* Template parameters are the base generator and the array
|
||||||
|
* length k, which should be around 100. The template parameter
|
||||||
|
* val is the validation value checked by validation.
|
||||||
|
*/
|
||||||
|
template<class UniformRandomNumberGenerator, int k,
|
||||||
|
#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
|
||||||
|
typename UniformRandomNumberGenerator::result_type
|
||||||
|
#else
|
||||||
|
uint32_t
|
||||||
|
#endif
|
||||||
|
val = 0>
|
||||||
|
class shuffle_output
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef UniformRandomNumberGenerator base_type;
|
||||||
|
typedef typename base_type::result_type result_type;
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
BOOST_STATIC_CONSTANT(int, buffer_size = k);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c shuffle_output generator by invoking the
|
||||||
|
* default constructor of the base generator.
|
||||||
|
*
|
||||||
|
* Complexity: Exactly k+1 invocations of the base generator.
|
||||||
|
*/
|
||||||
|
shuffle_output() : _rng() { init(); }
|
||||||
|
#if defined(BOOST_MSVC) && _MSC_VER < 1300
|
||||||
|
// MSVC does not implicitly generate the copy constructor here
|
||||||
|
shuffle_output(const shuffle_output & x)
|
||||||
|
: _rng(x._rng), y(x.y) { std::copy(x.v, x.v+k, v); }
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Constructs a shuffle_output generator by invoking the one-argument
|
||||||
|
* constructor of the base generator with the parameter seed.
|
||||||
|
*
|
||||||
|
* Complexity: Exactly k+1 invocations of the base generator.
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
explicit shuffle_output(T s) : _rng(s) { init(); }
|
||||||
|
/**
|
||||||
|
* Constructs a shuffle_output generator by using a copy
|
||||||
|
* of the provided generator.
|
||||||
|
*
|
||||||
|
* Precondition: The template argument UniformRandomNumberGenerator
|
||||||
|
* shall denote a CopyConstructible type.
|
||||||
|
*
|
||||||
|
* Complexity: Exactly k+1 invocations of the base generator.
|
||||||
|
*/
|
||||||
|
explicit shuffle_output(const base_type & rng) : _rng(rng) { init(); }
|
||||||
|
template<class It> shuffle_output(It& first, It last)
|
||||||
|
: _rng(first, last) { init(); }
|
||||||
|
void seed() { _rng.seed(); init(); }
|
||||||
|
/**
|
||||||
|
* Invokes the one-argument seed method of the base generator
|
||||||
|
* with the parameter seed and re-initializes the internal buffer array.
|
||||||
|
*
|
||||||
|
* Complexity: Exactly k+1 invocations of the base generator.
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
void seed(T s) { _rng.seed(s); init(); }
|
||||||
|
template<class It> void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
_rng.seed(first, last);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
const base_type& base() const { return _rng; }
|
||||||
|
|
||||||
|
result_type operator()() {
|
||||||
|
// calculating the range every time may seem wasteful. However, this
|
||||||
|
// makes the information locally available for the optimizer.
|
||||||
|
result_type range = (max)()-(min)()+1;
|
||||||
|
int j = k*(y-(min)())/range;
|
||||||
|
// assert(0 <= j && j < k);
|
||||||
|
y = v[j];
|
||||||
|
v[j] = _rng();
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); }
|
||||||
|
static bool validation(result_type x) { return val == x; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const shuffle_output& s)
|
||||||
|
{
|
||||||
|
os << s._rng << " " << s.y << " ";
|
||||||
|
for(int i = 0; i < s.buffer_size; ++i)
|
||||||
|
os << s.v[i] << " ";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, shuffle_output& s)
|
||||||
|
{
|
||||||
|
is >> s._rng >> std::ws >> s.y >> std::ws;
|
||||||
|
for(int i = 0; i < s.buffer_size; ++i)
|
||||||
|
is >> s.v[i] >> std::ws;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const shuffle_output& x, const shuffle_output& y)
|
||||||
|
{ return x._rng == y._rng && x.y == y.y && std::equal(x.v, x.v+k, y.v); }
|
||||||
|
friend bool operator!=(const shuffle_output& x, const shuffle_output& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const shuffle_output& rhs) const
|
||||||
|
{ return _rng == rhs._rng && y == rhs.y && std::equal(v, v+k, rhs.v); }
|
||||||
|
bool operator!=(const shuffle_output& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
private:
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
|
||||||
|
#endif
|
||||||
|
result_type range = (max)()-(min)();
|
||||||
|
assert(range > 0); // otherwise there would be little choice
|
||||||
|
if(static_cast<unsigned long>(k * range) <
|
||||||
|
static_cast<unsigned long>(range)) // not a sufficient condition
|
||||||
|
// likely overflow with bucket number computation
|
||||||
|
assert(!"overflow will occur");
|
||||||
|
|
||||||
|
// we cannot use std::generate, because it uses pass-by-value for _rng
|
||||||
|
for(result_type * p = v; p != v+k; ++p)
|
||||||
|
*p = _rng();
|
||||||
|
y = _rng();
|
||||||
|
}
|
||||||
|
|
||||||
|
base_type _rng;
|
||||||
|
result_type v[k];
|
||||||
|
result_type y;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class UniformRandomNumberGenerator, int k,
|
||||||
|
#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
|
||||||
|
typename UniformRandomNumberGenerator::result_type
|
||||||
|
#else
|
||||||
|
uint32_t
|
||||||
|
#endif
|
||||||
|
val>
|
||||||
|
const bool shuffle_output<UniformRandomNumberGenerator, k, val>::has_fixed_range;
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator, int k,
|
||||||
|
#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
|
||||||
|
typename UniformRandomNumberGenerator::result_type
|
||||||
|
#else
|
||||||
|
uint32_t
|
||||||
|
#endif
|
||||||
|
val>
|
||||||
|
const int shuffle_output<UniformRandomNumberGenerator, k, val>::buffer_size;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
// validation by experiment from Harry Erwin's generator.h (private e-mail)
|
||||||
|
/**
|
||||||
|
* According to Harry Erwin (private e-mail), the specialization
|
||||||
|
* @c kreutzer1986 was suggested in:
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "System Simulation: Programming Styles and Languages (International
|
||||||
|
* Computer Science Series)", Wolfgang Kreutzer, Addison-Wesley, December 1986.
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
typedef random::shuffle_output<
|
||||||
|
random::linear_congruential<uint32_t, 1366, 150889, 714025, 0>,
|
||||||
|
97, 139726> kreutzer1986;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_SHUFFLE_OUTPUT_HPP
|
||||||
465
Boost/boost/random/subtract_with_carry.hpp
Normal file
465
Boost/boost/random/subtract_with_carry.hpp
Normal file
@@ -0,0 +1,465 @@
|
|||||||
|
/* boost random/subtract_with_carry.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: subtract_with_carry.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2002-03-02 created
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP
|
||||||
|
#define BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm> // std::equal
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp> // std::pow
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/detail/seed.hpp>
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300
|
||||||
|
# define BOOST_RANDOM_EXTRACT_SWC_01
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE_CC__) && defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ <= 3)
|
||||||
|
# define BOOST_RANDOM_EXTRACT_SWC_01
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# ifdef BOOST_RANDOM_EXTRACT_SWC_01
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template <class IStream, class SubtractWithCarry, class RealType>
|
||||||
|
void extract_subtract_with_carry_01(
|
||||||
|
IStream& is
|
||||||
|
, SubtractWithCarry& f
|
||||||
|
, RealType& carry
|
||||||
|
, RealType* x
|
||||||
|
, RealType modulus)
|
||||||
|
{
|
||||||
|
RealType value;
|
||||||
|
for(unsigned int j = 0; j < f.long_lag; ++j) {
|
||||||
|
is >> value >> std::ws;
|
||||||
|
x[j] = value / modulus;
|
||||||
|
}
|
||||||
|
is >> value >> std::ws;
|
||||||
|
carry = value / modulus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of @c subtract_with_carry model a
|
||||||
|
* \pseudo_random_number_generator. The algorithm is
|
||||||
|
* described in
|
||||||
|
*
|
||||||
|
* @blockquote
|
||||||
|
* "A New Class of Random Number Generators", George
|
||||||
|
* Marsaglia and Arif Zaman, Annals of Applied Probability,
|
||||||
|
* Volume 1, Number 3 (1991), 462-480.
|
||||||
|
* @endblockquote
|
||||||
|
*/
|
||||||
|
template<class IntType, IntType m, unsigned int s, unsigned int r,
|
||||||
|
IntType val>
|
||||||
|
class subtract_with_carry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef IntType result_type;
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = true);
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, min_value = 0);
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, max_value = m-1);
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, modulus = m);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, long_lag = r);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, short_lag = s);
|
||||||
|
|
||||||
|
subtract_with_carry() {
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_signed);
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
|
||||||
|
#endif
|
||||||
|
seed();
|
||||||
|
}
|
||||||
|
BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(subtract_with_carry, uint32_t, value)
|
||||||
|
{ seed(value); }
|
||||||
|
BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(subtract_with_carry, Generator, gen)
|
||||||
|
{ seed(gen); }
|
||||||
|
template<class It> subtract_with_carry(It& first, It last) { seed(first,last); }
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
void seed() { seed(19780503u); }
|
||||||
|
BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(subtract_with_carry, uint32_t, value)
|
||||||
|
{
|
||||||
|
random::linear_congruential<int32_t, 40014, 0, 2147483563, 0> intgen(value);
|
||||||
|
seed(intgen);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For GCC, moving this function out-of-line prevents inlining, which may
|
||||||
|
// reduce overall object code size. However, MSVC does not grok
|
||||||
|
// out-of-line template member functions.
|
||||||
|
BOOST_RANDOM_DETAIL_GENERATOR_SEED(subtract_with_carry, Generator, gen)
|
||||||
|
{
|
||||||
|
// I could have used std::generate_n, but it takes "gen" by value
|
||||||
|
for(unsigned int j = 0; j < long_lag; ++j)
|
||||||
|
x[j] = gen() % modulus;
|
||||||
|
carry = (x[long_lag-1] == 0);
|
||||||
|
k = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class It>
|
||||||
|
void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
unsigned int j;
|
||||||
|
for(j = 0; j < long_lag && first != last; ++j, ++first)
|
||||||
|
x[j] = *first % modulus;
|
||||||
|
if(first == last && j < long_lag)
|
||||||
|
throw std::invalid_argument("subtract_with_carry::seed");
|
||||||
|
carry = (x[long_lag-1] == 0);
|
||||||
|
k = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return min_value; }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return max_value; }
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
int short_index = k - short_lag;
|
||||||
|
if(short_index < 0)
|
||||||
|
short_index += long_lag;
|
||||||
|
IntType delta;
|
||||||
|
if (x[short_index] >= x[k] + carry) {
|
||||||
|
// x(n) >= 0
|
||||||
|
delta = x[short_index] - (x[k] + carry);
|
||||||
|
carry = 0;
|
||||||
|
} else {
|
||||||
|
// x(n) < 0
|
||||||
|
delta = modulus - x[k] - carry + x[short_index];
|
||||||
|
carry = 1;
|
||||||
|
}
|
||||||
|
x[k] = delta;
|
||||||
|
++k;
|
||||||
|
if(k >= long_lag)
|
||||||
|
k = 0;
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static bool validation(result_type x) { return x == val; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os,
|
||||||
|
const subtract_with_carry& f)
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0; j < f.long_lag; ++j)
|
||||||
|
os << f.compute(j) << " ";
|
||||||
|
os << f.carry << " ";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, subtract_with_carry& f)
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0; j < f.long_lag; ++j)
|
||||||
|
is >> f.x[j] >> std::ws;
|
||||||
|
is >> f.carry >> std::ws;
|
||||||
|
f.k = 0;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const subtract_with_carry& x, const subtract_with_carry& y)
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0; j < r; ++j)
|
||||||
|
if(x.compute(j) != y.compute(j))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator!=(const subtract_with_carry& x, const subtract_with_carry& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const subtract_with_carry& rhs) const
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0; j < r; ++j)
|
||||||
|
if(compute(j) != rhs.compute(j))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const subtract_with_carry& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
// returns x(i-r+index), where index is in 0..r-1
|
||||||
|
IntType compute(unsigned int index) const
|
||||||
|
{
|
||||||
|
return x[(k+index) % long_lag];
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
// state representation; next output (state) is x(i)
|
||||||
|
// x[0] ... x[k] x[k+1] ... x[long_lag-1] represents
|
||||||
|
// x(i-k) ... x(i) x(i+1) ... x(i-k+long_lag-1)
|
||||||
|
// speed: base: 20-25 nsec
|
||||||
|
// ranlux_4: 230 nsec, ranlux_7: 430 nsec, ranlux_14: 810 nsec
|
||||||
|
// This state representation makes operator== and save/restore more
|
||||||
|
// difficult, because we've already computed "too much" and thus
|
||||||
|
// have to undo some steps to get at x(i-r) etc.
|
||||||
|
|
||||||
|
// state representation: next output (state) is x(i)
|
||||||
|
// x[0] ... x[k] x[k+1] ... x[long_lag-1] represents
|
||||||
|
// x(i-k) ... x(i) x(i-long_lag+1) ... x(i-k-1)
|
||||||
|
// speed: base 28 nsec
|
||||||
|
// ranlux_4: 370 nsec, ranlux_7: 688 nsec, ranlux_14: 1343 nsec
|
||||||
|
IntType x[long_lag];
|
||||||
|
unsigned int k;
|
||||||
|
int carry;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val>
|
||||||
|
const bool subtract_with_carry<IntType, m, s, r, val>::has_fixed_range;
|
||||||
|
template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val>
|
||||||
|
const IntType subtract_with_carry<IntType, m, s, r, val>::min_value;
|
||||||
|
template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val>
|
||||||
|
const IntType subtract_with_carry<IntType, m, s, r, val>::max_value;
|
||||||
|
template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val>
|
||||||
|
const IntType subtract_with_carry<IntType, m, s, r, val>::modulus;
|
||||||
|
template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val>
|
||||||
|
const unsigned int subtract_with_carry<IntType, m, s, r, val>::long_lag;
|
||||||
|
template<class IntType, IntType m, unsigned int s, unsigned int r, IntType val>
|
||||||
|
const unsigned int subtract_with_carry<IntType, m, s, r, val>::short_lag;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// use a floating-point representation to produce values in [0..1)
|
||||||
|
/** @copydoc boost::random::subtract_with_carry */
|
||||||
|
template<class RealType, int w, unsigned int s, unsigned int r, int val=0>
|
||||||
|
class subtract_with_carry_01
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType result_type;
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
BOOST_STATIC_CONSTANT(int, word_size = w);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, long_lag = r);
|
||||||
|
BOOST_STATIC_CONSTANT(unsigned int, short_lag = s);
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<result_type>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
subtract_with_carry_01() { init_modulus(); seed(); }
|
||||||
|
explicit subtract_with_carry_01(uint32_t value)
|
||||||
|
{ init_modulus(); seed(value); }
|
||||||
|
template<class It> subtract_with_carry_01(It& first, It last)
|
||||||
|
{ init_modulus(); seed(first,last); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void init_modulus()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::pow;
|
||||||
|
#endif
|
||||||
|
_modulus = pow(RealType(2), word_size);
|
||||||
|
}
|
||||||
|
/// \endcond hide_private_members
|
||||||
|
|
||||||
|
public:
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
void seed(uint32_t value = 19780503u)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::fmod;
|
||||||
|
#endif
|
||||||
|
random::linear_congruential<int32_t, 40014, 0, 2147483563, 0> gen(value);
|
||||||
|
unsigned long array[(w+31)/32 * long_lag];
|
||||||
|
for(unsigned int j = 0; j < sizeof(array)/sizeof(unsigned long); ++j)
|
||||||
|
array[j] = gen();
|
||||||
|
unsigned long * start = array;
|
||||||
|
seed(start, array + sizeof(array)/sizeof(unsigned long));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class It>
|
||||||
|
void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::fmod;
|
||||||
|
using std::pow;
|
||||||
|
#endif
|
||||||
|
unsigned long mask = ~((~0u) << (w%32)); // now lowest (w%32) bits set
|
||||||
|
RealType two32 = pow(RealType(2), 32);
|
||||||
|
unsigned int j;
|
||||||
|
for(j = 0; j < long_lag && first != last; ++j) {
|
||||||
|
x[j] = RealType(0);
|
||||||
|
for(int i = 0; i < w/32 && first != last; ++i, ++first)
|
||||||
|
x[j] += *first / pow(two32,i+1);
|
||||||
|
if(first != last && mask != 0) {
|
||||||
|
x[j] += fmod((*first & mask) / _modulus, RealType(1));
|
||||||
|
++first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(first == last && j < long_lag)
|
||||||
|
throw std::invalid_argument("subtract_with_carry_01::seed");
|
||||||
|
carry = (x[long_lag-1] ? 0 : 1 / _modulus);
|
||||||
|
k = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
int short_index = k - short_lag;
|
||||||
|
if(short_index < 0)
|
||||||
|
short_index += long_lag;
|
||||||
|
RealType delta = x[short_index] - x[k] - carry;
|
||||||
|
if(delta < 0) {
|
||||||
|
delta += RealType(1);
|
||||||
|
carry = RealType(1)/_modulus;
|
||||||
|
} else {
|
||||||
|
carry = 0;
|
||||||
|
}
|
||||||
|
x[k] = delta;
|
||||||
|
++k;
|
||||||
|
if(k >= long_lag)
|
||||||
|
k = 0;
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validation(result_type x)
|
||||||
|
{ return x == val/pow(RealType(2), word_size); }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os,
|
||||||
|
const subtract_with_carry_01& f)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
// allow for Koenig lookup
|
||||||
|
using std::pow;
|
||||||
|
#endif
|
||||||
|
std::ios_base::fmtflags oldflags = os.flags(os.dec | os.fixed | os.left);
|
||||||
|
for(unsigned int j = 0; j < f.long_lag; ++j)
|
||||||
|
os << (f.compute(j) * f._modulus) << " ";
|
||||||
|
os << (f.carry * f._modulus);
|
||||||
|
os.flags(oldflags);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, subtract_with_carry_01& f)
|
||||||
|
{
|
||||||
|
# ifdef BOOST_RANDOM_EXTRACT_SWC_01
|
||||||
|
detail::extract_subtract_with_carry_01(is, f, f.carry, f.x, f._modulus);
|
||||||
|
# else
|
||||||
|
// MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template type
|
||||||
|
// parameter "RealType" available from the class template scope, so use
|
||||||
|
// the member typedef
|
||||||
|
typename subtract_with_carry_01::result_type value;
|
||||||
|
for(unsigned int j = 0; j < long_lag; ++j) {
|
||||||
|
is >> value >> std::ws;
|
||||||
|
f.x[j] = value / f._modulus;
|
||||||
|
}
|
||||||
|
is >> value >> std::ws;
|
||||||
|
f.carry = value / f._modulus;
|
||||||
|
# endif
|
||||||
|
f.k = 0;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const subtract_with_carry_01& x,
|
||||||
|
const subtract_with_carry_01& y)
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0; j < r; ++j)
|
||||||
|
if(x.compute(j) != y.compute(j))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator!=(const subtract_with_carry_01& x,
|
||||||
|
const subtract_with_carry_01& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const subtract_with_carry_01& rhs) const
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0; j < r; ++j)
|
||||||
|
if(compute(j) != rhs.compute(j))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const subtract_with_carry_01& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
RealType compute(unsigned int index) const;
|
||||||
|
/// \endcond
|
||||||
|
unsigned int k;
|
||||||
|
RealType carry;
|
||||||
|
RealType x[long_lag];
|
||||||
|
RealType _modulus;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class RealType, int w, unsigned int s, unsigned int r, int val>
|
||||||
|
const bool subtract_with_carry_01<RealType, w, s, r, val>::has_fixed_range;
|
||||||
|
template<class RealType, int w, unsigned int s, unsigned int r, int val>
|
||||||
|
const int subtract_with_carry_01<RealType, w, s, r, val>::word_size;
|
||||||
|
template<class RealType, int w, unsigned int s, unsigned int r, int val>
|
||||||
|
const unsigned int subtract_with_carry_01<RealType, w, s, r, val>::long_lag;
|
||||||
|
template<class RealType, int w, unsigned int s, unsigned int r, int val>
|
||||||
|
const unsigned int subtract_with_carry_01<RealType, w, s, r, val>::short_lag;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
template<class RealType, int w, unsigned int s, unsigned int r, int val>
|
||||||
|
RealType subtract_with_carry_01<RealType, w, s, r, val>::compute(unsigned int index) const
|
||||||
|
{
|
||||||
|
return x[(k+index) % long_lag];
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP
|
||||||
118
Boost/boost/random/triangle_distribution.hpp
Normal file
118
Boost/boost/random/triangle_distribution.hpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/* boost random/triangle_distribution.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: triangle_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP
|
||||||
|
#define BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP
|
||||||
|
|
||||||
|
#include <boost/config/no_tr1/cmath.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/uniform_01.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of @c triangle_distribution model a \random_distribution.
|
||||||
|
* A @c triangle_distribution has three parameters, @c a, @c b, and @c c,
|
||||||
|
* which are the smallest, the most probable and the largest values of
|
||||||
|
* the distribution respectively.
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class triangle_distribution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c triangle_distribution with the parameters
|
||||||
|
* @c a, @c b, and @c c.
|
||||||
|
*
|
||||||
|
* Preconditions: a <= b <= c.
|
||||||
|
*/
|
||||||
|
explicit triangle_distribution(result_type a_arg = result_type(0),
|
||||||
|
result_type b_arg = result_type(0.5),
|
||||||
|
result_type c_arg = result_type(1))
|
||||||
|
: _a(a_arg), _b(b_arg), _c(c_arg)
|
||||||
|
{
|
||||||
|
assert(_a <= _b && _b <= _c);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/** Returns the @c a parameter of the distribution */
|
||||||
|
result_type a() const { return _a; }
|
||||||
|
/** Returns the @c b parameter of the distribution */
|
||||||
|
result_type b() const { return _b; }
|
||||||
|
/** Returns the @c c parameter of the distribution */
|
||||||
|
result_type c() const { return _c; }
|
||||||
|
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
using std::sqrt;
|
||||||
|
#endif
|
||||||
|
result_type u = eng();
|
||||||
|
if( u <= q1 )
|
||||||
|
return _a + p1*sqrt(u);
|
||||||
|
else
|
||||||
|
return _c - d3*sqrt(d2*u-d1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const triangle_distribution& td)
|
||||||
|
{
|
||||||
|
os << td._a << " " << td._b << " " << td._c;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, triangle_distribution& td)
|
||||||
|
{
|
||||||
|
is >> std::ws >> td._a >> std::ws >> td._b >> std::ws >> td._c;
|
||||||
|
td.init();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \cond hide_private_members
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
using std::sqrt;
|
||||||
|
#endif
|
||||||
|
d1 = _b - _a;
|
||||||
|
d2 = _c - _a;
|
||||||
|
d3 = sqrt(_c - _b);
|
||||||
|
q1 = d1 / d2;
|
||||||
|
p1 = sqrt(d1 * d2);
|
||||||
|
}
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
result_type _a, _b, _c;
|
||||||
|
result_type d1, d2, d3, q1, p1;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP
|
||||||
273
Boost/boost/random/uniform_01.hpp
Normal file
273
Boost/boost/random/uniform_01.hpp
Normal file
@@ -0,0 +1,273 @@
|
|||||||
|
/* boost random/uniform_01.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: uniform_01.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_UNIFORM_01_HPP
|
||||||
|
#define BOOST_RANDOM_UNIFORM_01_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/detail/pass_through_engine.hpp>
|
||||||
|
|
||||||
|
#include <boost/random/detail/disable_warnings.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
#ifdef BOOST_RANDOM_DOXYGEN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The distribution function uniform_01 models a \random_distribution.
|
||||||
|
* On each invocation, it returns a random floating-point value
|
||||||
|
* uniformly distributed in the range [0..1).
|
||||||
|
*
|
||||||
|
* The template parameter RealType shall denote a float-like value type
|
||||||
|
* with support for binary operators +, -, and /.
|
||||||
|
*
|
||||||
|
* Note: The current implementation is buggy, because it may not fill
|
||||||
|
* all of the mantissa with random bits. I'm unsure how to fill a
|
||||||
|
* (to-be-invented) @c boost::bigfloat class with random bits efficiently.
|
||||||
|
* It's probably time for a traits class.
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class uniform_01
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const;
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const;
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng);
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const new_uniform_01&)
|
||||||
|
{
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, new_uniform_01&)
|
||||||
|
{
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<class RealType>
|
||||||
|
class new_uniform_01
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
// compiler-generated copy ctor and copy assignment are fine
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng) {
|
||||||
|
for (;;) {
|
||||||
|
typedef typename Engine::result_type base_result;
|
||||||
|
result_type factor = result_type(1) /
|
||||||
|
(result_type((eng.max)()-(eng.min)()) +
|
||||||
|
result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0));
|
||||||
|
result_type result = result_type(eng() - (eng.min)()) * factor;
|
||||||
|
if (result < result_type(1))
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const new_uniform_01&)
|
||||||
|
{
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, new_uniform_01&)
|
||||||
|
{
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator, class RealType>
|
||||||
|
class backward_compatible_uniform_01
|
||||||
|
{
|
||||||
|
typedef boost::random::detail::ptr_helper<UniformRandomNumberGenerator> traits;
|
||||||
|
typedef boost::random::detail::pass_through_engine<UniformRandomNumberGenerator> internal_engine_type;
|
||||||
|
public:
|
||||||
|
typedef UniformRandomNumberGenerator base_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
explicit backward_compatible_uniform_01(typename traits::rvalue_type rng)
|
||||||
|
: _rng(rng),
|
||||||
|
_factor(result_type(1) /
|
||||||
|
(result_type((_rng.max)()-(_rng.min)()) +
|
||||||
|
result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// compiler-generated copy ctor and copy assignment are fine
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
|
||||||
|
typename traits::value_type& base() { return _rng.base(); }
|
||||||
|
const typename traits::value_type& base() const { return _rng.base(); }
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
result_type operator()() {
|
||||||
|
for (;;) {
|
||||||
|
result_type result = result_type(_rng() - (_rng.min)()) * _factor;
|
||||||
|
if (result < result_type(1))
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const backward_compatible_uniform_01& u)
|
||||||
|
{
|
||||||
|
os << u._rng;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, backward_compatible_uniform_01& u)
|
||||||
|
{
|
||||||
|
is >> u._rng;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef typename internal_engine_type::result_type base_result;
|
||||||
|
internal_engine_type _rng;
|
||||||
|
result_type _factor;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class UniformRandomNumberGenerator, class RealType>
|
||||||
|
const bool backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType>::has_fixed_range;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template<class UniformRandomNumberGenerator>
|
||||||
|
struct select_uniform_01
|
||||||
|
{
|
||||||
|
template<class RealType>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct select_uniform_01<float>
|
||||||
|
{
|
||||||
|
template<class RealType>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef new_uniform_01<float> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct select_uniform_01<double>
|
||||||
|
{
|
||||||
|
template<class RealType>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef new_uniform_01<double> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct select_uniform_01<long double>
|
||||||
|
{
|
||||||
|
template<class RealType>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef new_uniform_01<long double> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Because it is so commonly used: uniform distribution on the real [0..1)
|
||||||
|
// range. This allows for specializations to avoid a costly int -> float
|
||||||
|
// conversion plus float multiplication
|
||||||
|
template<class UniformRandomNumberGenerator = double, class RealType = double>
|
||||||
|
class uniform_01
|
||||||
|
: public detail::select_uniform_01<UniformRandomNumberGenerator>::BOOST_NESTED_TEMPLATE apply<RealType>::type
|
||||||
|
{
|
||||||
|
typedef typename detail::select_uniform_01<UniformRandomNumberGenerator>::BOOST_NESTED_TEMPLATE apply<RealType>::type impl_type;
|
||||||
|
typedef boost::random::detail::ptr_helper<UniformRandomNumberGenerator> traits;
|
||||||
|
public:
|
||||||
|
|
||||||
|
uniform_01() {}
|
||||||
|
|
||||||
|
explicit uniform_01(typename traits::rvalue_type rng)
|
||||||
|
: impl_type(rng)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_01& u)
|
||||||
|
{
|
||||||
|
os << static_cast<const impl_type&>(u);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, uniform_01& u)
|
||||||
|
{
|
||||||
|
is >> static_cast<impl_type&>(u);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#include <boost/random/detail/enable_warnings.hpp>
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_UNIFORM_01_HPP
|
||||||
300
Boost/boost/random/uniform_int.hpp
Normal file
300
Boost/boost/random/uniform_int.hpp
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
/* boost random/uniform_int.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: uniform_int.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-04-08 added min<max assertion (N. Becker)
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_UNIFORM_INT_HPP
|
||||||
|
#define BOOST_RANDOM_UNIFORM_INT_HPP
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/detail/signed_unsigned_tools.hpp>
|
||||||
|
#include <boost/type_traits/make_unsigned.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The distribution function uniform_int models a \random_distribution.
|
||||||
|
* On each invocation, it returns a random integer value uniformly
|
||||||
|
* distributed in the set of integer numbers {min, min+1, min+2, ..., max}.
|
||||||
|
*
|
||||||
|
* The template parameter IntType shall denote an integer-like value type.
|
||||||
|
*/
|
||||||
|
template<class IntType = int>
|
||||||
|
class uniform_int
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef IntType input_type;
|
||||||
|
typedef IntType result_type;
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
typedef typename make_unsigned<result_type>::type range_type;
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a uniform_int object. @c min and @c max are
|
||||||
|
* the parameters of the distribution.
|
||||||
|
*
|
||||||
|
* Requires: min <= max
|
||||||
|
*/
|
||||||
|
explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9)
|
||||||
|
: _min(min_arg), _max(max_arg)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
|
||||||
|
#endif
|
||||||
|
assert(min_arg <= max_arg);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: The "min" parameter of the distribution
|
||||||
|
*/
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
|
||||||
|
/**
|
||||||
|
* Returns: The "max" parameter of the distribution
|
||||||
|
*/
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
// can't have member function templates out-of-line due to MSVC bugs
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
return generate(eng, _min, _max, _range);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng, result_type n)
|
||||||
|
{
|
||||||
|
assert(n > 0);
|
||||||
|
|
||||||
|
if (n == 1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return generate(eng, 0, n - 1, n - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_int& ud)
|
||||||
|
{
|
||||||
|
os << ud._min << " " << ud._max;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, uniform_int& ud)
|
||||||
|
{
|
||||||
|
is >> std::ws >> ud._min >> std::ws >> ud._max;
|
||||||
|
ud.init();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(push)
|
||||||
|
// disable division by zero warning, since we can't
|
||||||
|
// actually divide by zero.
|
||||||
|
#pragma warning(disable:4723)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
template<class Engine>
|
||||||
|
static result_type generate(Engine& eng, result_type min_value, result_type /*max_value*/, range_type range)
|
||||||
|
{
|
||||||
|
typedef typename Engine::result_type base_result;
|
||||||
|
// ranges are always unsigned
|
||||||
|
typedef typename make_unsigned<base_result>::type base_unsigned;
|
||||||
|
const base_result bmin = (eng.min)();
|
||||||
|
const base_unsigned brange =
|
||||||
|
random::detail::subtract<base_result>()((eng.max)(), (eng.min)());
|
||||||
|
|
||||||
|
if(range == 0) {
|
||||||
|
return min_value;
|
||||||
|
} else if(brange == range) {
|
||||||
|
// this will probably never happen in real life
|
||||||
|
// basically nothing to do; just take care we don't overflow / underflow
|
||||||
|
base_unsigned v = random::detail::subtract<base_result>()(eng(), bmin);
|
||||||
|
return random::detail::add<base_unsigned, result_type>()(v, min_value);
|
||||||
|
} else if(brange < range) {
|
||||||
|
// use rejection method to handle things like 0..3 --> 0..4
|
||||||
|
for(;;) {
|
||||||
|
// concatenate several invocations of the base RNG
|
||||||
|
// take extra care to avoid overflows
|
||||||
|
|
||||||
|
// limit == floor((range+1)/(brange+1))
|
||||||
|
// Therefore limit*(brange+1) <= range+1
|
||||||
|
range_type limit;
|
||||||
|
if(range == (std::numeric_limits<range_type>::max)()) {
|
||||||
|
limit = range/(range_type(brange)+1);
|
||||||
|
if(range % (range_type(brange)+1) == range_type(brange))
|
||||||
|
++limit;
|
||||||
|
} else {
|
||||||
|
limit = (range+1)/(range_type(brange)+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We consider "result" as expressed to base (brange+1):
|
||||||
|
// For every power of (brange+1), we determine a random factor
|
||||||
|
range_type result = range_type(0);
|
||||||
|
range_type mult = range_type(1);
|
||||||
|
|
||||||
|
// loop invariants:
|
||||||
|
// result < mult
|
||||||
|
// mult <= range
|
||||||
|
while(mult <= limit) {
|
||||||
|
// Postcondition: result <= range, thus no overflow
|
||||||
|
//
|
||||||
|
// limit*(brange+1)<=range+1 def. of limit (1)
|
||||||
|
// eng()-bmin<=brange eng() post. (2)
|
||||||
|
// and mult<=limit. loop condition (3)
|
||||||
|
// Therefore mult*(eng()-bmin+1)<=range+1 by (1),(2),(3) (4)
|
||||||
|
// Therefore mult*(eng()-bmin)+mult<=range+1 rearranging (4) (5)
|
||||||
|
// result<mult loop invariant (6)
|
||||||
|
// Therefore result+mult*(eng()-bmin)<range+1 by (5), (6) (7)
|
||||||
|
//
|
||||||
|
// Postcondition: result < mult*(brange+1)
|
||||||
|
//
|
||||||
|
// result<mult loop invariant (1)
|
||||||
|
// eng()-bmin<=brange eng() post. (2)
|
||||||
|
// Therefore result+mult*(eng()-bmin) <
|
||||||
|
// mult+mult*(eng()-bmin) by (1) (3)
|
||||||
|
// Therefore result+(eng()-bmin)*mult <
|
||||||
|
// mult+mult*brange by (2), (3) (4)
|
||||||
|
// Therefore result+(eng()-bmin)*mult <
|
||||||
|
// mult*(brange+1) by (4)
|
||||||
|
result += static_cast<range_type>(random::detail::subtract<base_result>()(eng(), bmin) * mult);
|
||||||
|
|
||||||
|
// equivalent to (mult * (brange+1)) == range+1, but avoids overflow.
|
||||||
|
if(mult * range_type(brange) == range - mult + 1) {
|
||||||
|
// The destination range is an integer power of
|
||||||
|
// the generator's range.
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Postcondition: mult <= range
|
||||||
|
//
|
||||||
|
// limit*(brange+1)<=range+1 def. of limit (1)
|
||||||
|
// mult<=limit loop condition (2)
|
||||||
|
// Therefore mult*(brange+1)<=range+1 by (1), (2) (3)
|
||||||
|
// mult*(brange+1)!=range+1 preceding if (4)
|
||||||
|
// Therefore mult*(brange+1)<range+1 by (3), (4) (5)
|
||||||
|
//
|
||||||
|
// Postcondition: result < mult
|
||||||
|
//
|
||||||
|
// See the second postcondition on the change to result.
|
||||||
|
mult *= range_type(brange)+range_type(1);
|
||||||
|
}
|
||||||
|
// loop postcondition: range/mult < brange+1
|
||||||
|
//
|
||||||
|
// mult > limit loop condition (1)
|
||||||
|
// Suppose range/mult >= brange+1 Assumption (2)
|
||||||
|
// range >= mult*(brange+1) by (2) (3)
|
||||||
|
// range+1 > mult*(brange+1) by (3) (4)
|
||||||
|
// range+1 > (limit+1)*(brange+1) by (1), (4) (5)
|
||||||
|
// (range+1)/(brange+1) > limit+1 by (5) (6)
|
||||||
|
// limit < floor((range+1)/(brange+1)) by (6) (7)
|
||||||
|
// limit==floor((range+1)/(brange+1)) def. of limit (8)
|
||||||
|
// not (2) reductio (9)
|
||||||
|
//
|
||||||
|
// loop postcondition: (range/mult)*mult+(mult-1) >= range
|
||||||
|
//
|
||||||
|
// (range/mult)*mult + range%mult == range identity (1)
|
||||||
|
// range%mult < mult def. of % (2)
|
||||||
|
// (range/mult)*mult+mult > range by (1), (2) (3)
|
||||||
|
// (range/mult)*mult+(mult-1) >= range by (3) (4)
|
||||||
|
//
|
||||||
|
// Note that the maximum value of result at this point is (mult-1),
|
||||||
|
// so after this final step, we generate numbers that can be
|
||||||
|
// at least as large as range. We have to really careful to avoid
|
||||||
|
// overflow in this final addition and in the rejection. Anything
|
||||||
|
// that overflows is larger than range and can thus be rejected.
|
||||||
|
|
||||||
|
// range/mult < brange+1 -> no endless loop
|
||||||
|
range_type result_increment = uniform_int<range_type>(0, range/mult)(eng);
|
||||||
|
if((std::numeric_limits<range_type>::max)() / mult < result_increment) {
|
||||||
|
// The multiplcation would overflow. Reject immediately.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result_increment *= mult;
|
||||||
|
// unsigned integers are guaranteed to wrap on overflow.
|
||||||
|
result += result_increment;
|
||||||
|
if(result < result_increment) {
|
||||||
|
// The addition overflowed. Reject.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(result > range) {
|
||||||
|
// Too big. Reject.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return random::detail::add<range_type, result_type>()(result, min_value);
|
||||||
|
}
|
||||||
|
} else { // brange > range
|
||||||
|
base_unsigned bucket_size;
|
||||||
|
// it's safe to add 1 to range, as long as we cast it first,
|
||||||
|
// because we know that it is less than brange. However,
|
||||||
|
// we do need to be careful not to cause overflow by adding 1
|
||||||
|
// to brange.
|
||||||
|
if(brange == (std::numeric_limits<base_unsigned>::max)()) {
|
||||||
|
bucket_size = brange / (static_cast<base_unsigned>(range)+1);
|
||||||
|
if(brange % (static_cast<base_unsigned>(range)+1) == static_cast<base_unsigned>(range)) {
|
||||||
|
++bucket_size;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bucket_size = (brange+1) / (static_cast<base_unsigned>(range)+1);
|
||||||
|
}
|
||||||
|
for(;;) {
|
||||||
|
base_unsigned result =
|
||||||
|
random::detail::subtract<base_result>()(eng(), bmin);
|
||||||
|
result /= bucket_size;
|
||||||
|
// result and range are non-negative, and result is possibly larger
|
||||||
|
// than range, so the cast is safe
|
||||||
|
if(result <= static_cast<base_unsigned>(range))
|
||||||
|
return random::detail::add<base_unsigned, result_type>()(result, min_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
_range = random::detail::subtract<result_type>()(_max, _min);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
// The result_type may be signed or unsigned, but the _range is always
|
||||||
|
// unsigned.
|
||||||
|
result_type _min, _max;
|
||||||
|
range_type _range;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_UNIFORM_INT_HPP
|
||||||
101
Boost/boost/random/uniform_on_sphere.hpp
Normal file
101
Boost/boost/random/uniform_on_sphere.hpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/* boost random/uniform_on_sphere.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: uniform_on_sphere.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
|
||||||
|
#define BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm> // std::transform
|
||||||
|
#include <functional> // std::bind2nd, std::divides
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/normal_distribution.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of class template uniform_on_sphere model a
|
||||||
|
* \random_distribution. Such a distribution produces random
|
||||||
|
* numbers uniformly distributed on the unit sphere of arbitrary
|
||||||
|
* dimension @c dim. The @c Cont template parameter must be a STL-like
|
||||||
|
* container type with begin and end operations returning non-const
|
||||||
|
* ForwardIterators of type @c Cont::iterator. Each invocation of the
|
||||||
|
* @c UniformRandomNumberGenerator shall result in a floating-point
|
||||||
|
* value in the range [0,1).
|
||||||
|
*/
|
||||||
|
template<class RealType = double, class Cont = std::vector<RealType> >
|
||||||
|
class uniform_on_sphere
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef Cont result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c uniform_on_sphere distribution.
|
||||||
|
* @c dim is the dimension of the sphere.
|
||||||
|
*/
|
||||||
|
explicit uniform_on_sphere(int dim = 2) : _container(dim), _dim(dim) { }
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
void reset() { _normal.reset(); }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
const result_type & operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
RealType sqsum = 0;
|
||||||
|
for(typename Cont::iterator it = _container.begin();
|
||||||
|
it != _container.end();
|
||||||
|
++it) {
|
||||||
|
RealType val = _normal(eng);
|
||||||
|
*it = val;
|
||||||
|
sqsum += val * val;
|
||||||
|
}
|
||||||
|
#ifndef BOOST_NO_STDC_NAMESPACE
|
||||||
|
using std::sqrt;
|
||||||
|
#endif
|
||||||
|
// for all i: result[i] /= sqrt(sqsum)
|
||||||
|
std::transform(_container.begin(), _container.end(), _container.begin(),
|
||||||
|
std::bind2nd(std::divides<RealType>(), sqrt(sqsum)));
|
||||||
|
return _container;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_on_sphere& sd)
|
||||||
|
{
|
||||||
|
os << sd._dim;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, uniform_on_sphere& sd)
|
||||||
|
{
|
||||||
|
is >> std::ws >> sd._dim;
|
||||||
|
sd._container.resize(sd._dim);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
normal_distribution<RealType> _normal;
|
||||||
|
result_type _container;
|
||||||
|
int _dim;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
|
||||||
108
Boost/boost/random/uniform_real.hpp
Normal file
108
Boost/boost/random/uniform_real.hpp
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/* boost random/uniform_real.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: uniform_real.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-04-08 added min<max assertion (N. Becker)
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_UNIFORM_REAL_HPP
|
||||||
|
#define BOOST_RANDOM_UNIFORM_REAL_HPP
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The distribution function uniform_real models a random distribution.
|
||||||
|
* On each invocation, it returns a random floating-point value uniformly
|
||||||
|
* distributed in the range [min..max). The value is computed using
|
||||||
|
* std::numeric_limits<RealType>::digits random binary digits, i.e.
|
||||||
|
* the mantissa of the floating-point value is completely filled with
|
||||||
|
* random bits.
|
||||||
|
*
|
||||||
|
* Note: The current implementation is buggy, because it may not fill
|
||||||
|
* all of the mantissa with random bits.
|
||||||
|
*/
|
||||||
|
template<class RealType = double>
|
||||||
|
class uniform_real
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef RealType input_type;
|
||||||
|
typedef RealType result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a uniform_real object. @c min and @c max are the
|
||||||
|
* parameters of the distribution.
|
||||||
|
*
|
||||||
|
* Requires: min <= max
|
||||||
|
*/
|
||||||
|
explicit uniform_real(RealType min_arg = RealType(0),
|
||||||
|
RealType max_arg = RealType(1))
|
||||||
|
: _min(min_arg), _max(max_arg)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
|
||||||
|
#endif
|
||||||
|
assert(min_arg <= max_arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-generated copy ctor and assignment operator are fine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: The "min" parameter of the distribution
|
||||||
|
*/
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
|
||||||
|
/**
|
||||||
|
* Returns: The "max" parameter of the distribution
|
||||||
|
*/
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng) {
|
||||||
|
result_type numerator = static_cast<result_type>(eng() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION());
|
||||||
|
result_type divisor = static_cast<result_type>(eng.max BOOST_PREVENT_MACRO_SUBSTITUTION() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION());
|
||||||
|
assert(divisor > 0);
|
||||||
|
assert(numerator >= 0 && numerator <= divisor);
|
||||||
|
return numerator / divisor * (_max - _min) + _min;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_real& ud)
|
||||||
|
{
|
||||||
|
os << ud._min << " " << ud._max;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, uniform_real& ud)
|
||||||
|
{
|
||||||
|
is >> std::ws >> ud._min >> std::ws >> ud._max;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
RealType _min, _max;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_UNIFORM_REAL_HPP
|
||||||
158
Boost/boost/random/uniform_smallint.hpp
Normal file
158
Boost/boost/random/uniform_smallint.hpp
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
/* boost random/uniform_smallint.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000-2001
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: uniform_smallint.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2001-04-08 added min<max assertion (N. Becker)
|
||||||
|
* 2001-02-18 moved to individual header files
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_UNIFORM_SMALLINT_HPP
|
||||||
|
#define BOOST_RANDOM_UNIFORM_SMALLINT_HPP
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
#include <boost/random/uniform_01.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
// uniform integer distribution on a small range [min, max]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The distribution function uniform_smallint models a \random_distribution.
|
||||||
|
* On each invocation, it returns a random integer value uniformly distributed
|
||||||
|
* in the set of integer numbers {min, min+1, min+2, ..., max}. It assumes
|
||||||
|
* that the desired range (max-min+1) is small compared to the range of the
|
||||||
|
* underlying source of random numbers and thus makes no attempt to limit
|
||||||
|
* quantization errors.
|
||||||
|
*
|
||||||
|
* Let r<sub>out</sub>=(max-min+1) the desired range of integer numbers, and
|
||||||
|
* let r<sub>base</sub> be the range of the underlying source of random
|
||||||
|
* numbers. Then, for the uniform distribution, the theoretical probability
|
||||||
|
* for any number i in the range r<sub>out</sub> will be p<sub>out</sub>(i) =
|
||||||
|
* 1/r<sub>out</sub>. Likewise, assume a uniform distribution on r<sub>base</sub> for
|
||||||
|
* the underlying source of random numbers, i.e. p<sub>base</sub>(i) =
|
||||||
|
* 1/r<sub>base</sub>. Let p<sub>out_s</sub>(i) denote the random
|
||||||
|
* distribution generated by @c uniform_smallint. Then the sum over all
|
||||||
|
* i in r<sub>out</sub> of (p<sub>out_s</sub>(i)/p<sub>out</sub>(i) - 1)<sup>2</sup>
|
||||||
|
* shall not exceed r<sub>out</sub>/r<sub>base</sub><sup>2</sup>
|
||||||
|
* (r<sub>base</sub> mod r<sub>out</sub>)(r<sub>out</sub> -
|
||||||
|
* r<sub>base</sub> mod r<sub>out</sub>).
|
||||||
|
*
|
||||||
|
* The template parameter IntType shall denote an integer-like value type.
|
||||||
|
*
|
||||||
|
* Note: The property above is the square sum of the relative differences
|
||||||
|
* in probabilities between the desired uniform distribution
|
||||||
|
* p<sub>out</sub>(i) and the generated distribution p<sub>out_s</sub>(i).
|
||||||
|
* The property can be fulfilled with the calculation
|
||||||
|
* (base_rng mod r<sub>out</sub>), as follows: Let r = r<sub>base</sub> mod
|
||||||
|
* r<sub>out</sub>. The base distribution on r<sub>base</sub> is folded onto the
|
||||||
|
* range r<sub>out</sub>. The numbers i < r have assigned (r<sub>base</sub>
|
||||||
|
* div r<sub>out</sub>)+1 numbers of the base distribution, the rest has
|
||||||
|
* only (r<sub>base</sub> div r<sub>out</sub>). Therefore,
|
||||||
|
* p<sub>out_s</sub>(i) = ((r<sub>base</sub> div r<sub>out</sub>)+1) /
|
||||||
|
* r<sub>base</sub> for i < r and p<sub>out_s</sub>(i) = (r<sub>base</sub>
|
||||||
|
* div r<sub>out</sub>)/r<sub>base</sub> otherwise. Substituting this in the
|
||||||
|
* above sum formula leads to the desired result.
|
||||||
|
*
|
||||||
|
* Note: The upper bound for (r<sub>base</sub> mod r<sub>out</sub>)
|
||||||
|
* (r<sub>out</sub> - r<sub>base</sub> mod r<sub>out</sub>) is
|
||||||
|
* r<sub>out</sub><sup>2</sup>/4. Regarding the upper bound for the
|
||||||
|
* square sum of the relative quantization error of
|
||||||
|
* r<sub>out</sub><sup>3</sup>/(4*r<sub>base</sub><sup>2</sup>), it
|
||||||
|
* seems wise to either choose r<sub>base</sub> so that r<sub>base</sub> >
|
||||||
|
* 10*r<sub>out</sub><sup>2</sup> or ensure that r<sub>base</sub> is
|
||||||
|
* divisible by r<sub>out</sub>.
|
||||||
|
*/
|
||||||
|
template<class IntType = int>
|
||||||
|
class uniform_smallint
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef IntType input_type;
|
||||||
|
typedef IntType result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c uniform_smallint. @c min and @c max are the
|
||||||
|
* lower and upper bounds of the output range, respectively.
|
||||||
|
*/
|
||||||
|
explicit uniform_smallint(IntType min_arg = 0, IntType max_arg = 9)
|
||||||
|
: _min(min_arg), _max(max_arg)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
|
||||||
|
void reset() { }
|
||||||
|
|
||||||
|
template<class Engine>
|
||||||
|
result_type operator()(Engine& eng)
|
||||||
|
{
|
||||||
|
typedef typename Engine::result_type base_result;
|
||||||
|
base_result _range = static_cast<base_result>(_max-_min)+1;
|
||||||
|
base_result _factor = 1;
|
||||||
|
|
||||||
|
// LCGs get bad when only taking the low bits.
|
||||||
|
// (probably put this logic into a partial template specialization)
|
||||||
|
// Check how many low bits we can ignore before we get too much
|
||||||
|
// quantization error.
|
||||||
|
base_result r_base = (eng.max)() - (eng.min)();
|
||||||
|
if(r_base == (std::numeric_limits<base_result>::max)()) {
|
||||||
|
_factor = 2;
|
||||||
|
r_base /= 2;
|
||||||
|
}
|
||||||
|
r_base += 1;
|
||||||
|
if(r_base % _range == 0) {
|
||||||
|
// No quantization effects, good
|
||||||
|
_factor = r_base / _range;
|
||||||
|
} else {
|
||||||
|
// carefully avoid overflow; pessimizing here
|
||||||
|
for( ; r_base/_range/32 >= _range; _factor *= 2)
|
||||||
|
r_base /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<result_type>(((eng() - (eng.min)()) / _factor) % _range + _min);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_smallint& ud)
|
||||||
|
{
|
||||||
|
os << ud._min << " " << ud._max;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, uniform_smallint& ud)
|
||||||
|
{
|
||||||
|
is >> std::ws >> ud._min >> std::ws >> ud._max;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
result_type _min;
|
||||||
|
result_type _max;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_UNIFORM_SMALLINT_HPP
|
||||||
220
Boost/boost/random/variate_generator.hpp
Normal file
220
Boost/boost/random/variate_generator.hpp
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
/* boost random/variate_generator.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: variate_generator.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP
|
||||||
|
#define BOOST_RANDOM_RANDOM_GENERATOR_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
// implementation details
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
#include <boost/random/uniform_01.hpp>
|
||||||
|
#include <boost/random/detail/pass_through_engine.hpp>
|
||||||
|
#include <boost/random/detail/uniform_int_float.hpp>
|
||||||
|
#include <boost/random/detail/ptr_helper.hpp>
|
||||||
|
|
||||||
|
// Borland C++ 5.6.0 has problems using its numeric_limits traits as
|
||||||
|
// template parameters
|
||||||
|
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
|
||||||
|
#include <boost/type_traits/is_integral.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/random/detail/disable_warnings.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
|
||||||
|
namespace random {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<bool have_int, bool want_int>
|
||||||
|
struct engine_helper;
|
||||||
|
|
||||||
|
// for consistency, always have two levels of decorations
|
||||||
|
template<>
|
||||||
|
struct engine_helper<true, true>
|
||||||
|
{
|
||||||
|
template<class Engine, class DistInputType>
|
||||||
|
struct impl
|
||||||
|
{
|
||||||
|
typedef pass_through_engine<Engine> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct engine_helper<false, false>
|
||||||
|
{
|
||||||
|
template<class Engine, class DistInputType>
|
||||||
|
struct impl
|
||||||
|
{
|
||||||
|
typedef uniform_01<Engine, DistInputType> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct engine_helper<true, false>
|
||||||
|
{
|
||||||
|
template<class Engine, class DistInputType>
|
||||||
|
struct impl
|
||||||
|
{
|
||||||
|
typedef uniform_01<Engine, DistInputType> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct engine_helper<false, true>
|
||||||
|
{
|
||||||
|
template<class Engine, class DistInputType>
|
||||||
|
struct impl
|
||||||
|
{
|
||||||
|
typedef uniform_int_float<Engine, unsigned long> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace random
|
||||||
|
|
||||||
|
///\endcond
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A random variate generator is used to join a random number
|
||||||
|
* generator together with a random number distribution.
|
||||||
|
* Boost.Random provides a vast choice of \generators as well
|
||||||
|
* as \distributions.
|
||||||
|
*
|
||||||
|
* Instantations of class template @c variate_generator model
|
||||||
|
* a \number_generator.
|
||||||
|
*
|
||||||
|
* The argument for the template parameter Engine shall be of
|
||||||
|
* the form U, U&, or U*, where U models a
|
||||||
|
* \uniform_random_number_generator. Then, the member
|
||||||
|
* engine_value_type names U (not the pointer or reference to U).
|
||||||
|
*
|
||||||
|
* Specializations of @c variate_generator satisfy the
|
||||||
|
* requirements of CopyConstructible. They also satisfy the
|
||||||
|
* requirements of Assignable unless the template parameter
|
||||||
|
* Engine is of the form U&.
|
||||||
|
*
|
||||||
|
* The complexity of all functions specified in this section
|
||||||
|
* is constant. No function described in this section except
|
||||||
|
* the constructor throws an exception.
|
||||||
|
*/
|
||||||
|
template<class Engine, class Distribution>
|
||||||
|
class variate_generator
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
typedef random::detail::pass_through_engine<Engine> decorated_engine;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename decorated_engine::base_type engine_value_type;
|
||||||
|
typedef Engine engine_type;
|
||||||
|
typedef Distribution distribution_type;
|
||||||
|
typedef typename Distribution::result_type result_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a @c variate_generator object with the associated
|
||||||
|
* \uniform_random_number_generator eng and the associated
|
||||||
|
* \random_distribution d.
|
||||||
|
*
|
||||||
|
* Throws: If and what the copy constructor of Engine or
|
||||||
|
* Distribution throws.
|
||||||
|
*/
|
||||||
|
variate_generator(Engine e, Distribution d)
|
||||||
|
: _eng(decorated_engine(e)), _dist(d) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: distribution()(e)
|
||||||
|
*
|
||||||
|
* Notes: The sequence of numbers produced by the
|
||||||
|
* \uniform_random_number_generator e, s<sub>e</sub>, is
|
||||||
|
* obtained from the sequence of numbers produced by the
|
||||||
|
* associated \uniform_random_number_generator eng, s<sub>eng</sub>,
|
||||||
|
* as follows: Consider the values of @c numeric_limits<T>::is_integer
|
||||||
|
* for @c T both @c Distribution::input_type and
|
||||||
|
* @c engine_value_type::result_type. If the values for both types are
|
||||||
|
* true, then se is identical to s<sub>eng</sub>. Otherwise, if the
|
||||||
|
* values for both types are false, then the numbers in s<sub>eng</sub>
|
||||||
|
* are divided by engine().max()-engine().min() to obtain the numbers
|
||||||
|
* in s<sub>e</sub>. Otherwise, if the value for
|
||||||
|
* @c engine_value_type::result_type is true and the value for
|
||||||
|
* @c Distribution::input_type is false, then the numbers in s<sub>eng</sub>
|
||||||
|
* are divided by engine().max()-engine().min()+1 to obtain the numbers in
|
||||||
|
* s<sub>e</sub>. Otherwise, the mapping from s<sub>eng</sub> to
|
||||||
|
* s<sub>e</sub> is implementation-defined. In all cases, an
|
||||||
|
* implicit conversion from @c engine_value_type::result_type to
|
||||||
|
* @c Distribution::input_type is performed. If such a conversion does
|
||||||
|
* not exist, the program is ill-formed.
|
||||||
|
*/
|
||||||
|
result_type operator()() { return _dist(_eng); }
|
||||||
|
/**
|
||||||
|
* Returns: distribution()(e, value).
|
||||||
|
* For the semantics of e, see the description of operator()().
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
result_type operator()(T value) { return _dist(_eng, value); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: A reference to the associated uniform random number generator.
|
||||||
|
*/
|
||||||
|
engine_value_type& engine() { return _eng.base().base(); }
|
||||||
|
/**
|
||||||
|
* Returns: A reference to the associated uniform random number generator.
|
||||||
|
*/
|
||||||
|
const engine_value_type& engine() const { return _eng.base().base(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns: A reference to the associated random distribution.
|
||||||
|
*/
|
||||||
|
distribution_type& distribution() { return _dist; }
|
||||||
|
/**
|
||||||
|
* Returns: A reference to the associated random distribution.
|
||||||
|
*/
|
||||||
|
const distribution_type& distribution() const { return _dist; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Precondition: distribution().min() is well-formed
|
||||||
|
*
|
||||||
|
* Returns: distribution().min()
|
||||||
|
*/
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
|
||||||
|
/**
|
||||||
|
* Precondition: distribution().max() is well-formed
|
||||||
|
*
|
||||||
|
* Returns: distribution().max()
|
||||||
|
*/
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
|
||||||
|
typedef typename random::detail::engine_helper<
|
||||||
|
::boost::is_integral<typename decorated_engine::result_type>::value,
|
||||||
|
::boost::is_integral<typename Distribution::input_type>::value
|
||||||
|
>::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
|
||||||
|
#else
|
||||||
|
enum {
|
||||||
|
have_int = std::numeric_limits<typename decorated_engine::result_type>::is_integer,
|
||||||
|
want_int = std::numeric_limits<typename Distribution::input_type>::is_integer
|
||||||
|
};
|
||||||
|
typedef typename random::detail::engine_helper<have_int, want_int>::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
internal_engine_type _eng;
|
||||||
|
distribution_type _dist;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#include <boost/random/detail/disable_warnings.hpp>
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP
|
||||||
184
Boost/boost/random/xor_combine.hpp
Normal file
184
Boost/boost/random/xor_combine.hpp
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
/* boost random/xor_combine.hpp header file
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2002
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* See http://www.boost.org for most recent version including documentation.
|
||||||
|
*
|
||||||
|
* $Id: xor_combine.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_XOR_COMBINE_HPP
|
||||||
|
#define BOOST_RANDOM_XOR_COMBINE_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
#include <algorithm> // for std::min and std::max
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/cstdint.hpp> // uint32_t
|
||||||
|
#include <boost/random/detail/config.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace random {
|
||||||
|
|
||||||
|
/// \cond hide_private_members
|
||||||
|
#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
|
||||||
|
#define BOOST_RANDOM_VAL_TYPE typename URNG1::result_type
|
||||||
|
#else
|
||||||
|
#define BOOST_RANDOM_VAL_TYPE uint32_t
|
||||||
|
#endif
|
||||||
|
/// \endcond
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiations of @c xor_combine model a \pseudo_random_number_generator.
|
||||||
|
* To produce its output it invokes each of the base generators, shifts
|
||||||
|
* their results and xors them together.
|
||||||
|
*/
|
||||||
|
template<class URNG1, int s1, class URNG2, int s2
|
||||||
|
#ifndef BOOST_RANDOM_DOXYGEN
|
||||||
|
, BOOST_RANDOM_VAL_TYPE val = 0
|
||||||
|
#endif
|
||||||
|
>
|
||||||
|
class xor_combine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef URNG1 base1_type;
|
||||||
|
typedef URNG2 base2_type;
|
||||||
|
typedef typename base1_type::result_type result_type;
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
BOOST_STATIC_CONSTANT(int, shift1 = s1);
|
||||||
|
BOOST_STATIC_CONSTANT(int, shift2 = s2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructors a @c xor_combine by default constructing
|
||||||
|
* both base generators.
|
||||||
|
*/
|
||||||
|
xor_combine() : _rng1(), _rng2()
|
||||||
|
{ }
|
||||||
|
/**
|
||||||
|
* Constructs a @c xor_combine by copying two base generators.
|
||||||
|
*/
|
||||||
|
xor_combine(const base1_type & rng1, const base2_type & rng2)
|
||||||
|
: _rng1(rng1), _rng2(rng2) { }
|
||||||
|
/**
|
||||||
|
* Constructs a @c xor_combine, seeding both base generators
|
||||||
|
* with @c v.
|
||||||
|
*/
|
||||||
|
xor_combine(const result_type & v)
|
||||||
|
: _rng1(v), _rng2(v) { }
|
||||||
|
/**
|
||||||
|
* Constructs a @c xor_combine, seeding both base generators
|
||||||
|
* with values from the iterator range [first, last) and changes
|
||||||
|
* first to point to the element after the last one used. If there
|
||||||
|
* are not enough elements in the range to seed both generators,
|
||||||
|
* throws @c std::invalid_argument.
|
||||||
|
*/
|
||||||
|
template<class It> xor_combine(It& first, It last)
|
||||||
|
: _rng1(first, last), _rng2( /* advanced by other call */ first, last) { }
|
||||||
|
/**
|
||||||
|
* Calls @c seed() for both base generators.
|
||||||
|
*/
|
||||||
|
void seed() { _rng1.seed(); _rng2.seed(); }
|
||||||
|
/**
|
||||||
|
* @c seeds both base generators with @c v.
|
||||||
|
*/
|
||||||
|
void seed(const result_type & v) { _rng1.seed(v); _rng2.seed(v); }
|
||||||
|
/**
|
||||||
|
* seeds both base generators with values from the iterator
|
||||||
|
* range [first, last) and changes first to point to the element
|
||||||
|
* after the last one used. If there are not enough elements in
|
||||||
|
* the range to seed both generators, throws @c std::invalid_argument.
|
||||||
|
*/
|
||||||
|
template<class It> void seed(It& first, It last)
|
||||||
|
{
|
||||||
|
_rng1.seed(first, last);
|
||||||
|
_rng2.seed(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the first base generator. */
|
||||||
|
const base1_type& base1() { return _rng1; }
|
||||||
|
/** Returns the second base generator. */
|
||||||
|
const base2_type& base2() { return _rng2; }
|
||||||
|
|
||||||
|
/** Returns the next value of the generator. */
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
|
||||||
|
#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::is_integer);
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<typename base2_type::result_type>::is_integer);
|
||||||
|
BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::digits >= std::numeric_limits<typename base2_type::result_type>::digits);
|
||||||
|
#endif
|
||||||
|
return (_rng1() << s1) ^ (_rng2() << s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the smallest value that the generator can produce.
|
||||||
|
*/
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::min BOOST_PREVENT_MACRO_SUBSTITUTION((_rng1.min)(), (_rng2.min)()); }
|
||||||
|
/**
|
||||||
|
* Returns the largest value that the generator can produce.
|
||||||
|
*/
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::max BOOST_PREVENT_MACRO_SUBSTITUTION((_rng1.min)(), (_rng2.max)()); }
|
||||||
|
static bool validation(result_type x) { return val == x; }
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||||
|
|
||||||
|
#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_ostream<CharT,Traits>&
|
||||||
|
operator<<(std::basic_ostream<CharT,Traits>& os, const xor_combine& s)
|
||||||
|
{
|
||||||
|
os << s._rng1 << " " << s._rng2 << " ";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharT, class Traits>
|
||||||
|
friend std::basic_istream<CharT,Traits>&
|
||||||
|
operator>>(std::basic_istream<CharT,Traits>& is, xor_combine& s)
|
||||||
|
{
|
||||||
|
is >> s._rng1 >> std::ws >> s._rng2 >> std::ws;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
friend bool operator==(const xor_combine& x, const xor_combine& y)
|
||||||
|
{ return x._rng1 == y._rng1 && x._rng2 == y._rng2; }
|
||||||
|
friend bool operator!=(const xor_combine& x, const xor_combine& y)
|
||||||
|
{ return !(x == y); }
|
||||||
|
#else
|
||||||
|
// Use a member function; Streamable concept not supported.
|
||||||
|
bool operator==(const xor_combine& rhs) const
|
||||||
|
{ return _rng1 == rhs._rng1 && _rng2 == rhs._rng2; }
|
||||||
|
bool operator!=(const xor_combine& rhs) const
|
||||||
|
{ return !(*this == rhs); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
base1_type _rng1;
|
||||||
|
base2_type _rng2;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
// A definition is required even for integral static constants
|
||||||
|
template<class URNG1, int s1, class URNG2, int s2, BOOST_RANDOM_VAL_TYPE val>
|
||||||
|
const bool xor_combine<URNG1, s1, URNG2, s2, val>::has_fixed_range;
|
||||||
|
template<class URNG1, int s1, class URNG2, int s2, BOOST_RANDOM_VAL_TYPE val>
|
||||||
|
const int xor_combine<URNG1, s1, URNG2, s2, val>::shift1;
|
||||||
|
template<class URNG1, int s1, class URNG2, int s2, BOOST_RANDOM_VAL_TYPE val>
|
||||||
|
const int xor_combine<URNG1, s1, URNG2, s2, val>::shift2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef BOOST_RANDOM_VAL_TYPE
|
||||||
|
|
||||||
|
} // namespace random
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_RANDOM_XOR_COMBINE_HPP
|
||||||
125
Boost/boost/uuid/name_generator.hpp
Normal file
125
Boost/boost/uuid/name_generator.hpp
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
// Boost name_generator.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2010 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_NAME_GENERATOR_HPP
|
||||||
|
#define BOOST_UUID_NAME_GENERATOR_HPP
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <boost/uuid/sha1.hpp>
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring> // for strlen, wcslen
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||||
|
namespace std {
|
||||||
|
using ::strlen;
|
||||||
|
using ::wcslen;
|
||||||
|
} //namespace std
|
||||||
|
#endif //BOOST_NO_STDC_NAMESPACE
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
|
||||||
|
// generate a name-based uuid
|
||||||
|
// TODO: add in common namesspace uuids
|
||||||
|
class name_generator {
|
||||||
|
public:
|
||||||
|
typedef uuid result_type;
|
||||||
|
|
||||||
|
explicit name_generator(uuid const& namespace_uuid)
|
||||||
|
: namespace_uuid(namespace_uuid)
|
||||||
|
{}
|
||||||
|
|
||||||
|
uuid operator()(const char* name) {
|
||||||
|
reset();
|
||||||
|
process_characters(name, std::strlen(name));
|
||||||
|
return sha_to_uuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid operator()(const wchar_t* name) {
|
||||||
|
reset();
|
||||||
|
process_characters(name, std::wcslen(name));
|
||||||
|
return sha_to_uuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ch, typename char_traits, typename alloc>
|
||||||
|
uuid operator()(std::basic_string<ch, char_traits, alloc> const& name) {
|
||||||
|
reset();
|
||||||
|
process_characters(name.c_str(), name.length());
|
||||||
|
return sha_to_uuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid operator()(void const* buffer, std::size_t byte_count) {
|
||||||
|
reset();
|
||||||
|
sha.process_bytes(buffer, byte_count);
|
||||||
|
return sha_to_uuid();
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
// we convert all characters to uint32_t so that each
|
||||||
|
// character is 4 bytes reguardless of sizeof(char) or
|
||||||
|
// sizeof(wchar_t). We want the name string on any
|
||||||
|
// platform / compiler to generate the same uuid
|
||||||
|
// except for char
|
||||||
|
template <typename char_type>
|
||||||
|
void process_characters(char_type const*const characters, size_t count) {
|
||||||
|
BOOST_ASSERT(sizeof(uint32_t) >= sizeof(char_type));
|
||||||
|
|
||||||
|
for (size_t i=0; i<count; i++) {
|
||||||
|
uint32_t c = characters[i];
|
||||||
|
sha.process_byte( (c >> 0) && 0xFF );
|
||||||
|
sha.process_byte( (c >> 8) && 0xFF );
|
||||||
|
sha.process_byte( (c >> 16) && 0xFF );
|
||||||
|
sha.process_byte( (c >> 24) && 0xFF );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_characters(char const*const characters, size_t count) {
|
||||||
|
sha.process_bytes(characters, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
sha.reset();
|
||||||
|
sha.process_bytes(namespace_uuid.begin(), namespace_uuid.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid sha_to_uuid()
|
||||||
|
{
|
||||||
|
unsigned int digest[5];
|
||||||
|
|
||||||
|
sha.get_digest(digest);
|
||||||
|
|
||||||
|
uuid u;
|
||||||
|
for (int i=0; i<4; ++i) {
|
||||||
|
*(u.begin() + i*4+0) = ((digest[i] >> 24) & 0xFF);
|
||||||
|
*(u.begin() + i*4+1) = ((digest[i] >> 16) & 0xFF);
|
||||||
|
*(u.begin() + i*4+2) = ((digest[i] >> 8) & 0xFF);
|
||||||
|
*(u.begin() + i*4+3) = ((digest[i] >> 0) & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set variant
|
||||||
|
// must be 0b10xxxxxx
|
||||||
|
*(u.begin()+8) &= 0xBF;
|
||||||
|
*(u.begin()+8) |= 0x80;
|
||||||
|
|
||||||
|
// set version
|
||||||
|
// must be 0b0101xxxx
|
||||||
|
*(u.begin()+6) &= 0x5F; //0b01011111
|
||||||
|
*(u.begin()+6) |= 0x50; //0b01010000
|
||||||
|
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uuid namespace_uuid;
|
||||||
|
detail::sha1 sha;
|
||||||
|
};
|
||||||
|
|
||||||
|
}} // namespace boost::uuids
|
||||||
|
|
||||||
|
#endif // BOOST_UUID_NAME_GENERATOR_HPP
|
||||||
34
Boost/boost/uuid/nil_generator.hpp
Normal file
34
Boost/boost/uuid/nil_generator.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Boost nil_generator.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2010 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_NIL_GENERATOR_HPP
|
||||||
|
#define BOOST_UUID_NIL_GENERATOR_HPP
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
|
||||||
|
// generate a nil uuid
|
||||||
|
struct nil_generator {
|
||||||
|
typedef uuid result_type;
|
||||||
|
|
||||||
|
uuid operator()() const {
|
||||||
|
// initialize to all zeros
|
||||||
|
uuid u = {{0}};
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline uuid nil_uuid() {
|
||||||
|
return nil_generator()();
|
||||||
|
}
|
||||||
|
|
||||||
|
}} // namespace boost::uuids
|
||||||
|
|
||||||
|
#endif // BOOST_UUID_NIL_GENERATOR_HPP
|
||||||
|
|
||||||
118
Boost/boost/uuid/random_generator.hpp
Normal file
118
Boost/boost/uuid/random_generator.hpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
// Boost random_generator.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2010 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_RANDOM_GENERATOR_HPP
|
||||||
|
#define BOOST_UUID_RANDOM_GENERATOR_HPP
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <boost/uuid/seed_rng.hpp>
|
||||||
|
#include <boost/random/uniform_int.hpp>
|
||||||
|
#include <boost/random/variate_generator.hpp>
|
||||||
|
#include <boost/random/mersenne_twister.hpp>
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
|
||||||
|
// generate a random-based uuid
|
||||||
|
template <typename UniformRandomNumberGenerator>
|
||||||
|
class basic_random_generator {
|
||||||
|
private:
|
||||||
|
typedef uniform_int<unsigned long> distribution_type;
|
||||||
|
typedef variate_generator<UniformRandomNumberGenerator*, distribution_type> generator_type;
|
||||||
|
|
||||||
|
struct null_deleter
|
||||||
|
{
|
||||||
|
void operator()(void const *) const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef uuid result_type;
|
||||||
|
|
||||||
|
// default constructor creates the random number generator
|
||||||
|
basic_random_generator()
|
||||||
|
: pURNG(new UniformRandomNumberGenerator)
|
||||||
|
, generator
|
||||||
|
( pURNG.get()
|
||||||
|
, distribution_type
|
||||||
|
( (std::numeric_limits<unsigned long>::min)()
|
||||||
|
, (std::numeric_limits<unsigned long>::max)()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// seed the random number generator
|
||||||
|
detail::seed(*pURNG);
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep a reference to a random number generator
|
||||||
|
// don't seed a given random number generator
|
||||||
|
explicit basic_random_generator(UniformRandomNumberGenerator& gen)
|
||||||
|
: pURNG(&gen, null_deleter())
|
||||||
|
, generator
|
||||||
|
( pURNG.get()
|
||||||
|
, distribution_type
|
||||||
|
( (std::numeric_limits<unsigned long>::min)()
|
||||||
|
, (std::numeric_limits<unsigned long>::max)()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// keep a pointer to a random number generator
|
||||||
|
// don't seed a given random number generator
|
||||||
|
explicit basic_random_generator(UniformRandomNumberGenerator* pGen)
|
||||||
|
: pURNG(pGen, null_deleter())
|
||||||
|
, generator
|
||||||
|
( pURNG.get()
|
||||||
|
, distribution_type
|
||||||
|
( (std::numeric_limits<unsigned long>::min)()
|
||||||
|
, (std::numeric_limits<unsigned long>::max)()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(pURNG);
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid operator()()
|
||||||
|
{
|
||||||
|
uuid u;
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
unsigned long random_value = generator();
|
||||||
|
for (uuid::iterator it=u.begin(); it!=u.end(); ++it, ++i) {
|
||||||
|
if (i==sizeof(unsigned long)) {
|
||||||
|
random_value = generator();
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*it = ((random_value >> (i*8)) & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set variant
|
||||||
|
// must be 0b10xxxxxx
|
||||||
|
*(u.begin()+8) &= 0xBF;
|
||||||
|
*(u.begin()+8) |= 0x80;
|
||||||
|
|
||||||
|
// set version
|
||||||
|
// must be 0b0100xxxx
|
||||||
|
*(u.begin()+6) &= 0x4F; //0b01001111
|
||||||
|
*(u.begin()+6) |= 0x40; //0b01000000
|
||||||
|
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
shared_ptr<UniformRandomNumberGenerator> pURNG;
|
||||||
|
generator_type generator;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef basic_random_generator<mt19937> random_generator;
|
||||||
|
|
||||||
|
}} // namespace boost::uuids
|
||||||
|
|
||||||
|
#endif //BOOST_UUID_RANDOM_GENERATOR_HPP
|
||||||
262
Boost/boost/uuid/seed_rng.hpp
Normal file
262
Boost/boost/uuid/seed_rng.hpp
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
// Boost seed_rng.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2007 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 09 Nov 2007 - Initial Revision
|
||||||
|
// 25 Feb 2008 - moved to namespace boost::uuids::detail
|
||||||
|
// 28 Nov 2009 - disabled deprecated warnings for MSVC
|
||||||
|
|
||||||
|
// seed_rng models a UniformRandomNumberGenerator (see Boost.Random).
|
||||||
|
// Random number generators are hard to seed well. This is intended to provide
|
||||||
|
// good seed values for random number generators.
|
||||||
|
// It creates random numbers from a sha1 hash of data from a variary of sources,
|
||||||
|
// all of which are standard function calls. It produces random numbers slowly.
|
||||||
|
// Peter Dimov provided the details of sha1_random_digest_().
|
||||||
|
// see http://archives.free.net.ph/message/20070507.175609.4c4f503a.en.html
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_SEED_RNG_HPP
|
||||||
|
#define BOOST_UUID_SEED_RNG_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <cstring> // for memcpy
|
||||||
|
#include <limits>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <ctime> // for time_t, time, clock_t, clock
|
||||||
|
#include <cstdlib> // for rand
|
||||||
|
#include <cstdio> // for FILE, fopen, fread, fclose
|
||||||
|
#include <boost/uuid/sha1.hpp>
|
||||||
|
//#include <boost/nondet_random.hpp> //forward declare boost::random_device
|
||||||
|
|
||||||
|
// can't use boost::generator_iterator since boost::random number seed(Iter&, Iter)
|
||||||
|
// functions need a last iterator
|
||||||
|
//#include <boost/generator_iterator.hpp>
|
||||||
|
# include <boost/iterator/iterator_facade.hpp>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(push) // Save warning settings.
|
||||||
|
#pragma warning(disable : 4996) // Disable deprecated std::fopen
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||||
|
namespace std {
|
||||||
|
using ::memcpy;
|
||||||
|
using ::time_t;
|
||||||
|
using ::time;
|
||||||
|
using ::clock_t;
|
||||||
|
using ::clock;
|
||||||
|
using ::rand;
|
||||||
|
using ::FILE;
|
||||||
|
using ::fopen;
|
||||||
|
using ::fread;
|
||||||
|
using ::fclose;
|
||||||
|
} //namespace std
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// forward declare random number generators
|
||||||
|
namespace boost {
|
||||||
|
class random_device;
|
||||||
|
} //namespace boost
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
// should this be part of Boost.Random?
|
||||||
|
class seed_rng
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef unsigned int result_type;
|
||||||
|
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
|
||||||
|
//BOOST_STATIC_CONSTANT(unsigned int, min_value = 0);
|
||||||
|
//BOOST_STATIC_CONSTANT(unsigned int, max_value = UINT_MAX);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// note: rd_ intentionally left uninitialized
|
||||||
|
seed_rng()
|
||||||
|
: rd_index_(5)
|
||||||
|
, random_(std::fopen( "/dev/urandom", "rb" ))
|
||||||
|
{}
|
||||||
|
|
||||||
|
~seed_rng()
|
||||||
|
{
|
||||||
|
if (random_) {
|
||||||
|
std::fclose(random_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const
|
||||||
|
{
|
||||||
|
return (std::numeric_limits<result_type>::min)();
|
||||||
|
}
|
||||||
|
result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const
|
||||||
|
{
|
||||||
|
return (std::numeric_limits<result_type>::max)();
|
||||||
|
}
|
||||||
|
|
||||||
|
result_type operator()()
|
||||||
|
{
|
||||||
|
if (rd_index_ >= 5) {
|
||||||
|
//get new digest
|
||||||
|
sha1_random_digest_();
|
||||||
|
|
||||||
|
rd_index_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rd_[rd_index_++];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static unsigned int * sha1_random_digest_state_()
|
||||||
|
{
|
||||||
|
// intentionally left uninitialized
|
||||||
|
static unsigned int state[ 5 ];
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sha1_random_digest_()
|
||||||
|
{
|
||||||
|
boost::uuids::detail::sha1 sha;
|
||||||
|
|
||||||
|
unsigned int * ps = sha1_random_digest_state_();
|
||||||
|
|
||||||
|
unsigned int state[ 5 ];
|
||||||
|
std::memcpy( state, ps, sizeof( state ) ); // harmless data race
|
||||||
|
|
||||||
|
sha.process_bytes( (unsigned char const*)state, sizeof( state ) );
|
||||||
|
sha.process_bytes( (unsigned char const*)&ps, sizeof( ps ) );
|
||||||
|
|
||||||
|
{
|
||||||
|
std::time_t tm = std::time( 0 );
|
||||||
|
sha.process_bytes( (unsigned char const*)&tm, sizeof( tm ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::clock_t ck = std::clock();
|
||||||
|
sha.process_bytes( (unsigned char const*)&ck, sizeof( ck ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
unsigned int rn[] = { std::rand(), std::rand(), std::rand() };
|
||||||
|
sha.process_bytes( (unsigned char const*)rn, sizeof( rn ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// intentionally left uninitialized
|
||||||
|
unsigned char buffer[ 20 ];
|
||||||
|
|
||||||
|
if(random_)
|
||||||
|
{
|
||||||
|
std::fread( buffer, 1, 20, random_ );
|
||||||
|
}
|
||||||
|
|
||||||
|
// using an uninitialized buffer[] if fopen fails
|
||||||
|
// intentional, we rely on its contents being random
|
||||||
|
sha.process_bytes( buffer, sizeof( buffer ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// *p is intentionally left uninitialized
|
||||||
|
unsigned int * p = new unsigned int;
|
||||||
|
|
||||||
|
sha.process_bytes( (unsigned char const*)p, sizeof( *p ) );
|
||||||
|
sha.process_bytes( (unsigned char const*)&p, sizeof( p ) );
|
||||||
|
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
|
||||||
|
sha.process_bytes( (unsigned char const*)rd_, sizeof( rd_ ) );
|
||||||
|
|
||||||
|
unsigned int digest[ 5 ];
|
||||||
|
sha.get_digest( digest );
|
||||||
|
|
||||||
|
for( int i = 0; i < 5; ++i )
|
||||||
|
{
|
||||||
|
// harmless data race
|
||||||
|
ps[ i ] ^= digest[ i ];
|
||||||
|
rd_[ i ] ^= digest[ i ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int rd_[5];
|
||||||
|
int rd_index_;
|
||||||
|
std::FILE * random_;
|
||||||
|
|
||||||
|
private: // make seed_rng noncopyable
|
||||||
|
seed_rng(seed_rng const&);
|
||||||
|
seed_rng& operator=(seed_rng const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
// almost a copy of boost::generator_iterator
|
||||||
|
// but default constructor sets m_g to NULL
|
||||||
|
template <class Generator>
|
||||||
|
class generator_iterator
|
||||||
|
: public iterator_facade<
|
||||||
|
generator_iterator<Generator>
|
||||||
|
, typename Generator::result_type
|
||||||
|
, single_pass_traversal_tag
|
||||||
|
, typename Generator::result_type const&
|
||||||
|
>
|
||||||
|
{
|
||||||
|
typedef iterator_facade<
|
||||||
|
generator_iterator<Generator>
|
||||||
|
, typename Generator::result_type
|
||||||
|
, single_pass_traversal_tag
|
||||||
|
, typename Generator::result_type const&
|
||||||
|
> super_t;
|
||||||
|
|
||||||
|
public:
|
||||||
|
generator_iterator() : m_g(NULL) {}
|
||||||
|
generator_iterator(Generator* g) : m_g(g), m_value((*m_g)()) {}
|
||||||
|
|
||||||
|
void increment()
|
||||||
|
{
|
||||||
|
m_value = (*m_g)();
|
||||||
|
}
|
||||||
|
|
||||||
|
const typename Generator::result_type&
|
||||||
|
dereference() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool equal(generator_iterator const& y) const
|
||||||
|
{
|
||||||
|
return this->m_g == y.m_g && this->m_value == y.m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Generator* m_g;
|
||||||
|
typename Generator::result_type m_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
// seed() seeds a random number generator with good seed values
|
||||||
|
|
||||||
|
template <typename UniformRandomNumberGenerator>
|
||||||
|
inline void seed(UniformRandomNumberGenerator& rng)
|
||||||
|
{
|
||||||
|
seed_rng seed_gen;
|
||||||
|
generator_iterator<seed_rng> begin(&seed_gen);
|
||||||
|
generator_iterator<seed_rng> end;
|
||||||
|
rng.seed(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
// random_device does not / can not be seeded
|
||||||
|
template <>
|
||||||
|
inline void seed<boost::random_device>(boost::random_device&) {}
|
||||||
|
|
||||||
|
// random_device does not / can not be seeded
|
||||||
|
template <>
|
||||||
|
inline void seed<seed_rng>(seed_rng&) {}
|
||||||
|
|
||||||
|
}}} //namespace boost::uuids::detail
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(pop) // Restore warnings to previous state.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
208
Boost/boost/uuid/sha1.hpp
Normal file
208
Boost/boost/uuid/sha1.hpp
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
// boost/uuid/sha1.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2007 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 29 May 2007 - Initial Revision
|
||||||
|
// 25 Feb 2008 - moved to namespace boost::uuids::detail
|
||||||
|
|
||||||
|
// This is a byte oriented implementation
|
||||||
|
// Note: this implementation does not handle message longer than
|
||||||
|
// 2^32 bytes.
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_SHA1_H
|
||||||
|
#define BOOST_UUID_SHA1_H
|
||||||
|
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||||
|
namespace std {
|
||||||
|
using ::size_t;
|
||||||
|
} // namespace std
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT(sizeof(unsigned char)*8 == 8);
|
||||||
|
BOOST_STATIC_ASSERT(sizeof(unsigned int)*8 == 32);
|
||||||
|
|
||||||
|
inline unsigned int left_rotate(unsigned int x, std::size_t n)
|
||||||
|
{
|
||||||
|
return (x<<n) ^ (x>> (32-n));
|
||||||
|
}
|
||||||
|
|
||||||
|
class sha1
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef unsigned int(&digest_type)[5];
|
||||||
|
public:
|
||||||
|
sha1();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void process_byte(unsigned char byte);
|
||||||
|
void process_block(void const* bytes_begin, void const* bytes_end);
|
||||||
|
void process_bytes(void const* buffer, std::size_t byte_count);
|
||||||
|
|
||||||
|
void get_digest(digest_type digest);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void process_block();
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int h_[5];
|
||||||
|
|
||||||
|
unsigned char block_[64];
|
||||||
|
|
||||||
|
std::size_t block_byte_index_;
|
||||||
|
std::size_t byte_count_;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline sha1::sha1()
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sha1::reset()
|
||||||
|
{
|
||||||
|
h_[0] = 0x67452301;
|
||||||
|
h_[1] = 0xEFCDAB89;
|
||||||
|
h_[2] = 0x98BADCFE;
|
||||||
|
h_[3] = 0x10325476;
|
||||||
|
h_[4] = 0xC3D2E1F0;
|
||||||
|
|
||||||
|
block_byte_index_ = 0;
|
||||||
|
byte_count_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sha1::process_byte(unsigned char byte)
|
||||||
|
{
|
||||||
|
block_[block_byte_index_++] = byte;
|
||||||
|
++byte_count_;
|
||||||
|
if (block_byte_index_ == 64) {
|
||||||
|
block_byte_index_ = 0;
|
||||||
|
process_block();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sha1::process_block(void const* bytes_begin, void const* bytes_end)
|
||||||
|
{
|
||||||
|
unsigned char const* begin = static_cast<unsigned char const*>(bytes_begin);
|
||||||
|
unsigned char const* end = static_cast<unsigned char const*>(bytes_end);
|
||||||
|
for(; begin != end; ++begin) {
|
||||||
|
process_byte(*begin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sha1::process_bytes(void const* buffer, std::size_t byte_count)
|
||||||
|
{
|
||||||
|
unsigned char const* b = static_cast<unsigned char const*>(buffer);
|
||||||
|
process_block(b, b+byte_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sha1::process_block()
|
||||||
|
{
|
||||||
|
unsigned int w[80];
|
||||||
|
for (std::size_t i=0; i<16; ++i) {
|
||||||
|
w[i] = (block_[i*4 + 0] << 24);
|
||||||
|
w[i] |= (block_[i*4 + 1] << 16);
|
||||||
|
w[i] |= (block_[i*4 + 2] << 8);
|
||||||
|
w[i] |= (block_[i*4 + 3]);
|
||||||
|
}
|
||||||
|
for (std::size_t i=16; i<80; ++i) {
|
||||||
|
w[i] = left_rotate((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int a = h_[0];
|
||||||
|
unsigned int b = h_[1];
|
||||||
|
unsigned int c = h_[2];
|
||||||
|
unsigned int d = h_[3];
|
||||||
|
unsigned int e = h_[4];
|
||||||
|
|
||||||
|
for (std::size_t i=0; i<80; ++i) {
|
||||||
|
unsigned int f;
|
||||||
|
unsigned int k;
|
||||||
|
|
||||||
|
if (i<20) {
|
||||||
|
f = (b & c) | (~b & d);
|
||||||
|
k = 0x5A827999;
|
||||||
|
} else if (i<40) {
|
||||||
|
f = b ^ c ^ d;
|
||||||
|
k = 0x6ED9EBA1;
|
||||||
|
} else if (i<60) {
|
||||||
|
f = (b & c) | (b & d) | (c & d);
|
||||||
|
k = 0x8F1BBCDC;
|
||||||
|
} else {
|
||||||
|
f = b ^ c ^ d;
|
||||||
|
k = 0xCA62C1D6;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned temp = left_rotate(a, 5) + f + e + k + w[i];
|
||||||
|
e = d;
|
||||||
|
d = c;
|
||||||
|
c = left_rotate(b, 30);
|
||||||
|
b = a;
|
||||||
|
a = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
h_[0] += a;
|
||||||
|
h_[1] += b;
|
||||||
|
h_[2] += c;
|
||||||
|
h_[3] += d;
|
||||||
|
h_[4] += e;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sha1::get_digest(digest_type digest)
|
||||||
|
{
|
||||||
|
std::size_t bit_count = byte_count_*8;
|
||||||
|
|
||||||
|
// append the bit '1' to the message
|
||||||
|
process_byte(0x80);
|
||||||
|
|
||||||
|
// append k bits '0', where k is the minimum number >= 0
|
||||||
|
// such that the resulting message length is congruent to 56 (mod 64)
|
||||||
|
// check if there is enough space for padding and bit_count
|
||||||
|
if (block_byte_index_ > 56) {
|
||||||
|
// finish this block
|
||||||
|
while (block_byte_index_ != 0) {
|
||||||
|
process_byte(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// one more block
|
||||||
|
while (block_byte_index_ < 56) {
|
||||||
|
process_byte(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (block_byte_index_ < 56) {
|
||||||
|
process_byte(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// append length of message (before pre-processing)
|
||||||
|
// as a 64-bit big-endian integer
|
||||||
|
process_byte(0);
|
||||||
|
process_byte(0);
|
||||||
|
process_byte(0);
|
||||||
|
process_byte(0);
|
||||||
|
process_byte( static_cast<unsigned char>((bit_count>>24) & 0xFF));
|
||||||
|
process_byte( static_cast<unsigned char>((bit_count>>16) & 0xFF));
|
||||||
|
process_byte( static_cast<unsigned char>((bit_count>>8 ) & 0xFF));
|
||||||
|
process_byte( static_cast<unsigned char>((bit_count) & 0xFF));
|
||||||
|
|
||||||
|
// get final digest
|
||||||
|
digest[0] = h_[0];
|
||||||
|
digest[1] = h_[1];
|
||||||
|
digest[2] = h_[2];
|
||||||
|
digest[3] = h_[3];
|
||||||
|
digest[4] = h_[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
}}} // namespace boost::uuids::detail
|
||||||
|
|
||||||
|
#endif
|
||||||
184
Boost/boost/uuid/string_generator.hpp
Normal file
184
Boost/boost/uuid/string_generator.hpp
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
// Boost string_generator.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2010 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_STRING_GENERATOR_HPP
|
||||||
|
#define BOOST_UUID_STRING_GENERATOR_HPP
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring> // for strlen, wcslen
|
||||||
|
#include <iterator>
|
||||||
|
#include <algorithm> // for find
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||||
|
namespace std {
|
||||||
|
using ::strlen;
|
||||||
|
using ::wcslen;
|
||||||
|
} //namespace std
|
||||||
|
#endif //BOOST_NO_STDC_NAMESPACE
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
|
||||||
|
// generate a uuid from a string
|
||||||
|
// lexical_cast works fine using uuid_io.hpp
|
||||||
|
// but this generator should accept more forms
|
||||||
|
// and be more efficient
|
||||||
|
// would like to accept the following forms:
|
||||||
|
// 0123456789abcdef0123456789abcdef
|
||||||
|
// 01234567-89ab-cdef-0123456789abcdef
|
||||||
|
// {01234567-89ab-cdef-0123456789abcdef}
|
||||||
|
// {0123456789abcdef0123456789abcdef}
|
||||||
|
// others?
|
||||||
|
struct string_generator {
|
||||||
|
typedef uuid result_type;
|
||||||
|
|
||||||
|
template <typename ch, typename char_traits, typename alloc>
|
||||||
|
uuid operator()(std::basic_string<ch, char_traits, alloc> const& s) const {
|
||||||
|
return operator()(s.begin(), s.end());
|
||||||
|
};
|
||||||
|
|
||||||
|
uuid operator()(char const*const s) const {
|
||||||
|
return operator()(s, s+std::strlen(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid operator()(wchar_t const*const s) const {
|
||||||
|
return operator()(s, s+std::wcslen(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename CharIterator>
|
||||||
|
uuid operator()(CharIterator begin, CharIterator end) const
|
||||||
|
{
|
||||||
|
typedef typename std::iterator_traits<CharIterator>::value_type char_type;
|
||||||
|
|
||||||
|
// check open brace
|
||||||
|
char_type c = get_next_char(begin, end);
|
||||||
|
bool has_open_brace = is_open_brace(c);
|
||||||
|
char_type open_brace_char = c;
|
||||||
|
if (has_open_brace) {
|
||||||
|
c = get_next_char(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has_dashes = false;
|
||||||
|
|
||||||
|
uuid u;
|
||||||
|
int i=0;
|
||||||
|
for (uuid::iterator it_byte=u.begin(); it_byte!=u.end(); ++it_byte, ++i) {
|
||||||
|
if (it_byte != u.begin()) {
|
||||||
|
c = get_next_char(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 4) {
|
||||||
|
has_dashes = is_dash(c);
|
||||||
|
if (has_dashes) {
|
||||||
|
c = get_next_char(begin, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_dashes) {
|
||||||
|
if (i == 6 || i == 8 || i == 10) {
|
||||||
|
if (is_dash(c)) {
|
||||||
|
c = get_next_char(begin, end);
|
||||||
|
} else {
|
||||||
|
throw_invalid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*it_byte = get_value(c);
|
||||||
|
|
||||||
|
c = get_next_char(begin, end);
|
||||||
|
*it_byte <<= 4;
|
||||||
|
*it_byte |= get_value(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check close brace
|
||||||
|
if (has_open_brace) {
|
||||||
|
c = get_next_char(begin, end);
|
||||||
|
check_close_brace(c, open_brace_char);
|
||||||
|
}
|
||||||
|
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <typename CharIterator>
|
||||||
|
typename std::iterator_traits<CharIterator>::value_type
|
||||||
|
get_next_char(CharIterator& begin, CharIterator end) const {
|
||||||
|
if (begin == end) {
|
||||||
|
throw_invalid();
|
||||||
|
}
|
||||||
|
return *begin++;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char get_value(char c) const {
|
||||||
|
static char const*const digits_begin = "0123456789abcdefABCDEF";
|
||||||
|
static char const*const digits_end = digits_begin + 22;
|
||||||
|
|
||||||
|
static unsigned char const values[] =
|
||||||
|
{ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15
|
||||||
|
, static_cast<unsigned char>(-1) };
|
||||||
|
|
||||||
|
char const* d = std::find(digits_begin, digits_end, c);
|
||||||
|
return values[d - digits_begin];
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char get_value(wchar_t c) const {
|
||||||
|
static wchar_t const*const digits_begin = L"0123456789abcdefABCDEF";
|
||||||
|
static wchar_t const*const digits_end = digits_begin + 22;
|
||||||
|
|
||||||
|
static unsigned char const values[] =
|
||||||
|
{ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15
|
||||||
|
, static_cast<unsigned char>(-1) };
|
||||||
|
|
||||||
|
wchar_t const* d = std::find(digits_begin, digits_end, c);
|
||||||
|
return values[d - digits_begin];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_dash(char c) const {
|
||||||
|
return c == '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_dash(wchar_t c) const {
|
||||||
|
return c == L'-';
|
||||||
|
}
|
||||||
|
|
||||||
|
// return closing brace
|
||||||
|
bool is_open_brace(char c) const {
|
||||||
|
return (c == '{');
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_open_brace(wchar_t c) const {
|
||||||
|
return (c == L'{');
|
||||||
|
}
|
||||||
|
|
||||||
|
void check_close_brace(char c, char open_brace) const {
|
||||||
|
if (open_brace == '{' && c == '}') {
|
||||||
|
//great
|
||||||
|
} else {
|
||||||
|
throw_invalid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void check_close_brace(wchar_t c, wchar_t open_brace) const {
|
||||||
|
if (open_brace == L'{' && c == L'}') {
|
||||||
|
// great
|
||||||
|
} else {
|
||||||
|
throw_invalid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void throw_invalid() const {
|
||||||
|
throw std::runtime_error("invalid uuid string");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}} // namespace boost::uuids
|
||||||
|
|
||||||
|
#endif //BOOST_UUID_STRING_GENERATOR_HPP
|
||||||
|
|
||||||
221
Boost/boost/uuid/uuid.hpp
Normal file
221
Boost/boost/uuid/uuid.hpp
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
// Boost uuid.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2006 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 06 Feb 2006 - Initial Revision
|
||||||
|
// 09 Nov 2006 - fixed variant and version bits for v4 guids
|
||||||
|
// 13 Nov 2006 - added serialization
|
||||||
|
// 17 Nov 2006 - added name-based guid creation
|
||||||
|
// 20 Nov 2006 - add fixes for gcc (from Tim Blechmann)
|
||||||
|
// 07 Mar 2007 - converted to header only
|
||||||
|
// 10 May 2007 - removed need for Boost.Thread
|
||||||
|
// - added better seed - thanks Peter Dimov
|
||||||
|
// - removed null()
|
||||||
|
// - replaced byte_count() and output_bytes() with size() and begin() and end()
|
||||||
|
// 11 May 2007 - fixed guid(ByteInputIterator first, ByteInputIterator last)
|
||||||
|
// - optimized operator>>
|
||||||
|
// 14 May 2007 - converted from guid to uuid
|
||||||
|
// 29 May 2007 - uses new implementation of sha1
|
||||||
|
// 01 Jun 2007 - removed using namespace directives
|
||||||
|
// 09 Nov 2007 - moved implementation to uuid.ipp file
|
||||||
|
// 12 Nov 2007 - moved serialize code to uuid_serialize.hpp file
|
||||||
|
// 25 Feb 2008 - moved to namespace boost::uuids
|
||||||
|
// 19 Mar 2009 - changed to a POD, reorganized files
|
||||||
|
// 28 Nov 2009 - disabled deprecated warnings for MSVC
|
||||||
|
// 30 Nov 2009 - used BOOST_STATIC_CONSTANT
|
||||||
|
// 02 Dec 2009 - removed BOOST_STATIC_CONSTANT - not all compilers like it
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_HPP
|
||||||
|
#define BOOST_UUID_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <boost/config.hpp> // for static assert
|
||||||
|
#ifndef BOOST_UUID_NO_TYPE_TRAITS
|
||||||
|
#include <boost/type_traits/is_pod.hpp>
|
||||||
|
#include <boost/type_traits/integral_constant.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(push) // Save warning settings.
|
||||||
|
#pragma warning(disable : 4996) // Disable deprecated std::swap_ranges, std::equal
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||||
|
namespace std {
|
||||||
|
using ::size_t;
|
||||||
|
using ::ptrdiff_t;
|
||||||
|
} //namespace std
|
||||||
|
#endif //BOOST_NO_STDC_NAMESPACE
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
|
||||||
|
struct uuid
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef uint8_t value_type;
|
||||||
|
typedef uint8_t& reference;
|
||||||
|
typedef uint8_t const& const_reference;
|
||||||
|
typedef uint8_t* iterator;
|
||||||
|
typedef uint8_t const* const_iterator;
|
||||||
|
typedef std::size_t size_type;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
|
||||||
|
// This does not work on some compilers
|
||||||
|
// They seem to want the variable definec in
|
||||||
|
// a cpp file
|
||||||
|
//BOOST_STATIC_CONSTANT(size_type, static_size = 16);
|
||||||
|
static size_type static_size() { return 16; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
iterator begin() { return data; } /* throw() */
|
||||||
|
const_iterator begin() const { return data; } /* throw() */
|
||||||
|
iterator end() { return data+size(); } /* throw() */
|
||||||
|
const_iterator end() const { return data+size(); } /* throw() */
|
||||||
|
|
||||||
|
size_type size() const { return static_size(); } /* throw() */
|
||||||
|
|
||||||
|
bool is_nil() const /* throw() */
|
||||||
|
{
|
||||||
|
for(size_t i=0; i<static_size(); i++) {
|
||||||
|
if (data[i] != 0U) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum variant_type
|
||||||
|
{
|
||||||
|
variant_ncs, // NCS backward compatibility
|
||||||
|
variant_rfc_4122, // defined in RFC 4122 document
|
||||||
|
variant_microsoft, // Microsoft Corporation backward compatibility
|
||||||
|
variant_future // future definition
|
||||||
|
};
|
||||||
|
variant_type variant() const /* throw() */
|
||||||
|
{
|
||||||
|
// variant is stored in octet 7
|
||||||
|
// which is index 8, since indexes count backwards
|
||||||
|
unsigned char octet7 = data[8]; // octet 7 is array index 8
|
||||||
|
if ( (octet7 & 0x80) == 0x00 ) { // 0b0xxxxxxx
|
||||||
|
return variant_ncs;
|
||||||
|
} else if ( (octet7 & 0xC0) == 0x80 ) { // 0b10xxxxxx
|
||||||
|
return variant_rfc_4122;
|
||||||
|
} else if ( (octet7 & 0xE0) == 0xC0 ) { // 0b110xxxxx
|
||||||
|
return variant_microsoft;
|
||||||
|
} else {
|
||||||
|
//assert( (octet7 & 0xE0) == 0xE0 ) // 0b111xxxx
|
||||||
|
return variant_future;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum version_type
|
||||||
|
{
|
||||||
|
version_unknown = -1,
|
||||||
|
version_time_based = 1,
|
||||||
|
version_dce_security = 2,
|
||||||
|
version_name_based_md5 = 3,
|
||||||
|
version_random_number_based = 4,
|
||||||
|
version_name_based_sha1 = 5
|
||||||
|
};
|
||||||
|
version_type version() const /* throw() */
|
||||||
|
{
|
||||||
|
//version is stored in octet 9
|
||||||
|
// which is index 6, since indexes count backwards
|
||||||
|
unsigned char octet9 = data[6];
|
||||||
|
if ( (octet9 & 0xF0) == 0x10 ) {
|
||||||
|
return version_time_based;
|
||||||
|
} else if ( (octet9 & 0xF0) == 0x20 ) {
|
||||||
|
return version_dce_security;
|
||||||
|
} else if ( (octet9 & 0xF0) == 0x30 ) {
|
||||||
|
return version_name_based_md5;
|
||||||
|
} else if ( (octet9 & 0xF0) == 0x40 ) {
|
||||||
|
return version_random_number_based;
|
||||||
|
} else if ( (octet9 & 0xF0) == 0x50 ) {
|
||||||
|
return version_name_based_sha1;
|
||||||
|
} else {
|
||||||
|
return version_unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// note: linear complexity
|
||||||
|
void swap(uuid& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
std::swap_ranges(begin(), end(), rhs.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// or should it be array<uint8_t, 16>
|
||||||
|
uint8_t data[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(uuid const& lhs, uuid const& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(uuid const& lhs, uuid const& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator<(uuid const& lhs, uuid const& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator>(uuid const& lhs, uuid const& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
return rhs < lhs;
|
||||||
|
}
|
||||||
|
inline bool operator<=(uuid const& lhs, uuid const& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
return !(rhs < lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator>=(uuid const& lhs, uuid const& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
return !(lhs < rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void swap(uuid& lhs, uuid& rhs) /* throw() */
|
||||||
|
{
|
||||||
|
lhs.swap(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is equivalent to boost::hash_range(u.begin(), u.end());
|
||||||
|
inline std::size_t hash_value(uuid const& u) /* throw() */
|
||||||
|
{
|
||||||
|
std::size_t seed = 0;
|
||||||
|
for(uuid::const_iterator i=u.begin(); i != u.end(); ++i)
|
||||||
|
{
|
||||||
|
seed ^= static_cast<std::size_t>(*i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
}} //namespace boost::uuids
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_NO_TYPE_TRAITS
|
||||||
|
// type traits specializations
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct is_pod<uuids::uuid> : true_type {};
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(pop) // Restore warnings to previous state.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // BOOST_UUID_HPP
|
||||||
19
Boost/boost/uuid/uuid_generators.hpp
Normal file
19
Boost/boost/uuid/uuid_generators.hpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Boost uuid_generators.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2006 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 06 Feb 2006 - Initial Revision
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_GENERATORS_HPP
|
||||||
|
#define BOOST_UUID_GENERATORS_HPP
|
||||||
|
|
||||||
|
#include <boost/uuid/nil_generator.hpp>
|
||||||
|
#include <boost/uuid/string_generator.hpp>
|
||||||
|
#include <boost/uuid/name_generator.hpp>
|
||||||
|
#include <boost/uuid/random_generator.hpp>
|
||||||
|
|
||||||
|
#endif //BOOST_UUID_GENERATORS_HPP
|
||||||
198
Boost/boost/uuid/uuid_io.hpp
Normal file
198
Boost/boost/uuid/uuid_io.hpp
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
// Boost uuid_io.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2009 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 20 Mar 2009 - Initial Revision
|
||||||
|
// 28 Nov 2009 - disabled deprecated warnings for MSVC
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_IO_HPP
|
||||||
|
#define BOOST_UUID_IO_HPP
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <ios>
|
||||||
|
#include <ostream>
|
||||||
|
#include <istream>
|
||||||
|
#include <boost/io/ios_state.hpp>
|
||||||
|
#include <locale>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(push) // Save warning settings.
|
||||||
|
#pragma warning(disable : 4996) // Disable deprecated std::ctype<char>::widen, std::copy
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace uuids {
|
||||||
|
|
||||||
|
template <typename ch, typename char_traits>
|
||||||
|
std::basic_ostream<ch, char_traits>& operator<<(std::basic_ostream<ch, char_traits> &os, uuid const& u)
|
||||||
|
{
|
||||||
|
io::ios_flags_saver flags_saver(os);
|
||||||
|
io::basic_ios_fill_saver<ch, char_traits> fill_saver(os);
|
||||||
|
|
||||||
|
const typename std::basic_ostream<ch, char_traits>::sentry ok(os);
|
||||||
|
if (ok) {
|
||||||
|
const std::streamsize width = os.width(0);
|
||||||
|
const std::streamsize uuid_width = 36;
|
||||||
|
const std::ios_base::fmtflags flags = os.flags();
|
||||||
|
const typename std::basic_ios<ch, char_traits>::char_type fill = os.fill();
|
||||||
|
if (flags & (std::ios_base::right | std::ios_base::internal)) {
|
||||||
|
for (std::streamsize i=uuid_width; i<width; i++) {
|
||||||
|
os << fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os << std::hex;
|
||||||
|
os.fill(os.widen('0'));
|
||||||
|
|
||||||
|
std::size_t i=0;
|
||||||
|
for (uuid::const_iterator i_data = u.begin(); i_data!=u.end(); ++i_data, ++i) {
|
||||||
|
os.width(2);
|
||||||
|
os << static_cast<unsigned int>(*i_data);
|
||||||
|
if (i == 3 || i == 5 || i == 7 || i == 9) {
|
||||||
|
os << os.widen('-');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & std::ios_base::left) {
|
||||||
|
for (std::streamsize i=uuid_width; i<width; i++) {
|
||||||
|
os << fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.width(0); //used the width so reset it
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ch, typename char_traits>
|
||||||
|
std::basic_istream<ch, char_traits>& operator>>(std::basic_istream<ch, char_traits> &is, uuid &u)
|
||||||
|
{
|
||||||
|
const typename std::basic_istream<ch, char_traits>::sentry ok(is);
|
||||||
|
if (ok) {
|
||||||
|
unsigned char data[16];
|
||||||
|
|
||||||
|
typedef std::ctype<ch> ctype_t;
|
||||||
|
ctype_t const& ctype = std::use_facet<ctype_t>(is.getloc());
|
||||||
|
|
||||||
|
ch xdigits[16];
|
||||||
|
{
|
||||||
|
char szdigits[] = "0123456789ABCDEF";
|
||||||
|
ctype.widen(szdigits, szdigits+16, xdigits);
|
||||||
|
}
|
||||||
|
ch*const xdigits_end = xdigits+16;
|
||||||
|
|
||||||
|
ch c;
|
||||||
|
for (std::size_t i=0; i<u.size() && is; ++i) {
|
||||||
|
is >> c;
|
||||||
|
c = ctype.toupper(c);
|
||||||
|
|
||||||
|
ch* f = std::find(xdigits, xdigits_end, c);
|
||||||
|
if (f == xdigits_end) {
|
||||||
|
is.setstate(std::ios_base::failbit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char byte = static_cast<unsigned char>(std::distance(&xdigits[0], f));
|
||||||
|
|
||||||
|
is >> c;
|
||||||
|
c = ctype.toupper(c);
|
||||||
|
f = std::find(xdigits, xdigits_end, c);
|
||||||
|
if (f == xdigits_end) {
|
||||||
|
is.setstate(std::ios_base::failbit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte <<= 4;
|
||||||
|
byte |= static_cast<unsigned char>(std::distance(&xdigits[0], f));
|
||||||
|
|
||||||
|
data[i] = byte;
|
||||||
|
|
||||||
|
if (is) {
|
||||||
|
if (i == 3 || i == 5 || i == 7 || i == 9) {
|
||||||
|
is >> c;
|
||||||
|
if (c != is.widen('-')) is.setstate(std::ios_base::failbit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is) {
|
||||||
|
std::copy(data, data+16, u.begin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
inline char to_char(size_t i) {
|
||||||
|
if (i <= 9) {
|
||||||
|
return static_cast<char>('0' + i);
|
||||||
|
} else {
|
||||||
|
return static_cast<char>('a' + (i-10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline wchar_t to_wchar(size_t i) {
|
||||||
|
if (i <= 9) {
|
||||||
|
return static_cast<wchar_t>(L'0' + i);
|
||||||
|
} else {
|
||||||
|
return static_cast<wchar_t>(L'a' + (i-10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
inline std::string to_string(uuid const& u)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
result.reserve(36);
|
||||||
|
|
||||||
|
std::size_t i=0;
|
||||||
|
for (uuid::const_iterator it_data = u.begin(); it_data!=u.end(); ++it_data, ++i) {
|
||||||
|
const size_t hi = ((*it_data) >> 4) & 0x0F;
|
||||||
|
result += detail::to_char(hi);
|
||||||
|
|
||||||
|
const size_t lo = (*it_data) & 0x0F;
|
||||||
|
result += detail::to_char(lo);
|
||||||
|
|
||||||
|
if (i == 3 || i == 5 || i == 7 || i == 9) {
|
||||||
|
result += '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_STD_WSTRING
|
||||||
|
inline std::wstring to_wstring(uuid const& u)
|
||||||
|
{
|
||||||
|
std::wstring result;
|
||||||
|
result.reserve(36);
|
||||||
|
|
||||||
|
std::size_t i=0;
|
||||||
|
for (uuid::const_iterator it_data = u.begin(); it_data!=u.end(); ++it_data, ++i) {
|
||||||
|
const size_t hi = ((*it_data) >> 4) & 0x0F;
|
||||||
|
result += detail::to_wchar(hi);
|
||||||
|
|
||||||
|
const size_t lo = (*it_data) & 0x0F;
|
||||||
|
result += detail::to_wchar(lo);
|
||||||
|
|
||||||
|
if (i == 3 || i == 5 || i == 7 || i == 9) {
|
||||||
|
result += L'-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}} //namespace boost::uuids
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(pop) // Restore warnings to previous state.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // BOOST_UUID_IO_HPP
|
||||||
20
Boost/boost/uuid/uuid_serialize.hpp
Normal file
20
Boost/boost/uuid/uuid_serialize.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Boost uuid_serialize.hpp header file ----------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2007 Andy Tompkins.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 12 Nov 2007 - Initial Revision
|
||||||
|
// 25 Feb 2008 - moved to namespace boost::uuids::detail
|
||||||
|
|
||||||
|
#ifndef BOOST_UUID_SERIALIZE_HPP
|
||||||
|
#define BOOST_UUID_SERIALIZE_HPP
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <boost/serialization/level.hpp>
|
||||||
|
|
||||||
|
BOOST_CLASS_IMPLEMENTATION(boost::uuids::uuid, boost::serialization::primitive_type)
|
||||||
|
|
||||||
|
#endif // BOOST_UUID_SERIALIZE_HPP
|
||||||
18
Boost/boost/weak_ptr.hpp
Normal file
18
Boost/boost/weak_ptr.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef BOOST_WEAK_PTR_HPP_INCLUDED
|
||||||
|
#define BOOST_WEAK_PTR_HPP_INCLUDED
|
||||||
|
|
||||||
|
//
|
||||||
|
// weak_ptr.hpp
|
||||||
|
//
|
||||||
|
// Copyright (c) 2001, 2002, 2003 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
//
|
||||||
|
// See http://www.boost.org/libs/smart_ptr/weak_ptr.htm for documentation.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
|
|
||||||
|
#endif // #ifndef BOOST_WEAK_PTR_HPP_INCLUDED
|
||||||
BIN
Boost/lib/libboost_system-vc100-mt-1_44.lib
Normal file
BIN
Boost/lib/libboost_system-vc100-mt-1_44.lib
Normal file
Binary file not shown.
BIN
Boost/lib/libboost_system-vc100-mt-gd-1_44.lib
Normal file
BIN
Boost/lib/libboost_system-vc100-mt-gd-1_44.lib
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -73,7 +73,7 @@
|
|||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||||
<AdditionalIncludeDirectories>src/zipFS;Dependencies/SDL/include;Dependencies/include;$(JGEEXTRAS);../Boost;../projects/mtg/include;include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>src/zipFS;Dependencies/SDL/include;Dependencies/include;$(JGEEXTRAS);../Boost;../projects/mtg/include;include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>SDL_CONFIG;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>TIXML_USE_STL; SDL_CONFIG;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<StringPooling>true</StringPooling>
|
<StringPooling>true</StringPooling>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<AdditionalIncludeDirectories>src/zipFS;Dependencies/SDL/include;Dependencies/include;$(JGEEXTRAS);../Boost;../projects/mtg/include;include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>src/zipFS;Dependencies/SDL/include;Dependencies/include;$(JGEEXTRAS);../Boost;../projects/mtg/include;include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>SDL_CONFIG;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>TIXML_USE_STL; SDL_CONFIG;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
<Optimization>Full</Optimization>
|
<Optimization>Full</Optimization>
|
||||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||||
<AdditionalIncludeDirectories>src/zipFS;Dependencies/SDL/include;Dependencies/include;$(JGEEXTRAS);../Boost;../projects/mtg/include;include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>src/zipFS;Dependencies/SDL/include;Dependencies/include;$(JGEEXTRAS);../Boost;../projects/mtg/include;include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>SDL_CONFIG;WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_HAS_ITERATOR_DEBBUGING=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>TIXML_USE_STL; SDL_CONFIG;WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_HAS_ITERATOR_DEBBUGING=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<StringPooling>true</StringPooling>
|
<StringPooling>true</StringPooling>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ HGE_OBJS = src/hge/hgecolor.o src/hge/hgeparticle.o \
|
|||||||
|
|
||||||
|
|
||||||
CXXFLAGS = -W -Wall -Werror -Wno-unused
|
CXXFLAGS = -W -Wall -Werror -Wno-unused
|
||||||
|
CXXFLAGS += -DTIXML_USE_STL
|
||||||
|
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
CXXFLAGS += -ggdb3
|
CXXFLAGS += -ggdb3
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
// dirty, but I get OS header includes this way
|
// dirty, but I get OS header includes this way
|
||||||
#include "JGE.h"
|
#include "JGE.h"
|
||||||
|
|
||||||
|
#include "OutputCapturer.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -29,12 +31,23 @@ std::string ToHex(T* pointer)
|
|||||||
#if defined (WIN32) || defined (LINUX)
|
#if defined (WIN32) || defined (LINUX)
|
||||||
|
|
||||||
#ifdef QT_CONFIG
|
#ifdef QT_CONFIG
|
||||||
|
|
||||||
|
#ifdef CAPTURE_STDERR
|
||||||
#define DebugTrace(inString) \
|
#define DebugTrace(inString) \
|
||||||
{ \
|
{ \
|
||||||
std::ostringstream stream; \
|
std::ostringstream stream; \
|
||||||
stream << inString << std::endl; \
|
stream << inString; \
|
||||||
qDebug(stream.str().c_str()); \
|
OutputCapturer::add(stream.str()); \
|
||||||
}
|
}
|
||||||
|
#else // CAPTURE_STDERR
|
||||||
|
#define DebugTrace(inString) \
|
||||||
|
{ \
|
||||||
|
std::ostringstream stream; \
|
||||||
|
stream << inString; \
|
||||||
|
qDebug("%s", stream.str().c_str()); \
|
||||||
|
}
|
||||||
|
#endif // CAPTURE_STDERR
|
||||||
|
|
||||||
#elif defined (ANDROID)
|
#elif defined (ANDROID)
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#define DebugTrace(inString) \
|
#define DebugTrace(inString) \
|
||||||
@@ -48,7 +61,7 @@ std::string ToHex(T* pointer)
|
|||||||
{ \
|
{ \
|
||||||
std::ostringstream stream; \
|
std::ostringstream stream; \
|
||||||
stream << inString << std::endl; \
|
stream << inString << std::endl; \
|
||||||
OutputDebugString(stream.str().c_str()); \
|
OutputDebugStringA(stream.str().c_str()); \
|
||||||
}
|
}
|
||||||
#endif // QT_CONFIG
|
#endif // QT_CONFIG
|
||||||
#endif // Win32, Linux
|
#endif // Win32, Linux
|
||||||
|
|||||||
128
JGE/include/Downloader.h
Normal file
128
JGE/include/Downloader.h
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
#ifndef DOWNLOADER_H
|
||||||
|
#define DOWNLOADER_H
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This class handles download of remote resources (any kind of file)
|
||||||
|
// All the resources are stored locally in the userPath
|
||||||
|
// For every resources, the downloader verifies if the resource was modifed
|
||||||
|
// on the server before downloading the update. The Downloader maintains a catalogue
|
||||||
|
// of resource downloaded to be able to check if they need to be updated.
|
||||||
|
//
|
||||||
|
// The interface can be used completly synchronously by the application and some
|
||||||
|
// context or message loop is needed in the implementation of this interface
|
||||||
|
//
|
||||||
|
// Note that the Downloader could in theory by implemented on top of JNetwork.
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
#include <string>
|
||||||
|
#include <ostream>
|
||||||
|
#include <istream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
|
#include "Threading.h"
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class DownloadRequest
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
: public QObject
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
#endif
|
||||||
|
void fileDownloaded();
|
||||||
|
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
signals:
|
||||||
|
void percentChanged(int percent);
|
||||||
|
void statusChanged(int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef enum {
|
||||||
|
NOT_PRESENT,
|
||||||
|
DOWNLOADING,
|
||||||
|
DOWNLOADED,
|
||||||
|
DOWNLOAD_ERROR
|
||||||
|
} DownloadStatus;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
string mLocalPath;
|
||||||
|
string mRemoteResourceURL;
|
||||||
|
// previous one is the original, next one can change after redirection
|
||||||
|
string mRequestedRemoteResourceURL;
|
||||||
|
string mETag;
|
||||||
|
DownloadStatus mDownloadStatus;
|
||||||
|
bool mUpgradeAvailable;
|
||||||
|
size_t mTotalSize;
|
||||||
|
size_t mCurrentSize;
|
||||||
|
ofstream mFile;
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
QNetworkReply* mNetworkReply;
|
||||||
|
static QNetworkAccessManager networkAccessManager;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
DownloadRequest(string localPath="",
|
||||||
|
string remoteResourceURL="",
|
||||||
|
string ETag = "",
|
||||||
|
DownloadStatus downloadStatus=NOT_PRESENT,
|
||||||
|
size_t totalSize = 0,
|
||||||
|
size_t currentSize = 0);
|
||||||
|
~DownloadRequest();
|
||||||
|
static bool NetworkIsAccessible();
|
||||||
|
|
||||||
|
string getTempLocalPath() const { return (mLocalPath+".tmp"); };
|
||||||
|
string getLocalPath() const { return mLocalPath; };
|
||||||
|
string getRemoteResource() const { return mRemoteResourceURL; };
|
||||||
|
string getETag() const { return mETag; };
|
||||||
|
void startGet();
|
||||||
|
void startHead();
|
||||||
|
DownloadStatus getDownloadStatus() const { return mDownloadStatus; };
|
||||||
|
bool upgradeAvailable() const { return mUpgradeAvailable; };
|
||||||
|
void getSizes(size_t& totalSize, size_t¤tSize) {
|
||||||
|
totalSize = mTotalSize;
|
||||||
|
currentSize = mCurrentSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
friend ostream& operator<<(ostream& out, const DownloadRequest& d);
|
||||||
|
friend istream& operator>>(istream&, DownloadRequest&);
|
||||||
|
friend class Downloader;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Downloader
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Downloader(string globalRemoteURL="", string localCacheRecords="");
|
||||||
|
virtual ~Downloader();
|
||||||
|
static Downloader* mInstance;
|
||||||
|
string mGlobalRemoteURL;
|
||||||
|
string mLocalCacheRecords;
|
||||||
|
boost::mutex mMutex;
|
||||||
|
map<string, DownloadRequest*> mRequestMap;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Downloader* GetInstance();
|
||||||
|
static void Release();
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
DownloadRequest* Get(string localPath, string remoteResourceURL="");
|
||||||
|
|
||||||
|
friend ostream& operator<<(ostream& out, const Downloader& d);
|
||||||
|
friend istream& operator>>(istream&, Downloader&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOWNLOADER_H
|
||||||
@@ -297,7 +297,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
float mTimer;
|
float mTimer;
|
||||||
float mFrameTime;
|
float mFrameTime;
|
||||||
JAnimator* mAnimator;
|
|
||||||
vector<JAnimatorObject *> mObjects;
|
vector<JAnimatorObject *> mObjects;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ private:
|
|||||||
float mTexY;
|
float mTexY;
|
||||||
float mTexWidth;
|
float mTexWidth;
|
||||||
float mTexHeight;
|
float mTexHeight;
|
||||||
JTexture* mTexture;
|
|
||||||
JQuad* mQuad;
|
JQuad* mQuad;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ public:
|
|||||||
bool readIntoString(const string & FilePath, string & target);
|
bool readIntoString(const string & FilePath, string & target);
|
||||||
bool openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode = ios_base::out );
|
bool openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode = ios_base::out );
|
||||||
bool Rename(string from, string to);
|
bool Rename(string from, string to);
|
||||||
|
bool Remove(string aFile);
|
||||||
|
|
||||||
//Returns true if strFilename exists somewhere in the fileSystem
|
//Returns true if strFilename exists somewhere in the fileSystem
|
||||||
bool FileExists(const string& strFilename);
|
bool FileExists(const string& strFilename);
|
||||||
@@ -163,4 +164,4 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -44,6 +44,17 @@ typedef WPARAM LocalKeySym;
|
|||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
typedef KeySym LocalKeySym;
|
typedef KeySym LocalKeySym;
|
||||||
#define LOCAL_KEY_NONE XK_VoidSymbol
|
#define LOCAL_KEY_NONE XK_VoidSymbol
|
||||||
|
#undef Status
|
||||||
|
#undef Bool
|
||||||
|
#undef None
|
||||||
|
#undef CursorShape
|
||||||
|
#undef KeyPress
|
||||||
|
#undef KeyRelease
|
||||||
|
#undef FocusIn
|
||||||
|
#undef FocusOut
|
||||||
|
#undef FontChange
|
||||||
|
#undef Unsorted
|
||||||
|
#undef GrayScale
|
||||||
|
|
||||||
#elif defined(ANDROID) // This is temporary until we understand how to send real key events from Java
|
#elif defined(ANDROID) // This is temporary until we understand how to send real key events from Java
|
||||||
typedef long unsigned int LocalKeySym;
|
typedef long unsigned int LocalKeySym;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
virtual bool ButtonPressed(); // action button pressed, return false to ignore
|
virtual bool ButtonPressed(); // action button pressed, return false to ignore
|
||||||
|
|
||||||
// Used for mouse support so that the GUI engine can found out which Object was selected
|
// Used for mouse support so that the GUI engine can found out which Object was selected
|
||||||
virtual bool getTopLeft(float& top, float& left)
|
virtual bool getTopLeft(float&, float&)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ public:
|
|||||||
int mCount;
|
int mCount;
|
||||||
|
|
||||||
JGuiController(JGE* jge, int id, JGuiListener* listener);
|
JGuiController(JGE* jge, int id, JGuiListener* listener);
|
||||||
~JGuiController();
|
virtual ~JGuiController();
|
||||||
|
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ private:
|
|||||||
|
|
||||||
float mHeight;
|
float mHeight;
|
||||||
float mScale;
|
float mScale;
|
||||||
|
float mTextureScale;
|
||||||
float mRotation;
|
float mRotation;
|
||||||
float mTracking;
|
float mTracking;
|
||||||
float mSpacing;
|
float mSpacing;
|
||||||
|
|||||||
@@ -13,34 +13,42 @@ class JSocket;
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "Threading.h"
|
#include "Threading.h"
|
||||||
|
|
||||||
typedef void(*processCmd)(istream&, ostream&);
|
typedef void(*processCmd)(void*, stringstream&, stringstream&);
|
||||||
|
|
||||||
class JNetwork {
|
class JNetwork {
|
||||||
private:
|
private:
|
||||||
|
private:
|
||||||
|
boost::thread *mpWorkerThread;
|
||||||
|
struct CommandStruc{
|
||||||
|
void* object;
|
||||||
|
string command;
|
||||||
|
processCmd processCommand;
|
||||||
|
};
|
||||||
|
|
||||||
|
string serverIP;
|
||||||
int connected_to_ap;
|
int connected_to_ap;
|
||||||
JSocket* socket;
|
JSocket* socket;
|
||||||
boost::mutex sendMutex;
|
boost::mutex sendMutex;
|
||||||
boost::mutex receiveMutex;
|
boost::mutex receiveMutex;
|
||||||
stringstream received;
|
stringstream received;
|
||||||
stringstream toSend;
|
stringstream toSend;
|
||||||
static map<string, processCmd> sCommandMap;
|
static map<string, CommandStruc> sCommandMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JNetwork();
|
JNetwork();
|
||||||
~JNetwork();
|
~JNetwork();
|
||||||
string serverIP;
|
void Update();
|
||||||
|
void getServerIp(string& aString);
|
||||||
|
|
||||||
int connect(string serverIP = "");
|
int connect(const string& serverIP = "");
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
bool isServer() { return serverIP == ""; };
|
||||||
static void ThreadProc(void* param);
|
static void ThreadProc(void* param);
|
||||||
#if !defined (WIN32) && !defined (LINUX)
|
#if !defined (WIN32) && !defined (LINUX)
|
||||||
static int connect_to_apctl(int config);
|
static int connect_to_apctl(int config);
|
||||||
#endif
|
#endif
|
||||||
bool sendCommand(string command);
|
bool sendCommand(const string& command, const string& payload = "", const string& suffix = "Request");
|
||||||
static void registerCommand(string command, processCmd processCommand, processCmd processResponse);
|
static void registerCommand(string command, void* object, processCmd processRequest, processCmd processResponse);
|
||||||
|
|
||||||
private:
|
|
||||||
boost::thread *mpWorkerThread;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -578,7 +578,7 @@ private:
|
|||||||
#if (!defined PSP)
|
#if (!defined PSP)
|
||||||
|
|
||||||
GLuint mCurrentTex;
|
GLuint mCurrentTex;
|
||||||
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || (defined WIN32)
|
#if ((defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) || (defined WIN32)) && (!defined CONSOLE_CONFIG)
|
||||||
// MVP matrix
|
// MVP matrix
|
||||||
ESMatrix theMvpMatrix;
|
ESMatrix theMvpMatrix;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "Threading.h"
|
#include "Threading.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#define SERVER_PORT 5001
|
||||||
|
|
||||||
class JSocket{
|
class JSocket{
|
||||||
public:
|
public:
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -19,10 +21,11 @@ public:
|
|||||||
} SOCKET_STATE;
|
} SOCKET_STATE;
|
||||||
|
|
||||||
|
|
||||||
// Server creation
|
|
||||||
JSocket(string ipAddr);
|
|
||||||
// Client creation
|
// Client creation
|
||||||
|
JSocket(string ipAddr);
|
||||||
|
// Server creation
|
||||||
JSocket();
|
JSocket();
|
||||||
|
|
||||||
~JSocket();
|
~JSocket();
|
||||||
|
|
||||||
JSocket* Accept();
|
JSocket* Accept();
|
||||||
@@ -32,6 +35,8 @@ public:
|
|||||||
void Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// socket state
|
||||||
|
SOCKET_STATE state;
|
||||||
// socket creation when server accepts a connection
|
// socket creation when server accepts a connection
|
||||||
JSocket(int fd);
|
JSocket(int fd);
|
||||||
// convert the socket into non-blocking state
|
// convert the socket into non-blocking state
|
||||||
@@ -39,11 +44,9 @@ private:
|
|||||||
// socket handle
|
// socket handle
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SOCKET mfd;
|
SOCKET mfd;
|
||||||
#elif LINUX
|
#elif LINUX || PSP
|
||||||
int mfd;
|
int mfd;
|
||||||
#endif
|
#endif
|
||||||
// socket state
|
|
||||||
SOCKET_STATE state;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,8 +25,7 @@
|
|||||||
#elif defined USE_PHONON
|
#elif defined USE_PHONON
|
||||||
#include <phonon/AudioOutput>
|
#include <phonon/AudioOutput>
|
||||||
#include <phonon/MediaObject>
|
#include <phonon/MediaObject>
|
||||||
#else
|
#elif defined WIN32
|
||||||
#ifdef WIN32
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#define WITH_FMOD
|
#define WITH_FMOD
|
||||||
#elif defined (PSP)
|
#elif defined (PSP)
|
||||||
@@ -43,10 +42,10 @@
|
|||||||
#include "JAudio.h"
|
#include "JAudio.h"
|
||||||
#include "JMP3.h"
|
#include "JMP3.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_FMOD
|
#ifdef WITH_FMOD
|
||||||
#include "../Dependencies/include/fmod.h"
|
#include "../Dependencies/include/fmod.h"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|||||||
@@ -39,10 +39,10 @@
|
|||||||
#define MAX_CHANNEL 128
|
#define MAX_CHANNEL 128
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
JGE_ERR_CANT_OPEN_FILE = -1,
|
JGE_ERR_CANT_OPEN_FILE = -1,
|
||||||
JGE_ERR_PNG = -2,
|
JGE_ERR_PNG = -2,
|
||||||
JGE_ERR_MALLOC_FAILED = -4,
|
JGE_ERR_MALLOC_FAILED = -4,
|
||||||
JGE_ERR_GENERIC = -5,
|
JGE_ERR_GENERIC = -5,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef PSP
|
#ifdef PSP
|
||||||
@@ -75,45 +75,76 @@ enum {
|
|||||||
#define SCREEN_HEIGHT_F 272.0f
|
#define SCREEN_HEIGHT_F 272.0f
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CONSOLE_CONFIG
|
||||||
|
#define DEFAULT_BLEND 0
|
||||||
|
#define BLEND_OPTION_ADD 0
|
||||||
|
#define BLEND_OPTION_BLEND 0
|
||||||
|
#define BLEND_ZERO 0
|
||||||
|
#define BLEND_ONE 0
|
||||||
|
#define BLEND_SRC_COLOR 0
|
||||||
|
#define BLEND_ONE_MINUS_SRC_COLOR 0
|
||||||
|
#define BLEND_SRC_ALPHA 0
|
||||||
|
#define BLEND_ONE_MINUS_SRC_ALPHA 0
|
||||||
|
#define BLEND_DST_ALPHA 0
|
||||||
|
#define BLEND_ONE_MINUS_DST_ALPHA 0
|
||||||
|
#define BLEND_DST_COLOR 0
|
||||||
|
#define BLEND_ONE_MINUS_DST_COLOR 0
|
||||||
|
#define BLEND_SRC_ALPHA_SATURATE 0
|
||||||
|
#define GU_PSM_5551 0
|
||||||
|
#else
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// #define DEFAULT_BLEND BLEND_DEFAULT
|
// #define DEFAULT_BLEND BLEND_DEFAULT
|
||||||
// #define BLEND_OPTION_ADD BLEND_COLORADD
|
// #define BLEND_OPTION_ADD BLEND_COLORADD
|
||||||
// #define BLEND_OPTION_BLEND (BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE)
|
// #define BLEND_OPTION_BLEND (BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE)
|
||||||
#else
|
#else
|
||||||
#define DEFAULT_BLEND GU_TFX_MODULATE
|
#define DEFAULT_BLEND GU_TFX_MODULATE
|
||||||
#define BLEND_OPTION_ADD GU_TFX_ADD
|
#define BLEND_OPTION_ADD GU_TFX_ADD
|
||||||
#define BLEND_OPTION_BLEND GU_TFX_BLEND
|
#define BLEND_OPTION_BLEND GU_TFX_BLEND
|
||||||
#endif
|
#endif
|
||||||
|
#endif // CONSOLE_CONFIG
|
||||||
|
|
||||||
#if (defined WIN32) && (!defined LINUX)
|
#if (defined WIN32) && (!defined LINUX)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(LINUX) || defined(IOS) || defined (ANDROID)
|
#if defined(LINUX) && (!defined WIN32) || defined(IOS) || defined (ANDROID)
|
||||||
typedef uint8_t byte;
|
typedef uint8_t byte;
|
||||||
typedef uint32_t DWORD;
|
typedef uint32_t DWORD;
|
||||||
typedef uint8_t BYTE;
|
typedef uint8_t BYTE;
|
||||||
#ifndef IOS
|
#ifndef IOS
|
||||||
typedef bool BOOL;
|
typedef bool BOOL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef int8_t s8;
|
||||||
|
typedef int16_t s16;
|
||||||
|
typedef int32_t s32;
|
||||||
|
typedef uint8_t u8;
|
||||||
|
typedef uint16_t u16;
|
||||||
|
typedef uint32_t u32;
|
||||||
|
#define PIXEL_TYPE DWORD
|
||||||
|
#define ARGB(a, r, g, b) ((PIXEL_TYPE)((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
|
||||||
|
#define RGBA(r, g, b, a) ((PIXEL_TYPE)((a) << 24) | ((b) << 16) | ((g) << 8) | (r))
|
||||||
|
#ifndef PSP
|
||||||
|
#define TEXTURE_FORMAT 0
|
||||||
|
#endif //PSP
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CONSOLE_CONFIG
|
||||||
#ifndef QT_CONFIG
|
#ifndef QT_CONFIG
|
||||||
#if defined (IOS)
|
#if defined (IOS)
|
||||||
#import <OpenGLES/ES2/gl.h>
|
#import <OpenGLES/ES2/gl.h>
|
||||||
#import <OpenGLES/ES2/glext.h>
|
#import <OpenGLES/ES2/glext.h>
|
||||||
#import <OpenGLES/ES1/gl.h>
|
#import <OpenGLES/ES1/gl.h>
|
||||||
# import <OpenGLES/ES1/glext.h>
|
#import <OpenGLES/ES1/glext.h>
|
||||||
#elif defined (ANDROID)
|
#elif defined (ANDROID)
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
#elif defined (WIN32) || defined (LINUX)
|
#elif defined (WIN32) || defined (LINUX)
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
# include <QtOpenGL>
|
#include <QtOpenGL>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined FORCE_GLES)
|
#if (defined FORCE_GLES)
|
||||||
@@ -127,152 +158,115 @@ enum {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (PSP)
|
#if defined (PSP)
|
||||||
|
#ifndef ABGR8888
|
||||||
#ifndef ABGR8888
|
#define ABGR8888
|
||||||
#define ABGR8888
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined (ABGR8888)
|
#if defined (ABGR8888)
|
||||||
#define PIXEL_TYPE u32
|
#ifndef ARGB
|
||||||
#ifndef ARGB
|
#define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format
|
||||||
#define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format
|
#endif
|
||||||
#endif
|
#define MAKE_COLOR(a, c) (a << 24 | c)
|
||||||
#define MAKE_COLOR(a, c) (a << 24 | c)
|
#define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels
|
||||||
#define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels
|
#define MASK_BLUE 0x00FF0000
|
||||||
#define MASK_BLUE 0x00FF0000
|
#define MASK_GREEN 0x0000FF00
|
||||||
#define MASK_GREEN 0x0000FF00
|
#define MASK_RED 0x000000FF
|
||||||
#define MASK_RED 0x000000FF
|
|
||||||
|
|
||||||
#define PIXEL_SIZE 4
|
#define PIXEL_SIZE 4
|
||||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888
|
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888
|
||||||
|
|
||||||
#define BUFFER_FORMAT GU_PSM_8888
|
#define BUFFER_FORMAT GU_PSM_8888
|
||||||
#define TEXTURE_FORMAT GU_PSM_8888
|
#define TEXTURE_FORMAT GU_PSM_8888
|
||||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_8888
|
#define TEXTURE_COLOR_FORMAT GU_COLOR_8888
|
||||||
|
|
||||||
|
|
||||||
#elif defined (ABGR5551)
|
#elif defined (ABGR5551)
|
||||||
|
|
||||||
#ifndef ARGB
|
#ifndef ARGB
|
||||||
#define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15))
|
#define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15))
|
||||||
#endif
|
#endif
|
||||||
#define MAKE_COLOR(a, c) (((a>>7)<<15) | c)
|
#define MAKE_COLOR(a, c) (((a>>7)<<15) | c)
|
||||||
#define MASK_ALPHA 0x8000
|
#define MASK_ALPHA 0x8000
|
||||||
#define MASK_BLUE 0x7C00
|
#define MASK_BLUE 0x7C00
|
||||||
#define MASK_GREEN 0x03E0
|
#define MASK_GREEN 0x03E0
|
||||||
#define MASK_RED 0x001F
|
#define MASK_RED 0x001F
|
||||||
#define PIXEL_TYPE u16
|
#define PIXEL_TYPE u16
|
||||||
#define PIXEL_SIZE 2
|
#define PIXEL_SIZE 2
|
||||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551
|
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551
|
||||||
|
|
||||||
#define BUFFER_FORMAT GU_PSM_8888
|
#define BUFFER_FORMAT GU_PSM_8888
|
||||||
#define TEXTURE_FORMAT GU_PSM_5551
|
#define TEXTURE_FORMAT GU_PSM_5551
|
||||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_5551
|
#define TEXTURE_COLOR_FORMAT GU_COLOR_5551
|
||||||
|
|
||||||
#elif defined (ABGR4444)
|
#elif defined (ABGR4444)
|
||||||
#ifndef ARGB
|
#ifndef ARGB
|
||||||
#define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12))
|
#define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12))
|
||||||
#endif
|
#endif
|
||||||
#define MAKE_COLOR(a, c) (((a>>4)<<12) | c)
|
#define MAKE_COLOR(a, c) (((a>>4)<<12) | c)
|
||||||
#define MASK_ALPHA 0xF000
|
#define MASK_ALPHA 0xF000
|
||||||
#define MASK_BLUE 0x0F00
|
#define MASK_BLUE 0x0F00
|
||||||
#define MASK_GREEN 0x00F0
|
#define MASK_GREEN 0x00F0
|
||||||
#define MASK_RED 0x000F
|
#define MASK_RED 0x000F
|
||||||
#define PIXEL_TYPE u16
|
#define PIXEL_TYPE u16
|
||||||
#define PIXEL_SIZE 2
|
#define PIXEL_SIZE 2
|
||||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444
|
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444
|
||||||
|
|
||||||
#define BUFFER_FORMAT GU_PSM_4444
|
#define BUFFER_FORMAT GU_PSM_4444
|
||||||
#define TEXTURE_FORMAT GU_PSM_4444
|
#define TEXTURE_FORMAT GU_PSM_4444
|
||||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_4444
|
#define TEXTURE_COLOR_FORMAT GU_COLOR_4444
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FRAME_BUFFER_WIDTH 512
|
#define FRAME_BUFFER_WIDTH 512
|
||||||
#define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE
|
#define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE
|
||||||
|
|
||||||
#define SLICE_SIZE_F 64.0f
|
#define SLICE_SIZE_F 64.0f
|
||||||
typedef unsigned int DWORD;
|
typedef unsigned int DWORD;
|
||||||
|
|
||||||
#define BLEND_ZERO 0x1000
|
#define BLEND_ZERO 0x1000
|
||||||
#define BLEND_ONE 0x1002
|
#define BLEND_ONE 0x1002
|
||||||
#define BLEND_SRC_COLOR GU_SRC_COLOR
|
#define BLEND_SRC_COLOR GU_SRC_COLOR
|
||||||
#define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR
|
#define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR
|
||||||
#define BLEND_SRC_ALPHA GU_SRC_ALPHA
|
#define BLEND_SRC_ALPHA GU_SRC_ALPHA
|
||||||
#define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA
|
#define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA
|
||||||
#define BLEND_DST_ALPHA GU_DST_ALPHA
|
#define BLEND_DST_ALPHA GU_DST_ALPHA
|
||||||
#define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA
|
#define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA
|
||||||
#define BLEND_DST_COLOR GU_DST_COLOR
|
#define BLEND_DST_COLOR GU_DST_COLOR
|
||||||
#define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR
|
#define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR
|
||||||
#define BLEND_SRC_ALPHA_SATURATE BLEND_ONE
|
#define BLEND_SRC_ALPHA_SATURATE BLEND_ONE
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
ScePspFVector2 texture;
|
ScePspFVector2 texture;
|
||||||
ScePspFVector3 pos;
|
ScePspFVector3 pos;
|
||||||
} PSPVertex3D;
|
} PSPVertex3D;
|
||||||
|
|
||||||
#else //non PSP
|
#else //non PSP
|
||||||
|
|
||||||
typedef int8_t s8;
|
|
||||||
typedef int16_t s16;
|
|
||||||
typedef int32_t s32;
|
|
||||||
typedef uint8_t u8;
|
|
||||||
typedef uint16_t u16;
|
|
||||||
typedef uint32_t u32;
|
|
||||||
|
|
||||||
|
#define BLEND_ZERO GL_ZERO
|
||||||
|
#define BLEND_ONE GL_ONE
|
||||||
|
#define BLEND_SRC_COLOR GL_SRC_COLOR
|
||||||
|
#define BLEND_ONE_MINUS_SRC_COLOR GL_ONE_MINUS_SRC_COLOR
|
||||||
|
#define BLEND_SRC_ALPHA GL_SRC_ALPHA
|
||||||
|
#define BLEND_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
|
||||||
|
#define BLEND_DST_ALPHA GL_DST_ALPHA
|
||||||
|
#define BLEND_ONE_MINUS_DST_ALPHA GL_ONE_MINUS_DST_ALPHA
|
||||||
|
#define BLEND_DST_COLOR GL_DST_COLOR
|
||||||
|
#define BLEND_ONE_MINUS_DST_COLOR GL_ONE_MINUS_DST_COLOR
|
||||||
|
#define BLEND_SRC_ALPHA_SATURATE GL_SRC_ALPHA_SATURATE
|
||||||
|
|
||||||
#define BLEND_ZERO GL_ZERO
|
|
||||||
#define BLEND_ONE GL_ONE
|
|
||||||
#define BLEND_SRC_COLOR GL_SRC_COLOR
|
|
||||||
#define BLEND_ONE_MINUS_SRC_COLOR GL_ONE_MINUS_SRC_COLOR
|
|
||||||
#define BLEND_SRC_ALPHA GL_SRC_ALPHA
|
|
||||||
#define BLEND_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
|
|
||||||
#define BLEND_DST_ALPHA GL_DST_ALPHA
|
|
||||||
#define BLEND_ONE_MINUS_DST_ALPHA GL_ONE_MINUS_DST_ALPHA
|
|
||||||
#define BLEND_DST_COLOR GL_DST_COLOR
|
|
||||||
#define BLEND_ONE_MINUS_DST_COLOR GL_ONE_MINUS_DST_COLOR
|
|
||||||
#define BLEND_SRC_ALPHA_SATURATE GL_SRC_ALPHA_SATURATE
|
|
||||||
|
|
||||||
#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
|
|
||||||
#define RGBA(r, g, b, a) (((a) << 24) | ((b) << 16) | ((g) << 8) | (r))
|
|
||||||
|
|
||||||
#define TEXTURE_FORMAT 0
|
|
||||||
#define GU_PSM_8888 0
|
#define GU_PSM_8888 0
|
||||||
#define GU_PSM_5551 0
|
#define GU_PSM_5551 0
|
||||||
#define GU_PSM_4444 0
|
#define GU_PSM_4444 0
|
||||||
#define GU_PSM_5650 0
|
#define GU_PSM_5650 0
|
||||||
#define PIXEL_TYPE DWORD
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
|
typedef uint32_t GLuint;
|
||||||
|
typedef float GLfloat;
|
||||||
typedef enum Buttons
|
#endif //CONSOLE_CONFIG
|
||||||
{
|
|
||||||
JGE_BTN_NONE = 0, // No button pressed
|
|
||||||
JGE_BTN_QUIT, // Home on PSP
|
|
||||||
JGE_BTN_MENU, // Start on PSP
|
|
||||||
JGE_BTN_CTRL, // Select
|
|
||||||
JGE_BTN_POWER, // Hold
|
|
||||||
JGE_BTN_SOUND, // Music note
|
|
||||||
JGE_BTN_RIGHT,
|
|
||||||
JGE_BTN_LEFT,
|
|
||||||
JGE_BTN_UP,
|
|
||||||
JGE_BTN_DOWN,
|
|
||||||
JGE_BTN_OK, // Circle in Japan, Cross in Europe
|
|
||||||
JGE_BTN_CANCEL, // Triangle
|
|
||||||
JGE_BTN_PRI, // Square (primary)
|
|
||||||
JGE_BTN_SEC, // Cross or Circle (secondary)
|
|
||||||
JGE_BTN_PREV, // Left trigger
|
|
||||||
JGE_BTN_NEXT, // Right trigger
|
|
||||||
JGE_BTN_FULLSCREEN, // Switch to fullscreen (obviously, PC only)
|
|
||||||
|
|
||||||
JGE_BTN_MAX = JGE_BTN_FULLSCREEN + 1
|
|
||||||
} JButton;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
struct Vertex
|
struct Vertex
|
||||||
@@ -357,7 +351,7 @@ public:
|
|||||||
|
|
||||||
int mFilter;
|
int mFilter;
|
||||||
|
|
||||||
#if defined (PSP)
|
#if defined (PSP)
|
||||||
int mTextureFormat;
|
int mTextureFormat;
|
||||||
int mTexId;
|
int mTexId;
|
||||||
bool mInVideoRAM;
|
bool mInVideoRAM;
|
||||||
@@ -542,5 +536,28 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum Buttons
|
||||||
|
{
|
||||||
|
JGE_BTN_NONE = 0, // No button pressed
|
||||||
|
JGE_BTN_QUIT, // Home on PSP
|
||||||
|
JGE_BTN_MENU, // Start on PSP
|
||||||
|
JGE_BTN_CTRL, // Select
|
||||||
|
JGE_BTN_POWER, // Hold
|
||||||
|
JGE_BTN_SOUND, // Music note
|
||||||
|
JGE_BTN_RIGHT,
|
||||||
|
JGE_BTN_LEFT,
|
||||||
|
JGE_BTN_UP,
|
||||||
|
JGE_BTN_DOWN,
|
||||||
|
JGE_BTN_OK, // Circle in Japan, Cross in Europe
|
||||||
|
JGE_BTN_CANCEL, // Triangle
|
||||||
|
JGE_BTN_PRI, // Square (primary)
|
||||||
|
JGE_BTN_SEC, // Cross or Circle (secondary)
|
||||||
|
JGE_BTN_PREV, // Left trigger
|
||||||
|
JGE_BTN_NEXT, // Right trigger
|
||||||
|
JGE_BTN_FULLSCREEN, // Switch to fullscreen (obviously, PC only)
|
||||||
|
|
||||||
|
JGE_BTN_MAX = JGE_BTN_FULLSCREEN + 1
|
||||||
|
} JButton;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
23
JGE/include/OutputCapturer.h
Normal file
23
JGE/include/OutputCapturer.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef OUTPUTCAPTURER_H
|
||||||
|
#define OUTPUTCAPTURER_H
|
||||||
|
|
||||||
|
#if defined(QT_CONFIG)
|
||||||
|
#include <Qt>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include "Threading.h"
|
||||||
|
|
||||||
|
class OutputCapturer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static std::ostringstream stream;
|
||||||
|
static boost::mutex mMutex;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void add(const std::string& s);
|
||||||
|
static void debugAndClear();
|
||||||
|
static void clear();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // OUTPUTCAPTURER_H
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef THREADING_H
|
#ifndef THREADING_H
|
||||||
#define THREADING_H
|
#define THREADING_H
|
||||||
|
|
||||||
#if !defined(PSP) && !defined(QT_CONFIG)
|
#if !defined(PSP) && !defined(QT_CONFIG) && !(__cplusplus > 199711L) && !defined(SDL_CONFIG)
|
||||||
#include <boost/date_time.hpp>
|
#include <boost/date_time.hpp>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#elif !defined(QT_CONFIG)
|
#elif defined(PSP)
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
** PSP specific variant of a boost mutex & scoped_lock
|
** PSP specific variant of a boost mutex & scoped_lock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class Mutex>
|
template <class Mutex>
|
||||||
@@ -60,7 +60,7 @@ namespace boost
|
|||||||
{
|
{
|
||||||
sceKernelDeleteSema(mID);
|
sceKernelDeleteSema(mID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lock()
|
void lock()
|
||||||
{
|
{
|
||||||
int result = sceKernelWaitSema(mID, 1, 0);
|
int result = sceKernelWaitSema(mID, 1, 0);
|
||||||
@@ -142,7 +142,7 @@ namespace boost
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mID;
|
int mID;
|
||||||
int mThreadID;
|
int mThreadID;
|
||||||
volatile int mRecursionCount;
|
volatile int mRecursionCount;
|
||||||
@@ -164,7 +164,7 @@ namespace boost
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Emulating boost::thread configuration glue, with some shortcuts
|
** Emulating boost::thread configuration glue, with some shortcuts
|
||||||
** This detail namespace is a distillation of boost's thread.hpp, thread_data.hpp.
|
** This detail namespace is a distillation of boost's thread.hpp, thread_data.hpp.
|
||||||
*/
|
*/
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -212,13 +212,13 @@ namespace boost
|
|||||||
**
|
**
|
||||||
** The intent of its usage is this form only:
|
** The intent of its usage is this form only:
|
||||||
** mWorkerThread = boost::thread(ThreadProc, this);
|
** mWorkerThread = boost::thread(ThreadProc, this);
|
||||||
** where ThreadProc is a static member function of the 'this' class,eg:
|
** where ThreadProc is a static member function of the 'this' class,eg:
|
||||||
** static void FOO::ThreadProc(void* inParam)
|
** static void FOO::ThreadProc(void* inParam)
|
||||||
** {
|
** {
|
||||||
** FOO* instance = reinterpret_cast<FOO*>(inParam);
|
** FOO* instance = reinterpret_cast<FOO*>(inParam);
|
||||||
** // now you have class instance data available...
|
** // now you have class instance data available...
|
||||||
** }
|
** }
|
||||||
**
|
**
|
||||||
** Any other variant of a thread proc with more than one param is unimplemented.
|
** Any other variant of a thread proc with more than one param is unimplemented.
|
||||||
*/
|
*/
|
||||||
class thread
|
class thread
|
||||||
@@ -227,7 +227,7 @@ namespace boost
|
|||||||
** Helper class for sceKernelStartThread, which passes args by value, not by reference
|
** Helper class for sceKernelStartThread, which passes args by value, not by reference
|
||||||
** We use this struct to wrap any pointers that we want to pass to the worker thread.
|
** We use this struct to wrap any pointers that we want to pass to the worker thread.
|
||||||
*/
|
*/
|
||||||
struct CallbackData
|
struct CallbackData
|
||||||
{
|
{
|
||||||
CallbackData(detail::thread_data_ptr inThreadInfo)
|
CallbackData(detail::thread_data_ptr inThreadInfo)
|
||||||
: mThreadInfo(inThreadInfo)
|
: mThreadInfo(inThreadInfo)
|
||||||
@@ -307,7 +307,7 @@ namespace boost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(QT_CONFIG)
|
#elif defined(QT_CONFIG) && (__cplusplus <= 199711L)
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -315,7 +315,6 @@ namespace boost
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include "../include/DebugRoutines.h"
|
|
||||||
#include "../include/JLogger.h"
|
#include "../include/JLogger.h"
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
@@ -538,6 +537,300 @@ namespace boost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif (__cplusplus > 199711L)
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
typedef std::thread thread;
|
||||||
|
|
||||||
|
template <class Mutex>
|
||||||
|
struct unique_lock
|
||||||
|
{
|
||||||
|
unique_lock(Mutex& inMutex) : mMutex(&inMutex)
|
||||||
|
{
|
||||||
|
mMutex->lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
~unique_lock()
|
||||||
|
{
|
||||||
|
mMutex->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex* mMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
class mutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef unique_lock<mutex> scoped_lock;
|
||||||
|
|
||||||
|
mutex()
|
||||||
|
: mQMutex()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~mutex()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock()
|
||||||
|
{
|
||||||
|
mQMutex.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock()
|
||||||
|
{
|
||||||
|
mQMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mutex mQMutex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutex(mutex const&);
|
||||||
|
mutex& operator=(mutex const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace posix_time
|
||||||
|
{
|
||||||
|
typedef unsigned int milliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
** boost's platform neutral sleep call.
|
||||||
|
*/
|
||||||
|
namespace this_thread
|
||||||
|
{
|
||||||
|
inline void sleep(boost::posix_time::milliseconds const& time)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(time));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(SDL_CONFIG)
|
||||||
|
#include "SDL_thread.h"
|
||||||
|
#include "SDL_timer.h"
|
||||||
|
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include "../include/JLogger.h"
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class Mutex>
|
||||||
|
struct unique_lock
|
||||||
|
{
|
||||||
|
unique_lock(Mutex& inMutex) : mMutex(&inMutex)
|
||||||
|
{
|
||||||
|
mMutex->lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
~unique_lock()
|
||||||
|
{
|
||||||
|
mMutex->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex* mMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
class mutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef unique_lock<mutex> scoped_lock;
|
||||||
|
|
||||||
|
mutex()
|
||||||
|
: mpSDLMutex(0)
|
||||||
|
{
|
||||||
|
mpSDLMutex = SDL_CreateMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
~mutex()
|
||||||
|
{
|
||||||
|
SDL_DestroyMutex(mpSDLMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock()
|
||||||
|
{
|
||||||
|
SDL_mutexP(mpSDLMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock()
|
||||||
|
{
|
||||||
|
SDL_mutexV(mpSDLMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_mutex* mpSDLMutex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutex(mutex const&);
|
||||||
|
mutex& operator=(mutex const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class recursive_mutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef unique_lock<recursive_mutex> scoped_lock;
|
||||||
|
|
||||||
|
recursive_mutex()
|
||||||
|
: mpSDLMutex(0)
|
||||||
|
{
|
||||||
|
mpSDLMutex = SDL_CreateMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
~recursive_mutex()
|
||||||
|
{
|
||||||
|
SDL_DestroyMutex(mpSDLMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock()
|
||||||
|
{
|
||||||
|
SDL_mutexP(mpSDLMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock()
|
||||||
|
{
|
||||||
|
SDL_mutexV(mpSDLMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_mutex* mpSDLMutex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
recursive_mutex(recursive_mutex const&);
|
||||||
|
recursive_mutex& operator=(recursive_mutex const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
** Emulating boost::thread configuration glue, with some shortcuts
|
||||||
|
** This detail namespace is a distillation of boost's thread.hpp, thread_data.hpp.
|
||||||
|
*/
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
struct thread_data_base
|
||||||
|
{
|
||||||
|
thread_data_base()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~thread_data_base()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void run() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::shared_ptr<detail::thread_data_base> thread_data_ptr;
|
||||||
|
|
||||||
|
template<typename F>
|
||||||
|
class thread_data : public detail::thread_data_base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
thread_data(F f_) : f(f_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
F f;
|
||||||
|
|
||||||
|
void operator=(thread_data&);
|
||||||
|
thread_data(thread_data&);
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace detail
|
||||||
|
|
||||||
|
/**
|
||||||
|
** A simplistic implementation of boost::thread, using QThread.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
class thread
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
** Helper class for sceKernelStartThread, which passes args by value, not by reference
|
||||||
|
** We use this struct to wrap any pointers that we want to pass to the worker thread.
|
||||||
|
*/
|
||||||
|
struct CallbackData
|
||||||
|
{
|
||||||
|
CallbackData(detail::thread_data_ptr inThreadInfo)
|
||||||
|
: mThreadInfo(inThreadInfo)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
detail::thread_data_ptr mThreadInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
thread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class F,class A1>
|
||||||
|
thread(F f, A1 a1) : mThreadInfo(make_thread_info(boost::bind(boost::type<void>(), f, a1)))
|
||||||
|
{
|
||||||
|
mpSDLThread = SDL_CreateThread(ThreadProc, &mThreadInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
~thread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void join()
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
SDL_WaitThread(mpSDLThread, &status);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static int ThreadProc(void *inParam)
|
||||||
|
{
|
||||||
|
detail::thread_data_ptr* threadInfo = reinterpret_cast<detail::thread_data_ptr* >(inParam);
|
||||||
|
CallbackData callbackData(*threadInfo);
|
||||||
|
|
||||||
|
LOG("Entering thread::ThreadProc");
|
||||||
|
callbackData.mThreadInfo->run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename F>
|
||||||
|
static inline detail::thread_data_ptr make_thread_info(F f)
|
||||||
|
{
|
||||||
|
return detail::thread_data_ptr(new detail::thread_data<F>(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
detail::thread_data_ptr mThreadInfo;
|
||||||
|
SDL_Thread* mpSDLThread;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace posix_time
|
||||||
|
{
|
||||||
|
typedef unsigned int milliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
** boost's platform neutral sleep call.
|
||||||
|
*/
|
||||||
|
namespace this_thread
|
||||||
|
{
|
||||||
|
inline void sleep(boost::posix_time::milliseconds const& time)
|
||||||
|
{
|
||||||
|
SDL_Delay(time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // THREADING_H
|
#endif // THREADING_H
|
||||||
|
|||||||
@@ -3,15 +3,6 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
/*************************** Macros and constants ***************************/
|
|
||||||
// returns a number ranging from -1.0 to 1.0
|
|
||||||
#define FRAND (((float)rand()-(float)rand())/RAND_MAX)
|
|
||||||
#define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
|
|
||||||
|
|
||||||
#define SQUARE(x) (x)*(x)
|
|
||||||
|
|
||||||
|
|
||||||
struct Vector3D
|
struct Vector3D
|
||||||
{
|
{
|
||||||
Vector3D(float x, float y, float z) : x(x), y(y), z(z) {}
|
Vector3D(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||||
@@ -63,7 +54,7 @@ struct Vector3D
|
|||||||
|
|
||||||
float Length()
|
float Length()
|
||||||
{
|
{
|
||||||
float length = (float)sqrt(SQUARE(x) + SQUARE(y) + SQUARE(z));
|
float length = sqrt(x*x + y*y + z*z);
|
||||||
return (length != 0.0f) ? length : 1.0f;
|
return (length != 0.0f) ? length : 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,19 @@
|
|||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#endif //Q_WS_MAEMO_5
|
#endif //Q_WS_MAEMO_5
|
||||||
|
|
||||||
|
class WagicWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WagicWrapper();
|
||||||
|
virtual ~WagicWrapper();
|
||||||
|
|
||||||
|
private:
|
||||||
|
JGE* m_engine;
|
||||||
|
JApp* m_app;
|
||||||
|
JGameLauncher* m_launcher;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef QT_WIDGET
|
#ifdef QT_WIDGET
|
||||||
class WagicCore : public QGLWidget
|
class WagicCore : public QGLWidget
|
||||||
#else
|
#else
|
||||||
@@ -35,6 +48,7 @@ private:
|
|||||||
#else
|
#else
|
||||||
typedef QDeclarativeItem super;
|
typedef QDeclarativeItem super;
|
||||||
#endif //QT_WIDGET
|
#endif //QT_WIDGET
|
||||||
|
void initApp();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -47,7 +61,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
explicit WagicCore(super *parent = 0);
|
explicit WagicCore(super *parent = 0);
|
||||||
virtual ~WagicCore();
|
virtual ~WagicCore();
|
||||||
void initApp();
|
static int runTestSuite();
|
||||||
|
|
||||||
Q_INVOKABLE void doOK() {
|
Q_INVOKABLE void doOK() {
|
||||||
doAndEnqueue(JGE_BTN_OK);
|
doAndEnqueue(JGE_BTN_OK);
|
||||||
@@ -73,7 +87,7 @@ public:
|
|||||||
Q_INVOKABLE qint64 getTick() {
|
Q_INVOKABLE qint64 getTick() {
|
||||||
return g_startTimer.elapsed();
|
return g_startTimer.elapsed();
|
||||||
};
|
};
|
||||||
Q_INVOKABLE void doScroll(int x, int y, int magnitude) {
|
Q_INVOKABLE void doScroll(int x, int y, int) {
|
||||||
m_engine->Scroll(x, y);
|
m_engine->Scroll(x, y);
|
||||||
};
|
};
|
||||||
int getNominalHeight(){ return SCREEN_HEIGHT;};
|
int getNominalHeight(){ return SCREEN_HEIGHT;};
|
||||||
@@ -122,6 +136,20 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int lastPosx(){
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
return m_lastPos.x()*devicePixelRatio();
|
||||||
|
#else
|
||||||
|
return m_lastPos.x();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
int lastPosy(){
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
return m_lastPos.y()*devicePixelRatio();
|
||||||
|
#else
|
||||||
|
return m_lastPos.y();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
void timerEvent( QTimerEvent* );
|
void timerEvent( QTimerEvent* );
|
||||||
void doAndEnqueue(JButton action) {
|
void doAndEnqueue(JButton action) {
|
||||||
m_engine->HoldKey_NoRepeat(action);
|
m_engine->HoldKey_NoRepeat(action);
|
||||||
@@ -140,6 +168,7 @@ private:
|
|||||||
int m_timerId;
|
int m_timerId;
|
||||||
bool m_active;
|
bool m_active;
|
||||||
QRect m_viewPort;
|
QRect m_viewPort;
|
||||||
|
QPoint m_lastPos;
|
||||||
#ifdef QT_WIDGET
|
#ifdef QT_WIDGET
|
||||||
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||||
int mMouseDownX;
|
int mMouseDownX;
|
||||||
|
|||||||
298
JGE/src/Downloader.cpp
Normal file
298
JGE/src/Downloader.cpp
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
#include "DebugRoutines.h"
|
||||||
|
#include "JFileSystem.h"
|
||||||
|
#include "Downloader.h"
|
||||||
|
|
||||||
|
#define RECORDS_DEFAULT_FILE "cache/records.txt"
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
QNetworkAccessManager DownloadRequest::networkAccessManager;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DownloadRequest::DownloadRequest(string localPath,
|
||||||
|
string remoteResourceURL,
|
||||||
|
string ETag,
|
||||||
|
DownloadStatus downloadStatus,
|
||||||
|
size_t totalSize,
|
||||||
|
size_t currentSize):
|
||||||
|
mLocalPath(localPath),
|
||||||
|
mRemoteResourceURL(remoteResourceURL),
|
||||||
|
mRequestedRemoteResourceURL(remoteResourceURL),
|
||||||
|
mETag(ETag),
|
||||||
|
mDownloadStatus(downloadStatus),
|
||||||
|
mUpgradeAvailable(false),
|
||||||
|
mTotalSize(totalSize),
|
||||||
|
mCurrentSize(currentSize)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadRequest::~DownloadRequest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::startHead()
|
||||||
|
{
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
QNetworkRequest request(QUrl(QString(mRequestedRemoteResourceURL.c_str())));
|
||||||
|
request.setRawHeader("If-None-Match", mETag.c_str());
|
||||||
|
mNetworkReply = networkAccessManager.head(request);
|
||||||
|
connect(mNetworkReply, SIGNAL(finished()), SLOT(fileDownloaded()));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::startGet()
|
||||||
|
{
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
mNetworkReply = networkAccessManager.get(QNetworkRequest(QUrl(QString(mRequestedRemoteResourceURL.c_str()))));
|
||||||
|
#endif
|
||||||
|
mFile.close();
|
||||||
|
JFileSystem::GetInstance()->Remove(getTempLocalPath());
|
||||||
|
JFileSystem::GetInstance()->openForWrite(mFile, getTempLocalPath());
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
connect(mNetworkReply, SIGNAL(downloadProgress(qint64, qint64)),
|
||||||
|
SLOT(downloadProgress(qint64, qint64)));
|
||||||
|
connect(mNetworkReply, SIGNAL(finished()), SLOT(fileDownloaded()));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::fileDownloaded()
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
QByteArray eTagByteArray = mNetworkReply->rawHeader("ETag");
|
||||||
|
if(!eTagByteArray.isEmpty()) {
|
||||||
|
string oldETag = mETag;
|
||||||
|
mETag = QString(eTagByteArray).toStdString();
|
||||||
|
if(oldETag!="" && oldETag != mETag)
|
||||||
|
mUpgradeAvailable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// let's check some error
|
||||||
|
if(mNetworkReply->error() != QNetworkReply::NoError) {
|
||||||
|
DebugTrace(mNetworkReply->errorString().toStdString());
|
||||||
|
mDownloadStatus = DownloadRequest::DOWNLOAD_ERROR;
|
||||||
|
mFile.close();
|
||||||
|
JFileSystem::GetInstance()->Remove(getTempLocalPath());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if we're getting redirected
|
||||||
|
QVariant redirectionTarget = mNetworkReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
|
||||||
|
if (!redirectionTarget.isNull()) {
|
||||||
|
QUrl newUrl = QUrl(mRequestedRemoteResourceURL.c_str()).resolved(redirectionTarget.toUrl());
|
||||||
|
DebugTrace(string("Redirect to ")+ newUrl.toString().toStdString());
|
||||||
|
|
||||||
|
mRequestedRemoteResourceURL = newUrl.toString().toStdString();
|
||||||
|
mNetworkReply->deleteLater();
|
||||||
|
if(mFile.is_open())
|
||||||
|
startGet();
|
||||||
|
else
|
||||||
|
startHead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mFile.is_open())
|
||||||
|
{
|
||||||
|
QByteArray byteArray = mNetworkReply->readAll();
|
||||||
|
mFile.write(byteArray.constData(), byteArray.size());
|
||||||
|
mFile.close();
|
||||||
|
if(!JFileSystem::GetInstance()->Rename(getTempLocalPath(), mLocalPath)) {
|
||||||
|
mDownloadStatus = DownloadRequest::DOWNLOAD_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mDownloadStatus = DownloadRequest::DOWNLOADED;
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
Downloader::GetInstance()->Update();
|
||||||
|
mNetworkReply->deleteLater();
|
||||||
|
|
||||||
|
emit statusChanged((int)mDownloadStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||||
|
{
|
||||||
|
QByteArray byteArray = mNetworkReply->readAll();
|
||||||
|
mFile.write(byteArray.constData(), byteArray.size());
|
||||||
|
mCurrentSize = bytesReceived;
|
||||||
|
mTotalSize = bytesTotal;
|
||||||
|
int percent = 0;
|
||||||
|
if(bytesTotal)
|
||||||
|
percent = (bytesReceived/bytesTotal)*100;
|
||||||
|
emit percentChanged(percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Downloader* Downloader::mInstance = 0;
|
||||||
|
|
||||||
|
Downloader::Downloader(string globalRemoteURL, string localcacheRecords):
|
||||||
|
mGlobalRemoteURL(globalRemoteURL),
|
||||||
|
mLocalCacheRecords(localcacheRecords)
|
||||||
|
{
|
||||||
|
JFileSystem::GetInstance()->MakeDir("cache");
|
||||||
|
|
||||||
|
izfstream downloadRecords;
|
||||||
|
if(mLocalCacheRecords.empty())
|
||||||
|
mLocalCacheRecords = RECORDS_DEFAULT_FILE;
|
||||||
|
if(JFileSystem::GetInstance()->openForRead(downloadRecords, mLocalCacheRecords))
|
||||||
|
{// File exists, let's read it.
|
||||||
|
downloadRecords >> (*this);
|
||||||
|
}
|
||||||
|
JFileSystem::GetInstance()->CloseFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
Downloader::~Downloader()
|
||||||
|
{
|
||||||
|
map<string, DownloadRequest*>::iterator ite;
|
||||||
|
for(ite = mRequestMap.begin(); ite != mRequestMap.end(); ite++)
|
||||||
|
{
|
||||||
|
delete (*ite).second;
|
||||||
|
}
|
||||||
|
mRequestMap.erase(mRequestMap.begin(), mRequestMap.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
Downloader* Downloader::GetInstance()
|
||||||
|
{
|
||||||
|
if(!mInstance)
|
||||||
|
{
|
||||||
|
mInstance = new Downloader();
|
||||||
|
}
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Downloader::Release()
|
||||||
|
{
|
||||||
|
if(mInstance)
|
||||||
|
{
|
||||||
|
delete mInstance;
|
||||||
|
mInstance = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DownloadRequest::NetworkIsAccessible()
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
networkAccessManager.setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||||
|
result = networkAccessManager.networkAccessible();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadRequest* Downloader::Get(string localPath, string remoteResourceURL)
|
||||||
|
{
|
||||||
|
map<string, DownloadRequest*>::iterator ite = mRequestMap.find(localPath);
|
||||||
|
if(ite == mRequestMap.end())
|
||||||
|
{ // request does not exist, let's create it
|
||||||
|
DownloadRequest* request = new DownloadRequest(localPath, remoteResourceURL);
|
||||||
|
std::pair<std::map<string,DownloadRequest*>::iterator,bool> ret;
|
||||||
|
ret = mRequestMap.insert ( std::pair<string,DownloadRequest*>(localPath, request) );
|
||||||
|
if (ret.second==false) {
|
||||||
|
DebugTrace("Downloader::Get Error inserting request in Map");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ite = ret.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, we can check the server
|
||||||
|
if((*ite).second->getDownloadStatus() == DownloadRequest::NOT_PRESENT ||
|
||||||
|
(*ite).second->upgradeAvailable())
|
||||||
|
{ // File is not here or an update is available, let's get it
|
||||||
|
(*ite).second->startGet();
|
||||||
|
(*ite).second->mDownloadStatus = DownloadRequest::DOWNLOADING;
|
||||||
|
}
|
||||||
|
else if ((*ite).second->getDownloadStatus() == DownloadRequest::DOWNLOADED)
|
||||||
|
{ // File is here, let's check if there is some update without blocking the playback
|
||||||
|
(*ite).second->startHead();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (*ite).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Downloader::Update()
|
||||||
|
{
|
||||||
|
ofstream downloadRecords;
|
||||||
|
if(JFileSystem::GetInstance()->openForWrite(downloadRecords, mLocalCacheRecords))
|
||||||
|
{
|
||||||
|
downloadRecords << (*this);
|
||||||
|
}
|
||||||
|
downloadRecords.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, const DownloadRequest& d)
|
||||||
|
{
|
||||||
|
// HEAD request fails, so this line erase cache record after upgrade check :(
|
||||||
|
// if(d.getDownloadStatus() == DownloadRequest::DOWNLOADED)
|
||||||
|
{
|
||||||
|
out << "localPath=" << d.mLocalPath << endl;
|
||||||
|
out << "remoteResource=" << d.mRemoteResourceURL << endl;
|
||||||
|
out << "ETag=" << d.mETag << endl;
|
||||||
|
out << "upgradeAvailable=" << d.mUpgradeAvailable <<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
istream& operator>>(istream& in, DownloadRequest& d)
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
|
||||||
|
while(std::getline(in, s))
|
||||||
|
{
|
||||||
|
size_t limiter = s.find("=");
|
||||||
|
string areaS;
|
||||||
|
if (limiter != string::npos)
|
||||||
|
{
|
||||||
|
areaS = s.substr(0, limiter);
|
||||||
|
if (areaS.compare("localPath") == 0)
|
||||||
|
{
|
||||||
|
d.mLocalPath = s.substr(limiter + 1);
|
||||||
|
}
|
||||||
|
else if (areaS.compare("remoteResource") == 0)
|
||||||
|
{
|
||||||
|
d.mRemoteResourceURL = s.substr(limiter + 1);
|
||||||
|
d.mRequestedRemoteResourceURL = d.mRemoteResourceURL;
|
||||||
|
}
|
||||||
|
else if (areaS.compare("ETag") == 0)
|
||||||
|
{
|
||||||
|
d.mETag = s.substr(limiter + 1);
|
||||||
|
d.mDownloadStatus = DownloadRequest::DOWNLOADED;
|
||||||
|
}
|
||||||
|
else if (areaS.compare("upgradeAvailable") == 0)
|
||||||
|
{
|
||||||
|
d.mUpgradeAvailable = (bool)atoi(s.substr(limiter + 1).c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, const Downloader& d)
|
||||||
|
{
|
||||||
|
map<string, DownloadRequest*>::const_iterator ite;
|
||||||
|
for(ite = d.mRequestMap.begin(); ite != d.mRequestMap.end(); ite++)
|
||||||
|
{
|
||||||
|
out << (*(*ite).second) << endl;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
istream& operator>>(istream& in, Downloader& d)
|
||||||
|
{
|
||||||
|
while(!in.eof())
|
||||||
|
{
|
||||||
|
DownloadRequest* downloadRequest = new DownloadRequest();
|
||||||
|
in >> (*downloadRequest);
|
||||||
|
|
||||||
|
if(!downloadRequest->getLocalPath().empty() &&
|
||||||
|
!downloadRequest->getRemoteResource().empty() &&
|
||||||
|
!downloadRequest->getETag().empty()) {
|
||||||
|
d.mRequestMap[downloadRequest->getLocalPath()] = downloadRequest;
|
||||||
|
} else {
|
||||||
|
delete downloadRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ bool JAnimator::Load(const char* scriptFile)
|
|||||||
element = script->ToElement();
|
element = script->ToElement();
|
||||||
printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));
|
printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));
|
||||||
|
|
||||||
const char *type[] =
|
string type[] =
|
||||||
{
|
{
|
||||||
"ANIMATION_TYPE_LOOPING",
|
"ANIMATION_TYPE_LOOPING",
|
||||||
"ANIMATION_TYPE_ONCE_AND_STAY",
|
"ANIMATION_TYPE_ONCE_AND_STAY",
|
||||||
@@ -78,7 +78,7 @@ bool JAnimator::Load(const char* scriptFile)
|
|||||||
|
|
||||||
const char* aniType = element->Attribute("type");
|
const char* aniType = element->Attribute("type");
|
||||||
for (int i=0;i<5;i++)
|
for (int i=0;i<5;i++)
|
||||||
if (strcmp(type[i], aniType)==0)
|
if (type[i] == aniType)
|
||||||
{
|
{
|
||||||
SetAnimationType(i);
|
SetAnimationType(i);
|
||||||
break;
|
break;
|
||||||
@@ -108,7 +108,7 @@ bool JAnimator::Load(const char* scriptFile)
|
|||||||
element = param->ToElement();
|
element = param->ToElement();
|
||||||
if (element != NULL)
|
if (element != NULL)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Value(), "settings")==0)
|
if (element->ValueStr() == "settings")
|
||||||
{
|
{
|
||||||
const char* quadName = element->Attribute("quad");
|
const char* quadName = element->Attribute("quad");
|
||||||
JQuad* quad = mResource->GetQuad(quadName);
|
JQuad* quad = mResource->GetQuad(quadName);
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ User folder is the only one that is really needed to guarantee both read and wri
|
|||||||
The content that users should not be touching.
|
The content that users should not be touching.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(ANDROID)
|
#ifndef PSP
|
||||||
#include "../../include/PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
#endif
|
#endif //PSP
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#pragma warning(disable : 4786)
|
#pragma warning(disable : 4786)
|
||||||
@@ -34,6 +34,10 @@ The content that users should not be touching.
|
|||||||
#include "../include/JLogger.h"
|
#include "../include/JLogger.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
#include <QDir>
|
||||||
|
#endif
|
||||||
|
|
||||||
JFileSystem* JFileSystem::mInstance = NULL;
|
JFileSystem* JFileSystem::mInstance = NULL;
|
||||||
|
|
||||||
JZipCache::JZipCache()
|
JZipCache::JZipCache()
|
||||||
@@ -121,11 +125,18 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
|
|||||||
|
|
||||||
DebugTrace("User path " << userPath);
|
DebugTrace("User path " << userPath);
|
||||||
#elif defined (QT_CONFIG)
|
#elif defined (QT_CONFIG)
|
||||||
|
|
||||||
|
QDir sysDir(RESDIR);
|
||||||
QDir dir(QDir::homePath());
|
QDir dir(QDir::homePath());
|
||||||
|
dir.mkdir(USERDIR);
|
||||||
dir.cd(USERDIR);
|
dir.cd(USERDIR);
|
||||||
|
|
||||||
userPath = QDir::toNativeSeparators(dir.absolutePath()).toStdString();
|
userPath = QDir::toNativeSeparators(dir.absolutePath()).toStdString();
|
||||||
systemPath = "";
|
systemPath = QDir::toNativeSeparators(sysDir.absolutePath()).toStdString();
|
||||||
|
|
||||||
|
DebugTrace("User path " << userPath);
|
||||||
|
DebugTrace("System path " << systemPath);
|
||||||
|
DebugTrace("Current path " << QDir::currentPath().toStdString());
|
||||||
#else
|
#else
|
||||||
//Find the Res.txt file and matching Res folders for backwards compatibility
|
//Find the Res.txt file and matching Res folders for backwards compatibility
|
||||||
ifstream mfile("Res.txt");
|
ifstream mfile("Res.txt");
|
||||||
@@ -302,11 +313,15 @@ bool JFileSystem::readIntoString(const string & FilePath, string & target)
|
|||||||
|
|
||||||
int fileSize = GetFileSize(file);
|
int fileSize = GetFileSize(file);
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
try {
|
try {
|
||||||
|
#endif
|
||||||
target.resize((std::string::size_type) fileSize);
|
target.resize((std::string::size_type) fileSize);
|
||||||
|
#ifndef __MINGW32__
|
||||||
} catch (bad_alloc&) {
|
} catch (bad_alloc&) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (fileSize)
|
if (fileSize)
|
||||||
@@ -320,6 +335,36 @@ bool JFileSystem::openForWrite(ofstream & File, const string & FilePath, ios_bas
|
|||||||
{
|
{
|
||||||
string filename = mUserFSPath;
|
string filename = mUserFSPath;
|
||||||
filename.append(FilePath);
|
filename.append(FilePath);
|
||||||
|
|
||||||
|
#if defined(ANDROID)
|
||||||
|
DebugTrace("ANDROID");
|
||||||
|
std::vector<string> dirs;
|
||||||
|
string path = filename.substr( 0, filename.find_last_of( '/' ) + 1 );
|
||||||
|
|
||||||
|
// put it into list
|
||||||
|
dirs.push_back(path);
|
||||||
|
|
||||||
|
//make list of directories that need to be created
|
||||||
|
do
|
||||||
|
{
|
||||||
|
path = path.substr( 0, path.find_last_of( '/', path.size() - 2 ) + 1 );
|
||||||
|
dirs.push_back(path);
|
||||||
|
|
||||||
|
} while (path.compare(mUserFSPath) != 0);
|
||||||
|
|
||||||
|
// remove mUserFSPath from list
|
||||||
|
dirs.pop_back();
|
||||||
|
|
||||||
|
// create missing directories
|
||||||
|
for (std::vector<string>::reverse_iterator it = dirs.rbegin(); it != dirs.rend(); ++it)
|
||||||
|
{
|
||||||
|
if(!DirExists(*it))
|
||||||
|
{
|
||||||
|
MAKEDIR((*it).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
File.open(filename.c_str(), mode);
|
File.open(filename.c_str(), mode);
|
||||||
|
|
||||||
if (File)
|
if (File)
|
||||||
@@ -512,7 +557,13 @@ bool JFileSystem::Rename(string _from, string _to)
|
|||||||
string from = mUserFSPath + _from;
|
string from = mUserFSPath + _from;
|
||||||
string to = mUserFSPath + _to;
|
string to = mUserFSPath + _to;
|
||||||
std::remove(to.c_str());
|
std::remove(to.c_str());
|
||||||
return rename(from.c_str(), to.c_str()) ? true: false;
|
return (rename(from.c_str(), to.c_str()) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JFileSystem::Remove(string aFile)
|
||||||
|
{
|
||||||
|
string toRemove = mUserFSPath + aFile;
|
||||||
|
return (std::remove(toRemove.c_str()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int JFileSystem::GetFileSize(izfstream & file)
|
int JFileSystem::GetFileSize(izfstream & file)
|
||||||
|
|||||||
@@ -591,6 +591,8 @@ void JGE::SendCommand(string command)
|
|||||||
sendJNICommand(command);
|
sendJNICommand(command);
|
||||||
#elif defined (IOS)
|
#elif defined (IOS)
|
||||||
SendCommand(command, "");
|
SendCommand(command, "");
|
||||||
|
#else
|
||||||
|
cerr << command;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,6 +604,8 @@ void JGE::SendCommand(std::string command, std::string parameter)
|
|||||||
[delegate handleWEngineCommand:[NSString stringWithCString: command.c_str() encoding: NSUTF8StringEncoding]
|
[delegate handleWEngineCommand:[NSString stringWithCString: command.c_str() encoding: NSUTF8StringEncoding]
|
||||||
withParameter: [NSString stringWithCString: parameter.c_str() encoding:NSUTF8StringEncoding]];
|
withParameter: [NSString stringWithCString: parameter.c_str() encoding:NSUTF8StringEncoding]];
|
||||||
|
|
||||||
|
#else
|
||||||
|
cerr << command << " " << parameter;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,6 +617,8 @@ void JGE::SendCommand(std::string command, float& x, float& y, float& width, flo
|
|||||||
#elif IOS
|
#elif IOS
|
||||||
wagicAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
|
wagicAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
|
||||||
[delegate handleWEngineCommand: [NSString stringWithCString: command.c_str() encoding: NSUTF8StringEncoding] withUIParameters: x yCoordinate: y width: width height: height];
|
[delegate handleWEngineCommand: [NSString stringWithCString: command.c_str() encoding: NSUTF8StringEncoding] withUIParameters: x yCoordinate: y width: width height: height];
|
||||||
|
#else
|
||||||
|
cerr << command << " " << x << " " << y << " " << width << " " << height;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -656,7 +662,6 @@ JNIEnv * JGE::getJNIEnv()
|
|||||||
|
|
||||||
string JGE::getFileSystemLocation()
|
string JGE::getFileSystemLocation()
|
||||||
{
|
{
|
||||||
char result[512];
|
|
||||||
JNIEnv * env = getJNIEnv();
|
JNIEnv * env = getJNIEnv();
|
||||||
if (env == NULL)
|
if (env == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
506
JGE/src/JGfx-fake.cpp
Normal file
506
JGE/src/JGfx-fake.cpp
Normal file
@@ -0,0 +1,506 @@
|
|||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
|
#include "../../include/JGE.h"
|
||||||
|
#include "../../include/JRenderer.h"
|
||||||
|
#include "../../include/JResourceManager.h"
|
||||||
|
#include "../../include/JFileSystem.h"
|
||||||
|
#include "../../include/JAssert.h"
|
||||||
|
|
||||||
|
JQuad::JQuad(JTexture *tex, float x, float y, float width, float height)
|
||||||
|
:mTex(tex), mX(x), mY(y), mWidth(width), mHeight(height)
|
||||||
|
{
|
||||||
|
JASSERT(tex != NULL);
|
||||||
|
JRenderer::GetInstance()->TransferTextureToGLContext(*tex);
|
||||||
|
|
||||||
|
mHotSpotX = 0.0f;
|
||||||
|
mHotSpotY = 0.0f;
|
||||||
|
//mBlend = BLEND_DEFAULT;
|
||||||
|
for (int i=0;i<4;i++)
|
||||||
|
mColor[i].color = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
mHFlipped = false;
|
||||||
|
mVFlipped = false;
|
||||||
|
|
||||||
|
SetTextureRect(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JQuad::SetTextureRect(float x, float y, float w, float h)
|
||||||
|
{
|
||||||
|
mX = x;
|
||||||
|
mY = y;
|
||||||
|
mWidth = w;
|
||||||
|
mHeight = h;
|
||||||
|
|
||||||
|
if(mTex)
|
||||||
|
{
|
||||||
|
mTX0 = x/mTex->mTexWidth;
|
||||||
|
mTY0 = y/mTex->mTexHeight;
|
||||||
|
mTX1 = (x+w)/mTex->mTexWidth;
|
||||||
|
mTY1 = (y+h)/mTex->mTexHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JQuad::GetTextureRect(float *x, float *y, float *w, float *h)
|
||||||
|
{
|
||||||
|
*x=mX; *y=mY; *w=mWidth; *h=mHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JQuad::SetColor(PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
for (int i=0;i<4;i++)
|
||||||
|
mColor[i].color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void JQuad::SetHotSpot(float x, float y)
|
||||||
|
{
|
||||||
|
mHotSpotX = x;
|
||||||
|
mHotSpotY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
JTexture::JTexture() : mWidth(0), mHeight(0), mBuffer(NULL)
|
||||||
|
{
|
||||||
|
mTexId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
JTexture::~JTexture()
|
||||||
|
{
|
||||||
|
if (mBuffer)
|
||||||
|
{
|
||||||
|
delete [] mBuffer;
|
||||||
|
mBuffer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JTexture::UpdateBits(int x, int y, int width, int height, PIXEL_TYPE* bits)
|
||||||
|
{
|
||||||
|
JRenderer::GetInstance()->BindTexture(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
JRenderer* JRenderer::mInstance = NULL;
|
||||||
|
bool JRenderer::m3DEnabled = false;
|
||||||
|
|
||||||
|
void JRenderer::Set3DFlag(bool flag) { m3DEnabled = flag; }
|
||||||
|
|
||||||
|
JRenderer* JRenderer::GetInstance()
|
||||||
|
{
|
||||||
|
if (mInstance == NULL)
|
||||||
|
{
|
||||||
|
mInstance = new JRenderer();
|
||||||
|
|
||||||
|
JASSERT(mInstance != NULL);
|
||||||
|
|
||||||
|
mInstance->InitRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::Destroy()
|
||||||
|
{
|
||||||
|
if (mInstance)
|
||||||
|
{
|
||||||
|
mInstance->DestroyRenderer();
|
||||||
|
delete mInstance;
|
||||||
|
mInstance = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JRenderer::JRenderer() : mActualWidth(SCREEN_WIDTH_F), mActualHeight(SCREEN_HEIGHT_F)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JRenderer::~JRenderer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::InitRenderer()
|
||||||
|
{
|
||||||
|
mCurrentTextureFilter = TEX_FILTER_NONE;
|
||||||
|
mImageFilter = NULL;
|
||||||
|
|
||||||
|
mCurrTexBlendSrc = BLEND_SRC_ALPHA;
|
||||||
|
mCurrTexBlendDest = BLEND_ONE_MINUS_SRC_ALPHA;
|
||||||
|
|
||||||
|
// mLineWidth = 1.0f;
|
||||||
|
mCurrentTex = -1;
|
||||||
|
mFOV = 75.0f;
|
||||||
|
|
||||||
|
#ifdef USING_MATH_TABLE
|
||||||
|
for (int i=0;i<360;i++)
|
||||||
|
{
|
||||||
|
mSinTable[i] = sinf(i*DEG2RAD);
|
||||||
|
mCosTable[i] = cosf(i*DEG2RAD);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mCurrentRenderMode = MODE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::DestroyRenderer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::BeginScene()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::EndScene()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::BindTexture(JTexture *tex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::EnableTextureFilter(bool flag)
|
||||||
|
{
|
||||||
|
if (flag)
|
||||||
|
mCurrentTextureFilter = TEX_FILTER_LINEAR;
|
||||||
|
else
|
||||||
|
mCurrentTextureFilter = TEX_FILTER_NEAREST;
|
||||||
|
|
||||||
|
mCurrentTex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap(float *a, float *b)
|
||||||
|
{
|
||||||
|
float n=*a;
|
||||||
|
*a = *b;
|
||||||
|
*b = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::RenderQuad(JQuad* quad, float xo, float yo, float angle, float xScale, float yScale)
|
||||||
|
{
|
||||||
|
//yo = SCREEN_HEIGHT-yo-1;//-(quad->mHeight);
|
||||||
|
float width = quad->mWidth;
|
||||||
|
float height = quad->mHeight;
|
||||||
|
float x = -quad->mHotSpotX;
|
||||||
|
float y = quad->mHotSpotY;
|
||||||
|
|
||||||
|
Vector2D pt[4];
|
||||||
|
pt[3] = Vector2D(x, y);
|
||||||
|
pt[2] = Vector2D(x+width, y);
|
||||||
|
pt[1] = Vector2D(x+width, y-height);
|
||||||
|
pt[0] = Vector2D(x, y-height);
|
||||||
|
|
||||||
|
|
||||||
|
Vector2D uv[4];
|
||||||
|
uv[0] = Vector2D(quad->mTX0, quad->mTY1);
|
||||||
|
uv[1] = Vector2D(quad->mTX1, quad->mTY1);
|
||||||
|
uv[2] = Vector2D(quad->mTX1, quad->mTY0);
|
||||||
|
uv[3] = Vector2D(quad->mTX0, quad->mTY0);
|
||||||
|
|
||||||
|
if (quad->mHFlipped)
|
||||||
|
{
|
||||||
|
Swap(&uv[0].x, &uv[1].x);
|
||||||
|
Swap(&uv[2].x, &uv[3].x);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quad->mVFlipped)
|
||||||
|
{
|
||||||
|
Swap(&uv[0].y, &uv[2].y);
|
||||||
|
Swap(&uv[1].y, &uv[3].y);
|
||||||
|
}
|
||||||
|
|
||||||
|
BindTexture(quad->mTex);
|
||||||
|
|
||||||
|
yo = SCREEN_HEIGHT_F - yo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::RenderQuad(JQuad* quad, VertexColor* pt)
|
||||||
|
{
|
||||||
|
for (int i=0;i<4;i++)
|
||||||
|
{
|
||||||
|
pt[i].y = SCREEN_HEIGHT_F - pt[i].y;
|
||||||
|
quad->mColor[i].color = pt[i].color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2D uv[4];
|
||||||
|
uv[0] = Vector2D(quad->mTX0, quad->mTY1);
|
||||||
|
uv[1] = Vector2D(quad->mTX1, quad->mTY1);
|
||||||
|
uv[2] = Vector2D(quad->mTX1, quad->mTY0);
|
||||||
|
uv[3] = Vector2D(quad->mTX0, quad->mTY0);
|
||||||
|
|
||||||
|
BindTexture(quad->mTex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
y = SCREEN_HEIGHT_F - y - height;
|
||||||
|
|
||||||
|
JColor col;
|
||||||
|
col.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::DrawRect(float x, float y, float width, float height, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
y = SCREEN_HEIGHT_F - y - height;
|
||||||
|
|
||||||
|
JColor col;
|
||||||
|
col.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE* colors)
|
||||||
|
{
|
||||||
|
JColor col[4];
|
||||||
|
for (int i=0;i<4;i++)
|
||||||
|
col[i].color = colors[i];
|
||||||
|
|
||||||
|
FillRect(x, y, width, height, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::FillRect(float x, float y, float width, float height, JColor* colors)
|
||||||
|
{
|
||||||
|
y = SCREEN_HEIGHT_F - y - height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::DrawLine(float x1, float y1, float x2, float y2, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
// glLineWidth (mLineWidth);
|
||||||
|
JColor col;
|
||||||
|
col.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::Plot(float x, float y, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::PlotArray(float *x, float *y, int count, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::ScreenShot(const char* filename __attribute__((unused)))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::TransferTextureToGLContext(JTexture& inTexture)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JTexture* JRenderer::CreateTexture(int width, int height, int mode __attribute__((unused)))
|
||||||
|
{
|
||||||
|
JTexture *tex = new JTexture();
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
JTexture* JRenderer::LoadTexture(const char* filename, int mode, int textureFormat)
|
||||||
|
{
|
||||||
|
JTexture *tex = new JTexture();
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::EnableVSync(bool flag __attribute__((unused)))
|
||||||
|
{
|
||||||
|
// if (flag)
|
||||||
|
// hge->System_SetState(HGE_FPS, 60); // HGEFPS_VSYNC
|
||||||
|
// else
|
||||||
|
// hge->System_SetState(HGE_FPS, HGEFPS_UNLIMITED);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::ClearScreen(PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::SetTexBlend(int src, int dest)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::SetTexBlendSrc(int src)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::SetTexBlendDest(int dest)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::Enable2D()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::Enable3D()
|
||||||
|
{ /* NOT USED
|
||||||
|
if (!m3DEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (mCurrentRenderMode == MODE_3D)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mCurrentRenderMode = MODE_3D;
|
||||||
|
|
||||||
|
glViewport (0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT); // Reset The Current Viewport
|
||||||
|
glMatrixMode (GL_PROJECTION); // Select The Projection Matrix
|
||||||
|
glLoadIdentity (); // Reset The Projection Matrix
|
||||||
|
gluPerspective (mFOV, (GLfloat)SCREEN_WIDTH/(GLfloat)SCREEN_HEIGHT, // Calculate The Aspect Ratio Of The Window
|
||||||
|
0.5f, 1000.0f);
|
||||||
|
glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
|
||||||
|
glLoadIdentity (); // Reset The Modelview Matrix
|
||||||
|
|
||||||
|
glEnable (GL_DEPTH_TEST); */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::SetClip(int, int, int, int)
|
||||||
|
{// NOT USED
|
||||||
|
//glScissor(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::LoadIdentity()
|
||||||
|
{// NOT USED
|
||||||
|
//glLoadIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::Translate(float, float, float)
|
||||||
|
{// NOT USED
|
||||||
|
//glTranslatef(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::RotateX(float)
|
||||||
|
{// NOT USED
|
||||||
|
//glRotatef(angle*RAD2DEG, 1.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::RotateY(float)
|
||||||
|
{// NOT USED
|
||||||
|
//glRotatef(angle*RAD2DEG, 0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::RotateZ(float)
|
||||||
|
{// NOT USED
|
||||||
|
//glRotatef(angle*RAD2DEG, 0.0f, 0.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::PushMatrix()
|
||||||
|
{// NOT USED
|
||||||
|
//glPushMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::PopMatrix()
|
||||||
|
{// NOT USED
|
||||||
|
//glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::RenderTriangles(JTexture* texture, Vertex3D *vertices, int start, int count)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::SetFOV(float fov)
|
||||||
|
{
|
||||||
|
mFOV = fov;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::FillPolygon(float* x, float* y, int count, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::DrawPolygon(float* x, float* y, int count, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::DrawLine(float x1, float y1, float x2, float y2, float lineWidth, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
float dy=y2-y1;
|
||||||
|
float dx=x2-x1;
|
||||||
|
if(dy==0 && dx==0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float l=(float)hypot(dx,dy);
|
||||||
|
|
||||||
|
float x[4];
|
||||||
|
float y[4];
|
||||||
|
|
||||||
|
x[0]=x1+lineWidth*(y2-y1)/l;
|
||||||
|
y[0]=y1-lineWidth*(x2-x1)/l;
|
||||||
|
|
||||||
|
x[1]=x1-lineWidth*(y2-y1)/l;
|
||||||
|
y[1]=y1+lineWidth*(x2-x1)/l;
|
||||||
|
|
||||||
|
x[2]=x2-lineWidth*(y2-y1)/l;
|
||||||
|
y[2]=y2+lineWidth*(x2-x1)/l;
|
||||||
|
|
||||||
|
x[3]=x2+lineWidth*(y2-y1)/l;
|
||||||
|
y[3]=y2-lineWidth*(x2-x1)/l;
|
||||||
|
|
||||||
|
FillPolygon(x, y, 4, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::DrawCircle(float x, float y, float radius, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void JRenderer::FillCircle(float x, float y, float radius, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::DrawPolygon(float x, float y, float size, int count, float startingAngle, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::FillPolygon(float x, float y, float size, int count, float startingAngle, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::SetImageFilter(JImageFilter* imageFilter)
|
||||||
|
{
|
||||||
|
mImageFilter = imageFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::DrawRoundRect(float x, float y, float w, float h, float radius, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void JRenderer::FillRoundRect(float x, float y, float w, float h, float radius, PIXEL_TYPE color)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@@ -49,12 +49,13 @@ JLBFont::JLBFont(const char *fontname, int lineheight, bool useVideoRAM)
|
|||||||
|
|
||||||
sprintf(filename, "%s.png", fontname);
|
sprintf(filename, "%s.png", fontname);
|
||||||
mTexture = mRenderer->LoadTexture(filename, useVideoRAM);
|
mTexture = mRenderer->LoadTexture(filename, useVideoRAM);
|
||||||
|
mTextureScale = (float) lineheight/ (mTexture->mHeight/16);
|
||||||
|
|
||||||
if (mTexture == NULL) return;
|
if (mTexture == NULL) return;
|
||||||
|
|
||||||
mHeight = (float) lineheight;
|
mHeight = (float) lineheight;
|
||||||
|
|
||||||
mQuad = new JQuad(mTexture, 0.0f, 0.0f, 16.0f, mHeight);
|
mQuad = new JQuad(mTexture, 0.0f, 0.0f, 16.0f/mTextureScale, mHeight/mTextureScale);
|
||||||
|
|
||||||
float a, b, c;
|
float a, b, c;
|
||||||
|
|
||||||
@@ -158,7 +159,7 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
|||||||
|
|
||||||
index = (*p - 32)+mBase;
|
index = (*p - 32)+mBase;
|
||||||
|
|
||||||
float charWidth = mCharWidth[index];
|
float charWidth = mCharWidth[index]*mTextureScale;
|
||||||
float delta = (charWidth + mTracking) * mScale;
|
float delta = (charWidth + mTracking) * mScale;
|
||||||
float xPos = mXPos[index];
|
float xPos = mXPos[index];
|
||||||
if (leftOffset)
|
if (leftOffset)
|
||||||
@@ -194,8 +195,8 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
|||||||
charWidth = (delta/mScale) - mTracking;
|
charWidth = (delta/mScale) - mTracking;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mQuad->SetTextureRect(xPos, mYPos[index], charWidth , mHeight);
|
mQuad->SetTextureRect(xPos, mYPos[index], charWidth/mTextureScale, mHeight/mTextureScale);
|
||||||
mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale, mScale);
|
mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale*mTextureScale, mScale*mTextureScale);
|
||||||
dx += delta;
|
dx += delta;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
@@ -235,7 +236,7 @@ float JLBFont::GetStringWidth(const char *string) const
|
|||||||
ch = *p - 32;
|
ch = *p - 32;
|
||||||
p++;
|
p++;
|
||||||
if (ch < 0) continue;
|
if (ch < 0) continue;
|
||||||
len += mCharWidth[ch+mBase] + mTracking;
|
len += (mCharWidth[ch+mBase]*mTextureScale) + mTracking;
|
||||||
}
|
}
|
||||||
len -= mTracking;
|
len -= mTracking;
|
||||||
return len*mScale;
|
return len*mScale;
|
||||||
|
|||||||
@@ -257,6 +257,8 @@ void JMD2Model::CalculateNormal(float *p1, float *p2, float *p3)
|
|||||||
#else
|
#else
|
||||||
// FIXME
|
// FIXME
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
|
cerr << p1 << " " << p2 << " " << p3 << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,15 +33,43 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "../include/JSocket.h"
|
#include "../include/JSocket.h"
|
||||||
|
|
||||||
map<string, processCmd> JNetwork::sCommandMap;
|
map<string, JNetwork::CommandStruc> JNetwork::sCommandMap;
|
||||||
|
|
||||||
bool JNetwork::isConnected(){
|
bool JNetwork::isConnected(){
|
||||||
if (connected_to_ap !=1) return false;
|
if (connected_to_ap !=1 || !socket) return false;
|
||||||
return socket->isConnected();
|
return socket->isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JNetwork::getServerIp(string& aString)
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
char ac[80];
|
||||||
|
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) {
|
||||||
|
DebugTrace("Error " << WSAGetLastError() <<
|
||||||
|
" when getting local host name.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DebugTrace( "Host name is " << ac << ".\n");
|
||||||
|
|
||||||
|
struct hostent *phe = gethostbyname(ac);
|
||||||
|
if (phe == 0) {
|
||||||
|
DebugTrace("Yow! Bad host lookup.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; phe->h_addr_list[i] != 0; ++i) {
|
||||||
|
struct in_addr addr;
|
||||||
|
memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr));
|
||||||
|
aString = inet_ntoa(addr);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
aString = "No clue";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JNetwork::JNetwork()
|
JNetwork::JNetwork()
|
||||||
: mpWorkerThread(NULL)
|
: mpWorkerThread(NULL), socket(0)
|
||||||
{
|
{
|
||||||
#if (defined WIN32) || (defined LINUX)
|
#if (defined WIN32) || (defined LINUX)
|
||||||
connected_to_ap = 1;
|
connected_to_ap = 1;
|
||||||
@@ -62,30 +90,68 @@ JNetwork::~JNetwork()
|
|||||||
delete socket;
|
delete socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JNetwork::sendCommand(string xString)
|
bool JNetwork::sendCommand(const string& xString, const string& payload, const string& suffix)
|
||||||
{
|
{
|
||||||
string aString = xString;
|
string aString;
|
||||||
boost::mutex::scoped_lock l(sendMutex);
|
boost::mutex::scoped_lock l(sendMutex);
|
||||||
if(!socket) {
|
if(!socket) {
|
||||||
DebugTrace("sendCommand failed: no sockeet");
|
DebugTrace("sendCommand failed: no socket");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
aString = aString + "Command";
|
aString = xString + suffix;
|
||||||
if(sCommandMap.find(aString) == sCommandMap.end()) {
|
if(sCommandMap.find(aString) == sCommandMap.end()) {
|
||||||
DebugTrace("sendCommand failed: command not registered");
|
DebugTrace("sendCommand failed: command not registered");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
aString = aString + "\n";
|
aString = "<" + aString + ">" + "\n" + payload + "\n" + "<" + aString + "/>";
|
||||||
|
|
||||||
toSend << aString;
|
toSend << aString;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JNetwork::registerCommand(string command, processCmd processCommand, processCmd processResponse)
|
void JNetwork::registerCommand(string command, void* object, processCmd processCommand, processCmd processResponse)
|
||||||
{
|
{
|
||||||
sCommandMap[command + "Command"] = processCommand;
|
CommandStruc struc;
|
||||||
sCommandMap[command + "Response"] = processResponse;
|
struc.object = object;
|
||||||
|
struc.command = command;
|
||||||
|
struc.processCommand = processCommand;
|
||||||
|
|
||||||
|
sCommandMap[command + "Request"] = struc;
|
||||||
|
struc.processCommand = processResponse;
|
||||||
|
sCommandMap[command + "Response"] = struc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JNetwork::Update()
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock r(receiveMutex);
|
||||||
|
// Checking for some command to execute
|
||||||
|
size_t begin_start_tag = received.str().find("<");
|
||||||
|
size_t end_start_tag = received.str().find(">");
|
||||||
|
string command = received.str().substr(begin_start_tag+1, end_start_tag-(begin_start_tag+1));
|
||||||
|
size_t begin_end_tag = received.str().find(command + "/>");
|
||||||
|
size_t end_end_tag = received.str().find("/>");
|
||||||
|
if(begin_start_tag != string::npos && begin_end_tag != string::npos )
|
||||||
|
{
|
||||||
|
map<string, CommandStruc>::iterator ite = sCommandMap.find(command);
|
||||||
|
if(ite != sCommandMap.end())
|
||||||
|
{
|
||||||
|
DebugTrace("begin of command received : " + received.str() );
|
||||||
|
DebugTrace("begin of command toSend : " + toSend.str() );
|
||||||
|
|
||||||
|
processCmd theMethod = (ite)->second.processCommand;
|
||||||
|
stringstream input(received.str().substr(end_start_tag+1, (begin_end_tag-1)-(end_start_tag+1)));
|
||||||
|
stringstream output;
|
||||||
|
theMethod((ite)->second.object, input, output);
|
||||||
|
string aString = received.str().substr(end_end_tag+2, string::npos);
|
||||||
|
received.str(aString);
|
||||||
|
if(output.str().size())
|
||||||
|
sendCommand((ite)->second.command, output.str(), "Response");
|
||||||
|
|
||||||
|
DebugTrace("end of command received : "<< received.str() );
|
||||||
|
DebugTrace("end of command toSend : "<< toSend.str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JNetwork::ThreadProc(void* param)
|
void JNetwork::ThreadProc(void* param)
|
||||||
@@ -105,71 +171,33 @@ void JNetwork::ThreadProc(void* param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(pSocket && pSocket->isConnected()) {
|
while(pSocket && pSocket->isConnected()) {
|
||||||
char buff[1024];
|
char buff[4096];
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock l(pThis->receiveMutex);
|
|
||||||
int len = pSocket->Read(buff, sizeof(buff));
|
int len = pSocket->Read(buff, sizeof(buff));
|
||||||
if(len) {
|
if(len > 0) {
|
||||||
|
boost::mutex::scoped_lock l(pThis->receiveMutex);
|
||||||
DebugTrace("receiving " << len << " bytes : " << buff);
|
DebugTrace("receiving " << len << " bytes : " << buff);
|
||||||
pThis->received << buff;
|
pThis->received.str(pThis->received.str() + buff);
|
||||||
}
|
DebugTrace("received " << pThis->received.str().size() << " bytes : " << pThis->received.str());
|
||||||
// Checking for some command to execute
|
|
||||||
size_t found = pThis->received.str().find("Command");
|
|
||||||
if(found != string::npos)
|
|
||||||
{
|
|
||||||
map<string, processCmd>::iterator ite = sCommandMap.find((pThis->received.str()).substr(0, found) + "Command");
|
|
||||||
if(ite != sCommandMap.end())
|
|
||||||
{
|
|
||||||
DebugTrace("begin of command received : "<< pThis->received.str() );
|
|
||||||
DebugTrace("begin of command toSend : "<< pThis->toSend.str() );
|
|
||||||
|
|
||||||
boost::mutex::scoped_lock l(pThis->sendMutex);
|
|
||||||
pThis->toSend << pThis->received.str().substr(0, found) + "Response ";
|
|
||||||
pThis->received.str("");
|
|
||||||
processCmd theMethod = (ite)->second;
|
|
||||||
theMethod(pThis->received, pThis->toSend);
|
|
||||||
|
|
||||||
DebugTrace("end of command received : "<< pThis->received.str() );
|
|
||||||
DebugTrace("end of command toSend : "<< pThis->toSend.str() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Checking for some response to execute
|
|
||||||
found = pThis->received.str().find("Response");
|
|
||||||
if(found != string::npos)
|
|
||||||
{
|
|
||||||
map<string, processCmd>::iterator ite = sCommandMap.find((pThis->received.str()).substr(0, found) + "Response");
|
|
||||||
if(ite != sCommandMap.end())
|
|
||||||
{
|
|
||||||
DebugTrace("begin of response received : "<< pThis->received.str() );
|
|
||||||
DebugTrace("begin of response toSend : "<< pThis->toSend.str() );
|
|
||||||
|
|
||||||
boost::mutex::scoped_lock l(pThis->sendMutex);
|
|
||||||
string aString;
|
|
||||||
pThis->received >> aString;
|
|
||||||
processCmd theMethod = (ite)->second;
|
|
||||||
theMethod(pThis->received, pThis->toSend);
|
|
||||||
pThis->received.str("");
|
|
||||||
|
|
||||||
DebugTrace("end of response received : "<< pThis->received.str() );
|
|
||||||
DebugTrace("end of response toSend : "<< pThis->toSend.str() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
boost::mutex::scoped_lock l(pThis->sendMutex);
|
boost::mutex::scoped_lock l(pThis->sendMutex);
|
||||||
if(!pThis->toSend.str().empty())
|
if(!pThis->toSend.str().empty())
|
||||||
{
|
{
|
||||||
DebugTrace("sending " << pThis->toSend.str().size() << " bytes : " << pThis->toSend.str());
|
DebugTrace("sending " << pThis->toSend.str().size() << " bytes : " << pThis->toSend.str());
|
||||||
pSocket->Write((char*)pThis->toSend.str().c_str(), pThis->toSend.str().size()+1);
|
pSocket->Write((char*)pThis->toSend.str().c_str(), pThis->toSend.str().size()+1);
|
||||||
pThis->toSend.str("");
|
pThis->toSend.str("");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugTrace("Quitting Thread");
|
DebugTrace("Quitting Thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (WIN32) || defined (LINUX)
|
#if defined (WIN32) || defined (LINUX)
|
||||||
int JNetwork::connect(string ip)
|
int JNetwork::connect(const string& ip)
|
||||||
{
|
{
|
||||||
if (mpWorkerThread) return 0;
|
if (mpWorkerThread) return 0;
|
||||||
serverIP = ip;
|
serverIP = ip;
|
||||||
@@ -179,7 +207,7 @@ int JNetwork::connect(string ip)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int JNetwork::connect(string serverIP){
|
int JNetwork::connect(const string& serverIP){
|
||||||
#ifdef NETWORK_SUPPORT
|
#ifdef NETWORK_SUPPORT
|
||||||
int err;
|
int err;
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ bool JOBJModel::Load(const char *modelName, const char *textureName)
|
|||||||
|
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
while (filePtr < size)
|
while (filePtr < size)
|
||||||
{
|
{
|
||||||
filePtr = ReadLine(tmpLine, buffer, filePtr, size);
|
filePtr = ReadLine(tmpLine, buffer, filePtr, size);
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((tmpLine[0] == '#') || (strlen(tmpLine) < 3))
|
if ((tmpLine[0] == '#') || (strlen(tmpLine) < 3))
|
||||||
{
|
{
|
||||||
@@ -89,19 +89,19 @@ bool JOBJModel::Load(const char *modelName, const char *textureName)
|
|||||||
|
|
||||||
if (count == 4)
|
if (count == 4)
|
||||||
{
|
{
|
||||||
if (strcmp(s1, "vn") == 0)
|
if (string("vn") == s1)
|
||||||
normalList.push_back(vert);
|
normalList.push_back(vert);
|
||||||
else if (strcmp(s1, "vt") == 0)
|
else if (string("vt") == s1)
|
||||||
texList.push_back(vert);
|
texList.push_back(vert);
|
||||||
else if (strcmp(s1, "v") == 0)
|
else if (string("v") == s1)
|
||||||
vertList.push_back(vert);
|
vertList.push_back(vert);
|
||||||
}
|
}
|
||||||
else if (count == 3)
|
else if (count == 3)
|
||||||
{
|
{
|
||||||
if (strcmp(s1, "vt") == 0)
|
if (string("vt") == s1)
|
||||||
texList.push_back(vert);
|
texList.push_back(vert);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (tmpLine[0] == 'f')
|
else if (tmpLine[0] == 'f')
|
||||||
{
|
{
|
||||||
@@ -211,7 +211,7 @@ bool JOBJModel::Load(const char *modelName, const char *textureName)
|
|||||||
if (textureName != NULL)
|
if (textureName != NULL)
|
||||||
mTexture = JRenderer::GetInstance()->LoadTexture(textureName);
|
mTexture = JRenderer::GetInstance()->LoadTexture(textureName);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
// FIELD_COUNT
|
// FIELD_COUNT
|
||||||
// };
|
// };
|
||||||
|
|
||||||
const char* lifeValues[] =
|
const string lifeValues[] =
|
||||||
{
|
{
|
||||||
"speed",
|
"speed",
|
||||||
"size",
|
"size",
|
||||||
@@ -104,7 +104,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
"gravity"
|
"gravity"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* typeNames[] =
|
const string typeNames[] =
|
||||||
{
|
{
|
||||||
"POINT",
|
"POINT",
|
||||||
"AREA",
|
"AREA",
|
||||||
@@ -113,7 +113,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
"CIRCLE"
|
"CIRCLE"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* modeNames[] =
|
const string modeNames[] =
|
||||||
{
|
{
|
||||||
"REPEAT",
|
"REPEAT",
|
||||||
"ONCE",
|
"ONCE",
|
||||||
@@ -149,32 +149,32 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
{
|
{
|
||||||
element = param->ToElement();
|
element = param->ToElement();
|
||||||
|
|
||||||
if (strcmp(element->Attribute("name"), "settings")==0)
|
if (string("settings") == element->Attribute("name"))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (strcmp(element->Attribute("blend"), "NORMAL")==0)
|
if (string("NORMAL") == element->Attribute("blend"))
|
||||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||||
else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0)
|
else if (string("ADDITIVE") == element->Attribute("blend"))
|
||||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
|
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||||
|
|
||||||
for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++)
|
for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Attribute("mode"), modeNames[i])==0)
|
if (modeNames[i] == element->Attribute("mode"))
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mEmitterMode = i;
|
mParticleEmitters[mEmitterCount]->mEmitterMode = i;
|
||||||
#if defined (_DEBUG)
|
#if defined (_DEBUG)
|
||||||
printf("emitter mode:%s\n", modeNames[i]);
|
printf("emitter mode:%s\n", modeNames[i].c_str());
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++)
|
for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Attribute("type"), typeNames[i])==0)
|
if (typeNames[i] == element->Attribute("type"))
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mType = i;
|
mParticleEmitters[mEmitterCount]->mType = i;
|
||||||
#if defined (_DEBUG)
|
#if defined (_DEBUG)
|
||||||
printf("emitter type:%s\n", typeNames[i]);
|
printf("emitter type:%s\n", typeNames[i].c_str());
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "quantity")==0)
|
else if (string("quantity") == element->Attribute("name"))
|
||||||
{
|
{
|
||||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||||
{
|
{
|
||||||
@@ -227,7 +227,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "lifex")==0)
|
else if (string("lifex") == element->Attribute("name"))
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
@@ -236,7 +236,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
mParticleEmitters[mEmitterCount]->mLifeMax= value;
|
mParticleEmitters[mEmitterCount]->mLifeMax= value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "anglex")==0)
|
else if (string("anglex") == element->Attribute("name"))
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
@@ -245,7 +245,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;
|
mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "speedx")==0)
|
else if (string("speedx") == element->Attribute("name"))
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
@@ -254,7 +254,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
mParticleEmitters[mEmitterCount]->mSpeedMax= value;
|
mParticleEmitters[mEmitterCount]->mSpeedMax= value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "sizex")==0)
|
else if (string("sizex") == element->Attribute("name"))
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
@@ -267,7 +267,7 @@ bool JParticleEffect::Load(const char* filename)
|
|||||||
{
|
{
|
||||||
for (int i=0;i<FIELD_COUNT;i++)
|
for (int i=0;i<FIELD_COUNT;i++)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Attribute("name"), lifeValues[i])==0)
|
if (lifeValues[i] == element->Attribute("name"))
|
||||||
{
|
{
|
||||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
#include "../include/JLBFont.h"
|
#include "../include/JLBFont.h"
|
||||||
#include "tinyxml/tinyxml.h"
|
#include "tinyxml/tinyxml.h"
|
||||||
|
|
||||||
#if defined (_DEBUG) && defined (WIN32)
|
#if defined (_DEBUG) && defined (WIN32) && (!defined LINUX)
|
||||||
#include "crtdbg.h"
|
#include "crtdbg.h"
|
||||||
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
||||||
#else
|
#else
|
||||||
@@ -119,11 +119,11 @@ bool JResourceManager::LoadResource(const string& resourceName)
|
|||||||
element = node->ToElement();
|
element = node->ToElement();
|
||||||
if (element != NULL)
|
if (element != NULL)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Value(), "texture")==0)
|
if (element->ValueStr() == "texture")
|
||||||
{
|
{
|
||||||
CreateTexture(element->Attribute("name"));
|
CreateTexture(element->Attribute("name"));
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Value(), "quad")==0)
|
else if (element->ValueStr() == "quad")
|
||||||
{
|
{
|
||||||
string quadName = element->Attribute("name");
|
string quadName = element->Attribute("name");
|
||||||
string textureName = element->Attribute("texture");
|
string textureName = element->Attribute("texture");
|
||||||
@@ -170,7 +170,7 @@ bool JResourceManager::LoadResource(const string& resourceName)
|
|||||||
GetQuad(id)->SetHotSpot(hotspotX, hotspotY);
|
GetQuad(id)->SetHotSpot(hotspotX, hotspotY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Value(), "font")==0)
|
else if (element->ValueStr() == "font")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#if 0
|
|
||||||
// need a complete rewrite to comply to the new interface
|
// need a complete rewrite to comply to the new interface
|
||||||
#ifdef NETWORK_SUPPORT
|
#ifdef NETWORK_SUPPORT
|
||||||
|
|
||||||
@@ -21,23 +20,21 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
|
|
||||||
#include "../include/JSocket.h"
|
#include "../include/JSocket.h"
|
||||||
JSocket * JSocket::mInstance = NULL;
|
|
||||||
|
|
||||||
#define SERVER_PORT 20666
|
JSocket::JSocket(){
|
||||||
|
|
||||||
int JSocket::connected = 0;
|
|
||||||
|
|
||||||
void JSocket::init(){
|
|
||||||
#ifdef NETWORK_SUPPORT
|
#ifdef NETWORK_SUPPORT
|
||||||
sceUtilityLoadNetModule(1);
|
sceUtilityLoadNetModule(1);
|
||||||
sceUtilityLoadNetModule(3);
|
sceUtilityLoadNetModule(3);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
JSocket::JSocket(){
|
JSocket::JSocket(string ipAddr)
|
||||||
init();
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JSocket::JSocket(int fd)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
JSocket::~JSocket(){
|
JSocket::~JSocket(){
|
||||||
@@ -48,7 +45,27 @@ JSocket::~JSocket(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JSocket::Disconnect()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JSocket* JSocket::Accept()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JSocket::Read(char* buff, int size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JSocket::Write(char* buff, int size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
int JSocket::make_socket(uint16_t port)
|
int JSocket::make_socket(uint16_t port)
|
||||||
{
|
{
|
||||||
int sock = -1;
|
int sock = -1;
|
||||||
|
|||||||
22
JGE/src/OutputCapturer.cpp
Normal file
22
JGE/src/OutputCapturer.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "../include/OutputCapturer.h"
|
||||||
|
|
||||||
|
std::ostringstream OutputCapturer::stream;
|
||||||
|
boost::mutex OutputCapturer::mMutex;
|
||||||
|
|
||||||
|
void OutputCapturer::add(const std::string& s)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(mMutex);
|
||||||
|
stream << s << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputCapturer::debugAndClear()
|
||||||
|
{
|
||||||
|
stream.flush();
|
||||||
|
qDebug("%s", stream.str().c_str());
|
||||||
|
stream.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputCapturer::clear()
|
||||||
|
{
|
||||||
|
stream.str("");
|
||||||
|
}
|
||||||
105
JGE/src/Qtconsole.cpp
Normal file
105
JGE/src/Qtconsole.cpp
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
#include "../include/JGE.h"
|
||||||
|
#include "../include/JTypes.h"
|
||||||
|
#include "../include/JApp.h"
|
||||||
|
#include "../include/JFileSystem.h"
|
||||||
|
#include "../include/JRenderer.h"
|
||||||
|
#include "../include/JGameLauncher.h"
|
||||||
|
|
||||||
|
#include "TestSuiteAI.h"
|
||||||
|
#include "GameOptions.h"
|
||||||
|
#include "MTGDeck.h"
|
||||||
|
#include "DebugRoutines.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
|
class WagicWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WagicWrapper();
|
||||||
|
virtual ~WagicWrapper();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// used mainly to mesure the delta between 2 updates
|
||||||
|
static QElapsedTimer g_startTimer;
|
||||||
|
|
||||||
|
private:
|
||||||
|
JGE* m_engine;
|
||||||
|
JApp* m_app;
|
||||||
|
JGameLauncher* m_launcher;
|
||||||
|
};
|
||||||
|
|
||||||
|
QElapsedTimer WagicWrapper::g_startTimer;
|
||||||
|
|
||||||
|
int JGEGetTime()
|
||||||
|
{
|
||||||
|
return (int)WagicWrapper::g_startTimer.elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JGEToggleFullscreen()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JGECreateDefaultBindings()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
WagicWrapper::WagicWrapper()
|
||||||
|
{
|
||||||
|
m_launcher = new JGameLauncher();
|
||||||
|
u32 flags = m_launcher->GetInitFlags();
|
||||||
|
if ((flags&JINIT_FLAG_ENABLE3D)!=0)
|
||||||
|
{
|
||||||
|
JRenderer::Set3DFlag(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
JGECreateDefaultBindings();
|
||||||
|
|
||||||
|
m_engine = JGE::GetInstance();
|
||||||
|
m_app = m_launcher->GetGameApp();
|
||||||
|
m_app->Create();
|
||||||
|
m_engine->SetApp(m_app);
|
||||||
|
JRenderer::GetInstance()->Enable2D();
|
||||||
|
g_startTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
WagicWrapper::~WagicWrapper()
|
||||||
|
{
|
||||||
|
if(m_launcher)
|
||||||
|
{
|
||||||
|
delete m_launcher;
|
||||||
|
m_launcher = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_engine)
|
||||||
|
m_engine->SetApp(NULL);
|
||||||
|
|
||||||
|
if (m_app)
|
||||||
|
{
|
||||||
|
m_app->Destroy();
|
||||||
|
delete m_app;
|
||||||
|
m_app = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
JGE::Destroy();
|
||||||
|
m_engine = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
int result = 0;
|
||||||
|
WagicWrapper* wagicCore = new WagicWrapper();
|
||||||
|
MTGCollection()->loadFolder("sets/primitives/");
|
||||||
|
MTGCollection()->loadFolder("sets/", "_cards.dat");
|
||||||
|
options.reloadProfile();
|
||||||
|
TestSuite testSuite("test/_tests.txt");
|
||||||
|
result = testSuite.run();
|
||||||
|
delete wagicCore;
|
||||||
|
DebugTrace("TestSuite done: failed test: " << result << " out of " << testSuite.nbTests + testSuite.nbAITests << " total");
|
||||||
|
#ifdef CAPTURE_STDERR
|
||||||
|
OutputCapturer::debugAndClear();
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#include <QtOpenGL>
|
#include <QtOpenGL>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QtGui/QApplication>
|
#include <QApplication>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#ifdef QT_WIDGET
|
#ifdef QT_WIDGET
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@@ -9,11 +9,11 @@
|
|||||||
#include <QtDeclarative>
|
#include <QtDeclarative>
|
||||||
#include "qmlapplicationviewer.h"
|
#include "qmlapplicationviewer.h"
|
||||||
#endif //QT_WIDGET
|
#endif //QT_WIDGET
|
||||||
#include "filedownloader.h"
|
#include "Downloader.h"
|
||||||
#include "GameApp.h"
|
#include "GameApp.h"
|
||||||
#include "corewrapper.h"
|
#include "corewrapper.h"
|
||||||
|
|
||||||
QWidget* g_glwidget = NULL;
|
WagicCore* g_glwidget = NULL;
|
||||||
|
|
||||||
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
||||||
{
|
{
|
||||||
@@ -68,11 +68,26 @@ int main(int argc, char* argv[])
|
|||||||
(createApplication(argc, argv));
|
(createApplication(argc, argv));
|
||||||
|
|
||||||
#endif //QT_WIDGET
|
#endif //QT_WIDGET
|
||||||
|
|
||||||
app->setApplicationName(WagicCore::getApplicationName());
|
app->setApplicationName(WagicCore::getApplicationName());
|
||||||
FileDownloader fileDownloader(USERDIR, WAGIC_RESOURCE_NAME);
|
DownloadRequest* downloadRequest = NULL;
|
||||||
|
#ifdef WAGIC_RESOURCE_URL
|
||||||
|
Downloader*downloader = Downloader::GetInstance();
|
||||||
|
downloadRequest = downloader->Get(
|
||||||
|
"core.zip",
|
||||||
|
WAGIC_RESOURCE_URL
|
||||||
|
);
|
||||||
|
#endif
|
||||||
#ifdef QT_WIDGET
|
#ifdef QT_WIDGET
|
||||||
g_glwidget = new WagicCore();
|
g_glwidget = new WagicCore();
|
||||||
g_glwidget->connect(&fileDownloader, SIGNAL(finished(int)), SLOT(start(int)));
|
if(!downloadRequest || downloadRequest->getDownloadStatus() == DownloadRequest::DOWNLOADED)
|
||||||
|
{
|
||||||
|
g_glwidget->start(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_glwidget->connect(downloadRequest, SIGNAL(statusChanged(int)), SLOT(start(int)));
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
qmlRegisterType<WagicCore>("CustomComponents", 1, 0, "WagicCore");
|
qmlRegisterType<WagicCore>("CustomComponents", 1, 0, "WagicCore");
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,20 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume(
|
|||||||
{
|
{
|
||||||
if (!g_engine)
|
if (!g_engine)
|
||||||
return;
|
return;
|
||||||
g_engine->Resume();
|
g_engine->Resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "Wagic_Version.h"
|
||||||
|
extern "C" jstring Java_org_libsdl_app_SDLActivity_getResourceName(
|
||||||
|
JNIEnv* env, jclass cls)
|
||||||
|
{
|
||||||
|
return env->NewStringUTF (WAGIC_RESOURCE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" jstring Java_org_libsdl_app_SDLActivity_getResourceUrl(
|
||||||
|
JNIEnv* env, jclass cls)
|
||||||
|
{
|
||||||
|
return env->NewStringUTF (WAGIC_RESOURCE_URL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -158,46 +159,53 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
|
|||||||
{
|
{
|
||||||
// we should use the native asset manager instead
|
// we should use the native asset manager instead
|
||||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||||
int fd = open(fullpath.c_str(), O_RDONLY);
|
|
||||||
FILE* file = fdopen(fd, "r");
|
|
||||||
off_t start = 0;
|
|
||||||
off_t length;
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
length = ftell(file);
|
|
||||||
SLresult result;
|
|
||||||
|
|
||||||
// configure audio source
|
if(fullpath.compare("") != 0)
|
||||||
SLDataLocator_AndroidFD loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
|
{
|
||||||
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
|
int fd = open(fullpath.c_str(), O_RDONLY);
|
||||||
SLDataSource audioSrc = {&loc_fd, &format_mime};
|
FILE* file = fdopen(fd, "r");
|
||||||
|
off_t start = 0;
|
||||||
|
off_t length;
|
||||||
|
fseek(file, 0, SEEK_END);
|
||||||
|
length = ftell(file);
|
||||||
|
SLresult result;
|
||||||
|
|
||||||
// configure audio sink
|
// configure audio source
|
||||||
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
|
SLDataLocator_AndroidFD loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
|
||||||
SLDataSink audioSnk = {&loc_outmix, NULL};
|
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
|
||||||
|
SLDataSource audioSrc = {&loc_fd, &format_mime};
|
||||||
|
|
||||||
// create audio player
|
// configure audio sink
|
||||||
const SLInterfaceID ids[2] = {SL_IID_SEEK, SL_IID_VOLUME};
|
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
|
||||||
const SLboolean req[2] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
|
SLDataSink audioSnk = {&loc_outmix, NULL};
|
||||||
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &music->playerObject, &audioSrc, &audioSnk,
|
|
||||||
2, ids, req);
|
|
||||||
DebugTrace("result " << result);
|
|
||||||
|
|
||||||
// realize the player
|
// create audio player
|
||||||
result = (*music->playerObject)->Realize(music->playerObject, SL_BOOLEAN_FALSE);
|
const SLInterfaceID ids[2] = {SL_IID_SEEK, SL_IID_VOLUME};
|
||||||
DebugTrace("result " << result);
|
const SLboolean req[2] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
|
||||||
|
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &music->playerObject, &audioSrc, &audioSnk, 2, ids, req);
|
||||||
|
DebugTrace("result " << result);
|
||||||
|
|
||||||
// get the play interface
|
// realize the player
|
||||||
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_PLAY, &music->playInterface);
|
result = (*music->playerObject)->Realize(music->playerObject, SL_BOOLEAN_FALSE);
|
||||||
DebugTrace("result " << result);
|
DebugTrace("result " << result);
|
||||||
|
|
||||||
// get the seek interface
|
// get the play interface
|
||||||
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_SEEK, &music->seekInterface);
|
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_PLAY, &music->playInterface);
|
||||||
DebugTrace("result " << result);
|
DebugTrace("result " << result);
|
||||||
|
|
||||||
// get the volume interface
|
// get the seek interface
|
||||||
//result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_VOLUME, (void *)&music->musicVolumeInterface);
|
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_SEEK, &music->seekInterface);
|
||||||
|
DebugTrace("result " << result);
|
||||||
DebugTrace("result " << result);
|
|
||||||
|
// get the volume interface
|
||||||
|
//result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_VOLUME, (void *)&music->musicVolumeInterface);
|
||||||
|
|
||||||
|
DebugTrace("result " << result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugTrace("Bad path to music file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrentMusic = music;
|
mCurrentMusic = music;
|
||||||
@@ -215,12 +223,10 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
|||||||
//(*music->musicVolumeInterface)->SetVolumeLevel(music->musicVolumeInterface, -1 * mVolume);
|
//(*music->musicVolumeInterface)->SetVolumeLevel(music->musicVolumeInterface, -1 * mVolume);
|
||||||
|
|
||||||
// enable whole file looping
|
// enable whole file looping
|
||||||
result = (*music->seekInterface)->SetLoop(music->seekInterface,
|
result = (*music->seekInterface)->SetLoop(music->seekInterface, looping ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN);
|
||||||
looping?SL_BOOLEAN_TRUE:SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN);
|
|
||||||
assert(SL_RESULT_SUCCESS == result);
|
assert(SL_RESULT_SUCCESS == result);
|
||||||
|
|
||||||
result = (*music->playInterface)->SetPlayState(music->playInterface,
|
result = (*music->playInterface)->SetPlayState(music->playInterface, SL_PLAYSTATE_PLAYING);
|
||||||
SL_PLAYSTATE_PLAYING);
|
|
||||||
assert(SL_RESULT_SUCCESS == result);
|
assert(SL_RESULT_SUCCESS == result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <QuartzCore/QuartzCore.h>
|
#import <QuartzCore/QuartzCore.h>
|
||||||
#import "AdWhirlDelegateProtocol.h"
|
|
||||||
#import "EAGLViewController.h"
|
#import "EAGLViewController.h"
|
||||||
#import "EAGLView.h"
|
#import "EAGLView.h"
|
||||||
#import "ESRenderer.h"
|
#import "ESRenderer.h"
|
||||||
@@ -8,9 +7,8 @@
|
|||||||
// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
|
// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
|
||||||
// The view content is basically an EAGL surface you render your OpenGL scene into.
|
// The view content is basically an EAGL surface you render your OpenGL scene into.
|
||||||
// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
|
// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
|
||||||
@interface EAGLView : UIView<AdWhirlDelegate,UIGestureRecognizerDelegate>
|
@interface EAGLView : UIView<UIGestureRecognizerDelegate>
|
||||||
{
|
{
|
||||||
AdWhirlView *adView;
|
|
||||||
//This is a trick, AdMob uses a viewController to display its Ads, trust me, you'll need this
|
//This is a trick, AdMob uses a viewController to display its Ads, trust me, you'll need this
|
||||||
EAGLViewController *viewController;
|
EAGLViewController *viewController;
|
||||||
|
|
||||||
@@ -27,7 +25,6 @@
|
|||||||
id displayLink;
|
id displayLink;
|
||||||
CGPoint currentLocation;
|
CGPoint currentLocation;
|
||||||
}
|
}
|
||||||
@property (nonatomic, retain) AdWhirlView *adView;
|
|
||||||
@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
|
@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
|
||||||
@property (nonatomic) NSInteger animationFrameInterval;
|
@property (nonatomic) NSInteger animationFrameInterval;
|
||||||
@property (nonatomic, readwrite) CGPoint currentLocation;
|
@property (nonatomic, readwrite) CGPoint currentLocation;
|
||||||
@@ -37,8 +34,6 @@
|
|||||||
- (void)drawView:(id)sender;
|
- (void)drawView:(id)sender;
|
||||||
|
|
||||||
- (void)updateKeyboard: (NSString *) inputString;
|
- (void)updateKeyboard: (NSString *) inputString;
|
||||||
- (void)removeAds;
|
|
||||||
- (void)displayAds;
|
|
||||||
|
|
||||||
- (void)destroyGame;
|
- (void)destroyGame;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "GameApp.h"
|
#include "GameApp.h"
|
||||||
|
|
||||||
#import "AdWhirlView.h"
|
|
||||||
#import "wagicAppDelegate.h"
|
#import "wagicAppDelegate.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -67,15 +66,10 @@ void DestroyGame(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Ad management constants
|
|
||||||
static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPHONE = @"b86aba511597401ca6b41c1626aa3013";
|
|
||||||
static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170c8d268f";
|
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
@implementation EAGLView
|
@implementation EAGLView
|
||||||
|
|
||||||
@synthesize adView;
|
|
||||||
@synthesize animating;
|
@synthesize animating;
|
||||||
@dynamic animationFrameInterval;
|
@dynamic animationFrameInterval;
|
||||||
@synthesize currentLocation;
|
@synthesize currentLocation;
|
||||||
@@ -91,7 +85,6 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
|||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
[renderer release];
|
[renderer release];
|
||||||
[self removeAds];
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,30 +628,6 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//These are the methods for the AdWhirl Delegate, you have to implement them
|
|
||||||
#pragma mark AdWhirlDelegate methods
|
|
||||||
|
|
||||||
- (void)adWhirlWillPresentFullScreenModal {
|
|
||||||
//It's recommended to invoke whatever you're using as a "Pause Menu" so your
|
|
||||||
//game won't keep running while the user is "playing" with the Ad (for example, iAds)
|
|
||||||
[self pauseGame];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)adWhirlDidDismissFullScreenModal {
|
|
||||||
//Once the user closes the Ad he'll want to return to the game and continue where
|
|
||||||
//he left it
|
|
||||||
[self resumeGame];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)adWhirlApplicationKey {
|
|
||||||
if ((UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPad)
|
|
||||||
return _MY_AD_WHIRL_APPLICATION_KEY_IPAD;
|
|
||||||
|
|
||||||
return _MY_AD_WHIRL_APPLICATION_KEY_IPHONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (UIViewController *)viewControllerForPresentingModalView {
|
- (UIViewController *)viewControllerForPresentingModalView {
|
||||||
//Remember that UIViewController we created in the Game.h file? AdMob will use it.
|
//Remember that UIViewController we created in the Game.h file? AdMob will use it.
|
||||||
//If you want to use "return self;" instead, AdMob will cancel the Ad requests.
|
//If you want to use "return self;" instead, AdMob will cancel the Ad requests.
|
||||||
@@ -666,101 +635,5 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
|
|
||||||
[UIView beginAnimations:@"AdWhirlDelegate.adWhirlDidReceiveAd:"
|
|
||||||
context:nil];
|
|
||||||
BOOL isLandscape = UIDeviceOrientationIsLandscape( [UIDevice currentDevice].orientation);
|
|
||||||
[UIView setAnimationDuration:0.7];
|
|
||||||
|
|
||||||
CGSize adSize = [adWhirlView actualAdSize];
|
|
||||||
CGRect newFrame = [adWhirlView frame];
|
|
||||||
CGSize screenSize = [self.window bounds].size;
|
|
||||||
|
|
||||||
newFrame.size = adSize;
|
|
||||||
// ads are 320 x 50
|
|
||||||
newFrame.origin.x = ( (isLandscape ? screenSize.height : screenSize.width) - adSize.width)/ 2;
|
|
||||||
newFrame.origin.y = ( (isLandscape ? screenSize.width : screenSize.height) - 50);
|
|
||||||
|
|
||||||
[adWhirlView setFrame: newFrame];
|
|
||||||
|
|
||||||
[UIView commitAnimations];
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo {
|
|
||||||
//The code to show my own Ad banner again
|
|
||||||
NSLog(@"failed to get an Ad");
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) removeAds {
|
|
||||||
//There's something weird about AdWhirl because setting the adView delegate
|
|
||||||
//to "nil" doesn't stops the Ad requests and also it doesn't remove the adView
|
|
||||||
//from superView; do the following to remove AdWhirl from your scene.
|
|
||||||
//
|
|
||||||
//If adView exists, remove everything
|
|
||||||
if (adView) {
|
|
||||||
//Remove adView from superView
|
|
||||||
[adView removeFromSuperview];
|
|
||||||
//Replace adView's view with "nil"
|
|
||||||
[adView replaceBannerViewWith:nil];
|
|
||||||
//Tell AdWhirl to stop requesting Ads
|
|
||||||
[adView ignoreNewAdRequests];
|
|
||||||
//Set adView delegate to "nil"
|
|
||||||
[adView setDelegate:nil];
|
|
||||||
//Release adView
|
|
||||||
[adView release];
|
|
||||||
//set adView to "nil"
|
|
||||||
adView = nil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-(void) displayAds
|
|
||||||
{
|
|
||||||
BOOL isLandscape = UIDeviceOrientationIsLandscape( [UIDevice currentDevice].orientation);
|
|
||||||
|
|
||||||
//Assign the AdWhirl Delegate to our adView
|
|
||||||
if ( adView != nil )
|
|
||||||
[self removeAds];
|
|
||||||
|
|
||||||
//Let's allocate the viewController (it's the same RootViewController as declared
|
|
||||||
//in our AppDelegate; will be used for the Ads)
|
|
||||||
viewController = [(wagicAppDelegate *)[[UIApplication sharedApplication] delegate] glViewController];
|
|
||||||
|
|
||||||
self.adView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
|
|
||||||
//Set auto-resizing mask
|
|
||||||
self.adView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
|
|
||||||
//This isn't really needed but also it makes no harm. It just retrieves the configuration
|
|
||||||
//from adwhirl.com so it knows what Ad networks to use
|
|
||||||
[adView updateAdWhirlConfig];
|
|
||||||
//Get the actual size for the requested Ad
|
|
||||||
CGSize adSize = [adView actualAdSize];
|
|
||||||
//
|
|
||||||
//Set the position; remember that we are using 4 values (in this order): X, Y, Width, Height
|
|
||||||
//You can comment this line if your game is in portrait mode and you want your Ad on the top
|
|
||||||
//if you want the Ad in other position (portrait or landscape), use the following code,
|
|
||||||
//for this example, the Ad will be positioned in the bottom+center of the screen
|
|
||||||
//(in landscape mode):
|
|
||||||
//Same explanation as the one in the method "adjustAdSize" for the Ad's width
|
|
||||||
int screenWidth = [viewController.parentViewController.view bounds].size.width;
|
|
||||||
float yOffset = [viewController.parentViewController.view bounds].size.height - adSize.height;
|
|
||||||
if ( isLandscape )
|
|
||||||
{
|
|
||||||
screenWidth = [viewController.parentViewController.view bounds].size.height;
|
|
||||||
yOffset = screenWidth - adSize.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.adView.frame = CGRectMake((screenWidth - adSize.width) / 2, yOffset, adSize.width, adSize.height);
|
|
||||||
|
|
||||||
//Trying to keep everything inside the Ad bounds
|
|
||||||
self.adView.clipsToBounds = YES;
|
|
||||||
//Adding the adView (used for our Ads) to our viewController
|
|
||||||
[viewController.view addSubview:adView];
|
|
||||||
//Bring our view to front
|
|
||||||
[viewController.view bringSubviewToFront:adView];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import "AdWhirlDelegateProtocol.h"
|
|
||||||
|
|
||||||
@interface EAGLViewController : UIViewController<UITextFieldDelegate> {
|
@interface EAGLViewController : UIViewController<UITextFieldDelegate> {
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,13 @@
|
|||||||
[inputField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
|
[inputField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
|
||||||
[inputField setAutocorrectionType:UITextAutocorrectionTypeNo];
|
[inputField setAutocorrectionType:UITextAutocorrectionTypeNo];
|
||||||
[inputField setKeyboardType: UIKeyboardTypeNamePhonePad];
|
[inputField setKeyboardType: UIKeyboardTypeNamePhonePad];
|
||||||
|
|
||||||
CGRect frame = [[UIScreen mainScreen] applicationFrame];
|
CGRect frame = [[UIScreen mainScreen] applicationFrame];
|
||||||
eaglView = [[EAGLView alloc] initWithFrame:frame];
|
eaglView = [[EAGLView alloc] initWithFrame:frame];
|
||||||
|
|
||||||
[self setView: eaglView];
|
[self setView: eaglView];
|
||||||
[self.view addSubview: inputField];
|
[self.view addSubview: inputField];
|
||||||
|
|
||||||
[inputField release];
|
[inputField release];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@@ -50,7 +53,7 @@
|
|||||||
|
|
||||||
- (void)viewWillAppear:(BOOL)animated {
|
- (void)viewWillAppear:(BOOL)animated {
|
||||||
NSLog(@"EAGL ViewController - view Will Appear");
|
NSLog(@"EAGL ViewController - view Will Appear");
|
||||||
[self.view resumeGame];
|
[self.view resumeGame];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,14 +78,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated {
|
- (void)viewDidAppear:(BOOL)animated {
|
||||||
|
|
||||||
NSLog(@"EAGL ViewController - view Did Appear");
|
NSLog(@"EAGL ViewController - view Did Appear");
|
||||||
|
|
||||||
UIDeviceOrientation currentDeviceOrientation = [UIDevice currentDevice].orientation;
|
UIDeviceOrientation currentDeviceOrientation = [UIDevice currentDevice].orientation;
|
||||||
UIInterfaceOrientation currentInterfaceOrientation = self.interfaceOrientation;
|
UIInterfaceOrientation currentInterfaceOrientation = self.interfaceOrientation;
|
||||||
|
|
||||||
NSLog(@"Current Interface: %@. Current Device: %@",
|
NSLog(@"Current Interface: %@. Current Device: %@",
|
||||||
[self interfaceOrientationName:currentInterfaceOrientation],
|
[self interfaceOrientationName:currentInterfaceOrientation],
|
||||||
[self deviceOrientationName:currentDeviceOrientation]);
|
[self deviceOrientationName:currentDeviceOrientation]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +94,7 @@
|
|||||||
- (void)didReceiveMemoryWarning {
|
- (void)didReceiveMemoryWarning {
|
||||||
// Releases the view if it doesn't have a superview.
|
// Releases the view if it doesn't have a superview.
|
||||||
[super didReceiveMemoryWarning];
|
[super didReceiveMemoryWarning];
|
||||||
|
|
||||||
// Release any cached data, images, etc. that aren't in use.
|
// Release any cached data, images, etc. that aren't in use.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +106,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - device orientation handlers
|
#pragma mark - device orientation handlers
|
||||||
|
- (NSUInteger)supportedInterfaceOrientations
|
||||||
|
{
|
||||||
|
//I want to support portrait in ABCView at iPhone only.
|
||||||
|
//and support all orientation in other views and iPad.
|
||||||
|
|
||||||
|
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
|
||||||
|
{
|
||||||
|
return UIInterfaceOrientationMaskLandscape;
|
||||||
|
}
|
||||||
|
|
||||||
|
//support all
|
||||||
|
return UIInterfaceOrientationMaskAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-(BOOL)shouldAutorotate {
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||||
// Overriden to allow any orientation.
|
// Overriden to allow any orientation.
|
||||||
@@ -110,23 +132,23 @@
|
|||||||
|
|
||||||
if ( isSmallScreen && UIInterfaceOrientationIsPortrait(interfaceOrientation))
|
if ( isSmallScreen && UIInterfaceOrientationIsPortrait(interfaceOrientation))
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
||||||
[[eaglView adView] rotateToOrientation: toInterfaceOrientation];
|
// [[eaglView adView] rotateToOrientation: toInterfaceOrientation];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark Orientation Information
|
#pragma mark Orientation Information
|
||||||
- (NSString*)interfaceOrientationName:(UIInterfaceOrientation) interfaceOrientation {
|
- (NSString*)interfaceOrientationName:(UIInterfaceOrientation) interfaceOrientation {
|
||||||
|
|
||||||
NSString* result = nil;
|
NSString* result = nil;
|
||||||
|
|
||||||
switch (interfaceOrientation) {
|
switch (interfaceOrientation) {
|
||||||
|
|
||||||
case UIInterfaceOrientationPortrait:
|
case UIInterfaceOrientationPortrait:
|
||||||
result = @"Portrait";
|
result = @"Portrait";
|
||||||
break;
|
break;
|
||||||
@@ -142,16 +164,16 @@
|
|||||||
default:
|
default:
|
||||||
result = @"Unknown Interface Orientation";
|
result = @"Unknown Interface Orientation";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
- (NSString*)deviceOrientationName:(UIDeviceOrientation) deviceOrientation {
|
- (NSString*)deviceOrientationName:(UIDeviceOrientation) deviceOrientation {
|
||||||
|
|
||||||
NSString* result = nil;
|
NSString* result = nil;
|
||||||
|
|
||||||
switch (deviceOrientation) {
|
switch (deviceOrientation) {
|
||||||
|
|
||||||
case UIDeviceOrientationUnknown:
|
case UIDeviceOrientationUnknown:
|
||||||
result = @"Unknown";
|
result = @"Unknown";
|
||||||
break;
|
break;
|
||||||
@@ -176,7 +198,7 @@
|
|||||||
default:
|
default:
|
||||||
result = @"Unknown Device Orientation";
|
result = @"Unknown Device Orientation";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -205,7 +227,7 @@
|
|||||||
[eaglView updateKeyboard: @"CLEAR"];
|
[eaglView updateKeyboard: @"CLEAR"];
|
||||||
else
|
else
|
||||||
[eaglView updateKeyboard: string];
|
[eaglView updateKeyboard: string];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +237,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL) textFieldShouldReturn:(UITextField *)textField
|
- (BOOL) textFieldShouldReturn:(UITextField *)textField
|
||||||
{
|
{
|
||||||
[eaglView updateKeyboard: @"SAVE"];
|
[eaglView updateKeyboard: @"SAVE"];
|
||||||
[textField resignFirstResponder];
|
[textField resignFirstResponder];
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ bool checkFramebufferStatus();
|
|||||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||||
if ( context == nil)
|
if ( context == nil)
|
||||||
context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1];
|
context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1];
|
||||||
|
|
||||||
if (!context || ![EAGLContext setCurrentContext:context])
|
if (!context || ![EAGLContext setCurrentContext:context])
|
||||||
{
|
{
|
||||||
[self release];
|
[self release];
|
||||||
@@ -46,20 +46,29 @@ bool checkFramebufferStatus();
|
|||||||
|
|
||||||
- (void)render
|
- (void)render
|
||||||
{
|
{
|
||||||
// NSLog(@"Renderer - render");
|
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
uint dt;
|
uint dt;
|
||||||
|
|
||||||
// This application only creates a single context which is already set current at this point.
|
// This application only creates a single context which is already set current at this point.
|
||||||
// This call is redundant, but needed if dealing with multiple contexts.
|
// This call is redundant, but needed if dealing with multiple contexts.
|
||||||
[EAGLContext setCurrentContext:context];
|
[EAGLContext setCurrentContext:context];
|
||||||
|
|
||||||
// This application only creates a single default framebuffer which is already bound at this point.
|
// This application only creates a single default framebuffer which is already bound at this point.
|
||||||
// This call is redundant, but needed if dealing with multiple framebuffers.
|
// This call is redundant, but needed if dealing with multiple framebuffers.
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
||||||
|
GLfloat currentRatio = (GLfloat) backingWidth / (GLfloat) backingHeight;
|
||||||
|
|
||||||
if ((GLfloat)backingWidth / (GLfloat)backingHeight < ACTUAL_RATIO)
|
// for retina devices. because of the 568 px, the ratio between height-width skews the
|
||||||
|
// frame a bit
|
||||||
|
|
||||||
|
if ( backingHeight == 568 || backingWidth == 568) {
|
||||||
|
viewPort.left = 0;
|
||||||
|
viewPort.top = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + 22; // account for status bar
|
||||||
|
viewPort.right = backingWidth;
|
||||||
|
viewPort.bottom = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + backingWidth / ACTUAL_RATIO - 22;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (currentRatio < ACTUAL_RATIO)
|
||||||
{
|
{
|
||||||
viewPort.left = 0;
|
viewPort.left = 0;
|
||||||
viewPort.top = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2;
|
viewPort.top = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2;
|
||||||
@@ -73,21 +82,21 @@ bool checkFramebufferStatus();
|
|||||||
viewPort.right = backingHeight * ACTUAL_RATIO;
|
viewPort.right = backingHeight * ACTUAL_RATIO;
|
||||||
viewPort.bottom = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + backingWidth / ACTUAL_RATIO + backingHeight;
|
viewPort.bottom = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + backingWidth / ACTUAL_RATIO + backingHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
glViewport(viewPort.left, viewPort.top, viewPort.right-viewPort.left, viewPort.bottom-viewPort.top);
|
glViewport(viewPort.left, viewPort.top, viewPort.right-viewPort.left, viewPort.bottom-viewPort.top);
|
||||||
|
|
||||||
JRenderer::GetInstance()->SetActualWidth(viewPort.right-viewPort.left);
|
JRenderer::GetInstance()->SetActualWidth(viewPort.right-viewPort.left);
|
||||||
JRenderer::GetInstance()->SetActualHeight(viewPort.bottom-viewPort.top);
|
JRenderer::GetInstance()->SetActualHeight(viewPort.bottom-viewPort.top);
|
||||||
|
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
uint64_t tickCount = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
uint64_t tickCount = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
dt = (tickCount - lastTickCount);
|
dt = (tickCount - lastTickCount);
|
||||||
lastTickCount = tickCount;
|
lastTickCount = tickCount;
|
||||||
|
|
||||||
g_engine->SetDelta((float)dt / 1000.0f);
|
g_engine->SetDelta((float)dt / 1000.0f);
|
||||||
g_engine->Update((float)dt / 1000.0f);
|
g_engine->Update((float)dt / 1000.0f);
|
||||||
|
|
||||||
g_engine->Render();
|
g_engine->Render();
|
||||||
|
|
||||||
// This application only creates a single color renderbuffer which is already bound at this point.
|
// This application only creates a single color renderbuffer which is already bound at this point.
|
||||||
@@ -103,18 +112,18 @@ bool checkFramebufferStatus();
|
|||||||
glDeleteFramebuffers(1, &defaultFramebuffer);
|
glDeleteFramebuffers(1, &defaultFramebuffer);
|
||||||
defaultFramebuffer = 0;
|
defaultFramebuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(colorRenderbuffer) {
|
if(colorRenderbuffer) {
|
||||||
glDeleteRenderbuffers(1, &colorRenderbuffer);
|
glDeleteRenderbuffers(1, &colorRenderbuffer);
|
||||||
colorRenderbuffer = 0;
|
colorRenderbuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenFramebuffers(1, &defaultFramebuffer);
|
glGenFramebuffers(1, &defaultFramebuffer);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
||||||
|
|
||||||
glGenRenderbuffers(1, &colorRenderbuffer);
|
glGenRenderbuffers(1, &colorRenderbuffer);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
|
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
|
||||||
|
|
||||||
// Allocate color buffer backing based on the current layer size
|
// Allocate color buffer backing based on the current layer size
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
|
||||||
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
|
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
|
||||||
@@ -127,41 +136,41 @@ bool checkFramebufferStatus();
|
|||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE); // do not calculate inside of poly's
|
glEnable(GL_CULL_FACE); // do not calculate inside of poly's
|
||||||
glFrontFace(GL_CCW);
|
glFrontFace(GL_CCW);
|
||||||
glEnable (GL_BLEND);
|
glEnable (GL_BLEND);
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
// glEnable(GL_SCISSOR_TEST); // Enable Clipping
|
// glEnable(GL_SCISSOR_TEST); // Enable Clipping
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers)
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers)
|
||||||
glClearDepthf(1.0f); // Depth Buffer Setup
|
glClearDepthf(1.0f); // Depth Buffer Setup
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkFramebufferStatus() {
|
bool checkFramebufferStatus() {
|
||||||
|
|
||||||
GLenum status = (GLenum)glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
GLenum status = (GLenum)glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
|
|
||||||
switch(status) {
|
switch(status) {
|
||||||
|
|
||||||
case GL_FRAMEBUFFER_COMPLETE:
|
case GL_FRAMEBUFFER_COMPLETE:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||||
printf("Framebuffer incomplete,incomplete attachment\n");
|
printf("Framebuffer incomplete,incomplete attachment\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||||
printf("Unsupported framebuffer format\n");
|
printf("Unsupported framebuffer format\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||||
printf("Framebuffer incomplete,missing attachment\n");
|
printf("Framebuffer incomplete,missing attachment\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +196,7 @@ bool checkFramebufferStatus() {
|
|||||||
|
|
||||||
[context release];
|
[context release];
|
||||||
context = nil;
|
context = nil;
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
- (void) updateComplete: (id) notificationMsg
|
- (void) updateComplete: (id) notificationMsg
|
||||||
{
|
{
|
||||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||||
|
|
||||||
[dnc removeObserver: self name: @"coreComplete" object: nil];
|
[dnc removeObserver: self name: @"coreComplete" object: nil];
|
||||||
[dnc removeObserver: self name: @"iosConfigComplete" object: nil];
|
[dnc removeObserver: self name: @"iosConfigComplete" object: nil];
|
||||||
[dnc postNotificationName: @"initializeGame" object: self];
|
[dnc postNotificationName: @"initializeGame" object: self];
|
||||||
@@ -34,12 +34,12 @@
|
|||||||
- (void) downloadResources
|
- (void) downloadResources
|
||||||
{
|
{
|
||||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||||
|
|
||||||
[dnc addObserver:self selector:@selector(initIosUpdate:) name:@"coreComplete" object: nil];
|
[dnc addObserver:self selector:@selector(initIosUpdate:) name:@"coreComplete" object: nil];
|
||||||
|
|
||||||
wagicDownloadController = [[WagicDownloadProgressViewController alloc] init];
|
wagicDownloadController = [[WagicDownloadProgressViewController alloc] init];
|
||||||
[wagicDownloadController performSelectorInBackground: @selector(startDownload:) withObject:@"core"];
|
[wagicDownloadController performSelectorInBackground: @selector(startDownload:) withObject:@"core"];
|
||||||
|
|
||||||
[self.window addSubview: wagicDownloadController.view];
|
[self.window addSubview: wagicDownloadController.view];
|
||||||
[self.window makeKeyWindow];
|
[self.window makeKeyWindow];
|
||||||
|
|
||||||
@@ -51,16 +51,16 @@
|
|||||||
NSString *pathPrefix = nil;
|
NSString *pathPrefix = nil;
|
||||||
if ( pathNamePrefix == nil ) // default to User
|
if ( pathNamePrefix == nil ) // default to User
|
||||||
pathPrefix = @"User";
|
pathPrefix = @"User";
|
||||||
else
|
else
|
||||||
pathPrefix = pathNamePrefix;
|
pathPrefix = pathNamePrefix;
|
||||||
|
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
|
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
NSString *userDocumentsDirectory = [paths objectAtIndex:0];
|
NSString *userDocumentsDirectory = [paths objectAtIndex:0];
|
||||||
NSString *downloadFilePath = [userDocumentsDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@/%@.zip", pathPrefix, folderName]];
|
NSString *downloadFilePath = [userDocumentsDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@/%@.zip", pathPrefix, folderName]];
|
||||||
|
|
||||||
ZipArchive *za = [[ZipArchive alloc] init];
|
ZipArchive *za = [[ZipArchive alloc] init];
|
||||||
if ([za UnzipOpenFile: downloadFilePath])
|
if ([za UnzipOpenFile: downloadFilePath])
|
||||||
{
|
{
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
NSLog(@"An Error occurred while unpacking zip file.");
|
NSLog(@"An Error occurred while unpacking zip file.");
|
||||||
}
|
}
|
||||||
[za UnzipCloseFile];
|
[za UnzipCloseFile];
|
||||||
|
|
||||||
if (ret == YES)
|
if (ret == YES)
|
||||||
{
|
{
|
||||||
// delete the archive
|
// delete the archive
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[za release], za = nil;
|
[za release], za = nil;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -98,15 +98,15 @@
|
|||||||
{
|
{
|
||||||
NSString *pathname = [NSString stringWithFormat: @"%@/%@", path, filename];
|
NSString *pathname = [NSString stringWithFormat: @"%@/%@", path, filename];
|
||||||
[data appendFormat: @"%@\n", pathname];
|
[data appendFormat: @"%@\n", pathname];
|
||||||
|
|
||||||
BOOL isDirectory = [[fileManager attributesOfItemAtPath: pathname error: nil] objectForKey: NSFileType] == NSFileTypeDirectory;
|
BOOL isDirectory = [[fileManager attributesOfItemAtPath: pathname error: nil] objectForKey: NSFileType] == NSFileTypeDirectory;
|
||||||
if (isDirectory)
|
if (isDirectory)
|
||||||
[data appendString: [self getDirContents: pathname]];
|
[data appendString: [self getDirContents: pathname]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *manifestList = [data stringByAppendingFormat: @"\n"];
|
NSString *manifestList = [data stringByAppendingFormat: @"\n"];
|
||||||
[data release];
|
[data release];
|
||||||
|
|
||||||
return manifestList;
|
return manifestList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,37 +114,37 @@
|
|||||||
{
|
{
|
||||||
NSString *manifestFile = [docsPath stringByAppendingPathComponent:@"Manifest"];
|
NSString *manifestFile = [docsPath stringByAppendingPathComponent:@"Manifest"];
|
||||||
[[self getDirContents: docsPath] writeToFile:manifestFile atomically:YES encoding:NSUTF8StringEncoding error: nil];
|
[[self getDirContents: docsPath] writeToFile:manifestFile atomically:YES encoding:NSUTF8StringEncoding error: nil];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
check for any zip files dropped into the documents directory before loading the game.
|
check for any zip files dropped into the documents directory before loading the game.
|
||||||
If so, move the "core" files into the "Res" directory and move all other zip files into the "User" directory.
|
If so, move the "core" files into the "Res" directory and move all other zip files into the "User" directory.
|
||||||
Check for a "core" zip file in the Res directory. If it exists, then return YES. Otherwise, return NO.
|
Check for a "core" zip file in the Res directory. If it exists, then return YES. Otherwise, return NO.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (void) initializeResources
|
- (void) initializeResources
|
||||||
{
|
{
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
NSString *docsPath = [paths objectAtIndex: 0];
|
NSString *docsPath = [paths objectAtIndex: 0];
|
||||||
NSArray *docsPathContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: docsPath error:nil];
|
NSArray *docsPathContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: docsPath error:nil];
|
||||||
NSString *versionPredicate = [NSString stringWithFormat: @"(self BEGINSWITH '%@')", [NSString stringWithCString: WAGIC_CORE_VERSION_STRING encoding:NSUTF8StringEncoding]];
|
NSString *versionPredicate = [NSString stringWithFormat: @"(self BEGINSWITH '%@')", [NSString stringWithCString: WAGIC_CORE_VERSION_STRING encoding:NSUTF8StringEncoding]];
|
||||||
NSCompoundPredicate *compoundPredicate = [[NSCompoundPredicate alloc] initWithType:NSAndPredicateType subpredicates: [NSArray arrayWithObjects: [NSPredicate predicateWithFormat:@"self ENDSWITH '.zip'"], [NSPredicate predicateWithFormat: [NSString stringWithFormat: @" NOT ( %@ ) ", versionPredicate]], nil]];
|
NSCompoundPredicate *compoundPredicate = [[NSCompoundPredicate alloc] initWithType:NSAndPredicateType subpredicates: [NSArray arrayWithObjects: [NSPredicate predicateWithFormat:@"self ENDSWITH '.zip'"], [NSPredicate predicateWithFormat: [NSString stringWithFormat: @" NOT ( %@ ) ", versionPredicate]], nil]];
|
||||||
|
|
||||||
NSArray *coreFiles = [docsPathContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat: versionPredicate]];
|
NSArray *coreFiles = [docsPathContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat: versionPredicate]];
|
||||||
|
|
||||||
NSArray *resourceZipFiles = [docsPathContents filteredArrayUsingPredicate: compoundPredicate];
|
NSArray *resourceZipFiles = [docsPathContents filteredArrayUsingPredicate: compoundPredicate];
|
||||||
NSString *userPath = [NSString stringWithFormat: @"%@/User", docsPath];
|
NSString *userPath = [NSString stringWithFormat: @"%@/User", docsPath];
|
||||||
NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath];
|
NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath];
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
|
|
||||||
[compoundPredicate release], compoundPredicate = nil;
|
[compoundPredicate release], compoundPredicate = nil;
|
||||||
|
|
||||||
if ( ([resourceZipFiles count] > 0 ) && ![fileManager fileExistsAtPath: userPath] )
|
if ( ([resourceZipFiles count] > 0 ) && ![fileManager fileExistsAtPath: userPath] )
|
||||||
[fileManager createDirectoryAtPath: userPath withIntermediateDirectories: YES attributes:nil error:nil ];
|
[fileManager createDirectoryAtPath: userPath withIntermediateDirectories: YES attributes:nil error:nil ];
|
||||||
|
|
||||||
for (NSString *zipFile in resourceZipFiles)
|
for (NSString *zipFile in resourceZipFiles)
|
||||||
{
|
{
|
||||||
NSString *oldPath = [NSString stringWithFormat: @"%@/%@", docsPath, zipFile];
|
NSString *oldPath = [NSString stringWithFormat: @"%@/%@", docsPath, zipFile];
|
||||||
@@ -155,7 +155,7 @@
|
|||||||
[fileManager removeItemAtPath: newPath error: &error];
|
[fileManager removeItemAtPath: newPath error: &error];
|
||||||
}
|
}
|
||||||
error = nil;
|
error = nil;
|
||||||
|
|
||||||
[fileManager moveItemAtPath: oldPath toPath:newPath error: &error];
|
[fileManager moveItemAtPath: oldPath toPath:newPath error: &error];
|
||||||
NSLog(@"Moving %@ to %@", oldPath, newPath);
|
NSLog(@"Moving %@ to %@", oldPath, newPath);
|
||||||
if ( error != nil )
|
if ( error != nil )
|
||||||
@@ -175,7 +175,7 @@
|
|||||||
[fileManager removeItemAtPath: newPath error: &error];
|
[fileManager removeItemAtPath: newPath error: &error];
|
||||||
}
|
}
|
||||||
error = nil;
|
error = nil;
|
||||||
|
|
||||||
[fileManager moveItemAtPath: oldPath toPath:newPath error: &error];
|
[fileManager moveItemAtPath: oldPath toPath:newPath error: &error];
|
||||||
NSLog(@"Moving %@ to %@", oldPath, newPath);
|
NSLog(@"Moving %@ to %@", oldPath, newPath);
|
||||||
if ( error != nil )
|
if ( error != nil )
|
||||||
@@ -187,21 +187,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) hasResourceFiles
|
- (BOOL) hasResourceFiles
|
||||||
{
|
{
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
NSString *docsPath = [paths objectAtIndex: 0];
|
NSString *docsPath = [paths objectAtIndex: 0];
|
||||||
NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath];
|
NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath];
|
||||||
|
|
||||||
NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil];
|
NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil];
|
||||||
NSString *versionPredicate = [NSString stringWithFormat: @"(self BEGINSWITH '%@')", [NSString stringWithCString: WAGIC_CORE_VERSION_STRING encoding:NSUTF8StringEncoding]];
|
NSString *versionPredicate = [NSString stringWithFormat: @"(self BEGINSWITH '%@')", [NSString stringWithCString: WAGIC_CORE_VERSION_STRING encoding:NSUTF8StringEncoding]];
|
||||||
|
|
||||||
NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat: versionPredicate]];
|
NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat: versionPredicate]];
|
||||||
|
|
||||||
if ([coreFiles count] >= 2)
|
if ([coreFiles count] >= 2)
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,30 +211,30 @@
|
|||||||
NSString *docsPath = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0];
|
NSString *docsPath = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0];
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
NSString *userPath = [docsPath stringByAppendingString: @"/User"];
|
NSString *userPath = [docsPath stringByAppendingString: @"/User"];
|
||||||
|
|
||||||
NSArray *userDirectories = [fm contentsOfDirectoryAtPath: userPath error: nil];
|
NSArray *userDirectories = [fm contentsOfDirectoryAtPath: userPath error: nil];
|
||||||
|
|
||||||
for (NSString *userFilename in userDirectories)
|
for (NSString *userFilename in userDirectories)
|
||||||
{
|
{
|
||||||
NSString *userPathname = [userPath stringByAppendingFormat: @"/%@", userFilename];
|
NSString *userPathname = [userPath stringByAppendingFormat: @"/%@", userFilename];
|
||||||
NSString *zipFileName = [userPathname stringByAppendingString: @".zip"];
|
NSString *zipFileName = [userPathname stringByAppendingString: @".zip"];
|
||||||
|
|
||||||
if ([[fm attributesOfItemAtPath: userPathname error: nil] objectForKey: NSFileType] == NSFileTypeDirectory && ([fm fileExistsAtPath:zipFileName]))
|
if ([[fm attributesOfItemAtPath: userPathname error: nil] objectForKey: NSFileType] == NSFileTypeDirectory && ([fm fileExistsAtPath:zipFileName]))
|
||||||
{
|
{
|
||||||
[self unpackageResources: userFilename pathPrefixName: @"User"];
|
[self unpackageResources: userFilename pathPrefixName: @"User"];
|
||||||
[fm removeItemAtPath: zipFileName error: nil];
|
[fm removeItemAtPath: zipFileName error: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( [userFilename hasPrefix: @"ai_decks"] ) // special case to allow manual override of AI decks in User directory
|
else if ( [userFilename hasPrefix: @"ai_decks"] ) // special case to allow manual override of AI decks in User directory
|
||||||
{
|
{
|
||||||
[self unpackageResources: @"ai_decks" pathPrefixName: @"User/ai/baka"];
|
[self unpackageResources: @"ai_decks" pathPrefixName: @"User/ai/baka"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// scan for deck*.txt and collection.dat as well as options.txt in the Documents directory and copy them into the player directory
|
// scan for deck*.txt and collection.dat as well as options.txt in the Documents directory and copy them into the player directory
|
||||||
NSArray *playerDataFilePredicates = [NSArray arrayWithObjects:
|
NSArray *playerDataFilePredicates = [NSArray arrayWithObjects:
|
||||||
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'deck' AND SELF ENDSWITH '.txt'"],
|
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'deck' AND SELF ENDSWITH '.txt'"],
|
||||||
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'options' AND SELF ENDSWITH '.txt'"],
|
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'options' AND SELF ENDSWITH '.txt'"],
|
||||||
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'tasks' AND SELF ENDSWITH '.dat'"],
|
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'tasks' AND SELF ENDSWITH '.dat'"],
|
||||||
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'collection' AND SELF ENDSWITH '.dat'"], nil];
|
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'collection' AND SELF ENDSWITH '.dat'"], nil];
|
||||||
|
|
||||||
NSCompoundPredicate *playerDataPredicate = [[NSCompoundPredicate alloc] initWithType:NSOrPredicateType subpredicates: playerDataFilePredicates];
|
NSCompoundPredicate *playerDataPredicate = [[NSCompoundPredicate alloc] initWithType:NSOrPredicateType subpredicates: playerDataFilePredicates];
|
||||||
@@ -246,23 +246,23 @@
|
|||||||
NSString *toPath = [docsPath stringByAppendingFormat: @"/User/player/%@", [file lowercaseString]];
|
NSString *toPath = [docsPath stringByAppendingFormat: @"/User/player/%@", [file lowercaseString]];
|
||||||
[fm moveItemAtPath: fromPath toPath: toPath error: nil];
|
[fm moveItemAtPath: fromPath toPath: toPath error: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
[playerDataPredicate release], playerDataPredicate = nil;
|
[playerDataPredicate release], playerDataPredicate = nil;
|
||||||
|
|
||||||
[self createManifest: docsPath];
|
[self createManifest: docsPath];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"readyToStartGame" object: nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"readyToStartGame" object: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) startGame
|
- (void) startGame
|
||||||
{
|
{
|
||||||
if (glViewController != nil)
|
if (glViewController != nil)
|
||||||
[glViewController release];
|
[glViewController release];
|
||||||
glViewController = [[EAGLViewController alloc] init];
|
glViewController = [[EAGLViewController alloc] init];
|
||||||
|
|
||||||
[[[self.window subviews] lastObject] removeFromSuperview];
|
[[[self.window subviews] lastObject] removeFromSuperview];
|
||||||
[self.window addSubview:self.glViewController.view];
|
[self.window setRootViewController: glViewController];
|
||||||
|
|
||||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||||
[dnc removeObserver: self name: @"intializeGame" object: nil];
|
[dnc removeObserver: self name: @"intializeGame" object: nil];
|
||||||
@@ -286,7 +286,7 @@
|
|||||||
[internetReach release];
|
[internetReach release];
|
||||||
[glViewController release];
|
[glViewController release];
|
||||||
[wagicDownloadController release];
|
[wagicDownloadController release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,23 +298,23 @@
|
|||||||
hostReach = [[Reachability reachabilityForGoogleDNS] retain];
|
hostReach = [[Reachability reachabilityForGoogleDNS] retain];
|
||||||
internetReach = [[Reachability reachabilityForInternetConnection] retain];
|
internetReach = [[Reachability reachabilityForInternetConnection] retain];
|
||||||
wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
|
wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
|
||||||
|
|
||||||
[hostReach startNotifier];
|
[hostReach startNotifier];
|
||||||
[internetReach startNotifier];
|
[internetReach startNotifier];
|
||||||
[wifiReach startNotifier];
|
[wifiReach startNotifier];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||||
{
|
{
|
||||||
self.glViewController = nil;
|
self.glViewController = nil;
|
||||||
|
|
||||||
[self setupNetworkListeners];
|
[self setupNetworkListeners];
|
||||||
|
|
||||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||||
[dnc addObserver:self selector:@selector(preGameInitialization) name:@"initializeGame" object: nil];
|
[dnc addObserver:self selector:@selector(preGameInitialization) name:@"initializeGame" object: nil];
|
||||||
[dnc addObserver:self selector:@selector(startGame) name:@"readyToStartGame" object: nil];
|
[dnc addObserver:self selector:@selector(startGame) name:@"readyToStartGame" object: nil];
|
||||||
|
|
||||||
[self initializeResources];
|
[self initializeResources];
|
||||||
// check to see if the Res folder exists. If it does continue
|
// check to see if the Res folder exists. If it does continue
|
||||||
// otherwise bring up the download dialog and download the core files
|
// otherwise bring up the download dialog and download the core files
|
||||||
@@ -328,7 +328,7 @@
|
|||||||
{
|
{
|
||||||
[self preGameInitialization];
|
[self preGameInitialization];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.window setBackgroundColor: [UIColor blackColor]];
|
[self.window setBackgroundColor: [UIColor blackColor]];
|
||||||
[self.window makeKeyAndVisible];
|
[self.window makeKeyAndVisible];
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@
|
|||||||
|
|
||||||
- (void)applicationWillTerminate:(UIApplication *)application
|
- (void)applicationWillTerminate:(UIApplication *)application
|
||||||
{
|
{
|
||||||
[self.glViewController.view destroyGame];
|
[self.glViewController.view destroyGame];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initializeKeyboard: (id) initialState
|
- (void)initializeKeyboard: (id) initialState
|
||||||
@@ -345,31 +345,18 @@
|
|||||||
[self.glViewController toggleKeyboardWithState: initialState];
|
[self.glViewController toggleKeyboardWithState: initialState];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) handleWEngineCommand:(NSString *) command
|
- (void) handleWEngineCommand:(NSString *) command
|
||||||
withUIParameters: (CGFloat) x
|
withUIParameters: (CGFloat) x
|
||||||
yCoordinate: (CGFloat) y
|
yCoordinate: (CGFloat) y
|
||||||
width: (CGFloat) width
|
width: (CGFloat) width
|
||||||
height: (CGFloat) height
|
height: (CGFloat) height
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter
|
- (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter
|
||||||
{
|
{
|
||||||
BOOL isDevicePhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone;
|
|
||||||
|
|
||||||
if ([command isEqualToString: @"entergamestate:menu"] )
|
if ([command isEqualToString: @"displayKeyboard"])
|
||||||
[glViewController.eaglView displayAds];
|
|
||||||
|
|
||||||
else if ([command isEqualToString: @"enterduelphase:end"] && isDevicePhone)
|
|
||||||
[glViewController.eaglView displayAds];
|
|
||||||
|
|
||||||
else if ([command isEqualToString: @"leaveduelphase:end"] ||
|
|
||||||
[command isEqualToString: @"leavegamestate:menu"])
|
|
||||||
{
|
|
||||||
if (isDevicePhone)
|
|
||||||
[glViewController.eaglView removeAds];
|
|
||||||
}
|
|
||||||
else if ([command isEqualToString: @"displayKeyboard"])
|
|
||||||
{
|
{
|
||||||
[self initializeKeyboard: parameter];
|
[self initializeKeyboard: parameter];
|
||||||
}
|
}
|
||||||
@@ -379,16 +366,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
||||||
{
|
{
|
||||||
bool isPhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone;
|
bool isPhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone;
|
||||||
|
|
||||||
if (isPhone)
|
if (isPhone)
|
||||||
{
|
{
|
||||||
UIImage *bgImage = [UIImage imageNamed: @"Default-Portrait.png"];
|
UIImage *bgImage = [UIImage imageNamed: @"Default-Portrait.png"];
|
||||||
[[[self.window subviews] objectAtIndex: 0] setBackgroundColor: [UIColor colorWithPatternImage: bgImage]];
|
[[[self.window subviews] objectAtIndex: 0] setBackgroundColor: [UIColor colorWithPatternImage: bgImage]];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[self.window setBackgroundColor: [UIColor clearColor]];
|
[self.window setBackgroundColor: [UIColor clearColor]];
|
||||||
if (UIInterfaceOrientationIsLandscape( toInterfaceOrientation)) {
|
if (UIInterfaceOrientationIsLandscape( toInterfaceOrientation)) {
|
||||||
@@ -410,12 +398,12 @@
|
|||||||
{
|
{
|
||||||
BOOL netAvailable = NO;
|
BOOL netAvailable = NO;
|
||||||
//NSDate *startTime = [[[NSDate alloc ] init] autorelease];
|
//NSDate *startTime = [[[NSDate alloc ] init] autorelease];
|
||||||
|
|
||||||
hostReach = [[Reachability reachabilityForGoogleDNS] retain];
|
hostReach = [[Reachability reachabilityForGoogleDNS] retain];
|
||||||
|
|
||||||
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
|
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
|
||||||
|
|
||||||
|
|
||||||
if (netStatus == ReachableViaWiFi || netStatus == ReachableViaWWAN) {
|
if (netStatus == ReachableViaWiFi || netStatus == ReachableViaWWAN) {
|
||||||
netAvailable = YES;
|
netAvailable = YES;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user