Compare commits
516 Commits
wagic-v0.1
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cc2c6cc4d | ||
|
|
a695323bc7 | ||
|
|
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
|
||||
17
.travis.yml
Normal file
17
.travis.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
language: cpp
|
||||
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 apt-get update -qq
|
||||
- if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch; fi
|
||||
- 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
|
||||
- echo yes | $ANDROID update sdk --filter 1,2,3,8 --no-ui --force > log.txt
|
||||
script: "./travis-script.sh"
|
||||
@@ -71,7 +71,7 @@ namespace boost {
|
||||
};
|
||||
|
||||
template<typename InputT, typename FindResultT>
|
||||
bool check_find_result(InputT& Input, FindResultT& FindResult)
|
||||
bool check_find_result(InputT&, FindResultT& FindResult)
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
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.
@@ -4,6 +4,8 @@
|
||||
// dirty, but I get OS header includes this way
|
||||
#include "JGE.h"
|
||||
|
||||
#include "OutputCapturer.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
@@ -29,12 +31,23 @@ std::string ToHex(T* pointer)
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
|
||||
#ifdef QT_CONFIG
|
||||
|
||||
#ifdef CAPTURE_STDERR
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
qDebug(stream.str().c_str()); \
|
||||
stream << inString; \
|
||||
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)
|
||||
#include <android/log.h>
|
||||
#define DebugTrace(inString) \
|
||||
|
||||
@@ -44,6 +44,17 @@ typedef WPARAM LocalKeySym;
|
||||
#include <X11/keysym.h>
|
||||
typedef KeySym LocalKeySym;
|
||||
#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
|
||||
typedef long unsigned int LocalKeySym;
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
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
|
||||
virtual bool getTopLeft(float& top, float& left)
|
||||
virtual bool getTopLeft(float&, float&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
int mCount;
|
||||
|
||||
JGuiController(JGE* jge, int id, JGuiListener* listener);
|
||||
~JGuiController();
|
||||
virtual ~JGuiController();
|
||||
|
||||
virtual void Render();
|
||||
virtual void Update(float dt);
|
||||
|
||||
@@ -172,6 +172,7 @@ private:
|
||||
|
||||
float mHeight;
|
||||
float mScale;
|
||||
float mTextureScale;
|
||||
float mRotation;
|
||||
float mTracking;
|
||||
float mSpacing;
|
||||
|
||||
@@ -13,34 +13,42 @@ class JSocket;
|
||||
#include <sstream>
|
||||
#include "Threading.h"
|
||||
|
||||
typedef void(*processCmd)(istream&, ostream&);
|
||||
typedef void(*processCmd)(void*, stringstream&, stringstream&);
|
||||
|
||||
class JNetwork {
|
||||
private:
|
||||
private:
|
||||
boost::thread *mpWorkerThread;
|
||||
struct CommandStruc{
|
||||
void* object;
|
||||
string command;
|
||||
processCmd processCommand;
|
||||
};
|
||||
|
||||
string serverIP;
|
||||
int connected_to_ap;
|
||||
JSocket* socket;
|
||||
boost::mutex sendMutex;
|
||||
boost::mutex receiveMutex;
|
||||
stringstream received;
|
||||
stringstream toSend;
|
||||
static map<string, processCmd> sCommandMap;
|
||||
static map<string, CommandStruc> sCommandMap;
|
||||
|
||||
public:
|
||||
JNetwork();
|
||||
~JNetwork();
|
||||
string serverIP;
|
||||
void Update();
|
||||
void getServerIp(string& aString);
|
||||
|
||||
int connect(string serverIP = "");
|
||||
int connect(const string& serverIP = "");
|
||||
bool isConnected();
|
||||
bool isServer() { return serverIP == ""; };
|
||||
static void ThreadProc(void* param);
|
||||
#if !defined (WIN32) && !defined (LINUX)
|
||||
static int connect_to_apctl(int config);
|
||||
#endif
|
||||
bool sendCommand(string command);
|
||||
static void registerCommand(string command, processCmd processCommand, processCmd processResponse);
|
||||
|
||||
private:
|
||||
boost::thread *mpWorkerThread;
|
||||
bool sendCommand(const string& command, const string& payload = "", const string& suffix = "Request");
|
||||
static void registerCommand(string command, void* object, processCmd processRequest, processCmd processResponse);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -578,7 +578,7 @@ private:
|
||||
#if (!defined PSP)
|
||||
|
||||
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
|
||||
ESMatrix theMvpMatrix;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "Threading.h"
|
||||
using namespace std;
|
||||
|
||||
#define SERVER_PORT 5001
|
||||
|
||||
class JSocket{
|
||||
public:
|
||||
typedef enum {
|
||||
@@ -19,10 +21,11 @@ public:
|
||||
} SOCKET_STATE;
|
||||
|
||||
|
||||
// Server creation
|
||||
JSocket(string ipAddr);
|
||||
// Client creation
|
||||
JSocket(string ipAddr);
|
||||
// Server creation
|
||||
JSocket();
|
||||
|
||||
~JSocket();
|
||||
|
||||
JSocket* Accept();
|
||||
@@ -32,6 +35,8 @@ public:
|
||||
void Disconnect();
|
||||
|
||||
private:
|
||||
// socket state
|
||||
SOCKET_STATE state;
|
||||
// socket creation when server accepts a connection
|
||||
JSocket(int fd);
|
||||
// convert the socket into non-blocking state
|
||||
@@ -39,11 +44,9 @@ private:
|
||||
// socket handle
|
||||
#ifdef WIN32
|
||||
SOCKET mfd;
|
||||
#elif LINUX
|
||||
#elif LINUX || PSP
|
||||
int mfd;
|
||||
#endif
|
||||
// socket state
|
||||
SOCKET_STATE state;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
#elif defined USE_PHONON
|
||||
#include <phonon/AudioOutput>
|
||||
#include <phonon/MediaObject>
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#elif defined WIN32
|
||||
#include <windows.h>
|
||||
#define WITH_FMOD
|
||||
#elif defined (PSP)
|
||||
@@ -43,10 +42,10 @@
|
||||
#include "JAudio.h"
|
||||
#include "JMP3.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FMOD
|
||||
#include "../Dependencies/include/fmod.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
using namespace std;
|
||||
|
||||
@@ -39,10 +39,10 @@
|
||||
#define MAX_CHANNEL 128
|
||||
|
||||
enum {
|
||||
JGE_ERR_CANT_OPEN_FILE = -1,
|
||||
JGE_ERR_PNG = -2,
|
||||
JGE_ERR_MALLOC_FAILED = -4,
|
||||
JGE_ERR_GENERIC = -5,
|
||||
JGE_ERR_CANT_OPEN_FILE = -1,
|
||||
JGE_ERR_PNG = -2,
|
||||
JGE_ERR_MALLOC_FAILED = -4,
|
||||
JGE_ERR_GENERIC = -5,
|
||||
};
|
||||
|
||||
#ifdef PSP
|
||||
@@ -75,45 +75,76 @@ enum {
|
||||
#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
|
||||
// #define DEFAULT_BLEND BLEND_DEFAULT
|
||||
// #define BLEND_OPTION_ADD BLEND_COLORADD
|
||||
// #define BLEND_OPTION_BLEND (BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE)
|
||||
#else
|
||||
#define DEFAULT_BLEND GU_TFX_MODULATE
|
||||
#define BLEND_OPTION_ADD GU_TFX_ADD
|
||||
#define BLEND_OPTION_BLEND GU_TFX_BLEND
|
||||
#define DEFAULT_BLEND GU_TFX_MODULATE
|
||||
#define BLEND_OPTION_ADD GU_TFX_ADD
|
||||
#define BLEND_OPTION_BLEND GU_TFX_BLEND
|
||||
#endif
|
||||
#endif // CONSOLE_CONFIG
|
||||
|
||||
#if (defined WIN32) && (!defined LINUX)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#if defined(LINUX) || defined(IOS) || defined (ANDROID)
|
||||
typedef uint8_t byte;
|
||||
typedef uint32_t DWORD;
|
||||
typedef uint8_t BYTE;
|
||||
#if defined(LINUX) && (!defined WIN32) || defined(IOS) || defined (ANDROID)
|
||||
typedef uint8_t byte;
|
||||
typedef uint32_t DWORD;
|
||||
typedef uint8_t BYTE;
|
||||
#ifndef IOS
|
||||
typedef bool BOOL;
|
||||
typedef bool BOOL;
|
||||
#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
|
||||
#if defined (IOS)
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
# import <OpenGLES/ES1/glext.h>
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
#import <OpenGLES/ES1/glext.h>
|
||||
#elif defined (ANDROID)
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
#elif defined (WIN32) || defined (LINUX)
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
#elif defined (WIN32) || defined (LINUX)
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
#else
|
||||
# include <QtOpenGL>
|
||||
#include <QtOpenGL>
|
||||
#endif
|
||||
|
||||
#if (defined FORCE_GLES)
|
||||
@@ -127,152 +158,115 @@ enum {
|
||||
#endif
|
||||
|
||||
#if defined (PSP)
|
||||
|
||||
#ifndef ABGR8888
|
||||
#define ABGR8888
|
||||
#endif
|
||||
#ifndef ABGR8888
|
||||
#define ABGR8888
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (ABGR8888)
|
||||
#define PIXEL_TYPE u32
|
||||
#ifndef ARGB
|
||||
#define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format
|
||||
#endif
|
||||
#define MAKE_COLOR(a, c) (a << 24 | c)
|
||||
#define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels
|
||||
#define MASK_BLUE 0x00FF0000
|
||||
#define MASK_GREEN 0x0000FF00
|
||||
#define MASK_RED 0x000000FF
|
||||
#if defined (ABGR8888)
|
||||
#ifndef ARGB
|
||||
#define ARGB(a, r, g, b) (PIXEL_TYPE)((a << 24) | (b << 16) | (g << 8) | r) // macro to assemble pixels in correct format
|
||||
#endif
|
||||
#define MAKE_COLOR(a, c) (a << 24 | c)
|
||||
#define MASK_ALPHA 0xFF000000 // masks for accessing individual pixels
|
||||
#define MASK_BLUE 0x00FF0000
|
||||
#define MASK_GREEN 0x0000FF00
|
||||
#define MASK_RED 0x000000FF
|
||||
|
||||
#define PIXEL_SIZE 4
|
||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888
|
||||
#define PIXEL_SIZE 4
|
||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_8888
|
||||
|
||||
#define BUFFER_FORMAT GU_PSM_8888
|
||||
#define TEXTURE_FORMAT GU_PSM_8888
|
||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_8888
|
||||
#define BUFFER_FORMAT GU_PSM_8888
|
||||
#define TEXTURE_FORMAT GU_PSM_8888
|
||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_8888
|
||||
|
||||
|
||||
#elif defined (ABGR5551)
|
||||
#elif defined (ABGR5551)
|
||||
|
||||
#ifndef ARGB
|
||||
#define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15))
|
||||
#endif
|
||||
#define MAKE_COLOR(a, c) (((a>>7)<<15) | c)
|
||||
#define MASK_ALPHA 0x8000
|
||||
#define MASK_BLUE 0x7C00
|
||||
#define MASK_GREEN 0x03E0
|
||||
#define MASK_RED 0x001F
|
||||
#define PIXEL_TYPE u16
|
||||
#define PIXEL_SIZE 2
|
||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551
|
||||
#ifndef ARGB
|
||||
#define ARGB(a, r, g, b) ((r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) | ((a >> 7) << 15))
|
||||
#endif
|
||||
#define MAKE_COLOR(a, c) (((a>>7)<<15) | c)
|
||||
#define MASK_ALPHA 0x8000
|
||||
#define MASK_BLUE 0x7C00
|
||||
#define MASK_GREEN 0x03E0
|
||||
#define MASK_RED 0x001F
|
||||
#define PIXEL_TYPE u16
|
||||
#define PIXEL_SIZE 2
|
||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_5551
|
||||
|
||||
#define BUFFER_FORMAT GU_PSM_8888
|
||||
#define TEXTURE_FORMAT GU_PSM_5551
|
||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_5551
|
||||
#define BUFFER_FORMAT GU_PSM_8888
|
||||
#define TEXTURE_FORMAT GU_PSM_5551
|
||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_5551
|
||||
|
||||
#elif defined (ABGR4444)
|
||||
#ifndef ARGB
|
||||
#define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12))
|
||||
#endif
|
||||
#define MAKE_COLOR(a, c) (((a>>4)<<12) | c)
|
||||
#define MASK_ALPHA 0xF000
|
||||
#define MASK_BLUE 0x0F00
|
||||
#define MASK_GREEN 0x00F0
|
||||
#define MASK_RED 0x000F
|
||||
#define PIXEL_TYPE u16
|
||||
#define PIXEL_SIZE 2
|
||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444
|
||||
#elif defined (ABGR4444)
|
||||
#ifndef ARGB
|
||||
#define ARGB(a, r, g, b) ((r >> 4) | ((g >> 4) << 4) | ((b >> 4) << 8) | ((a >> 4) << 12))
|
||||
#endif
|
||||
#define MAKE_COLOR(a, c) (((a>>4)<<12) | c)
|
||||
#define MASK_ALPHA 0xF000
|
||||
#define MASK_BLUE 0x0F00
|
||||
#define MASK_GREEN 0x00F0
|
||||
#define MASK_RED 0x000F
|
||||
#define PIXEL_TYPE u16
|
||||
#define PIXEL_SIZE 2
|
||||
#define PIXEL_FORMAT PSP_DISPLAY_PIXEL_FORMAT_4444
|
||||
|
||||
#define BUFFER_FORMAT GU_PSM_4444
|
||||
#define TEXTURE_FORMAT GU_PSM_4444
|
||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_4444
|
||||
#define BUFFER_FORMAT GU_PSM_4444
|
||||
#define TEXTURE_FORMAT GU_PSM_4444
|
||||
#define TEXTURE_COLOR_FORMAT GU_COLOR_4444
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define FRAME_BUFFER_WIDTH 512
|
||||
#define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE
|
||||
#define FRAME_BUFFER_WIDTH 512
|
||||
#define FRAME_BUFFER_SIZE FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*PIXEL_SIZE
|
||||
|
||||
#define SLICE_SIZE_F 64.0f
|
||||
typedef unsigned int DWORD;
|
||||
#define SLICE_SIZE_F 64.0f
|
||||
typedef unsigned int DWORD;
|
||||
|
||||
#define BLEND_ZERO 0x1000
|
||||
#define BLEND_ONE 0x1002
|
||||
#define BLEND_SRC_COLOR GU_SRC_COLOR
|
||||
#define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR
|
||||
#define BLEND_SRC_ALPHA GU_SRC_ALPHA
|
||||
#define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA
|
||||
#define BLEND_DST_ALPHA GU_DST_ALPHA
|
||||
#define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA
|
||||
#define BLEND_DST_COLOR GU_DST_COLOR
|
||||
#define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR
|
||||
#define BLEND_SRC_ALPHA_SATURATE BLEND_ONE
|
||||
#define BLEND_ZERO 0x1000
|
||||
#define BLEND_ONE 0x1002
|
||||
#define BLEND_SRC_COLOR GU_SRC_COLOR
|
||||
#define BLEND_ONE_MINUS_SRC_COLOR GU_ONE_MINUS_SRC_COLOR
|
||||
#define BLEND_SRC_ALPHA GU_SRC_ALPHA
|
||||
#define BLEND_ONE_MINUS_SRC_ALPHA GU_ONE_MINUS_SRC_ALPHA
|
||||
#define BLEND_DST_ALPHA GU_DST_ALPHA
|
||||
#define BLEND_ONE_MINUS_DST_ALPHA GU_ONE_MINUS_DST_ALPHA
|
||||
#define BLEND_DST_COLOR GU_DST_COLOR
|
||||
#define BLEND_ONE_MINUS_DST_COLOR GU_ONE_MINUS_DST_COLOR
|
||||
#define BLEND_SRC_ALPHA_SATURATE BLEND_ONE
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ScePspFVector2 texture;
|
||||
ScePspFVector3 pos;
|
||||
} PSPVertex3D;
|
||||
typedef struct
|
||||
{
|
||||
ScePspFVector2 texture;
|
||||
ScePspFVector3 pos;
|
||||
} PSPVertex3D;
|
||||
|
||||
#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_5551 0
|
||||
#define GU_PSM_4444 0
|
||||
#define GU_PSM_5650 0
|
||||
#define PIXEL_TYPE DWORD
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
#else
|
||||
typedef uint32_t GLuint;
|
||||
typedef float GLfloat;
|
||||
#endif //CONSOLE_CONFIG
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
struct Vertex
|
||||
@@ -357,7 +351,7 @@ public:
|
||||
|
||||
int mFilter;
|
||||
|
||||
#if defined (PSP)
|
||||
#if defined (PSP)
|
||||
int mTextureFormat;
|
||||
int mTexId;
|
||||
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
|
||||
|
||||
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
|
||||
@@ -315,7 +315,6 @@ namespace boost
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "../include/DebugRoutines.h"
|
||||
#include "../include/JLogger.h"
|
||||
|
||||
namespace boost
|
||||
|
||||
@@ -3,15 +3,6 @@
|
||||
|
||||
#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
|
||||
{
|
||||
Vector3D(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
@@ -63,7 +54,7 @@ struct Vector3D
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,19 @@
|
||||
#include <QDBusInterface>
|
||||
#endif //Q_WS_MAEMO_5
|
||||
|
||||
class WagicWrapper
|
||||
{
|
||||
public:
|
||||
WagicWrapper();
|
||||
virtual ~WagicWrapper();
|
||||
|
||||
private:
|
||||
JGE* m_engine;
|
||||
JApp* m_app;
|
||||
JGameLauncher* m_launcher;
|
||||
};
|
||||
|
||||
|
||||
#ifdef QT_WIDGET
|
||||
class WagicCore : public QGLWidget
|
||||
#else
|
||||
@@ -35,6 +48,7 @@ private:
|
||||
#else
|
||||
typedef QDeclarativeItem super;
|
||||
#endif //QT_WIDGET
|
||||
void initApp();
|
||||
|
||||
public:
|
||||
Q_OBJECT
|
||||
@@ -47,7 +61,7 @@ public:
|
||||
public:
|
||||
explicit WagicCore(super *parent = 0);
|
||||
virtual ~WagicCore();
|
||||
void initApp();
|
||||
static int runTestSuite();
|
||||
|
||||
Q_INVOKABLE void doOK() {
|
||||
doAndEnqueue(JGE_BTN_OK);
|
||||
@@ -73,7 +87,7 @@ public:
|
||||
Q_INVOKABLE qint64 getTick() {
|
||||
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);
|
||||
};
|
||||
int getNominalHeight(){ return SCREEN_HEIGHT;};
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#if defined(ANDROID)
|
||||
#include "../../include/PrecompiledHeader.h"
|
||||
#endif
|
||||
#ifndef PSP
|
||||
#include "PrecompiledHeader.h"
|
||||
#endif //PSP
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4786)
|
||||
@@ -34,6 +34,10 @@ The content that users should not be touching.
|
||||
#include "../include/JLogger.h"
|
||||
#include <dirent.h>
|
||||
|
||||
#ifdef QT_CONFIG
|
||||
#include <QDir>
|
||||
#endif
|
||||
|
||||
JFileSystem* JFileSystem::mInstance = NULL;
|
||||
|
||||
JZipCache::JZipCache()
|
||||
@@ -121,11 +125,18 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
|
||||
|
||||
DebugTrace("User path " << userPath);
|
||||
#elif defined (QT_CONFIG)
|
||||
|
||||
QDir sysDir("projects/mtg/bin/Res");
|
||||
QDir dir(QDir::homePath());
|
||||
dir.mkdir(USERDIR);
|
||||
dir.cd(USERDIR);
|
||||
|
||||
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
|
||||
//Find the Res.txt file and matching Res folders for backwards compatibility
|
||||
ifstream mfile("Res.txt");
|
||||
@@ -320,6 +331,36 @@ bool JFileSystem::openForWrite(ofstream & File, const string & FilePath, ios_bas
|
||||
{
|
||||
string filename = mUserFSPath;
|
||||
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);
|
||||
|
||||
if (File)
|
||||
|
||||
@@ -591,6 +591,8 @@ void JGE::SendCommand(string command)
|
||||
sendJNICommand(command);
|
||||
#elif defined (IOS)
|
||||
SendCommand(command, "");
|
||||
#else
|
||||
cerr << command;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -602,6 +604,8 @@ void JGE::SendCommand(std::string command, std::string parameter)
|
||||
[delegate handleWEngineCommand:[NSString stringWithCString: command.c_str() encoding: NSUTF8StringEncoding]
|
||||
withParameter: [NSString stringWithCString: parameter.c_str() encoding:NSUTF8StringEncoding]];
|
||||
|
||||
#else
|
||||
cerr << command << " " << parameter;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -613,6 +617,8 @@ void JGE::SendCommand(std::string command, float& x, float& y, float& width, flo
|
||||
#elif IOS
|
||||
wagicAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
|
||||
[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
|
||||
|
||||
}
|
||||
@@ -656,7 +662,6 @@ JNIEnv * JGE::getJNIEnv()
|
||||
|
||||
string JGE::getFileSystemLocation()
|
||||
{
|
||||
char result[512];
|
||||
JNIEnv * env = getJNIEnv();
|
||||
if (env == NULL)
|
||||
{
|
||||
|
||||
508
JGE/src/JGfx-fake.cpp
Normal file
508
JGE/src/JGfx-fake.cpp
Normal file
@@ -0,0 +1,508 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// 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() : 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);
|
||||
mTexture = mRenderer->LoadTexture(filename, useVideoRAM);
|
||||
mTextureScale = (float) lineheight/ (mTexture->mHeight/16);
|
||||
|
||||
if (mTexture == NULL) return;
|
||||
if (mTexture == NULL) return;
|
||||
|
||||
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;
|
||||
|
||||
@@ -158,7 +159,7 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
||||
|
||||
index = (*p - 32)+mBase;
|
||||
|
||||
float charWidth = mCharWidth[index];
|
||||
float charWidth = mCharWidth[index]*mTextureScale;
|
||||
float delta = (charWidth + mTracking) * mScale;
|
||||
float xPos = mXPos[index];
|
||||
if (leftOffset)
|
||||
@@ -194,8 +195,8 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
|
||||
charWidth = (delta/mScale) - mTracking;
|
||||
}
|
||||
}
|
||||
mQuad->SetTextureRect(xPos, mYPos[index], charWidth , mHeight);
|
||||
mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale, mScale);
|
||||
mQuad->SetTextureRect(xPos, mYPos[index], charWidth/mTextureScale, mHeight/mTextureScale);
|
||||
mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale*mTextureScale, mScale*mTextureScale);
|
||||
dx += delta;
|
||||
p++;
|
||||
}
|
||||
@@ -235,7 +236,7 @@ float JLBFont::GetStringWidth(const char *string) const
|
||||
ch = *p - 32;
|
||||
p++;
|
||||
if (ch < 0) continue;
|
||||
len += mCharWidth[ch+mBase] + mTracking;
|
||||
len += (mCharWidth[ch+mBase]*mTextureScale) + mTracking;
|
||||
}
|
||||
len -= mTracking;
|
||||
return len*mScale;
|
||||
|
||||
@@ -257,6 +257,8 @@ void JMD2Model::CalculateNormal(float *p1, float *p2, float *p3)
|
||||
#else
|
||||
// FIXME
|
||||
#endif
|
||||
#else
|
||||
cerr << p1 << " " << p2 << " " << p3 << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -33,15 +33,43 @@
|
||||
#include <sstream>
|
||||
#include "../include/JSocket.h"
|
||||
|
||||
map<string, processCmd> JNetwork::sCommandMap;
|
||||
map<string, JNetwork::CommandStruc> JNetwork::sCommandMap;
|
||||
|
||||
bool JNetwork::isConnected(){
|
||||
if (connected_to_ap !=1) return false;
|
||||
if (connected_to_ap !=1 || !socket) return false;
|
||||
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()
|
||||
: mpWorkerThread(NULL)
|
||||
: mpWorkerThread(NULL), socket(0)
|
||||
{
|
||||
#if (defined WIN32) || (defined LINUX)
|
||||
connected_to_ap = 1;
|
||||
@@ -62,30 +90,68 @@ JNetwork::~JNetwork()
|
||||
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);
|
||||
if(!socket) {
|
||||
DebugTrace("sendCommand failed: no sockeet");
|
||||
DebugTrace("sendCommand failed: no socket");
|
||||
return false;
|
||||
}
|
||||
aString = aString + "Command";
|
||||
aString = xString + suffix;
|
||||
if(sCommandMap.find(aString) == sCommandMap.end()) {
|
||||
DebugTrace("sendCommand failed: command not registered");
|
||||
return false;
|
||||
}
|
||||
aString = aString + "\n";
|
||||
aString = "<" + aString + ">" + "\n" + payload + "\n" + "<" + aString + "/>";
|
||||
|
||||
toSend << aString;
|
||||
|
||||
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;
|
||||
sCommandMap[command + "Response"] = processResponse;
|
||||
CommandStruc struc;
|
||||
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)
|
||||
@@ -105,71 +171,33 @@ void JNetwork::ThreadProc(void* param)
|
||||
}
|
||||
|
||||
while(pSocket && pSocket->isConnected()) {
|
||||
char buff[1024];
|
||||
char buff[4096];
|
||||
{
|
||||
boost::mutex::scoped_lock l(pThis->receiveMutex);
|
||||
int len = pSocket->Read(buff, sizeof(buff));
|
||||
if(len) {
|
||||
if(len > 0) {
|
||||
boost::mutex::scoped_lock l(pThis->receiveMutex);
|
||||
DebugTrace("receiving " << len << " bytes : " << buff);
|
||||
pThis->received << buff;
|
||||
}
|
||||
// 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() );
|
||||
}
|
||||
pThis->received.str(pThis->received.str() + buff);
|
||||
DebugTrace("received " << pThis->received.str().size() << " bytes : " << pThis->received.str());
|
||||
}
|
||||
}
|
||||
|
||||
boost::mutex::scoped_lock l(pThis->sendMutex);
|
||||
if(!pThis->toSend.str().empty())
|
||||
{
|
||||
DebugTrace("sending " << pThis->toSend.str().size() << " bytes : " << pThis->toSend.str());
|
||||
pSocket->Write((char*)pThis->toSend.str().c_str(), pThis->toSend.str().size()+1);
|
||||
pThis->toSend.str("");
|
||||
}
|
||||
{
|
||||
boost::mutex::scoped_lock l(pThis->sendMutex);
|
||||
if(!pThis->toSend.str().empty())
|
||||
{
|
||||
DebugTrace("sending " << pThis->toSend.str().size() << " bytes : " << pThis->toSend.str());
|
||||
pSocket->Write((char*)pThis->toSend.str().c_str(), pThis->toSend.str().size()+1);
|
||||
pThis->toSend.str("");
|
||||
}
|
||||
}
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
||||
}
|
||||
|
||||
DebugTrace("Quitting Thread");
|
||||
}
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
int JNetwork::connect(string ip)
|
||||
int JNetwork::connect(const string& ip)
|
||||
{
|
||||
if (mpWorkerThread) return 0;
|
||||
serverIP = ip;
|
||||
@@ -179,7 +207,7 @@ int JNetwork::connect(string ip)
|
||||
|
||||
#else
|
||||
|
||||
int JNetwork::connect(string serverIP){
|
||||
int JNetwork::connect(const string& serverIP){
|
||||
#ifdef NETWORK_SUPPORT
|
||||
int err;
|
||||
char buffer[4096];
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "../include/JLBFont.h"
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#if defined (_DEBUG) && defined (WIN32)
|
||||
#if defined (_DEBUG) && defined (WIN32) && (!defined LINUX)
|
||||
#include "crtdbg.h"
|
||||
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
||||
#else
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#if 0
|
||||
// need a complete rewrite to comply to the new interface
|
||||
#ifdef NETWORK_SUPPORT
|
||||
|
||||
@@ -21,23 +20,21 @@
|
||||
#endif
|
||||
|
||||
#include "../include/JGE.h"
|
||||
|
||||
#include "../include/JSocket.h"
|
||||
JSocket * JSocket::mInstance = NULL;
|
||||
|
||||
#define SERVER_PORT 20666
|
||||
|
||||
int JSocket::connected = 0;
|
||||
|
||||
void JSocket::init(){
|
||||
JSocket::JSocket(){
|
||||
#ifdef NETWORK_SUPPORT
|
||||
sceUtilityLoadNetModule(1);
|
||||
sceUtilityLoadNetModule(3);
|
||||
#endif
|
||||
}
|
||||
|
||||
JSocket::JSocket(){
|
||||
init();
|
||||
JSocket::JSocket(string ipAddr)
|
||||
{
|
||||
}
|
||||
|
||||
JSocket::JSocket(int fd)
|
||||
{
|
||||
}
|
||||
|
||||
JSocket::~JSocket(){
|
||||
@@ -48,7 +45,27 @@ JSocket::~JSocket(){
|
||||
#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 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("");
|
||||
}
|
||||
106
JGE/src/Qtconsole.cpp
Normal file
106
JGE/src/Qtconsole.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#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();
|
||||
int totalTests = testSuite.nbTests + testSuite.nbAITests;
|
||||
delete wagicCore;
|
||||
DebugTrace("TestSuite done: failed test: " << result << " out of " << totalTests << " total");
|
||||
#ifdef CAPTURE_STDERR
|
||||
OutputCapturer::debugAndClear();
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QtOpenGL>
|
||||
#include <QTime>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QApplication>
|
||||
#include <QScopedPointer>
|
||||
#ifdef QT_WIDGET
|
||||
#include <QWidget>
|
||||
@@ -68,6 +68,14 @@ int main(int argc, char* argv[])
|
||||
(createApplication(argc, argv));
|
||||
|
||||
#endif //QT_WIDGET
|
||||
|
||||
if(argc >= 2 && strcmp(argv[1], "testsuite")==0)
|
||||
{
|
||||
int result = 0;
|
||||
result += WagicCore::runTestSuite();
|
||||
return result;
|
||||
}
|
||||
|
||||
app->setApplicationName(WagicCore::getApplicationName());
|
||||
FileDownloader fileDownloader(USERDIR, WAGIC_RESOURCE_NAME);
|
||||
#ifdef QT_WIDGET
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.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
|
||||
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
|
||||
SLDataLocator_AndroidFD loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
|
||||
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
|
||||
SLDataSource audioSrc = {&loc_fd, &format_mime};
|
||||
if(fullpath.compare("") != 0)
|
||||
{
|
||||
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 sink
|
||||
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
|
||||
SLDataSink audioSnk = {&loc_outmix, NULL};
|
||||
// configure audio source
|
||||
SLDataLocator_AndroidFD loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
|
||||
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
|
||||
SLDataSource audioSrc = {&loc_fd, &format_mime};
|
||||
|
||||
// create audio player
|
||||
const SLInterfaceID ids[2] = {SL_IID_SEEK, SL_IID_VOLUME};
|
||||
const SLboolean req[2] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
|
||||
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &music->playerObject, &audioSrc, &audioSnk,
|
||||
2, ids, req);
|
||||
DebugTrace("result " << result);
|
||||
// configure audio sink
|
||||
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
|
||||
SLDataSink audioSnk = {&loc_outmix, NULL};
|
||||
|
||||
// realize the player
|
||||
result = (*music->playerObject)->Realize(music->playerObject, SL_BOOLEAN_FALSE);
|
||||
DebugTrace("result " << result);
|
||||
// create audio player
|
||||
const SLInterfaceID ids[2] = {SL_IID_SEEK, SL_IID_VOLUME};
|
||||
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
|
||||
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_PLAY, &music->playInterface);
|
||||
DebugTrace("result " << result);
|
||||
// realize the player
|
||||
result = (*music->playerObject)->Realize(music->playerObject, SL_BOOLEAN_FALSE);
|
||||
DebugTrace("result " << result);
|
||||
|
||||
// get the seek interface
|
||||
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_SEEK, &music->seekInterface);
|
||||
DebugTrace("result " << result);
|
||||
// get the play interface
|
||||
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_PLAY, &music->playInterface);
|
||||
DebugTrace("result " << result);
|
||||
|
||||
// get the volume interface
|
||||
//result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_VOLUME, (void *)&music->musicVolumeInterface);
|
||||
|
||||
DebugTrace("result " << result);
|
||||
// get the seek interface
|
||||
result = (*music->playerObject)->GetInterface(music->playerObject, SL_IID_SEEK, &music->seekInterface);
|
||||
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;
|
||||
@@ -215,12 +223,10 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
||||
//(*music->musicVolumeInterface)->SetVolumeLevel(music->musicVolumeInterface, -1 * mVolume);
|
||||
|
||||
// enable whole file looping
|
||||
result = (*music->seekInterface)->SetLoop(music->seekInterface,
|
||||
looping?SL_BOOLEAN_TRUE:SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN);
|
||||
result = (*music->seekInterface)->SetLoop(music->seekInterface, looping ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
result = (*music->playInterface)->SetPlayState(music->playInterface,
|
||||
SL_PLAYSTATE_PLAYING);
|
||||
result = (*music->playInterface)->SetPlayState(music->playInterface, SL_PLAYSTATE_PLAYING);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import "AdWhirlDelegateProtocol.h"
|
||||
#import "EAGLViewController.h"
|
||||
#import "EAGLView.h"
|
||||
#import "ESRenderer.h"
|
||||
@@ -8,9 +7,8 @@
|
||||
// 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.
|
||||
// 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
|
||||
EAGLViewController *viewController;
|
||||
|
||||
@@ -27,7 +25,6 @@
|
||||
id displayLink;
|
||||
CGPoint currentLocation;
|
||||
}
|
||||
@property (nonatomic, retain) AdWhirlView *adView;
|
||||
@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
|
||||
@property (nonatomic) NSInteger animationFrameInterval;
|
||||
@property (nonatomic, readwrite) CGPoint currentLocation;
|
||||
@@ -37,8 +34,6 @@
|
||||
- (void)drawView:(id)sender;
|
||||
|
||||
- (void)updateKeyboard: (NSString *) inputString;
|
||||
- (void)removeAds;
|
||||
- (void)displayAds;
|
||||
|
||||
- (void)destroyGame;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "GameApp.h"
|
||||
|
||||
#import "AdWhirlView.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 -
|
||||
|
||||
@implementation EAGLView
|
||||
|
||||
@synthesize adView;
|
||||
@synthesize animating;
|
||||
@dynamic animationFrameInterval;
|
||||
@synthesize currentLocation;
|
||||
@@ -91,7 +85,6 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
||||
- (void)dealloc
|
||||
{
|
||||
[renderer release];
|
||||
[self removeAds];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -173,11 +166,12 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
||||
[menuKeyRecognizer requireGestureRecognizerToFail: selectKeyRecognizer];
|
||||
[self addGestureRecognizer:menuKeyRecognizer];
|
||||
|
||||
/*
|
||||
// initialize the scaling factor
|
||||
lastScale = 1.f;
|
||||
UIPinchGestureRecognizer *pinchZoomRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchZoom:)];
|
||||
[self addGestureRecognizer:pinchZoomRecognizer];
|
||||
[pinchZoomRecognizer release];
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Create a single tap recognizer to select the nearest object.
|
||||
@@ -398,8 +392,6 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
|
||||
{
|
||||
return YES;
|
||||
@@ -432,6 +424,21 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
|
||||
}
|
||||
|
||||
#pragma mark Gesture Recognizer callbacks
|
||||
- (void)handlePinchZoom: (UIPinchGestureRecognizer *) pinchGesture {
|
||||
[[[pinchGesture view] layer] removeAllAnimations];
|
||||
CGFloat currentScaleFactor = [pinchGesture scale];
|
||||
|
||||
if (pinchGesture.state == UIGestureRecognizerStateEnded) {
|
||||
if (lastScale < 1.3f) {
|
||||
lastScale *= currentScaleFactor;
|
||||
}
|
||||
else {
|
||||
lastScale = 1;
|
||||
[self displayGameMenu];
|
||||
}
|
||||
pinchGesture.scale = 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handlePanMotion: (UIPanGestureRecognizer *) panGesture
|
||||
{
|
||||
@@ -635,30 +642,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 {
|
||||
//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.
|
||||
@@ -666,101 +649,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
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AdWhirlDelegateProtocol.h"
|
||||
|
||||
@interface EAGLViewController : UIViewController<UITextFieldDelegate> {
|
||||
|
||||
|
||||
@@ -25,10 +25,13 @@
|
||||
[inputField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
|
||||
[inputField setAutocorrectionType:UITextAutocorrectionTypeNo];
|
||||
[inputField setKeyboardType: UIKeyboardTypeNamePhonePad];
|
||||
|
||||
CGRect frame = [[UIScreen mainScreen] applicationFrame];
|
||||
eaglView = [[EAGLView alloc] initWithFrame:frame];
|
||||
|
||||
[self setView: eaglView];
|
||||
[self.view addSubview: inputField];
|
||||
|
||||
[inputField release];
|
||||
}
|
||||
return self;
|
||||
@@ -44,16 +47,14 @@
|
||||
|
||||
- (void)viewDidLoad {
|
||||
NSLog(@"EAGL ViewController - view Did Load");
|
||||
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
NSLog(@"EAGL ViewController - view Will Appear");
|
||||
[self.view resumeGame];
|
||||
[self.view resumeGame];
|
||||
}
|
||||
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[self.view pauseGame];
|
||||
@@ -74,15 +75,19 @@
|
||||
[self.view endGame];
|
||||
}
|
||||
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle {
|
||||
return UIStatusBarStyleLightContent;
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
|
||||
|
||||
NSLog(@"EAGL ViewController - view Did Appear");
|
||||
|
||||
|
||||
UIDeviceOrientation currentDeviceOrientation = [UIDevice currentDevice].orientation;
|
||||
UIInterfaceOrientation currentInterfaceOrientation = self.interfaceOrientation;
|
||||
|
||||
NSLog(@"Current Interface: %@. Current Device: %@",
|
||||
[self interfaceOrientationName:currentInterfaceOrientation],
|
||||
|
||||
NSLog(@"Current Interface: %@. Current Device: %@",
|
||||
[self interfaceOrientationName:currentInterfaceOrientation],
|
||||
[self deviceOrientationName:currentDeviceOrientation]);
|
||||
}
|
||||
|
||||
@@ -91,7 +96,7 @@
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
|
||||
// Release any cached data, images, etc. that aren't in use.
|
||||
}
|
||||
|
||||
@@ -103,6 +108,25 @@
|
||||
}
|
||||
|
||||
#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 {
|
||||
// Overriden to allow any orientation.
|
||||
@@ -110,23 +134,23 @@
|
||||
|
||||
if ( isSmallScreen && UIInterfaceOrientationIsPortrait(interfaceOrientation))
|
||||
return NO;
|
||||
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
||||
[[eaglView adView] rotateToOrientation: toInterfaceOrientation];
|
||||
// [[eaglView adView] rotateToOrientation: toInterfaceOrientation];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Orientation Information
|
||||
- (NSString*)interfaceOrientationName:(UIInterfaceOrientation) interfaceOrientation {
|
||||
|
||||
|
||||
NSString* result = nil;
|
||||
|
||||
|
||||
switch (interfaceOrientation) {
|
||||
|
||||
|
||||
case UIInterfaceOrientationPortrait:
|
||||
result = @"Portrait";
|
||||
break;
|
||||
@@ -142,16 +166,16 @@
|
||||
default:
|
||||
result = @"Unknown Interface Orientation";
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
- (NSString*)deviceOrientationName:(UIDeviceOrientation) deviceOrientation {
|
||||
|
||||
|
||||
NSString* result = nil;
|
||||
|
||||
|
||||
switch (deviceOrientation) {
|
||||
|
||||
|
||||
case UIDeviceOrientationUnknown:
|
||||
result = @"Unknown";
|
||||
break;
|
||||
@@ -176,7 +200,7 @@
|
||||
default:
|
||||
result = @"Unknown Device Orientation";
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -205,7 +229,7 @@
|
||||
[eaglView updateKeyboard: @"CLEAR"];
|
||||
else
|
||||
[eaglView updateKeyboard: string];
|
||||
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -215,7 +239,7 @@
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) textFieldShouldReturn:(UITextField *)textField
|
||||
- (BOOL) textFieldShouldReturn:(UITextField *)textField
|
||||
{
|
||||
[eaglView updateKeyboard: @"SAVE"];
|
||||
[textField resignFirstResponder];
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "JFileSystem.h"
|
||||
#include "JRenderer.h"
|
||||
#include "JGameLauncher.h"
|
||||
#include "UIScreen+Util.h"
|
||||
|
||||
#define ACTUAL_SCREEN_WIDTH (SCREEN_WIDTH)
|
||||
#define ACTUAL_SCREEN_HEIGHT (SCREEN_HEIGHT)
|
||||
@@ -33,7 +34,7 @@ bool checkFramebufferStatus();
|
||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
if ( context == nil)
|
||||
context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1];
|
||||
|
||||
|
||||
if (!context || ![EAGLContext setCurrentContext:context])
|
||||
{
|
||||
[self release];
|
||||
@@ -46,20 +47,29 @@ bool checkFramebufferStatus();
|
||||
|
||||
- (void)render
|
||||
{
|
||||
// NSLog(@"Renderer - render");
|
||||
|
||||
struct timeval tv;
|
||||
uint dt;
|
||||
|
||||
|
||||
// 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.
|
||||
[EAGLContext setCurrentContext:context];
|
||||
|
||||
|
||||
// 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.
|
||||
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 ( [UIScreen isRetinaDisplay]) {
|
||||
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.top = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2;
|
||||
@@ -73,21 +83,21 @@ bool checkFramebufferStatus();
|
||||
viewPort.right = backingHeight * ACTUAL_RATIO;
|
||||
viewPort.bottom = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + backingWidth / ACTUAL_RATIO + backingHeight;
|
||||
}
|
||||
|
||||
|
||||
glViewport(viewPort.left, viewPort.top, viewPort.right-viewPort.left, viewPort.bottom-viewPort.top);
|
||||
|
||||
JRenderer::GetInstance()->SetActualWidth(viewPort.right-viewPort.left);
|
||||
JRenderer::GetInstance()->SetActualHeight(viewPort.bottom-viewPort.top);
|
||||
|
||||
|
||||
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
uint64_t tickCount = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
dt = (tickCount - lastTickCount);
|
||||
lastTickCount = tickCount;
|
||||
|
||||
|
||||
g_engine->SetDelta((float)dt / 1000.0f);
|
||||
g_engine->Update((float)dt / 1000.0f);
|
||||
|
||||
|
||||
g_engine->Render();
|
||||
|
||||
// This application only creates a single color renderbuffer which is already bound at this point.
|
||||
@@ -103,18 +113,18 @@ bool checkFramebufferStatus();
|
||||
glDeleteFramebuffers(1, &defaultFramebuffer);
|
||||
defaultFramebuffer = 0;
|
||||
}
|
||||
|
||||
|
||||
if(colorRenderbuffer) {
|
||||
glDeleteRenderbuffers(1, &colorRenderbuffer);
|
||||
colorRenderbuffer = 0;
|
||||
}
|
||||
|
||||
|
||||
glGenFramebuffers(1, &defaultFramebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
||||
|
||||
|
||||
glGenRenderbuffers(1, &colorRenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
|
||||
|
||||
|
||||
// Allocate color buffer backing based on the current layer size
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
|
||||
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
|
||||
@@ -127,41 +137,41 @@ bool checkFramebufferStatus();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE); // do not calculate inside of poly's
|
||||
glFrontFace(GL_CCW);
|
||||
glFrontFace(GL_CCW);
|
||||
glEnable (GL_BLEND);
|
||||
|
||||
|
||||
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)
|
||||
glClearDepthf(1.0f); // Depth Buffer Setup
|
||||
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
bool checkFramebufferStatus() {
|
||||
|
||||
|
||||
GLenum status = (GLenum)glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
|
||||
|
||||
switch(status) {
|
||||
|
||||
|
||||
case GL_FRAMEBUFFER_COMPLETE:
|
||||
return true;
|
||||
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
printf("Framebuffer incomplete,incomplete attachment\n");
|
||||
return false;
|
||||
|
||||
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
printf("Unsupported framebuffer format\n");
|
||||
return false;
|
||||
|
||||
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
printf("Framebuffer incomplete,missing attachment\n");
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -187,7 +197,7 @@ bool checkFramebufferStatus() {
|
||||
|
||||
[context release];
|
||||
context = nil;
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
- (void) updateComplete: (id) notificationMsg
|
||||
{
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
|
||||
[dnc removeObserver: self name: @"coreComplete" object: nil];
|
||||
[dnc removeObserver: self name: @"iosConfigComplete" object: nil];
|
||||
[dnc postNotificationName: @"initializeGame" object: self];
|
||||
@@ -34,12 +34,12 @@
|
||||
- (void) downloadResources
|
||||
{
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
|
||||
[dnc addObserver:self selector:@selector(initIosUpdate:) name:@"coreComplete" object: nil];
|
||||
|
||||
wagicDownloadController = [[WagicDownloadProgressViewController alloc] init];
|
||||
[wagicDownloadController performSelectorInBackground: @selector(startDownload:) withObject:@"core"];
|
||||
|
||||
|
||||
[self.window addSubview: wagicDownloadController.view];
|
||||
[self.window makeKeyWindow];
|
||||
|
||||
@@ -51,16 +51,16 @@
|
||||
NSString *pathPrefix = nil;
|
||||
if ( pathNamePrefix == nil ) // default to User
|
||||
pathPrefix = @"User";
|
||||
else
|
||||
else
|
||||
pathPrefix = pathNamePrefix;
|
||||
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *userDocumentsDirectory = [paths objectAtIndex:0];
|
||||
NSString *downloadFilePath = [userDocumentsDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@/%@.zip", pathPrefix, folderName]];
|
||||
|
||||
|
||||
ZipArchive *za = [[ZipArchive alloc] init];
|
||||
if ([za UnzipOpenFile: downloadFilePath])
|
||||
{
|
||||
@@ -73,7 +73,7 @@
|
||||
NSLog(@"An Error occurred while unpacking zip file.");
|
||||
}
|
||||
[za UnzipCloseFile];
|
||||
|
||||
|
||||
if (ret == YES)
|
||||
{
|
||||
// delete the archive
|
||||
@@ -85,7 +85,7 @@
|
||||
}
|
||||
}
|
||||
[za release], za = nil;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -98,15 +98,15 @@
|
||||
{
|
||||
NSString *pathname = [NSString stringWithFormat: @"%@/%@", path, filename];
|
||||
[data appendFormat: @"%@\n", pathname];
|
||||
|
||||
|
||||
BOOL isDirectory = [[fileManager attributesOfItemAtPath: pathname error: nil] objectForKey: NSFileType] == NSFileTypeDirectory;
|
||||
if (isDirectory)
|
||||
[data appendString: [self getDirContents: pathname]];
|
||||
}
|
||||
|
||||
|
||||
NSString *manifestList = [data stringByAppendingFormat: @"\n"];
|
||||
[data release];
|
||||
|
||||
|
||||
return manifestList;
|
||||
}
|
||||
|
||||
@@ -114,37 +114,37 @@
|
||||
{
|
||||
NSString *manifestFile = [docsPath stringByAppendingPathComponent:@"Manifest"];
|
||||
[[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.
|
||||
If so, move the "core" files into the "Res" directory and move all other zip files into the "User" directory.
|
||||
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.
|
||||
Check for a "core" zip file in the Res directory. If it exists, then return YES. Otherwise, return NO.
|
||||
*/
|
||||
|
||||
- (void) initializeResources
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
|
||||
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *docsPath = [paths objectAtIndex: 0];
|
||||
NSArray *docsPathContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: docsPath error:nil];
|
||||
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]];
|
||||
|
||||
|
||||
NSArray *coreFiles = [docsPathContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat: versionPredicate]];
|
||||
|
||||
NSArray *resourceZipFiles = [docsPathContents filteredArrayUsingPredicate: compoundPredicate];
|
||||
NSString *userPath = [NSString stringWithFormat: @"%@/User", docsPath];
|
||||
NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath];
|
||||
NSError *error = nil;
|
||||
|
||||
|
||||
[compoundPredicate release], compoundPredicate = nil;
|
||||
|
||||
|
||||
if ( ([resourceZipFiles count] > 0 ) && ![fileManager fileExistsAtPath: userPath] )
|
||||
[fileManager createDirectoryAtPath: userPath withIntermediateDirectories: YES attributes:nil error:nil ];
|
||||
|
||||
|
||||
for (NSString *zipFile in resourceZipFiles)
|
||||
{
|
||||
NSString *oldPath = [NSString stringWithFormat: @"%@/%@", docsPath, zipFile];
|
||||
@@ -155,7 +155,7 @@
|
||||
[fileManager removeItemAtPath: newPath error: &error];
|
||||
}
|
||||
error = nil;
|
||||
|
||||
|
||||
[fileManager moveItemAtPath: oldPath toPath:newPath error: &error];
|
||||
NSLog(@"Moving %@ to %@", oldPath, newPath);
|
||||
if ( error != nil )
|
||||
@@ -175,7 +175,7 @@
|
||||
[fileManager removeItemAtPath: newPath error: &error];
|
||||
}
|
||||
error = nil;
|
||||
|
||||
|
||||
[fileManager moveItemAtPath: oldPath toPath:newPath error: &error];
|
||||
NSLog(@"Moving %@ to %@", oldPath, newPath);
|
||||
if ( error != nil )
|
||||
@@ -187,21 +187,21 @@
|
||||
}
|
||||
|
||||
- (BOOL) hasResourceFiles
|
||||
{
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *docsPath = [paths objectAtIndex: 0];
|
||||
NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath];
|
||||
|
||||
|
||||
NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil];
|
||||
NSString *versionPredicate = [NSString stringWithFormat: @"(self BEGINSWITH '%@')", [NSString stringWithCString: WAGIC_CORE_VERSION_STRING encoding:NSUTF8StringEncoding]];
|
||||
|
||||
NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat: versionPredicate]];
|
||||
|
||||
|
||||
if ([coreFiles count] >= 2)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -211,30 +211,30 @@
|
||||
NSString *docsPath = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0];
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *userPath = [docsPath stringByAppendingString: @"/User"];
|
||||
|
||||
|
||||
NSArray *userDirectories = [fm contentsOfDirectoryAtPath: userPath error: nil];
|
||||
|
||||
for (NSString *userFilename in userDirectories)
|
||||
{
|
||||
NSString *userPathname = [userPath stringByAppendingFormat: @"/%@", userFilename];
|
||||
NSString *zipFileName = [userPathname stringByAppendingString: @".zip"];
|
||||
|
||||
|
||||
if ([[fm attributesOfItemAtPath: userPathname error: nil] objectForKey: NSFileType] == NSFileTypeDirectory && ([fm fileExistsAtPath:zipFileName]))
|
||||
{
|
||||
[self unpackageResources: userFilename pathPrefixName: @"User"];
|
||||
[fm removeItemAtPath: zipFileName error: nil];
|
||||
}
|
||||
|
||||
|
||||
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"];
|
||||
}
|
||||
}
|
||||
// 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:
|
||||
[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] 'tasks' AND SELF ENDSWITH '.dat'"],
|
||||
NSArray *playerDataFilePredicates = [NSArray arrayWithObjects:
|
||||
[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] 'tasks' AND SELF ENDSWITH '.dat'"],
|
||||
[NSPredicate predicateWithFormat: @"SELF BEGINSWITH[cd] 'collection' AND SELF ENDSWITH '.dat'"], nil];
|
||||
|
||||
NSCompoundPredicate *playerDataPredicate = [[NSCompoundPredicate alloc] initWithType:NSOrPredicateType subpredicates: playerDataFilePredicates];
|
||||
@@ -246,23 +246,23 @@
|
||||
NSString *toPath = [docsPath stringByAppendingFormat: @"/User/player/%@", [file lowercaseString]];
|
||||
[fm moveItemAtPath: fromPath toPath: toPath error: nil];
|
||||
}
|
||||
|
||||
|
||||
[playerDataPredicate release], playerDataPredicate = nil;
|
||||
|
||||
|
||||
[self createManifest: docsPath];
|
||||
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"readyToStartGame" object: nil];
|
||||
}
|
||||
|
||||
|
||||
- (void) startGame
|
||||
{
|
||||
if (glViewController != nil)
|
||||
if (glViewController != nil)
|
||||
[glViewController release];
|
||||
glViewController = [[EAGLViewController alloc] init];
|
||||
|
||||
|
||||
[[[self.window subviews] lastObject] removeFromSuperview];
|
||||
[self.window addSubview:self.glViewController.view];
|
||||
[self.window setRootViewController: glViewController];
|
||||
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
[dnc removeObserver: self name: @"intializeGame" object: nil];
|
||||
@@ -286,7 +286,7 @@
|
||||
[internetReach release];
|
||||
[glViewController release];
|
||||
[wagicDownloadController release];
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -298,23 +298,23 @@
|
||||
hostReach = [[Reachability reachabilityForGoogleDNS] retain];
|
||||
internetReach = [[Reachability reachabilityForInternetConnection] retain];
|
||||
wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
|
||||
|
||||
|
||||
[hostReach startNotifier];
|
||||
[internetReach startNotifier];
|
||||
[wifiReach startNotifier];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
self.glViewController = nil;
|
||||
|
||||
|
||||
[self setupNetworkListeners];
|
||||
|
||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||
[dnc addObserver:self selector:@selector(preGameInitialization) name:@"initializeGame" object: nil];
|
||||
[dnc addObserver:self selector:@selector(startGame) name:@"readyToStartGame" object: nil];
|
||||
|
||||
|
||||
[self initializeResources];
|
||||
// check to see if the Res folder exists. If it does continue
|
||||
// otherwise bring up the download dialog and download the core files
|
||||
@@ -328,7 +328,7 @@
|
||||
{
|
||||
[self preGameInitialization];
|
||||
}
|
||||
|
||||
|
||||
[self.window setBackgroundColor: [UIColor blackColor]];
|
||||
[self.window makeKeyAndVisible];
|
||||
|
||||
@@ -337,7 +337,7 @@
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application
|
||||
{
|
||||
[self.glViewController.view destroyGame];
|
||||
[self.glViewController.view destroyGame];
|
||||
}
|
||||
|
||||
- (void)initializeKeyboard: (id) initialState
|
||||
@@ -345,31 +345,18 @@
|
||||
[self.glViewController toggleKeyboardWithState: initialState];
|
||||
}
|
||||
|
||||
- (void) handleWEngineCommand:(NSString *) command
|
||||
withUIParameters: (CGFloat) x
|
||||
yCoordinate: (CGFloat) y
|
||||
width: (CGFloat) width
|
||||
- (void) handleWEngineCommand:(NSString *) command
|
||||
withUIParameters: (CGFloat) x
|
||||
yCoordinate: (CGFloat) y
|
||||
width: (CGFloat) width
|
||||
height: (CGFloat) height
|
||||
{
|
||||
}
|
||||
|
||||
- (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter
|
||||
{
|
||||
BOOL isDevicePhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone;
|
||||
|
||||
if ([command isEqualToString: @"entergamestate:menu"] )
|
||||
[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"])
|
||||
if ([command isEqualToString: @"displayKeyboard"])
|
||||
{
|
||||
[self initializeKeyboard: parameter];
|
||||
}
|
||||
@@ -379,16 +366,17 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
||||
{
|
||||
bool isPhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone;
|
||||
|
||||
if (isPhone)
|
||||
|
||||
if (isPhone)
|
||||
{
|
||||
UIImage *bgImage = [UIImage imageNamed: @"Default-Portrait.png"];
|
||||
[[[self.window subviews] objectAtIndex: 0] setBackgroundColor: [UIColor colorWithPatternImage: bgImage]];
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
[self.window setBackgroundColor: [UIColor clearColor]];
|
||||
if (UIInterfaceOrientationIsLandscape( toInterfaceOrientation)) {
|
||||
@@ -410,12 +398,12 @@
|
||||
{
|
||||
BOOL netAvailable = NO;
|
||||
//NSDate *startTime = [[[NSDate alloc ] init] autorelease];
|
||||
|
||||
|
||||
hostReach = [[Reachability reachabilityForGoogleDNS] retain];
|
||||
|
||||
|
||||
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
|
||||
|
||||
|
||||
|
||||
|
||||
if (netStatus == ReachableViaWiFi || netStatus == ReachableViaWWAN) {
|
||||
netAvailable = YES;
|
||||
}
|
||||
|
||||
@@ -310,10 +310,13 @@ void JQuad::SetTextureRect(float x, float y, float w, float h)
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
|
||||
mTX0 = x/mTex->mTexWidth;
|
||||
mTY0 = y/mTex->mTexHeight;
|
||||
mTX1 = (x+w)/mTex->mTexWidth;
|
||||
mTY1 = (y+h)/mTex->mTexHeight;
|
||||
if(mTex)
|
||||
{
|
||||
mTX0 = x/mTex->mTexWidth;
|
||||
mTY0 = y/mTex->mTexHeight;
|
||||
mTX1 = (x+w)/mTex->mTexWidth;
|
||||
mTY1 = (y+h)/mTex->mTexHeight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -820,7 +823,7 @@ void JRenderer::BeginScene()
|
||||
esMatrixLoadIdentity(&theMvpMatrix);
|
||||
esOrtho(&theMvpMatrix, 0.0f, SCREEN_WIDTH_F, 0.0f, SCREEN_HEIGHT_F-1.0f,-1.0f, 1.0f);
|
||||
#endif //(!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
|
||||
#if (defined WIN32) || ((defined GL_VERSION_ES_CM_1_1) && (!defined IOS))
|
||||
#if (defined WIN32 && !defined GL_ES_VERSION_2_0) || ((defined GL_VERSION_ES_CM_1_1) && (!defined IOS))
|
||||
float scaleH = mActualHeight/SCREEN_HEIGHT_F;
|
||||
float scaleW = mActualWidth/SCREEN_WIDTH_F;
|
||||
if (scaleH != 1.0f || scaleW != 1.0f)
|
||||
@@ -840,7 +843,7 @@ void JRenderer::EndScene()
|
||||
void JRenderer::BindTexture(JTexture *tex)
|
||||
{
|
||||
checkGlError();
|
||||
if (mCurrentTex != tex->mTexId)
|
||||
if (tex && mCurrentTex != tex->mTexId)
|
||||
{
|
||||
mCurrentTex = tex->mTexId;
|
||||
|
||||
@@ -1584,7 +1587,7 @@ void JRenderer::Plot(float x, float y, PIXEL_TYPE color)
|
||||
glEnd();
|
||||
glColor4ub(255, 255, 255, 255);
|
||||
#else
|
||||
// FIXME, not used
|
||||
cerr << x << " " << y << " " << color << endl;
|
||||
#endif //#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
checkGlError();
|
||||
@@ -1606,6 +1609,7 @@ void JRenderer::PlotArray(float *x, float *y, int count, PIXEL_TYPE color)
|
||||
glColor4ub(255, 255, 255, 255);
|
||||
#else
|
||||
// FIXME, not used
|
||||
cerr << x << " " << y << " " << count << " " << " " << color << endl;
|
||||
#endif //#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
checkGlError();
|
||||
@@ -2242,7 +2246,7 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
||||
return tex;
|
||||
}
|
||||
#elif (defined QT_CONFIG)
|
||||
JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused)))
|
||||
JTexture* JRenderer::LoadTexture(const char* filename, int, int)
|
||||
{
|
||||
JTexture *tex = NULL;
|
||||
int rawsize = 0;
|
||||
@@ -2518,7 +2522,7 @@ void JRenderer::Enable3D()
|
||||
}
|
||||
|
||||
|
||||
void JRenderer::SetClip(int x, int y, int width, int height)
|
||||
void JRenderer::SetClip(int, int, int, int)
|
||||
{// NOT USED
|
||||
//glScissor(x, y, width, height);
|
||||
}
|
||||
@@ -2530,25 +2534,25 @@ void JRenderer::LoadIdentity()
|
||||
}
|
||||
|
||||
|
||||
void JRenderer::Translate(float x, float y, float z)
|
||||
void JRenderer::Translate(float, float, float)
|
||||
{// NOT USED
|
||||
//glTranslatef(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
void JRenderer::RotateX(float angle)
|
||||
void JRenderer::RotateX(float)
|
||||
{// NOT USED
|
||||
//glRotatef(angle*RAD2DEG, 1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
void JRenderer::RotateY(float angle)
|
||||
void JRenderer::RotateY(float)
|
||||
{// NOT USED
|
||||
//glRotatef(angle*RAD2DEG, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
void JRenderer::RotateZ(float angle)
|
||||
void JRenderer::RotateZ(float)
|
||||
{// NOT USED
|
||||
//glRotatef(angle*RAD2DEG, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
@@ -174,6 +174,7 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
|
||||
}
|
||||
return music;
|
||||
#else
|
||||
cerr << fileName << endl;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
@@ -203,6 +204,9 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
||||
else
|
||||
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF);
|
||||
}
|
||||
#else
|
||||
music = 0;
|
||||
looping = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -216,6 +220,8 @@ void JSoundSystem::StopMusic(JMusic *music)
|
||||
}
|
||||
#elif (defined WITH_FMOD)
|
||||
FSOUND_StopSound(mChannel);
|
||||
#else
|
||||
music = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -290,6 +296,7 @@ JSample *JSoundSystem::LoadSample(const char *fileName)
|
||||
}
|
||||
return sample;
|
||||
#else
|
||||
cerr << fileName << endl;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
@@ -308,6 +315,8 @@ void JSoundSystem::PlaySample(JSample *sample)
|
||||
int channel = FSOUND_PlaySound(FSOUND_FREE, sample->mSample);
|
||||
FSOUND_SetVolumeAbsolute(channel, static_cast<int>(mSampleVolume * 2.55));
|
||||
}
|
||||
#else
|
||||
sample = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,6 @@
|
||||
|
||||
#include "../../include/JSocket.h"
|
||||
#include "../../include/DebugRoutines.h"
|
||||
//JSocket * JSocket::mInstance = NULL;
|
||||
|
||||
//#define SERVER_PORT 20666
|
||||
#define SERVER_PORT 5001
|
||||
unsigned char ADRESSE_IP_SERVEUR [4] = {127,0,0,1};
|
||||
|
||||
|
||||
JSocket::JSocket(string ipAddr)
|
||||
@@ -28,7 +23,7 @@ JSocket::JSocket(string ipAddr)
|
||||
mfd(-1)
|
||||
{
|
||||
int result;
|
||||
struct hostent *hostentptr;
|
||||
struct hostent *hostentptr = 0;
|
||||
#ifdef WIN32
|
||||
SOCKADDR_IN Adresse_Socket_Server;
|
||||
WORD wVersionRequested;
|
||||
@@ -264,9 +259,17 @@ int JSocket::Read(char* buff, int size)
|
||||
#endif //WINDOWS
|
||||
if(readbytes < 0)
|
||||
{
|
||||
DebugTrace("Error reading from socket\n");
|
||||
#ifdef WIN32
|
||||
DebugTrace("Error reading from socket: " << WSAGetLastError());
|
||||
#endif //WINDOWS
|
||||
Disconnect();
|
||||
return -1;
|
||||
}
|
||||
else if(readbytes == 0)
|
||||
{
|
||||
Disconnect();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return readbytes;
|
||||
}
|
||||
@@ -303,6 +306,7 @@ int JSocket::Write(char* buff, int size)
|
||||
}
|
||||
else if (result < 0)
|
||||
{
|
||||
Disconnect();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
#include "corewrapper.h"
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#ifdef TESTSUITE
|
||||
#include "TestSuiteAI.h"
|
||||
#include "GameOptions.h"
|
||||
#include "MTGDeck.h"
|
||||
#endif
|
||||
#include "DebugRoutines.h"
|
||||
|
||||
#if (defined FORCE_GLES)
|
||||
#undef GL_ES_VERSION_2_0
|
||||
#undef GL_VERSION_2_0
|
||||
@@ -72,6 +79,64 @@ WagicCore::WagicCore(super *parent) :
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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 WagicCore::runTestSuite()
|
||||
{
|
||||
int result = 0;
|
||||
#ifdef TESTSUITE
|
||||
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;
|
||||
#endif
|
||||
DebugTrace("TestSuite done: failed test: " << result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void WagicCore::initApp()
|
||||
{
|
||||
if(!m_engine)
|
||||
@@ -467,12 +532,12 @@ void WagicCore::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void WagicCore::showEvent ( QShowEvent * event )
|
||||
void WagicCore::showEvent ( QShowEvent * )
|
||||
{
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
void WagicCore::hideEvent ( QHideEvent * event )
|
||||
void WagicCore::hideEvent ( QHideEvent * )
|
||||
{
|
||||
setActive(false);
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ void FileDownloader::computeRemoteHash()
|
||||
} else {
|
||||
QString aString = m_hashReply->readAll();
|
||||
|
||||
int index = aString.indexOf("SHA1 Checksum: ");
|
||||
m_remoteHash = aString.mid(index+52, 40);
|
||||
int index = aString.indexOf("<span id=\"sha1\">");
|
||||
m_remoteHash = aString.mid(index+16, 40);
|
||||
if(m_localHash != m_remoteHash)
|
||||
{ /* We download the real file */
|
||||
m_state = DOWNLOADING_FILE;
|
||||
|
||||
@@ -1,256 +1,256 @@
|
||||
// bfileio.h: interface for the binary file i/o.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2004 Tanguy Fautré.
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautré
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// File I/O Facilities.
|
||||
// ********************
|
||||
//
|
||||
// Current version: 1.00 BETA 4 (16/07/2004)
|
||||
//
|
||||
// Comment: readvar() and writevar() read a little endian ordered
|
||||
// value on a file and put it in a variable.
|
||||
// search_iterator only accepts "<directory>/*.<ext>".
|
||||
// Uses ANSI C "assert()". Define NDEBUG to turn it off.
|
||||
// (note: Visual C++ define NDEBUG in Release mode)
|
||||
//
|
||||
// History: - 1.00 BETA 4 (16/07/2004) - Fixed small bug in UNIX search_iterator
|
||||
// - 1.00 BETA 3 (27/06/2004) - Added UNIX compatibility
|
||||
// - 1.00 BETA 2 (21/02/2003) - Now endianess independent
|
||||
// - 1.00 BETA 1 (06/09/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#if defined WIN32
|
||||
#include <io.h> // Windows I/O facilities (Directories)
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
namespace io_facilities {
|
||||
|
||||
|
||||
|
||||
|
||||
// Global function for reading binary variables
|
||||
template <class T> std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes);
|
||||
template <class T> std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes);
|
||||
|
||||
|
||||
|
||||
// Class for searching files and directories
|
||||
// (!!! not compliant with C++ std::iterator and is thus meant for specific use !!!)
|
||||
class search_iterator
|
||||
{
|
||||
public:
|
||||
search_iterator();
|
||||
search_iterator(const char * FileSpec);
|
||||
~search_iterator();
|
||||
|
||||
operator bool () const;
|
||||
search_iterator & operator ++ ();
|
||||
search_iterator & begin(const char * FileSpec);
|
||||
search_iterator & next();
|
||||
bool end() const;
|
||||
std::string Name() const;
|
||||
|
||||
protected:
|
||||
bool m_Valid;
|
||||
|
||||
#if defined WIN32
|
||||
intptr_t m_hFiles;
|
||||
_finddata_t m_FindData;
|
||||
#else
|
||||
DIR * m_Directory;
|
||||
std::string m_Extension;
|
||||
struct dirent * m_DirectoryEntry;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// io_facilities:: Inline Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes)
|
||||
{
|
||||
// Debug test to ensure type size is big enough
|
||||
assert(sizeof(T) >= size_t(NbBytes));
|
||||
|
||||
// Var = 0 ensure type size won't matter
|
||||
T TmpVar = Var = 0;
|
||||
|
||||
for (std::streamsize i = 0; i < NbBytes; ++i) {
|
||||
File.read(reinterpret_cast<char *>(&TmpVar), 1);
|
||||
Var |= TmpVar << (i * CHAR_BIT);
|
||||
}
|
||||
|
||||
return File;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
inline std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes)
|
||||
{
|
||||
// Debug test to ensure type size is big enough
|
||||
assert(sizeof(T) >= size_t(NbBytes));
|
||||
|
||||
T TmpVar = Var;
|
||||
|
||||
for (std::streamsize i = 0; i < NbBytes; ++i)
|
||||
File.write(reinterpret_cast<const char *>(&(TmpVar >>= (CHAR_BIT * i))), 1);
|
||||
|
||||
return File;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// io_facilities::search_iterator Inline Member Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline search_iterator::search_iterator()
|
||||
: m_Valid(false),
|
||||
#if defined WIN32
|
||||
m_hFiles(-1)
|
||||
#else
|
||||
m_Directory(NULL)
|
||||
#endif
|
||||
{ }
|
||||
|
||||
inline search_iterator::search_iterator(const char * FileSpec)
|
||||
: m_Valid(false),
|
||||
#if defined WIN32
|
||||
m_hFiles(-1)
|
||||
#else
|
||||
m_Directory(NULL)
|
||||
#endif
|
||||
{
|
||||
begin(FileSpec);
|
||||
}
|
||||
|
||||
inline search_iterator::~search_iterator() {
|
||||
#if defined WIN32
|
||||
if (m_hFiles != -1) _findclose(m_hFiles);
|
||||
#else
|
||||
if (m_Directory != NULL) closedir(m_Directory);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline search_iterator::operator bool () const {
|
||||
return m_Valid;
|
||||
}
|
||||
|
||||
inline search_iterator & search_iterator::operator ++ () {
|
||||
return next();
|
||||
}
|
||||
|
||||
inline search_iterator & search_iterator::begin(const char * FileSpec) {
|
||||
#if defined WIN32
|
||||
if (m_hFiles != -1) _findclose(m_hFiles);
|
||||
m_Valid = ((m_hFiles = _findfirst(FileSpec, &m_FindData)) != -1);
|
||||
#else
|
||||
std::string DirectoryName;
|
||||
|
||||
if (m_Directory != NULL) closedir(m_Directory);
|
||||
|
||||
int i;
|
||||
for (i = strlen(FileSpec); i >= 0; --i)
|
||||
if (FileSpec[i] == '/') break;
|
||||
|
||||
if (i < 0)
|
||||
DirectoryName = ".";
|
||||
else
|
||||
DirectoryName.assign(FileSpec + 0, FileSpec + i++);
|
||||
|
||||
m_Extension = FileSpec + i + 1;
|
||||
std::transform(m_Extension.begin(), m_Extension.end(), m_Extension.begin(), ::tolower);
|
||||
m_Valid = ((m_Directory = opendir(DirectoryName.c_str())) != NULL);
|
||||
|
||||
if (! m_Valid)
|
||||
return (* this);
|
||||
|
||||
next();
|
||||
#endif
|
||||
|
||||
return (* this);
|
||||
}
|
||||
|
||||
inline bool search_iterator::end() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
inline search_iterator & search_iterator::next() {
|
||||
#if defined WIN32
|
||||
m_Valid = (_findnext(m_hFiles, &m_FindData) != -1);
|
||||
#else
|
||||
bool Found = false;
|
||||
while (! Found) {
|
||||
m_Valid = ((m_DirectoryEntry = readdir(m_Directory)) != NULL);
|
||||
if (m_Valid) {
|
||||
std::string FileName = m_DirectoryEntry->d_name;
|
||||
if (FileName[0] == '.')
|
||||
Found = false;
|
||||
else if (FileName.size() <= m_Extension.size())
|
||||
Found = false;
|
||||
else {
|
||||
std::transform(FileName.begin(), FileName.end(), FileName.begin(), ::tolower);
|
||||
if (std::equal(m_Extension.rbegin(), m_Extension.rend(), FileName.rbegin()))
|
||||
Found = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (* this);
|
||||
}
|
||||
|
||||
inline std::string search_iterator::Name() const {
|
||||
#if defined WIN32
|
||||
return (m_FindData.name);
|
||||
#else
|
||||
return (m_DirectoryEntry->d_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace io_facilities
|
||||
|
||||
|
||||
// bfileio.h: interface for the binary file i/o.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2004 Tanguy Fautre
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautr<EFBFBD>E
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// File I/O Facilities.
|
||||
// ********************
|
||||
//
|
||||
// Current version: 1.00 BETA 4 (16/07/2004)
|
||||
//
|
||||
// Comment: readvar() and writevar() read a little endian ordered
|
||||
// value on a file and put it in a variable.
|
||||
// search_iterator only accepts "<directory>/*.<ext>".
|
||||
// Uses ANSI C "assert()". Define NDEBUG to turn it off.
|
||||
// (note: Visual C++ define NDEBUG in Release mode)
|
||||
//
|
||||
// History: - 1.00 BETA 4 (16/07/2004) - Fixed small bug in UNIX search_iterator
|
||||
// - 1.00 BETA 3 (27/06/2004) - Added UNIX compatibility
|
||||
// - 1.00 BETA 2 (21/02/2003) - Now endianess independent
|
||||
// - 1.00 BETA 1 (06/09/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#if defined WIN32
|
||||
#include <io.h> // Windows I/O facilities (Directories)
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
namespace io_facilities {
|
||||
|
||||
|
||||
|
||||
|
||||
// Global function for reading binary variables
|
||||
template <class T> std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes);
|
||||
template <class T> std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes);
|
||||
|
||||
|
||||
|
||||
// Class for searching files and directories
|
||||
// (!!! not compliant with C++ std::iterator and is thus meant for specific use !!!)
|
||||
class search_iterator
|
||||
{
|
||||
public:
|
||||
search_iterator();
|
||||
search_iterator(const char * FileSpec);
|
||||
~search_iterator();
|
||||
|
||||
operator bool () const;
|
||||
search_iterator & operator ++ ();
|
||||
search_iterator & begin(const char * FileSpec);
|
||||
search_iterator & next();
|
||||
bool end() const;
|
||||
std::string Name() const;
|
||||
|
||||
protected:
|
||||
bool m_Valid;
|
||||
|
||||
#if defined WIN32
|
||||
intptr_t m_hFiles;
|
||||
_finddata_t m_FindData;
|
||||
#else
|
||||
DIR * m_Directory;
|
||||
std::string m_Extension;
|
||||
struct dirent * m_DirectoryEntry;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// io_facilities:: Inline Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes)
|
||||
{
|
||||
// Debug test to ensure type size is big enough
|
||||
assert(sizeof(T) >= size_t(NbBytes));
|
||||
|
||||
// Var = 0 ensure type size won't matter
|
||||
T TmpVar = Var = 0;
|
||||
|
||||
for (std::streamsize i = 0; i < NbBytes; ++i) {
|
||||
File.read(reinterpret_cast<char *>(&TmpVar), 1);
|
||||
Var |= TmpVar << (i * CHAR_BIT);
|
||||
}
|
||||
|
||||
return File;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
inline std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes)
|
||||
{
|
||||
// Debug test to ensure type size is big enough
|
||||
assert(sizeof(T) >= size_t(NbBytes));
|
||||
|
||||
T TmpVar = Var;
|
||||
|
||||
for (std::streamsize i = 0; i < NbBytes; ++i)
|
||||
File.write(reinterpret_cast<const char *>(&(TmpVar >>= (CHAR_BIT * i))), 1);
|
||||
|
||||
return File;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// io_facilities::search_iterator Inline Member Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline search_iterator::search_iterator()
|
||||
: m_Valid(false),
|
||||
#if defined WIN32
|
||||
m_hFiles(-1)
|
||||
#else
|
||||
m_Directory(NULL)
|
||||
#endif
|
||||
{ }
|
||||
|
||||
inline search_iterator::search_iterator(const char * FileSpec)
|
||||
: m_Valid(false),
|
||||
#if defined WIN32
|
||||
m_hFiles(-1)
|
||||
#else
|
||||
m_Directory(NULL)
|
||||
#endif
|
||||
{
|
||||
begin(FileSpec);
|
||||
}
|
||||
|
||||
inline search_iterator::~search_iterator() {
|
||||
#if defined WIN32
|
||||
if (m_hFiles != -1) _findclose(m_hFiles);
|
||||
#else
|
||||
if (m_Directory != NULL) closedir(m_Directory);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline search_iterator::operator bool () const {
|
||||
return m_Valid;
|
||||
}
|
||||
|
||||
inline search_iterator & search_iterator::operator ++ () {
|
||||
return next();
|
||||
}
|
||||
|
||||
inline search_iterator & search_iterator::begin(const char * FileSpec) {
|
||||
#if defined WIN32
|
||||
if (m_hFiles != -1) _findclose(m_hFiles);
|
||||
m_Valid = ((m_hFiles = _findfirst(FileSpec, &m_FindData)) != -1);
|
||||
#else
|
||||
std::string DirectoryName;
|
||||
|
||||
if (m_Directory != NULL) closedir(m_Directory);
|
||||
|
||||
int i;
|
||||
for (i = strlen(FileSpec); i >= 0; --i)
|
||||
if (FileSpec[i] == '/') break;
|
||||
|
||||
if (i < 0)
|
||||
DirectoryName = ".";
|
||||
else
|
||||
DirectoryName.assign(FileSpec + 0, FileSpec + i++);
|
||||
|
||||
m_Extension = FileSpec + i + 1;
|
||||
std::transform(m_Extension.begin(), m_Extension.end(), m_Extension.begin(), ::tolower);
|
||||
m_Valid = ((m_Directory = opendir(DirectoryName.c_str())) != NULL);
|
||||
|
||||
if (! m_Valid)
|
||||
return (* this);
|
||||
|
||||
next();
|
||||
#endif
|
||||
|
||||
return (* this);
|
||||
}
|
||||
|
||||
inline bool search_iterator::end() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
inline search_iterator & search_iterator::next() {
|
||||
#if defined WIN32
|
||||
m_Valid = (_findnext(m_hFiles, &m_FindData) != -1);
|
||||
#else
|
||||
bool Found = false;
|
||||
while (! Found) {
|
||||
m_Valid = ((m_DirectoryEntry = readdir(m_Directory)) != NULL);
|
||||
if (m_Valid) {
|
||||
std::string FileName = m_DirectoryEntry->d_name;
|
||||
if (FileName[0] == '.')
|
||||
Found = false;
|
||||
else if (FileName.size() <= m_Extension.size())
|
||||
Found = false;
|
||||
else {
|
||||
std::transform(FileName.begin(), FileName.end(), FileName.begin(), ::tolower);
|
||||
if (std::equal(m_Extension.rbegin(), m_Extension.rend(), FileName.rbegin()))
|
||||
Found = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (* this);
|
||||
}
|
||||
|
||||
inline std::string search_iterator::Name() const {
|
||||
#if defined WIN32
|
||||
return (m_FindData.name);
|
||||
#else
|
||||
return (m_DirectoryEntry->d_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace io_facilities
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// zfsystem.cpp: implementation of the zip file system classes.
|
||||
//
|
||||
// Copyright (C) 2004 Tanguy Fautré.
|
||||
// Copyright (C) 2004 Tanguy Fautre
|
||||
// For conditions of distribution and use,
|
||||
// see copyright notice in zfsystem.h
|
||||
//
|
||||
|
||||
@@ -1,332 +1,332 @@
|
||||
//Important: This file has been modified in order to be integrated in to JGE++
|
||||
//
|
||||
|
||||
// zfsystem.h: interface for the zip file system classes.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2004 Tanguy Fautré.
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautré
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip File System.
|
||||
// ****************
|
||||
//
|
||||
// Current version: 1.00 BETA 2 (16/07/2004)
|
||||
//
|
||||
// Comment: -
|
||||
//
|
||||
// History: - 1.00 BETA 2 (16/07/2004) - Updated to follow latest version
|
||||
// of fileio.h
|
||||
// - 1.00 BETA 1 (21/07/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ziphdr.h" // Zip file header
|
||||
#include "zstream.h" // Zip Stream
|
||||
|
||||
|
||||
|
||||
// Zip File System Namespace
|
||||
namespace zip_file_system {
|
||||
|
||||
|
||||
|
||||
|
||||
class filesystem;
|
||||
|
||||
|
||||
|
||||
// Input Zip File class
|
||||
class izfstream : public izstream
|
||||
{
|
||||
public:
|
||||
izfstream(filesystem * pFS = pDefaultFS);
|
||||
izfstream(const char * FilePath, filesystem * pFS = pDefaultFS);
|
||||
|
||||
void open(const char * FilePath, filesystem * pFS = pDefaultFS);
|
||||
void close();
|
||||
|
||||
bool is_open() const;
|
||||
|
||||
void setFS(filesystem * pFS = pDefaultFS);
|
||||
|
||||
bool Zipped() const;
|
||||
bool isBeingUsed() const;
|
||||
const std::string & FilePath() const;
|
||||
const std::string & FullFilePath() const;
|
||||
size_t getUncompSize();
|
||||
size_t getOffset();
|
||||
size_t getCompSize();
|
||||
|
||||
protected:
|
||||
friend class filesystem;
|
||||
|
||||
// Default File System Pointer (default = NULL)
|
||||
static filesystem * pDefaultFS;
|
||||
|
||||
std::string m_FilePath;
|
||||
std::string m_FullFilePath;
|
||||
filesystem * m_pFS;
|
||||
bool m_Zipped;
|
||||
size_t m_UncompSize;
|
||||
size_t m_Offset;
|
||||
size_t m_CompSize;
|
||||
bool m_Used;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// Zip File System central class
|
||||
class filesystem
|
||||
{
|
||||
public:
|
||||
// "local" file info class
|
||||
class file_info
|
||||
{
|
||||
public:
|
||||
file_info() : m_PackID(0), m_Offset(0), m_Size(0), m_CompSize(0), m_CompMethod(0), m_Directory(true) { }
|
||||
file_info(size_t PackID, size_t Offset, size_t Size, size_t CompSize, short CompMethod, bool Directory) :
|
||||
m_PackID(PackID), m_Offset(Offset), m_Size(Size), m_CompSize(CompSize), m_CompMethod(CompMethod), m_Directory(Directory) { }
|
||||
|
||||
size_t m_PackID;
|
||||
size_t m_Offset;
|
||||
size_t m_Size;
|
||||
size_t m_CompSize;
|
||||
short m_CompMethod;
|
||||
bool m_Directory;
|
||||
};
|
||||
|
||||
class limited_file_info
|
||||
{
|
||||
public:
|
||||
limited_file_info() : m_Offset(0), m_Size(0) { }
|
||||
limited_file_info(size_t Offset, size_t Size) :
|
||||
m_Offset(Offset), m_Size(Size) { }
|
||||
|
||||
size_t m_Offset;
|
||||
size_t m_Size;
|
||||
};
|
||||
|
||||
class pooledBuffer
|
||||
{
|
||||
public:
|
||||
pooledBuffer(std::string filename, std::string externalFilename ) : filename(filename), externalFilename(externalFilename), buffer(NULL) {}
|
||||
~pooledBuffer() { if (buffer) { delete buffer; } }
|
||||
std::string filename;
|
||||
std::string externalFilename;
|
||||
zbuffer * buffer;
|
||||
};
|
||||
|
||||
|
||||
filesystem(const char * BasePath = "", const char * FileExt = "zip", bool DefaultFS = true);
|
||||
~filesystem();
|
||||
|
||||
void MakeDefault();
|
||||
void Open(izfstream & File, const char * Filename);
|
||||
bool DirExists(const std::string & folderName);
|
||||
bool FileExists(const std::string & fileName);
|
||||
bool PreloadZip(const char * Filename, std::map<std::string, limited_file_info>& target);
|
||||
static std::string getCurrentZipName();
|
||||
static filesystem * getCurrentFS();
|
||||
static std::streamoff SkipLFHdr(std::istream & File, std::streamoff LFHdrPos);
|
||||
void unuse(izfstream & File);
|
||||
|
||||
//Fills the vector results with a list of children of the given folder
|
||||
std::vector<std::string>& scanfolder(const std::string& folderName, std::vector<std::string>& results);
|
||||
|
||||
friend std::ostream & operator << (std::ostream & Out, const filesystem & FS);
|
||||
static void closeTempFiles();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
// Zip file info class
|
||||
class zipfile_info
|
||||
{
|
||||
public:
|
||||
zipfile_info() : m_NbEntries(0), m_FilesSize(0), m_FilesCompSize(0) { }
|
||||
|
||||
std::string m_Filename;
|
||||
size_t m_NbEntries;
|
||||
size_t m_FilesSize;
|
||||
size_t m_FilesCompSize;
|
||||
};
|
||||
|
||||
// Class for file path string comparaison
|
||||
struct lt_path
|
||||
{
|
||||
bool operator() (const std::string & s1, const std::string & s2) const;
|
||||
};
|
||||
|
||||
|
||||
// Protected member functions
|
||||
// Zip file format related functions
|
||||
std::streamoff CentralDir(std::istream & File) const;
|
||||
std::streamoff CentralDirZipped(std::istream & File, std::streamoff begin, std::size_t size) const;
|
||||
headerid NextHeader(std::istream & File) const;
|
||||
|
||||
// File/Zip map related functions
|
||||
bool FileNotZipped(const char * FilePath) const;
|
||||
bool FindFile(const char * Filename, file_info * FileInfo) const;
|
||||
const std::string & FindZip(size_t PackID) const;
|
||||
void InsertZip(const char * Filename, const size_t PackID);
|
||||
|
||||
static zbuffer * getValidBuffer(const std::string & filename, const std::string & externalFilename, std::streamoff Offset = 0, std::streamoff Size = 0);
|
||||
static void closeBufferPool();
|
||||
|
||||
// New type definitions
|
||||
typedef std::map<size_t, zipfile_info> zipmap;
|
||||
typedef std::map<size_t, zipfile_info>::iterator zipmap_iterator;
|
||||
typedef std::map<size_t, zipfile_info>::const_iterator zipmap_const_iterator;
|
||||
typedef std::map<std::string, file_info, lt_path> filemap;
|
||||
typedef std::map<std::string, file_info, lt_path>::iterator filemap_iterator;
|
||||
typedef std::map<std::string, file_info, lt_path>::const_iterator filemap_const_iterator;
|
||||
|
||||
// Mighty protected member variables
|
||||
std::string m_BasePath;
|
||||
std::string m_FileExt;
|
||||
zipmap m_Zips;
|
||||
filemap m_Files;
|
||||
static std::vector<pooledBuffer *> m_Buffers;
|
||||
static std::ifstream CurrentZipFile;
|
||||
static std::string CurrentZipName;
|
||||
static filesystem * pCurrentFS;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// zip_file_system::izfile Inline Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline izfstream::izfstream(filesystem * pFS) : m_pFS(pFS) { }
|
||||
|
||||
inline izfstream::izfstream(const char * FilePath, filesystem * pFS) : m_pFS(pFS) {
|
||||
open(FilePath);
|
||||
}
|
||||
|
||||
inline void izfstream::setFS(filesystem * pFS) {
|
||||
m_pFS = pFS;
|
||||
}
|
||||
|
||||
inline size_t izfstream::getUncompSize()
|
||||
{
|
||||
return m_UncompSize;
|
||||
}
|
||||
|
||||
inline size_t izfstream::getOffset()
|
||||
{
|
||||
return m_Offset;
|
||||
}
|
||||
|
||||
inline size_t izfstream::getCompSize()
|
||||
{
|
||||
return m_CompSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void izfstream::open(const char * FilePath, filesystem * pFS) {
|
||||
if (pFS)
|
||||
m_pFS = pFS;
|
||||
|
||||
if (m_pFS != NULL)
|
||||
m_pFS->Open(* this, FilePath);
|
||||
}
|
||||
|
||||
inline void izfstream::close() {
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
if (m_pFS)
|
||||
m_pFS->unuse( * this);
|
||||
#else
|
||||
izstream::close();
|
||||
#endif
|
||||
m_FilePath = m_FullFilePath = "";
|
||||
m_UncompSize = 0;
|
||||
}
|
||||
|
||||
inline bool izfstream::is_open() const {
|
||||
return static_cast<zbuffer *>(rdbuf())->is_open();
|
||||
}
|
||||
|
||||
inline bool izfstream::Zipped() const {
|
||||
return m_Zipped;
|
||||
}
|
||||
|
||||
inline bool izfstream::isBeingUsed() const {
|
||||
return m_Used;
|
||||
}
|
||||
|
||||
inline const std::string & izfstream::FilePath() const {
|
||||
return m_FilePath;
|
||||
}
|
||||
|
||||
inline const std::string & izfstream::FullFilePath() const {
|
||||
return m_FullFilePath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// zip_file_system::filesystem Inline Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline filesystem::~filesystem() {
|
||||
// Security mesure with izfile::pDefaultFS
|
||||
if (izfstream::pDefaultFS == this)
|
||||
izfstream::pDefaultFS = NULL;
|
||||
}
|
||||
|
||||
inline void filesystem::closeTempFiles() {
|
||||
if (CurrentZipName.size())
|
||||
{
|
||||
CurrentZipFile.close();
|
||||
CurrentZipName = "";
|
||||
}
|
||||
closeBufferPool();
|
||||
}
|
||||
inline void filesystem::MakeDefault() {
|
||||
izfstream::pDefaultFS = this;
|
||||
}
|
||||
|
||||
|
||||
inline std::string filesystem::getCurrentZipName()
|
||||
{
|
||||
return CurrentZipName;
|
||||
}
|
||||
|
||||
inline filesystem * filesystem::getCurrentFS()
|
||||
{
|
||||
return pCurrentFS;
|
||||
}
|
||||
|
||||
} // namespace zip_file_system
|
||||
|
||||
//Important: This file has been modified in order to be integrated in to JGE++
|
||||
//
|
||||
|
||||
// zfsystem.h: interface for the zip file system classes.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2004 Tanguy Fautre
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautr<EFBFBD>E
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip File System.
|
||||
// ****************
|
||||
//
|
||||
// Current version: 1.00 BETA 2 (16/07/2004)
|
||||
//
|
||||
// Comment: -
|
||||
//
|
||||
// History: - 1.00 BETA 2 (16/07/2004) - Updated to follow latest version
|
||||
// of fileio.h
|
||||
// - 1.00 BETA 1 (21/07/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ziphdr.h" // Zip file header
|
||||
#include "zstream.h" // Zip Stream
|
||||
|
||||
|
||||
|
||||
// Zip File System Namespace
|
||||
namespace zip_file_system {
|
||||
|
||||
|
||||
|
||||
|
||||
class filesystem;
|
||||
|
||||
|
||||
|
||||
// Input Zip File class
|
||||
class izfstream : public izstream
|
||||
{
|
||||
public:
|
||||
izfstream(filesystem * pFS = pDefaultFS);
|
||||
izfstream(const char * FilePath, filesystem * pFS = pDefaultFS);
|
||||
|
||||
void open(const char * FilePath, filesystem * pFS = pDefaultFS);
|
||||
void close();
|
||||
|
||||
bool is_open() const;
|
||||
|
||||
void setFS(filesystem * pFS = pDefaultFS);
|
||||
|
||||
bool Zipped() const;
|
||||
bool isBeingUsed() const;
|
||||
const std::string & FilePath() const;
|
||||
const std::string & FullFilePath() const;
|
||||
size_t getUncompSize();
|
||||
size_t getOffset();
|
||||
size_t getCompSize();
|
||||
|
||||
protected:
|
||||
friend class filesystem;
|
||||
|
||||
// Default File System Pointer (default = NULL)
|
||||
static filesystem * pDefaultFS;
|
||||
|
||||
std::string m_FilePath;
|
||||
std::string m_FullFilePath;
|
||||
filesystem * m_pFS;
|
||||
bool m_Zipped;
|
||||
size_t m_UncompSize;
|
||||
size_t m_Offset;
|
||||
size_t m_CompSize;
|
||||
bool m_Used;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// Zip File System central class
|
||||
class filesystem
|
||||
{
|
||||
public:
|
||||
// "local" file info class
|
||||
class file_info
|
||||
{
|
||||
public:
|
||||
file_info() : m_PackID(0), m_Offset(0), m_Size(0), m_CompSize(0), m_CompMethod(0), m_Directory(true) { }
|
||||
file_info(size_t PackID, size_t Offset, size_t Size, size_t CompSize, short CompMethod, bool Directory) :
|
||||
m_PackID(PackID), m_Offset(Offset), m_Size(Size), m_CompSize(CompSize), m_CompMethod(CompMethod), m_Directory(Directory) { }
|
||||
|
||||
size_t m_PackID;
|
||||
size_t m_Offset;
|
||||
size_t m_Size;
|
||||
size_t m_CompSize;
|
||||
short m_CompMethod;
|
||||
bool m_Directory;
|
||||
};
|
||||
|
||||
class limited_file_info
|
||||
{
|
||||
public:
|
||||
limited_file_info() : m_Offset(0), m_Size(0) { }
|
||||
limited_file_info(size_t Offset, size_t Size) :
|
||||
m_Offset(Offset), m_Size(Size) { }
|
||||
|
||||
size_t m_Offset;
|
||||
size_t m_Size;
|
||||
};
|
||||
|
||||
class pooledBuffer
|
||||
{
|
||||
public:
|
||||
pooledBuffer(std::string filename, std::string externalFilename ) : filename(filename), externalFilename(externalFilename), buffer(NULL) {}
|
||||
~pooledBuffer() { if (buffer) { delete buffer; } }
|
||||
std::string filename;
|
||||
std::string externalFilename;
|
||||
zbuffer * buffer;
|
||||
};
|
||||
|
||||
|
||||
filesystem(const char * BasePath = "", const char * FileExt = "zip", bool DefaultFS = true);
|
||||
~filesystem();
|
||||
|
||||
void MakeDefault();
|
||||
void Open(izfstream & File, const char * Filename);
|
||||
bool DirExists(const std::string & folderName);
|
||||
bool FileExists(const std::string & fileName);
|
||||
bool PreloadZip(const char * Filename, std::map<std::string, limited_file_info>& target);
|
||||
static std::string getCurrentZipName();
|
||||
static filesystem * getCurrentFS();
|
||||
static std::streamoff SkipLFHdr(std::istream & File, std::streamoff LFHdrPos);
|
||||
void unuse(izfstream & File);
|
||||
|
||||
//Fills the vector results with a list of children of the given folder
|
||||
std::vector<std::string>& scanfolder(const std::string& folderName, std::vector<std::string>& results);
|
||||
|
||||
friend std::ostream & operator << (std::ostream & Out, const filesystem & FS);
|
||||
static void closeTempFiles();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
// Zip file info class
|
||||
class zipfile_info
|
||||
{
|
||||
public:
|
||||
zipfile_info() : m_NbEntries(0), m_FilesSize(0), m_FilesCompSize(0) { }
|
||||
|
||||
std::string m_Filename;
|
||||
size_t m_NbEntries;
|
||||
size_t m_FilesSize;
|
||||
size_t m_FilesCompSize;
|
||||
};
|
||||
|
||||
// Class for file path string comparaison
|
||||
struct lt_path
|
||||
{
|
||||
bool operator() (const std::string & s1, const std::string & s2) const;
|
||||
};
|
||||
|
||||
|
||||
// Protected member functions
|
||||
// Zip file format related functions
|
||||
std::streamoff CentralDir(std::istream & File) const;
|
||||
std::streamoff CentralDirZipped(std::istream & File, std::streamoff begin, std::size_t size) const;
|
||||
headerid NextHeader(std::istream & File) const;
|
||||
|
||||
// File/Zip map related functions
|
||||
bool FileNotZipped(const char * FilePath) const;
|
||||
bool FindFile(const char * Filename, file_info * FileInfo) const;
|
||||
const std::string & FindZip(size_t PackID) const;
|
||||
void InsertZip(const char * Filename, const size_t PackID);
|
||||
|
||||
static zbuffer * getValidBuffer(const std::string & filename, const std::string & externalFilename, std::streamoff Offset = 0, std::streamoff Size = 0);
|
||||
static void closeBufferPool();
|
||||
|
||||
// New type definitions
|
||||
typedef std::map<size_t, zipfile_info> zipmap;
|
||||
typedef std::map<size_t, zipfile_info>::iterator zipmap_iterator;
|
||||
typedef std::map<size_t, zipfile_info>::const_iterator zipmap_const_iterator;
|
||||
typedef std::map<std::string, file_info, lt_path> filemap;
|
||||
typedef std::map<std::string, file_info, lt_path>::iterator filemap_iterator;
|
||||
typedef std::map<std::string, file_info, lt_path>::const_iterator filemap_const_iterator;
|
||||
|
||||
// Mighty protected member variables
|
||||
std::string m_BasePath;
|
||||
std::string m_FileExt;
|
||||
zipmap m_Zips;
|
||||
filemap m_Files;
|
||||
static std::vector<pooledBuffer *> m_Buffers;
|
||||
static std::ifstream CurrentZipFile;
|
||||
static std::string CurrentZipName;
|
||||
static filesystem * pCurrentFS;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// zip_file_system::izfile Inline Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline izfstream::izfstream(filesystem * pFS) : m_pFS(pFS) { }
|
||||
|
||||
inline izfstream::izfstream(const char * FilePath, filesystem * pFS) : m_pFS(pFS) {
|
||||
open(FilePath);
|
||||
}
|
||||
|
||||
inline void izfstream::setFS(filesystem * pFS) {
|
||||
m_pFS = pFS;
|
||||
}
|
||||
|
||||
inline size_t izfstream::getUncompSize()
|
||||
{
|
||||
return m_UncompSize;
|
||||
}
|
||||
|
||||
inline size_t izfstream::getOffset()
|
||||
{
|
||||
return m_Offset;
|
||||
}
|
||||
|
||||
inline size_t izfstream::getCompSize()
|
||||
{
|
||||
return m_CompSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void izfstream::open(const char * FilePath, filesystem * pFS) {
|
||||
if (pFS)
|
||||
m_pFS = pFS;
|
||||
|
||||
if (m_pFS != NULL)
|
||||
m_pFS->Open(* this, FilePath);
|
||||
}
|
||||
|
||||
inline void izfstream::close() {
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
if (m_pFS)
|
||||
m_pFS->unuse( * this);
|
||||
#else
|
||||
izstream::close();
|
||||
#endif
|
||||
m_FilePath = m_FullFilePath = "";
|
||||
m_UncompSize = 0;
|
||||
}
|
||||
|
||||
inline bool izfstream::is_open() const {
|
||||
return static_cast<zbuffer *>(rdbuf())->is_open();
|
||||
}
|
||||
|
||||
inline bool izfstream::Zipped() const {
|
||||
return m_Zipped;
|
||||
}
|
||||
|
||||
inline bool izfstream::isBeingUsed() const {
|
||||
return m_Used;
|
||||
}
|
||||
|
||||
inline const std::string & izfstream::FilePath() const {
|
||||
return m_FilePath;
|
||||
}
|
||||
|
||||
inline const std::string & izfstream::FullFilePath() const {
|
||||
return m_FullFilePath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// zip_file_system::filesystem Inline Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline filesystem::~filesystem() {
|
||||
// Security mesure with izfile::pDefaultFS
|
||||
if (izfstream::pDefaultFS == this)
|
||||
izfstream::pDefaultFS = NULL;
|
||||
}
|
||||
|
||||
inline void filesystem::closeTempFiles() {
|
||||
if (CurrentZipName.size())
|
||||
{
|
||||
CurrentZipFile.close();
|
||||
CurrentZipName = "";
|
||||
}
|
||||
closeBufferPool();
|
||||
}
|
||||
inline void filesystem::MakeDefault() {
|
||||
izfstream::pDefaultFS = this;
|
||||
}
|
||||
|
||||
|
||||
inline std::string filesystem::getCurrentZipName()
|
||||
{
|
||||
return CurrentZipName;
|
||||
}
|
||||
|
||||
inline filesystem * filesystem::getCurrentFS()
|
||||
{
|
||||
return pCurrentFS;
|
||||
}
|
||||
|
||||
} // namespace zip_file_system
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ziphdr.cpp: implementation of the zip header classes.
|
||||
//
|
||||
// Copyright (C) 2002 Tanguy Fautré.
|
||||
// Copyright (C) 2002 Tanguy Fautre
|
||||
// For conditions of distribution and use,
|
||||
// see copyright notice in ziphdr.h
|
||||
//
|
||||
|
||||
@@ -1,143 +1,143 @@
|
||||
// zfsystem.h: interface for the zip header classes.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 Tanguy Fautré.
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautré
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip File Format Headers.
|
||||
// ***********************
|
||||
//
|
||||
// Current version: 1.00 BETA 2 (01/09/2003)
|
||||
//
|
||||
// Comment: Based on the ZIP file format specification from Appnote.txt
|
||||
// from the PKZip Website on July 13, 1998.
|
||||
// New implementations of the ZIP file format might not work
|
||||
// correctly (ZIP64 ?).
|
||||
//
|
||||
// History: - 1.00 BETA 2 (01/09/2003) - Use stdint.h sized types
|
||||
// - 1.00 BETA 1 (12/06/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
// Zip File System Namespace
|
||||
namespace zip_file_system {
|
||||
|
||||
|
||||
|
||||
|
||||
// Zip file headers
|
||||
enum headerid { LOCALFILE = 0x04034b50,
|
||||
FILE = 0x02014b50,
|
||||
ENDOFDIR = 0x06054b50,
|
||||
UNKNOWN,
|
||||
READERROR
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Zip file "local file" header class
|
||||
struct local_file_header
|
||||
{
|
||||
bool ReadHeader(std::istream & File);
|
||||
|
||||
static const uint_least32_t m_ConstSign= LOCALFILE;
|
||||
|
||||
uint_least32_t m_Signature;
|
||||
uint_least16_t m_VersionExtract;
|
||||
uint_least16_t m_GeneralFlags;
|
||||
uint_least16_t m_CompMethod;
|
||||
uint_least16_t m_Time;
|
||||
uint_least16_t m_Date;
|
||||
uint_least32_t m_CRC32;
|
||||
uint_least32_t m_CompSize;
|
||||
uint_least32_t m_UncompSize;
|
||||
uint_least16_t m_FilenameSize;
|
||||
uint_least16_t m_FieldSize;
|
||||
|
||||
std::vector<char> m_Filename;
|
||||
std::vector<char> m_ExtraField;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Zip file "file header" header class
|
||||
struct file_header
|
||||
{
|
||||
bool ReadHeader(std::istream & File);
|
||||
|
||||
static const headerid m_ConstSign = FILE;
|
||||
|
||||
uint_least32_t m_Signature;
|
||||
uint_least16_t m_VersionMade;
|
||||
uint_least16_t m_VersionExtract;
|
||||
uint_least16_t m_GeneralFlags;
|
||||
uint_least16_t m_CompMethod;
|
||||
uint_least16_t m_Time;
|
||||
uint_least16_t m_Date;
|
||||
uint_least32_t m_CRC32;
|
||||
uint_least32_t m_CompSize;
|
||||
uint_least32_t m_UncompSize;
|
||||
uint_least16_t m_FilenameSize;
|
||||
uint_least16_t m_FieldSize;
|
||||
uint_least16_t m_CommentSize;
|
||||
uint_least16_t m_DiskNb;
|
||||
uint_least16_t m_IntAttrib;
|
||||
uint_least32_t m_ExtAttrib;
|
||||
uint_least32_t m_RelOffset;
|
||||
|
||||
std::vector<char> m_Filename;
|
||||
std::vector<char> m_ExtraField;
|
||||
std::vector<char> m_Comment;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Zip file "end of central dir" header class
|
||||
struct eofcd_header
|
||||
{
|
||||
bool ReadHeader(std::istream & File);
|
||||
|
||||
static const headerid m_ConstSign = ENDOFDIR;
|
||||
|
||||
uint_least32_t m_Signature;
|
||||
uint_least16_t m_NbDisks;
|
||||
uint_least16_t m_DirDisk;
|
||||
uint_least16_t m_LocalEntries;
|
||||
uint_least16_t m_TotalEntries;
|
||||
uint_least32_t m_DirSize;
|
||||
uint_least32_t m_Offset;
|
||||
uint_least16_t m_CommentSize;
|
||||
|
||||
std::vector<char> m_Comment;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace zip_file_system
|
||||
|
||||
// zfsystem.h: interface for the zip header classes.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 Tanguy Fautre
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautr<EFBFBD>E
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip File Format Headers.
|
||||
// ***********************
|
||||
//
|
||||
// Current version: 1.00 BETA 2 (01/09/2003)
|
||||
//
|
||||
// Comment: Based on the ZIP file format specification from Appnote.txt
|
||||
// from the PKZip Website on July 13, 1998.
|
||||
// New implementations of the ZIP file format might not work
|
||||
// correctly (ZIP64 ?).
|
||||
//
|
||||
// History: - 1.00 BETA 2 (01/09/2003) - Use stdint.h sized types
|
||||
// - 1.00 BETA 1 (12/06/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
// Zip File System Namespace
|
||||
namespace zip_file_system {
|
||||
|
||||
|
||||
|
||||
|
||||
// Zip file headers
|
||||
enum headerid { LOCALFILE = 0x04034b50,
|
||||
FILE = 0x02014b50,
|
||||
ENDOFDIR = 0x06054b50,
|
||||
UNKNOWN,
|
||||
READERROR
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Zip file "local file" header class
|
||||
struct local_file_header
|
||||
{
|
||||
bool ReadHeader(std::istream & File);
|
||||
|
||||
static const uint_least32_t m_ConstSign= LOCALFILE;
|
||||
|
||||
uint_least32_t m_Signature;
|
||||
uint_least16_t m_VersionExtract;
|
||||
uint_least16_t m_GeneralFlags;
|
||||
uint_least16_t m_CompMethod;
|
||||
uint_least16_t m_Time;
|
||||
uint_least16_t m_Date;
|
||||
uint_least32_t m_CRC32;
|
||||
uint_least32_t m_CompSize;
|
||||
uint_least32_t m_UncompSize;
|
||||
uint_least16_t m_FilenameSize;
|
||||
uint_least16_t m_FieldSize;
|
||||
|
||||
std::vector<char> m_Filename;
|
||||
std::vector<char> m_ExtraField;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Zip file "file header" header class
|
||||
struct file_header
|
||||
{
|
||||
bool ReadHeader(std::istream & File);
|
||||
|
||||
static const headerid m_ConstSign = FILE;
|
||||
|
||||
uint_least32_t m_Signature;
|
||||
uint_least16_t m_VersionMade;
|
||||
uint_least16_t m_VersionExtract;
|
||||
uint_least16_t m_GeneralFlags;
|
||||
uint_least16_t m_CompMethod;
|
||||
uint_least16_t m_Time;
|
||||
uint_least16_t m_Date;
|
||||
uint_least32_t m_CRC32;
|
||||
uint_least32_t m_CompSize;
|
||||
uint_least32_t m_UncompSize;
|
||||
uint_least16_t m_FilenameSize;
|
||||
uint_least16_t m_FieldSize;
|
||||
uint_least16_t m_CommentSize;
|
||||
uint_least16_t m_DiskNb;
|
||||
uint_least16_t m_IntAttrib;
|
||||
uint_least32_t m_ExtAttrib;
|
||||
uint_least32_t m_RelOffset;
|
||||
|
||||
std::vector<char> m_Filename;
|
||||
std::vector<char> m_ExtraField;
|
||||
std::vector<char> m_Comment;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Zip file "end of central dir" header class
|
||||
struct eofcd_header
|
||||
{
|
||||
bool ReadHeader(std::istream & File);
|
||||
|
||||
static const headerid m_ConstSign = ENDOFDIR;
|
||||
|
||||
uint_least32_t m_Signature;
|
||||
uint_least16_t m_NbDisks;
|
||||
uint_least16_t m_DirDisk;
|
||||
uint_least16_t m_LocalEntries;
|
||||
uint_least16_t m_TotalEntries;
|
||||
uint_least32_t m_DirSize;
|
||||
uint_least32_t m_Offset;
|
||||
uint_least16_t m_CommentSize;
|
||||
|
||||
std::vector<char> m_Comment;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace zip_file_system
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// zstream.cpp: implementation of the zstream class.
|
||||
//
|
||||
// Copyright (C) 2002 Tanguy Fautré.
|
||||
// Copyright (C) 2002 Tanguy Fautre
|
||||
// For conditions of distribution and use,
|
||||
// see copyright notice in zfsystem.h
|
||||
//
|
||||
@@ -134,7 +134,7 @@ zbuffer_stored * zbuffer_stored::close()
|
||||
|
||||
|
||||
|
||||
int zbuffer_stored::overflow(int c)
|
||||
int zbuffer_stored::overflow(int)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ int zbuffer_stored::sync()
|
||||
|
||||
|
||||
|
||||
streambuf * zbuffer_stored::setbuf(char * pr, int nLength)
|
||||
streambuf * zbuffer_stored::setbuf(char *, int)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -298,7 +298,7 @@ zbuffer_deflated * zbuffer_deflated::close()
|
||||
|
||||
|
||||
|
||||
int zbuffer_deflated::overflow(int c)
|
||||
int zbuffer_deflated::overflow(int)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
@@ -442,7 +442,7 @@ int zbuffer_deflated::sync()
|
||||
|
||||
|
||||
|
||||
streambuf * zbuffer_deflated::setbuf(char * pr, int nLength)
|
||||
streambuf * zbuffer_deflated::setbuf(char *, int)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,189 +1,189 @@
|
||||
// zstream.h: interface for the zstream classes.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 Tanguy Fautré.
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautré
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip (Input) Stream.
|
||||
// *******************
|
||||
//
|
||||
// Current version: 1.00 BETA 4 (02/09/2003)
|
||||
//
|
||||
// Comment: izstream currently only supports "stored" and "deflated"
|
||||
// compression methods.
|
||||
//
|
||||
// !!!IMPORTANT!!!
|
||||
// Modify "zstream_zlib.h" for headers and lib dependencies
|
||||
// on Zlib (http://www.zlib.org)
|
||||
//
|
||||
// History: - 1.00 BETA 4 (02/09/2003) - Made zbuffer constructor protected
|
||||
// - 1.00 BETA 3 (21/02/2003) - Fixed bugs with seekoff()
|
||||
// - 1.00 BETA 2 (23/12/2002) - Fixed a bug with izstream
|
||||
// (Added m_ComMethod(-1) in constructor)
|
||||
// - 1.00 BETA 1 (29/05/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#include "zstream_zlib.h" // Zlib dependencies
|
||||
|
||||
#ifdef PSP
|
||||
#define USE_ZBUFFER_POOL
|
||||
#endif
|
||||
|
||||
// Zip File System Namespace
|
||||
namespace zip_file_system {
|
||||
|
||||
|
||||
|
||||
|
||||
// Base buffer class
|
||||
class zbuffer : public std::streambuf
|
||||
{
|
||||
public:
|
||||
virtual ~zbuffer() { }
|
||||
|
||||
virtual zbuffer * open(const char * Filename, std::streamoff Offset, std::streamoff Size) = 0;
|
||||
virtual zbuffer * close() = 0;
|
||||
|
||||
bool is_open() const { return m_Opened; }
|
||||
bool is_used() const {return m_Used;}
|
||||
void unuse() { m_Used = false;}
|
||||
bool use(std::streamoff Offset, std::streamoff Size);
|
||||
std::string getFilename() { return m_Filename; }
|
||||
|
||||
protected:
|
||||
zbuffer() : m_Size(0), m_Opened(false), m_Used(false) { }
|
||||
|
||||
static const int BUFFERSIZE = 4092;
|
||||
|
||||
std::string m_Filename;
|
||||
|
||||
|
||||
std::ifstream m_ZipFile;
|
||||
std::streamoff m_Pos;
|
||||
std::streamoff m_Size;
|
||||
char m_Buffer[BUFFERSIZE];
|
||||
bool m_Opened;
|
||||
bool m_Used;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Buffer class for stored compression method.
|
||||
class zbuffer_stored : public zbuffer
|
||||
{
|
||||
public:
|
||||
virtual ~zbuffer_stored() { close(); }
|
||||
|
||||
virtual zbuffer_stored * open(const char * Filename, std::streamoff Offset, std::streamoff Size);
|
||||
virtual zbuffer_stored * close();
|
||||
|
||||
virtual int overflow(int c = EOF);
|
||||
virtual int underflow();
|
||||
virtual int sync();
|
||||
virtual std::streambuf * setbuf(char * pr, int nLength);
|
||||
virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode);
|
||||
|
||||
// Default Implementation is enough
|
||||
// virtual streampos seekpos(streampos, int);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// Buffer class for deflated compression method.
|
||||
class zbuffer_deflated : public zbuffer
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~zbuffer_deflated() {
|
||||
close();
|
||||
}
|
||||
|
||||
virtual zbuffer_deflated * open(const char * Filename, std::streamoff Offset, std::streamoff Size);
|
||||
virtual zbuffer_deflated * close();
|
||||
|
||||
virtual int overflow(int c = EOF);
|
||||
virtual int underflow();
|
||||
virtual int sync();
|
||||
virtual std::streambuf * setbuf(char * pr, int nLength);
|
||||
virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode);
|
||||
|
||||
// Default Implementation is enough
|
||||
// virtual streampos seekpos(streampos, int);
|
||||
|
||||
protected:
|
||||
z_stream m_ZStream;
|
||||
std::streamoff m_CompPos;
|
||||
char m_CompBuffer[BUFFERSIZE];
|
||||
bool m_StreamEnd;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// main istream class for reading zipped files
|
||||
class izstream : public std::istream
|
||||
{
|
||||
public:
|
||||
|
||||
izstream() : std::istream(NULL), m_CompMethod(-1) { setstate(std::ios::badbit); }
|
||||
virtual ~izstream() {
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
rdbuf(NULL); //This doesn't delete the buffer, deletion is handled by zfsystem;
|
||||
#else
|
||||
delete(rdbuf());
|
||||
#endif
|
||||
}
|
||||
|
||||
void open(const char * Filename, std::streamoff Offset, std::streamoff Size, int CompMethod);
|
||||
void close() { SetCompMethod(-1); }
|
||||
|
||||
void _SetCompMethod(int CompMethod) { m_CompMethod = CompMethod; };
|
||||
|
||||
protected:
|
||||
static const int STORED = 0;
|
||||
static const int DEFLATED = 8;
|
||||
|
||||
zbuffer * GetRightBuffer(int CompMethod) const;
|
||||
|
||||
void SetCompMethod(int CompMethod) {
|
||||
delete rdbuf(GetRightBuffer(m_CompMethod = CompMethod));
|
||||
|
||||
if (rdbuf() == NULL)
|
||||
setstate(std::ios::badbit);
|
||||
}
|
||||
|
||||
int m_CompMethod;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace zip_file_system;
|
||||
|
||||
// zstream.h: interface for the zstream classes.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 Tanguy Fautre
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
// Tanguy Fautr<EFBFBD>E
|
||||
// softdev@telenet.be
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip (Input) Stream.
|
||||
// *******************
|
||||
//
|
||||
// Current version: 1.00 BETA 4 (02/09/2003)
|
||||
//
|
||||
// Comment: izstream currently only supports "stored" and "deflated"
|
||||
// compression methods.
|
||||
//
|
||||
// !!!IMPORTANT!!!
|
||||
// Modify "zstream_zlib.h" for headers and lib dependencies
|
||||
// on Zlib (http://www.zlib.org)
|
||||
//
|
||||
// History: - 1.00 BETA 4 (02/09/2003) - Made zbuffer constructor protected
|
||||
// - 1.00 BETA 3 (21/02/2003) - Fixed bugs with seekoff()
|
||||
// - 1.00 BETA 2 (23/12/2002) - Fixed a bug with izstream
|
||||
// (Added m_ComMethod(-1) in constructor)
|
||||
// - 1.00 BETA 1 (29/05/2002) - First public release
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#include "zstream_zlib.h" // Zlib dependencies
|
||||
|
||||
#ifdef PSP
|
||||
#define USE_ZBUFFER_POOL
|
||||
#endif
|
||||
|
||||
// Zip File System Namespace
|
||||
namespace zip_file_system {
|
||||
|
||||
|
||||
|
||||
|
||||
// Base buffer class
|
||||
class zbuffer : public std::streambuf
|
||||
{
|
||||
public:
|
||||
virtual ~zbuffer() { }
|
||||
|
||||
virtual zbuffer * open(const char * Filename, std::streamoff Offset, std::streamoff Size) = 0;
|
||||
virtual zbuffer * close() = 0;
|
||||
|
||||
bool is_open() const { return m_Opened; }
|
||||
bool is_used() const {return m_Used;}
|
||||
void unuse() { m_Used = false;}
|
||||
bool use(std::streamoff Offset, std::streamoff Size);
|
||||
std::string getFilename() { return m_Filename; }
|
||||
|
||||
protected:
|
||||
zbuffer() : m_Size(0), m_Opened(false), m_Used(false) { }
|
||||
|
||||
static const int BUFFERSIZE = 4092;
|
||||
|
||||
std::string m_Filename;
|
||||
|
||||
|
||||
std::ifstream m_ZipFile;
|
||||
std::streamoff m_Pos;
|
||||
std::streamoff m_Size;
|
||||
char m_Buffer[BUFFERSIZE];
|
||||
bool m_Opened;
|
||||
bool m_Used;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Buffer class for stored compression method.
|
||||
class zbuffer_stored : public zbuffer
|
||||
{
|
||||
public:
|
||||
virtual ~zbuffer_stored() { close(); }
|
||||
|
||||
virtual zbuffer_stored * open(const char * Filename, std::streamoff Offset, std::streamoff Size);
|
||||
virtual zbuffer_stored * close();
|
||||
|
||||
virtual int overflow(int c = EOF);
|
||||
virtual int underflow();
|
||||
virtual int sync();
|
||||
virtual std::streambuf * setbuf(char * pr, int nLength);
|
||||
virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode);
|
||||
|
||||
// Default Implementation is enough
|
||||
// virtual streampos seekpos(streampos, int);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// Buffer class for deflated compression method.
|
||||
class zbuffer_deflated : public zbuffer
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~zbuffer_deflated() {
|
||||
close();
|
||||
}
|
||||
|
||||
virtual zbuffer_deflated * open(const char * Filename, std::streamoff Offset, std::streamoff Size);
|
||||
virtual zbuffer_deflated * close();
|
||||
|
||||
virtual int overflow(int c = EOF);
|
||||
virtual int underflow();
|
||||
virtual int sync();
|
||||
virtual std::streambuf * setbuf(char * pr, int nLength);
|
||||
virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode);
|
||||
|
||||
// Default Implementation is enough
|
||||
// virtual streampos seekpos(streampos, int);
|
||||
|
||||
protected:
|
||||
z_stream m_ZStream;
|
||||
std::streamoff m_CompPos;
|
||||
char m_CompBuffer[BUFFERSIZE];
|
||||
bool m_StreamEnd;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// main istream class for reading zipped files
|
||||
class izstream : public std::istream
|
||||
{
|
||||
public:
|
||||
|
||||
izstream() : std::istream(NULL), m_CompMethod(-1) { setstate(std::ios::badbit); }
|
||||
virtual ~izstream() {
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
rdbuf(NULL); //This doesn't delete the buffer, deletion is handled by zfsystem;
|
||||
#else
|
||||
delete(rdbuf());
|
||||
#endif
|
||||
}
|
||||
|
||||
void open(const char * Filename, std::streamoff Offset, std::streamoff Size, int CompMethod);
|
||||
void close() { SetCompMethod(-1); }
|
||||
|
||||
void _SetCompMethod(int CompMethod) { m_CompMethod = CompMethod; };
|
||||
|
||||
protected:
|
||||
static const int STORED = 0;
|
||||
static const int DEFLATED = 8;
|
||||
|
||||
zbuffer * GetRightBuffer(int CompMethod) const;
|
||||
|
||||
void SetCompMethod(int CompMethod) {
|
||||
delete rdbuf(GetRightBuffer(m_CompMethod = CompMethod));
|
||||
|
||||
if (rdbuf() == NULL)
|
||||
setstate(std::ios::badbit);
|
||||
}
|
||||
|
||||
int m_CompMethod;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace zip_file_system;
|
||||
|
||||
|
||||
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
#Wagic the Homebrew
|
||||
|
||||
|
||||
[](https://travis-ci.org/WagicProject/wagic)
|
||||
|
||||
## Description
|
||||
|
||||
Wagic, the Homebrew, is a C++ game engine that allows to play card games against an AI on
|
||||
- Android (phones and tablets)
|
||||
- iOS (iPhone/iPad)
|
||||
- Sony PSP
|
||||
- Windows desktops
|
||||
- MacOS
|
||||
- Linux and derivated like Maemo or Meego
|
||||
|
||||
It is highly customizable and allows the player to tweak the rules / create their own cards, their own themes, etc...
|
||||
|
||||
|
||||
Info, Downloads, and more at http://wololo.net
|
||||
|
||||
-
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user