Compare commits
849 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
965c440d86 | ||
|
|
6b2aff821c | ||
|
|
84d9125ea1 | ||
|
|
9b969e762c | ||
|
|
2695d48ba7 | ||
|
|
aba2a6b17d | ||
|
|
7b87d17d22 | ||
|
|
e5172a9240 | ||
|
|
dcac7942fa | ||
|
|
4e13529adb | ||
|
|
c553835228 | ||
|
|
1b87193fc1 | ||
|
|
25fca56319 | ||
|
|
bf4252394c | ||
|
|
22757e064f | ||
|
|
fc9fa37e4e | ||
|
|
2d5e3402fa | ||
|
|
b7dd26121a | ||
|
|
23bdbeef4e | ||
|
|
9ac81c5219 | ||
|
|
6b9d346b8b | ||
|
|
9e68eb4d2c | ||
|
|
f1f47ee44a | ||
|
|
436b2b3140 | ||
|
|
f6cfa8ae49 | ||
|
|
13949a8d1f | ||
|
|
88db623dc1 | ||
|
|
976413173a | ||
|
|
91d3349585 | ||
|
|
6e1a774921 | ||
|
|
6b53b509fa | ||
|
|
b8b6203ecd | ||
|
|
81e1500675 | ||
|
|
d2cd18cb1e | ||
|
|
f5ac73f681 | ||
|
|
413630813a | ||
|
|
73b6ef2293 | ||
|
|
428bfbd810 | ||
|
|
c54409bdfb | ||
|
|
b63aebfdaf | ||
|
|
335f876a46 | ||
|
|
c5e99342a3 | ||
|
|
1710eb9249 | ||
|
|
d03770f91f | ||
|
|
9fe6f7a6ea | ||
|
|
2fc605fc3e | ||
|
|
edcd5c4713 | ||
|
|
bd3df1e06a | ||
|
|
b785d1c82b | ||
|
|
93bf14f84f | ||
|
|
5a84646282 | ||
|
|
2e6cfc08f0 | ||
|
|
4b6d3d47ec | ||
|
|
985abaa12a | ||
|
|
a381a7253a | ||
|
|
b8bb509d5c | ||
|
|
f48dbd0e19 | ||
|
|
31c1278374 | ||
|
|
f6aaafd60f | ||
|
|
ae3dec19fd | ||
|
|
990baa0929 | ||
|
|
7ecb65a141 | ||
|
|
a1e55103be | ||
|
|
1b4fc54405 | ||
|
|
e5dcea1fa0 | ||
|
|
9f25195629 | ||
|
|
6936fa1c1c | ||
|
|
7b25eacfc8 | ||
|
|
33989a61e3 | ||
|
|
08d9e8d076 | ||
|
|
da43ef0982 | ||
|
|
02f12bde81 | ||
|
|
b55d5375ac | ||
|
|
281f40bd56 | ||
|
|
dcb7c0c27e | ||
|
|
d3c44a6fa6 | ||
|
|
f432dc6bdc | ||
|
|
ce21ee6001 | ||
|
|
a431f5a674 | ||
|
|
f6153f17ad | ||
|
|
c17ecbc78c | ||
|
|
0feb9f0c56 | ||
|
|
e69cb3d950 | ||
|
|
e7c03dd512 | ||
|
|
0c1371ffae | ||
|
|
8a350acf39 | ||
|
|
594b3b5531 | ||
|
|
e13d06fe20 | ||
|
|
805bb84c8f | ||
|
|
1a62338349 | ||
|
|
4795ba83ba | ||
|
|
ad5b362bca | ||
|
|
8a735452de | ||
|
|
03d0f3e9ca | ||
|
|
ff0983cc42 | ||
|
|
159a413c7d | ||
|
|
6a753d1316 | ||
|
|
c89bf30e05 | ||
|
|
ba4b5ef9f2 | ||
|
|
5b39ee221f | ||
|
|
65c4432325 | ||
|
|
32bbb27c9f | ||
|
|
ef3c030576 | ||
|
|
554a182229 | ||
|
|
9154d78e58 | ||
|
|
82d933aa3d | ||
|
|
ef0fe9b13c | ||
|
|
f6700b7094 | ||
|
|
21f00cf251 | ||
|
|
900d2bf816 | ||
|
|
3846fa3f28 | ||
|
|
52f77d61ba | ||
|
|
039341de69 | ||
|
|
5adf332a5f | ||
|
|
efbb32a498 | ||
|
|
3156dd1321 | ||
|
|
2fbeeafbb8 | ||
|
|
db680f3bcd | ||
|
|
4a20fa5275 | ||
|
|
3fb2da7174 | ||
|
|
7f8bebbdd5 | ||
|
|
597fc0265f | ||
|
|
d5d5770dac | ||
|
|
772ac64e3b | ||
|
|
92d7337f04 | ||
|
|
200425114c | ||
|
|
b92a73a2a2 | ||
|
|
e83c77b99f | ||
|
|
28aa35160d | ||
|
|
18c9bfa134 | ||
|
|
bdb7763237 | ||
|
|
bc9ee46b8f | ||
|
|
b92b734db2 | ||
|
|
2748a6cd3c | ||
|
|
888876185d | ||
|
|
03fea6358b | ||
|
|
59b0dc6735 | ||
|
|
35a42b2172 | ||
|
|
daa4056f45 | ||
|
|
bb5abe633f | ||
|
|
dc238db355 | ||
|
|
4c692c23bb | ||
|
|
b093e82db3 | ||
|
|
7a1c2108a1 | ||
|
|
4aa2b49649 | ||
|
|
cdaced4df6 | ||
|
|
cdd029853b | ||
|
|
507bafdd9c | ||
|
|
07a36123e5 | ||
|
|
a205e7ada9 | ||
|
|
25e9330bb4 | ||
|
|
b2edfa454c | ||
|
|
07767a09d9 | ||
|
|
e8d85d9269 | ||
|
|
5cf0ba079f | ||
|
|
e08b1f82ce | ||
|
|
c2196149ee | ||
|
|
65b5ce7880 | ||
|
|
9c254ec3e0 | ||
|
|
f4418e0205 | ||
|
|
a314f7b42e | ||
|
|
dc5a72cda5 | ||
|
|
380cb41ca9 | ||
|
|
83f7e633a3 | ||
|
|
ab1c920435 | ||
|
|
7094d658f8 | ||
|
|
11617291e3 | ||
|
|
790aa03834 | ||
|
|
bcd16ea5ea | ||
|
|
81c044760b | ||
|
|
b0e0e80b69 | ||
|
|
280bb1d84f | ||
|
|
bb42dceaca | ||
|
|
d0873ed551 | ||
|
|
0fbddfc47b | ||
|
|
3f1dee2650 | ||
|
|
a4b8b93e7f | ||
|
|
02d1417ef4 | ||
|
|
50812a908c | ||
|
|
1a1ed55485 | ||
|
|
09fa322a0e | ||
|
|
1a9a423c35 | ||
|
|
7b0449213c | ||
|
|
c0251f5c29 | ||
|
|
4509d8a60b | ||
|
|
b1738b0902 | ||
|
|
45259462aa | ||
|
|
772a7427a2 | ||
|
|
afa58b81f6 | ||
|
|
6822c0f0e3 | ||
|
|
0a155ecb68 | ||
|
|
15fff94447 | ||
|
|
ff06df2acb | ||
|
|
df9301d591 | ||
|
|
e51b1bbb25 | ||
|
|
aa275f4b1c | ||
|
|
ed11bda9fd | ||
|
|
ed34a3f5d4 | ||
|
|
a99b8b7984 | ||
|
|
f750254cc2 | ||
|
|
21ece182f5 | ||
|
|
6439dca43a | ||
|
|
ca424a4577 | ||
|
|
87bc2cb1ab | ||
|
|
58f22cc3b5 | ||
|
|
fa8362f000 | ||
|
|
1816206dfc | ||
|
|
fcfa994152 | ||
|
|
e7262660c2 | ||
|
|
a1e14d5740 | ||
|
|
60c11f3f30 | ||
|
|
3fe584d366 | ||
|
|
28e38321ee | ||
|
|
1faeeeeabc | ||
|
|
75a0c672b1 | ||
|
|
db829b21aa | ||
|
|
24bdc29c27 | ||
|
|
692a78984f | ||
|
|
77a399738c | ||
|
|
5d7358899d | ||
|
|
aca25b9999 | ||
|
|
182c6c534b | ||
|
|
0500f155e6 | ||
|
|
125b826f62 | ||
|
|
922bfbf724 | ||
|
|
f1e584fad9 | ||
|
|
0c4dcdea71 | ||
|
|
ec4b383198 | ||
|
|
3328c7e78b | ||
|
|
357fcd44d7 | ||
|
|
5a0a682d35 | ||
|
|
1fcb7e5aba | ||
|
|
eec867bc9e | ||
|
|
5a956d2914 | ||
|
|
e0e29cc363 | ||
|
|
9fc8e03f72 | ||
|
|
b054e93f0e | ||
|
|
653680a356 | ||
|
|
40035f2e52 | ||
|
|
a70b7daec4 | ||
|
|
0f3e7b5dac | ||
|
|
2fbc08b606 | ||
|
|
e4897f709e | ||
|
|
84445aa28b | ||
|
|
0795f9a9f2 | ||
|
|
44ae0d67f6 | ||
|
|
a74f0ca370 | ||
|
|
266c1fcdcb | ||
|
|
977c3407e7 | ||
|
|
99c2299ed4 | ||
|
|
39a08f17da | ||
|
|
57de1187fc | ||
|
|
2bba6d4c0d | ||
|
|
2f03b225f7 | ||
|
|
533bc1ce94 | ||
|
|
add9df6058 | ||
|
|
d3496f3ff5 | ||
|
|
e97f7ee725 | ||
|
|
37497295fb | ||
|
|
2e89b3b5b9 | ||
|
|
518bbc651e | ||
|
|
ffd1d97e03 | ||
|
|
e503d431f1 | ||
|
|
49a066714a | ||
|
|
7eec610d21 | ||
|
|
530507c36b | ||
|
|
4d2584d8fc | ||
|
|
0f5057920e | ||
|
|
a98000cf3b | ||
|
|
0cec8de164 | ||
|
|
1caa8d923d | ||
|
|
4fa51f8c52 | ||
|
|
a8be765aa8 | ||
|
|
d2d35d490a | ||
|
|
26ba137424 | ||
|
|
e6006663ec | ||
|
|
74eb2772b6 | ||
|
|
3878a696af | ||
|
|
49ac34c405 | ||
|
|
a7d4a980ba | ||
|
|
2196db562e | ||
|
|
2ad3e0ed4c | ||
|
|
6e03fe77ae | ||
|
|
af8ec7b5dd | ||
|
|
7fa29e7341 | ||
|
|
9c6950d163 | ||
|
|
5d4cbfe8e7 | ||
|
|
4747422110 | ||
|
|
7d1416ac74 | ||
|
|
2efaa7af7b | ||
|
|
68e259870f | ||
|
|
29c2c94784 | ||
|
|
3f2e1d078f | ||
|
|
0a259da05a | ||
|
|
1b22fe6de2 | ||
|
|
9b700c3bd2 | ||
|
|
3b72e30c36 | ||
|
|
9eba103de9 | ||
|
|
ecadee3876 | ||
|
|
699f9105ae | ||
|
|
8a19e8dafe | ||
|
|
588c056205 | ||
|
|
866a7fb641 | ||
|
|
a5fe42268f | ||
|
|
0bd6816bdd | ||
|
|
1c6670c7a1 | ||
|
|
699a0eb934 | ||
|
|
72440ab937 | ||
|
|
9ad807bd58 | ||
|
|
9fb1970ac0 | ||
|
|
48dfac2588 | ||
|
|
c6d3714e6f | ||
|
|
1345c257c3 | ||
|
|
19112a8f27 | ||
|
|
e0979fcf3f | ||
|
|
d514ecbd5e | ||
|
|
a53dbb6950 | ||
|
|
a03b88e0eb | ||
|
|
4472eb1c40 | ||
|
|
3443987127 | ||
|
|
c73a79fd42 | ||
|
|
dedbe3d431 | ||
|
|
87ef713a17 | ||
|
|
4ba8ac4fa1 | ||
|
|
e74e0531bd | ||
|
|
b67cb4bd1f | ||
|
|
22628c9ac4 | ||
|
|
4dd0862fad | ||
|
|
0ec57fbb8d | ||
|
|
19ab584d32 | ||
|
|
97fe978d14 | ||
|
|
2a74c7d897 | ||
|
|
cdf9c2fc6f | ||
|
|
235f84a0d4 | ||
|
|
ccaa490a2f | ||
|
|
8eaf11b510 | ||
|
|
57a5faa448 | ||
|
|
be87191d0a | ||
|
|
40aabe76c7 | ||
|
|
9d304cb35c | ||
|
|
ee08a4966f | ||
|
|
aeca69903e | ||
|
|
e1b3f2b95a | ||
|
|
25c7436652 | ||
|
|
771c449621 | ||
|
|
61ecaa5756 | ||
|
|
c05dddc56e | ||
|
|
8e0747fd50 | ||
|
|
1bcc87c916 | ||
|
|
45797907d3 | ||
|
|
3498dea486 | ||
|
|
a4aab8458b | ||
|
|
534744d615 | ||
|
|
dc5450b95e | ||
|
|
9e0e276740 | ||
|
|
1c9c02f3ce | ||
|
|
7774f9f402 | ||
|
|
5607219945 | ||
|
|
69ef3efd2d | ||
|
|
36c118922b | ||
|
|
1d014953e3 | ||
|
|
c5cb1d9bcc | ||
|
|
86d12cf317 | ||
|
|
db9e59ede1 | ||
|
|
cc9b1b0a05 | ||
|
|
5c29de2013 | ||
|
|
559db104f8 | ||
|
|
365c57be4c | ||
|
|
6f0c84fc68 | ||
|
|
75782d9e99 | ||
|
|
69ddf4936e | ||
|
|
4b3108283f | ||
|
|
12d177a6c8 | ||
|
|
54717dc7e2 | ||
|
|
631c909abd | ||
|
|
208746f28f | ||
|
|
61c5f8ae22 | ||
|
|
4e0cca3a08 | ||
|
|
b86ffc2370 | ||
|
|
33574c9885 | ||
|
|
672c542f99 | ||
|
|
f741fe48a1 | ||
|
|
4347ebcee2 | ||
|
|
4e3e5a5361 | ||
|
|
8e6439c3d1 | ||
|
|
b54d358feb | ||
|
|
78baa7b12d | ||
|
|
19f1dd22e9 | ||
|
|
73f583f68a | ||
|
|
52de43e329 | ||
|
|
49ddacaac0 | ||
|
|
4533b3a1c0 | ||
|
|
f30ea02794 | ||
|
|
7112dda299 | ||
|
|
02636a7108 | ||
|
|
36a9456e0d | ||
|
|
113893dcea | ||
|
|
1abbe9c7b2 | ||
|
|
7205ac791c | ||
|
|
3335b81ad4 | ||
|
|
d9c9438f3c | ||
|
|
37250843e1 | ||
|
|
072ab88721 | ||
|
|
c208e6b107 | ||
|
|
65f3185b39 | ||
|
|
34f73f8a2b | ||
|
|
cb4142a97d | ||
|
|
80d08d5a34 | ||
|
|
052aecf533 | ||
|
|
7bde714f18 | ||
|
|
5ff429f656 | ||
|
|
92f27299e1 | ||
|
|
f9013375f8 | ||
|
|
f18b0045ba | ||
|
|
18173cc4c0 | ||
|
|
6a1ffdd7a5 | ||
|
|
8db78b2190 | ||
|
|
3fcccae241 | ||
|
|
6ff8add164 | ||
|
|
58a8c3c82a | ||
|
|
92c5c656c7 | ||
|
|
61856cd648 | ||
|
|
687f82b5c2 | ||
|
|
920c864bed | ||
|
|
1360c985b7 | ||
|
|
b6f953e13b | ||
|
|
796b96071b | ||
|
|
ec56ccc690 | ||
|
|
95931b67e1 | ||
|
|
706bbb83c9 | ||
|
|
43099f47d0 | ||
|
|
eca86999c3 | ||
|
|
a00b44a5fd | ||
|
|
5b8dcff2a4 | ||
|
|
e4d36e4982 | ||
|
|
adfdbf138d | ||
|
|
8d1ba26492 | ||
|
|
792625f763 | ||
|
|
5e8eae4ef8 | ||
|
|
148212da96 | ||
|
|
23ddb12529 | ||
|
|
186a5e8f7b | ||
|
|
dfb5fe1e04 | ||
|
|
640f75373e | ||
|
|
46e5d96ced | ||
|
|
ad3fbe2052 | ||
|
|
cd6c60fd46 | ||
|
|
f7be386d5a | ||
|
|
89b2131052 | ||
|
|
e5d1ca2e3c | ||
|
|
32b8224afd | ||
|
|
00e7ab1db8 | ||
|
|
e376a53b09 | ||
|
|
17a9cd5666 | ||
|
|
fc3de662c3 | ||
|
|
8de568c2fc | ||
|
|
55661883d9 | ||
|
|
b59d3ebeaa | ||
|
|
2866dcdd03 | ||
|
|
b147f9d58c | ||
|
|
8e2a6470ac | ||
|
|
19230f7672 | ||
|
|
764dfbe46a | ||
|
|
0ec7631310 | ||
|
|
0b39ece990 | ||
|
|
97500dff57 | ||
|
|
dc6299a029 | ||
|
|
58b1e2fb98 | ||
|
|
0302fdaaba | ||
|
|
09b260e0af | ||
|
|
24b7e998b2 | ||
|
|
19068ea5c7 | ||
|
|
b5cd3eb468 | ||
|
|
91a2b5a5f7 | ||
|
|
0096f6d962 | ||
|
|
87cfe41b15 | ||
|
|
c490086097 | ||
|
|
5b3fd7537e | ||
|
|
2cab2583c0 | ||
|
|
a40a3b594d | ||
|
|
0fa586a3d8 | ||
|
|
25977cc569 | ||
|
|
0be7064493 | ||
|
|
0b13dc254a | ||
|
|
c1e953ab6e | ||
|
|
a069764af1 | ||
|
|
3dbe6c3902 | ||
|
|
9f0b380024 | ||
|
|
193b102013 | ||
|
|
511fde91fa | ||
|
|
16e3cfc589 | ||
|
|
ed2012a36c | ||
|
|
46598fde32 | ||
|
|
94d0c5fa5c | ||
|
|
4e72291588 | ||
|
|
74cdf000b4 | ||
|
|
565dc3327b | ||
|
|
462af21793 | ||
|
|
94af659c86 | ||
|
|
b63c9fc67b | ||
|
|
f519b55a47 | ||
|
|
2fb039b429 | ||
|
|
4bce5aed77 | ||
|
|
eca6032306 | ||
|
|
dd2f515af1 | ||
|
|
df25482643 | ||
|
|
df016b3bf9 | ||
|
|
8699e96609 | ||
|
|
b0dcaaf744 | ||
|
|
7db001995c | ||
|
|
c88adf9314 | ||
|
|
b13713ce98 | ||
|
|
66b89d170f | ||
|
|
4311e2e686 | ||
|
|
fd566eff7a | ||
|
|
efaa3f9e55 | ||
|
|
b625ff0902 | ||
|
|
fee80321ef | ||
|
|
4b9331f086 | ||
|
|
df9316b896 | ||
|
|
dae5f86d4e | ||
|
|
75a0cefcb3 | ||
|
|
2271aa5b89 | ||
|
|
b668e2a967 | ||
|
|
ce44c59547 | ||
|
|
84802d931d | ||
|
|
8183c4383e | ||
|
|
af249098cd | ||
|
|
8fdd063f00 | ||
|
|
fe328f6a75 | ||
|
|
ef7163acd6 | ||
|
|
6e45f0d5b8 | ||
|
|
ff41faa3fe | ||
|
|
acb2d332ea | ||
|
|
0fb86f21e4 | ||
|
|
e4991d367e | ||
|
|
3144cfafd5 | ||
|
|
c538067544 | ||
|
|
f8e137a1dc | ||
|
|
36ea38fd91 | ||
|
|
baae5a7215 | ||
|
|
a4b267227e | ||
|
|
58dd159699 | ||
|
|
80082f9d51 | ||
|
|
7975ffc10b | ||
|
|
012083a4a1 | ||
|
|
3c67723e83 | ||
|
|
7f0598b3cb | ||
|
|
c5b27e0ae0 | ||
|
|
4e7ad31f18 | ||
|
|
c7a3e9d4ac | ||
|
|
a05e7a84c4 | ||
|
|
389cb85410 | ||
|
|
81ae2bed25 | ||
|
|
0ab71bc2e7 | ||
|
|
81e6bbe643 | ||
|
|
c4723f3b24 | ||
|
|
df4d8e0411 | ||
|
|
4f1820bcad | ||
|
|
e375097e43 | ||
|
|
c51bec0034 | ||
|
|
081c3fdb5b | ||
|
|
f1e7602775 | ||
|
|
acd75ffe1c | ||
|
|
fc813cb59b | ||
|
|
044d14f542 | ||
|
|
28b9f07b99 | ||
|
|
6f20dd4e45 | ||
|
|
2fc05e5b90 | ||
|
|
9afde31f97 | ||
|
|
e835ce0697 | ||
|
|
6030f56c76 | ||
|
|
ba89b53c63 | ||
|
|
1bfb877a3b | ||
|
|
72776d6fb6 | ||
|
|
7bb93420c4 | ||
|
|
bb1b0e0581 | ||
|
|
45ddcf0df9 | ||
|
|
9c4d7a286f | ||
|
|
7b290b43b5 | ||
|
|
2e2782b030 | ||
|
|
48f23bd1ba | ||
|
|
3ece33b26a | ||
|
|
efa98379b0 | ||
|
|
324aeba70f | ||
|
|
7b6715c7b5 | ||
|
|
1ea392b6c9 | ||
|
|
8b1a3849e6 | ||
|
|
e1d7e98c92 | ||
|
|
04b2e1152c | ||
|
|
d392eba4a0 | ||
|
|
799dec4f1c | ||
|
|
11df6ec927 | ||
|
|
03e363f5d9 | ||
|
|
39211889b0 | ||
|
|
db44549276 | ||
|
|
49e702c0c7 | ||
|
|
c9c5214b3e | ||
|
|
24a537d154 | ||
|
|
c32ecf171b | ||
|
|
a62ae21628 | ||
|
|
12f05e8f72 | ||
|
|
81fb727d20 | ||
|
|
e7655c761d | ||
|
|
464fcf4300 | ||
|
|
73b67ea9df | ||
|
|
04a9c80c14 | ||
|
|
80b5ed3d22 | ||
|
|
be5ad379b6 | ||
|
|
13d901fbfa | ||
|
|
f7e7273e91 | ||
|
|
4b3bd265a6 | ||
|
|
42dcec961b | ||
|
|
6b2a3b2916 | ||
|
|
930f9ca436 | ||
|
|
a96a767b9b | ||
|
|
36627dbe78 | ||
|
|
f86bc31cbb | ||
|
|
4a08ca4b5e | ||
|
|
e857aa0640 | ||
|
|
d3c98ad334 | ||
|
|
00dadfe14d | ||
|
|
f26fa92d47 | ||
|
|
7458072df2 | ||
|
|
89aa2a1902 | ||
|
|
7ab08779dc | ||
|
|
46b686910b | ||
|
|
940a799207 | ||
|
|
778cee3b27 | ||
|
|
fb3252732b | ||
|
|
608f7b75e2 | ||
|
|
83853c3dee | ||
|
|
8a0343ad6b | ||
|
|
92d43ce620 | ||
|
|
6943822fed | ||
|
|
aa146c4125 | ||
|
|
b8ec6babb5 | ||
|
|
505f4a2b4f | ||
|
|
1bb0d017c3 | ||
|
|
f33ce615d9 | ||
|
|
0edb49d7c6 | ||
|
|
1fa5a03605 | ||
|
|
fc6bda5cd8 | ||
|
|
59589b6a71 | ||
|
|
57b0624a0a | ||
|
|
2f22395eea | ||
|
|
21bc8d4dfb | ||
|
|
2e74fd8196 | ||
|
|
fee48ab04c | ||
|
|
591f885e67 | ||
|
|
ef803016c0 | ||
|
|
bac51045e5 | ||
|
|
cb5e9393a4 | ||
|
|
097509dd2a | ||
|
|
6cd44248c7 | ||
|
|
1fd61fbcef | ||
|
|
cd2245ef03 | ||
|
|
5ddc746915 | ||
|
|
f7d67067ad | ||
|
|
d1a824f76e | ||
|
|
d7b0fc09d7 | ||
|
|
2d07a6ec1f | ||
|
|
014ba5a7aa | ||
|
|
2f12e524dd | ||
|
|
ea6af75e8e | ||
|
|
a595c6ec6f | ||
|
|
98f785d199 | ||
|
|
a0ed0c864f | ||
|
|
d4ac42749e | ||
|
|
86414671d6 | ||
|
|
6cb935982d | ||
|
|
39ad040d8a | ||
|
|
4cc3824653 | ||
|
|
6d3e0600a1 | ||
|
|
b52c9c1676 | ||
|
|
f7506251fe | ||
|
|
5b06f298f1 | ||
|
|
dc5488a198 | ||
|
|
23d162e9e4 | ||
|
|
de6b660b12 | ||
|
|
60c175a51d | ||
|
|
c0a39c8064 | ||
|
|
61f4f93cc6 | ||
|
|
764404a472 | ||
|
|
04da85c88a | ||
|
|
9551b7a597 | ||
|
|
f1d537d035 | ||
|
|
b43e723c84 | ||
|
|
5466039c1a | ||
|
|
74e11117be | ||
|
|
e0abab2dc4 | ||
|
|
08ff3ff55c | ||
|
|
0b79d99cac | ||
|
|
38f655e7b8 | ||
|
|
6f546ffe95 | ||
|
|
ef8211a46e | ||
|
|
52ea5e4074 | ||
|
|
99621cf08a | ||
|
|
a9ae9ce758 | ||
|
|
fc5a529df8 | ||
|
|
bc1081550d | ||
|
|
e311ab1605 | ||
|
|
994ade0638 | ||
|
|
cf9522bd3b | ||
|
|
7fd1858db0 | ||
|
|
c41509151b | ||
|
|
4e12853d4a | ||
|
|
e1fadbc9b9 | ||
|
|
3c4d13d8b9 | ||
|
|
732159db07 | ||
|
|
00894eaccf | ||
|
|
17818178cf | ||
|
|
89c0abfada | ||
|
|
8bbdd92739 | ||
|
|
f724ceb052 | ||
|
|
b7ac85005f | ||
|
|
8ec899a8e7 | ||
|
|
1013c6a50e | ||
|
|
2cd5d3bab3 | ||
|
|
d9494960a2 | ||
|
|
c0eb6590da | ||
|
|
a9cefcb823 | ||
|
|
d1ff491010 | ||
|
|
2aa34f05d3 | ||
|
|
135d6915ee | ||
|
|
6282195b80 | ||
|
|
adec4f08c6 | ||
|
|
b24fe2f122 | ||
|
|
7b35bcb68a | ||
|
|
4b629045c3 | ||
|
|
c6ba1d05d1 | ||
|
|
3adac90573 | ||
|
|
0332188b6b | ||
|
|
790a1e2812 | ||
|
|
3bd1e13321 | ||
|
|
0cd642ca11 | ||
|
|
d5995998b0 | ||
|
|
62babb9c22 | ||
|
|
b98c69521b | ||
|
|
6cd37b3809 | ||
|
|
238170d0e2 | ||
|
|
6fb5b25530 | ||
|
|
d63f9e1eff | ||
|
|
461865bf3b | ||
|
|
e95d9b9cf6 | ||
|
|
c52b2a4fa9 | ||
|
|
d0ec5d2da0 | ||
|
|
6134058abc | ||
|
|
bd4121c260 | ||
|
|
fbab047d7f | ||
|
|
e216144d07 | ||
|
|
94d5b11191 | ||
|
|
d3c89da2eb | ||
|
|
754a8a637e | ||
|
|
ab24a50de7 | ||
|
|
8099dde34b | ||
|
|
99198fb07f | ||
|
|
18d02a0c95 | ||
|
|
e6cac7d5fb | ||
|
|
d8d6f00fee | ||
|
|
ef5c1a1099 | ||
|
|
2d92d8ee67 | ||
|
|
ae60266477 | ||
|
|
88da5261fc | ||
|
|
15efe9f702 | ||
|
|
badbc5c66e | ||
|
|
d6eea41e13 | ||
|
|
6a2c54adf5 | ||
|
|
75d4bc7c18 | ||
|
|
834f7feb27 | ||
|
|
5d2af3f9e1 | ||
|
|
60e8e4a82a | ||
|
|
92e23476ab | ||
|
|
4560fef058 | ||
|
|
c5d6574617 | ||
|
|
de61a0ca45 | ||
|
|
98470caae1 | ||
|
|
53486c067b | ||
|
|
5b805852fa | ||
|
|
94d02eeb4e | ||
|
|
dbfec1b247 | ||
|
|
a9a1a71145 | ||
|
|
91537bf5f3 | ||
|
|
1baad08288 | ||
|
|
1c5b846488 | ||
|
|
6867760cc4 | ||
|
|
516a9209b7 | ||
|
|
e352c953dc | ||
|
|
f455846d18 | ||
|
|
6d45ac942d | ||
|
|
48939abafa | ||
|
|
fbc9595f12 | ||
|
|
ed2c714419 | ||
|
|
ef7731fb8b | ||
|
|
b5ec03f585 | ||
|
|
a8b224a364 | ||
|
|
3f3943a233 | ||
|
|
4171b4ae47 | ||
|
|
baa4c44632 | ||
|
|
ffed8f37de | ||
|
|
8978a0d159 | ||
|
|
4d09be0cd3 | ||
|
|
987be01bd6 | ||
|
|
7f59fc6321 | ||
|
|
feeb122c0d | ||
|
|
0754f108c9 | ||
|
|
ea82f86749 | ||
|
|
7bd217386a | ||
|
|
1f1e02fee1 | ||
|
|
6d1e4fb3da | ||
|
|
9090f84611 | ||
|
|
8e5ddba173 | ||
|
|
86fccb5071 | ||
|
|
414c3baf15 | ||
|
|
bbbddbf617 | ||
|
|
7638b5a95e | ||
|
|
3df6b05c00 | ||
|
|
8566c58f2b | ||
|
|
33ccb71526 | ||
|
|
2b07b92039 | ||
|
|
959bc269e4 | ||
|
|
8609068dbf | ||
|
|
d6cea80768 | ||
|
|
0f2d6fb324 | ||
|
|
f5d303045c | ||
|
|
ad61b0c84e | ||
|
|
18373bb679 | ||
|
|
c30dfe3bfe | ||
|
|
4993961c16 | ||
|
|
89aece7c28 | ||
|
|
ec96946513 | ||
|
|
e49aa0d424 | ||
|
|
b5c929572a | ||
|
|
394822aa50 | ||
|
|
d12ba5e527 | ||
|
|
ab316bcb2e | ||
|
|
93fc08df45 | ||
|
|
266dd02ef5 | ||
|
|
61c1e359e9 | ||
|
|
32c83986e5 | ||
|
|
f64af2e69d | ||
|
|
6e925c7cdd | ||
|
|
5f50f776c6 | ||
|
|
946ccf3db4 | ||
|
|
7a0aea390b | ||
|
|
ff0e6315f9 | ||
|
|
b7fb485349 | ||
|
|
45cbe66d5d | ||
|
|
bc7a6399c1 |
41
.clang-format
Normal file
41
.clang-format
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
BasedOnStyle: llvm
|
||||||
|
---
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
ColumnLimit: 0
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '<[[:alnum:]_]+>'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '<(gtest|gmock)/'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '<[[:alnum:]_./]+>'
|
||||||
|
Priority: 3
|
||||||
|
- Regex: '<entt/'
|
||||||
|
Priority: 4
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 5
|
||||||
|
IndentPPDirectives: AfterHash
|
||||||
|
IndentWidth: 4
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
Language: Cpp
|
||||||
|
PointerAlignment: Right
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceAroundPointerQualifiers: After
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCtorInitializerColon: false
|
||||||
|
SpaceBeforeInheritanceColon: false
|
||||||
|
SpaceBeforeParens: Never
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: false
|
||||||
|
Standard: Latest
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
8
.github/FUNDING.yml
vendored
8
.github/FUNDING.yml
vendored
@@ -1,12 +1,4 @@
|
|||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
github: skypjack
|
github: skypjack
|
||||||
patreon:
|
|
||||||
open_collective:
|
|
||||||
ko_fi:
|
|
||||||
tidelift:
|
|
||||||
community_bridge:
|
|
||||||
liberapay:
|
|
||||||
issuehunt:
|
|
||||||
otechie:
|
|
||||||
custom: https://www.paypal.me/skypjack
|
custom: https://www.paypal.me/skypjack
|
||||||
|
|||||||
154
.github/workflows/build.yml
vendored
154
.github/workflows/build.yml
vendored
@@ -5,48 +5,42 @@ on: [push, pull_request]
|
|||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 15
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
compiler: [
|
compiler:
|
||||||
g++-7, g++-8, g++-9, g++,
|
- pkg: g++-7
|
||||||
clang++-8, clang++-9, clang++-10, clang++
|
exe: g++-7
|
||||||
]
|
- pkg: g++-8
|
||||||
|
exe: g++-8
|
||||||
|
- pkg: g++-9
|
||||||
|
exe: g++-9
|
||||||
|
- pkg: g++-10
|
||||||
|
exe: g++-10
|
||||||
|
- pkg: clang-8
|
||||||
|
exe: clang++-8
|
||||||
|
- pkg: clang-9
|
||||||
|
exe: clang++-9
|
||||||
|
- pkg: clang-10
|
||||||
|
exe: clang++-10
|
||||||
|
- pkg: clang-11
|
||||||
|
exe: clang++-11
|
||||||
|
- pkg: clang-12
|
||||||
|
exe: clang++-12
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Install g++-7
|
- name: Install compiler
|
||||||
if: ${{ matrix.compiler == 'g++-7' }}
|
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt update
|
||||||
sudo apt-get install g++-7 -y
|
sudo apt install -y ${{ matrix.compiler.pkg }}
|
||||||
- name: Install g++-8
|
|
||||||
if: ${{ matrix.compiler == 'g++-8' }}
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install g++-8 -y
|
|
||||||
- name: Install clang-8
|
|
||||||
if: ${{ matrix.compiler == 'clang++-8' }}
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install clang-8 -y
|
|
||||||
- name: Install clang-9
|
|
||||||
if: ${{ matrix.compiler == 'clang++-9' }}
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install clang-9 -y
|
|
||||||
- name: Install clang-10
|
|
||||||
if: ${{ matrix.compiler == 'clang++-10' }}
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install clang-10 -y
|
|
||||||
- name: Compile tests
|
- name: Compile tests
|
||||||
working-directory: build
|
working-directory: build
|
||||||
env:
|
env:
|
||||||
CXX: ${{ matrix.compiler }}
|
CXX: ${{ matrix.compiler.exe }}
|
||||||
run: |
|
run: |
|
||||||
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
|
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
|
||||||
make -j4
|
make -j4
|
||||||
@@ -54,27 +48,49 @@ jobs:
|
|||||||
working-directory: build
|
working-directory: build
|
||||||
env:
|
env:
|
||||||
CTEST_OUTPUT_ON_FAILURE: 1
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
run: ctest --timeout 10 -C Debug -j4
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
|
|
||||||
windows:
|
linux-extra:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 15
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [windows-latest, windows-2016]
|
compiler: [g++, clang++]
|
||||||
toolset: [clang-cl, default, v141]
|
id_type: ["std::uint32_t", "std::uint64_t"]
|
||||||
|
cxx_std: [cxx_std_17, cxx_std_20]
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Compile tests
|
||||||
|
working-directory: build
|
||||||
|
env:
|
||||||
|
CXX: ${{ matrix.compiler }}
|
||||||
|
run: |
|
||||||
|
cmake -DENTT_BUILD_TESTING=ON -DENTT_CXX_STD=${{ matrix.cxx_std }} -DENTT_ID_TYPE=${{ matrix.id_type }} ..
|
||||||
|
make -j4
|
||||||
|
- name: Run tests
|
||||||
|
working-directory: build
|
||||||
|
env:
|
||||||
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
|
|
||||||
|
windows:
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
toolset: [default, v141, v142, clang-cl]
|
||||||
include:
|
include:
|
||||||
- toolset: clang-cl
|
|
||||||
toolset_option: -T"ClangCl"
|
|
||||||
- toolset: v141
|
- toolset: v141
|
||||||
toolset_option: -T"v141"
|
toolset_option: -T"v141"
|
||||||
exclude:
|
- toolset: v142
|
||||||
- os: windows-2016
|
toolset_option: -T"v142"
|
||||||
toolset: clang-cl
|
- toolset: clang-cl
|
||||||
- os: windows-2016
|
toolset_option: -T"ClangCl"
|
||||||
toolset: v141
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@@ -87,10 +103,33 @@ jobs:
|
|||||||
working-directory: build
|
working-directory: build
|
||||||
env:
|
env:
|
||||||
CTEST_OUTPUT_ON_FAILURE: 1
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
run: ctest --timeout 10 -C Debug -j4
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
|
|
||||||
|
windows-extra:
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
id_type: ["std::uint32_t", "std::uint64_t"]
|
||||||
|
cxx_std: [cxx_std_17, cxx_std_20]
|
||||||
|
|
||||||
|
runs-on: windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Compile tests
|
||||||
|
working-directory: build
|
||||||
|
run: |
|
||||||
|
cmake -DENTT_BUILD_TESTING=ON -DENTT_CXX_STD=${{ matrix.cxx_std }} -DENTT_ID_TYPE=${{ matrix.id_type }} ..
|
||||||
|
cmake --build . -j 4
|
||||||
|
- name: Run tests
|
||||||
|
working-directory: build
|
||||||
|
env:
|
||||||
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 15
|
||||||
runs-on: macOS-latest
|
runs-on: macOS-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -104,4 +143,27 @@ jobs:
|
|||||||
working-directory: build
|
working-directory: build
|
||||||
env:
|
env:
|
||||||
CTEST_OUTPUT_ON_FAILURE: 1
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
run: ctest --timeout 10 -C Debug -j4
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
|
|
||||||
|
macos-extra:
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
id_type: ["std::uint32_t", "std::uint64_t"]
|
||||||
|
cxx_std: [cxx_std_17, cxx_std_20]
|
||||||
|
|
||||||
|
runs-on: macOS-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Compile tests
|
||||||
|
working-directory: build
|
||||||
|
run: |
|
||||||
|
cmake -DENTT_BUILD_TESTING=ON -DENTT_CXX_STD=${{ matrix.cxx_std }} -DENTT_ID_TYPE=${{ matrix.id_type }} ..
|
||||||
|
make -j4
|
||||||
|
- name: Run tests
|
||||||
|
working-directory: build
|
||||||
|
env:
|
||||||
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
|
|||||||
56
.github/workflows/coverage.yml
vendored
56
.github/workflows/coverage.yml
vendored
@@ -5,34 +5,34 @@ on: [push, pull_request]
|
|||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
codecov:
|
codecov:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 15
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Compile tests
|
- name: Compile tests
|
||||||
working-directory: build
|
working-directory: build
|
||||||
env:
|
env:
|
||||||
CXXFLAGS: "--coverage -fno-inline"
|
CXXFLAGS: "--coverage -fno-inline"
|
||||||
CXX: g++
|
CXX: g++
|
||||||
run: |
|
run: |
|
||||||
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
|
cmake -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
|
||||||
make -j4
|
make -j4
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
working-directory: build
|
working-directory: build
|
||||||
env:
|
env:
|
||||||
CTEST_OUTPUT_ON_FAILURE: 1
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
run: ctest --timeout 10 -C Debug -j4
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
- name: Collect data
|
- name: Collect data
|
||||||
working-directory: build
|
working-directory: build
|
||||||
run: |
|
run: |
|
||||||
sudo apt install lcov
|
sudo apt install lcov
|
||||||
lcov -c -d . -o coverage.info
|
lcov -c -d . -o coverage.info
|
||||||
lcov -l coverage.info
|
lcov -l coverage.info
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
file: build/coverage.info
|
files: build/coverage.info
|
||||||
name: EnTT
|
name: EnTT
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
|
|||||||
10
.github/workflows/sanitizer.yml
vendored
10
.github/workflows/sanitizer.yml
vendored
@@ -4,12 +4,14 @@ on: [push, pull_request]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
linux:
|
clang:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 15
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
compiler: [clang++]
|
compiler: [clang++]
|
||||||
|
id_type: ["std::uint32_t", "std::uint64_t"]
|
||||||
|
cxx_std: [cxx_std_17, cxx_std_20]
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
@@ -20,10 +22,10 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CXX: ${{ matrix.compiler }}
|
CXX: ${{ matrix.compiler }}
|
||||||
run: |
|
run: |
|
||||||
cmake -DENTT_USE_SANITIZER=ON -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON ..
|
cmake -DENTT_USE_SANITIZER=ON -DENTT_BUILD_TESTING=ON -DENTT_BUILD_LIB=ON -DENTT_BUILD_EXAMPLE=ON -DENTT_CXX_STD=${{ matrix.cxx_std }} -DENTT_ID_TYPE=${{ matrix.id_type }} ..
|
||||||
make -j4
|
make -j4
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
working-directory: build
|
working-directory: build
|
||||||
env:
|
env:
|
||||||
CTEST_OUTPUT_ON_FAILURE: 1
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
run: ctest --timeout 10 -C Debug -j4
|
run: ctest --timeout 30 -C Debug -j4
|
||||||
|
|||||||
3
AUTHORS
3
AUTHORS
@@ -11,6 +11,7 @@ ceeac
|
|||||||
ColinH
|
ColinH
|
||||||
corystegel
|
corystegel
|
||||||
Croydon
|
Croydon
|
||||||
|
cschreib
|
||||||
cugone
|
cugone
|
||||||
dbacchet
|
dbacchet
|
||||||
dBagrat
|
dBagrat
|
||||||
@@ -31,6 +32,7 @@ Lawrencemm
|
|||||||
markand
|
markand
|
||||||
mhammerc
|
mhammerc
|
||||||
Milerius
|
Milerius
|
||||||
|
Minimonium
|
||||||
morbo84
|
morbo84
|
||||||
m-waka
|
m-waka
|
||||||
netpoetica
|
netpoetica
|
||||||
@@ -46,6 +48,7 @@ The5-1
|
|||||||
vblanco20-1
|
vblanco20-1
|
||||||
willtunnels
|
willtunnels
|
||||||
WizardIke
|
WizardIke
|
||||||
|
WoLfulus
|
||||||
w1th0utnam3
|
w1th0utnam3
|
||||||
xissburg
|
xissburg
|
||||||
zaucy
|
zaucy
|
||||||
|
|||||||
172
CMakeLists.txt
172
CMakeLists.txt
@@ -4,14 +4,6 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.12.4)
|
cmake_minimum_required(VERSION 3.12.4)
|
||||||
|
|
||||||
#
|
|
||||||
# Building in-tree is not allowed (we take care of your craziness).
|
|
||||||
#
|
|
||||||
|
|
||||||
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
|
||||||
message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the source code and call cmake from there. Thank you.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Read project version
|
# Read project version
|
||||||
#
|
#
|
||||||
@@ -30,7 +22,7 @@ project(
|
|||||||
VERSION ${ENTT_VERSION}
|
VERSION ${ENTT_VERSION}
|
||||||
DESCRIPTION "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more"
|
DESCRIPTION "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more"
|
||||||
HOMEPAGE_URL "https://github.com/skypjack/entt"
|
HOMEPAGE_URL "https://github.com/skypjack/entt"
|
||||||
LANGUAGES CXX
|
LANGUAGES C CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
@@ -39,40 +31,67 @@ endif()
|
|||||||
|
|
||||||
message(VERBOSE "*")
|
message(VERBOSE "*")
|
||||||
message(VERBOSE "* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
|
message(VERBOSE "* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
|
||||||
message(VERBOSE "* Copyright (c) 2017-2021 Michele Caini <michele.caini@gmail.com>")
|
message(VERBOSE "* Copyright (c) 2017-2022 Michele Caini <michele.caini@gmail.com>")
|
||||||
message(VERBOSE "*")
|
message(VERBOSE "*")
|
||||||
|
|
||||||
option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if availbale." ON)
|
|
||||||
option(ENTT_USE_SANITIZER "Enable sanitizers by adding -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined flags" OFF)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Compiler stuff
|
# Compiler stuff
|
||||||
#
|
#
|
||||||
|
|
||||||
if(NOT WIN32 AND ENTT_USE_LIBCPP)
|
option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if available." OFF)
|
||||||
include(CheckCXXSourceCompiles)
|
option(ENTT_USE_SANITIZER "Enable sanitizers by adding -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined flags if available." OFF)
|
||||||
include(CMakePushCheckState)
|
|
||||||
|
|
||||||
cmake_push_check_state()
|
if(ENTT_USE_LIBCPP)
|
||||||
|
if(NOT WIN32)
|
||||||
|
include(CheckCXXSourceCompiles)
|
||||||
|
include(CMakePushCheckState)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
|
cmake_push_check_state()
|
||||||
|
|
||||||
check_cxx_source_compiles("
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
|
||||||
#include<type_traits>
|
|
||||||
int main() { return std::is_same_v<int, char>; }
|
|
||||||
" ENTT_HAS_LIBCPP)
|
|
||||||
|
|
||||||
if(NOT ENTT_HAS_LIBCPP)
|
check_cxx_source_compiles("
|
||||||
message(VERBOSE "The option ENTT_USE_LIBCPP is set (by default) but libc++ is not available. The flag will not be added to the target.")
|
#include<type_traits>
|
||||||
|
int main() { return std::is_same_v<int, char>; }
|
||||||
|
" ENTT_HAS_LIBCPP)
|
||||||
|
|
||||||
|
cmake_pop_check_state()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
cmake_pop_check_state()
|
if(NOT ENTT_HAS_LIBCPP)
|
||||||
|
message(VERBOSE "The option ENTT_USE_LIBCPP is set but libc++ is not available. The flag will not be added to the target.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENTT_USE_SANITIZER)
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
|
||||||
|
set(ENTT_HAS_SANITIZER TRUE CACHE BOOL "" FORCE)
|
||||||
|
mark_as_advanced(ENTT_HAS_SANITIZER)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ENTT_HAS_SANITIZER)
|
||||||
|
message(VERBOSE "The option ENTT_USE_SANITIZER is set but sanitizer support is not available. The flags will not be added to the target.")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Add EnTT target
|
# Add EnTT target
|
||||||
#
|
#
|
||||||
|
|
||||||
|
option(ENTT_INCLUDE_HEADERS "Add all EnTT headers to the EnTT target." OFF)
|
||||||
|
option(ENTT_INCLUDE_NATVIS "Add EnTT natvis files to the EnTT target." OFF)
|
||||||
|
|
||||||
|
if(ENTT_INCLUDE_NATVIS)
|
||||||
|
if(MSVC)
|
||||||
|
set(ENTT_HAS_NATVIS TRUE CACHE BOOL "" FORCE)
|
||||||
|
mark_as_advanced(ENTT_HAS_NATVIS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ENTT_HAS_NATVIS)
|
||||||
|
message(VERBOSE "The option ENTT_INCLUDE_NATVIS is set but natvis files are not supported. They will not be added to the target.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
add_library(EnTT INTERFACE)
|
add_library(EnTT INTERFACE)
|
||||||
@@ -85,7 +104,103 @@ target_include_directories(
|
|||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
)
|
)
|
||||||
|
|
||||||
if(ENTT_USE_SANITIZER)
|
target_compile_features(EnTT INTERFACE cxx_std_17)
|
||||||
|
|
||||||
|
if(ENTT_INCLUDE_HEADERS)
|
||||||
|
target_sources(
|
||||||
|
EnTT
|
||||||
|
INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/config/config.h>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/config/macro.h>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/config/version.h>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/container/dense_map.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/container/dense_set.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/container/fwd.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/algorithm.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/any.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/attribute.h>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/compressed_pair.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/enum.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/family.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/fwd.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/hashed_string.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/ident.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/iterator.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/memory.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/monostate.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/tuple.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/type_info.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/type_traits.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/core/utility.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/component.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/entity.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/fwd.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/group.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/handle.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/helper.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/observer.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/organizer.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/registry.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/runtime_view.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/sigh_storage_mixin.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/snapshot.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/sparse_set.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/storage.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/utility.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/view.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/locator/locator.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/adl_pointer.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/container.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/ctx.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/factory.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/fwd.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/meta.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/node.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/pointer.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/policy.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/range.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/resolve.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/template.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/type_traits.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/utility.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/platform/android-ndk-r17.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/poly/fwd.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/poly/poly.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/process/process.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/process/scheduler.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/cache.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/fwd.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/loader.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/resource/resource.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/delegate.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/dispatcher.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/emitter.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/fwd.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/signal/sigh.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entt.hpp>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/fwd.hpp>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENTT_HAS_NATVIS)
|
||||||
|
target_sources(
|
||||||
|
EnTT
|
||||||
|
INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/config.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/container.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/core.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/entity.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/locator.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/meta.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/platform.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/poly.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/process.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/resource.natvis>
|
||||||
|
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/natvis/entt/signal.natvis>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENTT_HAS_SANITIZER)
|
||||||
target_compile_options(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
|
target_compile_options(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
|
||||||
target_link_libraries(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
|
target_link_libraries(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
|
||||||
endif()
|
endif()
|
||||||
@@ -94,8 +209,6 @@ if(ENTT_HAS_LIBCPP)
|
|||||||
target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
|
target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_features(EnTT INTERFACE cxx_std_17)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Install pkg-config file
|
# Install pkg-config file
|
||||||
#
|
#
|
||||||
@@ -174,6 +287,9 @@ if(ENTT_BUILD_TESTING)
|
|||||||
option(ENTT_BUILD_LIB "Build lib tests." OFF)
|
option(ENTT_BUILD_LIB "Build lib tests." OFF)
|
||||||
option(ENTT_BUILD_SNAPSHOT "Build snapshot test with Cereal." OFF)
|
option(ENTT_BUILD_SNAPSHOT "Build snapshot test with Cereal." OFF)
|
||||||
|
|
||||||
|
set(ENTT_ID_TYPE std::uint32_t CACHE STRING "Type of identifiers to use for the tests")
|
||||||
|
set(ENTT_CXX_STD cxx_std_17 CACHE STRING "C++ standard revision to use for the tests")
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
First of all, thank you very much for taking the time to contribute to the
|
First of all, thank you very much for taking the time to contribute to the
|
||||||
`EnTT` framework.<br/>
|
`EnTT` library.<br/>
|
||||||
How to do it mostly depends on the type of contribution:
|
How to do it mostly depends on the type of contribution:
|
||||||
|
|
||||||
* If you have a question, **please** ensure there isn't already an answer for
|
* If you have a question, **please** ensure there isn't already an answer for
|
||||||
@@ -28,7 +28,7 @@ How to do it mostly depends on the type of contribution:
|
|||||||
* If you found a bug and you wrote a patch to fix it, open a new
|
* If you found a bug and you wrote a patch to fix it, open a new
|
||||||
[pull request](https://github.com/skypjack/entt/pulls) with your code.
|
[pull request](https://github.com/skypjack/entt/pulls) with your code.
|
||||||
**Please**, add some tests to avoid regressions in future if possible, it
|
**Please**, add some tests to avoid regressions in future if possible, it
|
||||||
would be really appreciated. Note that the `EnTT` framework has a
|
would be really appreciated. Note that the `EnTT` library has a
|
||||||
[coverage at 100%](https://coveralls.io/github/skypjack/entt?branch=master)
|
[coverage at 100%](https://coveralls.io/github/skypjack/entt?branch=master)
|
||||||
(at least it was at 100% at the time I wrote this file) and this is the reason
|
(at least it was at 100% at the time I wrote this file) and this is the reason
|
||||||
for which you can be confident with using it in a production environment.
|
for which you can be confident with using it in a production environment.
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2017-2021 Michele Caini
|
Copyright (c) 2017-2022 Michele Caini, author of EnTT
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
47
README.md
47
README.md
@@ -11,6 +11,9 @@
|
|||||||
[](https://discord.gg/5BjPWBd)
|
[](https://discord.gg/5BjPWBd)
|
||||||
[](https://www.paypal.me/skypjack)
|
[](https://www.paypal.me/skypjack)
|
||||||
|
|
||||||
|
> `EnTT` has been a dream so far, we haven't found a single bug to date and it's
|
||||||
|
> super easy to work with
|
||||||
|
|
||||||
`EnTT` is a header-only, tiny and easy to use library for game programming and
|
`EnTT` is a header-only, tiny and easy to use library for game programming and
|
||||||
much more written in **modern C++**.<br/>
|
much more written in **modern C++**.<br/>
|
||||||
[Among others](https://github.com/skypjack/entt/wiki/EnTT-in-Action), it's used
|
[Among others](https://github.com/skypjack/entt/wiki/EnTT-in-Action), it's used
|
||||||
@@ -49,6 +52,7 @@ Many thanks to [these people](https://skypjack.github.io/sponsorship/) and
|
|||||||
* [Integration](#integration)
|
* [Integration](#integration)
|
||||||
* [Requirements](#requirements)
|
* [Requirements](#requirements)
|
||||||
* [CMake](#cmake)
|
* [CMake](#cmake)
|
||||||
|
* [Natvis support](#natvis-support)
|
||||||
* [Packaging Tools](#packaging-tools)
|
* [Packaging Tools](#packaging-tools)
|
||||||
* [pkg-config](#pkg-config)
|
* [pkg-config](#pkg-config)
|
||||||
* [Documentation](#documentation)
|
* [Documentation](#documentation)
|
||||||
@@ -73,33 +77,32 @@ This project started off as a pure entity-component system. Over time the
|
|||||||
codebase has grown as more and more classes and functionalities were added.<br/>
|
codebase has grown as more and more classes and functionalities were added.<br/>
|
||||||
Here is a brief, yet incomplete list of what it offers today:
|
Here is a brief, yet incomplete list of what it offers today:
|
||||||
|
|
||||||
* Statically generated integer **identifiers** for types (assigned either at
|
* Built-in **RTTI system** mostly similar to the standard one.
|
||||||
compile-time or at runtime).
|
|
||||||
* A `constexpr` utility for human readable **resource names**.
|
* A `constexpr` utility for human readable **resource names**.
|
||||||
* A minimal **configuration system** built using the monostate pattern.
|
* Minimal **configuration system** built using the monostate pattern.
|
||||||
* An incredibly fast **entity-component system** based on sparse sets, with its
|
* Incredibly fast **entity-component system** with its own _pay for what you
|
||||||
own _pay for what you use_ policy to adjust performance and memory usage
|
use_ policy.
|
||||||
according to the users' requirements.
|
|
||||||
* Views and groups to iterate entities and components and allow different access
|
* Views and groups to iterate entities and components and allow different access
|
||||||
patterns, from **perfect SoA** to fully random.
|
patterns, from **perfect SoA** to fully random.
|
||||||
* A lot of **facilities** built on top of the entity-component system to help
|
* A lot of **facilities** built on top of the entity-component system to help
|
||||||
the users and avoid reinventing the wheel (dependencies, snapshot, handles,
|
the users and avoid reinventing the wheel.
|
||||||
support for **reactive systems** and so on).
|
|
||||||
* The smallest and most basic implementation of a **service locator** ever seen.
|
* The smallest and most basic implementation of a **service locator** ever seen.
|
||||||
* A built-in, non-intrusive and macro-free runtime **reflection system**.
|
* A built-in, non-intrusive and macro-free runtime **reflection system**.
|
||||||
* **Static polymorphism** made simple and within everyone's reach.
|
* **Static polymorphism** made simple and within everyone's reach.
|
||||||
|
* A few homemade containers, like a sparse set based **hash map**.
|
||||||
* A **cooperative scheduler** for processes of any type.
|
* A **cooperative scheduler** for processes of any type.
|
||||||
* All that is needed for **resource management** (cache, loaders, handles).
|
* All that is needed for **resource management** (cache, loaders, handles).
|
||||||
* Delegates, **signal handlers** (with built-in support for collectors) and a
|
* Delegates, **signal handlers** and a tiny event dispatcher.
|
||||||
tiny event dispatcher for immediate and delayed events to integrate in loops.
|
|
||||||
* A general purpose **event emitter** as a CRTP idiom based class template.
|
* A general purpose **event emitter** as a CRTP idiom based class template.
|
||||||
* And **much more**! Check out the
|
* And **much more**! Check out the
|
||||||
[**wiki**](https://github.com/skypjack/entt/wiki).
|
[**wiki**](https://github.com/skypjack/entt/wiki).
|
||||||
|
|
||||||
Consider this list a work in progress as well as the project. The whole API is
|
Consider these lists a work in progress as well as the project. The whole API is
|
||||||
fully documented in-code for those who are brave enough to read it.
|
fully documented in-code for those who are brave enough to read it.<br/>
|
||||||
|
Please, do note that all tools are also DLL-friendly now and run smoothly across
|
||||||
|
boundaries.
|
||||||
|
|
||||||
It is also known that `EnTT` is used in **Minecraft**.<br/>
|
One thing known to most is that `EnTT` is also used in **Minecraft**.<br/>
|
||||||
Given that the game is available literally everywhere, I can confidently say
|
Given that the game is available literally everywhere, I can confidently say
|
||||||
that the library has been sufficiently tested on every platform that can come to
|
that the library has been sufficiently tested on every platform that can come to
|
||||||
mind.
|
mind.
|
||||||
@@ -156,7 +159,7 @@ int main() {
|
|||||||
## Motivation
|
## Motivation
|
||||||
|
|
||||||
I started developing `EnTT` for the _wrong_ reason: my goal was to design an
|
I started developing `EnTT` for the _wrong_ reason: my goal was to design an
|
||||||
entity-component system to beat another well known open source solution both in
|
entity-component system to beat another well known open source library both in
|
||||||
terms of performance and possibly memory usage.<br/>
|
terms of performance and possibly memory usage.<br/>
|
||||||
In the end, I did it, but it wasn't very satisfying. Actually it wasn't
|
In the end, I did it, but it wasn't very satisfying. Actually it wasn't
|
||||||
satisfying at all. The fastest and nothing more, fairly little indeed. When I
|
satisfying at all. The fastest and nothing more, fairly little indeed. When I
|
||||||
@@ -246,6 +249,14 @@ Covering all possible cases would require a treaty and not a simple README file,
|
|||||||
but I'm confident that anyone reading this section also knows what it's about
|
but I'm confident that anyone reading this section also knows what it's about
|
||||||
and can use `EnTT` from a `CMake` project without problems.
|
and can use `EnTT` from a `CMake` project without problems.
|
||||||
|
|
||||||
|
## Natvis support
|
||||||
|
|
||||||
|
When using `CMake`, just enable the option `ENTT_INCLUDE_NATVIS` and enjoy
|
||||||
|
it.<br/>
|
||||||
|
Otherwise, most of the tools are covered via Natvis and all files can be found
|
||||||
|
in the `natvis` directory, divided by module.<br/>
|
||||||
|
If you spot errors or have suggestions, any contribution is welcome!
|
||||||
|
|
||||||
## Packaging Tools
|
## Packaging Tools
|
||||||
|
|
||||||
`EnTT` is available for some of the most known packaging tools. In particular:
|
`EnTT` is available for some of the most known packaging tools. In particular:
|
||||||
@@ -265,6 +276,12 @@ and can use `EnTT` from a `CMake` project without problems.
|
|||||||
$ vcpkg install entt
|
$ vcpkg install entt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or you can use the `experimental` feature to test the latest changes:
|
||||||
|
|
||||||
|
```
|
||||||
|
vcpkg install entt[experimental] --head
|
||||||
|
```
|
||||||
|
|
||||||
The `EnTT` port in `vcpkg` is kept up to date by Microsoft team members and
|
The `EnTT` port in `vcpkg` is kept up to date by Microsoft team members and
|
||||||
community contributors.<br/>
|
community contributors.<br/>
|
||||||
If the version is out of date, please
|
If the version is out of date, please
|
||||||
@@ -399,7 +416,7 @@ know who has participated so far.
|
|||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
Code and documentation Copyright (c) 2017-2021 Michele Caini.<br/>
|
Code and documentation Copyright (c) 2017-2022 Michele Caini.<br/>
|
||||||
Colorful logo Copyright (c) 2018-2021 Richard Caseres.
|
Colorful logo Copyright (c) 2018-2021 Richard Caseres.
|
||||||
|
|
||||||
Code released under
|
Code released under
|
||||||
|
|||||||
38
TODO
38
TODO
@@ -1,36 +1,26 @@
|
|||||||
* long term feature: shared_ptr less locator and resource cache
|
|
||||||
* debugging tools (#60): the issue online already contains interesting tips on this, look at it
|
* debugging tools (#60): the issue online already contains interesting tips on this, look at it
|
||||||
* work stealing job system (see #100) + mt scheduler based on const awareness for types
|
* work stealing job system (see #100) + mt scheduler based on const awareness for types
|
||||||
* allow to replace std:: with custom implementations
|
|
||||||
* add examples (and credits) from @alanjfs :)
|
* add examples (and credits) from @alanjfs :)
|
||||||
* custom pools example (multi instance, tables, enable/disable, and so on...)
|
|
||||||
|
EXAMPLES
|
||||||
|
* filter on runtime values/variables (not only types)
|
||||||
|
* support to polymorphic types (see #859)
|
||||||
|
|
||||||
WIP:
|
WIP:
|
||||||
* remove view/storage dispatcher, add support to relax policy constraints on user request (eg view.use<T>())
|
* view/group: no storage_traits dependency -> use storage instead of components for the definition
|
||||||
* improve perf for sparse_set/storage::insert/emplace/destroy/remove/...
|
* basic_storage::bind for cross-registry setups
|
||||||
* custom allocators all over
|
* uses-allocator construction: any (with allocator support), poly, ...
|
||||||
|
* process scheduler: reviews, use free lists internally
|
||||||
|
* iterator based try_emplace vs try_insert for perf reasons
|
||||||
|
* dedicated entity storage, in-place O(1) release/destroy for non-orphaned entities, out-of-sync model
|
||||||
|
* entity-only and exclude-only views
|
||||||
|
* custom allocators all over (sigh storage mixin, registry, ...)
|
||||||
|
* consider removing ENTT_NOEXCEPT, use ENTT_NOEXCEPT_IF (or noexcept(...)) as appropriate in any case (ie make compressed_pair conditionally noexcept)
|
||||||
|
* add test for maximum number of entities reached
|
||||||
|
|
||||||
WIP:
|
WIP:
|
||||||
* make value_type available from meta container types, otherwise we have to default construct a container to get it
|
|
||||||
* make it possible to register externally managed pools with the registry (allow for system centric mode)
|
|
||||||
* registry: switch to the udata/mixin model and get rid of poly storage, use pointer to sparse set only for pools, discard pool_data type.
|
|
||||||
* it's now possible to have 0 as null entity/version, so we can finally switch to it
|
|
||||||
* make pools available (registry/view/group), review operator| for views
|
|
||||||
* page size: add per-pool size, allow for 0 sizes (old fully packed array)
|
|
||||||
* compressed pair to exploit ebo in sparse set and the others
|
|
||||||
* isolate view iterator, unwrap iterators in registry ::remove/::erase/::destroy to use the faster solution for non-view iterators
|
|
||||||
* remove view each<T>(F), each<T>(), make view::use return a view and remove the mutable data member
|
|
||||||
* resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
|
|
||||||
* make it possible to create views of the type `view<T, T>`, add get by index and such, allow to register custom pools by name with the registry
|
|
||||||
* add user data to type_info
|
* add user data to type_info
|
||||||
* any_vector for context variables
|
|
||||||
* make const registry::view thread safe, switch to a view<T...>{registry} model (long term goal)
|
|
||||||
* weak reference wrapper example with custom storage
|
|
||||||
* headless (sparse set only) view
|
|
||||||
* write documentation for custom storages and views!!
|
* write documentation for custom storages and views!!
|
||||||
* make runtime views use opaque storage and therefore return also elements.
|
* make runtime views use opaque storage and therefore return also elements.
|
||||||
* add exclude-only views to combine with packs
|
|
||||||
* entity-aware observer, add observer functions aside observer class
|
* entity-aware observer, add observer functions aside observer class
|
||||||
* deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views
|
* deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views
|
||||||
* snapshot: support for range-based archives
|
|
||||||
* add example: 64 bit ids with 32 bits reserved for users' purposes
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ add_custom_target(
|
|||||||
SOURCES
|
SOURCES
|
||||||
dox/extra.dox
|
dox/extra.dox
|
||||||
md/config.md
|
md/config.md
|
||||||
|
md/container.md
|
||||||
md/core.md
|
md/core.md
|
||||||
md/entity.md
|
md/entity.md
|
||||||
md/faq.md
|
md/faq.md
|
||||||
|
|||||||
67
docs/md/container.md
Normal file
67
docs/md/container.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# Crash Course: containers
|
||||||
|
|
||||||
|
<!--
|
||||||
|
@cond TURN_OFF_DOXYGEN
|
||||||
|
-->
|
||||||
|
# Table of Contents
|
||||||
|
|
||||||
|
* [Introduction](#introduction)
|
||||||
|
* [Containers](#containers)
|
||||||
|
* [Dense map](#dense-map)
|
||||||
|
* [Dense set](#dense-set)
|
||||||
|
|
||||||
|
<!--
|
||||||
|
@endcond TURN_OFF_DOXYGEN
|
||||||
|
-->
|
||||||
|
|
||||||
|
# Introduction
|
||||||
|
|
||||||
|
The standard C++ library offers a wide range of containers and it's really
|
||||||
|
difficult to do better (although it's very easy to do worse, as many examples
|
||||||
|
available online demonstrate).<br/>
|
||||||
|
`EnTT` doesn't try in any way to replace what is offered by the standard. Quite
|
||||||
|
the opposite, given the widespread use that is made of standard containers.<br/>
|
||||||
|
However, the library also tries to fill a gap in features and functionality by
|
||||||
|
making available some containers initially developed for internal use.
|
||||||
|
|
||||||
|
This section of the library is likely to grow larger over time. However, for the
|
||||||
|
moment it's quite small and mainly aimed at satisfying some internal needs.<br/>
|
||||||
|
For all containers made available, full test coverage and stability over time is
|
||||||
|
guaranteed as usual.
|
||||||
|
|
||||||
|
# Containers
|
||||||
|
|
||||||
|
## Dense map
|
||||||
|
|
||||||
|
The dense map made available in `EnTT` is a hash map that aims to return a
|
||||||
|
packed array of elements, so as to reduce the number of jumps in memory during
|
||||||
|
iterations.<br/>
|
||||||
|
The implementation is based on _sparse sets_ and each bucket is identified by an
|
||||||
|
implicit list within the packed array itself.
|
||||||
|
|
||||||
|
The interface is very close to its counterpart in the standard library, that is,
|
||||||
|
`std::unordered_map`.<br/>
|
||||||
|
However, both local and non-local iterators returned by a dense map belong to
|
||||||
|
the input iterator category although they respectively model the concepts of a
|
||||||
|
_forward iterator_ type and a _random access iterator_ type.<br/>
|
||||||
|
This is because they return a pair of references rather than a reference to a
|
||||||
|
pair. In other words, dense maps return a so called _proxy iterator_ the value
|
||||||
|
type of which is:
|
||||||
|
|
||||||
|
* `std::pair<const Key &, Type &>` for non-const iterator types.
|
||||||
|
* `std::pair<const Key &, const Type &>` for const iterator types.
|
||||||
|
|
||||||
|
This is quite different from what any standard library map returns and should be
|
||||||
|
taken into account when looking for a drop-in replacement.
|
||||||
|
|
||||||
|
## Dense set
|
||||||
|
|
||||||
|
The dense set made available in `EnTT` is a hash set that aims to return a
|
||||||
|
packed array of elements, so as to reduce the number of jumps in memory during
|
||||||
|
iterations.<br/>
|
||||||
|
The implementation is based on _sparse sets_ and each bucket is identified by an
|
||||||
|
implicit list within the packed array itself.
|
||||||
|
|
||||||
|
The interface is in all respects similar to its counterpart in the standard
|
||||||
|
library, that is, `std::unordered_set`.<br/>
|
||||||
|
Therefore, there is no need to go into the API description.
|
||||||
696
docs/md/core.md
696
docs/md/core.md
@@ -6,18 +6,21 @@
|
|||||||
# Table of Contents
|
# Table of Contents
|
||||||
|
|
||||||
* [Introduction](#introduction)
|
* [Introduction](#introduction)
|
||||||
* [Unique sequential identifiers](#unique-sequential-identifiers)
|
|
||||||
* [Compile-time generator](#compile-time-generator)
|
|
||||||
* [Runtime generator](#runtime-generator)
|
|
||||||
* [Hashed strings](#hashed-strings)
|
|
||||||
* [Wide characters](wide-characters)
|
|
||||||
* [Conflicts](#conflicts)
|
|
||||||
* [Monostate](#monostate)
|
|
||||||
* [Any as in any type](#any-as-in-any-type)
|
* [Any as in any type](#any-as-in-any-type)
|
||||||
* [Small buffer optimization](#small-buffer-optimization)
|
* [Small buffer optimization](#small-buffer-optimization)
|
||||||
* [Alignment requirement](#alignment-requirement)
|
* [Alignment requirement](#alignment-requirement)
|
||||||
|
* [Compressed pair](#compressed-pair)
|
||||||
|
* [Enum as bitmask](#enum-as-bitmask)
|
||||||
|
* [Hashed strings](#hashed-strings)
|
||||||
|
* [Wide characters](wide-characters)
|
||||||
|
* [Conflicts](#conflicts)
|
||||||
|
* [Memory](#memory)
|
||||||
|
* [Power of two and fast modulus](#power-of-two-and-fast-modulus)
|
||||||
|
* [Allocator aware unique pointers](#allocator-aware-unique-pointers)
|
||||||
|
* [Monostate](#monostate)
|
||||||
* [Type support](#type-support)
|
* [Type support](#type-support)
|
||||||
* [Type info](#type-info)
|
* [Built-in RTTI support](#built-in-rtti-support)
|
||||||
|
* [Type info](#type-info)
|
||||||
* [Almost unique identifiers](#almost-unique-identifiers)
|
* [Almost unique identifiers](#almost-unique-identifiers)
|
||||||
* [Type traits](#type-traits)
|
* [Type traits](#type-traits)
|
||||||
* [Size of](#size-of)
|
* [Size of](#size-of)
|
||||||
@@ -27,6 +30,9 @@
|
|||||||
* [Integral constant](#integral-constant)
|
* [Integral constant](#integral-constant)
|
||||||
* [Tag](#tag)
|
* [Tag](#tag)
|
||||||
* [Type list and value list](#type-list-and-value-list)
|
* [Type list and value list](#type-list-and-value-list)
|
||||||
|
* [Unique sequential identifiers](#unique-sequential-identifiers)
|
||||||
|
* [Compile-time generator](#compile-time-generator)
|
||||||
|
* [Runtime generator](#runtime-generator)
|
||||||
* [Utilities](#utilities)
|
* [Utilities](#utilities)
|
||||||
<!--
|
<!--
|
||||||
@endcond TURN_OFF_DOXYGEN
|
@endcond TURN_OFF_DOXYGEN
|
||||||
@@ -39,80 +45,249 @@ of the library itself.<br/>
|
|||||||
Hardly users will include these features in their code, but it's worth
|
Hardly users will include these features in their code, but it's worth
|
||||||
describing what `EnTT` offers so as not to reinvent the wheel in case of need.
|
describing what `EnTT` offers so as not to reinvent the wheel in case of need.
|
||||||
|
|
||||||
# Unique sequential identifiers
|
# Any as in any type
|
||||||
|
|
||||||
Sometimes it's useful to be able to give unique, sequential numeric identifiers
|
`EnTT` comes with its own `any` type. It may seem redundant considering that
|
||||||
to types either at compile-time or runtime.<br/>
|
C++17 introduced `std::any`, but it is not (hopefully).<br/>
|
||||||
There are plenty of different solutions for this out there and I could have used
|
First of all, the _type_ returned by an `std::any` is a const reference to an
|
||||||
one of them. However, I decided to spend my time to define a couple of tools
|
`std::type_info`, an implementation defined class that's not something everyone
|
||||||
that fully embraces what the modern C++ has to offer.
|
wants to see in a software. Furthermore, there is no way to connect it with the
|
||||||
|
type system of the library and therefore with its integrated RTTI support.<br/>
|
||||||
|
Note that this class is largely used internally by the library itself.
|
||||||
|
|
||||||
## Compile-time generator
|
The API is very similar to that of its most famous counterpart, mainly because
|
||||||
|
this class serves the same purpose of being an opaque container for any type of
|
||||||
|
value.<br/>
|
||||||
|
Instances of `any` also minimize the number of allocations by relying on a well
|
||||||
|
known technique called _small buffer optimization_ and a fake vtable.
|
||||||
|
|
||||||
To generate sequential numeric identifiers at compile-time, `EnTT` offers the
|
Creating an object of the `any` type, whether empty or not, is trivial:
|
||||||
`identifier` class template:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// defines the identifiers for the given types
|
// an empty container
|
||||||
using id = entt::identifier<a_type, another_type>;
|
entt::any empty{};
|
||||||
|
|
||||||
// ...
|
// a container for an int
|
||||||
|
entt::any any{0};
|
||||||
|
|
||||||
switch(a_type_identifier) {
|
// in place construction
|
||||||
case id::type<a_type>:
|
entt::any in_place{std::in_place_type<int>, 42};
|
||||||
// ...
|
|
||||||
break;
|
|
||||||
case id::type<another_type>:
|
|
||||||
// ...
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This is all what this class template has to offer: a `type` inline variable that
|
Alternatively, the `make_any` function serves the same purpose but requires to
|
||||||
contains a numeric identifier for the given type. It can be used in any context
|
always be explicit about the type:
|
||||||
where constant expressions are required.
|
|
||||||
|
|
||||||
As long as the list remains unchanged, identifiers are also guaranteed to be
|
|
||||||
stable across different runs. In case they have been used in a production
|
|
||||||
environment and a type has to be removed, one can just use a placeholder to left
|
|
||||||
the other identifiers unchanged:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template<typename> struct ignore_type {};
|
entt::any any = entt::make_any<int>(42);
|
||||||
|
|
||||||
using id = entt::identifier<
|
|
||||||
a_type_still_valid,
|
|
||||||
ignore_type<a_type_no_longer_valid>,
|
|
||||||
another_type_still_valid
|
|
||||||
>;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Perhaps a bit ugly to see in a codebase but it gets the job done at least.
|
In both cases, the `any` class takes the burden of destroying the contained
|
||||||
|
element when required, regardless of the storage strategy used for the specific
|
||||||
|
object.<br/>
|
||||||
|
Furthermore, an instance of `any` isn't tied to an actual type. Therefore, the
|
||||||
|
wrapper is reconfigured when it's assigned a new object of a type other than
|
||||||
|
the one it contains.
|
||||||
|
|
||||||
## Runtime generator
|
There exists also a way to directly assign a value to the variable contained by
|
||||||
|
an `entt::any`, without necessarily replacing it. This is especially useful when
|
||||||
To generate sequential numeric identifiers at runtime, `EnTT` offers the
|
the object is used in _aliasing mode_, as described below:
|
||||||
`family` class template:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// defines a custom generator
|
entt::any any{42};
|
||||||
using id = entt::family<struct my_tag>;
|
entt::any value{3};
|
||||||
|
|
||||||
// ...
|
// assigns by copy
|
||||||
|
any.assign(value);
|
||||||
|
|
||||||
const auto a_type_id = id::type<a_type>;
|
// assigns by move
|
||||||
const auto another_type_id = id::type<another_type>;
|
any.assign(std::move(value));
|
||||||
```
|
```
|
||||||
|
|
||||||
This is all what a _family_ has to offer: a `type` inline variable that contains
|
The `any` class will also perform a check on the type information and whether or
|
||||||
a numeric identifier for the given type.<br/>
|
not the original type was copy or move assignable, as appropriate.<br/>
|
||||||
The generator is customizable, so as to get different _sequences_ for different
|
In all cases, the `assign` function returns a boolean value to indicate the
|
||||||
purposes if needed.
|
success or failure of the operation.
|
||||||
|
|
||||||
Please, note that identifiers aren't guaranteed to be stable across different
|
When in doubt about the type of object contained, the `type` member function of
|
||||||
runs. Indeed it mostly depends on the flow of execution.
|
`any` returns a const reference to the `type_info` associated with its element,
|
||||||
|
or `type_id<void>()` if the container is empty. The type is also used internally
|
||||||
|
when comparing two `any` objects:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if(any == empty) { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case, before proceeding with a comparison, it's verified that the _type_
|
||||||
|
of the two objects is actually the same.<br/>
|
||||||
|
Refer to the `EnTT` type system documentation for more details about how
|
||||||
|
`type_info` works and on possible risks of a comparison.
|
||||||
|
|
||||||
|
A particularly interesting feature of this class is that it can also be used as
|
||||||
|
an opaque container for const and non-const references:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
int value = 42;
|
||||||
|
|
||||||
|
entt::any any{std::in_place_type<int &>(value)};
|
||||||
|
entt::any cany = entt::make_any<const int &>(value);
|
||||||
|
entt::any fwd = entt::forward_as_any(value);
|
||||||
|
|
||||||
|
any.emplace<const int &>(value);
|
||||||
|
```
|
||||||
|
|
||||||
|
In other words, whenever `any` is explicitly told to construct an _alias_, it
|
||||||
|
acts as a pointer to the original instance rather than making a copy of it or
|
||||||
|
moving it internally. The contained object is never destroyed and users must
|
||||||
|
ensure that its lifetime exceeds that of the container.<br/>
|
||||||
|
Similarly, it's possible to create non-owning copies of `any` from an existing
|
||||||
|
object:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// aliasing constructor
|
||||||
|
entt::any ref = other.as_ref();
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case, it doesn't matter if the original container actually holds an
|
||||||
|
object or acts already as a reference for unmanaged elements, the new instance
|
||||||
|
thus created won't create copies and will only serve as a reference for the
|
||||||
|
original item.<br/>
|
||||||
|
This means that, starting from the example above, both `ref` and `other` will
|
||||||
|
point to the same object, whether it's initially contained in `other` or already
|
||||||
|
an unmanaged element.
|
||||||
|
|
||||||
|
As a side note, it's worth mentioning that, while everything works transparently
|
||||||
|
when it comes to non-const references, there are some exceptions when it comes
|
||||||
|
to const references.<br/>
|
||||||
|
In particular, the `data` member function invoked on a non-const instance of
|
||||||
|
`any` that wraps a const reference will return a null pointer in all cases.
|
||||||
|
|
||||||
|
To cast an instance of `any` to a type, the library offers a set of `any_cast`
|
||||||
|
functions in all respects similar to their most famous counterparts.<br/>
|
||||||
|
The only difference is that, in the case of `EnTT`, these won't raise exceptions
|
||||||
|
but will only trigger an assert in debug mode, otherwise resulting in undefined
|
||||||
|
behavior in case of misuse in release mode.
|
||||||
|
|
||||||
|
## Small buffer optimization
|
||||||
|
|
||||||
|
The `any` class uses a technique called _small buffer optimization_ to reduce
|
||||||
|
the number of allocations where possible.<br/>
|
||||||
|
The default reserved size for an instance of `any` is `sizeof(double[2])`.
|
||||||
|
However, this is also configurable if needed. In fact, `any` is defined as an
|
||||||
|
alias for `basic_any<Len>`, where `Len` is the size above.<br/>
|
||||||
|
Users can easily set a custom size or define their own aliases:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using my_any = entt::basic_any<sizeof(double[4])>;
|
||||||
|
```
|
||||||
|
|
||||||
|
This feature, in addition to allowing the choice of a size that best suits the
|
||||||
|
needs of an application, also offers the possibility of forcing dynamic creation
|
||||||
|
of objects during construction.<br/>
|
||||||
|
In other terms, if the size is 0, `any` avoids the use of any optimization and
|
||||||
|
always dynamically allocates objects (except for aliasing cases).
|
||||||
|
|
||||||
|
Note that the size of the internal storage as well as the alignment requirements
|
||||||
|
are directly part of the type and therefore contribute to define different types
|
||||||
|
that won't be able to interoperate with each other.
|
||||||
|
|
||||||
|
## Alignment requirement
|
||||||
|
|
||||||
|
The alignment requirement is optional and by default the most stringent (the
|
||||||
|
largest) for any object whose size is at most equal to the one provided.<br/>
|
||||||
|
The `basic_any` class template inspects the alignment requirements in each case,
|
||||||
|
even when not provided and may decide not to use the small buffer optimization
|
||||||
|
in order to meet them.
|
||||||
|
|
||||||
|
The alignment requirement is provided as an optional second parameter following
|
||||||
|
the desired size for the internal storage:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using my_any = entt::basic_any<sizeof(double[4]), alignof(double[4])>;
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that the alignment requirements as well as the size of the internal storage
|
||||||
|
are directly part of the type and therefore contribute to define different types
|
||||||
|
that won't be able to interoperate with each other.
|
||||||
|
|
||||||
|
# Compressed pair
|
||||||
|
|
||||||
|
Primarily designed for internal use and far from being feature complete, the
|
||||||
|
`compressed_pair` class does exactly what it promises: it tries to reduce the
|
||||||
|
size of a pair by exploiting _Empty Base Class Optimization_ (or _EBCO_).<br/>
|
||||||
|
This class **is not** a drop-in replacement for `std::pair`. However, it offers
|
||||||
|
enough functionalities to be a good alternative for when reducing memory usage
|
||||||
|
is more important than having some cool and probably useless feature.
|
||||||
|
|
||||||
|
Although the API is very close to that of `std::pair` (apart from the fact that
|
||||||
|
the template parameters are inferred from the constructor and therefore there is
|
||||||
|
no` entt::make_compressed_pair`), the major difference is that `first` and
|
||||||
|
`second` are functions for implementation needs:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::compressed_pair pair{0, 3.};
|
||||||
|
pair.first() = 42;
|
||||||
|
```
|
||||||
|
|
||||||
|
There isn't much to describe then. It's recommended to rely on documentation and
|
||||||
|
intuition. At the end of the day, it's just a pair and nothing more.
|
||||||
|
|
||||||
|
# Enum as bitmask
|
||||||
|
|
||||||
|
Sometimes it's useful to be able to use enums as bitmasks. However, enum classes
|
||||||
|
aren't really suitable for the purpose out of the box. Main problem is that they
|
||||||
|
don't convert implicitly to their underlying type.<br/>
|
||||||
|
All that remains is to make a choice between using old-fashioned enums (with all
|
||||||
|
their problems that I don't want to discuss here) or writing _ugly_ code.
|
||||||
|
|
||||||
|
Fortunately, there is also a third way: adding enough operators in the global
|
||||||
|
scope to treat enum classes as bitmask transparently.<br/>
|
||||||
|
The ultimate goal is to be able to write code like the following (or maybe
|
||||||
|
something more meaningful, but this should give a grasp and remain simple at the
|
||||||
|
same time):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
enum class my_flag {
|
||||||
|
unknown = 0x01,
|
||||||
|
enabled = 0x02,
|
||||||
|
disabled = 0x04
|
||||||
|
};
|
||||||
|
|
||||||
|
const my_flag flags = my_flag::enabled;
|
||||||
|
const bool is_enabled = !!(flags & my_flag::enabled);
|
||||||
|
```
|
||||||
|
|
||||||
|
The problem with adding all operators to the global scope is that these will
|
||||||
|
come into play even when not required, with the risk of introducing errors that
|
||||||
|
are difficult to deal with.<br/>
|
||||||
|
However, C++ offers enough tools to get around this problem. In particular, the
|
||||||
|
library requires users to register all enum classes for which bitmask support
|
||||||
|
should be enabled:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
template<>
|
||||||
|
struct entt::enum_as_bitmask<my_flag>
|
||||||
|
: std::true_type
|
||||||
|
{};
|
||||||
|
```
|
||||||
|
|
||||||
|
This is handy when dealing with enum classes defined by third party libraries
|
||||||
|
and over which the users have no control. However, it's also verbose and can be
|
||||||
|
avoided by adding a specific value to the enum class itself:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
enum class my_flag {
|
||||||
|
unknown = 0x01,
|
||||||
|
enabled = 0x02,
|
||||||
|
disabled = 0x04,
|
||||||
|
_entt_enum_as_bitmask
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case, there is no need to specialize the `enum_as_bitmask` traits, since
|
||||||
|
`EnTT` will automatically detect the flag and enable the bitmask support.<br/>
|
||||||
|
Once the enum class has been registered (in one way or the other) all the most
|
||||||
|
common operators will be available, such as `&`, `|` but also `&=` and `|=`.
|
||||||
|
Refer to the official documentation for the full list of operators.
|
||||||
|
|
||||||
# Hashed strings
|
# Hashed strings
|
||||||
|
|
||||||
@@ -195,6 +370,54 @@ and over which users have not the control. Choosing a slightly different
|
|||||||
identifier is probably the best solution to make the conflict disappear in this
|
identifier is probably the best solution to make the conflict disappear in this
|
||||||
case.
|
case.
|
||||||
|
|
||||||
|
# Memory
|
||||||
|
|
||||||
|
There are a handful of tools within EnTT to interact with memory in one way or
|
||||||
|
another.<br/>
|
||||||
|
Some are geared towards simplifying the implementation of (internal or external)
|
||||||
|
allocator aware containers. Others, on the other hand, are designed to help the
|
||||||
|
developer with everyday problems.
|
||||||
|
|
||||||
|
The former are very specific and for niche problems. These are tools designed to
|
||||||
|
unwrap fancy or plain pointers (`to_address`) or to help forget the meaning of
|
||||||
|
acronyms like _POCCA_, _POCMA_ or _POCS_.<br/>
|
||||||
|
I won't describe them here in detail. Instead, I recommend reading the inline
|
||||||
|
documentation to those interested in the subject.
|
||||||
|
|
||||||
|
## Power of two and fast modulus
|
||||||
|
|
||||||
|
Finding out if a number is a power of two (`is_power_of_two`) or what the next
|
||||||
|
power of two is given a random value (`next_power_of_two`) is very useful at
|
||||||
|
times.<br/>
|
||||||
|
For example, it helps to allocate memory in pages having a size suitable for the
|
||||||
|
fast modulus:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
const std::size_t result = entt::fast_mod(value, modulus);
|
||||||
|
```
|
||||||
|
|
||||||
|
Where `modulus` is necessarily a power of two. Perhaps not everyone knows that
|
||||||
|
this type of operation is far superior in terms of performance to the basic
|
||||||
|
modulus and for this reason preferred in many areas.
|
||||||
|
|
||||||
|
## Allocator aware unique pointers
|
||||||
|
|
||||||
|
A nasty thing in C++ (at least up to C++20) is the fact that shared pointers
|
||||||
|
support allocators while unique pointers don't.<br/>
|
||||||
|
There is a proposal at the moment that also shows among the other things how
|
||||||
|
this can be implemented without any compiler support.
|
||||||
|
|
||||||
|
The `allocate_unique` function follows this proposal, making a virtue out of
|
||||||
|
necessity:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::unique_ptr<my_type, entt::allocation_deleter<my_type>> ptr = entt::allocate_unique<my_type>(allocator, arguments);
|
||||||
|
```
|
||||||
|
|
||||||
|
Although the internal implementation is slightly different from what is proposed
|
||||||
|
for the standard, this function offers an API that is a drop-in replacement for
|
||||||
|
the same feature.
|
||||||
|
|
||||||
# Monostate
|
# Monostate
|
||||||
|
|
||||||
The monostate pattern is often presented as an alternative to a singleton based
|
The monostate pattern is often presented as an alternative to a singleton based
|
||||||
@@ -218,182 +441,28 @@ const bool b = entt::monostate<"mykey"_hs>{};
|
|||||||
const int i = entt::monostate<entt::hashed_string{"mykey"}>{};
|
const int i = entt::monostate<entt::hashed_string{"mykey"}>{};
|
||||||
```
|
```
|
||||||
|
|
||||||
# Any as in any type
|
|
||||||
|
|
||||||
`EnTT` comes with its own `any` type. It may seem redundant considering that
|
|
||||||
C++17 introduced `std::any`, but it is not (hopefully).<br/>
|
|
||||||
In fact, the _type_ returned by an `std::any` is a const reference to an
|
|
||||||
`std::type_info`, an implementation defined class that's not something everyone
|
|
||||||
wants to see in a software. Furthermore, there is no way to connect it with the
|
|
||||||
type system of the library and therefore with its integrated RTTI support.<br/>
|
|
||||||
Note that this class is largely used internally by the library itself.
|
|
||||||
|
|
||||||
The API is very similar to that of its most famous counterpart, mainly because
|
|
||||||
this class serves the same purpose of being an opaque container for any type of
|
|
||||||
value.<br/>
|
|
||||||
Instances of `any` also minimize the number of allocations by relying on a well
|
|
||||||
known technique called _small buffer optimization_ and a fake vtable.
|
|
||||||
|
|
||||||
Creating an object of the `any` type, whether empty or not, is trivial:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
// an empty container
|
|
||||||
entt::any empty{};
|
|
||||||
|
|
||||||
// a container for an int
|
|
||||||
entt::any any{0};
|
|
||||||
|
|
||||||
// in place construction
|
|
||||||
entt::any in_place{std::in_place_type<int>, 42};
|
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively, the `make_any` function serves the same purpose but requires to
|
|
||||||
always be explicit about the type:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
entt::any any = entt::make_any<int>(42);
|
|
||||||
```
|
|
||||||
|
|
||||||
In both cases, the `any` class takes the burden of destroying the contained
|
|
||||||
element when required, regardless of the storage strategy used for the specific
|
|
||||||
object.<br/>
|
|
||||||
Furthermore, an instance of `any` is not tied to an actual type. Therefore, the
|
|
||||||
wrapper will be reconfigured by assigning it an object of a different type than
|
|
||||||
the one contained, so as to be able to handle the new instance.<br/>
|
|
||||||
When in doubt about the type of object contained, the `type` member function of
|
|
||||||
`any` returns an instance of `type_info` associated with its element, or an
|
|
||||||
invalid `type_info` object if the container is empty. The type is also used
|
|
||||||
internally when comparing two `any` objects:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
if(any == empty) { /* ... */ }
|
|
||||||
```
|
|
||||||
|
|
||||||
In this case, before proceeding with a comparison, it's verified that the _type_
|
|
||||||
of the two objects is actually the same.<br/>
|
|
||||||
Refer to the `EnTT` type system documentation for more details on how
|
|
||||||
`type_info` works and on possible risks of a comparison.
|
|
||||||
|
|
||||||
A particularly interesting feature of this class is that it can also be used as
|
|
||||||
an opaque container for const and non-const references:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
int value = 42;
|
|
||||||
|
|
||||||
entt::any any{std::in_place_type<int &>(value)};
|
|
||||||
entt::any cany = entt::make_any<const int &>(value);
|
|
||||||
entt::any fwd = entt::forward_as_any(value);
|
|
||||||
|
|
||||||
any.emplace<const int &>(value);
|
|
||||||
```
|
|
||||||
|
|
||||||
In other words, whenever `any` is explicitly told to construct an _alias_, it
|
|
||||||
acts as a pointer to the original instance rather than making a copy of it or
|
|
||||||
moving it internally. The contained object is never destroyed and users must
|
|
||||||
ensure that its lifetime exceeds that of the container.<br/>
|
|
||||||
Similarly, it's possible to create non-owning copies of `any` from an existing
|
|
||||||
object:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
// aliasing constructor
|
|
||||||
entt::any ref = other.as_ref();
|
|
||||||
```
|
|
||||||
|
|
||||||
In this case, it doesn't matter if the original container actually holds an
|
|
||||||
object or acts already as a reference for unmanaged elements, the new instance
|
|
||||||
thus created won't create copies and will only serve as a reference for the
|
|
||||||
original item.<br/>
|
|
||||||
This means that, starting from the example above, both `ref` and` other` will
|
|
||||||
point to the same object, whether it's initially contained in `other` or already
|
|
||||||
an unmanaged element.
|
|
||||||
|
|
||||||
As a side note, it's worth mentioning that, while everything works transparently
|
|
||||||
when it comes to non-const references, there are some exceptions when it comes
|
|
||||||
to const references.<br/>
|
|
||||||
In particular, the `data` member function invoked on a non-const instance of
|
|
||||||
`any` that wraps a const reference will return a null pointer in all cases.
|
|
||||||
|
|
||||||
To cast an instance of `any` to a type, the library offers a set of `any_cast`
|
|
||||||
functions in all respects similar to their most famous counterparts.<br/>
|
|
||||||
The only difference is that, in the case of `EnTT`, these won't raise exceptions
|
|
||||||
but will only trigger an assert in debug mode, otherwise resulting in undefined
|
|
||||||
behavior in case of misuse in release mode.
|
|
||||||
|
|
||||||
## Small buffer optimization
|
|
||||||
|
|
||||||
The `any` class uses a technique called _small buffer optimization_ to reduce
|
|
||||||
the number of allocations where possible.<br/>
|
|
||||||
The default reserved size for an instance of `any` is `sizeof(double[2])`.
|
|
||||||
However, this is also configurable if needed. In fact, `any` is defined as an
|
|
||||||
alias for `basic_any<Len>`, where `Len` is the size above.<br/>
|
|
||||||
Users can easily set a custom size or define their own aliases:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using my_any = entt::basic_any<sizeof(double[4])>;
|
|
||||||
```
|
|
||||||
|
|
||||||
This feature, in addition to allowing the choice of a size that best suits the
|
|
||||||
needs of an application, also offers the possibility of forcing dynamic creation
|
|
||||||
of objects during construction.<br/>
|
|
||||||
In other terms, if the size is 0, `any` avoids the use of any optimization and
|
|
||||||
always dynamically allocates objects (except for aliasing cases).
|
|
||||||
|
|
||||||
Note that the size of the internal storage as well as the alignment requirements
|
|
||||||
are directly part of the type and therefore contribute to define different types
|
|
||||||
that won't be able to interoperate with each other.
|
|
||||||
|
|
||||||
## Alignment requirement
|
|
||||||
|
|
||||||
The alignment requirement is optional and by default the most stringent (the
|
|
||||||
largest) for any object whose size is at most equal to the one provided.<br/>
|
|
||||||
The `basic_any` class template inspects the alignment requirements in each case,
|
|
||||||
even when not provided and may decide not to use the small buffer optimization
|
|
||||||
in order to meet them.
|
|
||||||
|
|
||||||
The alignment requirement is provided as an optional second parameter following
|
|
||||||
the desired size for the internal storage:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using my_any = entt::basic_any<sizeof(double[4]), alignof(double[4])>;
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that the alignment requirements as well as the size of the internal storage
|
|
||||||
are directly part of the type and therefore contribute to define different types
|
|
||||||
that won't be able to interoperate with each other.
|
|
||||||
|
|
||||||
# Type support
|
# Type support
|
||||||
|
|
||||||
`EnTT` provides some basic information about types of all kinds.<br/>
|
`EnTT` provides some basic information about types of all kinds.<br/>
|
||||||
It also offers additional features that are not yet available in the standard
|
It also offers additional features that are not yet available in the standard
|
||||||
library or that will never be.
|
library or that will never be.
|
||||||
|
|
||||||
## Type info
|
## Built-in RTTI support
|
||||||
|
|
||||||
The `type_info` class isn't a drop-in replacement for `std::type_info` but can
|
Runtime type identification support (or RTTI) is one of the most frequently
|
||||||
provide similar information which are not implementation defined and don't
|
disabled features in the C++ world, especially in the gaming sector. Regardless
|
||||||
require to enable RTTI.<br/>
|
of the reasons for this, it's often a shame not to be able to rely on opaque
|
||||||
Therefore, they can sometimes be even more reliable than those obtained
|
type information at runtime.<br/>
|
||||||
otherwise.
|
The library tries to fill this gap by offering a built-in system that doesn't
|
||||||
|
serve as a replacement but comes very close to being one and offers similar
|
||||||
|
information to that provided by its counterpart.
|
||||||
|
|
||||||
A type info object is an opaque class that is also copy and move constructible.
|
Basically, the whole system relies on a handful of classes. In particular:
|
||||||
This class is returned by the `type_id` function template:
|
|
||||||
|
|
||||||
```cpp
|
* The unique sequential identifier associated with a given type:
|
||||||
auto info = entt::type_id<a_type>();
|
|
||||||
```
|
|
||||||
|
|
||||||
These are the information made available by this object:
|
|
||||||
|
|
||||||
* The unique, sequential identifier associated with a given type:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto index = entt::type_id<a_type>().seq();
|
auto index = entt::type_index<a_type>::value();
|
||||||
```
|
|
||||||
|
|
||||||
This is also an alias for the following:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto index = entt::type_seq<a_type>::value();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The returned value isn't guaranteed to be stable across different runs.
|
The returned value isn't guaranteed to be stable across different runs.
|
||||||
@@ -407,13 +476,13 @@ These are the information made available by this object:
|
|||||||
and therefore the generation of custom runtime sequences of indices for their
|
and therefore the generation of custom runtime sequences of indices for their
|
||||||
own purposes, if necessary.
|
own purposes, if necessary.
|
||||||
|
|
||||||
An external generator can also be used if needed. In fact, `type_seq` can be
|
An external generator can also be used if needed. In fact, `type_index` can be
|
||||||
specialized by type and is also _sfinae-friendly_ in order to allow more
|
specialized by type and is also _sfinae-friendly_ in order to allow more
|
||||||
refined specializations such as:
|
refined specializations such as:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct entt::type_seq<Type, std::void_d<decltype(Type::index())>> {
|
struct entt::type_index<Type, std::void_d<decltype(Type::index())>> {
|
||||||
static entt::id_type value() ENTT_NOEXCEPT {
|
static entt::id_type value() ENTT_NOEXCEPT {
|
||||||
return Type::index();
|
return Type::index();
|
||||||
}
|
}
|
||||||
@@ -426,21 +495,13 @@ These are the information made available by this object:
|
|||||||
|
|
||||||
* The hash value associated with a given type:
|
* The hash value associated with a given type:
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto hash = entt::type_id<a_type>().hash();
|
|
||||||
```
|
|
||||||
|
|
||||||
This is also an alias for the following:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto hash = entt::type_hash<a_type>::value();
|
auto hash = entt::type_hash<a_type>::value();
|
||||||
```
|
```
|
||||||
|
|
||||||
In general, the `value` function exposed by `type_hash` is also `constexpr`
|
In general, the `value` function exposed by `type_hash` is also `constexpr`
|
||||||
but this isn't guaranteed for all compilers and platforms (although it's valid
|
but this isn't guaranteed for all compilers and platforms (although it's valid
|
||||||
with the most well-known and popular ones).<br/>
|
with the most well-known and popular ones).
|
||||||
The `hash` function offered by the type info object isn't `constexpr` in any
|
|
||||||
case instead.
|
|
||||||
|
|
||||||
This function **can** use non-standard features of the language for its own
|
This function **can** use non-standard features of the language for its own
|
||||||
purposes. This makes it possible to provide compile-time identifiers that
|
purposes. This makes it possible to provide compile-time identifiers that
|
||||||
@@ -450,18 +511,12 @@ These are the information made available by this object:
|
|||||||
that identifiers remain stable across executions. Moreover, they are generated
|
that identifiers remain stable across executions. Moreover, they are generated
|
||||||
at runtime and are no longer a compile-time thing.
|
at runtime and are no longer a compile-time thing.
|
||||||
|
|
||||||
As for `type_seq`, also `type_hash` is a _sfinae-friendly_ class that can be
|
As for `type_index`, also `type_hash` is a _sfinae-friendly_ class that can be
|
||||||
specialized in order to customize its behavior globally or on a per-type or
|
specialized in order to customize its behavior globally or on a per-type or
|
||||||
per-traits basis.
|
per-traits basis.
|
||||||
|
|
||||||
* The name associated with a given type:
|
* The name associated with a given type:
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto name = entt::type_id<my_type>().name();
|
|
||||||
```
|
|
||||||
|
|
||||||
This is also an alias for the following:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto name = entt::type_name<a_type>::value();
|
auto name = entt::type_name<a_type>::value();
|
||||||
```
|
```
|
||||||
@@ -489,10 +544,84 @@ These are the information made available by this object:
|
|||||||
means of the `ENTT_STANDARD_CPP` definition. In this case, the name will be
|
means of the `ENTT_STANDARD_CPP` definition. In this case, the name will be
|
||||||
empty by default.
|
empty by default.
|
||||||
|
|
||||||
As for `type_seq`, also `type_name` is a _sfinae-friendly_ class that can be
|
As for `type_index`, also `type_name` is a _sfinae-friendly_ class that can be
|
||||||
specialized in order to customize its behavior globally or on a per-type or
|
specialized in order to customize its behavior globally or on a per-type or
|
||||||
per-traits basis.
|
per-traits basis.
|
||||||
|
|
||||||
|
These are then combined into utilities that aim to offer an API that is somewhat
|
||||||
|
similar to that offered by the language.
|
||||||
|
|
||||||
|
### Type info
|
||||||
|
|
||||||
|
The `type_info` class isn't a drop-in replacement for `std::type_info` but can
|
||||||
|
provide similar information which are not implementation defined and don't
|
||||||
|
require to enable RTTI.<br/>
|
||||||
|
Therefore, they can sometimes be even more reliable than those obtained
|
||||||
|
otherwise.
|
||||||
|
|
||||||
|
Its type defines an opaque class that is also copyable and movable.<br/>
|
||||||
|
Objects of this type are generally returned by the `type_id` functions:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// by type
|
||||||
|
auto info = entt::type_id<a_type>();
|
||||||
|
|
||||||
|
// by value
|
||||||
|
auto other = entt::type_id(42);
|
||||||
|
```
|
||||||
|
|
||||||
|
All elements thus received are nothing more than const references to instances
|
||||||
|
of `type_info` with static storage duration.<br/>
|
||||||
|
This is convenient for saving the entire object aside for the cost of a pointer.
|
||||||
|
However, nothing prevents from constructing `type_info` objects directly:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::type_info info{std::in_place_type<int>};
|
||||||
|
```
|
||||||
|
|
||||||
|
These are the information made available by `type_info`:
|
||||||
|
|
||||||
|
* The index associated with a given type:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto idx = entt::type_id<a_type>().index();
|
||||||
|
```
|
||||||
|
|
||||||
|
This is also an alias for the following:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto idx = entt::type_index<std::remove_cv_t<std::remove_reference_t<a_type>>>::value();
|
||||||
|
```
|
||||||
|
|
||||||
|
* The hash value associated with a given type:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto hash = entt::type_id<a_type>().hash();
|
||||||
|
```
|
||||||
|
|
||||||
|
This is also an alias for the following:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto hash = entt::type_hash<std::remove_cv_t<std::remove_reference_t<a_type>>>::value();
|
||||||
|
```
|
||||||
|
|
||||||
|
* The name associated with a given type:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto name = entt::type_id<my_type>().name();
|
||||||
|
```
|
||||||
|
|
||||||
|
This is also an alias for the following:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto name = entt::type_name<std::remove_cv_t<std::remove_reference_t<a_type>>>::value();
|
||||||
|
```
|
||||||
|
|
||||||
|
Where all accessed features are available at compile-time, the `type_info` class
|
||||||
|
is also fully `constexpr`. However, this cannot be guaranteed in advance and
|
||||||
|
depends mainly on the compiler in use and any specializations of the classes
|
||||||
|
described above.
|
||||||
|
|
||||||
### Almost unique identifiers
|
### Almost unique identifiers
|
||||||
|
|
||||||
Since the default non-standard, compile-time implementation of `type_hash` makes
|
Since the default non-standard, compile-time implementation of `type_hash` makes
|
||||||
@@ -633,7 +762,7 @@ Here is a (possibly incomplete) list of the functionalities that come with a
|
|||||||
type list:
|
type list:
|
||||||
|
|
||||||
* `type_list_element[_t]` to get the N-th element of a type list.
|
* `type_list_element[_t]` to get the N-th element of a type list.
|
||||||
* `type_list_cast[_t]` and a handy `operator+` to concatenate type lists.
|
* `type_list_cat[_t]` and a handy `operator+` to concatenate type lists.
|
||||||
* `type_list_unique[_t]` to remove duplicate types from a type list.
|
* `type_list_unique[_t]` to remove duplicate types from a type list.
|
||||||
* `type_list_contains[_v]` to know if a type list contains a given type.
|
* `type_list_contains[_v]` to know if a type list contains a given type.
|
||||||
* `type_list_diff[_t]` to remove types from type lists.
|
* `type_list_diff[_t]` to remove types from type lists.
|
||||||
@@ -644,6 +773,81 @@ Many of these functionalities also exist in their version dedicated to value
|
|||||||
lists. We therefore have `value_list_element[_v]` as well as
|
lists. We therefore have `value_list_element[_v]` as well as
|
||||||
`value_list_cat[_t]`and so on.
|
`value_list_cat[_t]`and so on.
|
||||||
|
|
||||||
|
# Unique sequential identifiers
|
||||||
|
|
||||||
|
Sometimes it's useful to be able to give unique, sequential numeric identifiers
|
||||||
|
to types either at compile-time or runtime.<br/>
|
||||||
|
There are plenty of different solutions for this out there and I could have used
|
||||||
|
one of them. However, I decided to spend my time to define a couple of tools
|
||||||
|
that fully embraces what the modern C++ has to offer.
|
||||||
|
|
||||||
|
## Compile-time generator
|
||||||
|
|
||||||
|
To generate sequential numeric identifiers at compile-time, `EnTT` offers the
|
||||||
|
`identifier` class template:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// defines the identifiers for the given types
|
||||||
|
using id = entt::identifier<a_type, another_type>;
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
switch(a_type_identifier) {
|
||||||
|
case id::type<a_type>:
|
||||||
|
// ...
|
||||||
|
break;
|
||||||
|
case id::type<another_type>:
|
||||||
|
// ...
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is all what this class template has to offer: a `type` inline variable that
|
||||||
|
contains a numeric identifier for the given type. It can be used in any context
|
||||||
|
where constant expressions are required.
|
||||||
|
|
||||||
|
As long as the list remains unchanged, identifiers are also guaranteed to be
|
||||||
|
stable across different runs. In case they have been used in a production
|
||||||
|
environment and a type has to be removed, one can just use a placeholder to left
|
||||||
|
the other identifiers unchanged:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
template<typename> struct ignore_type {};
|
||||||
|
|
||||||
|
using id = entt::identifier<
|
||||||
|
a_type_still_valid,
|
||||||
|
ignore_type<a_type_no_longer_valid>,
|
||||||
|
another_type_still_valid
|
||||||
|
>;
|
||||||
|
```
|
||||||
|
|
||||||
|
Perhaps a bit ugly to see in a codebase but it gets the job done at least.
|
||||||
|
|
||||||
|
## Runtime generator
|
||||||
|
|
||||||
|
To generate sequential numeric identifiers at runtime, `EnTT` offers the
|
||||||
|
`family` class template:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// defines a custom generator
|
||||||
|
using id = entt::family<struct my_tag>;
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
const auto a_type_id = id::type<a_type>;
|
||||||
|
const auto another_type_id = id::type<another_type>;
|
||||||
|
```
|
||||||
|
|
||||||
|
This is all what a _family_ has to offer: a `type` inline variable that contains
|
||||||
|
a numeric identifier for the given type.<br/>
|
||||||
|
The generator is customizable, so as to get different _sequences_ for different
|
||||||
|
purposes if needed.
|
||||||
|
|
||||||
|
Please, note that identifiers aren't guaranteed to be stable across different
|
||||||
|
runs. Indeed it mostly depends on the flow of execution.
|
||||||
|
|
||||||
# Utilities
|
# Utilities
|
||||||
|
|
||||||
It's not possible to escape the temptation to add utilities of some kind to a
|
It's not possible to escape the temptation to add utilities of some kind to a
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -149,15 +149,14 @@ more details.
|
|||||||
## The standard and the non-copyable types
|
## The standard and the non-copyable types
|
||||||
|
|
||||||
`EnTT` uses internally the trait `std::is_copy_constructible_v` to check if a
|
`EnTT` uses internally the trait `std::is_copy_constructible_v` to check if a
|
||||||
component is actually copyable. This trait doesn't check if an object can
|
component is actually copyable. However, this trait doesn't really check whether
|
||||||
actually be copied but only verifies if there is a copy constructor
|
a type is actually copyable. Instead, it just checks that a suitable copy
|
||||||
available.<br/>
|
constructor and copy operator exist.<br/>
|
||||||
This can lead to surprising results due to some idiosyncrasies of the standard
|
This can lead to surprising results due to some idiosyncrasies of the standard.
|
||||||
mainly related to the need to guarantee backward compatibility.
|
|
||||||
|
|
||||||
For example, `std::vector` defines a copy constructor no matter if its value
|
For example, `std::vector` defines a copy constructor that is conditionally
|
||||||
type is copyable or not. As a result, `std::is_copy_constructible_v` is true
|
enabled depending on whether the value type is copyable or not. As a result,
|
||||||
for the following specialization:
|
`std::is_copy_constructible_v` returns true for the following specialization:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
struct type {
|
struct type {
|
||||||
@@ -165,21 +164,30 @@ struct type {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
When trying to assign an instance of this type to an entity in the ECS part,
|
However, the copy constructor is effectively disabled upon specialization.
|
||||||
this may trigger a compilation error because we cannot really make a copy of
|
Therefore, trying to assign an instance of this type to an entity may trigger a
|
||||||
it.<br/>
|
compilation error.<br/>
|
||||||
As a workaround, users can mark the type explicitly as non-copyable:
|
As a workaround, users can mark the type explicitly as non-copyable. This also
|
||||||
|
suppresses the implicit generation of the move constructor and operator, which
|
||||||
|
will therefore have to be defaulted accordingly:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
struct type {
|
struct type {
|
||||||
type(const type &) = delete;
|
type(const type &) = delete;
|
||||||
|
type(type &&) = default;
|
||||||
|
|
||||||
type & operator=(const type &) = delete;
|
type & operator=(const type &) = delete;
|
||||||
|
type & operator=(type &&) = default;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<action>> vec;
|
std::vector<std::unique_ptr<action>> vec;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
Unfortunately, this will also disable aggregate initialization.
|
Note that aggregate initialization is also disabled as a consequence.<br/>
|
||||||
|
Fortunately, this type of trick is quite rare. The bad news is that there is no
|
||||||
|
way to deal with it at the library level, this being due to the design of the
|
||||||
|
language. On the other hand, the fact that the language itself also offers a way
|
||||||
|
to mitigate the problem makes it manageable.
|
||||||
|
|
||||||
## Which functions trigger which signals
|
## Which functions trigger which signals
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
# Table of Contents
|
# Table of Contents
|
||||||
|
|
||||||
* [Working across boundaries](#working-across-boundaries)
|
* [Working across boundaries](#working-across-boundaries)
|
||||||
* [The EnTT way](#the-entt-way)
|
* [Smooth until proven otherwise](#smooth-until-proven-otherwise)
|
||||||
* [Meta context](#meta-context)
|
* [Meta context](#meta-context)
|
||||||
* [Memory management](#memory-management)
|
* [Memory management](#memory-management)
|
||||||
<!--
|
<!--
|
||||||
@@ -19,48 +19,31 @@
|
|||||||
general and on GNU/Linux when default visibility was set to hidden. The
|
general and on GNU/Linux when default visibility was set to hidden. The
|
||||||
limitation was mainly due to a custom utility used to assign unique, sequential
|
limitation was mainly due to a custom utility used to assign unique, sequential
|
||||||
identifiers with different types.<br/>
|
identifiers with different types.<br/>
|
||||||
Fortunately, nowadays using `EnTT` across boundaries is easier. However, use in
|
Fortunately, nowadays using `EnTT` across boundaries is much easier.
|
||||||
standalone applications is favored and user intervention is otherwise required.
|
|
||||||
|
|
||||||
## The EnTT way
|
## Smooth until proven otherwise
|
||||||
|
|
||||||
Many classes in `EnTT` make extensive use of type erasure for their purposes.
|
Many classes in `EnTT` make extensive use of type erasure for their purposes.
|
||||||
This isn't a problem in itself (in fact, it's the basis of an API so convenient
|
This isn't a problem on itself (in fact, it's the basis of an API so convenient
|
||||||
to use). However, a way is needed to recognize the objects whose type has been
|
to use). However, a way is needed to recognize the objects whose type has been
|
||||||
erased on the other side of a boundary.<br/>
|
erased on the other side of a boundary.<br/>
|
||||||
The `type_hash` class template is how identifiers are generated and thus made
|
The `type_hash` class template is how identifiers are generated and thus made
|
||||||
available to the rest of the library. The `type_seq` class template makes all
|
available to the rest of the library. In general, this class doesn't arouse much
|
||||||
types _indexable_ instead, so as to speed up the lookup.
|
interest. The only exception is when a conflict between identifiers occurs
|
||||||
|
(definitely uncommon though) or when the default solution proposed by `EnTT`
|
||||||
|
isn't suitable for the user's purposes.<br/>
|
||||||
|
The section dedicated to `type_info` contains all the details to get around the
|
||||||
|
issue in a concise and elegant way. Please refer to the specific documentation.
|
||||||
|
|
||||||
In general, these classes don't arouse much interest. The only exceptions are:
|
When working with linked libraries, compile definitions `ENTT_API_EXPORT` and
|
||||||
|
`ENTT_API_IMPORT` can be used where there is a need to import or export symbols,
|
||||||
* When a conflict between identifiers occurs (definitely uncommon though) or
|
so as to make everything work nicely across boundaries.<br/>
|
||||||
when the default solution proposed by `EnTT` isn't suitable for the user's
|
On the other hand, everything should run smoothly when working with plugins or
|
||||||
purposes.<br/>
|
shared libraries that don't export any symbols.
|
||||||
The section dedicated to `type_info` contains all the details to get around
|
|
||||||
the problem in a concise and elegant way. Please refer to the specific
|
|
||||||
documentation.
|
|
||||||
|
|
||||||
* When working with linked libraries that also export all required symbols.<br/>
|
|
||||||
Compile definitions `ENTT_API_EXPORT` and `ENTT_API_IMPORT` should be passed
|
|
||||||
respectively where there is a need to import or export the symbols defined by
|
|
||||||
`EnTT`, so as to make everything work nicely across boundaries.
|
|
||||||
|
|
||||||
* When working with plugins or shared libraries that don't export any symbol. In
|
|
||||||
this case, `type_seq` confuses the other classes by giving potentially wrong
|
|
||||||
information to them.<br/>
|
|
||||||
To avoid problems, it's required to provide a custom generator. Briefly, it's
|
|
||||||
necessary to specialize the `type_seq` class and make it point to a context
|
|
||||||
that is also shared between the main application and the dynamically loaded
|
|
||||||
libraries or plugins.<br/>
|
|
||||||
This will make the type system available to the whole application, not just to
|
|
||||||
a particular tool such as the registry or the dispatcher. It means that a call
|
|
||||||
to `type_seq::value()` will return the same identifier for the same type from
|
|
||||||
both sides of a boundary and can be used reliably for any purpose.
|
|
||||||
|
|
||||||
For anyone who needs more details, the test suite contains multiple examples
|
For anyone who needs more details, the test suite contains multiple examples
|
||||||
covering the most common cases (see the `lib` directory for all details).<br/>
|
covering the most common cases (see the `lib` directory for all details).<br/>
|
||||||
It goes without saying that it's impossible to cover all the possible cases.
|
It goes without saying that it's impossible to cover **all** possible cases.
|
||||||
However, what is offered should hopefully serve as a basis for all of them.
|
However, what is offered should hopefully serve as a basis for all of them.
|
||||||
|
|
||||||
## Meta context
|
## Meta context
|
||||||
|
|||||||
@@ -20,14 +20,24 @@ I hope this list can grow much more in the future:
|
|||||||
* [Minecraft Earth](https://www.minecraft.net/en-us/about-earth) by
|
* [Minecraft Earth](https://www.minecraft.net/en-us/about-earth) by
|
||||||
[Mojang](https://mojang.com/): an augmented reality game for mobile, that
|
[Mojang](https://mojang.com/): an augmented reality game for mobile, that
|
||||||
lets users bring Minecraft into the real world.
|
lets users bring Minecraft into the real world.
|
||||||
|
* [Ember Sword](https://embersword.com/): a modern Free-to-Play MMORPG with a
|
||||||
|
player-driven economy, a classless combat system, and scarce, tradable
|
||||||
|
cosmetic collectibles.
|
||||||
|
* Apparently [Diablo II: Resurrected](https://diablo2.blizzard.com/) by
|
||||||
|
[Blizzard](https://www.blizzard.com/): monsters, heroes, items, spells, all
|
||||||
|
resurrected. Thanks unknown insider.
|
||||||
|
* [Apparently](https://www.youtube.com/watch?v=P8xvOA3ikrQ&t=1105s)
|
||||||
|
[Call of Duty: Vanguard](https://www.callofduty.com/vanguard) by
|
||||||
|
[Sledgehammer Games](https://www.sledgehammergames.com/): I can neither
|
||||||
|
confirm nor deny but there is a license I know in the credits.
|
||||||
|
* Apparently [D&D Dark Alliance](https://darkalliance.wizards.com) by
|
||||||
|
[Wizards of the Coast](https://company.wizards.com): your party, their
|
||||||
|
funeral.
|
||||||
* [TiltedOnline](https://github.com/tiltedphoques/TiltedOnline) by
|
* [TiltedOnline](https://github.com/tiltedphoques/TiltedOnline) by
|
||||||
[Tilted Phoques](https://github.com/tiltedphoques): Skyrim and Fallout 4 mod
|
[Tilted Phoques](https://github.com/tiltedphoques): Skyrim and Fallout 4 mod
|
||||||
to play online.
|
to play online.
|
||||||
* [Antkeeper](https://github.com/antkeeper/antkeeper-source): an ant colony
|
* [Antkeeper](https://github.com/antkeeper/antkeeper-source): an ant colony
|
||||||
simulation [game](https://antkeeper.com/).
|
simulation [game](https://antkeeper.com/).
|
||||||
* [War of Rights](https://store.steampowered.com/app/424030/War_of_Rights/): a
|
|
||||||
multiplayer game set during the perilous days of the American Civil War, by
|
|
||||||
Campfire Games.
|
|
||||||
* [Openblack](https://github.com/openblack/openblack): open source
|
* [Openblack](https://github.com/openblack/openblack): open source
|
||||||
reimplementation of the game _Black & White_ (2001).
|
reimplementation of the game _Black & White_ (2001).
|
||||||
* [Land of the Rair](https://github.com/LandOfTheRair/core2): the new backend
|
* [Land of the Rair](https://github.com/LandOfTheRair/core2): the new backend
|
||||||
@@ -70,8 +80,20 @@ I hope this list can grow much more in the future:
|
|||||||
arcade game about shooting dirty rocks in space, inspired by Asteroids.
|
arcade game about shooting dirty rocks in space, inspired by Asteroids.
|
||||||
* [Wanderer](https://github.com/albin-johansson/wanderer): a 2D exploration
|
* [Wanderer](https://github.com/albin-johansson/wanderer): a 2D exploration
|
||||||
based indie game.
|
based indie game.
|
||||||
* [Spelunky® Classic remake](https://github.com/dbeef/spelunky-psp): A truly
|
* [Spelunky® Classic remake](https://github.com/dbeef/spelunky-psp): a truly
|
||||||
multiplatform experience with a rewrite from scratch.
|
multiplatform experience with a rewrite from scratch.
|
||||||
|
* [CubbyTower](https://github.com/utilForever/CubbyTower): a simple tower
|
||||||
|
defense game using C++ with Entity Component System (ECS).
|
||||||
|
* [Runeterra](https://github.com/utilForever/Runeterra): Legends of Runeterra
|
||||||
|
simulator using C++ with some reinforcement learning.
|
||||||
|
* [Black Sun](https://store.steampowered.com/app/1670930/Black_Sun/): fly your
|
||||||
|
space ship through a large 2D open world.
|
||||||
|
* [PokeMaster](https://github.com/utilForever/PokeMaster): Pokemon Battle
|
||||||
|
simulator using C++ with some reinforcement learning.
|
||||||
|
* [HomeHearth](https://youtu.be/GrEWl8npL9Y): choose your hero, protect the
|
||||||
|
town, before it's too late.
|
||||||
|
* [City Builder Game](https://github.com/PhiGei2000/CityBuilderGame): a simple
|
||||||
|
city-building game using C++ and OpenGL.
|
||||||
|
|
||||||
* Engines and the like:
|
* Engines and the like:
|
||||||
* [Aether Engine](https://hadean.com/spatial-simulation/)
|
* [Aether Engine](https://hadean.com/spatial-simulation/)
|
||||||
@@ -92,6 +114,9 @@ I hope this list can grow much more in the future:
|
|||||||
vrooooommm.
|
vrooooommm.
|
||||||
* [Antara Gaming SDK](https://github.com/KomodoPlatform/antara-gaming-sdk):
|
* [Antara Gaming SDK](https://github.com/KomodoPlatform/antara-gaming-sdk):
|
||||||
the Komodo Gaming Software Development Kit.
|
the Komodo Gaming Software Development Kit.
|
||||||
|
* [XVP](https://ravingbots.com/xvp-expansive-vehicle-physics-for-unreal-engine/):
|
||||||
|
[_eXpansive Vehicle Physics_](https://github.com/raving-bots/xvp/wiki/Plugin-integration-guide)
|
||||||
|
plugin for Unreal Engine.
|
||||||
* [Apparently](https://teamwisp.github.io/credits/)
|
* [Apparently](https://teamwisp.github.io/credits/)
|
||||||
[Wisp](https://teamwisp.github.io/product/) by
|
[Wisp](https://teamwisp.github.io/product/) by
|
||||||
[Team Wisp](https://teamwisp.github.io/): an advanced real-time ray tracing
|
[Team Wisp](https://teamwisp.github.io/): an advanced real-time ray tracing
|
||||||
@@ -116,6 +141,21 @@ I hope this list can grow much more in the future:
|
|||||||
framework in C++17 for backend development.
|
framework in C++17 for backend development.
|
||||||
* [Unity/EnTT](https://github.com/TongTungGiang/unity-entt): tech demo of a
|
* [Unity/EnTT](https://github.com/TongTungGiang/unity-entt): tech demo of a
|
||||||
native simulation layer using `EnTT` and `Unity` as a rendering engine.
|
native simulation layer using `EnTT` and `Unity` as a rendering engine.
|
||||||
|
* [OverEngine](https://github.com/OverShifted/OverEngine): an over-engineered
|
||||||
|
game engine.
|
||||||
|
* [Electro](https://github.com/Electro-Technologies/Electro): high performance
|
||||||
|
3D game engine with a high emphasis on rendering.
|
||||||
|
* [Kawaii](https://github.com/Mathieu-Lala/Kawaii_Engine): a modern data
|
||||||
|
oriented game engine.
|
||||||
|
* [Becketron](https://github.com/Doctor-Foxling/Becketron): a game engine
|
||||||
|
written mostly in C++.
|
||||||
|
* [Spatial Engine](https://github.com/luizgabriel/Spatial.Engine): a
|
||||||
|
cross-platform engine created on top of google's filament rendering engine.
|
||||||
|
* [Kaguya](https://github.com/KaiH0717/Kaguya): D3D12 Rendering Engine.
|
||||||
|
* [OpenAWE](https://github.com/OpenAWE-Project/OpenAWE): open implementation
|
||||||
|
of the Alan Wake Engine.
|
||||||
|
* [Nazara Engine](https://github.com/DigitalPulseSoftware/NazaraEngine): fast,
|
||||||
|
cross-platform, object-oriented API to help in daily developer life.
|
||||||
|
|
||||||
* Articles, videos and blog posts:
|
* Articles, videos and blog posts:
|
||||||
* [Some posts](https://skypjack.github.io/tags/#entt) on my personal
|
* [Some posts](https://skypjack.github.io/tags/#entt) on my personal
|
||||||
@@ -180,6 +220,8 @@ I hope this list can grow much more in the future:
|
|||||||
controller emulator and renderer.
|
controller emulator and renderer.
|
||||||
* [Ragdoll](https://ragdolldynamics.com/): real-time physics for Autodesk Maya
|
* [Ragdoll](https://ragdolldynamics.com/): real-time physics for Autodesk Maya
|
||||||
2020.
|
2020.
|
||||||
|
* [Project Lagrange](https://github.com/adobe/lagrange): a robust geometry
|
||||||
|
processing library by [Adobe](https://github.com/adobe).
|
||||||
* [AtomicDEX](https://github.com/KomodoPlatform/atomicDEX-Desktop): a secure
|
* [AtomicDEX](https://github.com/KomodoPlatform/atomicDEX-Desktop): a secure
|
||||||
wallet and non-custodial decentralized exchange rolled into one application.
|
wallet and non-custodial decentralized exchange rolled into one application.
|
||||||
* [Apparently](https://www.linkedin.com/in/skypjack/)
|
* [Apparently](https://www.linkedin.com/in/skypjack/)
|
||||||
|
|||||||
@@ -14,62 +14,43 @@
|
|||||||
# Introduction
|
# Introduction
|
||||||
|
|
||||||
Usually service locators are tightly bound to the services they expose and it's
|
Usually service locators are tightly bound to the services they expose and it's
|
||||||
hard to define a general purpose solution. This template based implementation
|
hard to define a general purpose solution.<br/>
|
||||||
tries to fill the gap and to get rid of the burden of defining a different
|
This tiny class tries to fill the gap and to get rid of the burden of defining a
|
||||||
specific locator for each application.<br/>
|
different specific locator for each application.
|
||||||
This class is tiny, partially unsafe and thus risky to use. Moreover it doesn't
|
|
||||||
fit probably most of the scenarios in which a service locator is required. Look
|
|
||||||
at it as a small tool that can sometimes be useful if users know how to handle
|
|
||||||
it.
|
|
||||||
|
|
||||||
# Service locator
|
# Service locator
|
||||||
|
|
||||||
The API is straightforward. The basic idea is that services are implemented by
|
The service locator API tries to mimic that of `std::optional` and adds some
|
||||||
means of interfaces and rely on polymorphism.<br/>
|
extra functionalities on top of it such as allocator support.<br/>
|
||||||
The locator is instantiated with the base type of the service if any and a
|
There are a couple of functions to set up a service, namely `emplace` and
|
||||||
concrete implementation is provided along with all the parameters required to
|
`allocate_emplace`:
|
||||||
initialize it. As an example:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// the service has no base type, a locator is used to treat it as a kind of singleton
|
entt::locator<interface>::emplace<service>(argument);
|
||||||
entt::service_locator<my_service>::set(params...);
|
entt::locator<interface>::allocate_emplace<service>(allocator, argument);
|
||||||
|
|
||||||
// sets up an opaque service
|
|
||||||
entt::service_locator<audio_interface>::set<audio_implementation>(params...);
|
|
||||||
|
|
||||||
// resets (destroys) the service
|
|
||||||
entt::service_locator<audio_interface>::reset();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The locator can also be queried to know if an active service is currently set
|
The difference is that the latter expects an allocator as the first argument and
|
||||||
and to retrieve it if necessary (either as a pointer or as a reference):
|
uses it to allocate the service itself.<br/>
|
||||||
|
Once a service has been set up, it's retrieved using the value function:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// no service currently set
|
interface &service = entt::locator<interface>::value();
|
||||||
auto empty = entt::service_locator<audio_interface>::empty();
|
|
||||||
|
|
||||||
// gets a (possibly empty) shared pointer to the service ...
|
|
||||||
std::shared_ptr<audio_interface> ptr = entt::service_locator<audio_interface>::get();
|
|
||||||
|
|
||||||
// ... or a reference, but it's undefined behaviour if the service isn't set yet
|
|
||||||
audio_interface &ref = entt::service_locator<audio_interface>::ref();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
A common use is to wrap the different locators in a container class, creating
|
Since the service may not be set (and therefore this function may result in an
|
||||||
aliases for the various services:
|
undefined behavior), the `has_value` and `value_or` functions are also available
|
||||||
|
to test a service locator and to get a fallback service in case there is none:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
struct locator {
|
if(entt::locator<interface>::has_value()) {
|
||||||
using camera = entt::service_locator<camera_interface>;
|
|
||||||
using audio = entt::service_locator<audio_interface>;
|
|
||||||
// ...
|
|
||||||
};
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
void init() {
|
|
||||||
locator::camera::set<camera_null>();
|
|
||||||
locator::audio::set<audio_implementation>(params...);
|
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface &service = entt::locator<interface>::value_or<fallback_impl>(argument);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
All arguments are used only if necessary, that is, if a service doesn't already
|
||||||
|
exist and therefore the fallback service is constructed and returned. In all
|
||||||
|
other cases, they are discarded.<br/>
|
||||||
|
Finally, to reset a service, use the `reset` function.
|
||||||
|
|||||||
158
docs/md/meta.md
158
docs/md/meta.md
@@ -13,6 +13,7 @@
|
|||||||
* [Container support](#container-support)
|
* [Container support](#container-support)
|
||||||
* [Pointer-like types](#pointer-like-types)
|
* [Pointer-like types](#pointer-like-types)
|
||||||
* [Template information](#template-information)
|
* [Template information](#template-information)
|
||||||
|
* [Automatic conversions](#automatic-conversions)
|
||||||
* [Implicitly generated default constructor](#implicitly-generated-default-constructor)
|
* [Implicitly generated default constructor](#implicitly-generated-default-constructor)
|
||||||
* [Policies: the more, the less](#policies-the-more-the-less)
|
* [Policies: the more, the less](#policies-the-more-the-less)
|
||||||
* [Named constants and enums](#named-constants-and-enums)
|
* [Named constants and enums](#named-constants-and-enums)
|
||||||
@@ -109,9 +110,10 @@ decorated version of it. This object can be used to add the following:
|
|||||||
entt::meta<my_type>().ctor<int, char>().ctor<&factory>();
|
entt::meta<my_type>().ctor<int, char>().ctor<&factory>();
|
||||||
```
|
```
|
||||||
|
|
||||||
* _Destructors_. Free functions can be set as destructors of reflected types.
|
* _Destructors_. Free functions and member functions can be used as destructors
|
||||||
The purpose is to give users the ability to free up resources that require
|
of reflected types. The purpose is to give users the ability to free up
|
||||||
special treatment before an object is actually destroyed.<br/>
|
resources that require special treatment before an object is actually
|
||||||
|
destroyed.<br/>
|
||||||
Use the `dtor` member function for this purpose:
|
Use the `dtor` member function for this purpose:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -146,6 +148,12 @@ decorated version of it. This object can be used to add the following:
|
|||||||
entt::meta<my_type>().data<nullptr, &my_type::data_member>("member"_hs);
|
entt::meta<my_type>().data<nullptr, &my_type::data_member>("member"_hs);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Multiple setters are also supported by means of a `value_list` object:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::meta<my_type>().data<entt::value_list<&from_int, &from_string>, &my_type::data_member>("member"_hs);
|
||||||
|
```
|
||||||
|
|
||||||
Refer to the inline documentation for all the details.
|
Refer to the inline documentation for all the details.
|
||||||
|
|
||||||
* _Member functions_. Both real member functions of the underlying type and free
|
* _Member functions_. Both real member functions of the underlying type and free
|
||||||
@@ -267,19 +275,6 @@ Refer to the inline documentation for all the details.
|
|||||||
|
|
||||||
The meta objects that compose a meta type are accessed in the following ways:
|
The meta objects that compose a meta type are accessed in the following ways:
|
||||||
|
|
||||||
* _Meta constructors_. They are accessed by types of arguments:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto ctor = entt::resolve<my_type>().ctor<int, char>();
|
|
||||||
```
|
|
||||||
|
|
||||||
The returned type is `meta_ctor` and may be invalid if there is no constructor
|
|
||||||
that accepts the supplied arguments or at least some types from which they are
|
|
||||||
derived or to which they can be converted.<br/>
|
|
||||||
A meta constructor offers an API to know the number of its arguments and their
|
|
||||||
expected meta types. Furthermor, it's possible to invoke it and therefore to
|
|
||||||
construct new instances of the underlying type.
|
|
||||||
|
|
||||||
* _Meta data_. They are accessed by _name_:
|
* _Meta data_. They are accessed by _name_:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -328,7 +323,7 @@ Furthermore, all them are also returned by specific overloads that provide the
|
|||||||
caller with iterable ranges of top-level elements. As an example:
|
caller with iterable ranges of top-level elements. As an example:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
for(auto data = entt::resolve<my_type>().data()) {
|
for(auto data: entt::resolve<my_type>().data()) {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -421,7 +416,7 @@ to case. In particular:
|
|||||||
```
|
```
|
||||||
|
|
||||||
* The `resize` member function allows to resize the wrapped container and
|
* The `resize` member function allows to resize the wrapped container and
|
||||||
returns true in case of succes:
|
returns true in case of success:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
const bool ok = view.resize(3u);
|
const bool ok = view.resize(3u);
|
||||||
@@ -715,6 +710,56 @@ correspondence between real types and meta types.<br/>
|
|||||||
Therefore, the specialization will be used as is and the information it contains
|
Therefore, the specialization will be used as is and the information it contains
|
||||||
will be associated with the appropriate type when required.
|
will be associated with the appropriate type when required.
|
||||||
|
|
||||||
|
## Automatic conversions
|
||||||
|
|
||||||
|
In C++, there are a number of conversions allowed between arithmetic types that
|
||||||
|
make it convenient to work with this kind of data.<br/>
|
||||||
|
If this were to be translated into explicit registrations with the reflection
|
||||||
|
system, it would result in a long series of instructions such as the following:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::meta<int>()
|
||||||
|
.conv<bool>()
|
||||||
|
.conv<char>()
|
||||||
|
// ...
|
||||||
|
.conv<double>();
|
||||||
|
```
|
||||||
|
|
||||||
|
Repeated for each type eligible to undergo this type of conversions. This is
|
||||||
|
both error prone and repetitive.<br/>
|
||||||
|
Similarly, the language allows users to silently convert unscoped enums to their
|
||||||
|
underlying types and offers what it takes to do the same for scoped enums. It
|
||||||
|
would result in the following if it were to be done explicitly:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::meta<my_enum>()
|
||||||
|
.conv<std::underlying_type_t<my_enum>>();
|
||||||
|
```
|
||||||
|
|
||||||
|
Fortunately, all of this can also be avoided. `EnTT` offers implicit support for
|
||||||
|
these types of conversions:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::meta_any any{42};
|
||||||
|
any.allow_cast<double>();
|
||||||
|
double value = any.cast<double>();
|
||||||
|
```
|
||||||
|
|
||||||
|
With no need for registration, the conversion takes place automatically under
|
||||||
|
the hood. The same goes for a call to `allow_cast` involving a meta type:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::meta_type type = entt::resolve<int>();
|
||||||
|
entt::meta_any any{my_enum::a_value};
|
||||||
|
any.allow_cast(type);
|
||||||
|
int value = any.cast<int>();
|
||||||
|
```
|
||||||
|
|
||||||
|
This should make working with arithmetic types and scoped or unscoped enums as
|
||||||
|
easy as it is in C++.<br/>
|
||||||
|
It's also worth noting that it's still possible to set up conversion functions
|
||||||
|
manually and these will always be preferred over the automatic ones.
|
||||||
|
|
||||||
## Implicitly generated default constructor
|
## Implicitly generated default constructor
|
||||||
|
|
||||||
In many cases, it's useful to be able to create objects of default constructible
|
In many cases, it's useful to be able to create objects of default constructible
|
||||||
@@ -726,14 +771,7 @@ them.
|
|||||||
For this reason and only for default constructible types, default constructors
|
For this reason and only for default constructible types, default constructors
|
||||||
are automatically defined and associated with their meta types, whether they are
|
are automatically defined and associated with their meta types, whether they are
|
||||||
explicitly or implicitly generated.<br/>
|
explicitly or implicitly generated.<br/>
|
||||||
Therefore, it won't be necessary to do this in order to construct an integer
|
Therefore, this is all is needed to construct an integer from its meta type:
|
||||||
from its meta type:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
entt::meta<int>().ctor<>();
|
|
||||||
```
|
|
||||||
|
|
||||||
Instead, just do this:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
entt::resolve<int>().construct();
|
entt::resolve<int>().construct();
|
||||||
@@ -742,11 +780,8 @@ entt::resolve<int>().construct();
|
|||||||
Where the meta type can be for example the one returned from a meta container,
|
Where the meta type can be for example the one returned from a meta container,
|
||||||
useful for building keys without knowing or having to register the actual types.
|
useful for building keys without knowing or having to register the actual types.
|
||||||
|
|
||||||
In all cases, when users register custom defaul constructors, they are preferred
|
In all cases, when users register default constructors, they are preferred both
|
||||||
both during searches and when the `construct` member function is invoked.<br/>
|
during searches and when the `construct` member function is invoked.
|
||||||
However, the implicitly generated default constructor will always be returned,
|
|
||||||
either if one is not explicitly specified or if all constructors are iterated
|
|
||||||
for some reason (in this case, it will always be the last element).
|
|
||||||
|
|
||||||
## Policies: the more, the less
|
## Policies: the more, the less
|
||||||
|
|
||||||
@@ -771,9 +806,11 @@ There are a few alternatives available at the moment:
|
|||||||
* The _as-void_ policy, associated with the type `entt::as_void_t`.<br/>
|
* The _as-void_ policy, associated with the type `entt::as_void_t`.<br/>
|
||||||
Its purpose is to discard the return value of a meta object, whatever it is,
|
Its purpose is to discard the return value of a meta object, whatever it is,
|
||||||
thus making it appear as if its type were `void`:
|
thus making it appear as if its type were `void`:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
entt::meta<my_type>().func<&my_type::member_function, entt::as_void_t>("member"_hs);
|
entt::meta<my_type>().func<&my_type::member_function, entt::as_void_t>("member"_hs);
|
||||||
```
|
```
|
||||||
|
|
||||||
If the use with functions is obvious, it must be said that it's also possible
|
If the use with functions is obvious, it must be said that it's also possible
|
||||||
to use this policy with constructors and data members. In the first case, the
|
to use this policy with constructors and data members. In the first case, the
|
||||||
constructor will be invoked but the returned wrapper will actually be empty.
|
constructor will be invoked but the returned wrapper will actually be empty.
|
||||||
@@ -785,9 +822,11 @@ There are a few alternatives available at the moment:
|
|||||||
Accessing the object contained in the wrapper for which the _reference_ was
|
Accessing the object contained in the wrapper for which the _reference_ was
|
||||||
requested will make it possible to directly access the instance used to
|
requested will make it possible to directly access the instance used to
|
||||||
initialize the wrapper itself:
|
initialize the wrapper itself:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
entt::meta<my_type>().data<&my_type::data_member, entt::as_ref_t>("member"_hs);
|
entt::meta<my_type>().data<&my_type::data_member, entt::as_ref_t>("member"_hs);
|
||||||
```
|
```
|
||||||
|
|
||||||
These policies work with constructors (for example, when objects are taken
|
These policies work with constructors (for example, when objects are taken
|
||||||
from an external container rather than created on demand), data members and
|
from an external container rather than created on demand), data members and
|
||||||
functions in general.<br/>
|
functions in general.<br/>
|
||||||
@@ -881,38 +920,15 @@ Multiple formats are supported when it comes to defining a property:
|
|||||||
|
|
||||||
A tuple contains one or more properties. All of them are treated individually.
|
A tuple contains one or more properties. All of them are treated individually.
|
||||||
|
|
||||||
* Annotations:
|
Note that it's not possible to invoke `prop` multiple times for the same meta
|
||||||
|
object and trying to do that will result in a compilation error.<br/>
|
||||||
|
However, the `props` function is available to associate several properties at
|
||||||
|
once. In this case, properties in the key/value form aren't allowed, since they
|
||||||
|
would be interpreted as two different properties rather than a single one.
|
||||||
|
|
||||||
```cpp
|
The meta objects for which properties are supported are currently meta types,
|
||||||
entt::meta<my_type>().type("reflected_type"_hs).prop(&property_generator);
|
meta data and meta functions.<br/>
|
||||||
```
|
These types also offer a couple of member functions named `prop` to iterate all
|
||||||
|
|
||||||
An annotation is an invocable object that returns one or more properties. All
|
|
||||||
of them are treated individually.
|
|
||||||
|
|
||||||
It's possible to invoke the `prop` function several times if needed, one for
|
|
||||||
each property to associate with the last meta object created:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
entt::meta<my_type>()
|
|
||||||
.type("reflected_type"_hs)
|
|
||||||
.prop(entt::hashed_string{"Name"}, "Reflected Type")
|
|
||||||
.data<&my_type::data_member>("member"_hs)
|
|
||||||
.prop(std::make_pair("tooltip"_hs, "Member"))
|
|
||||||
.prop(my_enum::a_value, 42);
|
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively, the `props` function is available to associate several properties
|
|
||||||
at a time. However, in this case properties in the key/value form aren't
|
|
||||||
allowed, since they would be interpreted as two different properties rather than
|
|
||||||
a single one.
|
|
||||||
|
|
||||||
The meta objects for which properties are supported are currently the meta
|
|
||||||
types, meta constructors, meta data and meta functions. It's not possible to
|
|
||||||
attach properties to other types of meta objects and the factory returned as a
|
|
||||||
result of their construction won't allow such an operation.
|
|
||||||
|
|
||||||
These types offer a couple of member functions named `prop` to iterate all
|
|
||||||
properties at once or to search a specific property by key:
|
properties at once or to search a specific property by key:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -942,7 +958,21 @@ objects from it and making its identifier no longer visible. The underlying node
|
|||||||
will remain available though, as if it were implicitly generated:
|
will remain available though, as if it were implicitly generated:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
entt::resolve<my_type>().reset();
|
entt::meta_reset<my_type>();
|
||||||
```
|
```
|
||||||
|
|
||||||
The type can be re-registered later with a completely different name and form.
|
It's also possible to reset types by their unique identifiers if required:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::meta_reset("my_type"_hs);
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally, there exists a non-template overload of the `meta_reset` function that
|
||||||
|
doesn't accept argument and resets all searchable types (that is, all types that
|
||||||
|
were assigned an unique identifier):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
entt::meta_reset();
|
||||||
|
```
|
||||||
|
|
||||||
|
All types can be re-registered later with a completely different name and form.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
* [Concept and implementation](#concept-and-implementation)
|
* [Concept and implementation](#concept-and-implementation)
|
||||||
* [Deduced interface](#deduced-interface)
|
* [Deduced interface](#deduced-interface)
|
||||||
* [Defined interface](#defined-interface)
|
* [Defined interface](#defined-interface)
|
||||||
* [Fullfill a concept](#fullfill-a-concept)
|
* [Fulfill a concept](#fulfill-a-concept)
|
||||||
* [Inheritance](#inheritance)
|
* [Inheritance](#inheritance)
|
||||||
* [Static polymorphism in the wild](#static-polymorphism-in-the-wild)
|
* [Static polymorphism in the wild](#static-polymorphism-in-the-wild)
|
||||||
* [Storage size and alignment requirement](#storage-size-and-alignment-requirement)
|
* [Storage size and alignment requirement](#storage-size-and-alignment-requirement)
|
||||||
@@ -24,8 +24,8 @@ Static polymorphism is a very powerful tool in C++, albeit sometimes cumbersome
|
|||||||
to obtain.<br/>
|
to obtain.<br/>
|
||||||
This module aims to make it simple and easy to use.
|
This module aims to make it simple and easy to use.
|
||||||
|
|
||||||
The library allows to define _concepts_ as interfaces to fullfill with concrete
|
The library allows to define _concepts_ as interfaces to fulfill with concrete
|
||||||
classes withouth having to inherit from a common base.<br/>
|
classes without having to inherit from a common base.<br/>
|
||||||
This is, among others, one of the advantages of static polymorphism in general
|
This is, among others, one of the advantages of static polymorphism in general
|
||||||
and of a generic wrapper like that offered by the `poly` class template in
|
and of a generic wrapper like that offered by the `poly` class template in
|
||||||
particular.<br/>
|
particular.<br/>
|
||||||
@@ -74,7 +74,7 @@ limitations and it's therefore useful to be able to get around the deduction by
|
|||||||
providing a custom definition for the static virtual table.
|
providing a custom definition for the static virtual table.
|
||||||
|
|
||||||
Once the interface is defined, it will be sufficient to provide a generic
|
Once the interface is defined, it will be sufficient to provide a generic
|
||||||
implementation to fullfill the concept.<br/>
|
implementation to fulfill the concept.<br/>
|
||||||
Also in this case, the library allows customizations based on types or families
|
Also in this case, the library allows customizations based on types or families
|
||||||
of types, so as to be able to go beyond the generic case where necessary.
|
of types, so as to be able to go beyond the generic case where necessary.
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ struct Drawable: entt::type_list<> {
|
|||||||
```
|
```
|
||||||
|
|
||||||
It's recognizable by the fact that it inherits from an empty type list.<br/>
|
It's recognizable by the fact that it inherits from an empty type list.<br/>
|
||||||
Functions can also be const, accept any number of paramters and return a type
|
Functions can also be const, accept any number of parameters and return a type
|
||||||
other than `void`:
|
other than `void`:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -120,7 +120,7 @@ external call:
|
|||||||
struct Drawable: entt::type_list<> {
|
struct Drawable: entt::type_list<> {
|
||||||
template<typename Base>
|
template<typename Base>
|
||||||
struct type: Base {
|
struct type: Base {
|
||||||
bool draw() const { entt::poly_call<0>(*this); }
|
void draw() const { entt::poly_call<0>(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
@@ -187,7 +187,7 @@ the interface itself.
|
|||||||
Explicitly defining a static virtual table suppresses the deduction step and
|
Explicitly defining a static virtual table suppresses the deduction step and
|
||||||
allows maximum flexibility when providing the implementation for a concept.
|
allows maximum flexibility when providing the implementation for a concept.
|
||||||
|
|
||||||
## Fullfill a concept
|
## Fulfill a concept
|
||||||
|
|
||||||
The `impl` alias template of a concept is used to define how it's fulfilled:
|
The `impl` alias template of a concept is used to define how it's fulfilled:
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ struct Drawable: entt::type_list<> {
|
|||||||
|
|
||||||
In this case, it's stated that the `draw` method of a generic type will be
|
In this case, it's stated that the `draw` method of a generic type will be
|
||||||
enough to satisfy the requirements of the `Drawable` concept.<br/>
|
enough to satisfy the requirements of the `Drawable` concept.<br/>
|
||||||
Both member functions and free functions are supported to fullfill concepts:
|
Both member functions and free functions are supported to fulfill concepts:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ I hope this list can grow much more in the future:
|
|||||||
ECS that uses sparse sets to keep track of entities in systems.
|
ECS that uses sparse sets to keep track of entities in systems.
|
||||||
* [EntityX](https://github.com/alecthomas/entityx): a bitset based ECS that
|
* [EntityX](https://github.com/alecthomas/entityx): a bitset based ECS that
|
||||||
uses a single large matrix of components indexed with entities.
|
uses a single large matrix of components indexed with entities.
|
||||||
|
* [Gaia-ECS](https://github.com/richardbiely/gaia-ecs): a chunk based
|
||||||
|
archetype ECS.
|
||||||
* [Polypropylene](https://github.com/pmbittner/Polypropylene): a hybrid
|
* [Polypropylene](https://github.com/pmbittner/Polypropylene): a hybrid
|
||||||
solution between an ECS and dynamic mixins.
|
solution between an ECS and dynamic mixins.
|
||||||
|
|
||||||
@@ -44,15 +46,25 @@ I hope this list can grow much more in the future:
|
|||||||
by `EnTT`.
|
by `EnTT`.
|
||||||
|
|
||||||
* Javascript:
|
* Javascript:
|
||||||
* [\@javelin/ecs](https://github.com/3mcd/javelin/tree/master/packages/ecs): an
|
* [\@javelin/ecs](https://github.com/3mcd/javelin/tree/master/packages/ecs):
|
||||||
archetype ECS in TypeScript.
|
an archetype ECS in TypeScript.
|
||||||
* [ecsy](https://github.com/MozillaReality/ecsy): I haven't had the time to
|
* [ecsy](https://github.com/MozillaReality/ecsy): I haven't had the time to
|
||||||
investigate the underlying design of `ecsy` but it looks cool anyway.
|
investigate the underlying design of `ecsy` but it looks cool anyway.
|
||||||
|
|
||||||
|
* Perl:
|
||||||
|
* [Game::Entities](https://gitlab.com/jjatria/perl-game-entities): a simple
|
||||||
|
entity registry for ECS designs inspired by `EnTT`.
|
||||||
|
|
||||||
|
* Raku:
|
||||||
|
* [Game::Entities](https://gitlab.com/jjatria/raku-game-entities): a simple
|
||||||
|
entity registry for ECS designs inspired by `EnTT`.
|
||||||
|
|
||||||
* Rust:
|
* Rust:
|
||||||
* [Legion](https://github.com/TomGillen/legion): a chunk based archetype ECS.
|
* [Legion](https://github.com/TomGillen/legion): a chunk based archetype ECS.
|
||||||
* [Shipyard](https://github.com/leudz/shipyard): it borrows some ideas from
|
* [Shipyard](https://github.com/leudz/shipyard): it borrows some ideas from
|
||||||
`EnTT` and offers a sparse sets based ECS with grouping functionalities.
|
`EnTT` and offers a sparse sets based ECS with grouping functionalities.
|
||||||
|
* [Sparsey](https://github.com/LechintanTudor/sparsey): sparse set based ECS
|
||||||
|
written in Rust.
|
||||||
* [Specs](https://github.com/amethyst/specs): a parallel ECS based mainly on
|
* [Specs](https://github.com/amethyst/specs): a parallel ECS based mainly on
|
||||||
hierarchical bitsets that allows different types of storage as needed.
|
hierarchical bitsets that allows different types of storage as needed.
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
* [Introduction](#introduction)
|
* [Introduction](#introduction)
|
||||||
* [The resource, the loader and the cache](#the-resource-the-loader-and-the-cache)
|
* [The resource, the loader and the cache](#the-resource-the-loader-and-the-cache)
|
||||||
|
* [Resource handle](#resource-handle)
|
||||||
|
* [Loaders](#loader)
|
||||||
|
* [The cache class](#the-cache)
|
||||||
<!--
|
<!--
|
||||||
@endcond TURN_OFF_DOXYGEN
|
@endcond TURN_OFF_DOXYGEN
|
||||||
-->
|
-->
|
||||||
@@ -21,211 +24,169 @@ Examples are loading everything on start, loading on request, predictive
|
|||||||
loading, and so on.
|
loading, and so on.
|
||||||
|
|
||||||
`EnTT` doesn't pretend to offer a _one-fits-all_ solution for the different
|
`EnTT` doesn't pretend to offer a _one-fits-all_ solution for the different
|
||||||
cases. Instead, it offers a minimal and perhaps trivial cache that can be useful
|
cases.<br/>
|
||||||
most of the time during prototyping and sometimes even in a production
|
Instead, the library offers a minimal, general purpose resource cache that might
|
||||||
environments.<br/>
|
be useful in many cases.
|
||||||
For those interested in the subject, the plan is to improve it considerably over
|
|
||||||
time in terms of performance, memory usage and functionalities. Hoping to make
|
|
||||||
it, of course, one step at a time.
|
|
||||||
|
|
||||||
# The resource, the loader and the cache
|
# The resource, the loader and the cache
|
||||||
|
|
||||||
There are three main actors in the model: the resource, the loader and the
|
Resource, loader and cache are the three main actors for the purpose.<br/>
|
||||||
cache.
|
The _resource_ is an image, an audio, a video or any other type:
|
||||||
|
|
||||||
The _resource_ is whatever users want it to be. An image, a video, an audio,
|
|
||||||
whatever. There are no limits.<br/>
|
|
||||||
As a minimal example:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
struct my_resource { const int value; };
|
struct my_resource { const int value; };
|
||||||
```
|
```
|
||||||
|
|
||||||
A _loader_ is a class the aim of which is to load a specific resource. It has to
|
The _loader_ is a callable type the aim of which is to load a specific resource:
|
||||||
inherit directly from a dedicated base class as in the following example:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
struct my_loader final: entt::resource_loader<my_loader, my_resource> {
|
struct my_loader final {
|
||||||
// ...
|
using result_type = std::shared_ptr<my_resource>;
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
Where `my_resource` is the type of resources it creates.<br/>
|
result_type operator()(int value) const {
|
||||||
A resource loader must also expose a public const member function named `load`
|
|
||||||
that accepts a variable number of arguments and returns a shared pointer to a
|
|
||||||
resource.<br/>
|
|
||||||
As an example:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
struct my_loader: entt::resource_loader<my_loader, my_resource> {
|
|
||||||
std::shared_ptr<my_resource> load(int value) const {
|
|
||||||
// ...
|
// ...
|
||||||
return std::shared_ptr<my_resource>(new my_resource{ value });
|
return std::make_shared<my_resource>(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
In general, resource loaders should not have a state or retain data of any type.
|
Its function operator can accept any arguments and should return a value of the
|
||||||
They should let the cache manage their resources instead.<br/>
|
declared result type (`std::shared_ptr<my_resource>` in the example).<br/>
|
||||||
As a side note, base class and CRTP idiom aren't strictly required with the
|
A loader can also overload its function call operator to make it possible to
|
||||||
current implementation. One could argue that a cache can easily work with
|
construct the same or another resource from different lists of arguments.
|
||||||
loaders of any type. However, future changes won't be breaking ones by forcing
|
|
||||||
the use of a base class today and that's why the model is already in its place.
|
|
||||||
|
|
||||||
Finally, a cache is a specialization of a class template tailored to a specific
|
Finally, a cache is a specialization of a class template tailored to a specific
|
||||||
resource:
|
resource and (optionally) a loader:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
using my_cache = entt::resource_cache<my_resource>;
|
using my_cache = entt::resource_cache<my_resource, my_loader>;
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
my_cache cache{};
|
my_cache cache{};
|
||||||
```
|
```
|
||||||
|
|
||||||
The idea is to create different caches for different types of resources and to
|
The cache is meant to be used to create different caches for different types of
|
||||||
manage each one independently in the most appropriate way.<br/>
|
resources and to manage each one independently in the most appropriate way.<br/>
|
||||||
As a (very) trivial example, audio tracks can survive in most of the scenes of
|
As a (very) trivial example, audio tracks can survive in most of the scenes of
|
||||||
an application while meshes can be associated with a single scene and then
|
an application while meshes can be associated with a single scene only, then
|
||||||
discarded when users leave it.
|
discarded when a player leaves it.
|
||||||
|
|
||||||
A cache offers a set of basic functionalities to query its internal state and to
|
## Resource handle
|
||||||
_organize_ it:
|
|
||||||
|
Resources aren't returned directly to the caller. Instead, they are wrapped in a
|
||||||
|
_resource handle_ identified by the `entt::resource` class template.<br/>
|
||||||
|
For those who know the _flyweight design pattern_ already, that's exactly what
|
||||||
|
it is. To all others, this is the time to brush up on some notions instead.
|
||||||
|
|
||||||
|
A shared pointer could have been used as a resource handle. In fact, the default
|
||||||
|
handle mostly maps the interface of its standard counterpart and only adds a few
|
||||||
|
things to it.<br/>
|
||||||
|
However, the handle in `EnTT` is designed as a standalone class template named
|
||||||
|
`resource`. It boils down to the fact that specializing a class in the standard
|
||||||
|
is often undefined behavior while having the ability to specialize the handle
|
||||||
|
for one, more or all resource types could help over time.
|
||||||
|
|
||||||
|
## Loaders
|
||||||
|
|
||||||
|
A loader is a class that is responsible for _loading_ the resources.<br/>
|
||||||
|
By default, it's just a callable object which forwards its arguments to the
|
||||||
|
resource itself. That is, a _passthrough type_. All the work is demanded to the
|
||||||
|
constructor(s) of the resource itself.<br/>
|
||||||
|
Loaders also are fully customizable as expected.
|
||||||
|
|
||||||
|
A custom loader is a class with at least one function call operator and a member
|
||||||
|
type named `result_type`.<br/>
|
||||||
|
The loader isn't required to return a resource handle. As long as `return_type`
|
||||||
|
is suitable for constructing a handle, that's fine.
|
||||||
|
|
||||||
|
When using the default handle, it expects a resource type which is convertible
|
||||||
|
to or suitable for constructing an `std::shared_ptr<Type>` (where `Type` is the
|
||||||
|
actual resource type).<br/>
|
||||||
|
In other terms, the loader should return shared pointers to the given resource
|
||||||
|
type. However, it isn't mandatory. Users can easily get around this constraint
|
||||||
|
by specializing both the handle and the loader.
|
||||||
|
|
||||||
|
A cache forwards all its arguments to the loader if required. This means that
|
||||||
|
loaders can also support tag dispatching to offer different loading policies:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// gets the number of resources managed by a cache
|
struct my_loader {
|
||||||
const auto size = cache.size();
|
using result_type = std::shared_ptr<my_resource>;
|
||||||
|
|
||||||
// checks if a cache contains at least a valid resource
|
struct from_disk_tag{};
|
||||||
const auto empty = cache.empty();
|
struct from_network_tag{};
|
||||||
|
|
||||||
// clears a cache and discards its content
|
template<typename Args>
|
||||||
cache.clear();
|
result_type operator()(from_disk_tag, Args&&... args) {
|
||||||
|
// ...
|
||||||
|
return std::make_shared<my_resource>(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Args>
|
||||||
|
result_type operator()(from_network_tag, Args&&... args) {
|
||||||
|
// ...
|
||||||
|
return std::make_shared<my_resource>(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Besides these member functions, a cache contains what is needed to load, use and
|
This makes the whole loading logic quite flexible and easy to extend over time.
|
||||||
discard resources of the given type.<br/>
|
|
||||||
Before exploring this part of the interface, it makes sense to mention how
|
## The cache class
|
||||||
resources are identified. They have type `id_type` and therefore they can be
|
|
||||||
created explicitly as in the following example:
|
The cache is the class that is asked to _connect the dots_.<br/>
|
||||||
|
It loads the resources, store them aside and returns handles as needed:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
constexpr auto identifier = "my/resource/identifier"_hs;
|
entt::resource_cache<my_resource, my_loader> cache{};
|
||||||
// this is equivalent to the following
|
|
||||||
constexpr entt::id_type hs = entt::hashed_string{"my/resource/identifier"};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The class `hashed_string` is described in a dedicated section, so I won't go in
|
Under the hood, a cache is nothing more than a map where the key value has type
|
||||||
details here.
|
`entt::id_type` while the mapped value is whatever type its loader returns.<br/>
|
||||||
|
For this reason, it offers most of the functionality a user would expect from a
|
||||||
Resources are loaded and thus stored in a cache through the `load` member
|
map, such as `empty` or `size` and so on. Similarly, it's an iterable type that
|
||||||
function. It accepts the loader to use as a template parameter, the resource
|
also supports indexing by resource id:
|
||||||
identifier and the parameters used to construct the resource as arguments:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// uses the identifier declared above
|
for(entt::resource<my_resource> curr: cache) {
|
||||||
cache.load<my_loader>(identifier, 0);
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
// uses a hashed string directly
|
if(entt::resource<my_resource> res = cache["resource/id"_hs]; res) {
|
||||||
cache.load<my_loader>("another/identifier"_hs, 42);
|
|
||||||
```
|
|
||||||
|
|
||||||
The function returns a handle to the resource, whether it already exists or is
|
|
||||||
loaded. In case the loader returns an invalid pointer, the handle is invalid as
|
|
||||||
well and therefore it can be easily used with an `if` statement:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
if(entt::resource_handle handle = cache.load<my_loader>("another/identifier"_hs, 42); handle) {
|
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Before trying to load a resource, the `contains` member function can be used to
|
Please, refer to the inline documentation for all the details about the other
|
||||||
know if a cache already contains a specific resource:
|
functions (for example `contains` or `erase`).
|
||||||
|
|
||||||
|
Set aside the part of the API that this class shares with a map, it also adds
|
||||||
|
something on top of it in order to address the most common requirements of a
|
||||||
|
resource cache.<br/>
|
||||||
|
In particular, it doesn't have an `emplace` member function which is replaced by
|
||||||
|
`load` and `force_load` instead (where the former loads a new resource only if
|
||||||
|
not present while the second triggers a forced loading in any case):
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto exists = cache.contains("my/identifier"_hs);
|
auto ret = cache.load("resource/id"_hs);
|
||||||
|
|
||||||
|
// true only if the resource was not already present
|
||||||
|
const bool loaded = ret.second;
|
||||||
|
|
||||||
|
// takes the resource handle pointed to by the returned iterator
|
||||||
|
entt::resource<my_resource> res = *ret.first;
|
||||||
```
|
```
|
||||||
|
|
||||||
There exists also a member function to use to force a reload of an already
|
Note that the hashed string is used for convenience in the example above.<br/>
|
||||||
existing resource if needed:
|
Resource identifiers are nothing more than integral values. Therefore, plain
|
||||||
|
numbers as well as non-class enum value are accepted.
|
||||||
|
|
||||||
```cpp
|
Moreover, it's worth mentioning that both the iterators of a cache and its
|
||||||
auto handle = cache.reload<my_loader>("another/identifier"_hs, 42);
|
indexing operators return resource handles rather than instances of the mapped
|
||||||
```
|
type.<br/>
|
||||||
|
Since the cache has no control over the loader and a resource isn't required to
|
||||||
As above, the function returns a handle to the resource that is invalid in case
|
also be convertible to bool, these handles can be invalid. This usually means an
|
||||||
of errors. The `reload` member function is a kind of alias of the following
|
error in the user logic but it may also be an _expected_ event.<br/>
|
||||||
snippet:
|
It's therefore recommended to verify handles validity with a check in debug (for
|
||||||
|
example, when loading) or an appropriate logic in retail.
|
||||||
```cpp
|
|
||||||
cache.discard(identifier);
|
|
||||||
cache.load<my_loader>(identifier, 42);
|
|
||||||
```
|
|
||||||
|
|
||||||
Where the `discard` member function is used to get rid of a resource if loaded.
|
|
||||||
In case the cache doesn't contain a resource for the given identifier, `discard`
|
|
||||||
does nothing and returns immediately.
|
|
||||||
|
|
||||||
So far, so good. Resources are finally loaded and stored within the cache.<br/>
|
|
||||||
They are returned to users in the form of handles. To get one of them later on:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto handle = cache.handle("my/identifier"_hs);
|
|
||||||
```
|
|
||||||
|
|
||||||
The idea behind a handle is the same of the flyweight pattern. In other terms,
|
|
||||||
resources aren't copied around. Instead, instances are shared between handles.
|
|
||||||
Users of a resource own a handle that guarantees that a resource isn't destroyed
|
|
||||||
until all the handles are destroyed, even if the resource itself is removed from
|
|
||||||
the cache.<br/>
|
|
||||||
Handles are tiny objects both movable and copyable. They return the contained
|
|
||||||
resource as a (possibly const) reference on request:
|
|
||||||
|
|
||||||
* By means of the `get` member function:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto &resource = handle.get();
|
|
||||||
```
|
|
||||||
|
|
||||||
* Using the proper cast operator:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto &resource = handle;
|
|
||||||
```
|
|
||||||
|
|
||||||
* Through the dereference operator:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto &resource = *handle;
|
|
||||||
```
|
|
||||||
|
|
||||||
The resource can also be accessed directly using the arrow operator if required:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto value = handle->value;
|
|
||||||
```
|
|
||||||
|
|
||||||
To test if a handle is still valid, the cast operator to `bool` allows users to
|
|
||||||
use it in a guard:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
if(handle) {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Finally, in case there is the need to load a resource and thus to get a handle
|
|
||||||
without storing the resource itself in the cache, users can rely on the `temp`
|
|
||||||
member function template.<br/>
|
|
||||||
The declaration is similar to that of `load`, a (possibly invalid) handle for
|
|
||||||
the resource is returned also in this case:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
if(auto handle = cache.temp<my_loader>(42); handle) {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Do not forget to test the handle for validity. Otherwise, getting a reference to
|
|
||||||
the resource it points may result in undefined behavior.
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
* [Lambda support](#lambda-support)
|
* [Lambda support](#lambda-support)
|
||||||
* [Signals](#signals)
|
* [Signals](#signals)
|
||||||
* [Event dispatcher](#event-dispatcher)
|
* [Event dispatcher](#event-dispatcher)
|
||||||
|
* [Named queues](#named-queues)
|
||||||
* [Event emitter](#event-emitter)
|
* [Event emitter](#event-emitter)
|
||||||
<!--
|
<!--
|
||||||
@endcond TURN_OFF_DOXYGEN
|
@endcond TURN_OFF_DOXYGEN
|
||||||
@@ -361,7 +362,7 @@ case:
|
|||||||
struct my_collector {
|
struct my_collector {
|
||||||
std::vector<int> vec{};
|
std::vector<int> vec{};
|
||||||
|
|
||||||
bool operator()(int v) noexcept {
|
bool operator()(int v) {
|
||||||
vec.push_back(v);
|
vec.push_back(v);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -375,23 +376,20 @@ signal.collect(std::ref(collector));
|
|||||||
|
|
||||||
# Event dispatcher
|
# Event dispatcher
|
||||||
|
|
||||||
The event dispatcher class is designed so as to be used in a loop. It allows
|
The event dispatcher class allows users to trigger immediate events or to queue
|
||||||
users both to trigger immediate events or to queue events to be published all
|
and publish them all together later.<br/>
|
||||||
together once per tick.<br/>
|
This class lazily instantiates its queues. Therefore, it's not necessary to
|
||||||
This class shares part of its API with the one of the signal handler, but it
|
_announce_ the event types in advance:
|
||||||
doesn't require that all the types of events are specified when declared:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// define a general purpose dispatcher
|
// define a general purpose dispatcher
|
||||||
entt::dispatcher dispatcher{};
|
entt::dispatcher dispatcher{};
|
||||||
```
|
```
|
||||||
|
|
||||||
In order to register an instance of a class to a dispatcher, its type must
|
A listener registered with a dispatcher is such that its type offers one or more
|
||||||
expose one or more member functions the arguments of which are such that `E &`
|
member functions that take arguments of type `Event &` for any type of event,
|
||||||
can be converted to them for each type of event `E`, no matter what the return
|
regardless of the return value.<br/>
|
||||||
value is.<br/>
|
These functions are linked directly via `connect` to a _sink_:
|
||||||
The name of the member function aimed to receive the event must be provided to
|
|
||||||
the `connect` member function of the sink in charge for the specific event:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
struct an_event { int value; };
|
struct an_event { int value; };
|
||||||
@@ -409,8 +407,8 @@ dispatcher.sink<an_event>().connect<&listener::receive>(listener);
|
|||||||
dispatcher.sink<another_event>().connect<&listener::method>(listener);
|
dispatcher.sink<another_event>().connect<&listener::method>(listener);
|
||||||
```
|
```
|
||||||
|
|
||||||
The `disconnect` member function follows the same pattern and can be used to
|
The `disconnect` member function is used to remove one listener at a time or all
|
||||||
remove one listener at a time or all of them at once:
|
of them at once:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
dispatcher.sink<an_event>().disconnect<&listener::receive>(listener);
|
dispatcher.sink<an_event>().disconnect<&listener::receive>(listener);
|
||||||
@@ -418,14 +416,10 @@ dispatcher.sink<another_event>().disconnect(listener);
|
|||||||
```
|
```
|
||||||
|
|
||||||
The `trigger` member function serves the purpose of sending an immediate event
|
The `trigger` member function serves the purpose of sending an immediate event
|
||||||
to all the listeners registered so far. It offers a convenient approach that
|
to all the listeners registered so far:
|
||||||
relieves users from having to create the event itself. Instead, it's enough to
|
|
||||||
specify the type of event and provide all the parameters required to construct
|
|
||||||
it.<br/>
|
|
||||||
As an example:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
dispatcher.trigger<an_event>(42);
|
dispatcher.trigger(an_event{42});
|
||||||
dispatcher.trigger<another_event>();
|
dispatcher.trigger<another_event>();
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -434,16 +428,14 @@ method can be used to push around urgent messages like an _is terminating_
|
|||||||
notification on a mobile app.
|
notification on a mobile app.
|
||||||
|
|
||||||
On the other hand, the `enqueue` member function queues messages together and
|
On the other hand, the `enqueue` member function queues messages together and
|
||||||
allows to maintain control over the moment they are sent to listeners. The
|
helps to maintain control over the moment they are sent to listeners:
|
||||||
signature of this method is more or less the same of `trigger`:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
dispatcher.enqueue<an_event>(42);
|
dispatcher.enqueue<an_event>(42);
|
||||||
dispatcher.enqueue<another_event>();
|
dispatcher.enqueue(another_event{});
|
||||||
```
|
```
|
||||||
|
|
||||||
Events are stored aside until the `update` member function is invoked, then all
|
Events are stored aside until the `update` member function is invoked:
|
||||||
the messages that are still pending are sent to the listeners at once:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// emits all the events of the given type at once
|
// emits all the events of the given type at once
|
||||||
@@ -456,6 +448,30 @@ dispatcher.update();
|
|||||||
This way users can embed the dispatcher in a loop and literally dispatch events
|
This way users can embed the dispatcher in a loop and literally dispatch events
|
||||||
once per tick to their systems.
|
once per tick to their systems.
|
||||||
|
|
||||||
|
## Named queues
|
||||||
|
|
||||||
|
All queues within a dispatcher are associated by default with an event type and
|
||||||
|
then retrieved from it.<br/>
|
||||||
|
However, it's possible to create queues with different _names_ (and therefore
|
||||||
|
also multiple queues for a single type). In fact, more or less all functions
|
||||||
|
also take an additional parameter. As an example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
dispatcher.sink<an_event>("custom"_hs).connect<&listener::receive>(listener);
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case, the term _name_ is misused as these are actual numeric identifiers
|
||||||
|
of type `id_type`.<br/>
|
||||||
|
An exception to this rule is the `enqueue` function. There is no additional
|
||||||
|
parameter for it but rather a different function:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
dispatcher.enqueue_hint<an_event>("custom"_hs, 42);
|
||||||
|
```
|
||||||
|
|
||||||
|
This is mainly due to the template argument deduction rules and unfortunately
|
||||||
|
there is no real (elegant) way to avoid it.
|
||||||
|
|
||||||
# Event emitter
|
# Event emitter
|
||||||
|
|
||||||
A general purpose event emitter thought mainly for those cases where it comes to
|
A general purpose event emitter thought mainly for those cases where it comes to
|
||||||
|
|||||||
3
natvis/entt/config.natvis
Normal file
3
natvis/entt/config.natvis
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
</AutoVisualizer>
|
||||||
33
natvis/entt/container.natvis
Normal file
33
natvis/entt/container.natvis
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
<Type Name="entt::dense_map<*>">
|
||||||
|
<Intrinsic Name="size" Expression="packed.first_base::value.size()"/>
|
||||||
|
<Intrinsic Name="bucket_count" Expression="sparse.first_base::value.size()"/>
|
||||||
|
<DisplayString>{{ size={ size() } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[capacity]" ExcludeView="simple">packed.first_base::value.capacity()</Item>
|
||||||
|
<Item Name="[bucket_count]" ExcludeView="simple">bucket_count()</Item>
|
||||||
|
<Item Name="[load_factor]" ExcludeView="simple">(float)size() / (float)bucket_count()</Item>
|
||||||
|
<Item Name="[max_load_factor]" ExcludeView="simple">threshold</Item>
|
||||||
|
<IndexListItems>
|
||||||
|
<Size>size()</Size>
|
||||||
|
<ValueNode>packed.first_base::value[$i].element</ValueNode>
|
||||||
|
</IndexListItems>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::dense_set<*>">
|
||||||
|
<Intrinsic Name="size" Expression="packed.first_base::value.size()"/>
|
||||||
|
<Intrinsic Name="bucket_count" Expression="sparse.first_base::value.size()"/>
|
||||||
|
<DisplayString>{{ size={ size() } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[capacity]" ExcludeView="simple">packed.first_base::value.capacity()</Item>
|
||||||
|
<Item Name="[bucket_count]" ExcludeView="simple">bucket_count()</Item>
|
||||||
|
<Item Name="[load_factor]" ExcludeView="simple">(float)size() / (float)bucket_count()</Item>
|
||||||
|
<Item Name="[max_load_factor]" ExcludeView="simple">threshold</Item>
|
||||||
|
<IndexListItems>
|
||||||
|
<Size>size()</Size>
|
||||||
|
<ValueNode>packed.first_base::value[$i].second</ValueNode>
|
||||||
|
</IndexListItems>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
</AutoVisualizer>
|
||||||
33
natvis/entt/core.natvis
Normal file
33
natvis/entt/core.natvis
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
<Type Name="entt::basic_any<*>">
|
||||||
|
<DisplayString>{{ type={ info->alias,na }, policy={ mode,en } }}</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::compressed_pair<*>">
|
||||||
|
<Intrinsic Name="first" Optional="true" Expression="((first_base*)this)->value"/>
|
||||||
|
<Intrinsic Name="first" Optional="true" Expression="*(first_base::base_type*)this"/>
|
||||||
|
<Intrinsic Name="second" Optional="true" Expression="((second_base*)this)->value"/>
|
||||||
|
<Intrinsic Name="second" Optional="true" Expression="*(second_base::base_type*)this"/>
|
||||||
|
<DisplayString >({ first() }, { second() })</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[first]">first()</Item>
|
||||||
|
<Item Name="[second]">second()</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::basic_hashed_string<*>">
|
||||||
|
<DisplayString Condition="base_type::repr != nullptr">{{ hash={ base_type::hash } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[data]">base_type::repr,na</Item>
|
||||||
|
<Item Name="[length]">base_type::length</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::type_info">
|
||||||
|
<DisplayString Condition="seq != 0u">{{ name={ alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[hash]">identifier</Item>
|
||||||
|
<Item Name="[index]">seq</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
</AutoVisualizer>
|
||||||
145
natvis/entt/entity.natvis
Normal file
145
natvis/entt/entity.natvis
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
<Type Name="entt::basic_registry<*>">
|
||||||
|
<Intrinsic Name="pools_size" Expression="pools.packed.first_base::value.size()"/>
|
||||||
|
<Intrinsic Name="vars_size" Expression="vars.data.packed.first_base::value.size()"/>
|
||||||
|
<Intrinsic Name="to_entity" Expression="*((entity_traits::entity_type *)&entity) & entity_traits::entity_mask">
|
||||||
|
<Parameter Name="entity" Type="entity_traits::value_type &"/>
|
||||||
|
</Intrinsic>
|
||||||
|
<DisplayString>{{ size={ entities.size() } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item IncludeView="simple" Name="[entities]">entities,view(simple)nr</Item>
|
||||||
|
<Synthetic Name="[entities]" ExcludeView="simple">
|
||||||
|
<DisplayString>{ entities.size() }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<CustomListItems>
|
||||||
|
<Variable Name="pos" InitialValue="0" />
|
||||||
|
<Variable Name="last" InitialValue="entities.size()"/>
|
||||||
|
<Loop>
|
||||||
|
<Break Condition="pos == last"/>
|
||||||
|
<If Condition="to_entity(entities[pos]) == pos">
|
||||||
|
<Item Name="[{ pos }]">entities[pos]</Item>
|
||||||
|
</If>
|
||||||
|
<Exec>++pos</Exec>
|
||||||
|
</Loop>
|
||||||
|
</CustomListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[destroyed]" ExcludeView="simple">
|
||||||
|
<DisplayString>{ to_entity(free_list) != entity_traits::entity_mask }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<CustomListItems>
|
||||||
|
<Variable Name="it" InitialValue="to_entity(free_list)" />
|
||||||
|
<Loop>
|
||||||
|
<Break Condition="it == entity_traits::entity_mask"/>
|
||||||
|
<Item Name="[{ it }]">entities[it]</Item>
|
||||||
|
<Exec>it = to_entity(entities[it])</Exec>
|
||||||
|
</Loop>
|
||||||
|
</CustomListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[pools]">
|
||||||
|
<DisplayString>{ pools_size() }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<IndexListItems ExcludeView="simple">
|
||||||
|
<Size>pools_size()</Size>
|
||||||
|
<ValueNode>*pools.packed.first_base::value[$i].element.second</ValueNode>
|
||||||
|
</IndexListItems>
|
||||||
|
<IndexListItems IncludeView="simple">
|
||||||
|
<Size>pools_size()</Size>
|
||||||
|
<ValueNode>*pools.packed.first_base::value[$i].element.second,view(simple)</ValueNode>
|
||||||
|
</IndexListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Item Name="[groups]" ExcludeView="simple">groups.size()</Item>
|
||||||
|
<Synthetic Name="[vars]">
|
||||||
|
<DisplayString>{ vars_size() }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<IndexListItems>
|
||||||
|
<Size>vars_size()</Size>
|
||||||
|
<ValueNode>vars.data.packed.first_base::value[$i].element.second</ValueNode>
|
||||||
|
</IndexListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::basic_sparse_set<*>">
|
||||||
|
<DisplayString>{{ size={ packed.size() }, type={ info->alias,na } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[capacity]" ExcludeView="simple">packed.capacity()</Item>
|
||||||
|
<Item Name="[policy]">mode,en</Item>
|
||||||
|
<Synthetic Name="[sparse]">
|
||||||
|
<DisplayString>{ sparse.size() * entity_traits::page_size }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem IncludeView="simple">sparse,view(simple)</ExpandedItem>
|
||||||
|
<CustomListItems ExcludeView="simple">
|
||||||
|
<Variable Name="pos" InitialValue="0"/>
|
||||||
|
<Variable Name="page" InitialValue="0"/>
|
||||||
|
<Variable Name="offset" InitialValue="0"/>
|
||||||
|
<Variable Name="last" InitialValue="sparse.size() * entity_traits::page_size"/>
|
||||||
|
<Loop>
|
||||||
|
<Break Condition="pos == last"/>
|
||||||
|
<Exec>page = pos / entity_traits::page_size</Exec>
|
||||||
|
<Exec>offset = pos & (entity_traits::page_size - 1)</Exec>
|
||||||
|
<If Condition="sparse[page] && (*((entity_traits::entity_type *)&sparse[page][offset]) < ~entity_traits::entity_mask)">
|
||||||
|
<Item Name="[{ pos }]">*((entity_traits::entity_type *)&sparse[page][offset]) & entity_traits::entity_mask</Item>
|
||||||
|
</If>
|
||||||
|
<Exec>++pos</Exec>
|
||||||
|
</Loop>
|
||||||
|
</CustomListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[packed]">
|
||||||
|
<DisplayString>{ packed.size() }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem IncludeView="simple">packed,view(simple)</ExpandedItem>
|
||||||
|
<CustomListItems ExcludeView="simple">
|
||||||
|
<Variable Name="pos" InitialValue="0"/>
|
||||||
|
<Variable Name="last" InitialValue="packed.size()"/>
|
||||||
|
<Loop>
|
||||||
|
<Break Condition="pos == last"/>
|
||||||
|
<If Condition="*((entity_traits::entity_type *)&packed[pos]) < ~entity_traits::entity_mask">
|
||||||
|
<Item Name="[{ pos }]">packed[pos]</Item>
|
||||||
|
</If>
|
||||||
|
<Exec>++pos</Exec>
|
||||||
|
</Loop>
|
||||||
|
</CustomListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::basic_storage<*>">
|
||||||
|
<DisplayString>{{ size={ base_type::packed.size() }, type={ base_type::info->alias,na } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[capacity]" Optional="true" ExcludeView="simple">packed.first_base::value.capacity() * comp_traits::page_size</Item>
|
||||||
|
<Item Name="[page size]" Optional="true" ExcludeView="simple">comp_traits::page_size</Item>
|
||||||
|
<Item Name="[base]" ExcludeView="simple">(base_type*)this,nand</Item>
|
||||||
|
<Item Name="[base]" IncludeView="simple">(base_type*)this,view(simple)nand</Item>
|
||||||
|
<!-- having SFINAE-like techniques in natvis is priceless :) -->
|
||||||
|
<CustomListItems Condition="packed.first_base::value.size() != 0" Optional="true">
|
||||||
|
<Variable Name="pos" InitialValue="0" />
|
||||||
|
<Variable Name="last" InitialValue="base_type::packed.size()"/>
|
||||||
|
<Loop>
|
||||||
|
<Break Condition="pos == last"/>
|
||||||
|
<If Condition="*((base_type::entity_traits::entity_type *)&base_type::packed[pos]) < ~base_type::entity_traits::entity_mask">
|
||||||
|
<Item Name="[{ pos }]">packed.first_base::value[pos / comp_traits::page_size][pos & (comp_traits::page_size - 1)]</Item>
|
||||||
|
</If>
|
||||||
|
<Exec>++pos</Exec>
|
||||||
|
</Loop>
|
||||||
|
</CustomListItems>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::basic_view<*>">
|
||||||
|
<DisplayString>{{ size_hint={ view->packed.size() } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[pools]">pools,na</Item>
|
||||||
|
<Item Name="[filter]">filter,na</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::null_t">
|
||||||
|
<DisplayString><null></DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::tombstone_t">
|
||||||
|
<DisplayString><tombstone></DisplayString>
|
||||||
|
</Type>
|
||||||
|
</AutoVisualizer>
|
||||||
3
natvis/entt/locator.natvis
Normal file
3
natvis/entt/locator.natvis
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
</AutoVisualizer>
|
||||||
197
natvis/entt/meta.natvis
Normal file
197
natvis/entt/meta.natvis
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
<Type Name="entt::meta_any">
|
||||||
|
<DisplayString Condition="node != nullptr">{{ type={ node->info->alias,na }, policy={ storage.mode,en } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem Condition="node != nullptr">*node</ExpandedItem>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::meta_associative_container">
|
||||||
|
<DisplayString Condition="mapped_type_node != nullptr">{{ key_type={ key_type_node->info->alias,na }, mapped_type={ mapped_type_node->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString Condition="key_type_node != nullptr">{{ key_type={ key_type_node->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_base_node">
|
||||||
|
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_conv_node">
|
||||||
|
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_ctor_node">
|
||||||
|
<DisplayString Condition="arg != nullptr">{{ arity={ arity } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_data_node">
|
||||||
|
<Intrinsic Name="has_property" Expression="!!(traits & property)">
|
||||||
|
<Parameter Name="property" Type="int"/>
|
||||||
|
</Intrinsic>
|
||||||
|
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[id]">id</Item>
|
||||||
|
<Item Name="[arity]">arity</Item>
|
||||||
|
<Item Name="[is_const]">has_property(entt::internal::meta_traits::is_const)</Item>
|
||||||
|
<Item Name="[is_static]">has_property(entt::internal::meta_traits::is_static)</Item>
|
||||||
|
<Synthetic Name="[prop]" Condition="prop != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>prop</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::meta_data">
|
||||||
|
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_func_node" >
|
||||||
|
<Intrinsic Name="has_property" Expression="!!(traits & property)">
|
||||||
|
<Parameter Name="property" Type="int"/>
|
||||||
|
</Intrinsic>
|
||||||
|
<DisplayString Condition="ret != nullptr">{{ arity={ arity }, ret={ ret->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[id]">id</Item>
|
||||||
|
<Item Name="[is_const]">has_property(entt::internal::meta_traits::is_const)</Item>
|
||||||
|
<Item Name="[is_static]">has_property(entt::internal::meta_traits::is_static)</Item>
|
||||||
|
<Synthetic Name="[prop]" Condition="prop != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>prop</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::meta_func">
|
||||||
|
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::meta_handle">
|
||||||
|
<DisplayString>{ any }</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_prop_node">
|
||||||
|
<DisplayString Condition="value.node != nullptr">{{ key_type={ id.node->info->alias,na }, mapped_type={ value.node->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString Condition="id.node != nullptr">{{ key_type={ id.node->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[key]">id</Item>
|
||||||
|
<Item Name="[value]">value</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::meta_prop">
|
||||||
|
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::meta_sequence_container">
|
||||||
|
<DisplayString Condition="value_type_node != nullptr">{{ value_type={ value_type_node->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_template_node">
|
||||||
|
<DisplayString Condition="type != nullptr">{{ type={ type->info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[arity]">arity</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::meta_type_node">
|
||||||
|
<Intrinsic Name="has_property" Expression="!!(traits & property)">
|
||||||
|
<Parameter Name="property" Type="int"/>
|
||||||
|
</Intrinsic>
|
||||||
|
<DisplayString Condition="info != nullptr">{{ type={ info->alias,na } }}</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[id]">id</Item>
|
||||||
|
<Item Name="[sizeof]">size_of</Item>
|
||||||
|
<Item Name="[is_arithmetic]">has_property(entt::internal::meta_traits::is_arithmetic)</Item>
|
||||||
|
<Item Name="[is_array]">has_property(entt::internal::meta_traits::is_array)</Item>
|
||||||
|
<Item Name="[is_enum]">has_property(entt::internal::meta_traits::is_enum)</Item>
|
||||||
|
<Item Name="[is_class]">has_property(entt::internal::meta_traits::is_class)</Item>
|
||||||
|
<Item Name="[is_pointer]">has_property(entt::internal::meta_traits::is_pointer)</Item>
|
||||||
|
<Item Name="[is_meta_pointer_like]">has_property(entt::internal::meta_traits::is_meta_pointer_like)</Item>
|
||||||
|
<Item Name="[is_meta_sequence_container]">has_property(entt::internal::meta_traits::is_meta_sequence_container)</Item>
|
||||||
|
<Item Name="[is_meta_associative_container]">has_property(entt::internal::meta_traits::is_meta_associative_container)</Item>
|
||||||
|
<Item Name="[default_constructor]">default_constructor != nullptr</Item>
|
||||||
|
<Item Name="[conversion_helper]">conversion_helper != nullptr</Item>
|
||||||
|
<Item Name="[template_info]" Condition="templ != nullptr">*templ</Item>
|
||||||
|
<Synthetic Name="[ctor]" Condition="ctor != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>ctor</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[base]" Condition="base != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>base</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[conv]" Condition="conv != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>conv</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[data]" Condition="data != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>data</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[func]" Condition="func != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>func</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
<Synthetic Name="[prop]" Condition="prop != nullptr">
|
||||||
|
<Expand>
|
||||||
|
<LinkedListItems>
|
||||||
|
<HeadPointer>prop</HeadPointer>
|
||||||
|
<NextPointer>next</NextPointer>
|
||||||
|
<ValueNode>*this</ValueNode>
|
||||||
|
</LinkedListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::meta_type">
|
||||||
|
<DisplayString Condition="node != nullptr">{ *node }</DisplayString>
|
||||||
|
<DisplayString>{{}}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem Condition="node != nullptr">node</ExpandedItem>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
</AutoVisualizer>
|
||||||
3
natvis/entt/platform.natvis
Normal file
3
natvis/entt/platform.natvis
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
</AutoVisualizer>
|
||||||
6
natvis/entt/poly.natvis
Normal file
6
natvis/entt/poly.natvis
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
<Type Name="entt::basic_poly<*>">
|
||||||
|
<DisplayString>{ storage }</DisplayString>
|
||||||
|
</Type>
|
||||||
|
</AutoVisualizer>
|
||||||
3
natvis/entt/process.natvis
Normal file
3
natvis/entt/process.natvis
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
</AutoVisualizer>
|
||||||
15
natvis/entt/resource.natvis
Normal file
15
natvis/entt/resource.natvis
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
<Type Name="entt::resource<*>">
|
||||||
|
<DisplayString>{ value }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem>value</ExpandedItem>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::resource_cache<*>">
|
||||||
|
<DisplayString>{ pool.first_base::value }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<ExpandedItem>pool.first_base::value</ExpandedItem>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
</AutoVisualizer>
|
||||||
52
natvis/entt/signal.natvis
Normal file
52
natvis/entt/signal.natvis
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||||
|
<Type Name="entt::connection">
|
||||||
|
<DisplayString>{{ bound={ signal != nullptr } }}</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::delegate<*>">
|
||||||
|
<DisplayString>{{ type={ "$T1" } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[empty]">fn == nullptr</Item>
|
||||||
|
<Item Name="[data]">instance</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::dispatcher">
|
||||||
|
<DisplayString>{{ size={ pools.size() } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Synthetic Name="[pools]">
|
||||||
|
<DisplayString>{ pools.size() }</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<IndexListItems>
|
||||||
|
<Size>pools.size()</Size>
|
||||||
|
<ValueNode>*pools.packed.first_base::value[$i].element.second</ValueNode>
|
||||||
|
</IndexListItems>
|
||||||
|
</Expand>
|
||||||
|
</Synthetic>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::internal::dispatcher_handler<*>">
|
||||||
|
<DisplayString>{{ size={ events.size() }, event={ "$T1" } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[signal]">signal</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::scoped_connection">
|
||||||
|
<DisplayString>{ conn }</DisplayString>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::sigh<*>">
|
||||||
|
<DisplayString>{{ size={ calls.size() }, type={ "$T1" } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<IndexListItems>
|
||||||
|
<Size>calls.size()</Size>
|
||||||
|
<ValueNode>calls[$i]</ValueNode>
|
||||||
|
</IndexListItems>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
<Type Name="entt::sink<*>">
|
||||||
|
<DisplayString>{{ type={ "$T1" } }}</DisplayString>
|
||||||
|
<Expand>
|
||||||
|
<Item Name="[signal]">signal,na</Item>
|
||||||
|
<Item Name="[offset]">offset</Item>
|
||||||
|
</Expand>
|
||||||
|
</Type>
|
||||||
|
</AutoVisualizer>
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,85 +1,79 @@
|
|||||||
#ifndef ENTT_CONFIG_CONFIG_H
|
#ifndef ENTT_CONFIG_CONFIG_H
|
||||||
#define ENTT_CONFIG_CONFIG_H
|
#define ENTT_CONFIG_CONFIG_H
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
#if defined(__cpp_exceptions) && !defined(ENTT_NOEXCEPTION)
|
#if defined(__cpp_exceptions) && !defined(ENTT_NOEXCEPTION)
|
||||||
# define ENTT_NOEXCEPT noexcept
|
# define ENTT_THROW throw
|
||||||
# define ENTT_THROW throw
|
# define ENTT_TRY try
|
||||||
# define ENTT_TRY try
|
# define ENTT_CATCH catch(...)
|
||||||
# define ENTT_CATCH catch(...)
|
|
||||||
#else
|
#else
|
||||||
# define ENTT_NOEXCEPT
|
# define ENTT_THROW
|
||||||
# define ENTT_THROW
|
# define ENTT_TRY if(true)
|
||||||
# define ENTT_TRY if(true)
|
# define ENTT_CATCH if(false)
|
||||||
# define ENTT_CATCH if(false)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ENTT_NOEXCEPT
|
||||||
#if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606L
|
# define ENTT_NOEXCEPT noexcept
|
||||||
# include <new>
|
# define ENTT_NOEXCEPT_IF(expr) noexcept(expr)
|
||||||
# define ENTT_LAUNDER(expr) std::launder(expr)
|
# else
|
||||||
#else
|
# define ENTT_NOEXCEPT_IF(...)
|
||||||
# define ENTT_LAUNDER(expr) expr
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENTT_USE_ATOMIC
|
||||||
#ifndef ENTT_USE_ATOMIC
|
# include <atomic>
|
||||||
# define ENTT_MAYBE_ATOMIC(Type) Type
|
# define ENTT_MAYBE_ATOMIC(Type) std::atomic<Type>
|
||||||
#else
|
#else
|
||||||
# include <atomic>
|
# define ENTT_MAYBE_ATOMIC(Type) Type
|
||||||
# define ENTT_MAYBE_ATOMIC(Type) std::atomic<Type>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef ENTT_ID_TYPE
|
#ifndef ENTT_ID_TYPE
|
||||||
# include <cstdint>
|
# include <cstdint>
|
||||||
# define ENTT_ID_TYPE std::uint32_t
|
# define ENTT_ID_TYPE std::uint32_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ENTT_SPARSE_PAGE
|
||||||
#ifdef ENTT_SPARSE_PAGE
|
# define ENTT_SPARSE_PAGE 4096
|
||||||
static_assert(ENTT_SPARSE_PAGE && ((ENTT_SPARSE_PAGE & (ENTT_SPARSE_PAGE - 1)) == 0), "ENTT_SPARSE_PAGE must be a power of two");
|
|
||||||
#else
|
|
||||||
# define ENTT_SPARSE_PAGE 4096
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ENTT_PACKED_PAGE
|
||||||
#ifdef ENTT_PACKED_PAGE
|
# define ENTT_PACKED_PAGE 1024
|
||||||
static_assert(ENTT_PACKED_PAGE && ((ENTT_PACKED_PAGE & (ENTT_PACKED_PAGE - 1)) == 0), "ENTT_PACKED_PAGE must be a power of two");
|
|
||||||
#else
|
|
||||||
# define ENTT_PACKED_PAGE 1024
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENTT_DISABLE_ASSERT
|
#ifdef ENTT_DISABLE_ASSERT
|
||||||
# undef ENTT_ASSERT
|
# undef ENTT_ASSERT
|
||||||
# define ENTT_ASSERT(...) (void(0))
|
# define ENTT_ASSERT(...) (void(0))
|
||||||
#elif !defined ENTT_ASSERT
|
#elif !defined ENTT_ASSERT
|
||||||
# include <cassert>
|
# include <cassert>
|
||||||
# define ENTT_ASSERT(condition, ...) assert(condition)
|
# define ENTT_ASSERT(condition, ...) assert(condition)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENTT_NO_ETO
|
#ifdef ENTT_NO_ETO
|
||||||
# include <type_traits>
|
# define ENTT_IGNORE_IF_EMPTY false
|
||||||
# define ENTT_IGNORE_IF_EMPTY std::false_type
|
|
||||||
#else
|
#else
|
||||||
# include <type_traits>
|
# define ENTT_IGNORE_IF_EMPTY true
|
||||||
# define ENTT_IGNORE_IF_EMPTY std::true_type
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENTT_STANDARD_CPP
|
||||||
#ifndef ENTT_STANDARD_CPP
|
# define ENTT_NONSTD false
|
||||||
|
#else
|
||||||
|
# define ENTT_NONSTD true
|
||||||
# if defined __clang__ || defined __GNUC__
|
# if defined __clang__ || defined __GNUC__
|
||||||
# define ENTT_PRETTY_FUNCTION __PRETTY_FUNCTION__
|
# define ENTT_PRETTY_FUNCTION __PRETTY_FUNCTION__
|
||||||
# define ENTT_PRETTY_FUNCTION_PREFIX '='
|
# define ENTT_PRETTY_FUNCTION_PREFIX '='
|
||||||
# define ENTT_PRETTY_FUNCTION_SUFFIX ']'
|
# define ENTT_PRETTY_FUNCTION_SUFFIX ']'
|
||||||
# elif defined _MSC_VER
|
# elif defined _MSC_VER
|
||||||
# define ENTT_PRETTY_FUNCTION __FUNCSIG__
|
# define ENTT_PRETTY_FUNCTION __FUNCSIG__
|
||||||
# define ENTT_PRETTY_FUNCTION_PREFIX '<'
|
# define ENTT_PRETTY_FUNCTION_PREFIX '<'
|
||||||
# define ENTT_PRETTY_FUNCTION_SUFFIX '>'
|
# define ENTT_PRETTY_FUNCTION_SUFFIX '>'
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined _MSC_VER
|
||||||
|
# pragma detect_mismatch("entt.version", ENTT_VERSION)
|
||||||
|
# pragma detect_mismatch("entt.noexcept", ENTT_XSTR(ENTT_TRY))
|
||||||
|
# pragma detect_mismatch("entt.id", ENTT_XSTR(ENTT_ID_TYPE))
|
||||||
|
# pragma detect_mismatch("entt.nonstd", ENTT_XSTR(ENTT_NONSTD))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
7
src/entt/config/macro.h
Normal file
7
src/entt/config/macro.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef ENTT_CONFIG_MACRO_H
|
||||||
|
#define ENTT_CONFIG_MACRO_H
|
||||||
|
|
||||||
|
#define ENTT_STR(arg) #arg
|
||||||
|
#define ENTT_XSTR(arg) ENTT_STR(arg)
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
#ifndef ENTT_CONFIG_VERSION_H
|
#ifndef ENTT_CONFIG_VERSION_H
|
||||||
#define ENTT_CONFIG_VERSION_H
|
#define ENTT_CONFIG_VERSION_H
|
||||||
|
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
#define ENTT_VERSION_MAJOR 3
|
#define ENTT_VERSION_MAJOR 3
|
||||||
#define ENTT_VERSION_MINOR 8
|
#define ENTT_VERSION_MINOR 10
|
||||||
#define ENTT_VERSION_PATCH 0
|
#define ENTT_VERSION_PATCH 1
|
||||||
|
|
||||||
|
#define ENTT_VERSION \
|
||||||
|
ENTT_XSTR(ENTT_VERSION_MAJOR) \
|
||||||
|
"." ENTT_XSTR(ENTT_VERSION_MINOR) "." ENTT_XSTR(ENTT_VERSION_PATCH)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
988
src/entt/container/dense_map.hpp
Normal file
988
src/entt/container/dense_map.hpp
Normal file
@@ -0,0 +1,988 @@
|
|||||||
|
#ifndef ENTT_CONTAINER_DENSE_MAP_HPP
|
||||||
|
#define ENTT_CONTAINER_DENSE_MAP_HPP
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <functional>
|
||||||
|
#include <iterator>
|
||||||
|
#include <limits>
|
||||||
|
#include <memory>
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
#include "../config/config.h"
|
||||||
|
#include "../core/compressed_pair.hpp"
|
||||||
|
#include "../core/iterator.hpp"
|
||||||
|
#include "../core/memory.hpp"
|
||||||
|
#include "../core/type_traits.hpp"
|
||||||
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename Key, typename Type>
|
||||||
|
struct dense_map_node final {
|
||||||
|
using value_type = std::pair<Key, Type>;
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
dense_map_node(const std::size_t pos, Args &&...args)
|
||||||
|
: next{pos},
|
||||||
|
element{std::forward<Args>(args)...} {}
|
||||||
|
|
||||||
|
template<typename Allocator, typename... Args>
|
||||||
|
dense_map_node(std::allocator_arg_t, const Allocator &allocator, const std::size_t pos, Args &&...args)
|
||||||
|
: next{pos},
|
||||||
|
element{entt::make_obj_using_allocator<value_type>(allocator, std::forward<Args>(args)...)} {}
|
||||||
|
|
||||||
|
template<typename Allocator>
|
||||||
|
dense_map_node(std::allocator_arg_t, const Allocator &allocator, const dense_map_node &other)
|
||||||
|
: next{other.next},
|
||||||
|
element{entt::make_obj_using_allocator<value_type>(allocator, other.element)} {}
|
||||||
|
|
||||||
|
template<typename Allocator>
|
||||||
|
dense_map_node(std::allocator_arg_t, const Allocator &allocator, dense_map_node &&other)
|
||||||
|
: next{other.next},
|
||||||
|
element{entt::make_obj_using_allocator<value_type>(allocator, std::move(other.element))} {}
|
||||||
|
|
||||||
|
std::size_t next;
|
||||||
|
value_type element;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename It>
|
||||||
|
class dense_map_iterator final {
|
||||||
|
template<typename>
|
||||||
|
friend class dense_map_iterator;
|
||||||
|
|
||||||
|
using first_type = decltype(std::as_const(std::declval<It>()->element.first));
|
||||||
|
using second_type = decltype((std::declval<It>()->element.second));
|
||||||
|
|
||||||
|
public:
|
||||||
|
using value_type = std::pair<first_type, second_type>;
|
||||||
|
using pointer = input_iterator_pointer<value_type>;
|
||||||
|
using reference = value_type;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
|
||||||
|
dense_map_iterator() ENTT_NOEXCEPT
|
||||||
|
: it{} {}
|
||||||
|
|
||||||
|
dense_map_iterator(const It iter) ENTT_NOEXCEPT
|
||||||
|
: it{iter} {}
|
||||||
|
|
||||||
|
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
|
||||||
|
dense_map_iterator(const dense_map_iterator<Other> &other) ENTT_NOEXCEPT
|
||||||
|
: it{other.it} {}
|
||||||
|
|
||||||
|
dense_map_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
|
return ++it, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
|
dense_map_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_iterator &operator--() ENTT_NOEXCEPT {
|
||||||
|
return --it, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_iterator operator--(int) ENTT_NOEXCEPT {
|
||||||
|
dense_map_iterator orig = *this;
|
||||||
|
return operator--(), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
|
||||||
|
it += value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
dense_map_iterator copy = *this;
|
||||||
|
return (copy += value);
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
|
||||||
|
return (*this += -value);
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
return (*this + -value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator[](const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
return {it[value].element.first, it[value].element.second};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
|
return operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
|
return {it->element.first, it->element.second};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
friend std::ptrdiff_t operator-(const dense_map_iterator<ILhs> &, const dense_map_iterator<IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
friend bool operator==(const dense_map_iterator<ILhs> &, const dense_map_iterator<IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
friend bool operator<(const dense_map_iterator<ILhs> &, const dense_map_iterator<IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
private:
|
||||||
|
It it;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] std::ptrdiff_t operator-(const dense_map_iterator<ILhs> &lhs, const dense_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it - rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator==(const dense_map_iterator<ILhs> &lhs, const dense_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it == rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator!=(const dense_map_iterator<ILhs> &lhs, const dense_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator<(const dense_map_iterator<ILhs> &lhs, const dense_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it < rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator>(const dense_map_iterator<ILhs> &lhs, const dense_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return rhs < lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator<=(const dense_map_iterator<ILhs> &lhs, const dense_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs > rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator>=(const dense_map_iterator<ILhs> &lhs, const dense_map_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs < rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename It>
|
||||||
|
class dense_map_local_iterator final {
|
||||||
|
template<typename>
|
||||||
|
friend class dense_map_local_iterator;
|
||||||
|
|
||||||
|
using first_type = decltype(std::as_const(std::declval<It>()->element.first));
|
||||||
|
using second_type = decltype((std::declval<It>()->element.second));
|
||||||
|
|
||||||
|
public:
|
||||||
|
using value_type = std::pair<first_type, second_type>;
|
||||||
|
using pointer = input_iterator_pointer<value_type>;
|
||||||
|
using reference = value_type;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
|
||||||
|
dense_map_local_iterator() ENTT_NOEXCEPT
|
||||||
|
: it{},
|
||||||
|
offset{} {}
|
||||||
|
|
||||||
|
dense_map_local_iterator(It iter, const std::size_t pos) ENTT_NOEXCEPT
|
||||||
|
: it{iter},
|
||||||
|
offset{pos} {}
|
||||||
|
|
||||||
|
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
|
||||||
|
dense_map_local_iterator(const dense_map_local_iterator<Other> &other) ENTT_NOEXCEPT
|
||||||
|
: it{other.it},
|
||||||
|
offset{other.offset} {}
|
||||||
|
|
||||||
|
dense_map_local_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
|
return offset = it[offset].next, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_map_local_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
|
dense_map_local_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
|
return operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
|
return {it[offset].element.first, it[offset].element.second};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::size_t index() const ENTT_NOEXCEPT {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
It it;
|
||||||
|
std::size_t offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator==(const dense_map_local_iterator<ILhs> &lhs, const dense_map_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.index() == rhs.index();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator!=(const dense_map_local_iterator<ILhs> &lhs, const dense_map_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Associative container for key-value pairs with unique keys.
|
||||||
|
*
|
||||||
|
* Internally, elements are organized into buckets. Which bucket an element is
|
||||||
|
* placed into depends entirely on the hash of its key. Keys with the same hash
|
||||||
|
* code appear in the same bucket.
|
||||||
|
*
|
||||||
|
* @tparam Key Key type of the associative container.
|
||||||
|
* @tparam Type Mapped type of the associative container.
|
||||||
|
* @tparam Hash Type of function to use to hash the keys.
|
||||||
|
* @tparam KeyEqual Type of function to use to compare the keys for equality.
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
*/
|
||||||
|
template<typename Key, typename Type, typename Hash, typename KeyEqual, typename Allocator>
|
||||||
|
class dense_map {
|
||||||
|
static constexpr float default_threshold = 0.875f;
|
||||||
|
static constexpr std::size_t minimum_capacity = 8u;
|
||||||
|
|
||||||
|
using node_type = internal::dense_map_node<Key, Type>;
|
||||||
|
using alloc_traits = typename std::allocator_traits<Allocator>;
|
||||||
|
static_assert(std::is_same_v<typename alloc_traits::value_type, std::pair<const Key, Type>>, "Invalid value type");
|
||||||
|
using sparse_container_type = std::vector<std::size_t, typename alloc_traits::template rebind_alloc<std::size_t>>;
|
||||||
|
using packed_container_type = std::vector<node_type, typename alloc_traits::template rebind_alloc<node_type>>;
|
||||||
|
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::size_t key_to_bucket(const Other &key) const ENTT_NOEXCEPT {
|
||||||
|
return fast_mod(sparse.second()(key), bucket_count());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] auto constrained_find(const Other &key, std::size_t bucket) {
|
||||||
|
for(auto it = begin(bucket), last = end(bucket); it != last; ++it) {
|
||||||
|
if(packed.second()(it->first, key)) {
|
||||||
|
return begin() + static_cast<typename iterator::difference_type>(it.index());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] auto constrained_find(const Other &key, std::size_t bucket) const {
|
||||||
|
for(auto it = cbegin(bucket), last = cend(bucket); it != last; ++it) {
|
||||||
|
if(packed.second()(it->first, key)) {
|
||||||
|
return cbegin() + static_cast<typename iterator::difference_type>(it.index());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Other, typename... Args>
|
||||||
|
[[nodiscard]] auto insert_or_do_nothing(Other &&key, Args &&...args) {
|
||||||
|
const auto index = key_to_bucket(key);
|
||||||
|
|
||||||
|
if(auto it = constrained_find(key, index); it != end()) {
|
||||||
|
return std::make_pair(it, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
packed.first().emplace_back(sparse.first()[index], std::piecewise_construct, std::forward_as_tuple(std::forward<Other>(key)), std::forward_as_tuple(std::forward<Args>(args)...));
|
||||||
|
sparse.first()[index] = packed.first().size() - 1u;
|
||||||
|
rehash_if_required();
|
||||||
|
|
||||||
|
return std::make_pair(--end(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Other, typename Arg>
|
||||||
|
[[nodiscard]] auto insert_or_overwrite(Other &&key, Arg &&value) {
|
||||||
|
const auto index = key_to_bucket(key);
|
||||||
|
|
||||||
|
if(auto it = constrained_find(key, index); it != end()) {
|
||||||
|
it->second = std::forward<Arg>(value);
|
||||||
|
return std::make_pair(it, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
packed.first().emplace_back(sparse.first()[index], std::forward<Other>(key), std::forward<Arg>(value));
|
||||||
|
sparse.first()[index] = packed.first().size() - 1u;
|
||||||
|
rehash_if_required();
|
||||||
|
|
||||||
|
return std::make_pair(--end(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_and_pop(const std::size_t pos) {
|
||||||
|
if(const auto last = size() - 1u; pos != last) {
|
||||||
|
packed.first()[pos] = std::move(packed.first().back());
|
||||||
|
size_type *curr = sparse.first().data() + key_to_bucket(packed.first().back().element.first);
|
||||||
|
for(; *curr != last; curr = &packed.first()[*curr].next) {}
|
||||||
|
*curr = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
packed.first().pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void rehash_if_required() {
|
||||||
|
if(size() > (bucket_count() * max_load_factor())) {
|
||||||
|
rehash(bucket_count() * 2u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*! @brief Key type of the container. */
|
||||||
|
using key_type = Key;
|
||||||
|
/*! @brief Mapped type of the container. */
|
||||||
|
using mapped_type = Type;
|
||||||
|
/*! @brief Key-value type of the container. */
|
||||||
|
using value_type = std::pair<const Key, Type>;
|
||||||
|
/*! @brief Unsigned integer type. */
|
||||||
|
using size_type = std::size_t;
|
||||||
|
/*! @brief Type of function to use to hash the keys. */
|
||||||
|
using hasher = Hash;
|
||||||
|
/*! @brief Type of function to use to compare the keys for equality. */
|
||||||
|
using key_equal = KeyEqual;
|
||||||
|
/*! @brief Allocator type. */
|
||||||
|
using allocator_type = Allocator;
|
||||||
|
/*! @brief Input iterator type. */
|
||||||
|
using iterator = internal::dense_map_iterator<typename packed_container_type::iterator>;
|
||||||
|
/*! @brief Constant input iterator type. */
|
||||||
|
using const_iterator = internal::dense_map_iterator<typename packed_container_type::const_iterator>;
|
||||||
|
/*! @brief Input iterator type. */
|
||||||
|
using local_iterator = internal::dense_map_local_iterator<typename packed_container_type::iterator>;
|
||||||
|
/*! @brief Constant input iterator type. */
|
||||||
|
using const_local_iterator = internal::dense_map_local_iterator<typename packed_container_type::const_iterator>;
|
||||||
|
|
||||||
|
/*! @brief Default constructor. */
|
||||||
|
dense_map()
|
||||||
|
: dense_map(minimum_capacity) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
explicit dense_map(const allocator_type &allocator)
|
||||||
|
: dense_map{minimum_capacity, hasher{}, key_equal{}, allocator} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator and user
|
||||||
|
* supplied minimal number of buckets.
|
||||||
|
* @param bucket_count Minimal number of buckets.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_map(const size_type bucket_count, const allocator_type &allocator)
|
||||||
|
: dense_map{bucket_count, hasher{}, key_equal{}, allocator} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator, hash
|
||||||
|
* function and user supplied minimal number of buckets.
|
||||||
|
* @param bucket_count Minimal number of buckets.
|
||||||
|
* @param hash Hash function to use.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_map(const size_type bucket_count, const hasher &hash, const allocator_type &allocator)
|
||||||
|
: dense_map{bucket_count, hash, key_equal{}, allocator} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator, hash
|
||||||
|
* function, compare function and user supplied minimal number of buckets.
|
||||||
|
* @param bucket_count Minimal number of buckets.
|
||||||
|
* @param hash Hash function to use.
|
||||||
|
* @param equal Compare function to use.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
explicit dense_map(const size_type bucket_count, const hasher &hash = hasher{}, const key_equal &equal = key_equal{}, const allocator_type &allocator = allocator_type{})
|
||||||
|
: sparse{allocator, hash},
|
||||||
|
packed{allocator, equal},
|
||||||
|
threshold{default_threshold} {
|
||||||
|
rehash(bucket_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @brief Default copy constructor. */
|
||||||
|
dense_map(const dense_map &) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocator-extended copy constructor.
|
||||||
|
* @param other The instance to copy from.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_map(const dense_map &other, const allocator_type &allocator)
|
||||||
|
: sparse{std::piecewise_construct, std::forward_as_tuple(other.sparse.first(), allocator), std::forward_as_tuple(other.sparse.second())},
|
||||||
|
packed{std::piecewise_construct, std::forward_as_tuple(other.packed.first(), allocator), std::forward_as_tuple(other.packed.second())},
|
||||||
|
threshold{other.threshold} {}
|
||||||
|
|
||||||
|
/*! @brief Default move constructor. */
|
||||||
|
dense_map(dense_map &&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocator-extended move constructor.
|
||||||
|
* @param other The instance to move from.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_map(dense_map &&other, const allocator_type &allocator)
|
||||||
|
: sparse{std::piecewise_construct, std::forward_as_tuple(std::move(other.sparse.first()), allocator), std::forward_as_tuple(std::move(other.sparse.second()))},
|
||||||
|
packed{std::piecewise_construct, std::forward_as_tuple(std::move(other.packed.first()), allocator), std::forward_as_tuple(std::move(other.packed.second()))},
|
||||||
|
threshold{other.threshold} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default copy assignment operator.
|
||||||
|
* @return This container.
|
||||||
|
*/
|
||||||
|
dense_map &operator=(const dense_map &) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default move assignment operator.
|
||||||
|
* @return This container.
|
||||||
|
*/
|
||||||
|
dense_map &operator=(dense_map &&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the associated allocator.
|
||||||
|
* @return The associated allocator.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
|
||||||
|
return sparse.first().get_allocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning.
|
||||||
|
*
|
||||||
|
* The returned iterator points to the first instance of the internal array.
|
||||||
|
* If the array is empty, the returned iterator will be equal to `end()`.
|
||||||
|
*
|
||||||
|
* @return An iterator to the first instance of the internal array.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cbegin */
|
||||||
|
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
|
||||||
|
return cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc begin */
|
||||||
|
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
|
||||||
|
return packed.first().begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end.
|
||||||
|
*
|
||||||
|
* The returned iterator points to the element following the last instance
|
||||||
|
* of the internal array. Attempting to dereference the returned iterator
|
||||||
|
* results in undefined behavior.
|
||||||
|
*
|
||||||
|
* @return An iterator to the element following the last instance of the
|
||||||
|
* internal array.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cend */
|
||||||
|
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
|
||||||
|
return cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc end */
|
||||||
|
[[nodiscard]] iterator end() ENTT_NOEXCEPT {
|
||||||
|
return packed.first().end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks whether a container is empty.
|
||||||
|
* @return True if the container is empty, false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of elements in a container.
|
||||||
|
* @return Number of elements in a container.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @brief Clears the container. */
|
||||||
|
void clear() ENTT_NOEXCEPT {
|
||||||
|
sparse.first().clear();
|
||||||
|
packed.first().clear();
|
||||||
|
rehash(0u);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts an element into the container, if the key does not exist.
|
||||||
|
* @param value A key-value pair eventually convertible to the value type.
|
||||||
|
* @return A pair consisting of an iterator to the inserted element (or to
|
||||||
|
* the element that prevented the insertion) and a bool denoting whether the
|
||||||
|
* insertion took place.
|
||||||
|
*/
|
||||||
|
std::pair<iterator, bool> insert(const value_type &value) {
|
||||||
|
return insert_or_do_nothing(value.first, value.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc insert */
|
||||||
|
std::pair<iterator, bool> insert(value_type &&value) {
|
||||||
|
return insert_or_do_nothing(std::move(value.first), std::move(value.second));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copydoc insert
|
||||||
|
* @tparam Arg Type of the key-value pair to insert into the container.
|
||||||
|
*/
|
||||||
|
template<typename Arg>
|
||||||
|
std::enable_if_t<std::is_constructible_v<value_type, Arg &&>, std::pair<iterator, bool>>
|
||||||
|
insert(Arg &&value) {
|
||||||
|
return insert_or_do_nothing(std::forward<Arg>(value).first, std::forward<Arg>(value).second);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts elements into the container, if their keys do not exist.
|
||||||
|
* @tparam It Type of input iterator.
|
||||||
|
* @param first An iterator to the first element of the range of elements.
|
||||||
|
* @param last An iterator past the last element of the range of elements.
|
||||||
|
*/
|
||||||
|
template<typename It>
|
||||||
|
void insert(It first, It last) {
|
||||||
|
for(; first != last; ++first) {
|
||||||
|
insert(*first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts an element into the container or assigns to the current
|
||||||
|
* element if the key already exists.
|
||||||
|
* @tparam Arg Type of the value to insert or assign.
|
||||||
|
* @param key A key used both to look up and to insert if not found.
|
||||||
|
* @param value A value to insert or assign.
|
||||||
|
* @return A pair consisting of an iterator to the element and a bool
|
||||||
|
* denoting whether the insertion took place.
|
||||||
|
*/
|
||||||
|
template<typename Arg>
|
||||||
|
std::pair<iterator, bool> insert_or_assign(const key_type &key, Arg &&value) {
|
||||||
|
return insert_or_overwrite(key, std::forward<Arg>(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc insert_or_assign */
|
||||||
|
template<typename Arg>
|
||||||
|
std::pair<iterator, bool> insert_or_assign(key_type &&key, Arg &&value) {
|
||||||
|
return insert_or_overwrite(std::move(key), std::forward<Arg>(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an element in-place, if the key does not exist.
|
||||||
|
*
|
||||||
|
* The element is also constructed when the container already has the key,
|
||||||
|
* in which case the newly constructed object is destroyed immediately.
|
||||||
|
*
|
||||||
|
* @tparam Args Types of arguments to forward to the constructor of the
|
||||||
|
* element.
|
||||||
|
* @param args Arguments to forward to the constructor of the element.
|
||||||
|
* @return A pair consisting of an iterator to the inserted element (or to
|
||||||
|
* the element that prevented the insertion) and a bool denoting whether the
|
||||||
|
* insertion took place.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
std::pair<iterator, bool> emplace([[maybe_unused]] Args &&...args) {
|
||||||
|
if constexpr(sizeof...(Args) == 0u) {
|
||||||
|
return insert_or_do_nothing(key_type{});
|
||||||
|
} else if constexpr(sizeof...(Args) == 1u) {
|
||||||
|
return insert_or_do_nothing(std::forward<Args>(args).first..., std::forward<Args>(args).second...);
|
||||||
|
} else if constexpr(sizeof...(Args) == 2u) {
|
||||||
|
return insert_or_do_nothing(std::forward<Args>(args)...);
|
||||||
|
} else {
|
||||||
|
auto &node = packed.first().emplace_back(packed.first().size(), std::forward<Args>(args)...);
|
||||||
|
const auto index = key_to_bucket(node.element.first);
|
||||||
|
|
||||||
|
if(auto it = constrained_find(node.element.first, index); it != end()) {
|
||||||
|
packed.first().pop_back();
|
||||||
|
return std::make_pair(it, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::swap(node.next, sparse.first()[index]);
|
||||||
|
rehash_if_required();
|
||||||
|
|
||||||
|
return std::make_pair(--end(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts in-place if the key does not exist, does nothing if the
|
||||||
|
* key exists.
|
||||||
|
* @tparam Args Types of arguments to forward to the constructor of the
|
||||||
|
* element.
|
||||||
|
* @param key A key used both to look up and to insert if not found.
|
||||||
|
* @param args Arguments to forward to the constructor of the element.
|
||||||
|
* @return A pair consisting of an iterator to the inserted element (or to
|
||||||
|
* the element that prevented the insertion) and a bool denoting whether the
|
||||||
|
* insertion took place.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
std::pair<iterator, bool> try_emplace(const key_type &key, Args &&...args) {
|
||||||
|
return insert_or_do_nothing(key, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc try_emplace */
|
||||||
|
template<typename... Args>
|
||||||
|
std::pair<iterator, bool> try_emplace(key_type &&key, Args &&...args) {
|
||||||
|
return insert_or_do_nothing(std::move(key), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes an element from a given position.
|
||||||
|
* @param pos An iterator to the element to remove.
|
||||||
|
* @return An iterator following the removed element.
|
||||||
|
*/
|
||||||
|
iterator erase(const_iterator pos) {
|
||||||
|
const auto diff = pos - cbegin();
|
||||||
|
erase(pos->first);
|
||||||
|
return begin() + diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes the given elements from a container.
|
||||||
|
* @param first An iterator to the first element of the range of elements.
|
||||||
|
* @param last An iterator past the last element of the range of elements.
|
||||||
|
* @return An iterator following the last removed element.
|
||||||
|
*/
|
||||||
|
iterator erase(const_iterator first, const_iterator last) {
|
||||||
|
const auto dist = first - cbegin();
|
||||||
|
|
||||||
|
for(auto from = last - cbegin(); from != dist; --from) {
|
||||||
|
erase(packed.first()[from - 1u].element.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (begin() + dist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes the element associated with a given key.
|
||||||
|
* @param key A key value of an element to remove.
|
||||||
|
* @return Number of elements removed (either 0 or 1).
|
||||||
|
*/
|
||||||
|
size_type erase(const key_type &key) {
|
||||||
|
for(size_type *curr = sparse.first().data() + key_to_bucket(key); *curr != (std::numeric_limits<size_type>::max)(); curr = &packed.first()[*curr].next) {
|
||||||
|
if(packed.second()(packed.first()[*curr].element.first, key)) {
|
||||||
|
const auto index = *curr;
|
||||||
|
*curr = packed.first()[*curr].next;
|
||||||
|
move_and_pop(index);
|
||||||
|
return 1u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0u;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Exchanges the contents with those of a given container.
|
||||||
|
* @param other Container to exchange the content with.
|
||||||
|
*/
|
||||||
|
void swap(dense_map &other) {
|
||||||
|
using std::swap;
|
||||||
|
swap(sparse, other.sparse);
|
||||||
|
swap(packed, other.packed);
|
||||||
|
swap(threshold, other.threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Accesses a given element with bounds checking.
|
||||||
|
* @param key A key of an element to find.
|
||||||
|
* @return A reference to the mapped value of the requested element.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] mapped_type &at(const key_type &key) {
|
||||||
|
auto it = find(key);
|
||||||
|
ENTT_ASSERT(it != end(), "Invalid key");
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc at */
|
||||||
|
[[nodiscard]] const mapped_type &at(const key_type &key) const {
|
||||||
|
auto it = find(key);
|
||||||
|
ENTT_ASSERT(it != cend(), "Invalid key");
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Accesses or inserts a given element.
|
||||||
|
* @param key A key of an element to find or insert.
|
||||||
|
* @return A reference to the mapped value of the requested element.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] mapped_type &operator[](const key_type &key) {
|
||||||
|
return insert_or_do_nothing(key).first->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Accesses or inserts a given element.
|
||||||
|
* @param key A key of an element to find or insert.
|
||||||
|
* @return A reference to the mapped value of the requested element.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] mapped_type &operator[](key_type &&key) {
|
||||||
|
return insert_or_do_nothing(std::move(key)).first->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Finds an element with a given key.
|
||||||
|
* @param key Key value of an element to search for.
|
||||||
|
* @return An iterator to an element with the given key. If no such element
|
||||||
|
* is found, a past-the-end iterator is returned.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] iterator find(const key_type &key) {
|
||||||
|
return constrained_find(key, key_to_bucket(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc find */
|
||||||
|
[[nodiscard]] const_iterator find(const key_type &key) const {
|
||||||
|
return constrained_find(key, key_to_bucket(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Finds an element with a key that compares _equivalent_ to a given
|
||||||
|
* value.
|
||||||
|
* @tparam Other Type of the key value of an element to search for.
|
||||||
|
* @param key Key value of an element to search for.
|
||||||
|
* @return An iterator to an element with the given key. If no such element
|
||||||
|
* is found, a past-the-end iterator is returned.
|
||||||
|
*/
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, iterator>>
|
||||||
|
find(const Other &key) {
|
||||||
|
return constrained_find(key, key_to_bucket(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc find */
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, const_iterator>>
|
||||||
|
find(const Other &key) const {
|
||||||
|
return constrained_find(key, key_to_bucket(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the container contains an element with a given key.
|
||||||
|
* @param key Key value of an element to search for.
|
||||||
|
* @return True if there is such an element, false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] bool contains(const key_type &key) const {
|
||||||
|
return (find(key) != cend());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the container contains an element with a key that
|
||||||
|
* compares _equivalent_ to a given value.
|
||||||
|
* @tparam Other Type of the key value of an element to search for.
|
||||||
|
* @param key Key value of an element to search for.
|
||||||
|
* @return True if there is such an element, false otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, bool>>
|
||||||
|
contains(const Other &key) const {
|
||||||
|
return (find(key) != cend());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the beginning of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator cbegin(const size_type index) const {
|
||||||
|
return {packed.first().begin(), sparse.first()[index]};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the beginning of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator begin(const size_type index) const {
|
||||||
|
return cbegin(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the beginning of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] local_iterator begin(const size_type index) {
|
||||||
|
return {packed.first().begin(), sparse.first()[index]};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the end of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator cend([[maybe_unused]] const size_type index) const {
|
||||||
|
return {packed.first().begin(), (std::numeric_limits<size_type>::max)()};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the end of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator end([[maybe_unused]] const size_type index) const {
|
||||||
|
return cend(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the end of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] local_iterator end([[maybe_unused]] const size_type index) {
|
||||||
|
return {packed.first().begin(), (std::numeric_limits<size_type>::max)()};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of buckets.
|
||||||
|
* @return The number of buckets.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type bucket_count() const {
|
||||||
|
return sparse.first().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the maximum number of buckets.
|
||||||
|
* @return The maximum number of buckets.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type max_bucket_count() const {
|
||||||
|
return sparse.first().max_size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of elements in a given bucket.
|
||||||
|
* @param index The index of the bucket to examine.
|
||||||
|
* @return The number of elements in the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type bucket_size(const size_type index) const {
|
||||||
|
return static_cast<size_type>(std::distance(begin(index), end(index)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the bucket for a given key.
|
||||||
|
* @param key The value of the key to examine.
|
||||||
|
* @return The bucket for the given key.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type bucket(const key_type &key) const {
|
||||||
|
return key_to_bucket(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the average number of elements per bucket.
|
||||||
|
* @return The average number of elements per bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] float load_factor() const {
|
||||||
|
return size() / static_cast<float>(bucket_count());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the maximum average number of elements per bucket.
|
||||||
|
* @return The maximum average number of elements per bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] float max_load_factor() const {
|
||||||
|
return threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the desired maximum average number of elements per bucket.
|
||||||
|
* @param value A desired maximum average number of elements per bucket.
|
||||||
|
*/
|
||||||
|
void max_load_factor(const float value) {
|
||||||
|
ENTT_ASSERT(value > 0.f, "Invalid load factor");
|
||||||
|
threshold = value;
|
||||||
|
rehash(0u);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reserves at least the specified number of buckets and regenerates
|
||||||
|
* the hash table.
|
||||||
|
* @param count New number of buckets.
|
||||||
|
*/
|
||||||
|
void rehash(const size_type count) {
|
||||||
|
auto value = (std::max)(count, minimum_capacity);
|
||||||
|
value = (std::max)(value, static_cast<size_type>(size() / max_load_factor()));
|
||||||
|
|
||||||
|
if(const auto sz = next_power_of_two(value); sz != bucket_count()) {
|
||||||
|
sparse.first().resize(sz);
|
||||||
|
std::fill(sparse.first().begin(), sparse.first().end(), (std::numeric_limits<size_type>::max)());
|
||||||
|
|
||||||
|
for(size_type pos{}, last = size(); pos < last; ++pos) {
|
||||||
|
const auto index = key_to_bucket(packed.first()[pos].element.first);
|
||||||
|
packed.first()[pos].next = std::exchange(sparse.first()[index], pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reserves space for at least the specified number of elements and
|
||||||
|
* regenerates the hash table.
|
||||||
|
* @param count New number of elements.
|
||||||
|
*/
|
||||||
|
void reserve(const size_type count) {
|
||||||
|
packed.first().reserve(count);
|
||||||
|
rehash(static_cast<size_type>(std::ceil(count / max_load_factor())));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the function used to hash the keys.
|
||||||
|
* @return The function used to hash the keys.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] hasher hash_function() const {
|
||||||
|
return sparse.second();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the function used to compare keys for equality.
|
||||||
|
* @return The function used to compare keys for equality.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] key_equal key_eq() const {
|
||||||
|
return packed.second();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
compressed_pair<sparse_container_type, hasher> sparse;
|
||||||
|
compressed_pair<packed_container_type, key_equal> packed;
|
||||||
|
float threshold;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
|
||||||
|
template<typename Key, typename Value, typename Allocator>
|
||||||
|
struct uses_allocator<entt::internal::dense_map_node<Key, Value>, Allocator>
|
||||||
|
: std::true_type {};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif
|
||||||
823
src/entt/container/dense_set.hpp
Normal file
823
src/entt/container/dense_set.hpp
Normal file
@@ -0,0 +1,823 @@
|
|||||||
|
#ifndef ENTT_CONTAINER_DENSE_SET_HPP
|
||||||
|
#define ENTT_CONTAINER_DENSE_SET_HPP
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <functional>
|
||||||
|
#include <iterator>
|
||||||
|
#include <limits>
|
||||||
|
#include <memory>
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
#include "../config/config.h"
|
||||||
|
#include "../core/compressed_pair.hpp"
|
||||||
|
#include "../core/memory.hpp"
|
||||||
|
#include "../core/type_traits.hpp"
|
||||||
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename It>
|
||||||
|
class dense_set_iterator final {
|
||||||
|
template<typename>
|
||||||
|
friend class dense_set_iterator;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using value_type = typename It::value_type::second_type;
|
||||||
|
using pointer = const value_type *;
|
||||||
|
using reference = const value_type &;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using iterator_category = std::random_access_iterator_tag;
|
||||||
|
|
||||||
|
dense_set_iterator() ENTT_NOEXCEPT
|
||||||
|
: it{} {}
|
||||||
|
|
||||||
|
dense_set_iterator(const It iter) ENTT_NOEXCEPT
|
||||||
|
: it{iter} {}
|
||||||
|
|
||||||
|
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
|
||||||
|
dense_set_iterator(const dense_set_iterator<Other> &other) ENTT_NOEXCEPT
|
||||||
|
: it{other.it} {}
|
||||||
|
|
||||||
|
dense_set_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
|
return ++it, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
|
dense_set_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_iterator &operator--() ENTT_NOEXCEPT {
|
||||||
|
return --it, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_iterator operator--(int) ENTT_NOEXCEPT {
|
||||||
|
dense_set_iterator orig = *this;
|
||||||
|
return operator--(), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
|
||||||
|
it += value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
dense_set_iterator copy = *this;
|
||||||
|
return (copy += value);
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
|
||||||
|
return (*this += -value);
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
return (*this + -value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator[](const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
return it[value].second;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
|
return std::addressof(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
|
return *operator->();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
friend std::ptrdiff_t operator-(const dense_set_iterator<ILhs> &, const dense_set_iterator<IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
friend bool operator==(const dense_set_iterator<ILhs> &, const dense_set_iterator<IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
friend bool operator<(const dense_set_iterator<ILhs> &, const dense_set_iterator<IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
private:
|
||||||
|
It it;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] std::ptrdiff_t operator-(const dense_set_iterator<ILhs> &lhs, const dense_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it - rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator==(const dense_set_iterator<ILhs> &lhs, const dense_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it == rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator!=(const dense_set_iterator<ILhs> &lhs, const dense_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator<(const dense_set_iterator<ILhs> &lhs, const dense_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it < rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator>(const dense_set_iterator<ILhs> &lhs, const dense_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return rhs < lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator<=(const dense_set_iterator<ILhs> &lhs, const dense_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs > rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator>=(const dense_set_iterator<ILhs> &lhs, const dense_set_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs < rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename It>
|
||||||
|
class dense_set_local_iterator final {
|
||||||
|
template<typename>
|
||||||
|
friend class dense_set_local_iterator;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using value_type = typename It::value_type::second_type;
|
||||||
|
using pointer = const value_type *;
|
||||||
|
using reference = const value_type &;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using iterator_category = std::forward_iterator_tag;
|
||||||
|
|
||||||
|
dense_set_local_iterator() ENTT_NOEXCEPT
|
||||||
|
: it{},
|
||||||
|
offset{} {}
|
||||||
|
|
||||||
|
dense_set_local_iterator(It iter, const std::size_t pos) ENTT_NOEXCEPT
|
||||||
|
: it{iter},
|
||||||
|
offset{pos} {}
|
||||||
|
|
||||||
|
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
|
||||||
|
dense_set_local_iterator(const dense_set_local_iterator<Other> &other) ENTT_NOEXCEPT
|
||||||
|
: it{other.it},
|
||||||
|
offset{other.offset} {}
|
||||||
|
|
||||||
|
dense_set_local_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
|
return offset = it[offset].first, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
dense_set_local_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
|
dense_set_local_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
|
return std::addressof(it[offset].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
|
return *operator->();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::size_t index() const ENTT_NOEXCEPT {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
It it;
|
||||||
|
std::size_t offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator==(const dense_set_local_iterator<ILhs> &lhs, const dense_set_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.index() == rhs.index();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ILhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator!=(const dense_set_local_iterator<ILhs> &lhs, const dense_set_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Associative container for unique objects of a given type.
|
||||||
|
*
|
||||||
|
* Internally, elements are organized into buckets. Which bucket an element is
|
||||||
|
* placed into depends entirely on its hash. Elements with the same hash code
|
||||||
|
* appear in the same bucket.
|
||||||
|
*
|
||||||
|
* @tparam Type Value type of the associative container.
|
||||||
|
* @tparam Hash Type of function to use to hash the values.
|
||||||
|
* @tparam KeyEqual Type of function to use to compare the values for equality.
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Hash, typename KeyEqual, typename Allocator>
|
||||||
|
class dense_set {
|
||||||
|
static constexpr float default_threshold = 0.875f;
|
||||||
|
static constexpr std::size_t minimum_capacity = 8u;
|
||||||
|
|
||||||
|
using node_type = std::pair<std::size_t, Type>;
|
||||||
|
using alloc_traits = std::allocator_traits<Allocator>;
|
||||||
|
static_assert(std::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
|
||||||
|
using sparse_container_type = std::vector<std::size_t, typename alloc_traits::template rebind_alloc<std::size_t>>;
|
||||||
|
using packed_container_type = std::vector<node_type, typename alloc_traits::template rebind_alloc<node_type>>;
|
||||||
|
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::size_t value_to_bucket(const Other &value) const ENTT_NOEXCEPT {
|
||||||
|
return fast_mod(sparse.second()(value), bucket_count());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) {
|
||||||
|
for(auto it = begin(bucket), last = end(bucket); it != last; ++it) {
|
||||||
|
if(packed.second()(*it, value)) {
|
||||||
|
return begin() + static_cast<typename iterator::difference_type>(it.index());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) const {
|
||||||
|
for(auto it = cbegin(bucket), last = cend(bucket); it != last; ++it) {
|
||||||
|
if(packed.second()(*it, value)) {
|
||||||
|
return cbegin() + static_cast<typename iterator::difference_type>(it.index());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] auto insert_or_do_nothing(Other &&value) {
|
||||||
|
const auto index = value_to_bucket(value);
|
||||||
|
|
||||||
|
if(auto it = constrained_find(value, index); it != end()) {
|
||||||
|
return std::make_pair(it, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
packed.first().emplace_back(sparse.first()[index], std::forward<Other>(value));
|
||||||
|
sparse.first()[index] = packed.first().size() - 1u;
|
||||||
|
rehash_if_required();
|
||||||
|
|
||||||
|
return std::make_pair(--end(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_and_pop(const std::size_t pos) {
|
||||||
|
if(const auto last = size() - 1u; pos != last) {
|
||||||
|
packed.first()[pos] = std::move(packed.first().back());
|
||||||
|
size_type *curr = sparse.first().data() + value_to_bucket(packed.first().back().second);
|
||||||
|
for(; *curr != last; curr = &packed.first()[*curr].first) {}
|
||||||
|
*curr = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
packed.first().pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void rehash_if_required() {
|
||||||
|
if(size() > (bucket_count() * max_load_factor())) {
|
||||||
|
rehash(bucket_count() * 2u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*! @brief Key type of the container. */
|
||||||
|
using key_type = Type;
|
||||||
|
/*! @brief Value type of the container. */
|
||||||
|
using value_type = Type;
|
||||||
|
/*! @brief Unsigned integer type. */
|
||||||
|
using size_type = std::size_t;
|
||||||
|
/*! @brief Type of function to use to hash the elements. */
|
||||||
|
using hasher = Hash;
|
||||||
|
/*! @brief Type of function to use to compare the elements for equality. */
|
||||||
|
using key_equal = KeyEqual;
|
||||||
|
/*! @brief Allocator type. */
|
||||||
|
using allocator_type = Allocator;
|
||||||
|
/*! @brief Random access iterator type. */
|
||||||
|
using iterator = internal::dense_set_iterator<typename packed_container_type::iterator>;
|
||||||
|
/*! @brief Constant random access iterator type. */
|
||||||
|
using const_iterator = internal::dense_set_iterator<typename packed_container_type::const_iterator>;
|
||||||
|
/*! @brief Forward iterator type. */
|
||||||
|
using local_iterator = internal::dense_set_local_iterator<typename packed_container_type::iterator>;
|
||||||
|
/*! @brief Constant forward iterator type. */
|
||||||
|
using const_local_iterator = internal::dense_set_local_iterator<typename packed_container_type::const_iterator>;
|
||||||
|
|
||||||
|
/*! @brief Default constructor. */
|
||||||
|
dense_set()
|
||||||
|
: dense_set(minimum_capacity) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
explicit dense_set(const allocator_type &allocator)
|
||||||
|
: dense_set{minimum_capacity, hasher{}, key_equal{}, allocator} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator and user
|
||||||
|
* supplied minimal number of buckets.
|
||||||
|
* @param bucket_count Minimal number of buckets.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_set(const size_type bucket_count, const allocator_type &allocator)
|
||||||
|
: dense_set{bucket_count, hasher{}, key_equal{}, allocator} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator, hash
|
||||||
|
* function and user supplied minimal number of buckets.
|
||||||
|
* @param bucket_count Minimal number of buckets.
|
||||||
|
* @param hash Hash function to use.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_set(const size_type bucket_count, const hasher &hash, const allocator_type &allocator)
|
||||||
|
: dense_set{bucket_count, hash, key_equal{}, allocator} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty container with a given allocator, hash
|
||||||
|
* function, compare function and user supplied minimal number of buckets.
|
||||||
|
* @param bucket_count Minimal number of buckets.
|
||||||
|
* @param hash Hash function to use.
|
||||||
|
* @param equal Compare function to use.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
explicit dense_set(const size_type bucket_count, const hasher &hash = hasher{}, const key_equal &equal = key_equal{}, const allocator_type &allocator = allocator_type{})
|
||||||
|
: sparse{allocator, hash},
|
||||||
|
packed{allocator, equal},
|
||||||
|
threshold{default_threshold} {
|
||||||
|
rehash(bucket_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @brief Default copy constructor. */
|
||||||
|
dense_set(const dense_set &) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocator-extended copy constructor.
|
||||||
|
* @param other The instance to copy from.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_set(const dense_set &other, const allocator_type &allocator)
|
||||||
|
: sparse{std::piecewise_construct, std::forward_as_tuple(other.sparse.first(), allocator), std::forward_as_tuple(other.sparse.second())},
|
||||||
|
packed{std::piecewise_construct, std::forward_as_tuple(other.packed.first(), allocator), std::forward_as_tuple(other.packed.second())},
|
||||||
|
threshold{other.threshold} {}
|
||||||
|
|
||||||
|
/*! @brief Default move constructor. */
|
||||||
|
dense_set(dense_set &&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocator-extended move constructor.
|
||||||
|
* @param other The instance to move from.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
dense_set(dense_set &&other, const allocator_type &allocator)
|
||||||
|
: sparse{std::piecewise_construct, std::forward_as_tuple(std::move(other.sparse.first()), allocator), std::forward_as_tuple(std::move(other.sparse.second()))},
|
||||||
|
packed{std::piecewise_construct, std::forward_as_tuple(std::move(other.packed.first()), allocator), std::forward_as_tuple(std::move(other.packed.second()))},
|
||||||
|
threshold{other.threshold} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default copy assignment operator.
|
||||||
|
* @return This container.
|
||||||
|
*/
|
||||||
|
dense_set &operator=(const dense_set &) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default move assignment operator.
|
||||||
|
* @return This container.
|
||||||
|
*/
|
||||||
|
dense_set &operator=(dense_set &&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the associated allocator.
|
||||||
|
* @return The associated allocator.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
|
||||||
|
return sparse.first().get_allocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning.
|
||||||
|
*
|
||||||
|
* The returned iterator points to the first instance of the internal array.
|
||||||
|
* If the array is empty, the returned iterator will be equal to `end()`.
|
||||||
|
*
|
||||||
|
* @return An iterator to the first instance of the internal array.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cbegin */
|
||||||
|
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
|
||||||
|
return cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc begin */
|
||||||
|
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
|
||||||
|
return packed.first().begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end.
|
||||||
|
*
|
||||||
|
* The returned iterator points to the element following the last instance
|
||||||
|
* of the internal array. Attempting to dereference the returned iterator
|
||||||
|
* results in undefined behavior.
|
||||||
|
*
|
||||||
|
* @return An iterator to the element following the last instance of the
|
||||||
|
* internal array.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cend */
|
||||||
|
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
|
||||||
|
return cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc end */
|
||||||
|
[[nodiscard]] iterator end() ENTT_NOEXCEPT {
|
||||||
|
return packed.first().end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks whether a container is empty.
|
||||||
|
* @return True if the container is empty, false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of elements in a container.
|
||||||
|
* @return Number of elements in a container.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||||
|
return packed.first().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @brief Clears the container. */
|
||||||
|
void clear() ENTT_NOEXCEPT {
|
||||||
|
sparse.first().clear();
|
||||||
|
packed.first().clear();
|
||||||
|
rehash(0u);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts an element into the container, if it does not exist.
|
||||||
|
* @param value An element to insert into the container.
|
||||||
|
* @return A pair consisting of an iterator to the inserted element (or to
|
||||||
|
* the element that prevented the insertion) and a bool denoting whether the
|
||||||
|
* insertion took place.
|
||||||
|
*/
|
||||||
|
std::pair<iterator, bool> insert(const value_type &value) {
|
||||||
|
return insert_or_do_nothing(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc insert */
|
||||||
|
std::pair<iterator, bool> insert(value_type &&value) {
|
||||||
|
return insert_or_do_nothing(std::move(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts elements into the container, if they do not exist.
|
||||||
|
* @tparam It Type of input iterator.
|
||||||
|
* @param first An iterator to the first element of the range of elements.
|
||||||
|
* @param last An iterator past the last element of the range of elements.
|
||||||
|
*/
|
||||||
|
template<typename It>
|
||||||
|
void insert(It first, It last) {
|
||||||
|
for(; first != last; ++first) {
|
||||||
|
insert(*first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an element in-place, if it does not exist.
|
||||||
|
*
|
||||||
|
* The element is also constructed when the container already has the key,
|
||||||
|
* in which case the newly constructed object is destroyed immediately.
|
||||||
|
*
|
||||||
|
* @tparam Args Types of arguments to forward to the constructor of the
|
||||||
|
* element.
|
||||||
|
* @param args Arguments to forward to the constructor of the element.
|
||||||
|
* @return A pair consisting of an iterator to the inserted element (or to
|
||||||
|
* the element that prevented the insertion) and a bool denoting whether the
|
||||||
|
* insertion took place.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
std::pair<iterator, bool> emplace(Args &&...args) {
|
||||||
|
if constexpr(((sizeof...(Args) == 1u) && ... && std::is_same_v<std::remove_cv_t<std::remove_reference_t<Args>>, value_type>)) {
|
||||||
|
return insert_or_do_nothing(std::forward<Args>(args)...);
|
||||||
|
} else {
|
||||||
|
auto &node = packed.first().emplace_back(std::piecewise_construct, std::make_tuple(packed.first().size()), std::forward_as_tuple(std::forward<Args>(args)...));
|
||||||
|
const auto index = value_to_bucket(node.second);
|
||||||
|
|
||||||
|
if(auto it = constrained_find(node.second, index); it != end()) {
|
||||||
|
packed.first().pop_back();
|
||||||
|
return std::make_pair(it, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::swap(node.first, sparse.first()[index]);
|
||||||
|
rehash_if_required();
|
||||||
|
|
||||||
|
return std::make_pair(--end(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes an element from a given position.
|
||||||
|
* @param pos An iterator to the element to remove.
|
||||||
|
* @return An iterator following the removed element.
|
||||||
|
*/
|
||||||
|
iterator erase(const_iterator pos) {
|
||||||
|
const auto diff = pos - cbegin();
|
||||||
|
erase(*pos);
|
||||||
|
return begin() + diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes the given elements from a container.
|
||||||
|
* @param first An iterator to the first element of the range of elements.
|
||||||
|
* @param last An iterator past the last element of the range of elements.
|
||||||
|
* @return An iterator following the last removed element.
|
||||||
|
*/
|
||||||
|
iterator erase(const_iterator first, const_iterator last) {
|
||||||
|
const auto dist = first - cbegin();
|
||||||
|
|
||||||
|
for(auto from = last - cbegin(); from != dist; --from) {
|
||||||
|
erase(packed.first()[from - 1u].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (begin() + dist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes the element associated with a given value.
|
||||||
|
* @param value Value of an element to remove.
|
||||||
|
* @return Number of elements removed (either 0 or 1).
|
||||||
|
*/
|
||||||
|
size_type erase(const value_type &value) {
|
||||||
|
for(size_type *curr = sparse.first().data() + value_to_bucket(value); *curr != (std::numeric_limits<size_type>::max)(); curr = &packed.first()[*curr].first) {
|
||||||
|
if(packed.second()(packed.first()[*curr].second, value)) {
|
||||||
|
const auto index = *curr;
|
||||||
|
*curr = packed.first()[*curr].first;
|
||||||
|
move_and_pop(index);
|
||||||
|
return 1u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0u;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Exchanges the contents with those of a given container.
|
||||||
|
* @param other Container to exchange the content with.
|
||||||
|
*/
|
||||||
|
void swap(dense_set &other) {
|
||||||
|
using std::swap;
|
||||||
|
swap(sparse, other.sparse);
|
||||||
|
swap(packed, other.packed);
|
||||||
|
swap(threshold, other.threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Finds an element with a given value.
|
||||||
|
* @param value Value of an element to search for.
|
||||||
|
* @return An iterator to an element with the given value. If no such
|
||||||
|
* element is found, a past-the-end iterator is returned.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] iterator find(const value_type &value) {
|
||||||
|
return constrained_find(value, value_to_bucket(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc find */
|
||||||
|
[[nodiscard]] const_iterator find(const value_type &value) const {
|
||||||
|
return constrained_find(value, value_to_bucket(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Finds an element that compares _equivalent_ to a given value.
|
||||||
|
* @tparam Other Type of an element to search for.
|
||||||
|
* @param value Value of an element to search for.
|
||||||
|
* @return An iterator to an element with the given value. If no such
|
||||||
|
* element is found, a past-the-end iterator is returned.
|
||||||
|
*/
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, iterator>>
|
||||||
|
find(const Other &value) {
|
||||||
|
return constrained_find(value, value_to_bucket(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc find */
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, const_iterator>>
|
||||||
|
find(const Other &value) const {
|
||||||
|
return constrained_find(value, value_to_bucket(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the container contains an element with a given value.
|
||||||
|
* @param value Value of an element to search for.
|
||||||
|
* @return True if there is such an element, false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] bool contains(const value_type &value) const {
|
||||||
|
return (find(value) != cend());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the container contains an element that compares
|
||||||
|
* _equivalent_ to a given value.
|
||||||
|
* @tparam Other Type of an element to search for.
|
||||||
|
* @param value Value of an element to search for.
|
||||||
|
* @return True if there is such an element, false otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Other>
|
||||||
|
[[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, bool>>
|
||||||
|
contains(const Other &value) const {
|
||||||
|
return (find(value) != cend());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the beginning of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator cbegin(const size_type index) const {
|
||||||
|
return {packed.first().begin(), sparse.first()[index]};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the beginning of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator begin(const size_type index) const {
|
||||||
|
return cbegin(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the beginning of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] local_iterator begin(const size_type index) {
|
||||||
|
return {packed.first().begin(), sparse.first()[index]};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the end of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator cend([[maybe_unused]] const size_type index) const {
|
||||||
|
return {packed.first().begin(), (std::numeric_limits<size_type>::max)()};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the end of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_local_iterator end([[maybe_unused]] const size_type index) const {
|
||||||
|
return cend(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end of a given bucket.
|
||||||
|
* @param index An index of a bucket to access.
|
||||||
|
* @return An iterator to the end of the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] local_iterator end([[maybe_unused]] const size_type index) {
|
||||||
|
return {packed.first().begin(), (std::numeric_limits<size_type>::max)()};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of buckets.
|
||||||
|
* @return The number of buckets.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type bucket_count() const {
|
||||||
|
return sparse.first().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the maximum number of buckets.
|
||||||
|
* @return The maximum number of buckets.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type max_bucket_count() const {
|
||||||
|
return sparse.first().max_size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of elements in a given bucket.
|
||||||
|
* @param index The index of the bucket to examine.
|
||||||
|
* @return The number of elements in the given bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type bucket_size(const size_type index) const {
|
||||||
|
return static_cast<size_type>(std::distance(begin(index), end(index)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the bucket for a given element.
|
||||||
|
* @param value The value of the element to examine.
|
||||||
|
* @return The bucket for the given element.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] size_type bucket(const value_type &value) const {
|
||||||
|
return value_to_bucket(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the average number of elements per bucket.
|
||||||
|
* @return The average number of elements per bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] float load_factor() const {
|
||||||
|
return size() / static_cast<float>(bucket_count());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the maximum average number of elements per bucket.
|
||||||
|
* @return The maximum average number of elements per bucket.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] float max_load_factor() const {
|
||||||
|
return threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the desired maximum average number of elements per bucket.
|
||||||
|
* @param value A desired maximum average number of elements per bucket.
|
||||||
|
*/
|
||||||
|
void max_load_factor(const float value) {
|
||||||
|
ENTT_ASSERT(value > 0.f, "Invalid load factor");
|
||||||
|
threshold = value;
|
||||||
|
rehash(0u);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reserves at least the specified number of buckets and regenerates
|
||||||
|
* the hash table.
|
||||||
|
* @param count New number of buckets.
|
||||||
|
*/
|
||||||
|
void rehash(const size_type count) {
|
||||||
|
auto value = (std::max)(count, minimum_capacity);
|
||||||
|
value = (std::max)(value, static_cast<size_type>(size() / max_load_factor()));
|
||||||
|
|
||||||
|
if(const auto sz = next_power_of_two(value); sz != bucket_count()) {
|
||||||
|
sparse.first().resize(sz);
|
||||||
|
std::fill(sparse.first().begin(), sparse.first().end(), (std::numeric_limits<size_type>::max)());
|
||||||
|
|
||||||
|
for(size_type pos{}, last = size(); pos < last; ++pos) {
|
||||||
|
const auto index = value_to_bucket(packed.first()[pos].second);
|
||||||
|
packed.first()[pos].first = std::exchange(sparse.first()[index], pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reserves space for at least the specified number of elements and
|
||||||
|
* regenerates the hash table.
|
||||||
|
* @param count New number of elements.
|
||||||
|
*/
|
||||||
|
void reserve(const size_type count) {
|
||||||
|
packed.first().reserve(count);
|
||||||
|
rehash(static_cast<size_type>(std::ceil(count / max_load_factor())));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the function used to hash the elements.
|
||||||
|
* @return The function used to hash the elements.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] hasher hash_function() const {
|
||||||
|
return sparse.second();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the function used to compare elements for equality.
|
||||||
|
* @return The function used to compare elements for equality.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] key_equal key_eq() const {
|
||||||
|
return packed.second();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
compressed_pair<sparse_container_type, hasher> sparse;
|
||||||
|
compressed_pair<packed_container_type, key_equal> packed;
|
||||||
|
float threshold;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
#endif
|
||||||
26
src/entt/container/fwd.hpp
Normal file
26
src/entt/container/fwd.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef ENTT_CONTAINER_FWD_HPP
|
||||||
|
#define ENTT_CONTAINER_FWD_HPP
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
template<
|
||||||
|
typename Key,
|
||||||
|
typename Type,
|
||||||
|
typename = std::hash<Key>,
|
||||||
|
typename = std::equal_to<Key>,
|
||||||
|
typename = std::allocator<std::pair<const Key, Type>>>
|
||||||
|
class dense_map;
|
||||||
|
|
||||||
|
template<
|
||||||
|
typename Type,
|
||||||
|
typename = std::hash<Type>,
|
||||||
|
typename = std::equal_to<Type>,
|
||||||
|
typename = std::allocator<Type>>
|
||||||
|
class dense_set;
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,18 +1,15 @@
|
|||||||
#ifndef ENTT_CORE_ALGORITHM_HPP
|
#ifndef ENTT_CORE_ALGORITHM_HPP
|
||||||
#define ENTT_CORE_ALGORITHM_HPP
|
#define ENTT_CORE_ALGORITHM_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <utility>
|
|
||||||
#include <iterator>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <iterator>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Function object to wrap `std::sort` in a class type.
|
* @brief Function object to wrap `std::sort` in a class type.
|
||||||
*
|
*
|
||||||
@@ -36,12 +33,11 @@ struct std_sort {
|
|||||||
* @param args Arguments to forward to the sort function, if any.
|
* @param args Arguments to forward to the sort function, if any.
|
||||||
*/
|
*/
|
||||||
template<typename It, typename Compare = std::less<>, typename... Args>
|
template<typename It, typename Compare = std::less<>, typename... Args>
|
||||||
void operator()(It first, It last, Compare compare = Compare{}, Args &&... args) const {
|
void operator()(It first, It last, Compare compare = Compare{}, Args &&...args) const {
|
||||||
std::sort(std::forward<Args>(args)..., std::move(first), std::move(last), std::move(compare));
|
std::sort(std::forward<Args>(args)..., std::move(first), std::move(last), std::move(compare));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Function object for performing insertion sort. */
|
/*! @brief Function object for performing insertion sort. */
|
||||||
struct insertion_sort {
|
struct insertion_sort {
|
||||||
/**
|
/**
|
||||||
@@ -62,8 +58,8 @@ struct insertion_sort {
|
|||||||
auto value = std::move(*it);
|
auto value = std::move(*it);
|
||||||
auto pre = it;
|
auto pre = it;
|
||||||
|
|
||||||
for(; pre > first && compare(value, *(pre-1)); --pre) {
|
for(; pre > first && compare(value, *(pre - 1)); --pre) {
|
||||||
*pre = std::move(*(pre-1));
|
*pre = std::move(*(pre - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
*pre = std::move(value);
|
*pre = std::move(value);
|
||||||
@@ -72,7 +68,6 @@ struct insertion_sort {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Function object for performing LSD radix sort.
|
* @brief Function object for performing LSD radix sort.
|
||||||
* @tparam Bit Number of bits processed per pass.
|
* @tparam Bit Number of bits processed per pass.
|
||||||
@@ -137,8 +132,6 @@ struct radix_sort {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#ifndef ENTT_CORE_ANY_HPP
|
#ifndef ENTT_CORE_ANY_HPP
|
||||||
#define ENTT_CORE_ANY_HPP
|
#define ENTT_CORE_ANY_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -13,10 +11,8 @@
|
|||||||
#include "type_info.hpp"
|
#include "type_info.hpp"
|
||||||
#include "type_traits.hpp"
|
#include "type_traits.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A SBO friendly, type-safe container for single values of any type.
|
* @brief A SBO friendly, type-safe container for single values of any type.
|
||||||
* @tparam Len Size of the storage reserved for the small buffer optimization.
|
* @tparam Len Size of the storage reserved for the small buffer optimization.
|
||||||
@@ -24,100 +20,102 @@ namespace entt {
|
|||||||
*/
|
*/
|
||||||
template<std::size_t Len, std::size_t Align>
|
template<std::size_t Len, std::size_t Align>
|
||||||
class basic_any {
|
class basic_any {
|
||||||
enum class operation: std::uint8_t { COPY, MOVE, DTOR, COMP, ADDR, CADDR, TYPE };
|
enum class operation : std::uint8_t {
|
||||||
enum class policy: std::uint8_t { OWNER, REF, CREF };
|
copy,
|
||||||
|
move,
|
||||||
|
transfer,
|
||||||
|
assign,
|
||||||
|
destroy,
|
||||||
|
compare,
|
||||||
|
get
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class policy : std::uint8_t {
|
||||||
|
owner,
|
||||||
|
ref,
|
||||||
|
cref
|
||||||
|
};
|
||||||
|
|
||||||
using storage_type = std::aligned_storage_t<Len + !Len, Align>;
|
using storage_type = std::aligned_storage_t<Len + !Len, Align>;
|
||||||
using vtable_type = const void *(const operation, const basic_any &, void *);
|
using vtable_type = const void *(const operation, const basic_any &, const void *);
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
static constexpr bool in_situ = Len && alignof(Type) <= alignof(storage_type) && sizeof(Type) <= sizeof(storage_type) && std::is_nothrow_move_constructible_v<Type>;
|
static constexpr bool in_situ = Len && alignof(Type) <= alignof(storage_type) && sizeof(Type) <= sizeof(storage_type) && std::is_nothrow_move_constructible_v<Type>;
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] static constexpr policy type_to_policy() {
|
static const void *basic_vtable([[maybe_unused]] const operation op, [[maybe_unused]] const basic_any &value, [[maybe_unused]] const void *other) {
|
||||||
if constexpr(std::is_lvalue_reference_v<Type>) {
|
static_assert(!std::is_same_v<Type, void> && std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, Type>, "Invalid type");
|
||||||
if constexpr(std::is_const_v<std::remove_reference_t<Type>>) {
|
const Type *element = nullptr;
|
||||||
return policy::CREF;
|
|
||||||
|
if constexpr(in_situ<Type>) {
|
||||||
|
element = value.owner() ? reinterpret_cast<const Type *>(&value.storage) : static_cast<const Type *>(value.instance);
|
||||||
|
} else {
|
||||||
|
element = static_cast<const Type *>(value.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(op) {
|
||||||
|
case operation::copy:
|
||||||
|
if constexpr(std::is_copy_constructible_v<Type>) {
|
||||||
|
static_cast<basic_any *>(const_cast<void *>(other))->initialize<Type>(*element);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case operation::move:
|
||||||
|
if constexpr(in_situ<Type>) {
|
||||||
|
if(value.owner()) {
|
||||||
|
return new(&static_cast<basic_any *>(const_cast<void *>(other))->storage) Type{std::move(*const_cast<Type *>(element))};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (static_cast<basic_any *>(const_cast<void *>(other))->instance = std::exchange(const_cast<basic_any &>(value).instance, nullptr));
|
||||||
|
case operation::transfer:
|
||||||
|
if constexpr(std::is_move_assignable_v<Type>) {
|
||||||
|
*const_cast<Type *>(element) = std::move(*static_cast<Type *>(const_cast<void *>(other)));
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
[[fallthrough]];
|
||||||
|
case operation::assign:
|
||||||
|
if constexpr(std::is_copy_assignable_v<Type>) {
|
||||||
|
*const_cast<Type *>(element) = *static_cast<const Type *>(other);
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case operation::destroy:
|
||||||
|
if constexpr(in_situ<Type>) {
|
||||||
|
element->~Type();
|
||||||
|
} else if constexpr(std::is_array_v<Type>) {
|
||||||
|
delete[] element;
|
||||||
} else {
|
} else {
|
||||||
return policy::REF;
|
delete element;
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
return policy::OWNER;
|
case operation::compare:
|
||||||
}
|
if constexpr(!std::is_function_v<Type> && !std::is_array_v<Type> && is_equality_comparable_v<Type>) {
|
||||||
}
|
return *static_cast<const Type *>(element) == *static_cast<const Type *>(other) ? other : nullptr;
|
||||||
|
} else {
|
||||||
template<typename Type>
|
return (element == other) ? other : nullptr;
|
||||||
[[nodiscard]] static bool compare(const void *lhs, const void *rhs) {
|
|
||||||
if constexpr(!std::is_function_v<Type> && is_equality_comparable_v<Type>) {
|
|
||||||
return *static_cast<const Type *>(lhs) == *static_cast<const Type *>(rhs);
|
|
||||||
} else {
|
|
||||||
return lhs == rhs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
static const void * basic_vtable([[maybe_unused]] const operation op, [[maybe_unused]] const basic_any &from, [[maybe_unused]] void *to) {
|
|
||||||
static_assert(std::is_same_v<std::remove_reference_t<std::remove_const_t<Type>>, Type>, "Invalid type");
|
|
||||||
|
|
||||||
if constexpr(!std::is_void_v<Type>) {
|
|
||||||
const Type *instance = (in_situ<Type> && from.mode == policy::OWNER)
|
|
||||||
? ENTT_LAUNDER(reinterpret_cast<const Type *>(&from.storage))
|
|
||||||
: static_cast<const Type *>(from.instance);
|
|
||||||
|
|
||||||
switch(op) {
|
|
||||||
case operation::COPY:
|
|
||||||
if constexpr(std::is_copy_constructible_v<Type>) {
|
|
||||||
static_cast<basic_any *>(to)->emplace<Type>(*instance);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case operation::MOVE:
|
|
||||||
if constexpr(in_situ<Type>) {
|
|
||||||
if(from.mode == policy::OWNER) {
|
|
||||||
return new (&static_cast<basic_any *>(to)->storage) Type{std::move(*const_cast<Type *>(instance))};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (static_cast<basic_any *>(to)->instance = std::exchange(const_cast<basic_any &>(from).instance, nullptr));
|
|
||||||
case operation::DTOR:
|
|
||||||
if(from.mode == policy::OWNER) {
|
|
||||||
if constexpr(in_situ<Type>) {
|
|
||||||
instance->~Type();
|
|
||||||
} else if constexpr(std::is_array_v<Type>) {
|
|
||||||
delete[] instance;
|
|
||||||
} else {
|
|
||||||
delete instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case operation::COMP:
|
|
||||||
return compare<Type>(instance, (*static_cast<const basic_any **>(to))->data()) ? to : nullptr;
|
|
||||||
case operation::ADDR:
|
|
||||||
if(from.mode == policy::CREF) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
[[fallthrough]];
|
|
||||||
case operation::CADDR:
|
|
||||||
return instance;
|
|
||||||
case operation::TYPE:
|
|
||||||
*static_cast<type_info *>(to) = type_id<Type>();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
case operation::get:
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type, typename... Args>
|
template<typename Type, typename... Args>
|
||||||
void initialize([[maybe_unused]] Args &&... args) {
|
void initialize([[maybe_unused]] Args &&...args) {
|
||||||
if constexpr(!std::is_void_v<Type>) {
|
if constexpr(!std::is_void_v<Type>) {
|
||||||
|
info = &type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
|
||||||
|
vtable = basic_vtable<std::remove_cv_t<std::remove_reference_t<Type>>>;
|
||||||
|
|
||||||
if constexpr(std::is_lvalue_reference_v<Type>) {
|
if constexpr(std::is_lvalue_reference_v<Type>) {
|
||||||
static_assert(sizeof...(Args) == 1u && (std::is_lvalue_reference_v<Args> && ...), "Invalid arguments");
|
static_assert(sizeof...(Args) == 1u && (std::is_lvalue_reference_v<Args> && ...), "Invalid arguments");
|
||||||
|
mode = std::is_const_v<std::remove_reference_t<Type>> ? policy::cref : policy::ref;
|
||||||
instance = (std::addressof(args), ...);
|
instance = (std::addressof(args), ...);
|
||||||
} else if constexpr(in_situ<Type>) {
|
} else if constexpr(in_situ<Type>) {
|
||||||
if constexpr(sizeof...(Args) != 0u && std::is_aggregate_v<Type>) {
|
if constexpr(sizeof...(Args) != 0u && std::is_aggregate_v<Type>) {
|
||||||
new (&storage) Type{std::forward<Args>(args)...};
|
new(&storage) Type{std::forward<Args>(args)...};
|
||||||
} else {
|
} else {
|
||||||
new (&storage) Type(std::forward<Args>(args)...);
|
new(&storage) Type(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if constexpr(sizeof...(Args) != 0u && std::is_aggregate_v<Type>) {
|
if constexpr(sizeof...(Args) != 0u && std::is_aggregate_v<Type>) {
|
||||||
@@ -131,9 +129,9 @@ class basic_any {
|
|||||||
|
|
||||||
basic_any(const basic_any &other, const policy pol) ENTT_NOEXCEPT
|
basic_any(const basic_any &other, const policy pol) ENTT_NOEXCEPT
|
||||||
: instance{other.data()},
|
: instance{other.data()},
|
||||||
|
info{other.info},
|
||||||
vtable{other.vtable},
|
vtable{other.vtable},
|
||||||
mode{pol}
|
mode{pol} {}
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief Size of the internal storage. */
|
/*! @brief Size of the internal storage. */
|
||||||
@@ -142,11 +140,11 @@ public:
|
|||||||
static constexpr auto alignment = Align;
|
static constexpr auto alignment = Align;
|
||||||
|
|
||||||
/*! @brief Default constructor. */
|
/*! @brief Default constructor. */
|
||||||
basic_any() ENTT_NOEXCEPT
|
constexpr basic_any() ENTT_NOEXCEPT
|
||||||
: instance{},
|
: instance{},
|
||||||
vtable{&basic_vtable<void>},
|
info{&type_id<void>()},
|
||||||
mode{policy::OWNER}
|
vtable{},
|
||||||
{}
|
mode{policy::owner} {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a wrapper by directly initializing the new object.
|
* @brief Constructs a wrapper by directly initializing the new object.
|
||||||
@@ -155,27 +153,11 @@ public:
|
|||||||
* @param args Parameters to use to construct the instance.
|
* @param args Parameters to use to construct the instance.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename... Args>
|
template<typename Type, typename... Args>
|
||||||
explicit basic_any(std::in_place_type_t<Type>, Args &&... args)
|
explicit basic_any(std::in_place_type_t<Type>, Args &&...args)
|
||||||
: instance{},
|
: basic_any{} {
|
||||||
vtable{&basic_vtable<std::remove_const_t<std::remove_reference_t<Type>>>},
|
|
||||||
mode{type_to_policy<Type>()}
|
|
||||||
{
|
|
||||||
initialize<Type>(std::forward<Args>(args)...);
|
initialize<Type>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructs a wrapper that holds an unmanaged object.
|
|
||||||
* @tparam Type Type of object to use to initialize the wrapper.
|
|
||||||
* @param value An instance of an object to use to initialize the wrapper.
|
|
||||||
*/
|
|
||||||
template<typename Type>
|
|
||||||
basic_any(std::reference_wrapper<Type> value) ENTT_NOEXCEPT
|
|
||||||
: basic_any{}
|
|
||||||
{
|
|
||||||
// invokes deprecated assignment operator (and avoids issues with vs2017)
|
|
||||||
*this = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a wrapper from a given value.
|
* @brief Constructs a wrapper from a given value.
|
||||||
* @tparam Type Type of object to use to initialize the wrapper.
|
* @tparam Type Type of object to use to initialize the wrapper.
|
||||||
@@ -183,10 +165,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, basic_any>>>
|
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, basic_any>>>
|
||||||
basic_any(Type &&value)
|
basic_any(Type &&value)
|
||||||
: instance{},
|
: basic_any{} {
|
||||||
vtable{&basic_vtable<std::decay_t<Type>>},
|
|
||||||
mode{policy::OWNER}
|
|
||||||
{
|
|
||||||
initialize<std::decay_t<Type>>(std::forward<Type>(value));
|
initialize<std::decay_t<Type>>(std::forward<Type>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,11 +174,10 @@ public:
|
|||||||
* @param other The instance to copy from.
|
* @param other The instance to copy from.
|
||||||
*/
|
*/
|
||||||
basic_any(const basic_any &other)
|
basic_any(const basic_any &other)
|
||||||
: instance{},
|
: basic_any{} {
|
||||||
vtable{&basic_vtable<void>},
|
if(other.vtable) {
|
||||||
mode{policy::OWNER}
|
other.vtable(operation::copy, other, this);
|
||||||
{
|
}
|
||||||
other.vtable(operation::COPY, other, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,15 +186,19 @@ public:
|
|||||||
*/
|
*/
|
||||||
basic_any(basic_any &&other) ENTT_NOEXCEPT
|
basic_any(basic_any &&other) ENTT_NOEXCEPT
|
||||||
: instance{},
|
: instance{},
|
||||||
|
info{other.info},
|
||||||
vtable{other.vtable},
|
vtable{other.vtable},
|
||||||
mode{other.mode}
|
mode{other.mode} {
|
||||||
{
|
if(other.vtable) {
|
||||||
vtable(operation::MOVE, other, this);
|
other.vtable(operation::move, other, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @brief Frees the internal storage, whatever it means. */
|
/*! @brief Frees the internal storage, whatever it means. */
|
||||||
~basic_any() {
|
~basic_any() {
|
||||||
vtable(operation::DTOR, *this, nullptr);
|
if(vtable && owner()) {
|
||||||
|
vtable(operation::destroy, *this, nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -224,9 +206,13 @@ public:
|
|||||||
* @param other The instance to copy from.
|
* @param other The instance to copy from.
|
||||||
* @return This any object.
|
* @return This any object.
|
||||||
*/
|
*/
|
||||||
basic_any & operator=(const basic_any &other) {
|
basic_any &operator=(const basic_any &other) {
|
||||||
reset();
|
reset();
|
||||||
other.vtable(operation::COPY, other, this);
|
|
||||||
|
if(other.vtable) {
|
||||||
|
other.vtable(operation::copy, other, this);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,23 +221,16 @@ public:
|
|||||||
* @param other The instance to move from.
|
* @param other The instance to move from.
|
||||||
* @return This any object.
|
* @return This any object.
|
||||||
*/
|
*/
|
||||||
basic_any & operator=(basic_any &&other) ENTT_NOEXCEPT {
|
basic_any &operator=(basic_any &&other) ENTT_NOEXCEPT {
|
||||||
std::exchange(vtable, other.vtable)(operation::DTOR, *this, nullptr);
|
reset();
|
||||||
other.vtable(operation::MOVE, other, this);
|
|
||||||
mode = other.mode;
|
if(other.vtable) {
|
||||||
return *this;
|
other.vtable(operation::move, other, this);
|
||||||
}
|
info = other.info;
|
||||||
|
vtable = other.vtable;
|
||||||
|
mode = other.mode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Value assignment operator.
|
|
||||||
* @tparam Type Type of object to use to initialize the wrapper.
|
|
||||||
* @param value An instance of an object to use to initialize the wrapper.
|
|
||||||
* @return This any object.
|
|
||||||
*/
|
|
||||||
template<typename Type>
|
|
||||||
[[deprecated("Use std::in_place_type<T &>, entt::make_any<T &>, emplace<Type &> or forward_as_any instead")]]
|
|
||||||
basic_any & operator=(std::reference_wrapper<Type> value) ENTT_NOEXCEPT {
|
|
||||||
emplace<Type &>(value.get());
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,26 +248,45 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the type of the contained object.
|
* @brief Returns the object type if any, `type_id<void>()` otherwise.
|
||||||
* @return The type of the contained object, if any.
|
* @return The object type if any, `type_id<void>()` otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] type_info type() const ENTT_NOEXCEPT {
|
[[nodiscard]] const type_info &type() const ENTT_NOEXCEPT {
|
||||||
type_info info{};
|
return *info;
|
||||||
vtable(operation::TYPE, *this, &info);
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an opaque pointer to the contained instance.
|
* @brief Returns an opaque pointer to the contained instance.
|
||||||
* @return An opaque pointer the contained instance, if any.
|
* @return An opaque pointer the contained instance, if any.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const void * data() const ENTT_NOEXCEPT {
|
[[nodiscard]] const void *data() const ENTT_NOEXCEPT {
|
||||||
return vtable(operation::CADDR, *this, nullptr);
|
return vtable ? vtable(operation::get, *this, nullptr) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc data */
|
/**
|
||||||
[[nodiscard]] void * data() ENTT_NOEXCEPT {
|
* @brief Returns an opaque pointer to the contained instance.
|
||||||
return const_cast<void *>(vtable(operation::ADDR, *this, nullptr));
|
* @param req Expected type.
|
||||||
|
* @return An opaque pointer the contained instance, if any.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const void *data(const type_info &req) const ENTT_NOEXCEPT {
|
||||||
|
return *info == req ? data() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an opaque pointer to the contained instance.
|
||||||
|
* @return An opaque pointer the contained instance, if any.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] void *data() ENTT_NOEXCEPT {
|
||||||
|
return (!vtable || mode == policy::cref) ? nullptr : const_cast<void *>(vtable(operation::get, *this, nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an opaque pointer to the contained instance.
|
||||||
|
* @param req Expected type.
|
||||||
|
* @return An opaque pointer the contained instance, if any.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] void *data(const type_info &req) ENTT_NOEXCEPT {
|
||||||
|
return *info == req ? data() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,16 +296,46 @@ public:
|
|||||||
* @param args Parameters to use to construct the instance.
|
* @param args Parameters to use to construct the instance.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename... Args>
|
template<typename Type, typename... Args>
|
||||||
void emplace(Args &&... args) {
|
void emplace(Args &&...args) {
|
||||||
std::exchange(vtable, &basic_vtable<std::remove_const_t<std::remove_reference_t<Type>>>)(operation::DTOR, *this, nullptr);
|
reset();
|
||||||
mode = type_to_policy<Type>();
|
|
||||||
initialize<Type>(std::forward<Args>(args)...);
|
initialize<Type>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assigns a value to the contained object without replacing it.
|
||||||
|
* @param other The value to assign to the contained object.
|
||||||
|
* @return True in case of success, false otherwise.
|
||||||
|
*/
|
||||||
|
bool assign(const any &other) {
|
||||||
|
if(vtable && mode != policy::cref && *info == *other.info) {
|
||||||
|
return (vtable(operation::assign, *this, other.data()) != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc assign */
|
||||||
|
bool assign(any &&other) {
|
||||||
|
if(vtable && mode != policy::cref && *info == *other.info) {
|
||||||
|
if(auto *val = other.data(); val) {
|
||||||
|
return (vtable(operation::transfer, *this, val) != nullptr);
|
||||||
|
} else {
|
||||||
|
return (vtable(operation::assign, *this, std::as_const(other).data()) != nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*! @brief Destroys contained object */
|
/*! @brief Destroys contained object */
|
||||||
void reset() {
|
void reset() {
|
||||||
std::exchange(vtable, &basic_vtable<void>)(operation::DTOR, *this, nullptr);
|
if(vtable && owner()) {
|
||||||
mode = policy::OWNER;
|
vtable(operation::destroy, *this, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
info = &type_id<void>();
|
||||||
|
vtable = nullptr;
|
||||||
|
mode = policy::owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -315,7 +343,7 @@ public:
|
|||||||
* @return False if the wrapper is empty, true otherwise.
|
* @return False if the wrapper is empty, true otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
|
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
|
||||||
return !(vtable(operation::CADDR, *this, nullptr) == nullptr);
|
return vtable != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -324,8 +352,11 @@ public:
|
|||||||
* @return False if the two objects differ in their content, true otherwise.
|
* @return False if the two objects differ in their content, true otherwise.
|
||||||
*/
|
*/
|
||||||
bool operator==(const basic_any &other) const ENTT_NOEXCEPT {
|
bool operator==(const basic_any &other) const ENTT_NOEXCEPT {
|
||||||
const basic_any *trampoline = &other;
|
if(vtable && *info == *other.info) {
|
||||||
return type() == other.type() && (vtable(operation::COMP, *this, &trampoline) || !other.data());
|
return (vtable(operation::compare, *this, other.data()) != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (!vtable && !other.vtable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -333,12 +364,12 @@ public:
|
|||||||
* @return A wrapper that shares a reference to an unmanaged object.
|
* @return A wrapper that shares a reference to an unmanaged object.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] basic_any as_ref() ENTT_NOEXCEPT {
|
[[nodiscard]] basic_any as_ref() ENTT_NOEXCEPT {
|
||||||
return basic_any{*this, (mode == policy::CREF ? policy::CREF : policy::REF)};
|
return basic_any{*this, (mode == policy::cref ? policy::cref : policy::ref)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc as_ref */
|
/*! @copydoc as_ref */
|
||||||
[[nodiscard]] basic_any as_ref() const ENTT_NOEXCEPT {
|
[[nodiscard]] basic_any as_ref() const ENTT_NOEXCEPT {
|
||||||
return basic_any{*this, policy::CREF};
|
return basic_any{*this, policy::cref};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -346,16 +377,19 @@ public:
|
|||||||
* @return True if the wrapper owns its object, false otherwise.
|
* @return True if the wrapper owns its object, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool owner() const ENTT_NOEXCEPT {
|
[[nodiscard]] bool owner() const ENTT_NOEXCEPT {
|
||||||
return (mode == policy::OWNER);
|
return (mode == policy::owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
union { const void *instance; storage_type storage; };
|
union {
|
||||||
|
const void *instance;
|
||||||
|
storage_type storage;
|
||||||
|
};
|
||||||
|
const type_info *info;
|
||||||
vtable_type *vtable;
|
vtable_type *vtable;
|
||||||
policy mode;
|
policy mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if two wrappers differ in their content.
|
* @brief Checks if two wrappers differ in their content.
|
||||||
* @tparam Len Size of the storage reserved for the small buffer optimization.
|
* @tparam Len Size of the storage reserved for the small buffer optimization.
|
||||||
@@ -369,7 +403,6 @@ template<std::size_t Len, std::size_t Align>
|
|||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Performs type-safe access to the contained object.
|
* @brief Performs type-safe access to the contained object.
|
||||||
* @tparam Type Type to which conversion is required.
|
* @tparam Type Type to which conversion is required.
|
||||||
@@ -380,47 +413,51 @@ template<std::size_t Len, std::size_t Align>
|
|||||||
*/
|
*/
|
||||||
template<typename Type, std::size_t Len, std::size_t Align>
|
template<typename Type, std::size_t Len, std::size_t Align>
|
||||||
Type any_cast(const basic_any<Len, Align> &data) ENTT_NOEXCEPT {
|
Type any_cast(const basic_any<Len, Align> &data) ENTT_NOEXCEPT {
|
||||||
const auto * const instance = any_cast<std::remove_reference_t<Type>>(&data);
|
const auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
|
||||||
ENTT_ASSERT(instance, "Invalid instance");
|
ENTT_ASSERT(instance, "Invalid instance");
|
||||||
return static_cast<Type>(*instance);
|
return static_cast<Type>(*instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc any_cast */
|
/*! @copydoc any_cast */
|
||||||
template<typename Type, std::size_t Len, std::size_t Align>
|
template<typename Type, std::size_t Len, std::size_t Align>
|
||||||
Type any_cast(basic_any<Len, Align> &data) ENTT_NOEXCEPT {
|
Type any_cast(basic_any<Len, Align> &data) ENTT_NOEXCEPT {
|
||||||
// forces const on non-reference types to make them work also with wrappers for const references
|
// forces const on non-reference types to make them work also with wrappers for const references
|
||||||
auto * const instance = any_cast<std::remove_reference_t<const Type>>(&data);
|
auto *const instance = any_cast<std::remove_reference_t<const Type>>(&data);
|
||||||
ENTT_ASSERT(instance, "Invalid instance");
|
ENTT_ASSERT(instance, "Invalid instance");
|
||||||
return static_cast<Type>(*instance);
|
return static_cast<Type>(*instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc any_cast */
|
/*! @copydoc any_cast */
|
||||||
template<typename Type, std::size_t Len, std::size_t Align>
|
template<typename Type, std::size_t Len, std::size_t Align>
|
||||||
Type any_cast(basic_any<Len, Align> &&data) ENTT_NOEXCEPT {
|
Type any_cast(basic_any<Len, Align> &&data) ENTT_NOEXCEPT {
|
||||||
// forces const on non-reference types to make them work also with wrappers for const references
|
if constexpr(std::is_copy_constructible_v<std::remove_cv_t<std::remove_reference_t<Type>>>) {
|
||||||
auto * const instance = any_cast<std::remove_reference_t<const Type>>(&data);
|
if(auto *const instance = any_cast<std::remove_reference_t<Type>>(&data); instance) {
|
||||||
ENTT_ASSERT(instance, "Invalid instance");
|
return static_cast<Type>(std::move(*instance));
|
||||||
return static_cast<Type>(std::move(*instance));
|
} else {
|
||||||
|
return any_cast<Type>(data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
|
||||||
|
ENTT_ASSERT(instance, "Invalid instance");
|
||||||
|
return static_cast<Type>(std::move(*instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc any_cast */
|
/*! @copydoc any_cast */
|
||||||
template<typename Type, std::size_t Len, std::size_t Align>
|
template<typename Type, std::size_t Len, std::size_t Align>
|
||||||
const Type * any_cast(const basic_any<Len, Align> *data) ENTT_NOEXCEPT {
|
const Type *any_cast(const basic_any<Len, Align> *data) ENTT_NOEXCEPT {
|
||||||
return (data->type() == type_id<Type>() ? static_cast<const Type *>(data->data()) : nullptr);
|
const auto &info = type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
|
||||||
|
return static_cast<const Type *>(data->data(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc any_cast */
|
/*! @copydoc any_cast */
|
||||||
template<typename Type, std::size_t Len, std::size_t Align>
|
template<typename Type, std::size_t Len, std::size_t Align>
|
||||||
Type * any_cast(basic_any<Len, Align> *data) ENTT_NOEXCEPT {
|
Type *any_cast(basic_any<Len, Align> *data) ENTT_NOEXCEPT {
|
||||||
|
const auto &info = type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
|
||||||
// last attempt to make wrappers for const references return their values
|
// last attempt to make wrappers for const references return their values
|
||||||
return (data->type() == type_id<Type>() ? static_cast<Type *>(static_cast<constness_as_t<basic_any<Len, Align>, Type> *>(data)->data()) : nullptr);
|
return static_cast<Type *>(static_cast<constness_as_t<basic_any<Len, Align>, Type> *>(data)->data(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a wrapper from a given type, passing it all arguments.
|
* @brief Constructs a wrapper from a given type, passing it all arguments.
|
||||||
* @tparam Type Type of object to use to initialize the wrapper.
|
* @tparam Type Type of object to use to initialize the wrapper.
|
||||||
@@ -431,11 +468,10 @@ Type * any_cast(basic_any<Len, Align> *data) ENTT_NOEXCEPT {
|
|||||||
* @return A properly initialized wrapper for an object of the given type.
|
* @return A properly initialized wrapper for an object of the given type.
|
||||||
*/
|
*/
|
||||||
template<typename Type, std::size_t Len = basic_any<>::length, std::size_t Align = basic_any<Len>::alignment, typename... Args>
|
template<typename Type, std::size_t Len = basic_any<>::length, std::size_t Align = basic_any<Len>::alignment, typename... Args>
|
||||||
basic_any<Len, Align> make_any(Args &&... args) {
|
basic_any<Len, Align> make_any(Args &&...args) {
|
||||||
return basic_any<Len, Align>{std::in_place_type<Type>, std::forward<Args>(args)...};
|
return basic_any<Len, Align>{std::in_place_type<Type>, std::forward<Args>(args)...};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Forwards its argument and avoids copies for lvalue references.
|
* @brief Forwards its argument and avoids copies for lvalue references.
|
||||||
* @tparam Len Size of the storage reserved for the small buffer optimization.
|
* @tparam Len Size of the storage reserved for the small buffer optimization.
|
||||||
@@ -449,8 +485,6 @@ basic_any<Len, Align> forward_as_any(Type &&value) {
|
|||||||
return basic_any<Len, Align>{std::in_place_type<std::conditional_t<std::is_rvalue_reference_v<Type>, std::decay_t<Type>, Type>>, std::forward<Type>(value)};
|
return basic_any<Len, Align>{std::in_place_type<std::conditional_t<std::is_rvalue_reference_v<Type>, std::decay_t<Type>, Type>>, std::forward<Type>(value)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,33 +1,30 @@
|
|||||||
#ifndef ENTT_CORE_ATTRIBUTE_H
|
#ifndef ENTT_CORE_ATTRIBUTE_H
|
||||||
#define ENTT_CORE_ATTRIBUTE_H
|
#define ENTT_CORE_ATTRIBUTE_H
|
||||||
|
|
||||||
|
|
||||||
#ifndef ENTT_EXPORT
|
#ifndef ENTT_EXPORT
|
||||||
# if defined _WIN32 || defined __CYGWIN__ || defined _MSC_VER
|
# if defined _WIN32 || defined __CYGWIN__ || defined _MSC_VER
|
||||||
# define ENTT_EXPORT __declspec(dllexport)
|
# define ENTT_EXPORT __declspec(dllexport)
|
||||||
# define ENTT_IMPORT __declspec(dllimport)
|
# define ENTT_IMPORT __declspec(dllimport)
|
||||||
# define ENTT_HIDDEN
|
# define ENTT_HIDDEN
|
||||||
# elif defined __GNUC__ && __GNUC__ >= 4
|
# elif defined __GNUC__ && __GNUC__ >= 4
|
||||||
# define ENTT_EXPORT __attribute__((visibility("default")))
|
# define ENTT_EXPORT __attribute__((visibility("default")))
|
||||||
# define ENTT_IMPORT __attribute__((visibility("default")))
|
# define ENTT_IMPORT __attribute__((visibility("default")))
|
||||||
# define ENTT_HIDDEN __attribute__((visibility("hidden")))
|
# define ENTT_HIDDEN __attribute__((visibility("hidden")))
|
||||||
# else /* Unsupported compiler */
|
# else /* Unsupported compiler */
|
||||||
# define ENTT_EXPORT
|
# define ENTT_EXPORT
|
||||||
# define ENTT_IMPORT
|
# define ENTT_IMPORT
|
||||||
# define ENTT_HIDDEN
|
# define ENTT_HIDDEN
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef ENTT_API
|
#ifndef ENTT_API
|
||||||
# if defined ENTT_API_EXPORT
|
# if defined ENTT_API_EXPORT
|
||||||
# define ENTT_API ENTT_EXPORT
|
# define ENTT_API ENTT_EXPORT
|
||||||
# elif defined ENTT_API_IMPORT
|
# elif defined ENTT_API_IMPORT
|
||||||
# define ENTT_API ENTT_IMPORT
|
# define ENTT_API ENTT_IMPORT
|
||||||
# else /* No API */
|
# else /* No API */
|
||||||
# define ENTT_API
|
# define ENTT_API
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
280
src/entt/core/compressed_pair.hpp
Normal file
280
src/entt/core/compressed_pair.hpp
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
#ifndef ENTT_CORE_COMPRESSED_PAIR_HPP
|
||||||
|
#define ENTT_CORE_COMPRESSED_PAIR_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include "../config/config.h"
|
||||||
|
#include "type_traits.hpp"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename Type, std::size_t, typename = void>
|
||||||
|
struct compressed_pair_element {
|
||||||
|
using reference = Type &;
|
||||||
|
using const_reference = const Type &;
|
||||||
|
|
||||||
|
template<bool Dummy = true, typename = std::enable_if_t<Dummy && std::is_default_constructible_v<Type>>>
|
||||||
|
compressed_pair_element()
|
||||||
|
: value{} {}
|
||||||
|
|
||||||
|
template<typename Args, typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Args>>, compressed_pair_element>>>
|
||||||
|
compressed_pair_element(Args &&args)
|
||||||
|
: value{std::forward<Args>(args)} {}
|
||||||
|
|
||||||
|
template<typename... Args, std::size_t... Index>
|
||||||
|
compressed_pair_element(std::tuple<Args...> args, std::index_sequence<Index...>)
|
||||||
|
: value{std::forward<Args>(std::get<Index>(args))...} {}
|
||||||
|
|
||||||
|
[[nodiscard]] reference get() ENTT_NOEXCEPT {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const_reference get() const ENTT_NOEXCEPT {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type value;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Type, std::size_t Tag>
|
||||||
|
struct compressed_pair_element<Type, Tag, std::enable_if_t<is_ebco_eligible_v<Type>>>: Type {
|
||||||
|
using reference = Type &;
|
||||||
|
using const_reference = const Type &;
|
||||||
|
using base_type = Type;
|
||||||
|
|
||||||
|
template<bool Dummy = true, typename = std::enable_if_t<Dummy && std::is_default_constructible_v<base_type>>>
|
||||||
|
compressed_pair_element()
|
||||||
|
: base_type{} {}
|
||||||
|
|
||||||
|
template<typename Args, typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Args>>, compressed_pair_element>>>
|
||||||
|
compressed_pair_element(Args &&args)
|
||||||
|
: base_type{std::forward<Args>(args)} {}
|
||||||
|
|
||||||
|
template<typename... Args, std::size_t... Index>
|
||||||
|
compressed_pair_element(std::tuple<Args...> args, std::index_sequence<Index...>)
|
||||||
|
: base_type{std::forward<Args>(std::get<Index>(args))...} {}
|
||||||
|
|
||||||
|
[[nodiscard]] reference get() ENTT_NOEXCEPT {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const_reference get() const ENTT_NOEXCEPT {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A compressed pair.
|
||||||
|
*
|
||||||
|
* A pair that exploits the _Empty Base Class Optimization_ (or _EBCO_) to
|
||||||
|
* reduce its final size to a minimum.
|
||||||
|
*
|
||||||
|
* @tparam First The type of the first element that the pair stores.
|
||||||
|
* @tparam Second The type of the second element that the pair stores.
|
||||||
|
*/
|
||||||
|
template<typename First, typename Second>
|
||||||
|
class compressed_pair final
|
||||||
|
: internal::compressed_pair_element<First, 0u>,
|
||||||
|
internal::compressed_pair_element<Second, 1u> {
|
||||||
|
using first_base = internal::compressed_pair_element<First, 0u>;
|
||||||
|
using second_base = internal::compressed_pair_element<Second, 1u>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*! @brief The type of the first element that the pair stores. */
|
||||||
|
using first_type = First;
|
||||||
|
/*! @brief The type of the second element that the pair stores. */
|
||||||
|
using second_type = Second;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default constructor, conditionally enabled.
|
||||||
|
*
|
||||||
|
* This constructor is only available when the types that the pair stores
|
||||||
|
* are both at least default constructible.
|
||||||
|
*
|
||||||
|
* @tparam Dummy Dummy template parameter used for internal purposes.
|
||||||
|
*/
|
||||||
|
template<bool Dummy = true, typename = std::enable_if_t<Dummy && std::is_default_constructible_v<first_type> && std::is_default_constructible_v<second_type>>>
|
||||||
|
constexpr compressed_pair()
|
||||||
|
: first_base{},
|
||||||
|
second_base{} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Copy constructor.
|
||||||
|
* @param other The instance to copy from.
|
||||||
|
*/
|
||||||
|
constexpr compressed_pair(const compressed_pair &other) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Move constructor.
|
||||||
|
* @param other The instance to move from.
|
||||||
|
*/
|
||||||
|
constexpr compressed_pair(compressed_pair &&other) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs a pair from its values.
|
||||||
|
* @tparam Arg Type of value to use to initialize the first element.
|
||||||
|
* @tparam Other Type of value to use to initialize the second element.
|
||||||
|
* @param arg Value to use to initialize the first element.
|
||||||
|
* @param other Value to use to initialize the second element.
|
||||||
|
*/
|
||||||
|
template<typename Arg, typename Other>
|
||||||
|
constexpr compressed_pair(Arg &&arg, Other &&other)
|
||||||
|
: first_base{std::forward<Arg>(arg)},
|
||||||
|
second_base{std::forward<Other>(other)} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs a pair by forwarding the arguments to its parts.
|
||||||
|
* @tparam Args Types of arguments to use to initialize the first element.
|
||||||
|
* @tparam Other Types of arguments to use to initialize the second element.
|
||||||
|
* @param args Arguments to use to initialize the first element.
|
||||||
|
* @param other Arguments to use to initialize the second element.
|
||||||
|
*/
|
||||||
|
template<typename... Args, typename... Other>
|
||||||
|
constexpr compressed_pair(std::piecewise_construct_t, std::tuple<Args...> args, std::tuple<Other...> other)
|
||||||
|
: first_base{std::move(args), std::index_sequence_for<Args...>{}},
|
||||||
|
second_base{std::move(other), std::index_sequence_for<Other...>{}} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Copy assignment operator.
|
||||||
|
* @param other The instance to copy from.
|
||||||
|
* @return This compressed pair object.
|
||||||
|
*/
|
||||||
|
constexpr compressed_pair &operator=(const compressed_pair &other) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Move assignment operator.
|
||||||
|
* @param other The instance to move from.
|
||||||
|
* @return This compressed pair object.
|
||||||
|
*/
|
||||||
|
constexpr compressed_pair &operator=(compressed_pair &&other) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the first element that a pair stores.
|
||||||
|
* @return The first element that a pair stores.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] first_type &first() ENTT_NOEXCEPT {
|
||||||
|
return static_cast<first_base &>(*this).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc first */
|
||||||
|
[[nodiscard]] const first_type &first() const ENTT_NOEXCEPT {
|
||||||
|
return static_cast<const first_base &>(*this).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the second element that a pair stores.
|
||||||
|
* @return The second element that a pair stores.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] second_type &second() ENTT_NOEXCEPT {
|
||||||
|
return static_cast<second_base &>(*this).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc second */
|
||||||
|
[[nodiscard]] const second_type &second() const ENTT_NOEXCEPT {
|
||||||
|
return static_cast<const second_base &>(*this).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Swaps two compressed pair objects.
|
||||||
|
* @param other The compressed pair to swap with.
|
||||||
|
*/
|
||||||
|
void swap(compressed_pair &other) {
|
||||||
|
using std::swap;
|
||||||
|
swap(first(), other.first());
|
||||||
|
swap(second(), other.second());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Extracts an element from the compressed pair.
|
||||||
|
* @tparam Index An integer value that is either 0 or 1.
|
||||||
|
* @return Returns a reference to the first element if `Index` is 0 and a
|
||||||
|
* reference to the second element if `Index` is 1.
|
||||||
|
*/
|
||||||
|
template<std::size_t Index>
|
||||||
|
decltype(auto) get() ENTT_NOEXCEPT {
|
||||||
|
if constexpr(Index == 0u) {
|
||||||
|
return first();
|
||||||
|
} else {
|
||||||
|
static_assert(Index == 1u, "Index out of bounds");
|
||||||
|
return second();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc get */
|
||||||
|
template<std::size_t Index>
|
||||||
|
decltype(auto) get() const ENTT_NOEXCEPT {
|
||||||
|
if constexpr(Index == 0u) {
|
||||||
|
return first();
|
||||||
|
} else {
|
||||||
|
static_assert(Index == 1u, "Index out of bounds");
|
||||||
|
return second();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deduction guide.
|
||||||
|
* @tparam Type Type of value to use to initialize the first element.
|
||||||
|
* @tparam Other Type of value to use to initialize the second element.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Other>
|
||||||
|
compressed_pair(Type &&, Other &&) -> compressed_pair<std::decay_t<Type>, std::decay_t<Other>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Swaps two compressed pair objects.
|
||||||
|
* @tparam First The type of the first element that the pairs store.
|
||||||
|
* @tparam Second The type of the second element that the pairs store.
|
||||||
|
* @param lhs A valid compressed pair object.
|
||||||
|
* @param rhs A valid compressed pair object.
|
||||||
|
*/
|
||||||
|
template<typename First, typename Second>
|
||||||
|
inline void swap(compressed_pair<First, Second> &lhs, compressed_pair<First, Second> &rhs) {
|
||||||
|
lhs.swap(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
// disable structured binding support for clang 6, it messes when specializing tuple_size
|
||||||
|
#if !defined __clang_major__ || __clang_major__ > 6
|
||||||
|
namespace std {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief `std::tuple_size` specialization for `compressed_pair`s.
|
||||||
|
* @tparam First The type of the first element that the pair stores.
|
||||||
|
* @tparam Second The type of the second element that the pair stores.
|
||||||
|
*/
|
||||||
|
template<typename First, typename Second>
|
||||||
|
struct tuple_size<entt::compressed_pair<First, Second>>: integral_constant<size_t, 2u> {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief `std::tuple_element` specialization for `compressed_pair`s.
|
||||||
|
* @tparam Index The index of the type to return.
|
||||||
|
* @tparam First The type of the first element that the pair stores.
|
||||||
|
* @tparam Second The type of the second element that the pair stores.
|
||||||
|
*/
|
||||||
|
template<size_t Index, typename First, typename Second>
|
||||||
|
struct tuple_element<Index, entt::compressed_pair<First, Second>>: conditional<Index == 0u, First, Second> {
|
||||||
|
static_assert(Index < 2u, "Index out of bounds");
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
98
src/entt/core/enum.hpp
Normal file
98
src/entt/core/enum.hpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#ifndef ENTT_CORE_ENUM_HPP
|
||||||
|
#define ENTT_CORE_ENUM_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable bitmask support for enum classes.
|
||||||
|
* @tparam Type The enum type for which to enable bitmask support.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename = void>
|
||||||
|
struct enum_as_bitmask: std::false_type {};
|
||||||
|
|
||||||
|
/*! @copydoc enum_as_bitmask */
|
||||||
|
template<typename Type>
|
||||||
|
struct enum_as_bitmask<Type, std::void_t<decltype(Type::_entt_enum_as_bitmask)>>: std::is_enum<Type> {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper variable template.
|
||||||
|
* @tparam Type The enum class type for which to enable bitmask support.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
inline constexpr bool enum_as_bitmask_v = enum_as_bitmask<Type>::value;
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Operator available for enums for which bitmask support is enabled.
|
||||||
|
* @tparam Type Enum class type.
|
||||||
|
* @param lhs The first value to use.
|
||||||
|
* @param rhs The second value to use.
|
||||||
|
* @return The result of invoking the operator on the underlying types of the
|
||||||
|
* two values provided.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
|
||||||
|
operator|(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
|
||||||
|
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc operator| */
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
|
||||||
|
operator&(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
|
||||||
|
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc operator| */
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
|
||||||
|
operator^(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
|
||||||
|
return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Operator available for enums for which bitmask support is enabled.
|
||||||
|
* @tparam Type Enum class type.
|
||||||
|
* @param value The value to use.
|
||||||
|
* @return The result of invoking the operator on the underlying types of the
|
||||||
|
* value provided.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
|
||||||
|
operator~(const Type value) ENTT_NOEXCEPT {
|
||||||
|
return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc operator~ */
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, bool>
|
||||||
|
operator!(const Type value) ENTT_NOEXCEPT {
|
||||||
|
return !static_cast<std::underlying_type_t<Type>>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc operator| */
|
||||||
|
template<typename Type>
|
||||||
|
constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
|
||||||
|
operator|=(Type &lhs, const Type rhs) ENTT_NOEXCEPT {
|
||||||
|
return (lhs = (lhs | rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc operator| */
|
||||||
|
template<typename Type>
|
||||||
|
constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
|
||||||
|
operator&=(Type &lhs, const Type rhs) ENTT_NOEXCEPT {
|
||||||
|
return (lhs = (lhs & rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc operator| */
|
||||||
|
template<typename Type>
|
||||||
|
constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
|
||||||
|
operator^=(Type &lhs, const Type rhs) ENTT_NOEXCEPT {
|
||||||
|
return (lhs = (lhs ^ rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
#ifndef ENTT_CORE_FAMILY_HPP
|
#ifndef ENTT_CORE_FAMILY_HPP
|
||||||
#define ENTT_CORE_FAMILY_HPP
|
#define ENTT_CORE_FAMILY_HPP
|
||||||
|
|
||||||
|
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Dynamic identifier generator.
|
* @brief Dynamic identifier generator.
|
||||||
*
|
*
|
||||||
@@ -30,8 +27,6 @@ public:
|
|||||||
inline static const family_type type = identifier++;
|
inline static const family_type type = identifier++;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,27 +1,21 @@
|
|||||||
#ifndef ENTT_CORE_FWD_HPP
|
#ifndef ENTT_CORE_FWD_HPP
|
||||||
#define ENTT_CORE_FWD_HPP
|
#define ENTT_CORE_FWD_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
template<std::size_t Len = sizeof(double[2]), std::size_t = alignof(typename std::aligned_storage_t<Len + !Len>)>
|
template<std::size_t Len = sizeof(double[2]), std::size_t = alignof(typename std::aligned_storage_t<Len + !Len>)>
|
||||||
class basic_any;
|
class basic_any;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for type identifiers. */
|
/*! @brief Alias declaration for type identifiers. */
|
||||||
using id_type = ENTT_ID_TYPE;
|
using id_type = ENTT_ID_TYPE;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using any = basic_any<>;
|
using any = basic_any<>;
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,29 +1,23 @@
|
|||||||
#ifndef ENTT_CORE_HASHED_STRING_HPP
|
#ifndef ENTT_CORE_HASHED_STRING_HPP
|
||||||
#define ENTT_CORE_HASHED_STRING_HPP
|
#define ENTT_CORE_HASHED_STRING_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @cond TURN_OFF_DOXYGEN
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
struct fnv1a_traits;
|
struct fnv1a_traits;
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct fnv1a_traits<std::uint32_t> {
|
struct fnv1a_traits<std::uint32_t> {
|
||||||
using type = std::uint32_t;
|
using type = std::uint32_t;
|
||||||
@@ -31,7 +25,6 @@ struct fnv1a_traits<std::uint32_t> {
|
|||||||
static constexpr std::uint32_t prime = 16777619;
|
static constexpr std::uint32_t prime = 16777619;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct fnv1a_traits<std::uint64_t> {
|
struct fnv1a_traits<std::uint64_t> {
|
||||||
using type = std::uint64_t;
|
using type = std::uint64_t;
|
||||||
@@ -39,84 +32,99 @@ struct fnv1a_traits<std::uint64_t> {
|
|||||||
static constexpr std::uint64_t prime = 1099511628211ull;
|
static constexpr std::uint64_t prime = 1099511628211ull;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Char>
|
||||||
|
struct basic_hashed_string {
|
||||||
|
using value_type = Char;
|
||||||
|
using size_type = std::size_t;
|
||||||
|
using hash_type = id_type;
|
||||||
|
|
||||||
}
|
const value_type *repr;
|
||||||
|
size_type length;
|
||||||
|
hash_type hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Zero overhead unique identifier.
|
* @brief Zero overhead unique identifier.
|
||||||
*
|
*
|
||||||
* A hashed string is a compile-time tool that allows users to use
|
* A hashed string is a compile-time tool that allows users to use
|
||||||
* human-readable identifers in the codebase while using their numeric
|
* human-readable identifiers in the codebase while using their numeric
|
||||||
* counterparts at runtime.<br/>
|
* counterparts at runtime.<br/>
|
||||||
* Because of that, a hashed string can also be used in constant expressions if
|
* Because of that, a hashed string can also be used in constant expressions if
|
||||||
* required.
|
* required.
|
||||||
*
|
*
|
||||||
|
* @warning
|
||||||
|
* This class doesn't take ownership of user-supplied strings nor does it make a
|
||||||
|
* copy of them.
|
||||||
|
*
|
||||||
* @tparam Char Character type.
|
* @tparam Char Character type.
|
||||||
*/
|
*/
|
||||||
template<typename Char>
|
template<typename Char>
|
||||||
class basic_hashed_string {
|
class basic_hashed_string: internal::basic_hashed_string<Char> {
|
||||||
using traits_type = internal::fnv1a_traits<id_type>;
|
using base_type = internal::basic_hashed_string<Char>;
|
||||||
|
using hs_traits = internal::fnv1a_traits<id_type>;
|
||||||
|
|
||||||
struct const_wrapper {
|
struct const_wrapper {
|
||||||
// non-explicit constructor on purpose
|
// non-explicit constructor on purpose
|
||||||
constexpr const_wrapper(const Char *curr) ENTT_NOEXCEPT: str{curr} {}
|
constexpr const_wrapper(const Char *str) ENTT_NOEXCEPT: repr{str} {}
|
||||||
const Char *str;
|
const Char *repr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fowler–Noll–Vo hash function v. 1a - the good
|
// Fowler–Noll–Vo hash function v. 1a - the good
|
||||||
[[nodiscard]] static constexpr id_type helper(const Char *curr) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr auto helper(const Char *str) ENTT_NOEXCEPT {
|
||||||
auto value = traits_type::offset;
|
base_type base{str, 0u, hs_traits::offset};
|
||||||
|
|
||||||
while(*curr != 0) {
|
for(; str[base.length]; ++base.length) {
|
||||||
value = (value ^ static_cast<traits_type::type>(*(curr++))) * traits_type::prime;
|
base.hash = (base.hash ^ static_cast<hs_traits::type>(str[base.length])) * hs_traits::prime;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fowler–Noll–Vo hash function v. 1a - the good
|
||||||
|
[[nodiscard]] static constexpr auto helper(const Char *str, const std::size_t len) ENTT_NOEXCEPT {
|
||||||
|
base_type base{str, len, hs_traits::offset};
|
||||||
|
|
||||||
|
for(size_type pos{}; pos < len; ++pos) {
|
||||||
|
base.hash = (base.hash ^ static_cast<hs_traits::type>(str[pos])) * hs_traits::prime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief Character type. */
|
/*! @brief Character type. */
|
||||||
using value_type = Char;
|
using value_type = typename base_type::value_type;
|
||||||
/*! @brief Unsigned integer type. */
|
/*! @brief Unsigned integer type. */
|
||||||
using hash_type = id_type;
|
using size_type = typename base_type::size_type;
|
||||||
|
/*! @brief Unsigned integer type. */
|
||||||
|
using hash_type = typename base_type::hash_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns directly the numeric representation of a string view.
|
* @brief Returns directly the numeric representation of a string view.
|
||||||
* @param str Human-readable identifer.
|
* @param str Human-readable identifier.
|
||||||
* @param size Length of the string to hash.
|
* @param len Length of the string to hash.
|
||||||
* @return The numeric representation of the string.
|
* @return The numeric representation of the string.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static constexpr hash_type value(const value_type *str, std::size_t size) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr hash_type value(const value_type *str, const size_type len) ENTT_NOEXCEPT {
|
||||||
id_type partial{traits_type::offset};
|
return basic_hashed_string{str, len};
|
||||||
while(size--) { partial = (partial^(str++)[0])*traits_type::prime; }
|
|
||||||
return partial;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns directly the numeric representation of a string.
|
* @brief Returns directly the numeric representation of a string.
|
||||||
*
|
|
||||||
* Forcing template resolution avoids implicit conversions. An
|
|
||||||
* human-readable identifier can be anything but a plain, old bunch of
|
|
||||||
* characters.<br/>
|
|
||||||
* Example of use:
|
|
||||||
* @code{.cpp}
|
|
||||||
* const auto value = basic_hashed_string<char>::to_value("my.png");
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* @tparam N Number of characters of the identifier.
|
* @tparam N Number of characters of the identifier.
|
||||||
* @param str Human-readable identifer.
|
* @param str Human-readable identifier.
|
||||||
* @return The numeric representation of the string.
|
* @return The numeric representation of the string.
|
||||||
*/
|
*/
|
||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
[[nodiscard]] static constexpr hash_type value(const value_type (&str)[N]) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr hash_type value(const value_type (&str)[N]) ENTT_NOEXCEPT {
|
||||||
return helper(str);
|
return basic_hashed_string{str};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,97 +132,98 @@ public:
|
|||||||
* @param wrapper Helps achieving the purpose by relying on overloading.
|
* @param wrapper Helps achieving the purpose by relying on overloading.
|
||||||
* @return The numeric representation of the string.
|
* @return The numeric representation of the string.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static hash_type value(const_wrapper wrapper) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr hash_type value(const_wrapper wrapper) ENTT_NOEXCEPT {
|
||||||
return helper(wrapper.str);
|
return basic_hashed_string{wrapper};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @brief Constructs an empty hashed string. */
|
/*! @brief Constructs an empty hashed string. */
|
||||||
constexpr basic_hashed_string() ENTT_NOEXCEPT
|
constexpr basic_hashed_string() ENTT_NOEXCEPT
|
||||||
: str{nullptr}, hash{}
|
: base_type{} {}
|
||||||
{}
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs a hashed string from a string view.
|
||||||
|
* @param str Human-readable identifier.
|
||||||
|
* @param len Length of the string to hash.
|
||||||
|
*/
|
||||||
|
constexpr basic_hashed_string(const value_type *str, const size_type len) ENTT_NOEXCEPT
|
||||||
|
: base_type{helper(str, len)} {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a hashed string from an array of const characters.
|
* @brief Constructs a hashed string from an array of const characters.
|
||||||
*
|
|
||||||
* Forcing template resolution avoids implicit conversions. An
|
|
||||||
* human-readable identifier can be anything but a plain, old bunch of
|
|
||||||
* characters.<br/>
|
|
||||||
* Example of use:
|
|
||||||
* @code{.cpp}
|
|
||||||
* basic_hashed_string<char> hs{"my.png"};
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* @tparam N Number of characters of the identifier.
|
* @tparam N Number of characters of the identifier.
|
||||||
* @param curr Human-readable identifer.
|
* @param str Human-readable identifier.
|
||||||
*/
|
*/
|
||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
constexpr basic_hashed_string(const value_type (&curr)[N]) ENTT_NOEXCEPT
|
constexpr basic_hashed_string(const value_type (&str)[N]) ENTT_NOEXCEPT
|
||||||
: str{curr}, hash{helper(curr)}
|
: base_type{helper(str)} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Explicit constructor on purpose to avoid constructing a hashed
|
* @brief Explicit constructor on purpose to avoid constructing a hashed
|
||||||
* string directly from a `const value_type *`.
|
* string directly from a `const value_type *`.
|
||||||
|
*
|
||||||
|
* @warning
|
||||||
|
* The lifetime of the string is not extended nor is it copied.
|
||||||
|
*
|
||||||
* @param wrapper Helps achieving the purpose by relying on overloading.
|
* @param wrapper Helps achieving the purpose by relying on overloading.
|
||||||
*/
|
*/
|
||||||
explicit constexpr basic_hashed_string(const_wrapper wrapper) ENTT_NOEXCEPT
|
explicit constexpr basic_hashed_string(const_wrapper wrapper) ENTT_NOEXCEPT
|
||||||
: str{wrapper.str}, hash{helper(wrapper.str)}
|
: base_type{helper(wrapper.repr)} {}
|
||||||
{}
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the size a hashed string.
|
||||||
|
* @return The size of the hashed string.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr size_type size() const ENTT_NOEXCEPT {
|
||||||
|
return base_type::length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the human-readable representation of a hashed string.
|
* @brief Returns the human-readable representation of a hashed string.
|
||||||
* @return The string used to initialize the instance.
|
* @return The string used to initialize the hashed string.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] constexpr const value_type * data() const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr const value_type *data() const ENTT_NOEXCEPT {
|
||||||
return str;
|
return base_type::repr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the numeric representation of a hashed string.
|
* @brief Returns the numeric representation of a hashed string.
|
||||||
* @return The numeric representation of the instance.
|
* @return The numeric representation of the hashed string.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] constexpr hash_type value() const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr hash_type value() const ENTT_NOEXCEPT {
|
||||||
return hash;
|
return base_type::hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc data */
|
/*! @copydoc data */
|
||||||
[[nodiscard]] constexpr operator const value_type *() const ENTT_NOEXCEPT { return data(); }
|
[[nodiscard]] constexpr operator const value_type *() const ENTT_NOEXCEPT {
|
||||||
|
return data();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the numeric representation of a hashed string.
|
* @brief Returns the numeric representation of a hashed string.
|
||||||
* @return The numeric representation of the instance.
|
* @return The numeric representation of the hashed string.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] constexpr operator hash_type() const ENTT_NOEXCEPT { return value(); }
|
[[nodiscard]] constexpr operator hash_type() const ENTT_NOEXCEPT {
|
||||||
|
return value();
|
||||||
/**
|
|
||||||
* @brief Compares two hashed strings.
|
|
||||||
* @param other Hashed string with which to compare.
|
|
||||||
* @return True if the two hashed strings are identical, false otherwise.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] constexpr bool operator==(const basic_hashed_string &other) const ENTT_NOEXCEPT {
|
|
||||||
return hash == other.hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
const value_type *str;
|
|
||||||
hash_type hash;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deduction guide.
|
* @brief Deduction guide.
|
||||||
*
|
* @tparam Char Character type.
|
||||||
* It allows to deduce the character type of the hashed string directly from a
|
* @param str Human-readable identifier.
|
||||||
* human-readable identifer provided to the constructor.
|
* @param len Length of the string to hash.
|
||||||
*
|
*/
|
||||||
|
template<typename Char>
|
||||||
|
basic_hashed_string(const Char *str, const std::size_t len) -> basic_hashed_string<Char>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deduction guide.
|
||||||
* @tparam Char Character type.
|
* @tparam Char Character type.
|
||||||
* @tparam N Number of characters of the identifier.
|
* @tparam N Number of characters of the identifier.
|
||||||
* @param str Human-readable identifer.
|
* @param str Human-readable identifier.
|
||||||
*/
|
*/
|
||||||
template<typename Char, std::size_t N>
|
template<typename Char, std::size_t N>
|
||||||
basic_hashed_string(const Char (&str)[N])
|
basic_hashed_string(const Char (&str)[N]) -> basic_hashed_string<Char>;
|
||||||
-> basic_hashed_string<Char>;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares two hashed strings.
|
* @brief Compares two hashed strings.
|
||||||
@@ -224,46 +233,101 @@ basic_hashed_string(const Char (&str)[N])
|
|||||||
* @return True if the two hashed strings are identical, false otherwise.
|
* @return True if the two hashed strings are identical, false otherwise.
|
||||||
*/
|
*/
|
||||||
template<typename Char>
|
template<typename Char>
|
||||||
|
[[nodiscard]] constexpr bool operator==(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.value() == rhs.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two hashed strings.
|
||||||
|
* @tparam Char Character type.
|
||||||
|
* @param lhs A valid hashed string.
|
||||||
|
* @param rhs A valid hashed string.
|
||||||
|
* @return True if the two hashed strings differ, false otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Char>
|
||||||
[[nodiscard]] constexpr bool operator!=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr bool operator!=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two hashed strings.
|
||||||
|
* @tparam Char Character type.
|
||||||
|
* @param lhs A valid hashed string.
|
||||||
|
* @param rhs A valid hashed string.
|
||||||
|
* @return True if the first element is less than the second, false otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Char>
|
||||||
|
[[nodiscard]] constexpr bool operator<(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.value() < rhs.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two hashed strings.
|
||||||
|
* @tparam Char Character type.
|
||||||
|
* @param lhs A valid hashed string.
|
||||||
|
* @param rhs A valid hashed string.
|
||||||
|
* @return True if the first element is less than or equal to the second, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Char>
|
||||||
|
[[nodiscard]] constexpr bool operator<=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(rhs < lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two hashed strings.
|
||||||
|
* @tparam Char Character type.
|
||||||
|
* @param lhs A valid hashed string.
|
||||||
|
* @param rhs A valid hashed string.
|
||||||
|
* @return True if the first element is greater than the second, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Char>
|
||||||
|
[[nodiscard]] constexpr bool operator>(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return rhs < lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two hashed strings.
|
||||||
|
* @tparam Char Character type.
|
||||||
|
* @param lhs A valid hashed string.
|
||||||
|
* @param rhs A valid hashed string.
|
||||||
|
* @return True if the first element is greater than or equal to the second,
|
||||||
|
* false otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Char>
|
||||||
|
[[nodiscard]] constexpr bool operator>=(const basic_hashed_string<Char> &lhs, const basic_hashed_string<Char> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs < rhs);
|
||||||
|
}
|
||||||
|
|
||||||
/*! @brief Aliases for common character types. */
|
/*! @brief Aliases for common character types. */
|
||||||
using hashed_string = basic_hashed_string<char>;
|
using hashed_string = basic_hashed_string<char>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Aliases for common character types. */
|
/*! @brief Aliases for common character types. */
|
||||||
using hashed_wstring = basic_hashed_string<wchar_t>;
|
using hashed_wstring = basic_hashed_string<wchar_t>;
|
||||||
|
|
||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User defined literal for hashed strings.
|
* @brief User defined literal for hashed strings.
|
||||||
* @param str The literal without its suffix.
|
* @param str The literal without its suffix.
|
||||||
* @return A properly initialized hashed string.
|
* @return A properly initialized hashed string.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] constexpr entt::hashed_string operator"" _hs(const char *str, std::size_t) ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr hashed_string operator"" _hs(const char *str, std::size_t) ENTT_NOEXCEPT {
|
||||||
return entt::hashed_string{str};
|
return hashed_string{str};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User defined literal for hashed wstrings.
|
* @brief User defined literal for hashed wstrings.
|
||||||
* @param str The literal without its suffix.
|
* @param str The literal without its suffix.
|
||||||
* @return A properly initialized hashed wstring.
|
* @return A properly initialized hashed wstring.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] constexpr entt::hashed_wstring operator"" _hws(const wchar_t *str, std::size_t) ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr hashed_wstring operator"" _hws(const wchar_t *str, std::size_t) ENTT_NOEXCEPT {
|
||||||
return entt::hashed_wstring{str};
|
return hashed_wstring{str};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace literals
|
||||||
|
|
||||||
}
|
} // namespace entt
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
#ifndef ENTT_CORE_IDENT_HPP
|
#ifndef ENTT_CORE_IDENT_HPP
|
||||||
#define ENTT_CORE_IDENT_HPP
|
#define ENTT_CORE_IDENT_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <utility>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
#include "type_traits.hpp"
|
#include "type_traits.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Types identifiers.
|
* @brief Types identifiers.
|
||||||
*
|
*
|
||||||
@@ -43,8 +40,8 @@ namespace entt {
|
|||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
class identifier {
|
class identifier {
|
||||||
template<typename Type, std::size_t... Index>
|
template<typename Type, std::size_t... Index>
|
||||||
[[nodiscard]] static constexpr id_type get(std::index_sequence<Index...>) {
|
[[nodiscard]] static constexpr id_type get(std::index_sequence<Index...>) ENTT_NOEXCEPT {
|
||||||
static_assert(std::disjunction_v<std::is_same<Type, Types>...>, "Invalid type");
|
static_assert((std::is_same_v<Type, Types> || ...), "Invalid type");
|
||||||
return (0 + ... + (std::is_same_v<Type, type_list_element_t<Index, type_list<std::decay_t<Types>...>>> ? id_type{Index} : id_type{}));
|
return (0 + ... + (std::is_same_v<Type, type_list_element_t<Index, type_list<std::decay_t<Types>...>>> ? id_type{Index} : id_type{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +54,6 @@ public:
|
|||||||
static constexpr identifier_type type = get<std::decay_t<Type>>(std::index_sequence_for<Types...>{});
|
static constexpr identifier_type type = get<std::decay_t<Type>>(std::index_sequence_for<Types...>{});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
117
src/entt/core/iterator.hpp
Normal file
117
src/entt/core/iterator.hpp
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
#ifndef ENTT_CORE_ITERATOR_HPP
|
||||||
|
#define ENTT_CORE_ITERATOR_HPP
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper type to use as pointer with input iterators.
|
||||||
|
* @tparam Type of wrapped value.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
struct input_iterator_pointer final {
|
||||||
|
/*! @brief Pointer type. */
|
||||||
|
using pointer = Type *;
|
||||||
|
|
||||||
|
/*! @brief Default copy constructor, deleted on purpose. */
|
||||||
|
input_iterator_pointer(const input_iterator_pointer &) = delete;
|
||||||
|
|
||||||
|
/*! @brief Default move constructor. */
|
||||||
|
input_iterator_pointer(input_iterator_pointer &&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs a proxy object by move.
|
||||||
|
* @param val Value to use to initialize the proxy object.
|
||||||
|
*/
|
||||||
|
input_iterator_pointer(Type &&val)
|
||||||
|
: value{std::move(val)} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default copy assignment operator, deleted on purpose.
|
||||||
|
* @return This proxy object.
|
||||||
|
*/
|
||||||
|
input_iterator_pointer &operator=(const input_iterator_pointer &) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default move assignment operator.
|
||||||
|
* @return This proxy object.
|
||||||
|
*/
|
||||||
|
input_iterator_pointer &operator=(input_iterator_pointer &&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Access operator for accessing wrapped values.
|
||||||
|
* @return A pointer to the wrapped value.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] pointer operator->() ENTT_NOEXCEPT {
|
||||||
|
return std::addressof(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utility class to create an iterable object from a pair of iterators.
|
||||||
|
* @tparam It Type of iterator.
|
||||||
|
* @tparam Sentinel Type of sentinel.
|
||||||
|
*/
|
||||||
|
template<typename It, typename Sentinel = It>
|
||||||
|
struct iterable_adaptor final {
|
||||||
|
/*! @brief Value type. */
|
||||||
|
using value_type = typename std::iterator_traits<It>::value_type;
|
||||||
|
/*! @brief Iterator type. */
|
||||||
|
using iterator = It;
|
||||||
|
/*! @brief Sentinel type. */
|
||||||
|
using sentinel = Sentinel;
|
||||||
|
|
||||||
|
/*! @brief Default constructor. */
|
||||||
|
iterable_adaptor() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates an iterable object from a pair of iterators.
|
||||||
|
* @param from Begin iterator.
|
||||||
|
* @param to End iterator.
|
||||||
|
*/
|
||||||
|
iterable_adaptor(iterator from, sentinel to)
|
||||||
|
: first{from},
|
||||||
|
last{to} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning.
|
||||||
|
* @return An iterator to the first element of the range.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end.
|
||||||
|
* @return An iterator to the element following the last element of the
|
||||||
|
* range.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] sentinel end() const ENTT_NOEXCEPT {
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc begin */
|
||||||
|
[[nodiscard]] iterator cbegin() const ENTT_NOEXCEPT {
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc end */
|
||||||
|
[[nodiscard]] sentinel cend() const ENTT_NOEXCEPT {
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
It first;
|
||||||
|
Sentinel last;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
#endif
|
||||||
289
src/entt/core/memory.hpp
Normal file
289
src/entt/core/memory.hpp
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
#ifndef ENTT_CORE_MEMORY_HPP
|
||||||
|
#define ENTT_CORE_MEMORY_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <limits>
|
||||||
|
#include <memory>
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unwraps fancy pointers, does nothing otherwise (waiting for C++20).
|
||||||
|
* @tparam Type Pointer type.
|
||||||
|
* @param ptr Fancy or raw pointer.
|
||||||
|
* @return A raw pointer that represents the address of the original pointer.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr auto to_address(Type &&ptr) ENTT_NOEXCEPT {
|
||||||
|
if constexpr(std::is_pointer_v<std::remove_cv_t<std::remove_reference_t<Type>>>) {
|
||||||
|
return ptr;
|
||||||
|
} else {
|
||||||
|
return to_address(std::forward<Type>(ptr).operator->());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utility function to design allocation-aware containers.
|
||||||
|
* @tparam Allocator Type of allocator.
|
||||||
|
* @param lhs A valid allocator.
|
||||||
|
* @param rhs Another valid allocator.
|
||||||
|
*/
|
||||||
|
template<typename Allocator>
|
||||||
|
constexpr void propagate_on_container_copy_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {
|
||||||
|
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value) {
|
||||||
|
lhs = rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utility function to design allocation-aware containers.
|
||||||
|
* @tparam Allocator Type of allocator.
|
||||||
|
* @param lhs A valid allocator.
|
||||||
|
* @param rhs Another valid allocator.
|
||||||
|
*/
|
||||||
|
template<typename Allocator>
|
||||||
|
constexpr void propagate_on_container_move_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {
|
||||||
|
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {
|
||||||
|
lhs = std::move(rhs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utility function to design allocation-aware containers.
|
||||||
|
* @tparam Allocator Type of allocator.
|
||||||
|
* @param lhs A valid allocator.
|
||||||
|
* @param rhs Another valid allocator.
|
||||||
|
*/
|
||||||
|
template<typename Allocator>
|
||||||
|
constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {
|
||||||
|
ENTT_ASSERT(std::allocator_traits<Allocator>::propagate_on_container_swap::value || lhs == rhs, "Cannot swap the containers");
|
||||||
|
|
||||||
|
if constexpr(std::allocator_traits<Allocator>::propagate_on_container_swap::value) {
|
||||||
|
using std::swap;
|
||||||
|
swap(lhs, rhs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks whether a value is a power of two or not.
|
||||||
|
* @param value A value that may or may not be a power of two.
|
||||||
|
* @return True if the value is a power of two, false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] inline constexpr bool is_power_of_two(const std::size_t value) ENTT_NOEXCEPT {
|
||||||
|
return value && ((value & (value - 1)) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the smallest power of two greater than or equal to a value.
|
||||||
|
* @param value The value to use.
|
||||||
|
* @return The smallest power of two greater than or equal to the given value.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] inline constexpr std::size_t next_power_of_two(const std::size_t value) ENTT_NOEXCEPT {
|
||||||
|
ENTT_ASSERT(value < (std::size_t{1u} << (std::numeric_limits<std::size_t>::digits - 1)), "Numeric limits exceeded");
|
||||||
|
std::size_t curr = value - (value != 0u);
|
||||||
|
|
||||||
|
for(int next = 1; next < std::numeric_limits<std::size_t>::digits; next = next * 2) {
|
||||||
|
curr |= curr >> next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ++curr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fast module utility function (powers of two only).
|
||||||
|
* @param value A value for which to calculate the modulus.
|
||||||
|
* @param mod _Modulus_, it must be a power of two.
|
||||||
|
* @return The common remainder.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] inline constexpr std::size_t fast_mod(const std::size_t value, const std::size_t mod) ENTT_NOEXCEPT {
|
||||||
|
ENTT_ASSERT(is_power_of_two(mod), "Value must be a power of two");
|
||||||
|
return value & (mod - 1u);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deleter for allocator-aware unique pointers (waiting for C++20).
|
||||||
|
* @tparam Args Types of arguments to use to construct the object.
|
||||||
|
*/
|
||||||
|
template<typename Allocator>
|
||||||
|
struct allocation_deleter: private Allocator {
|
||||||
|
/*! @brief Allocator type. */
|
||||||
|
using allocator_type = Allocator;
|
||||||
|
/*! @brief Pointer type. */
|
||||||
|
using pointer = typename std::allocator_traits<Allocator>::pointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inherited constructors.
|
||||||
|
* @param alloc The allocator to use.
|
||||||
|
*/
|
||||||
|
allocation_deleter(const allocator_type &alloc)
|
||||||
|
: Allocator{alloc} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroys the pointed object and deallocates its memory.
|
||||||
|
* @param ptr A valid pointer to an object of the given type.
|
||||||
|
*/
|
||||||
|
void operator()(pointer ptr) {
|
||||||
|
using alloc_traits = typename std::allocator_traits<Allocator>;
|
||||||
|
alloc_traits::destroy(*this, to_address(ptr));
|
||||||
|
alloc_traits::deallocate(*this, ptr, 1u);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allows `std::unique_ptr` to use allocators (waiting for C++20).
|
||||||
|
* @tparam Type Type of object to allocate for and to construct.
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
* @tparam Args Types of arguments to use to construct the object.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
* @param args Parameters to use to construct the object.
|
||||||
|
* @return A properly initialized unique pointer with a custom deleter.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Allocator, typename... Args>
|
||||||
|
auto allocate_unique(Allocator &allocator, Args &&...args) {
|
||||||
|
static_assert(!std::is_array_v<Type>, "Array types are not supported");
|
||||||
|
|
||||||
|
using alloc_traits = typename std::allocator_traits<Allocator>::template rebind_traits<Type>;
|
||||||
|
using allocator_type = typename alloc_traits::allocator_type;
|
||||||
|
|
||||||
|
allocator_type alloc{allocator};
|
||||||
|
auto ptr = alloc_traits::allocate(alloc, 1u);
|
||||||
|
|
||||||
|
ENTT_TRY {
|
||||||
|
alloc_traits::construct(alloc, to_address(ptr), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
ENTT_CATCH {
|
||||||
|
alloc_traits::deallocate(alloc, ptr, 1u);
|
||||||
|
ENTT_THROW;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::unique_ptr<Type, allocation_deleter<allocator_type>>{ptr, alloc};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
struct uses_allocator_construction {
|
||||||
|
template<typename Allocator, typename... Params>
|
||||||
|
static constexpr auto args([[maybe_unused]] const Allocator &allocator, Params &&...params) ENTT_NOEXCEPT {
|
||||||
|
if constexpr(!std::uses_allocator_v<Type, Allocator> && std::is_constructible_v<Type, Params...>) {
|
||||||
|
return std::forward_as_tuple(std::forward<Params>(params)...);
|
||||||
|
} else {
|
||||||
|
static_assert(std::uses_allocator_v<Type, Allocator>, "Ill-formed request");
|
||||||
|
|
||||||
|
if constexpr(std::is_constructible_v<Type, std::allocator_arg_t, const Allocator &, Params...>) {
|
||||||
|
return std::tuple<std::allocator_arg_t, const Allocator &, Params &&...>(std::allocator_arg, allocator, std::forward<Params>(params)...);
|
||||||
|
} else {
|
||||||
|
static_assert(std::is_constructible_v<Type, Params..., const Allocator &>, "Ill-formed request");
|
||||||
|
return std::forward_as_tuple(std::forward<Params>(params)..., allocator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Type, typename Other>
|
||||||
|
struct uses_allocator_construction<std::pair<Type, Other>> {
|
||||||
|
using type = std::pair<Type, Other>;
|
||||||
|
|
||||||
|
template<typename Allocator, typename First, typename Second>
|
||||||
|
static constexpr auto args(const Allocator &allocator, std::piecewise_construct_t, First &&first, Second &&second) ENTT_NOEXCEPT {
|
||||||
|
return std::make_tuple(
|
||||||
|
std::piecewise_construct,
|
||||||
|
std::apply([&allocator](auto &&...curr) { return uses_allocator_construction<Type>::args(allocator, std::forward<decltype(curr)>(curr)...); }, std::forward<First>(first)),
|
||||||
|
std::apply([&allocator](auto &&...curr) { return uses_allocator_construction<Other>::args(allocator, std::forward<decltype(curr)>(curr)...); }, std::forward<Second>(second)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Allocator>
|
||||||
|
static constexpr auto args(const Allocator &allocator) ENTT_NOEXCEPT {
|
||||||
|
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::tuple<>{}, std::tuple<>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Allocator, typename First, typename Second>
|
||||||
|
static constexpr auto args(const Allocator &allocator, First &&first, Second &&second) ENTT_NOEXCEPT {
|
||||||
|
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::forward_as_tuple(std::forward<First>(first)), std::forward_as_tuple(std::forward<Second>(second)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Allocator, typename First, typename Second>
|
||||||
|
static constexpr auto args(const Allocator &allocator, const std::pair<First, Second> &value) ENTT_NOEXCEPT {
|
||||||
|
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::forward_as_tuple(value.first), std::forward_as_tuple(value.second));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Allocator, typename First, typename Second>
|
||||||
|
static constexpr auto args(const Allocator &allocator, std::pair<First, Second> &&value) ENTT_NOEXCEPT {
|
||||||
|
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, std::forward_as_tuple(std::move(value.first)), std::forward_as_tuple(std::move(value.second)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Uses-allocator construction utility (waiting for C++20).
|
||||||
|
*
|
||||||
|
* Primarily intended for internal use. Prepares the argument list needed to
|
||||||
|
* create an object of a given type by means of uses-allocator construction.
|
||||||
|
*
|
||||||
|
* @tparam Type Type to return arguments for.
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
* @tparam Args Types of arguments to use to construct the object.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
* @param args Parameters to use to construct the object.
|
||||||
|
* @return The arguments needed to create an object of the given type.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Allocator, typename... Args>
|
||||||
|
constexpr auto uses_allocator_construction_args(const Allocator &allocator, Args &&...args) ENTT_NOEXCEPT {
|
||||||
|
return internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Uses-allocator construction utility (waiting for C++20).
|
||||||
|
*
|
||||||
|
* Primarily intended for internal use. Creates an object of a given type by
|
||||||
|
* means of uses-allocator construction.
|
||||||
|
*
|
||||||
|
* @tparam Type Type of object to create.
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
* @tparam Args Types of arguments to use to construct the object.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
* @param args Parameters to use to construct the object.
|
||||||
|
* @return A newly created object of the given type.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Allocator, typename... Args>
|
||||||
|
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args) {
|
||||||
|
return std::make_from_tuple<Type>(internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Uses-allocator construction utility (waiting for C++20).
|
||||||
|
*
|
||||||
|
* Primarily intended for internal use. Creates an object of a given type by
|
||||||
|
* means of uses-allocator construction at an uninitialized memory location.
|
||||||
|
*
|
||||||
|
* @tparam Type Type of object to create.
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
* @tparam Args Types of arguments to use to construct the object.
|
||||||
|
* @param value Memory location in which to place the object.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
* @param args Parameters to use to construct the object.
|
||||||
|
* @return A pointer to the newly created object of the given type.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Allocator, typename... Args>
|
||||||
|
constexpr Type *uninitialized_construct_using_allocator(Type *value, const Allocator &allocator, Args &&...args) {
|
||||||
|
return std::apply([&](auto &&...curr) { return new(value) Type(std::forward<decltype(curr)>(curr)...); }, internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
#ifndef ENTT_CORE_MONOSTATE_HPP
|
#ifndef ENTT_CORE_MONOSTATE_HPP
|
||||||
#define ENTT_CORE_MONOSTATE_HPP
|
#define ENTT_CORE_MONOSTATE_HPP
|
||||||
|
|
||||||
|
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Minimal implementation of the monostate pattern.
|
* @brief Minimal implementation of the monostate pattern.
|
||||||
*
|
*
|
||||||
@@ -47,7 +44,6 @@ private:
|
|||||||
inline static ENTT_MAYBE_ATOMIC(Type) value{};
|
inline static ENTT_MAYBE_ATOMIC(Type) value{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam Value Value used to differentiate between different variables.
|
* @tparam Value Value used to differentiate between different variables.
|
||||||
@@ -55,8 +51,6 @@ private:
|
|||||||
template<id_type Value>
|
template<id_type Value>
|
||||||
inline monostate<Value> monostate_v = {};
|
inline monostate<Value> monostate_v = {};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
29
src/entt/core/tuple.hpp
Normal file
29
src/entt/core/tuple.hpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef ENTT_CORE_TUPLE_HPP
|
||||||
|
#define ENTT_CORE_TUPLE_HPP
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Utility function to unwrap tuples of a single element.
|
||||||
|
* @tparam Type Tuple type of any sizes.
|
||||||
|
* @param value A tuple object of the given type.
|
||||||
|
* @return The tuple itself if it contains more than one element, the first
|
||||||
|
* element otherwise.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
constexpr decltype(auto) unwrap_tuple(Type &&value) ENTT_NOEXCEPT {
|
||||||
|
if constexpr(std::tuple_size_v<std::remove_reference_t<Type>> == 1u) {
|
||||||
|
return std::get<0>(std::forward<Type>(value));
|
||||||
|
} else {
|
||||||
|
return std::forward<Type>(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,40 +1,35 @@
|
|||||||
#ifndef ENTT_CORE_TYPE_INFO_HPP
|
#ifndef ENTT_CORE_TYPE_INFO_HPP
|
||||||
#define ENTT_CORE_TYPE_INFO_HPP
|
#define ENTT_CORE_TYPE_INFO_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "../core/attribute.h"
|
#include "../core/attribute.h"
|
||||||
#include "hashed_string.hpp"
|
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
#include "hashed_string.hpp"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @cond TURN_OFF_DOXYGEN
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
struct ENTT_API type_index final {
|
||||||
struct ENTT_API type_seq final {
|
|
||||||
[[nodiscard]] static id_type next() ENTT_NOEXCEPT {
|
[[nodiscard]] static id_type next() ENTT_NOEXCEPT {
|
||||||
static ENTT_MAYBE_ATOMIC(id_type) value{};
|
static ENTT_MAYBE_ATOMIC(id_type) value{};
|
||||||
return value++;
|
return value++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] constexpr auto stripped_type_name() ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr auto stripped_type_name() ENTT_NOEXCEPT {
|
||||||
#if defined ENTT_PRETTY_FUNCTION
|
#if defined ENTT_PRETTY_FUNCTION
|
||||||
std::string_view pretty_function{ENTT_PRETTY_FUNCTION};
|
std::string_view pretty_function{ENTT_PRETTY_FUNCTION};
|
||||||
auto first = pretty_function.find_first_not_of(' ', pretty_function.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX)+1);
|
auto first = pretty_function.find_first_not_of(' ', pretty_function.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX) + 1);
|
||||||
auto value = pretty_function.substr(first, pretty_function.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
|
auto value = pretty_function.substr(first, pretty_function.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
|
||||||
return value;
|
return value;
|
||||||
#else
|
#else
|
||||||
@@ -42,21 +37,18 @@ template<typename Type>
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
|
template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
|
||||||
[[nodiscard]] static constexpr std::string_view type_name(int) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr std::string_view type_name(int) ENTT_NOEXCEPT {
|
||||||
constexpr auto value = stripped_type_name<Type>();
|
constexpr auto value = stripped_type_name<Type>();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] static std::string_view type_name(char) ENTT_NOEXCEPT {
|
[[nodiscard]] static std::string_view type_name(char) ENTT_NOEXCEPT {
|
||||||
static const auto value = stripped_type_name<Type>();
|
static const auto value = stripped_type_name<Type>();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
|
template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
|
||||||
[[nodiscard]] static constexpr id_type type_hash(int) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr id_type type_hash(int) ENTT_NOEXCEPT {
|
||||||
constexpr auto stripped = stripped_type_name<Type>();
|
constexpr auto stripped = stripped_type_name<Type>();
|
||||||
@@ -64,7 +56,6 @@ template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] static id_type type_hash(char) ENTT_NOEXCEPT {
|
[[nodiscard]] static id_type type_hash(char) ENTT_NOEXCEPT {
|
||||||
static const auto value = [](const auto stripped) {
|
static const auto value = [](const auto stripped) {
|
||||||
@@ -73,36 +64,34 @@ template<typename Type>
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type sequential identifier.
|
* @brief Type sequential identifier.
|
||||||
* @tparam Type Type for which to generate a sequential identifier.
|
* @tparam Type Type for which to generate a sequential identifier.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename = void>
|
template<typename Type, typename = void>
|
||||||
struct ENTT_API type_seq final {
|
struct ENTT_API type_index final {
|
||||||
/**
|
/**
|
||||||
* @brief Returns the sequential identifier of a given type.
|
* @brief Returns the sequential identifier of a given type.
|
||||||
* @return The sequential identifier of a given type.
|
* @return The sequential identifier of a given type.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static id_type value() ENTT_NOEXCEPT {
|
[[nodiscard]] static id_type value() ENTT_NOEXCEPT {
|
||||||
static const id_type value = internal::type_seq::next();
|
static const id_type value = internal::type_index::next();
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc value */
|
/*! @copydoc value */
|
||||||
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT { return value(); }
|
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type hash.
|
* @brief Type hash.
|
||||||
* @tparam Type Type for which to generate a hash value.
|
* @tparam Type Type for which to generate a hash value.
|
||||||
@@ -118,15 +107,16 @@ struct type_hash final {
|
|||||||
return internal::type_hash<Type>(0);
|
return internal::type_hash<Type>(0);
|
||||||
#else
|
#else
|
||||||
[[nodiscard]] static constexpr id_type value() ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr id_type value() ENTT_NOEXCEPT {
|
||||||
return type_seq<Type>::value();
|
return type_index<Type>::value();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc value */
|
/*! @copydoc value */
|
||||||
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT { return value(); }
|
[[nodiscard]] constexpr operator id_type() const ENTT_NOEXCEPT {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type name.
|
* @brief Type name.
|
||||||
* @tparam Type Type for which to generate a name.
|
* @tparam Type Type for which to generate a name.
|
||||||
@@ -142,119 +132,143 @@ struct type_name final {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc value */
|
/*! @copydoc value */
|
||||||
[[nodiscard]] constexpr operator std::string_view() const ENTT_NOEXCEPT { return value(); }
|
[[nodiscard]] constexpr operator std::string_view() const ENTT_NOEXCEPT {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Implementation specific information about a type. */
|
/*! @brief Implementation specific information about a type. */
|
||||||
class type_info final {
|
struct type_info final {
|
||||||
template<typename>
|
/**
|
||||||
friend type_info type_id() ENTT_NOEXCEPT;
|
* @brief Constructs a type info object for a given type.
|
||||||
|
* @tparam Type Type for which to construct a type info object.
|
||||||
type_info(id_type seq_v, id_type hash_v, std::string_view name_v) ENTT_NOEXCEPT
|
*/
|
||||||
: seq_value{seq_v},
|
template<typename Type>
|
||||||
hash_value{hash_v},
|
constexpr type_info(std::in_place_type_t<Type>) ENTT_NOEXCEPT
|
||||||
name_value{name_v}
|
: seq{type_index<std::remove_cv_t<std::remove_reference_t<Type>>>::value()},
|
||||||
{}
|
identifier{type_hash<std::remove_cv_t<std::remove_reference_t<Type>>>::value()},
|
||||||
|
alias{type_name<std::remove_cv_t<std::remove_reference_t<Type>>>::value()} {}
|
||||||
public:
|
|
||||||
/*! @brief Default constructor. */
|
|
||||||
type_info() ENTT_NOEXCEPT
|
|
||||||
: type_info({}, {}, {})
|
|
||||||
{}
|
|
||||||
|
|
||||||
/*! @brief Default copy constructor. */
|
|
||||||
type_info(const type_info &) ENTT_NOEXCEPT = default;
|
|
||||||
/*! @brief Default move constructor. */
|
|
||||||
type_info(type_info &&) ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default copy assignment operator.
|
* @brief Type index.
|
||||||
* @return This type info object.
|
* @return Type index.
|
||||||
*/
|
*/
|
||||||
type_info & operator=(const type_info &) ENTT_NOEXCEPT = default;
|
[[nodiscard]] constexpr id_type index() const ENTT_NOEXCEPT {
|
||||||
|
return seq;
|
||||||
/**
|
|
||||||
* @brief Default move assignment operator.
|
|
||||||
* @return This type info object.
|
|
||||||
*/
|
|
||||||
type_info & operator=(type_info &&) ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks if a type info object is properly initialized.
|
|
||||||
* @return True if the object is properly initialized, false otherwise.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
|
|
||||||
return name_value.data() != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type sequential identifier.
|
|
||||||
* @return Type sequential identifier.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] id_type seq() const ENTT_NOEXCEPT {
|
|
||||||
return seq_value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type hash.
|
* @brief Type hash.
|
||||||
* @return Type hash.
|
* @return Type hash.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] id_type hash() const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr id_type hash() const ENTT_NOEXCEPT {
|
||||||
return hash_value;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type name.
|
* @brief Type name.
|
||||||
* @return Type name.
|
* @return Type name.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::string_view name() const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr std::string_view name() const ENTT_NOEXCEPT {
|
||||||
return name_value;
|
return alias;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Compares the contents of two type info objects.
|
|
||||||
* @param other Object with which to compare.
|
|
||||||
* @return False if the two contents differ, true otherwise.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] bool operator==(const type_info &other) const ENTT_NOEXCEPT {
|
|
||||||
return hash_value == other.hash_value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
id_type seq_value;
|
id_type seq;
|
||||||
id_type hash_value;
|
id_type identifier;
|
||||||
std::string_view name_value;
|
std::string_view alias;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares the contents of two type info objects.
|
* @brief Compares the contents of two type info objects.
|
||||||
* @param lhs A type info object.
|
* @param lhs A type info object.
|
||||||
* @param rhs A type info object.
|
* @param rhs A type info object.
|
||||||
* @return True if the two contents differ, false otherwise.
|
* @return True if the two type info objects are identical, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] inline bool operator!=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
|
[[nodiscard]] inline constexpr bool operator==(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.hash() == rhs.hash();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares the contents of two type info objects.
|
||||||
|
* @param lhs A type info object.
|
||||||
|
* @param rhs A type info object.
|
||||||
|
* @return True if the two type info objects differ, false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] inline constexpr bool operator!=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two type info objects.
|
||||||
|
* @param lhs A valid type info object.
|
||||||
|
* @param rhs A valid type info object.
|
||||||
|
* @return True if the first element is less than the second, false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr bool operator<(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.index() < rhs.index();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the type info object for a given type.
|
* @brief Compares two type info objects.
|
||||||
|
* @param lhs A valid type info object.
|
||||||
|
* @param rhs A valid type info object.
|
||||||
|
* @return True if the first element is less than or equal to the second, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr bool operator<=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(rhs < lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two type info objects.
|
||||||
|
* @param lhs A valid type info object.
|
||||||
|
* @param rhs A valid type info object.
|
||||||
|
* @return True if the first element is greater than the second, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr bool operator>(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
|
||||||
|
return rhs < lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two type info objects.
|
||||||
|
* @param lhs A valid type info object.
|
||||||
|
* @param rhs A valid type info object.
|
||||||
|
* @return True if the first element is greater than or equal to the second,
|
||||||
|
* false otherwise.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr bool operator>=(const type_info &lhs, const type_info &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs < rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the type info object associated to a given type.
|
||||||
|
*
|
||||||
|
* The returned element refers to an object with static storage duration.<br/>
|
||||||
|
* The type doesn't need to be a complete type. If the type is a reference, the
|
||||||
|
* result refers to the referenced type. In all cases, top-level cv-qualifiers
|
||||||
|
* are ignored.
|
||||||
|
*
|
||||||
* @tparam Type Type for which to generate a type info object.
|
* @tparam Type Type for which to generate a type info object.
|
||||||
* @return The type info object for the given type.
|
* @return A reference to a properly initialized type info object.
|
||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] type_info type_id() ENTT_NOEXCEPT {
|
[[nodiscard]] const type_info &type_id() ENTT_NOEXCEPT {
|
||||||
return type_info{
|
if constexpr(std::is_same_v<Type, std::remove_cv_t<std::remove_reference_t<Type>>>) {
|
||||||
type_seq<std::remove_cv_t<std::remove_reference_t<Type>>>::value(),
|
static type_info instance{std::in_place_type<Type>};
|
||||||
type_hash<std::remove_cv_t<std::remove_reference_t<Type>>>::value(),
|
return instance;
|
||||||
type_name<std::remove_cv_t<std::remove_reference_t<Type>>>::value()
|
} else {
|
||||||
};
|
return type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! @copydoc type_id */
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] const type_info &type_id(Type &&) ENTT_NOEXCEPT {
|
||||||
|
return type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef ENTT_CORE_TYPE_TRAITS_HPP
|
#ifndef ENTT_CORE_TYPE_TRAITS_HPP
|
||||||
#define ENTT_CORE_TYPE_TRAITS_HPP
|
#define ENTT_CORE_TYPE_TRAITS_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -9,10 +8,8 @@
|
|||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Utility class to disambiguate overloaded functions.
|
* @brief Utility class to disambiguate overloaded functions.
|
||||||
* @tparam N Number of choices available.
|
* @tparam N Number of choices available.
|
||||||
@@ -20,17 +17,13 @@ namespace entt {
|
|||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
struct choice_t
|
struct choice_t
|
||||||
// Unfortunately, doxygen cannot parse such a construct.
|
// Unfortunately, doxygen cannot parse such a construct.
|
||||||
/*! @cond TURN_OFF_DOXYGEN */
|
: /*! @cond TURN_OFF_DOXYGEN */ choice_t<N - 1> /*! @endcond */
|
||||||
: choice_t<N-1>
|
|
||||||
/*! @endcond */
|
|
||||||
{};
|
{};
|
||||||
|
|
||||||
|
|
||||||
/*! @copybrief choice_t */
|
/*! @copybrief choice_t */
|
||||||
template<>
|
template<>
|
||||||
struct choice_t<0> {};
|
struct choice_t<0> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variable template for the choice trick.
|
* @brief Variable template for the choice trick.
|
||||||
* @tparam N Number of choices available.
|
* @tparam N Number of choices available.
|
||||||
@@ -38,7 +31,6 @@ struct choice_t<0> {};
|
|||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
inline constexpr choice_t<N> choice{};
|
inline constexpr choice_t<N> choice{};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Identity type trait.
|
* @brief Identity type trait.
|
||||||
*
|
*
|
||||||
@@ -53,7 +45,6 @@ struct type_identity {
|
|||||||
using type = Type;
|
using type = Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam Type A type.
|
* @tparam Type A type.
|
||||||
@@ -61,7 +52,6 @@ struct type_identity {
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
using type_identity_t = typename type_identity<Type>::type;
|
using type_identity_t = typename type_identity<Type>::type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A type-only `sizeof` wrapper that returns 0 where `sizeof` complains.
|
* @brief A type-only `sizeof` wrapper that returns 0 where `sizeof` complains.
|
||||||
* @tparam Type The type of which to return the size.
|
* @tparam Type The type of which to return the size.
|
||||||
@@ -70,30 +60,25 @@ using type_identity_t = typename type_identity<Type>::type;
|
|||||||
template<typename Type, typename = void>
|
template<typename Type, typename = void>
|
||||||
struct size_of: std::integral_constant<std::size_t, 0u> {};
|
struct size_of: std::integral_constant<std::size_t, 0u> {};
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc size_of */
|
/*! @copydoc size_of */
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct size_of<Type, std::void_t<decltype(sizeof(Type))>>
|
struct size_of<Type, std::void_t<decltype(sizeof(Type))>>
|
||||||
: std::integral_constant<std::size_t, sizeof(Type)>
|
: std::integral_constant<std::size_t, sizeof(Type)> {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam Type The type of which to return the size.
|
* @tparam Type The type of which to return the size.
|
||||||
*/
|
*/
|
||||||
template<class Type>
|
template<typename Type>
|
||||||
inline constexpr std::size_t size_of_v = size_of<Type>::value;
|
inline constexpr std::size_t size_of_v = size_of<Type>::value;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Using declaration to be used to _repeat_ the same type a number of
|
* @brief Using declaration to be used to _repeat_ the same type a number of
|
||||||
* times equal to the size of a given parameter pack.
|
* times equal to the size of a given parameter pack.
|
||||||
* @tparam Type A type to repeat.
|
* @tparam Type A type to repeat.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename>
|
template<typename Type, typename>
|
||||||
using unpack_as_t = Type;
|
using unpack_as_type = Type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template to be used to _repeat_ the same value a
|
* @brief Helper variable template to be used to _repeat_ the same value a
|
||||||
@@ -101,8 +86,7 @@ using unpack_as_t = Type;
|
|||||||
* @tparam Value A value to repeat.
|
* @tparam Value A value to repeat.
|
||||||
*/
|
*/
|
||||||
template<auto Value, typename>
|
template<auto Value, typename>
|
||||||
inline constexpr auto unpack_as_v = Value;
|
inline constexpr auto unpack_as_value = Value;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wraps a static constant.
|
* @brief Wraps a static constant.
|
||||||
@@ -111,7 +95,6 @@ inline constexpr auto unpack_as_v = Value;
|
|||||||
template<auto Value>
|
template<auto Value>
|
||||||
using integral_constant = std::integral_constant<decltype(Value), Value>;
|
using integral_constant = std::integral_constant<decltype(Value), Value>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias template to facilitate the creation of named values.
|
* @brief Alias template to facilitate the creation of named values.
|
||||||
* @tparam Value A constant value at least convertible to `id_type`.
|
* @tparam Value A constant value at least convertible to `id_type`.
|
||||||
@@ -119,7 +102,6 @@ using integral_constant = std::integral_constant<decltype(Value), Value>;
|
|||||||
template<id_type Value>
|
template<id_type Value>
|
||||||
using tag = integral_constant<Value>;
|
using tag = integral_constant<Value>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A class to use to push around lists of types, nothing more.
|
* @brief A class to use to push around lists of types, nothing more.
|
||||||
* @tparam Type Types provided by the type list.
|
* @tparam Type Types provided by the type list.
|
||||||
@@ -132,12 +114,10 @@ struct type_list {
|
|||||||
static constexpr auto size = sizeof...(Type);
|
static constexpr auto size = sizeof...(Type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Primary template isn't defined on purpose. */
|
/*! @brief Primary template isn't defined on purpose. */
|
||||||
template<std::size_t, typename>
|
template<std::size_t, typename>
|
||||||
struct type_list_element;
|
struct type_list_element;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides compile-time indexed access to the types of a type list.
|
* @brief Provides compile-time indexed access to the types of a type list.
|
||||||
* @tparam Index Index of the type to return.
|
* @tparam Index Index of the type to return.
|
||||||
@@ -146,9 +126,7 @@ struct type_list_element;
|
|||||||
*/
|
*/
|
||||||
template<std::size_t Index, typename Type, typename... Other>
|
template<std::size_t Index, typename Type, typename... Other>
|
||||||
struct type_list_element<Index, type_list<Type, Other...>>
|
struct type_list_element<Index, type_list<Type, Other...>>
|
||||||
: type_list_element<Index - 1u, type_list<Other...>>
|
: type_list_element<Index - 1u, type_list<Other...>> {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides compile-time indexed access to the types of a type list.
|
* @brief Provides compile-time indexed access to the types of a type list.
|
||||||
@@ -161,7 +139,6 @@ struct type_list_element<0u, type_list<Type, Other...>> {
|
|||||||
using type = Type;
|
using type = Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam Index Index of the type to return.
|
* @tparam Index Index of the type to return.
|
||||||
@@ -170,7 +147,6 @@ struct type_list_element<0u, type_list<Type, Other...>> {
|
|||||||
template<std::size_t Index, typename List>
|
template<std::size_t Index, typename List>
|
||||||
using type_list_element_t = typename type_list_element<Index, List>::type;
|
using type_list_element_t = typename type_list_element<Index, List>::type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Concatenates multiple type lists.
|
* @brief Concatenates multiple type lists.
|
||||||
* @tparam Type Types provided by the first type list.
|
* @tparam Type Types provided by the first type list.
|
||||||
@@ -178,14 +154,14 @@ using type_list_element_t = typename type_list_element<Index, List>::type;
|
|||||||
* @return A type list composed by the types of both the type lists.
|
* @return A type list composed by the types of both the type lists.
|
||||||
*/
|
*/
|
||||||
template<typename... Type, typename... Other>
|
template<typename... Type, typename... Other>
|
||||||
constexpr type_list<Type..., Other...> operator+(type_list<Type...>, type_list<Other...>) { return {}; }
|
constexpr type_list<Type..., Other...> operator+(type_list<Type...>, type_list<Other...>) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
/*! @brief Primary template isn't defined on purpose. */
|
/*! @brief Primary template isn't defined on purpose. */
|
||||||
template<typename...>
|
template<typename...>
|
||||||
struct type_list_cat;
|
struct type_list_cat;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Concatenates multiple type lists. */
|
/*! @brief Concatenates multiple type lists. */
|
||||||
template<>
|
template<>
|
||||||
struct type_list_cat<> {
|
struct type_list_cat<> {
|
||||||
@@ -193,7 +169,6 @@ struct type_list_cat<> {
|
|||||||
using type = type_list<>;
|
using type = type_list<>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Concatenates multiple type lists.
|
* @brief Concatenates multiple type lists.
|
||||||
* @tparam Type Types provided by the first type list.
|
* @tparam Type Types provided by the first type list.
|
||||||
@@ -206,7 +181,6 @@ struct type_list_cat<type_list<Type...>, type_list<Other...>, List...> {
|
|||||||
using type = typename type_list_cat<type_list<Type..., Other...>, List...>::type;
|
using type = typename type_list_cat<type_list<Type..., Other...>, List...>::type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Concatenates multiple type lists.
|
* @brief Concatenates multiple type lists.
|
||||||
* @tparam Type Types provided by the type list.
|
* @tparam Type Types provided by the type list.
|
||||||
@@ -217,7 +191,6 @@ struct type_list_cat<type_list<Type...>> {
|
|||||||
using type = type_list<Type...>;
|
using type = type_list<Type...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam List Type lists to concatenate.
|
* @tparam List Type lists to concatenate.
|
||||||
@@ -225,12 +198,10 @@ struct type_list_cat<type_list<Type...>> {
|
|||||||
template<typename... List>
|
template<typename... List>
|
||||||
using type_list_cat_t = typename type_list_cat<List...>::type;
|
using type_list_cat_t = typename type_list_cat<List...>::type;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Primary template isn't defined on purpose. */
|
/*! @brief Primary template isn't defined on purpose. */
|
||||||
template<typename>
|
template<typename>
|
||||||
struct type_list_unique;
|
struct type_list_unique;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Removes duplicates types from a type list.
|
* @brief Removes duplicates types from a type list.
|
||||||
* @tparam Type One of the types provided by the given type list.
|
* @tparam Type One of the types provided by the given type list.
|
||||||
@@ -240,13 +211,11 @@ template<typename Type, typename... Other>
|
|||||||
struct type_list_unique<type_list<Type, Other...>> {
|
struct type_list_unique<type_list<Type, Other...>> {
|
||||||
/*! @brief A type list without duplicate types. */
|
/*! @brief A type list without duplicate types. */
|
||||||
using type = std::conditional_t<
|
using type = std::conditional_t<
|
||||||
std::disjunction_v<std::is_same<Type, Other>...>,
|
(std::is_same_v<Type, Other> || ...),
|
||||||
typename type_list_unique<type_list<Other...>>::type,
|
typename type_list_unique<type_list<Other...>>::type,
|
||||||
type_list_cat_t<type_list<Type>, typename type_list_unique<type_list<Other...>>::type>
|
type_list_cat_t<type_list<Type>, typename type_list_unique<type_list<Other...>>::type>>;
|
||||||
>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Removes duplicates types from a type list. */
|
/*! @brief Removes duplicates types from a type list. */
|
||||||
template<>
|
template<>
|
||||||
struct type_list_unique<type_list<>> {
|
struct type_list_unique<type_list<>> {
|
||||||
@@ -254,7 +223,6 @@ struct type_list_unique<type_list<>> {
|
|||||||
using type = type_list<>;
|
using type = type_list<>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam Type A type list.
|
* @tparam Type A type list.
|
||||||
@@ -262,7 +230,6 @@ struct type_list_unique<type_list<>> {
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
using type_list_unique_t = typename type_list_unique<Type>::type;
|
using type_list_unique_t = typename type_list_unique<Type>::type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides the member constant `value` to true if a type list contains a
|
* @brief Provides the member constant `value` to true if a type list contains a
|
||||||
* given type, false otherwise.
|
* given type, false otherwise.
|
||||||
@@ -272,7 +239,6 @@ using type_list_unique_t = typename type_list_unique<Type>::type;
|
|||||||
template<typename List, typename Type>
|
template<typename List, typename Type>
|
||||||
struct type_list_contains;
|
struct type_list_contains;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copybrief type_list_contains
|
* @copybrief type_list_contains
|
||||||
* @tparam Type Types provided by the type list.
|
* @tparam Type Types provided by the type list.
|
||||||
@@ -281,21 +247,18 @@ struct type_list_contains;
|
|||||||
template<typename... Type, typename Other>
|
template<typename... Type, typename Other>
|
||||||
struct type_list_contains<type_list<Type...>, Other>: std::disjunction<std::is_same<Type, Other>...> {};
|
struct type_list_contains<type_list<Type...>, Other>: std::disjunction<std::is_same<Type, Other>...> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam List Type list.
|
* @tparam List Type list.
|
||||||
* @tparam Type Type to look for.
|
* @tparam Type Type to look for.
|
||||||
*/
|
*/
|
||||||
template<class List, typename Type>
|
template<typename List, typename Type>
|
||||||
inline constexpr bool type_list_contains_v = type_list_contains<List, Type>::value;
|
inline constexpr bool type_list_contains_v = type_list_contains<List, Type>::value;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Primary template isn't defined on purpose. */
|
/*! @brief Primary template isn't defined on purpose. */
|
||||||
template<typename...>
|
template<typename...>
|
||||||
struct type_list_diff;
|
struct type_list_diff;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Computes the difference between two type lists.
|
* @brief Computes the difference between two type lists.
|
||||||
* @tparam Type Types provided by the first type list.
|
* @tparam Type Types provided by the first type list.
|
||||||
@@ -307,7 +270,6 @@ struct type_list_diff<type_list<Type...>, type_list<Other...>> {
|
|||||||
using type = type_list_cat_t<std::conditional_t<type_list_contains_v<type_list<Other...>, Type>, type_list<>, type_list<Type>>...>;
|
using type = type_list_cat_t<std::conditional_t<type_list_contains_v<type_list<Other...>, Type>, type_list<>, type_list<Type>>...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam List Type lists between which to compute the difference.
|
* @tparam List Type lists between which to compute the difference.
|
||||||
@@ -315,7 +277,6 @@ struct type_list_diff<type_list<Type...>, type_list<Other...>> {
|
|||||||
template<typename... List>
|
template<typename... List>
|
||||||
using type_list_diff_t = typename type_list_diff<List...>::type;
|
using type_list_diff_t = typename type_list_diff<List...>::type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A class to use to push around lists of constant values, nothing more.
|
* @brief A class to use to push around lists of constant values, nothing more.
|
||||||
* @tparam Value Values provided by the value list.
|
* @tparam Value Values provided by the value list.
|
||||||
@@ -328,12 +289,10 @@ struct value_list {
|
|||||||
static constexpr auto size = sizeof...(Value);
|
static constexpr auto size = sizeof...(Value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Primary template isn't defined on purpose. */
|
/*! @brief Primary template isn't defined on purpose. */
|
||||||
template<std::size_t, typename>
|
template<std::size_t, typename>
|
||||||
struct value_list_element;
|
struct value_list_element;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides compile-time indexed access to the values of a value list.
|
* @brief Provides compile-time indexed access to the values of a value list.
|
||||||
* @tparam Index Index of the value to return.
|
* @tparam Index Index of the value to return.
|
||||||
@@ -342,9 +301,7 @@ struct value_list_element;
|
|||||||
*/
|
*/
|
||||||
template<std::size_t Index, auto Value, auto... Other>
|
template<std::size_t Index, auto Value, auto... Other>
|
||||||
struct value_list_element<Index, value_list<Value, Other...>>
|
struct value_list_element<Index, value_list<Value, Other...>>
|
||||||
: value_list_element<Index - 1u, value_list<Other...>>
|
: value_list_element<Index - 1u, value_list<Other...>> {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides compile-time indexed access to the types of a type list.
|
* @brief Provides compile-time indexed access to the types of a type list.
|
||||||
@@ -357,7 +314,6 @@ struct value_list_element<0u, value_list<Value, Other...>> {
|
|||||||
static constexpr auto value = Value;
|
static constexpr auto value = Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam Index Index of the value to return.
|
* @tparam Index Index of the value to return.
|
||||||
@@ -366,7 +322,6 @@ struct value_list_element<0u, value_list<Value, Other...>> {
|
|||||||
template<std::size_t Index, typename List>
|
template<std::size_t Index, typename List>
|
||||||
inline constexpr auto value_list_element_v = value_list_element<Index, List>::value;
|
inline constexpr auto value_list_element_v = value_list_element<Index, List>::value;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Concatenates multiple value lists.
|
* @brief Concatenates multiple value lists.
|
||||||
* @tparam Value Values provided by the first value list.
|
* @tparam Value Values provided by the first value list.
|
||||||
@@ -374,14 +329,14 @@ inline constexpr auto value_list_element_v = value_list_element<Index, List>::va
|
|||||||
* @return A value list composed by the values of both the value lists.
|
* @return A value list composed by the values of both the value lists.
|
||||||
*/
|
*/
|
||||||
template<auto... Value, auto... Other>
|
template<auto... Value, auto... Other>
|
||||||
constexpr value_list<Value..., Other...> operator+(value_list<Value...>, value_list<Other...>) { return {}; }
|
constexpr value_list<Value..., Other...> operator+(value_list<Value...>, value_list<Other...>) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
/*! @brief Primary template isn't defined on purpose. */
|
/*! @brief Primary template isn't defined on purpose. */
|
||||||
template<typename...>
|
template<typename...>
|
||||||
struct value_list_cat;
|
struct value_list_cat;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Concatenates multiple value lists. */
|
/*! @brief Concatenates multiple value lists. */
|
||||||
template<>
|
template<>
|
||||||
struct value_list_cat<> {
|
struct value_list_cat<> {
|
||||||
@@ -389,7 +344,6 @@ struct value_list_cat<> {
|
|||||||
using type = value_list<>;
|
using type = value_list<>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Concatenates multiple value lists.
|
* @brief Concatenates multiple value lists.
|
||||||
* @tparam Value Values provided by the first value list.
|
* @tparam Value Values provided by the first value list.
|
||||||
@@ -402,7 +356,6 @@ struct value_list_cat<value_list<Value...>, value_list<Other...>, List...> {
|
|||||||
using type = typename value_list_cat<value_list<Value..., Other...>, List...>::type;
|
using type = typename value_list_cat<value_list<Value..., Other...>, List...>::type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Concatenates multiple value lists.
|
* @brief Concatenates multiple value lists.
|
||||||
* @tparam Value Values provided by the value list.
|
* @tparam Value Values provided by the value list.
|
||||||
@@ -413,7 +366,6 @@ struct value_list_cat<value_list<Value...>> {
|
|||||||
using type = value_list<Value...>;
|
using type = value_list<Value...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam List Value lists to concatenate.
|
* @tparam List Value lists to concatenate.
|
||||||
@@ -421,74 +373,10 @@ struct value_list_cat<value_list<Value...>> {
|
|||||||
template<typename... List>
|
template<typename... List>
|
||||||
using value_list_cat_t = typename value_list_cat<List...>::type;
|
using value_list_cat_t = typename value_list_cat<List...>::type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @cond TURN_OFF_DOXYGEN
|
|
||||||
* Internal details not to be documented.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
|
||||||
[[nodiscard]] constexpr bool is_equality_comparable(...) { return false; }
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
[[nodiscard]] constexpr auto is_equality_comparable(choice_t<0>)
|
|
||||||
-> decltype(std::declval<Type>() == std::declval<Type>()) { return true; }
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
[[nodiscard]] constexpr auto is_equality_comparable(choice_t<1>)
|
|
||||||
-> decltype(std::declval<typename Type::value_type>(), std::declval<Type>() == std::declval<Type>()) {
|
|
||||||
if constexpr(std::is_same_v<typename Type::value_type, Type>) {
|
|
||||||
return is_equality_comparable<Type>(choice<0>);
|
|
||||||
} else {
|
|
||||||
return is_equality_comparable<typename Type::value_type>(choice<2>);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
[[nodiscard]] constexpr auto is_equality_comparable(choice_t<2>)
|
|
||||||
-> decltype(std::declval<typename Type::mapped_type>(), std::declval<Type>() == std::declval<Type>()) {
|
|
||||||
return is_equality_comparable<typename Type::key_type>(choice<2>) && is_equality_comparable<typename Type::mapped_type>(choice<2>);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal details not to be documented.
|
|
||||||
* @endcond
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Provides the member constant `value` to true if a given type is
|
|
||||||
* equality comparable, false otherwise.
|
|
||||||
* @tparam Type The type to test.
|
|
||||||
*/
|
|
||||||
template<typename Type, typename = void>
|
|
||||||
struct is_equality_comparable: std::bool_constant<internal::is_equality_comparable<Type>(choice<2>)> {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Helper variable template.
|
|
||||||
* @tparam Type The type to test.
|
|
||||||
*/
|
|
||||||
template<class Type>
|
|
||||||
inline constexpr bool is_equality_comparable_v = is_equality_comparable<Type>::value;
|
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Same as std::is_invocable, but with tuples. */
|
/*! @brief Same as std::is_invocable, but with tuples. */
|
||||||
template<typename, typename>
|
template<typename, typename>
|
||||||
struct is_applicable: std::false_type {};
|
struct is_applicable: std::false_type {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copybrief is_applicable
|
* @copybrief is_applicable
|
||||||
* @tparam Func A valid function type.
|
* @tparam Func A valid function type.
|
||||||
@@ -498,7 +386,6 @@ struct is_applicable: std::false_type {};
|
|||||||
template<typename Func, template<typename...> class Tuple, typename... Args>
|
template<typename Func, template<typename...> class Tuple, typename... Args>
|
||||||
struct is_applicable<Func, Tuple<Args...>>: std::is_invocable<Func, Args...> {};
|
struct is_applicable<Func, Tuple<Args...>>: std::is_invocable<Func, Args...> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copybrief is_applicable
|
* @copybrief is_applicable
|
||||||
* @tparam Func A valid function type.
|
* @tparam Func A valid function type.
|
||||||
@@ -508,7 +395,6 @@ struct is_applicable<Func, Tuple<Args...>>: std::is_invocable<Func, Args...> {};
|
|||||||
template<typename Func, template<typename...> class Tuple, typename... Args>
|
template<typename Func, template<typename...> class Tuple, typename... Args>
|
||||||
struct is_applicable<Func, const Tuple<Args...>>: std::is_invocable<Func, Args...> {};
|
struct is_applicable<Func, const Tuple<Args...>>: std::is_invocable<Func, Args...> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam Func A valid function type.
|
* @tparam Func A valid function type.
|
||||||
@@ -517,12 +403,10 @@ struct is_applicable<Func, const Tuple<Args...>>: std::is_invocable<Func, Args..
|
|||||||
template<typename Func, typename Args>
|
template<typename Func, typename Args>
|
||||||
inline constexpr bool is_applicable_v = is_applicable<Func, Args>::value;
|
inline constexpr bool is_applicable_v = is_applicable<Func, Args>::value;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Same as std::is_invocable_r, but with tuples for arguments. */
|
/*! @brief Same as std::is_invocable_r, but with tuples for arguments. */
|
||||||
template<typename, typename, typename>
|
template<typename, typename, typename>
|
||||||
struct is_applicable_r: std::false_type {};
|
struct is_applicable_r: std::false_type {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copybrief is_applicable_r
|
* @copybrief is_applicable_r
|
||||||
* @tparam Ret The type to which the return type of the function should be
|
* @tparam Ret The type to which the return type of the function should be
|
||||||
@@ -533,7 +417,6 @@ struct is_applicable_r: std::false_type {};
|
|||||||
template<typename Ret, typename Func, typename... Args>
|
template<typename Ret, typename Func, typename... Args>
|
||||||
struct is_applicable_r<Ret, Func, std::tuple<Args...>>: std::is_invocable_r<Ret, Func, Args...> {};
|
struct is_applicable_r<Ret, Func, std::tuple<Args...>>: std::is_invocable_r<Ret, Func, Args...> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam Ret The type to which the return type of the function should be
|
* @tparam Ret The type to which the return type of the function should be
|
||||||
@@ -544,7 +427,6 @@ struct is_applicable_r<Ret, Func, std::tuple<Args...>>: std::is_invocable_r<Ret,
|
|||||||
template<typename Ret, typename Func, typename Args>
|
template<typename Ret, typename Func, typename Args>
|
||||||
inline constexpr bool is_applicable_r_v = is_applicable_r<Ret, Func, Args>::value;
|
inline constexpr bool is_applicable_r_v = is_applicable_r<Ret, Func, Args>::value;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides the member constant `value` to true if a given type is
|
* @brief Provides the member constant `value` to true if a given type is
|
||||||
* complete, false otherwise.
|
* complete, false otherwise.
|
||||||
@@ -553,12 +435,10 @@ inline constexpr bool is_applicable_r_v = is_applicable_r<Ret, Func, Args>::valu
|
|||||||
template<typename Type, typename = void>
|
template<typename Type, typename = void>
|
||||||
struct is_complete: std::false_type {};
|
struct is_complete: std::false_type {};
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc is_complete */
|
/*! @copydoc is_complete */
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct is_complete<Type, std::void_t<decltype(sizeof(Type))>>: std::true_type {};
|
struct is_complete<Type, std::void_t<decltype(sizeof(Type))>>: std::true_type {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam Type The type to test.
|
* @tparam Type The type to test.
|
||||||
@@ -566,7 +446,6 @@ struct is_complete<Type, std::void_t<decltype(sizeof(Type))>>: std::true_type {}
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline constexpr bool is_complete_v = is_complete<Type>::value;
|
inline constexpr bool is_complete_v = is_complete<Type>::value;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides the member constant `value` to true if a given type is an
|
* @brief Provides the member constant `value` to true if a given type is an
|
||||||
* iterator, false otherwise.
|
* iterator, false otherwise.
|
||||||
@@ -575,13 +454,30 @@ inline constexpr bool is_complete_v = is_complete<Type>::value;
|
|||||||
template<typename Type, typename = void>
|
template<typename Type, typename = void>
|
||||||
struct is_iterator: std::false_type {};
|
struct is_iterator: std::false_type {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename, typename = void>
|
||||||
|
struct has_iterator_category: std::false_type {};
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
struct has_iterator_category<Type, std::void_t<typename std::iterator_traits<Type>::iterator_category>>: std::true_type {};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
/*! @copydoc is_iterator */
|
/*! @copydoc is_iterator */
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct is_iterator<Type, std::void_t<typename std::iterator_traits<Type>::iterator_category>>
|
struct is_iterator<Type, std::enable_if_t<!std::is_same_v<std::remove_const_t<std::remove_pointer_t<Type>>, void>>>
|
||||||
: std::true_type
|
: internal::has_iterator_category<Type> {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
@@ -590,39 +486,110 @@ struct is_iterator<Type, std::void_t<typename std::iterator_traits<Type>::iterat
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline constexpr bool is_iterator_v = is_iterator<Type>::value;
|
inline constexpr bool is_iterator_v = is_iterator<Type>::value;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides the member constant `value` to true if a given type is of the
|
* @brief Provides the member constant `value` to true if a given type is both
|
||||||
* required iterator type, false otherwise.
|
* an empty and non-final class, false otherwise.
|
||||||
* @tparam Type The type to test.
|
* @tparam Type The type to test
|
||||||
* @tparam It Required iterator type.
|
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename It, typename = void>
|
template<typename Type>
|
||||||
struct is_iterator_type: std::false_type {};
|
struct is_ebco_eligible
|
||||||
|
: std::conjunction<std::is_empty<Type>, std::negation<std::is_final<Type>>> {};
|
||||||
|
|
||||||
/*! @copydoc is_iterator_type */
|
|
||||||
template<typename Type, typename It>
|
|
||||||
struct is_iterator_type<Type, It, std::enable_if_t<is_iterator_v<Type> && std::is_same_v<Type, It>>>
|
|
||||||
: std::true_type
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc is_iterator_type */
|
|
||||||
template<typename Type, typename It>
|
|
||||||
struct is_iterator_type<Type, It, std::enable_if_t<!std::is_same_v<Type, It>, std::void_t<typename It::iterator_type>>>
|
|
||||||
: is_iterator_type<Type, typename It::iterator_type>
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam Type The type to test.
|
* @tparam Type The type to test.
|
||||||
* @tparam It Required iterator type.
|
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename It>
|
template<typename Type>
|
||||||
inline constexpr bool is_iterator_type_v = is_iterator_type<Type, It>::value;
|
inline constexpr bool is_ebco_eligible_v = is_ebco_eligible<Type>::value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Provides the member constant `value` to true if `Type::is_transparent`
|
||||||
|
* is valid and denotes a type, false otherwise.
|
||||||
|
* @tparam Type The type to test.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename = void>
|
||||||
|
struct is_transparent: std::false_type {};
|
||||||
|
|
||||||
|
/*! @copydoc is_transparent */
|
||||||
|
template<typename Type>
|
||||||
|
struct is_transparent<Type, std::void_t<typename Type::is_transparent>>: std::true_type {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper variable template.
|
||||||
|
* @tparam Type The type to test.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
inline constexpr bool is_transparent_v = is_transparent<Type>::value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Provides the member constant `value` to true if a given type is
|
||||||
|
* equality comparable, false otherwise.
|
||||||
|
* @tparam Type The type to test.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename = void>
|
||||||
|
struct is_equality_comparable: std::false_type {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename, typename = void>
|
||||||
|
struct has_tuple_size_value: std::false_type {};
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
struct has_tuple_size_value<Type, std::void_t<decltype(std::tuple_size<const Type>::value)>>: std::true_type {};
|
||||||
|
|
||||||
|
template<typename Type, std::size_t... Index>
|
||||||
|
[[nodiscard]] constexpr bool unpack_maybe_equality_comparable(std::index_sequence<Index...>) {
|
||||||
|
return (is_equality_comparable<std::tuple_element_t<Index, Type>>::value && ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
[[nodiscard]] constexpr bool maybe_equality_comparable(choice_t<0>) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr auto maybe_equality_comparable(choice_t<1>) -> decltype(std::declval<typename Type::value_type>(), bool{}) {
|
||||||
|
if constexpr(is_iterator_v<Type>) {
|
||||||
|
return true;
|
||||||
|
} else if constexpr(std::is_same_v<typename Type::value_type, Type>) {
|
||||||
|
return maybe_equality_comparable<Type>(choice<0>);
|
||||||
|
} else {
|
||||||
|
return is_equality_comparable<typename Type::value_type>::value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
[[nodiscard]] constexpr std::enable_if_t<is_complete_v<std::tuple_size<std::remove_const_t<Type>>>, bool> maybe_equality_comparable(choice_t<2>) {
|
||||||
|
if constexpr(has_tuple_size_value<Type>::value) {
|
||||||
|
return unpack_maybe_equality_comparable<Type>(std::make_index_sequence<std::tuple_size<Type>::value>{});
|
||||||
|
} else {
|
||||||
|
return maybe_equality_comparable<Type>(choice<1>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! @copydoc is_equality_comparable */
|
||||||
|
template<typename Type>
|
||||||
|
struct is_equality_comparable<Type, std::void_t<decltype(std::declval<Type>() == std::declval<Type>())>>
|
||||||
|
: std::bool_constant<internal::maybe_equality_comparable<Type>(choice<2>)> {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper variable template.
|
||||||
|
* @tparam Type The type to test.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
inline constexpr bool is_equality_comparable_v = is_equality_comparable<Type>::value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Transcribes the constness of a type to another type.
|
* @brief Transcribes the constness of a type to another type.
|
||||||
@@ -635,7 +602,6 @@ struct constness_as {
|
|||||||
using type = std::remove_const_t<To>;
|
using type = std::remove_const_t<To>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc constness_as */
|
/*! @copydoc constness_as */
|
||||||
template<typename To, typename From>
|
template<typename To, typename From>
|
||||||
struct constness_as<To, const From> {
|
struct constness_as<To, const From> {
|
||||||
@@ -643,7 +609,6 @@ struct constness_as<To, const From> {
|
|||||||
using type = std::add_const_t<To>;
|
using type = std::add_const_t<To>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias template to facilitate the transcription of the constness.
|
* @brief Alias template to facilitate the transcription of the constness.
|
||||||
* @tparam To The type to which to transcribe the constness.
|
* @tparam To The type to which to transcribe the constness.
|
||||||
@@ -652,7 +617,6 @@ struct constness_as<To, const From> {
|
|||||||
template<typename To, typename From>
|
template<typename To, typename From>
|
||||||
using constness_as_t = typename constness_as<To, From>::type;
|
using constness_as_t = typename constness_as<To, From>::type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Extracts the class of a non-static member object or function.
|
* @brief Extracts the class of a non-static member object or function.
|
||||||
* @tparam Member A pointer to a non-static member object or function.
|
* @tparam Member A pointer to a non-static member object or function.
|
||||||
@@ -662,20 +626,19 @@ class member_class {
|
|||||||
static_assert(std::is_member_pointer_v<Member>, "Invalid pointer type to non-static member object or function");
|
static_assert(std::is_member_pointer_v<Member>, "Invalid pointer type to non-static member object or function");
|
||||||
|
|
||||||
template<typename Class, typename Ret, typename... Args>
|
template<typename Class, typename Ret, typename... Args>
|
||||||
static Class * clazz(Ret(Class:: *)(Args...));
|
static Class *clazz(Ret (Class::*)(Args...));
|
||||||
|
|
||||||
template<typename Class, typename Ret, typename... Args>
|
template<typename Class, typename Ret, typename... Args>
|
||||||
static Class * clazz(Ret(Class:: *)(Args...) const);
|
static Class *clazz(Ret (Class::*)(Args...) const);
|
||||||
|
|
||||||
template<typename Class, typename Type>
|
template<typename Class, typename Type>
|
||||||
static Class * clazz(Type Class:: *);
|
static Class *clazz(Type Class::*);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief The class of the given non-static member object or function. */
|
/*! @brief The class of the given non-static member object or function. */
|
||||||
using type = std::remove_pointer_t<decltype(clazz(std::declval<Member>()))>;
|
using type = std::remove_pointer_t<decltype(clazz(std::declval<Member>()))>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam Member A pointer to a non-static member object or function.
|
* @tparam Member A pointer to a non-static member object or function.
|
||||||
@@ -683,8 +646,6 @@ public:
|
|||||||
template<typename Member>
|
template<typename Member>
|
||||||
using member_class_t = typename member_class<Member>::type;
|
using member_class_t = typename member_class<Member>::type;
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#ifndef ENTT_CORE_UTILITY_HPP
|
#ifndef ENTT_CORE_UTILITY_HPP
|
||||||
#define ENTT_CORE_UTILITY_HPP
|
#define ENTT_CORE_UTILITY_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Identity function object (waiting for C++20). */
|
/*! @brief Identity function object (waiting for C++20). */
|
||||||
struct identity {
|
struct identity {
|
||||||
|
/*! @brief Indicates that this is a transparent function object. */
|
||||||
|
using is_transparent = void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns its argument unchanged.
|
* @brief Returns its argument unchanged.
|
||||||
* @tparam Type Type of the argument.
|
* @tparam Type Type of the argument.
|
||||||
@@ -18,12 +18,11 @@ struct identity {
|
|||||||
* @return The submitted value as-is.
|
* @return The submitted value as-is.
|
||||||
*/
|
*/
|
||||||
template<class Type>
|
template<class Type>
|
||||||
[[nodiscard]] constexpr Type && operator()(Type &&value) const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr Type &&operator()(Type &&value) const ENTT_NOEXCEPT {
|
||||||
return std::forward<Type>(value);
|
return std::forward<Type>(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constant utility to disambiguate overloaded members of a class.
|
* @brief Constant utility to disambiguate overloaded members of a class.
|
||||||
* @tparam Type Type of the desired overload.
|
* @tparam Type Type of the desired overload.
|
||||||
@@ -32,8 +31,9 @@ struct identity {
|
|||||||
* @return Pointer to the member.
|
* @return Pointer to the member.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename Class>
|
template<typename Type, typename Class>
|
||||||
[[nodiscard]] constexpr auto overload(Type Class:: *member) ENTT_NOEXCEPT { return member; }
|
[[nodiscard]] constexpr auto overload(Type Class::*member) ENTT_NOEXCEPT {
|
||||||
|
return member;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constant utility to disambiguate overloaded functions.
|
* @brief Constant utility to disambiguate overloaded functions.
|
||||||
@@ -42,8 +42,9 @@ template<typename Type, typename Class>
|
|||||||
* @return Pointer to the function.
|
* @return Pointer to the function.
|
||||||
*/
|
*/
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
[[nodiscard]] constexpr auto overload(Func *func) ENTT_NOEXCEPT { return func; }
|
[[nodiscard]] constexpr auto overload(Func *func) ENTT_NOEXCEPT {
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type for visitors.
|
* @brief Helper type for visitors.
|
||||||
@@ -54,15 +55,12 @@ struct overloaded: Func... {
|
|||||||
using Func::operator()...;
|
using Func::operator()...;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deduction guide.
|
* @brief Deduction guide.
|
||||||
* @tparam Func Types of function objects.
|
* @tparam Func Types of function objects.
|
||||||
*/
|
*/
|
||||||
template<class... Func>
|
template<class... Func>
|
||||||
overloaded(Func...)
|
overloaded(Func...) -> overloaded<Func...>;
|
||||||
-> overloaded<Func...>;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Basic implementation of a y-combinator.
|
* @brief Basic implementation of a y-combinator.
|
||||||
@@ -74,9 +72,8 @@ struct y_combinator {
|
|||||||
* @brief Constructs a y-combinator from a given function.
|
* @brief Constructs a y-combinator from a given function.
|
||||||
* @param recursive A potentially recursive function.
|
* @param recursive A potentially recursive function.
|
||||||
*/
|
*/
|
||||||
y_combinator(Func recursive):
|
y_combinator(Func recursive)
|
||||||
func{std::move(recursive)}
|
: func{std::move(recursive)} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Invokes a y-combinator and therefore its underlying function.
|
* @brief Invokes a y-combinator and therefore its underlying function.
|
||||||
@@ -84,14 +81,14 @@ struct y_combinator {
|
|||||||
* @param args Parameters to use to invoke the underlying function.
|
* @param args Parameters to use to invoke the underlying function.
|
||||||
* @return Return value of the underlying function, if any.
|
* @return Return value of the underlying function, if any.
|
||||||
*/
|
*/
|
||||||
template <class... Args>
|
template<class... Args>
|
||||||
decltype(auto) operator()(Args &&... args) const {
|
decltype(auto) operator()(Args &&...args) const {
|
||||||
return func(*this, std::forward<Args>(args)...);
|
return func(*this, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc operator()() */
|
/*! @copydoc operator()() */
|
||||||
template <class... Args>
|
template<class... Args>
|
||||||
decltype(auto) operator()(Args &&... args) {
|
decltype(auto) operator()(Args &&...args) {
|
||||||
return func(*this, std::forward<Args>(args)...);
|
return func(*this, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +96,6 @@ private:
|
|||||||
Func func;
|
Func func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,34 +1,61 @@
|
|||||||
#ifndef ENTT_ENTITY_COMPONENT_HPP
|
#ifndef ENTT_ENTITY_COMPONENT_HPP
|
||||||
#define ENTT_ENTITY_COMPONENT_HPP
|
#define ENTT_ENTITY_COMPONENT_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
/*! @brief Commonly used default traits for all types. */
|
namespace internal {
|
||||||
struct basic_component_traits {
|
|
||||||
/*! @brief Pointer stability, default is `std::false_type`. */
|
|
||||||
using in_place_delete = std::false_type;
|
|
||||||
/*! @brief Empty type optimization, default is `ENTT_IGNORE_IF_EMPTY`. */
|
|
||||||
using ignore_if_empty = ENTT_IGNORE_IF_EMPTY;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
template<typename, typename = void>
|
||||||
|
struct in_place_delete: std::false_type {};
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
struct in_place_delete<Type, std::enable_if_t<Type::in_place_delete>>
|
||||||
|
: std::true_type {};
|
||||||
|
|
||||||
|
template<typename Type, typename = void>
|
||||||
|
struct page_size: std::integral_constant<std::size_t, (ENTT_IGNORE_IF_EMPTY && std::is_empty_v<Type>) ? 0u : ENTT_PACKED_PAGE> {};
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
struct page_size<Type, std::enable_if_t<std::is_convertible_v<decltype(Type::page_size), std::size_t>>>
|
||||||
|
: std::integral_constant<std::size_t, Type::page_size> {};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Common way to access various properties of components.
|
* @brief Common way to access various properties of components.
|
||||||
* @tparam Type Type of component.
|
* @tparam Type Type of component.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename = void>
|
template<typename Type, typename = void>
|
||||||
struct component_traits: basic_component_traits {
|
struct component_traits {
|
||||||
static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
|
static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
|
||||||
|
|
||||||
|
/*! @brief Pointer stability, default is `false`. */
|
||||||
|
static constexpr bool in_place_delete = internal::in_place_delete<Type>::value;
|
||||||
|
/*! @brief Page size, default is `ENTT_PACKED_PAGE` for non-empty types. */
|
||||||
|
static constexpr std::size_t page_size = internal::page_size<Type>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper variable template.
|
||||||
|
* @tparam Type Type of component.
|
||||||
|
*/
|
||||||
|
template<class Type>
|
||||||
|
inline constexpr bool ignore_as_empty_v = (component_traits<Type>::page_size == 0u);
|
||||||
|
|
||||||
}
|
} // namespace entt
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,91 +1,78 @@
|
|||||||
#ifndef ENTT_ENTITY_ENTITY_HPP
|
#ifndef ENTT_ENTITY_ENTITY_HPP
|
||||||
#define ENTT_ENTITY_ENTITY_HPP
|
#define ENTT_ENTITY_ENTITY_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
#include "fwd.hpp"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @cond TURN_OFF_DOXYGEN
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
||||||
template<typename, typename = void>
|
template<typename, typename = void>
|
||||||
struct entt_traits;
|
struct entt_traits;
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
|
struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
|
||||||
: entt_traits<std::underlying_type_t<Type>>
|
: entt_traits<std::underlying_type_t<Type>> {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
|
struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
|
||||||
: entt_traits<typename Type::entity_type>
|
: entt_traits<typename Type::entity_type> {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct entt_traits<std::uint32_t> {
|
struct entt_traits<std::uint32_t> {
|
||||||
using entity_type = std::uint32_t;
|
using entity_type = std::uint32_t;
|
||||||
using version_type = std::uint16_t;
|
using version_type = std::uint16_t;
|
||||||
using difference_type = std::int64_t;
|
|
||||||
|
|
||||||
static constexpr entity_type entity_mask = 0xFFFFF;
|
static constexpr entity_type entity_mask = 0xFFFFF;
|
||||||
static constexpr entity_type version_mask = 0xFFF;
|
static constexpr entity_type version_mask = 0xFFF;
|
||||||
static constexpr std::size_t entity_shift = 20u;
|
static constexpr std::size_t entity_shift = 20u;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct entt_traits<std::uint64_t> {
|
struct entt_traits<std::uint64_t> {
|
||||||
using entity_type = std::uint64_t;
|
using entity_type = std::uint64_t;
|
||||||
using version_type = std::uint32_t;
|
using version_type = std::uint32_t;
|
||||||
using difference_type = std::int64_t;
|
|
||||||
|
|
||||||
static constexpr entity_type entity_mask = 0xFFFFFFFF;
|
static constexpr entity_type entity_mask = 0xFFFFFFFF;
|
||||||
static constexpr entity_type version_mask = 0xFFFFFFFF;
|
static constexpr entity_type version_mask = 0xFFFFFFFF;
|
||||||
static constexpr std::size_t entity_shift = 32u;
|
static constexpr std::size_t entity_shift = 32u;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Entity traits.
|
* @brief Entity traits.
|
||||||
* @tparam Type Type of identifier.
|
* @tparam Type Type of identifier.
|
||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class entt_traits: private internal::entt_traits<Type> {
|
class entt_traits: internal::entt_traits<Type> {
|
||||||
using traits_type = internal::entt_traits<Type>;
|
using base_type = internal::entt_traits<Type>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief Value type. */
|
/*! @brief Value type. */
|
||||||
using value_type = Type;
|
using value_type = Type;
|
||||||
/*! @brief Underlying entity type. */
|
/*! @brief Underlying entity type. */
|
||||||
using entity_type = typename traits_type::entity_type;
|
using entity_type = typename base_type::entity_type;
|
||||||
/*! @brief Underlying version type. */
|
/*! @brief Underlying version type. */
|
||||||
using version_type = typename traits_type::version_type;
|
using version_type = typename base_type::version_type;
|
||||||
/*! @brief Difference type. */
|
/*! @brief Reserved identifier. */
|
||||||
using difference_type = typename traits_type::difference_type;
|
static constexpr entity_type reserved = base_type::entity_mask | (base_type::version_mask << base_type::entity_shift);
|
||||||
|
/*! @brief Page size, default is `ENTT_SPARSE_PAGE`. */
|
||||||
|
static constexpr auto page_size = ENTT_SPARSE_PAGE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts an entity to its underlying type.
|
* @brief Converts an entity to its underlying type.
|
||||||
@@ -102,7 +89,7 @@ public:
|
|||||||
* @return The integral representation of the entity part.
|
* @return The integral representation of the entity part.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static constexpr entity_type to_entity(const value_type value) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr entity_type to_entity(const value_type value) ENTT_NOEXCEPT {
|
||||||
return (to_integral(value) & traits_type::entity_mask);
|
return (to_integral(value) & base_type::entity_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,8 +98,7 @@ public:
|
|||||||
* @return The integral representation of the version part.
|
* @return The integral representation of the version part.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static constexpr version_type to_version(const value_type value) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr version_type to_version(const value_type value) ENTT_NOEXCEPT {
|
||||||
constexpr auto mask = (traits_type::version_mask << traits_type::entity_shift);
|
return (to_integral(value) >> base_type::entity_shift);
|
||||||
return ((to_integral(value) & mask) >> traits_type::entity_shift);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,34 +111,64 @@ public:
|
|||||||
* @param version The version part of the identifier.
|
* @param version The version part of the identifier.
|
||||||
* @return A properly constructed identifier.
|
* @return A properly constructed identifier.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static constexpr value_type construct(const entity_type entity = traits_type::entity_mask, const version_type version = traits_type::version_mask) ENTT_NOEXCEPT {
|
[[nodiscard]] static constexpr value_type construct(const entity_type entity, const version_type version) ENTT_NOEXCEPT {
|
||||||
return value_type{(entity & traits_type::entity_mask) | (version << traits_type::entity_shift)};
|
return value_type{(entity & base_type::entity_mask) | (static_cast<entity_type>(version) << base_type::entity_shift)};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Combines two identifiers in a single one.
|
||||||
|
*
|
||||||
|
* The returned identifier is a copy of the first element except for its
|
||||||
|
* version, which is taken from the second element.
|
||||||
|
*
|
||||||
|
* @param lhs The identifier from which to take the entity part.
|
||||||
|
* @param rhs The identifier from which to take the version part.
|
||||||
|
* @return A properly constructed identifier.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] static constexpr value_type combine(const entity_type lhs, const entity_type rhs) ENTT_NOEXCEPT {
|
||||||
|
constexpr auto mask = (base_type::version_mask << base_type::entity_shift);
|
||||||
|
return value_type{(lhs & base_type::entity_mask) | (rhs & mask)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts an entity to its underlying type.
|
* @copydoc entt_traits<Entity>::to_integral
|
||||||
* @tparam Entity The value type.
|
* @tparam Entity The value type.
|
||||||
* @param entity The value to convert.
|
|
||||||
* @return The integral representation of the given value.
|
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
[[nodiscard]] constexpr auto to_integral(const Entity entity) ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_integral(const Entity value) ENTT_NOEXCEPT {
|
||||||
return entt_traits<Entity>::to_integral(entity);
|
return entt_traits<Entity>::to_integral(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copydoc entt_traits<Entity>::to_entity
|
||||||
|
* @tparam Entity The value type.
|
||||||
|
*/
|
||||||
|
template<typename Entity>
|
||||||
|
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_entity(const Entity value) ENTT_NOEXCEPT {
|
||||||
|
return entt_traits<Entity>::to_entity(value);
|
||||||
|
}
|
||||||
|
|
||||||
/*! @brief Null object for all entity identifiers. */
|
/**
|
||||||
|
* @copydoc entt_traits<Entity>::to_version
|
||||||
|
* @tparam Entity The value type.
|
||||||
|
*/
|
||||||
|
template<typename Entity>
|
||||||
|
[[nodiscard]] constexpr typename entt_traits<Entity>::version_type to_version(const Entity value) ENTT_NOEXCEPT {
|
||||||
|
return entt_traits<Entity>::to_version(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @brief Null object for all identifiers. */
|
||||||
struct null_t {
|
struct null_t {
|
||||||
/**
|
/**
|
||||||
* @brief Converts the null object to identifiers of any type.
|
* @brief Converts the null object to identifiers of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @return The null representation for the given type.
|
* @return The null representation for the given type.
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
|
||||||
return entt_traits<Entity>::construct();
|
using entity_traits = entt_traits<Entity>;
|
||||||
|
return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,44 +190,33 @@ struct null_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a null object and an entity identifier of any type.
|
* @brief Compares a null object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @return False if the two elements differ, true otherwise.
|
* @return False if the two elements differ, true otherwise.
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
[[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
|
||||||
return entt_traits<Entity>::to_entity(entity) == entt_traits<Entity>::to_entity(*this);
|
using entity_traits = entt_traits<Entity>;
|
||||||
|
return entity_traits::to_entity(entity) == entity_traits::to_entity(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a null object and an entity identifier of any type.
|
* @brief Compares a null object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @return True if the two elements differ, false otherwise.
|
* @return True if the two elements differ, false otherwise.
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
[[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
|
||||||
return !(entity == *this);
|
return !(entity == *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a null object from an entity identifier of any type.
|
|
||||||
* @tparam Entity Type of entity identifier.
|
|
||||||
* @param entity Entity identifier to turn into a null object.
|
|
||||||
* @return The null representation for the given identifier.
|
|
||||||
*/
|
|
||||||
template<typename Entity>
|
|
||||||
[[nodiscard]] constexpr Entity operator|(const Entity entity) const ENTT_NOEXCEPT {
|
|
||||||
return entt_traits<Entity>::construct(entt_traits<Entity>::to_entity(*this), entt_traits<Entity>::to_version(entity));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a null object and an entity identifier of any type.
|
* @brief Compares a null object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @param other A null object yet to be converted.
|
* @param other A null object yet to be converted.
|
||||||
* @return False if the two elements differ, true otherwise.
|
* @return False if the two elements differ, true otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -220,11 +225,10 @@ template<typename Entity>
|
|||||||
return other.operator==(entity);
|
return other.operator==(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a null object and an entity identifier of any type.
|
* @brief Compares a null object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @param other A null object yet to be converted.
|
* @param other A null object yet to be converted.
|
||||||
* @return True if the two elements differ, false otherwise.
|
* @return True if the two elements differ, false otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -233,17 +237,17 @@ template<typename Entity>
|
|||||||
return !(other == entity);
|
return !(other == entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! @brief Tombstone object for all identifiers. */
|
||||||
/*! @brief Tombstone object for all entity identifiers. */
|
|
||||||
struct tombstone_t {
|
struct tombstone_t {
|
||||||
/**
|
/**
|
||||||
* @brief Converts the tombstone object to identifiers of any type.
|
* @brief Converts the tombstone object to identifiers of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @return The tombstone representation for the given type.
|
* @return The tombstone representation for the given type.
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
|
||||||
return entt_traits<Entity>::construct();
|
using entity_traits = entt_traits<Entity>;
|
||||||
|
return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -265,44 +269,33 @@ struct tombstone_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a tombstone object and an entity identifier of any type.
|
* @brief Compares a tombstone object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @return False if the two elements differ, true otherwise.
|
* @return False if the two elements differ, true otherwise.
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
[[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
|
||||||
return entt_traits<Entity>::to_version(entity) == entt_traits<Entity>::to_version(*this);
|
using entity_traits = entt_traits<Entity>;
|
||||||
|
return entity_traits::to_version(entity) == entity_traits::to_version(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a tombstone object and an entity identifier of any type.
|
* @brief Compares a tombstone object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @return True if the two elements differ, false otherwise.
|
* @return True if the two elements differ, false otherwise.
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
[[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
|
[[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
|
||||||
return !(entity == *this);
|
return !(entity == *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a tombstone object from an entity identifier of any type.
|
|
||||||
* @tparam Entity Type of entity identifier.
|
|
||||||
* @param entity Entity identifier to turn into a tombstone object.
|
|
||||||
* @return The tombstone representation for the given identifier.
|
|
||||||
*/
|
|
||||||
template<typename Entity>
|
|
||||||
[[nodiscard]] constexpr Entity operator|(const Entity entity) const ENTT_NOEXCEPT {
|
|
||||||
return entt_traits<Entity>::construct(entt_traits<Entity>::to_entity(entity));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a tombstone object and an entity identifier of any type.
|
* @brief Compares a tombstone object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @param other A tombstone object yet to be converted.
|
* @param other A tombstone object yet to be converted.
|
||||||
* @return False if the two elements differ, true otherwise.
|
* @return False if the two elements differ, true otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -311,11 +304,10 @@ template<typename Entity>
|
|||||||
return other.operator==(entity);
|
return other.operator==(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares a tombstone object and an entity identifier of any type.
|
* @brief Compares a tombstone object and an identifier of any type.
|
||||||
* @tparam Entity Type of entity identifier.
|
* @tparam Entity Type of identifier.
|
||||||
* @param entity Entity identifier with which to compare.
|
* @param entity Identifier with which to compare.
|
||||||
* @param other A tombstone object yet to be converted.
|
* @param other A tombstone object yet to be converted.
|
||||||
* @return True if the two elements differ, false otherwise.
|
* @return True if the two elements differ, false otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -324,28 +316,24 @@ template<typename Entity>
|
|||||||
return !(other == entity);
|
return !(other == entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compile-time constant for null entities.
|
* @brief Compile-time constant for null entities.
|
||||||
*
|
*
|
||||||
* There exist implicit conversions from this variable to entity identifiers of
|
* There exist implicit conversions from this variable to identifiers of any
|
||||||
* any allowed type. Similarly, there exist comparision operators between the
|
* allowed type. Similarly, there exist comparison operators between the null
|
||||||
* null entity and any other entity identifier.
|
* entity and any other identifier.
|
||||||
*/
|
*/
|
||||||
inline constexpr null_t null{};
|
inline constexpr null_t null{};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compile-time constant for tombstone entities.
|
* @brief Compile-time constant for tombstone entities.
|
||||||
*
|
*
|
||||||
* There exist implicit conversions from this variable to entity identifiers of
|
* There exist implicit conversions from this variable to identifiers of any
|
||||||
* any allowed type. Similarly, there exist comparision operators between the
|
* allowed type. Similarly, there exist comparison operators between the
|
||||||
* tombstone entity and any other entity identifier.
|
* tombstone entity and any other identifier.
|
||||||
*/
|
*/
|
||||||
inline constexpr tombstone_t tombstone{};
|
inline constexpr tombstone_t tombstone{};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,70 +1,54 @@
|
|||||||
#ifndef ENTT_ENTITY_FWD_HPP
|
#ifndef ENTT_ENTITY_FWD_HPP
|
||||||
#define ENTT_ENTITY_FWD_HPP
|
#define ENTT_ENTITY_FWD_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "../core/fwd.hpp"
|
#include "../core/fwd.hpp"
|
||||||
|
#include "utility.hpp"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
template<typename Entity, typename = std::allocator<Entity>>
|
template<typename Entity, typename = std::allocator<Entity>>
|
||||||
class basic_sparse_set;
|
class basic_sparse_set;
|
||||||
|
|
||||||
|
template<typename, typename Type, typename = std::allocator<Type>, typename = void>
|
||||||
template<typename, typename Type, typename = std::allocator<Type>>
|
class basic_storage;
|
||||||
struct basic_storage;
|
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
class basic_registry;
|
class basic_registry;
|
||||||
|
|
||||||
|
template<typename, typename, typename, typename = void>
|
||||||
template<typename...>
|
class basic_view;
|
||||||
struct basic_view;
|
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
class basic_runtime_view;
|
struct basic_runtime_view;
|
||||||
|
|
||||||
|
template<typename, typename, typename, typename>
|
||||||
template<typename...>
|
|
||||||
class basic_group;
|
class basic_group;
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
class basic_observer;
|
class basic_observer;
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
class basic_organizer;
|
class basic_organizer;
|
||||||
|
|
||||||
|
|
||||||
template<typename, typename...>
|
template<typename, typename...>
|
||||||
struct basic_handle;
|
struct basic_handle;
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
class basic_snapshot;
|
class basic_snapshot;
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
class basic_snapshot_loader;
|
class basic_snapshot_loader;
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
class basic_continuous_loader;
|
class basic_continuous_loader;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Default entity identifier. */
|
/*! @brief Default entity identifier. */
|
||||||
enum class entity: id_type {};
|
enum class entity : id_type {};
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using sparse_set = basic_sparse_set<entity>;
|
using sparse_set = basic_sparse_set<entity>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias declaration for the most common use case.
|
* @brief Alias declaration for the most common use case.
|
||||||
* @tparam Args Other template parameters.
|
* @tparam Args Other template parameters.
|
||||||
@@ -72,27 +56,21 @@ using sparse_set = basic_sparse_set<entity>;
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using storage = basic_storage<entity, Args...>;
|
using storage = basic_storage<entity, Args...>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using registry = basic_registry<entity>;
|
using registry = basic_registry<entity>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using observer = basic_observer<entity>;
|
using observer = basic_observer<entity>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using organizer = basic_organizer<entity>;
|
using organizer = basic_organizer<entity>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using handle = basic_handle<entity>;
|
using handle = basic_handle<entity>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using const_handle = basic_handle<const entity>;
|
using const_handle = basic_handle<const entity>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias declaration for the most common use case.
|
* @brief Alias declaration for the most common use case.
|
||||||
* @tparam Args Other template parameters.
|
* @tparam Args Other template parameters.
|
||||||
@@ -100,7 +78,6 @@ using const_handle = basic_handle<const entity>;
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using handle_view = basic_handle<entity, Args...>;
|
using handle_view = basic_handle<entity, Args...>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias declaration for the most common use case.
|
* @brief Alias declaration for the most common use case.
|
||||||
* @tparam Args Other template parameters.
|
* @tparam Args Other template parameters.
|
||||||
@@ -108,30 +85,25 @@ using handle_view = basic_handle<entity, Args...>;
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using const_handle_view = basic_handle<const entity, Args...>;
|
using const_handle_view = basic_handle<const entity, Args...>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using snapshot = basic_snapshot<entity>;
|
using snapshot = basic_snapshot<entity>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using snapshot_loader = basic_snapshot_loader<entity>;
|
using snapshot_loader = basic_snapshot_loader<entity>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using continuous_loader = basic_continuous_loader<entity>;
|
using continuous_loader = basic_continuous_loader<entity>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias declaration for the most common use case.
|
* @brief Alias declaration for the most common use case.
|
||||||
* @tparam Args Other template parameters.
|
* @tparam Get Types of components iterated by the view.
|
||||||
|
* @tparam Exclude Types of components used to filter the view.
|
||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename Get, typename Exclude = exclude_t<>>
|
||||||
using view = basic_view<entity, Args...>;
|
using view = basic_view<entity, Get, Exclude>;
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Alias declaration for the most common use case. */
|
/*! @brief Alias declaration for the most common use case. */
|
||||||
using runtime_view = basic_runtime_view<entity>;
|
using runtime_view = basic_runtime_view<sparse_set>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias declaration for the most common use case.
|
* @brief Alias declaration for the most common use case.
|
||||||
@@ -140,8 +112,6 @@ using runtime_view = basic_runtime_view<entity>;
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using group = basic_group<entity, Args...>;
|
using group = basic_group<entity, Args...>;
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,32 +1,30 @@
|
|||||||
#ifndef ENTT_ENTITY_GROUP_HPP
|
#ifndef ENTT_ENTITY_GROUP_HPP
|
||||||
#define ENTT_ENTITY_GROUP_HPP
|
#define ENTT_ENTITY_GROUP_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
#include "../core/iterator.hpp"
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
|
#include "component.hpp"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
#include "sparse_set.hpp"
|
#include "sparse_set.hpp"
|
||||||
#include "storage.hpp"
|
#include "storage.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Group.
|
* @brief Group.
|
||||||
*
|
*
|
||||||
* Primary template isn't defined on purpose. All the specializations give a
|
* Primary template isn't defined on purpose. All the specializations give a
|
||||||
* compile-time error, but for a few reasonable cases.
|
* compile-time error, but for a few reasonable cases.
|
||||||
*/
|
*/
|
||||||
template<typename...>
|
template<typename, typename, typename, typename>
|
||||||
class basic_group;
|
class basic_group;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Non-owning group.
|
* @brief Non-owning group.
|
||||||
*
|
*
|
||||||
@@ -60,112 +58,112 @@ class basic_group;
|
|||||||
* In any other case, attempting to use a group results in undefined behavior.
|
* In any other case, attempting to use a group results in undefined behavior.
|
||||||
*
|
*
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
* @tparam Exclude Types of components used to filter the group.
|
|
||||||
* @tparam Get Type of components observed by the group.
|
* @tparam Get Type of components observed by the group.
|
||||||
|
* @tparam Exclude Types of components used to filter the group.
|
||||||
*/
|
*/
|
||||||
template<typename Entity, typename... Exclude, typename... Get>
|
template<typename Entity, typename... Get, typename... Exclude>
|
||||||
class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
|
class basic_group<Entity, owned_t<>, get_t<Get...>, exclude_t<Exclude...>> {
|
||||||
/*! @brief A registry is allowed to create groups. */
|
/*! @brief A registry is allowed to create groups. */
|
||||||
friend class basic_registry<Entity>;
|
friend class basic_registry<Entity>;
|
||||||
|
|
||||||
using basic_common_type = basic_sparse_set<Entity>;
|
template<typename Comp>
|
||||||
|
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
|
||||||
|
|
||||||
template<typename Component>
|
using basic_common_type = std::common_type_t<typename storage_type<Get>::base_type...>;
|
||||||
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
|
|
||||||
|
|
||||||
class iterable final {
|
struct extended_group_iterator final {
|
||||||
template<typename It>
|
using difference_type = std::ptrdiff_t;
|
||||||
struct iterable_iterator final {
|
using value_type = decltype(std::tuple_cat(std::tuple<Entity>{}, std::declval<basic_group>().get({})));
|
||||||
using difference_type = std::ptrdiff_t;
|
using pointer = input_iterator_pointer<value_type>;
|
||||||
using value_type = decltype(std::tuple_cat(std::tuple<Entity>{}, std::declval<basic_group>().get({})));
|
using reference = value_type;
|
||||||
using pointer = void;
|
using iterator_category = std::input_iterator_tag;
|
||||||
using reference = value_type;
|
|
||||||
using iterator_category = std::input_iterator_tag;
|
|
||||||
|
|
||||||
template<typename... Args>
|
extended_group_iterator() = default;
|
||||||
iterable_iterator(It from, const std::tuple<storage_type<Get> *...> &args) ENTT_NOEXCEPT
|
|
||||||
: it{from},
|
|
||||||
pools{args}
|
|
||||||
{}
|
|
||||||
|
|
||||||
iterable_iterator & operator++() ENTT_NOEXCEPT {
|
extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<storage_type<Get> *...> &args)
|
||||||
return ++it, *this;
|
: it{from},
|
||||||
}
|
pools{args} {}
|
||||||
|
|
||||||
iterable_iterator operator++(int) ENTT_NOEXCEPT {
|
extended_group_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
iterable_iterator orig = *this;
|
return ++it, *this;
|
||||||
return ++(*this), orig;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
|
||||||
const auto entt = *it;
|
|
||||||
return std::tuple_cat(std::make_tuple(entt), get_as_tuple(*std::get<storage_type<Get> *>(pools), entt)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator==(const iterable_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return other.it == it;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const iterable_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
It it;
|
|
||||||
std::tuple<storage_type<Get> *...> pools;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
using iterator = iterable_iterator<typename basic_common_type::iterator>;
|
|
||||||
using reverse_iterator = iterable_iterator<typename basic_common_type::reverse_iterator>;
|
|
||||||
|
|
||||||
iterable(basic_common_type * const ref, const std::tuple<storage_type<Get> *...> &cpools)
|
|
||||||
: handler{ref},
|
|
||||||
pools{cpools}
|
|
||||||
{}
|
|
||||||
|
|
||||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
|
||||||
return handler ? iterator{handler->begin(), pools} : iterator{{}, pools};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
extended_group_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
return handler ? iterator{handler->end(), pools} : iterator{{}, pools};
|
extended_group_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
return handler ? reverse_iterator{handler->rbegin(), pools} : reverse_iterator{{}, pools};
|
const auto entt = *it;
|
||||||
|
return std::tuple_cat(std::make_tuple(entt), std::get<storage_type<Get> *>(pools)->get_as_tuple(entt)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
return handler ? reverse_iterator{handler->rend(), pools} : reverse_iterator{{}, pools};
|
return operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator==(const extended_group_iterator &other) const ENTT_NOEXCEPT {
|
||||||
|
return other.it == it;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator!=(const extended_group_iterator &other) const ENTT_NOEXCEPT {
|
||||||
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
basic_common_type * const handler;
|
typename basic_common_type::iterator it;
|
||||||
const std::tuple<storage_type<Get> *...> pools;
|
std::tuple<storage_type<Get> *...> pools;
|
||||||
};
|
};
|
||||||
|
|
||||||
basic_group(basic_common_type &ref, storage_type<Get> &... gpool) ENTT_NOEXCEPT
|
basic_group(basic_common_type &ref, storage_type<Get> &...gpool) ENTT_NOEXCEPT
|
||||||
: handler{&ref},
|
: handler{&ref},
|
||||||
pools{&gpool...}
|
pools{&gpool...} {}
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief Underlying entity identifier. */
|
/*! @brief Underlying entity identifier. */
|
||||||
using entity_type = Entity;
|
using entity_type = Entity;
|
||||||
/*! @brief Unsigned integer type. */
|
/*! @brief Unsigned integer type. */
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
|
/*! @brief Common type among all storage types. */
|
||||||
|
using base_type = basic_common_type;
|
||||||
/*! @brief Random access iterator type. */
|
/*! @brief Random access iterator type. */
|
||||||
using iterator = typename basic_common_type::iterator;
|
using iterator = typename base_type::iterator;
|
||||||
/*! @brief Reversed iterator type. */
|
/*! @brief Reversed iterator type. */
|
||||||
using reverse_iterator = typename basic_common_type::reverse_iterator;
|
using reverse_iterator = typename base_type::reverse_iterator;
|
||||||
/*! @brief Iterable group type. */
|
/*! @brief Iterable group type. */
|
||||||
using iterable_group = iterable;
|
using iterable = iterable_adaptor<extended_group_iterator>;
|
||||||
|
|
||||||
/*! @brief Default constructor to use to create empty, invalid groups. */
|
/*! @brief Default constructor to use to create empty, invalid groups. */
|
||||||
basic_group() ENTT_NOEXCEPT
|
basic_group() ENTT_NOEXCEPT
|
||||||
: handler{}
|
: handler{} {}
|
||||||
{}
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a const reference to the underlying handler.
|
||||||
|
* @return A const reference to the underlying handler.
|
||||||
|
*/
|
||||||
|
const base_type &handle() const ENTT_NOEXCEPT {
|
||||||
|
return *handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the storage for a given component type.
|
||||||
|
* @tparam Comp Type of component of which to return the storage.
|
||||||
|
* @return The storage for the given component type.
|
||||||
|
*/
|
||||||
|
template<typename Comp>
|
||||||
|
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
|
||||||
|
return *std::get<storage_type<Comp> *>(pools);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the storage for a given component type.
|
||||||
|
* @tparam Comp Index of component of which to return the storage.
|
||||||
|
* @return The storage for the given component type.
|
||||||
|
*/
|
||||||
|
template<std::size_t Comp>
|
||||||
|
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
|
||||||
|
return *std::get<Comp>(pools);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the number of entities that have the given components.
|
* @brief Returns the number of entities that have the given components.
|
||||||
@@ -199,18 +197,6 @@ public:
|
|||||||
return !*this || handler->empty();
|
return !*this || handler->empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Direct access to the list of entities.
|
|
||||||
*
|
|
||||||
* The returned pointer is such that range `[data(), data() + size())` is
|
|
||||||
* always a valid range, even if the container is empty.
|
|
||||||
*
|
|
||||||
* @return A pointer to the array of entities.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] auto data() const ENTT_NOEXCEPT {
|
|
||||||
return *this ? handler->data() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an iterator to the first entity of the group.
|
* @brief Returns an iterator to the first entity of the group.
|
||||||
*
|
*
|
||||||
@@ -269,7 +255,7 @@ public:
|
|||||||
* @return The first entity of the group if one exists, the null entity
|
* @return The first entity of the group if one exists, the null entity
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] entity_type front() const {
|
[[nodiscard]] entity_type front() const ENTT_NOEXCEPT {
|
||||||
const auto it = begin();
|
const auto it = begin();
|
||||||
return it != end() ? *it : null;
|
return it != end() ? *it : null;
|
||||||
}
|
}
|
||||||
@@ -279,18 +265,18 @@ public:
|
|||||||
* @return The last entity of the group if one exists, the null entity
|
* @return The last entity of the group if one exists, the null entity
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] entity_type back() const {
|
[[nodiscard]] entity_type back() const ENTT_NOEXCEPT {
|
||||||
const auto it = rbegin();
|
const auto it = rbegin();
|
||||||
return it != rend() ? *it : null;
|
return it != rend() ? *it : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finds an entity.
|
* @brief Finds an entity.
|
||||||
* @param entt A valid entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return An iterator to the given entity if it's found, past the end
|
* @return An iterator to the given entity if it's found, past the end
|
||||||
* iterator otherwise.
|
* iterator otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator find(const entity_type entt) const {
|
[[nodiscard]] iterator find(const entity_type entt) const ENTT_NOEXCEPT {
|
||||||
const auto it = *this ? handler->find(entt) : iterator{};
|
const auto it = *this ? handler->find(entt) : iterator{};
|
||||||
return it != end() && *it == entt ? it : end();
|
return it != end() && *it == entt ? it : end();
|
||||||
}
|
}
|
||||||
@@ -314,10 +300,10 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if a group contains an entity.
|
* @brief Checks if a group contains an entity.
|
||||||
* @param entt A valid entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return True if the group contains the given entity, false otherwise.
|
* @return True if the group contains the given entity, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
[[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
|
||||||
return *this && handler->contains(entt);
|
return *this && handler->contains(entt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,20 +318,20 @@ public:
|
|||||||
* error. Attempting to use an entity that doesn't belong to the group
|
* error. Attempting to use an entity that doesn't belong to the group
|
||||||
* results in undefined behavior.
|
* results in undefined behavior.
|
||||||
*
|
*
|
||||||
* @tparam Component Types of components to get.
|
* @tparam Comp Types of components to get.
|
||||||
* @param entt A valid entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return The components assigned to the entity.
|
* @return The components assigned to the entity.
|
||||||
*/
|
*/
|
||||||
template<typename... Component>
|
template<typename... Comp>
|
||||||
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
|
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
|
||||||
ENTT_ASSERT(contains(entt), "Group does not contain entity");
|
ENTT_ASSERT(contains(entt), "Group does not contain entity");
|
||||||
|
|
||||||
if constexpr(sizeof...(Component) == 0) {
|
if constexpr(sizeof...(Comp) == 0) {
|
||||||
return std::tuple_cat(get_as_tuple(*std::get<storage_type<Get> *>(pools), entt)...);
|
return std::tuple_cat(std::get<storage_type<Get> *>(pools)->get_as_tuple(entt)...);
|
||||||
} else if constexpr(sizeof...(Component) == 1) {
|
} else if constexpr(sizeof...(Comp) == 1) {
|
||||||
return (std::get<storage_type<Component> *>(pools)->get(entt), ...);
|
return (std::get<storage_type<Comp> *>(pools)->get(entt), ...);
|
||||||
} else {
|
} else {
|
||||||
return std::tuple_cat(get_as_tuple(*std::get<storage_type<Component> *>(pools), entt)...);
|
return std::tuple_cat(std::get<storage_type<Comp> *>(pools)->get_as_tuple(entt)...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +369,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an iterable object to use to _visit_ the group.
|
* @brief Returns an iterable object to use to _visit_ a group.
|
||||||
*
|
*
|
||||||
* The iterable object returns tuples that contain the current entity and a
|
* The iterable object returns tuples that contain the current entity and a
|
||||||
* set of references to its non-empty components. The _constness_ of the
|
* set of references to its non-empty components. The _constness_ of the
|
||||||
@@ -395,8 +381,9 @@ public:
|
|||||||
*
|
*
|
||||||
* @return An iterable object to use to _visit_ the group.
|
* @return An iterable object to use to _visit_ the group.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterable_group each() const ENTT_NOEXCEPT {
|
[[nodiscard]] iterable each() const ENTT_NOEXCEPT {
|
||||||
return iterable_group{handler, pools};
|
return handler ? iterable{extended_group_iterator{handler->begin(), pools}, extended_group_iterator{handler->end(), pools}}
|
||||||
|
: iterable{extended_group_iterator{{}, pools}, extended_group_iterator{{}, pools}};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -420,14 +407,14 @@ public:
|
|||||||
* Moreover, the comparison function object shall induce a
|
* Moreover, the comparison function object shall induce a
|
||||||
* _strict weak ordering_ on the values.
|
* _strict weak ordering_ on the values.
|
||||||
*
|
*
|
||||||
* The sort function oject must offer a member function template
|
* The sort function object must offer a member function template
|
||||||
* `operator()` that accepts three arguments:
|
* `operator()` that accepts three arguments:
|
||||||
*
|
*
|
||||||
* * An iterator to the first element of the range to sort.
|
* * An iterator to the first element of the range to sort.
|
||||||
* * An iterator past the last element of the range to sort.
|
* * An iterator past the last element of the range to sort.
|
||||||
* * A comparison function to use to compare the elements.
|
* * A comparison function to use to compare the elements.
|
||||||
*
|
*
|
||||||
* @tparam Component Optional types of components to compare.
|
* @tparam Comp Optional types of components to compare.
|
||||||
* @tparam Compare Type of comparison function object.
|
* @tparam Compare Type of comparison function object.
|
||||||
* @tparam Sort Type of sort function object.
|
* @tparam Sort Type of sort function object.
|
||||||
* @tparam Args Types of arguments to forward to the sort function object.
|
* @tparam Args Types of arguments to forward to the sort function object.
|
||||||
@@ -435,20 +422,22 @@ public:
|
|||||||
* @param algo A valid sort function object.
|
* @param algo A valid sort function object.
|
||||||
* @param args Arguments to forward to the sort function object, if any.
|
* @param args Arguments to forward to the sort function object, if any.
|
||||||
*/
|
*/
|
||||||
template<typename... Component, typename Compare, typename Sort = std_sort, typename... Args>
|
template<typename... Comp, typename Compare, typename Sort = std_sort, typename... Args>
|
||||||
void sort(Compare compare, Sort algo = Sort{}, Args &&... args) {
|
void sort(Compare compare, Sort algo = Sort{}, Args &&...args) {
|
||||||
if(*this) {
|
if(*this) {
|
||||||
if constexpr(sizeof...(Component) == 0) {
|
if constexpr(sizeof...(Comp) == 0) {
|
||||||
static_assert(std::is_invocable_v<Compare, const entity_type, const entity_type>, "Invalid comparison function");
|
static_assert(std::is_invocable_v<Compare, const entity_type, const entity_type>, "Invalid comparison function");
|
||||||
handler->sort(std::move(compare), std::move(algo), std::forward<Args>(args)...);
|
handler->sort(std::move(compare), std::move(algo), std::forward<Args>(args)...);
|
||||||
} else if constexpr(sizeof...(Component) == 1) {
|
|
||||||
handler->sort([this, compare = std::move(compare)](const entity_type lhs, const entity_type rhs) {
|
|
||||||
return compare((std::get<storage_type<Component> *>(pools)->get(lhs), ...), (std::get<storage_type<Component> *>(pools)->get(rhs), ...));
|
|
||||||
}, std::move(algo), std::forward<Args>(args)...);
|
|
||||||
} else {
|
} else {
|
||||||
handler->sort([this, compare = std::move(compare)](const entity_type lhs, const entity_type rhs) {
|
auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) {
|
||||||
return compare(std::forward_as_tuple(std::get<storage_type<Component> *>(pools)->get(lhs)...), std::forward_as_tuple(std::get<storage_type<Component> *>(pools)->get(rhs)...));
|
if constexpr(sizeof...(Comp) == 1) {
|
||||||
}, std::move(algo), std::forward<Args>(args)...);
|
return compare((std::get<storage_type<Comp> *>(pools)->get(lhs), ...), (std::get<storage_type<Comp> *>(pools)->get(rhs), ...));
|
||||||
|
} else {
|
||||||
|
return compare(std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(lhs)...), std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(rhs)...));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handler->sort(std::move(comp), std::move(algo), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,21 +456,20 @@ public:
|
|||||||
* can quickly ruin the order imposed to the pool of entities shared between
|
* can quickly ruin the order imposed to the pool of entities shared between
|
||||||
* the non-owning groups.
|
* the non-owning groups.
|
||||||
*
|
*
|
||||||
* @tparam Component Type of component to use to impose the order.
|
* @tparam Comp Type of component to use to impose the order.
|
||||||
*/
|
*/
|
||||||
template<typename Component>
|
template<typename Comp>
|
||||||
void sort() const {
|
void sort() const {
|
||||||
if(*this) {
|
if(*this) {
|
||||||
handler->respect(*std::get<storage_type<Component> *>(pools));
|
handler->respect(*std::get<storage_type<Comp> *>(pools));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
basic_common_type * const handler;
|
base_type *const handler;
|
||||||
const std::tuple<storage_type<Get> *...> pools;
|
const std::tuple<storage_type<Get> *...> pools;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Owning group.
|
* @brief Owning group.
|
||||||
*
|
*
|
||||||
@@ -524,143 +512,118 @@ private:
|
|||||||
* In any other case, attempting to use a group results in undefined behavior.
|
* In any other case, attempting to use a group results in undefined behavior.
|
||||||
*
|
*
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
* @tparam Exclude Types of components used to filter the group.
|
|
||||||
* @tparam Get Types of components observed by the group.
|
|
||||||
* @tparam Owned Types of components owned by the group.
|
* @tparam Owned Types of components owned by the group.
|
||||||
|
* @tparam Get Types of components observed by the group.
|
||||||
|
* @tparam Exclude Types of components used to filter the group.
|
||||||
*/
|
*/
|
||||||
template<typename Entity, typename... Exclude, typename... Get, typename... Owned>
|
template<typename Entity, typename... Owned, typename... Get, typename... Exclude>
|
||||||
class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> final {
|
class basic_group<Entity, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> {
|
||||||
/*! @brief A registry is allowed to create groups. */
|
/*! @brief A registry is allowed to create groups. */
|
||||||
friend class basic_registry<Entity>;
|
friend class basic_registry<Entity>;
|
||||||
|
|
||||||
using basic_common_type = basic_sparse_set<Entity>;
|
template<typename Comp>
|
||||||
|
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
|
||||||
|
|
||||||
template<typename Component>
|
using basic_common_type = std::common_type_t<typename storage_type<Owned>::base_type..., typename storage_type<Get>::base_type...>;
|
||||||
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
|
|
||||||
|
|
||||||
class iterable final {
|
class extended_group_iterator final {
|
||||||
template<typename, typename>
|
template<typename Type>
|
||||||
struct iterable_iterator;
|
auto index_to_element(storage_type<Type> &cpool) const {
|
||||||
|
if constexpr(ignore_as_empty_v<std::remove_const_t<Type>>) {
|
||||||
template<typename It, typename... OIt>
|
return std::make_tuple();
|
||||||
struct iterable_iterator<It, type_list<OIt...>> final {
|
} else {
|
||||||
using difference_type = std::ptrdiff_t;
|
return std::forward_as_tuple(cpool.rbegin()[it.index()]);
|
||||||
using value_type = decltype(std::tuple_cat(std::tuple<Entity>{}, std::declval<basic_group>().get({})));
|
|
||||||
using pointer = void;
|
|
||||||
using reference = value_type;
|
|
||||||
using iterator_category = std::input_iterator_tag;
|
|
||||||
|
|
||||||
template<typename... Other>
|
|
||||||
iterable_iterator(It from, const std::tuple<Other...> &other, const std::tuple<storage_type<Get> *...> &cpools) ENTT_NOEXCEPT
|
|
||||||
: it{from},
|
|
||||||
owned{std::get<OIt>(other)...},
|
|
||||||
get{cpools}
|
|
||||||
{}
|
|
||||||
|
|
||||||
iterable_iterator & operator++() ENTT_NOEXCEPT {
|
|
||||||
return ++it, (++std::get<OIt>(owned), ...), *this;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
iterable_iterator operator++(int) ENTT_NOEXCEPT {
|
|
||||||
iterable_iterator orig = *this;
|
|
||||||
return ++(*this), orig;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
|
||||||
return std::tuple_cat(
|
|
||||||
std::make_tuple(*it),
|
|
||||||
std::forward_as_tuple(*std::get<OIt>(owned)...),
|
|
||||||
get_as_tuple(*std::get<storage_type<Get> *>(get), *it)...
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator==(const iterable_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return other.it == it;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const iterable_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
It it;
|
|
||||||
std::tuple<OIt...> owned;
|
|
||||||
std::tuple<storage_type<Get> *...> get;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using iterator = iterable_iterator<
|
using difference_type = std::ptrdiff_t;
|
||||||
typename basic_common_type::iterator,
|
using value_type = decltype(std::tuple_cat(std::tuple<Entity>{}, std::declval<basic_group>().get({})));
|
||||||
type_list_cat_t<std::conditional_t<std::is_void_v<decltype(std::declval<storage_type<Owned>>().get({}))>, type_list<>, type_list<decltype(std::declval<storage_type<Owned>>().end())>>...>
|
using pointer = input_iterator_pointer<value_type>;
|
||||||
>;
|
using reference = value_type;
|
||||||
using reverse_iterator = iterable_iterator<
|
using iterator_category = std::input_iterator_tag;
|
||||||
typename basic_common_type::reverse_iterator,
|
|
||||||
type_list_cat_t<std::conditional_t<std::is_void_v<decltype(std::declval<storage_type<Owned>>().get({}))>, type_list<>, type_list<decltype(std::declval<storage_type<Owned>>().rbegin())>>...>
|
|
||||||
>;
|
|
||||||
|
|
||||||
iterable(std::tuple<storage_type<Owned> *..., storage_type<Get> *...> cpools, const std::size_t * const extent)
|
extended_group_iterator() = default;
|
||||||
: pools{cpools},
|
|
||||||
length{extent}
|
|
||||||
{}
|
|
||||||
|
|
||||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
template<typename... Other>
|
||||||
return length ? iterator{
|
extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<storage_type<Owned> *..., storage_type<Get> *...> &cpools)
|
||||||
std::get<0>(pools)->basic_common_type::end() - *length,
|
: it{from},
|
||||||
std::make_tuple((std::get<storage_type<Owned> *>(pools)->end() - *length)...),
|
pools{cpools} {}
|
||||||
std::make_tuple(std::get<storage_type<Get> *>(pools)...)
|
|
||||||
} : iterator{{}, std::make_tuple(decltype(std::get<storage_type<Owned> *>(pools)->end()){}...), std::make_tuple(std::get<storage_type<Get> *>(pools)...)};
|
extended_group_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
|
return ++it, *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
extended_group_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
return length ? iterator{
|
extended_group_iterator orig = *this;
|
||||||
std::get<0>(pools)->basic_common_type::end(),
|
return ++(*this), orig;
|
||||||
std::make_tuple((std::get<storage_type<Owned> *>(pools)->end())...),
|
|
||||||
std::make_tuple(std::get<storage_type<Get> *>(pools)...)
|
|
||||||
} : iterator{{}, std::make_tuple(decltype(std::get<storage_type<Owned> *>(pools)->end()){}...), std::make_tuple(std::get<storage_type<Get> *>(pools)...)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
return length ? reverse_iterator{
|
return std::tuple_cat(
|
||||||
std::get<0>(pools)->basic_common_type::rbegin(),
|
std::make_tuple(*it),
|
||||||
std::make_tuple((std::get<storage_type<Owned> *>(pools)->rbegin())...),
|
index_to_element<Owned>(*std::get<storage_type<Owned> *>(pools))...,
|
||||||
std::make_tuple(std::get<storage_type<Get> *>(pools)...)
|
std::get<storage_type<Get> *>(pools)->get_as_tuple(*it)...);
|
||||||
} : reverse_iterator{{}, std::make_tuple(decltype(std::get<storage_type<Owned> *>(pools)->rbegin()){}...), std::make_tuple(std::get<storage_type<Get> *>(pools)...)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
return length ? reverse_iterator{
|
return operator*();
|
||||||
std::get<0>(pools)->basic_common_type::rbegin() + *length,
|
}
|
||||||
std::make_tuple((std::get<storage_type<Owned> *>(pools)->rbegin() + *length)...),
|
|
||||||
std::make_tuple(std::get<storage_type<Get> *>(pools)...)
|
[[nodiscard]] bool operator==(const extended_group_iterator &other) const ENTT_NOEXCEPT {
|
||||||
} : reverse_iterator{{}, std::make_tuple(decltype(std::get<storage_type<Owned> *>(pools)->rbegin()){}...), std::make_tuple(std::get<storage_type<Get> *>(pools)...)};
|
return other.it == it;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator!=(const extended_group_iterator &other) const ENTT_NOEXCEPT {
|
||||||
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::tuple<storage_type<Owned> *..., storage_type<Get> *...> pools;
|
typename basic_common_type::iterator it;
|
||||||
const std::size_t * const length;
|
std::tuple<storage_type<Owned> *..., storage_type<Get> *...> pools;
|
||||||
};
|
};
|
||||||
|
|
||||||
basic_group(const std::size_t &extent, storage_type<Owned> &... opool, storage_type<Get> &... gpool) ENTT_NOEXCEPT
|
basic_group(const std::size_t &extent, storage_type<Owned> &...opool, storage_type<Get> &...gpool) ENTT_NOEXCEPT
|
||||||
: pools{&opool..., &gpool...},
|
: pools{&opool..., &gpool...},
|
||||||
length{&extent}
|
length{&extent} {}
|
||||||
{}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief Underlying entity identifier. */
|
/*! @brief Underlying entity identifier. */
|
||||||
using entity_type = Entity;
|
using entity_type = Entity;
|
||||||
/*! @brief Unsigned integer type. */
|
/*! @brief Unsigned integer type. */
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
|
/*! @brief Common type among all storage types. */
|
||||||
|
using base_type = basic_common_type;
|
||||||
/*! @brief Random access iterator type. */
|
/*! @brief Random access iterator type. */
|
||||||
using iterator = typename basic_common_type::iterator;
|
using iterator = typename base_type::iterator;
|
||||||
/*! @brief Reversed iterator type. */
|
/*! @brief Reversed iterator type. */
|
||||||
using reverse_iterator = typename basic_common_type::reverse_iterator;
|
using reverse_iterator = typename base_type::reverse_iterator;
|
||||||
/*! @brief Iterable group type. */
|
/*! @brief Iterable group type. */
|
||||||
using iterable_group = iterable;
|
using iterable = iterable_adaptor<extended_group_iterator>;
|
||||||
|
|
||||||
/*! @brief Default constructor to use to create empty, invalid groups. */
|
/*! @brief Default constructor to use to create empty, invalid groups. */
|
||||||
basic_group() ENTT_NOEXCEPT
|
basic_group() ENTT_NOEXCEPT
|
||||||
: length{}
|
: length{} {}
|
||||||
{}
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the storage for a given component type.
|
||||||
|
* @tparam Comp Type of component of which to return the storage.
|
||||||
|
* @return The storage for the given component type.
|
||||||
|
*/
|
||||||
|
template<typename Comp>
|
||||||
|
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
|
||||||
|
return *std::get<storage_type<Comp> *>(pools);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the storage for a given component type.
|
||||||
|
* @tparam Comp Index of component of which to return the storage.
|
||||||
|
* @return The storage for the given component type.
|
||||||
|
*/
|
||||||
|
template<std::size_t Comp>
|
||||||
|
[[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
|
||||||
|
return *std::get<Comp>(pools);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the number of entities that have the given components.
|
* @brief Returns the number of entities that have the given components.
|
||||||
@@ -678,34 +641,6 @@ public:
|
|||||||
return !*this || !*length;
|
return !*this || !*length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Direct access to the raw representation offered by the storage.
|
|
||||||
*
|
|
||||||
* @warning
|
|
||||||
* This function is only available for owned types.
|
|
||||||
*
|
|
||||||
* @tparam Component Type of component in which one is interested.
|
|
||||||
* @return A pointer to the array of components.
|
|
||||||
*/
|
|
||||||
template<typename Component>
|
|
||||||
[[nodiscard]] auto raw() const ENTT_NOEXCEPT {
|
|
||||||
static_assert((std::is_same_v<Component, Owned> || ...), "Non-owned type");
|
|
||||||
auto *cpool = std::get<storage_type<Component> *>(pools);
|
|
||||||
return cpool ? cpool->raw() : decltype(cpool->raw()){};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Direct access to the list of entities.
|
|
||||||
*
|
|
||||||
* The returned pointer is such that range `[data(), data() + size())` is
|
|
||||||
* always a valid range, even if the container is empty.
|
|
||||||
*
|
|
||||||
* @return A pointer to the array of entities.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] auto data() const ENTT_NOEXCEPT {
|
|
||||||
return *this ? std::get<0>(pools)->data() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an iterator to the first entity of the group.
|
* @brief Returns an iterator to the first entity of the group.
|
||||||
*
|
*
|
||||||
@@ -715,7 +650,7 @@ public:
|
|||||||
* @return An iterator to the first entity of the group.
|
* @return An iterator to the first entity of the group.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||||
return *this ? (std::get<0>(pools)->basic_common_type::end() - *length) : iterator{};
|
return *this ? (std::get<0>(pools)->base_type::end() - *length) : iterator{};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -729,7 +664,7 @@ public:
|
|||||||
* group.
|
* group.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
||||||
return *this ? std::get<0>(pools)->basic_common_type::end() : iterator{};
|
return *this ? std::get<0>(pools)->base_type::end() : iterator{};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -741,7 +676,7 @@ public:
|
|||||||
* @return An iterator to the first entity of the reversed group.
|
* @return An iterator to the first entity of the reversed group.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
|
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
|
||||||
return *this ? std::get<0>(pools)->basic_common_type::rbegin() : reverse_iterator{};
|
return *this ? std::get<0>(pools)->base_type::rbegin() : reverse_iterator{};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -756,7 +691,7 @@ public:
|
|||||||
* reversed group.
|
* reversed group.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
|
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
|
||||||
return *this ? (std::get<0>(pools)->basic_common_type::rbegin() + *length) : reverse_iterator{};
|
return *this ? (std::get<0>(pools)->base_type::rbegin() + *length) : reverse_iterator{};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -764,7 +699,7 @@ public:
|
|||||||
* @return The first entity of the group if one exists, the null entity
|
* @return The first entity of the group if one exists, the null entity
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] entity_type front() const {
|
[[nodiscard]] entity_type front() const ENTT_NOEXCEPT {
|
||||||
const auto it = begin();
|
const auto it = begin();
|
||||||
return it != end() ? *it : null;
|
return it != end() ? *it : null;
|
||||||
}
|
}
|
||||||
@@ -774,18 +709,18 @@ public:
|
|||||||
* @return The last entity of the group if one exists, the null entity
|
* @return The last entity of the group if one exists, the null entity
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] entity_type back() const {
|
[[nodiscard]] entity_type back() const ENTT_NOEXCEPT {
|
||||||
const auto it = rbegin();
|
const auto it = rbegin();
|
||||||
return it != rend() ? *it : null;
|
return it != rend() ? *it : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finds an entity.
|
* @brief Finds an entity.
|
||||||
* @param entt A valid entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return An iterator to the given entity if it's found, past the end
|
* @return An iterator to the given entity if it's found, past the end
|
||||||
* iterator otherwise.
|
* iterator otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator find(const entity_type entt) const {
|
[[nodiscard]] iterator find(const entity_type entt) const ENTT_NOEXCEPT {
|
||||||
const auto it = *this ? std::get<0>(pools)->find(entt) : iterator{};
|
const auto it = *this ? std::get<0>(pools)->find(entt) : iterator{};
|
||||||
return it != end() && it >= begin() && *it == entt ? it : end();
|
return it != end() && it >= begin() && *it == entt ? it : end();
|
||||||
}
|
}
|
||||||
@@ -809,10 +744,10 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if a group contains an entity.
|
* @brief Checks if a group contains an entity.
|
||||||
* @param entt A valid entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return True if the group contains the given entity, false otherwise.
|
* @return True if the group contains the given entity, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
[[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
|
||||||
return *this && std::get<0>(pools)->contains(entt) && (std::get<0>(pools)->index(entt) < (*length));
|
return *this && std::get<0>(pools)->contains(entt) && (std::get<0>(pools)->index(entt) < (*length));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -827,20 +762,20 @@ public:
|
|||||||
* error. Attempting to use an entity that doesn't belong to the group
|
* error. Attempting to use an entity that doesn't belong to the group
|
||||||
* results in undefined behavior.
|
* results in undefined behavior.
|
||||||
*
|
*
|
||||||
* @tparam Component Types of components to get.
|
* @tparam Comp Types of components to get.
|
||||||
* @param entt A valid entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return The components assigned to the entity.
|
* @return The components assigned to the entity.
|
||||||
*/
|
*/
|
||||||
template<typename... Component>
|
template<typename... Comp>
|
||||||
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
|
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
|
||||||
ENTT_ASSERT(contains(entt), "Group does not contain entity");
|
ENTT_ASSERT(contains(entt), "Group does not contain entity");
|
||||||
|
|
||||||
if constexpr(sizeof...(Component) == 0) {
|
if constexpr(sizeof...(Comp) == 0) {
|
||||||
return std::tuple_cat(get_as_tuple(*std::get<storage_type<Owned> *>(pools), entt)..., get_as_tuple(*std::get<storage_type<Get> *>(pools), entt)...);
|
return std::tuple_cat(std::get<storage_type<Owned> *>(pools)->get_as_tuple(entt)..., std::get<storage_type<Get> *>(pools)->get_as_tuple(entt)...);
|
||||||
} else if constexpr(sizeof...(Component) == 1) {
|
} else if constexpr(sizeof...(Comp) == 1) {
|
||||||
return (std::get<storage_type<Component> *>(pools)->get(entt), ...);
|
return (std::get<storage_type<Comp> *>(pools)->get(entt), ...);
|
||||||
} else {
|
} else {
|
||||||
return std::tuple_cat(get_as_tuple(*std::get<storage_type<Component> *>(pools), entt)...);
|
return std::tuple_cat(std::get<storage_type<Comp> *>(pools)->get_as_tuple(entt)...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,13 +807,13 @@ public:
|
|||||||
if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_group>().get({})))>) {
|
if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_group>().get({})))>) {
|
||||||
std::apply(func, args);
|
std::apply(func, args);
|
||||||
} else {
|
} else {
|
||||||
std::apply([&func](auto, auto &&... less) { func(std::forward<decltype(less)>(less)...); }, args);
|
std::apply([&func](auto, auto &&...less) { func(std::forward<decltype(less)>(less)...); }, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an iterable object to use to _visit_ the group.
|
* @brief Returns an iterable object to use to _visit_ a group.
|
||||||
*
|
*
|
||||||
* The iterable object returns tuples that contain the current entity and a
|
* The iterable object returns tuples that contain the current entity and a
|
||||||
* set of references to its non-empty components. The _constness_ of the
|
* set of references to its non-empty components. The _constness_ of the
|
||||||
@@ -890,8 +825,9 @@ public:
|
|||||||
*
|
*
|
||||||
* @return An iterable object to use to _visit_ the group.
|
* @return An iterable object to use to _visit_ the group.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterable_group each() const ENTT_NOEXCEPT {
|
[[nodiscard]] iterable each() const ENTT_NOEXCEPT {
|
||||||
return iterable_group{pools, length};
|
iterator last = length ? std::get<0>(pools)->basic_common_type::end() : iterator{};
|
||||||
|
return {extended_group_iterator{last - *length, pools}, extended_group_iterator{last, pools}};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -916,14 +852,14 @@ public:
|
|||||||
* Moreover, the comparison function object shall induce a
|
* Moreover, the comparison function object shall induce a
|
||||||
* _strict weak ordering_ on the values.
|
* _strict weak ordering_ on the values.
|
||||||
*
|
*
|
||||||
* The sort function oject must offer a member function template
|
* The sort function object must offer a member function template
|
||||||
* `operator()` that accepts three arguments:
|
* `operator()` that accepts three arguments:
|
||||||
*
|
*
|
||||||
* * An iterator to the first element of the range to sort.
|
* * An iterator to the first element of the range to sort.
|
||||||
* * An iterator past the last element of the range to sort.
|
* * An iterator past the last element of the range to sort.
|
||||||
* * A comparison function to use to compare the elements.
|
* * A comparison function to use to compare the elements.
|
||||||
*
|
*
|
||||||
* @tparam Component Optional types of components to compare.
|
* @tparam Comp Optional types of components to compare.
|
||||||
* @tparam Compare Type of comparison function object.
|
* @tparam Compare Type of comparison function object.
|
||||||
* @tparam Sort Type of sort function object.
|
* @tparam Sort Type of sort function object.
|
||||||
* @tparam Args Types of arguments to forward to the sort function object.
|
* @tparam Args Types of arguments to forward to the sort function object.
|
||||||
@@ -931,39 +867,39 @@ public:
|
|||||||
* @param algo A valid sort function object.
|
* @param algo A valid sort function object.
|
||||||
* @param args Arguments to forward to the sort function object, if any.
|
* @param args Arguments to forward to the sort function object, if any.
|
||||||
*/
|
*/
|
||||||
template<typename... Component, typename Compare, typename Sort = std_sort, typename... Args>
|
template<typename... Comp, typename Compare, typename Sort = std_sort, typename... Args>
|
||||||
void sort(Compare compare, Sort algo = Sort{}, Args &&... args) const {
|
void sort(Compare compare, Sort algo = Sort{}, Args &&...args) const {
|
||||||
auto *cpool = std::get<0>(pools);
|
auto *cpool = std::get<0>(pools);
|
||||||
|
|
||||||
if constexpr(sizeof...(Component) == 0) {
|
if constexpr(sizeof...(Comp) == 0) {
|
||||||
static_assert(std::is_invocable_v<Compare, const entity_type, const entity_type>, "Invalid comparison function");
|
static_assert(std::is_invocable_v<Compare, const entity_type, const entity_type>, "Invalid comparison function");
|
||||||
cpool->sort_n(*length, std::move(compare), std::move(algo), std::forward<Args>(args)...);
|
cpool->sort_n(*length, std::move(compare), std::move(algo), std::forward<Args>(args)...);
|
||||||
} else if constexpr(sizeof...(Component) == 1) {
|
|
||||||
cpool->sort_n(*length, [this, compare = std::move(compare)](const entity_type lhs, const entity_type rhs) {
|
|
||||||
return compare((std::get<storage_type<Component> *>(pools)->get(lhs), ...), (std::get<storage_type<Component> *>(pools)->get(rhs), ...));
|
|
||||||
}, std::move(algo), std::forward<Args>(args)...);
|
|
||||||
} else {
|
} else {
|
||||||
cpool->sort_n(*length, [this, compare = std::move(compare)](const entity_type lhs, const entity_type rhs) {
|
auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) {
|
||||||
return compare(std::forward_as_tuple(std::get<storage_type<Component> *>(pools)->get(lhs)...), std::forward_as_tuple(std::get<storage_type<Component> *>(pools)->get(rhs)...));
|
if constexpr(sizeof...(Comp) == 1) {
|
||||||
}, std::move(algo), std::forward<Args>(args)...);
|
return compare((std::get<storage_type<Comp> *>(pools)->get(lhs), ...), (std::get<storage_type<Comp> *>(pools)->get(rhs), ...));
|
||||||
|
} else {
|
||||||
|
return compare(std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(lhs)...), std::forward_as_tuple(std::get<storage_type<Comp> *>(pools)->get(rhs)...));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
cpool->sort_n(*length, std::move(comp), std::move(algo), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
[this](auto *head, auto *... other) {
|
[this](auto *head, auto *...other) {
|
||||||
for(auto next = *length; next; --next) {
|
for(auto next = *length; next; --next) {
|
||||||
const auto pos = next - 1;
|
const auto pos = next - 1;
|
||||||
[[maybe_unused]] const auto entt = head->data()[pos];
|
[[maybe_unused]] const auto entt = head->data()[pos];
|
||||||
(other->swap(other->data()[pos], entt), ...);
|
(other->swap_elements(other->data()[pos], entt), ...);
|
||||||
}
|
}
|
||||||
}(std::get<storage_type<Owned> *>(pools)...);
|
}(std::get<storage_type<Owned> *>(pools)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::tuple<storage_type<Owned> *..., storage_type<Get> *...> pools;
|
const std::tuple<storage_type<Owned> *..., storage_type<Get> *...> pools;
|
||||||
const size_type * const length;
|
const size_type *const length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef ENTT_ENTITY_HANDLE_HPP
|
#ifndef ENTT_ENTITY_HANDLE_HPP
|
||||||
#define ENTT_ENTITY_HANDLE_HPP
|
#define ENTT_ENTITY_HANDLE_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -10,10 +9,8 @@
|
|||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
#include "registry.hpp"
|
#include "registry.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Non-owning handle to an entity.
|
* @brief Non-owning handle to an entity.
|
||||||
*
|
*
|
||||||
@@ -35,29 +32,17 @@ struct basic_handle {
|
|||||||
|
|
||||||
/*! @brief Constructs an invalid handle. */
|
/*! @brief Constructs an invalid handle. */
|
||||||
basic_handle() ENTT_NOEXCEPT
|
basic_handle() ENTT_NOEXCEPT
|
||||||
: reg{}, entt{null}
|
: reg{},
|
||||||
{}
|
entt{null} {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a handle from a given registry and entity.
|
* @brief Constructs a handle from a given registry and entity.
|
||||||
* @param ref An instance of the registry class.
|
* @param ref An instance of the registry class.
|
||||||
* @param value An entity identifier.
|
* @param value A valid identifier.
|
||||||
*/
|
*/
|
||||||
basic_handle(registry_type &ref, entity_type value) ENTT_NOEXCEPT
|
basic_handle(registry_type &ref, entity_type value) ENTT_NOEXCEPT
|
||||||
: reg{&ref}, entt{value}
|
: reg{&ref},
|
||||||
{}
|
entt{value} {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Compares two handles.
|
|
||||||
* @tparam Args Template parameters of the handle with which to compare.
|
|
||||||
* @param other Handle with which to compare.
|
|
||||||
* @return True if both handles refer to the same registry and the same
|
|
||||||
* entity, false otherwise.
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
[[nodiscard]] bool operator==(const basic_handle<Args...> &other) const ENTT_NOEXCEPT {
|
|
||||||
return reg == other.registry() && entt == other.entity();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a const handle from a non-const one.
|
* @brief Constructs a const handle from a non-const one.
|
||||||
@@ -68,18 +53,15 @@ struct basic_handle {
|
|||||||
*/
|
*/
|
||||||
template<typename Other, typename... Args>
|
template<typename Other, typename... Args>
|
||||||
operator basic_handle<Other, Args...>() const ENTT_NOEXCEPT {
|
operator basic_handle<Other, Args...>() const ENTT_NOEXCEPT {
|
||||||
static_assert(
|
static_assert(std::is_same_v<Other, Entity> || std::is_same_v<std::remove_const_t<Other>, Entity>, "Invalid conversion between different handles");
|
||||||
(std::is_same_v<Other, Entity> || std::is_same_v<std::remove_const_t<Other>, Entity>)
|
static_assert((sizeof...(Type) == 0 || ((sizeof...(Args) != 0 && sizeof...(Args) <= sizeof...(Type)) && ... && (type_list_contains_v<type_list<Type...>, Args>))), "Invalid conversion between different handles");
|
||||||
&& (sizeof...(Type) == 0 || ((sizeof...(Args) != 0 && sizeof...(Args) <= sizeof...(Type)) && ... && (type_list_contains_v<type_list<Type...>, Args>))),
|
|
||||||
"Invalid conversion between different handles"
|
|
||||||
);
|
|
||||||
|
|
||||||
return reg ? basic_handle<Other, Args...>{*reg, entt} : basic_handle<Other, Args...>{};
|
return reg ? basic_handle<Other, Args...>{*reg, entt} : basic_handle<Other, Args...>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts a handle to its underlying entity.
|
* @brief Converts a handle to its underlying entity.
|
||||||
* @return An entity identifier.
|
* @return The contained identifier.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] operator entity_type() const ENTT_NOEXCEPT {
|
[[nodiscard]] operator entity_type() const ENTT_NOEXCEPT {
|
||||||
return entity();
|
return entity();
|
||||||
@@ -105,7 +87,7 @@ struct basic_handle {
|
|||||||
* @brief Returns a pointer to the underlying registry, if any.
|
* @brief Returns a pointer to the underlying registry, if any.
|
||||||
* @return A pointer to the underlying registry, if any.
|
* @return A pointer to the underlying registry, if any.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] registry_type * registry() const ENTT_NOEXCEPT {
|
[[nodiscard]] registry_type *registry() const ENTT_NOEXCEPT {
|
||||||
return reg;
|
return reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +125,7 @@ struct basic_handle {
|
|||||||
* @return A reference to the newly created component.
|
* @return A reference to the newly created component.
|
||||||
*/
|
*/
|
||||||
template<typename Component, typename... Args>
|
template<typename Component, typename... Args>
|
||||||
decltype(auto) emplace(Args &&... args) const {
|
decltype(auto) emplace(Args &&...args) const {
|
||||||
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
||||||
return reg->template emplace<Component>(entt, std::forward<Args>(args)...);
|
return reg->template emplace<Component>(entt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
@@ -157,7 +139,7 @@ struct basic_handle {
|
|||||||
* @return A reference to the newly created component.
|
* @return A reference to the newly created component.
|
||||||
*/
|
*/
|
||||||
template<typename Component, typename... Args>
|
template<typename Component, typename... Args>
|
||||||
decltype(auto) emplace_or_replace(Args &&... args) const {
|
decltype(auto) emplace_or_replace(Args &&...args) const {
|
||||||
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
||||||
return reg->template emplace_or_replace<Component>(entt, std::forward<Args>(args)...);
|
return reg->template emplace_or_replace<Component>(entt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
@@ -171,7 +153,7 @@ struct basic_handle {
|
|||||||
* @return A reference to the patched component.
|
* @return A reference to the patched component.
|
||||||
*/
|
*/
|
||||||
template<typename Component, typename... Func>
|
template<typename Component, typename... Func>
|
||||||
decltype(auto) patch(Func &&... func) const {
|
decltype(auto) patch(Func &&...func) const {
|
||||||
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
||||||
return reg->template patch<Component>(entt, std::forward<Func>(func)...);
|
return reg->template patch<Component>(entt, std::forward<Func>(func)...);
|
||||||
}
|
}
|
||||||
@@ -185,7 +167,7 @@ struct basic_handle {
|
|||||||
* @return A reference to the component being replaced.
|
* @return A reference to the component being replaced.
|
||||||
*/
|
*/
|
||||||
template<typename Component, typename... Args>
|
template<typename Component, typename... Args>
|
||||||
decltype(auto) replace(Args &&... args) const {
|
decltype(auto) replace(Args &&...args) const {
|
||||||
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
||||||
return reg->template replace<Component>(entt, std::forward<Args>(args)...);
|
return reg->template replace<Component>(entt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
@@ -213,23 +195,6 @@ struct basic_handle {
|
|||||||
reg->template erase<Component...>(entt);
|
reg->template erase<Component...>(entt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc remove */
|
|
||||||
template<typename... Component>
|
|
||||||
[[deprecated("Use ::remove instead")]]
|
|
||||||
size_type remove_if_exists() const {
|
|
||||||
return remove<Component...>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Removes all the components from a handle and makes it orphaned.
|
|
||||||
* @sa basic_registry::remove_all
|
|
||||||
*/
|
|
||||||
[[deprecated("No longer supported")]]
|
|
||||||
void remove_all() const {
|
|
||||||
static_assert(sizeof...(Type) == 0, "Invalid operation");
|
|
||||||
reg->remove_all(entt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if a handle has all the given components.
|
* @brief Checks if a handle has all the given components.
|
||||||
* @sa basic_registry::all_of
|
* @sa basic_registry::all_of
|
||||||
@@ -274,7 +239,7 @@ struct basic_handle {
|
|||||||
* @return Reference to the component owned by the handle.
|
* @return Reference to the component owned by the handle.
|
||||||
*/
|
*/
|
||||||
template<typename Component, typename... Args>
|
template<typename Component, typename... Args>
|
||||||
[[nodiscard]] decltype(auto) get_or_emplace(Args &&... args) const {
|
[[nodiscard]] decltype(auto) get_or_emplace(Args &&...args) const {
|
||||||
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
static_assert(((sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>), "Invalid type");
|
||||||
return reg->template get_or_emplace<Component>(entt, std::forward<Args>(args)...);
|
return reg->template get_or_emplace<Component>(entt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
@@ -300,14 +265,27 @@ struct basic_handle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Visits a handle and returns the types for its components.
|
* @brief Visits a handle and returns the pools for its components.
|
||||||
* @sa basic_registry::visit
|
*
|
||||||
|
* The signature of the function should be equivalent to the following:
|
||||||
|
*
|
||||||
|
* @code{.cpp}
|
||||||
|
* void(id_type, const basic_sparse_set<entity_type> &);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* Returned pools are those that contain the entity associated with the
|
||||||
|
* handle.
|
||||||
|
*
|
||||||
* @tparam Func Type of the function object to invoke.
|
* @tparam Func Type of the function object to invoke.
|
||||||
* @param func A valid function object.
|
* @param func A valid function object.
|
||||||
*/
|
*/
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
void visit(Func &&func) const {
|
void visit(Func &&func) const {
|
||||||
reg->visit(entt, std::forward<Func>(func));
|
for(auto [id, storage]: reg->storage()) {
|
||||||
|
if(storage.contains(entt)) {
|
||||||
|
func(id, storage);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -315,41 +293,48 @@ private:
|
|||||||
entity_type entt;
|
entity_type entt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compares two handles.
|
||||||
|
* @tparam Args Scope of the first handle.
|
||||||
|
* @tparam Other Scope of the second handle.
|
||||||
|
* @param lhs A valid handle.
|
||||||
|
* @param rhs A valid handle.
|
||||||
|
* @return True if both handles refer to the same registry and the same
|
||||||
|
* entity, false otherwise.
|
||||||
|
*/
|
||||||
|
template<typename... Args, typename... Other>
|
||||||
|
[[nodiscard]] bool operator==(const basic_handle<Args...> &lhs, const basic_handle<Other...> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.registry() == rhs.registry() && lhs.entity() == rhs.entity();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares two handles.
|
* @brief Compares two handles.
|
||||||
* @tparam Type A valid entity type (see entt_traits for more details).
|
* @tparam Args Scope of the first handle.
|
||||||
* @tparam Other A valid entity type (see entt_traits for more details).
|
* @tparam Other Scope of the second handle.
|
||||||
* @param lhs A valid handle.
|
* @param lhs A valid handle.
|
||||||
* @param rhs A valid handle.
|
* @param rhs A valid handle.
|
||||||
* @return False if both handles refer to the same registry and the same
|
* @return False if both handles refer to the same registry and the same
|
||||||
* entity, true otherwise.
|
* entity, true otherwise.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename Other>
|
template<typename... Args, typename... Other>
|
||||||
bool operator!=(const basic_handle<Type> &lhs, const basic_handle<Other> &rhs) ENTT_NOEXCEPT {
|
[[nodiscard]] bool operator!=(const basic_handle<Args...> &lhs, const basic_handle<Other...> &rhs) ENTT_NOEXCEPT {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deduction guide.
|
||||||
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
|
*/
|
||||||
|
template<typename Entity>
|
||||||
|
basic_handle(basic_registry<Entity> &, Entity) -> basic_handle<Entity>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deduction guide.
|
* @brief Deduction guide.
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
basic_handle(basic_registry<Entity> &, Entity)
|
basic_handle(const basic_registry<Entity> &, Entity) -> basic_handle<const Entity>;
|
||||||
-> basic_handle<Entity>;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Deduction guide.
|
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
|
||||||
*/
|
|
||||||
template<typename Entity>
|
|
||||||
basic_handle(const basic_registry<Entity> &, Entity)
|
|
||||||
-> basic_handle<const Entity>;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
#ifndef ENTT_ENTITY_HELPER_HPP
|
#ifndef ENTT_ENTITY_HELPER_HPP
|
||||||
#define ENTT_ENTITY_HELPER_HPP
|
#define ENTT_ENTITY_HELPER_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "../core/fwd.hpp"
|
#include "../core/fwd.hpp"
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
#include "../signal/delegate.hpp"
|
#include "../signal/delegate.hpp"
|
||||||
#include "registry.hpp"
|
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
#include "registry.hpp"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts a registry to a view.
|
* @brief Converts a registry to a view.
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
@@ -38,7 +35,7 @@ struct as_view {
|
|||||||
* @return A newly created view.
|
* @return A newly created view.
|
||||||
*/
|
*/
|
||||||
template<typename Exclude, typename... Component>
|
template<typename Exclude, typename... Component>
|
||||||
operator basic_view<entity_type, Exclude, Component...>() const {
|
operator basic_view<entity_type, get_t<Component...>, Exclude>() const {
|
||||||
return reg.template view<Component...>(Exclude{});
|
return reg.template view<Component...>(Exclude{});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +43,6 @@ private:
|
|||||||
registry_type ®
|
registry_type ®
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deduction guide.
|
* @brief Deduction guide.
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
@@ -54,7 +50,6 @@ private:
|
|||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
as_view(basic_registry<Entity> &) -> as_view<Entity>;
|
as_view(basic_registry<Entity> &) -> as_view<Entity>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deduction guide.
|
* @brief Deduction guide.
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
@@ -62,7 +57,6 @@ as_view(basic_registry<Entity> &) -> as_view<Entity>;
|
|||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
as_view(const basic_registry<Entity> &) -> as_view<const Entity>;
|
as_view(const basic_registry<Entity> &) -> as_view<const Entity>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts a registry to a group.
|
* @brief Converts a registry to a group.
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
@@ -82,13 +76,13 @@ struct as_group {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Conversion function from a registry to a group.
|
* @brief Conversion function from a registry to a group.
|
||||||
* @tparam Exclude Types of components used to filter the group.
|
|
||||||
* @tparam Get Types of components observed by the group.
|
* @tparam Get Types of components observed by the group.
|
||||||
|
* @tparam Exclude Types of components used to filter the group.
|
||||||
* @tparam Owned Types of components owned by the group.
|
* @tparam Owned Types of components owned by the group.
|
||||||
* @return A newly created group.
|
* @return A newly created group.
|
||||||
*/
|
*/
|
||||||
template<typename Exclude, typename Get, typename... Owned>
|
template<typename Get, typename Exclude, typename... Owned>
|
||||||
operator basic_group<entity_type, Exclude, Get, Owned...>() const {
|
operator basic_group<entity_type, owned_t<Owned...>, Get, Exclude>() const {
|
||||||
if constexpr(std::is_const_v<registry_type>) {
|
if constexpr(std::is_const_v<registry_type>) {
|
||||||
return reg.template group_if_exists<Owned...>(Get{}, Exclude{});
|
return reg.template group_if_exists<Owned...>(Get{}, Exclude{});
|
||||||
} else {
|
} else {
|
||||||
@@ -100,7 +94,6 @@ private:
|
|||||||
registry_type ®
|
registry_type ®
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deduction guide.
|
* @brief Deduction guide.
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
@@ -108,7 +101,6 @@ private:
|
|||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
as_group(basic_registry<Entity> &) -> as_group<Entity>;
|
as_group(basic_registry<Entity> &) -> as_group<Entity>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deduction guide.
|
* @brief Deduction guide.
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
@@ -116,8 +108,6 @@ as_group(basic_registry<Entity> &) -> as_group<Entity>;
|
|||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
as_group(const basic_registry<Entity> &) -> as_group<const Entity>;
|
as_group(const basic_registry<Entity> &) -> as_group<const Entity>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper to create a listener that directly invokes a member function.
|
* @brief Helper to create a listener that directly invokes a member function.
|
||||||
* @tparam Member Member function to invoke on a component of the given type.
|
* @tparam Member Member function to invoke on a component of the given type.
|
||||||
@@ -133,7 +123,6 @@ void invoke(basic_registry<Entity> ®, const Entity entt) {
|
|||||||
func(reg, entt);
|
func(reg, entt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the entity associated with a given component.
|
* @brief Returns the entity associated with a given component.
|
||||||
*
|
*
|
||||||
@@ -149,20 +138,19 @@ void invoke(basic_registry<Entity> ®, const Entity entt) {
|
|||||||
*/
|
*/
|
||||||
template<typename Entity, typename Component>
|
template<typename Entity, typename Component>
|
||||||
Entity to_entity(const basic_registry<Entity> ®, const Component &instance) {
|
Entity to_entity(const basic_registry<Entity> ®, const Component &instance) {
|
||||||
const auto view = reg.template view<const Component>();
|
const auto &storage = reg.template storage<Component>();
|
||||||
|
const typename basic_registry<Entity>::base_type &base = storage;
|
||||||
const auto *addr = std::addressof(instance);
|
const auto *addr = std::addressof(instance);
|
||||||
|
|
||||||
for(auto it = view.rbegin(), last = view.rend(); it < last; it += ENTT_PACKED_PAGE) {
|
for(auto it = base.rbegin(), last = base.rend(); it < last; it += ENTT_PACKED_PAGE) {
|
||||||
if(const auto dist = (addr - std::addressof(view.template get<const Component>(*it))); dist >= 0 && dist < ENTT_PACKED_PAGE) {
|
if(const auto dist = (addr - std::addressof(storage.get(*it))); dist >= 0 && dist < ENTT_PACKED_PAGE) {
|
||||||
return *(it + dist);
|
return *(it + dist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entt::null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,30 +1,26 @@
|
|||||||
#ifndef ENTT_ENTITY_OBSERVER_HPP
|
#ifndef ENTT_ENTITY_OBSERVER_HPP
|
||||||
#define ENTT_ENTITY_OBSERVER_HPP
|
#define ENTT_ENTITY_OBSERVER_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <utility>
|
#include <limits>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
#include "../signal/delegate.hpp"
|
#include "../signal/delegate.hpp"
|
||||||
|
#include "entity.hpp"
|
||||||
|
#include "fwd.hpp"
|
||||||
#include "registry.hpp"
|
#include "registry.hpp"
|
||||||
#include "storage.hpp"
|
#include "storage.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
#include "entity.hpp"
|
|
||||||
#include "fwd.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Grouping matcher. */
|
/*! @brief Grouping matcher. */
|
||||||
template<typename...>
|
template<typename...>
|
||||||
struct matcher {};
|
struct matcher {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Collector.
|
* @brief Collector.
|
||||||
*
|
*
|
||||||
@@ -34,7 +30,6 @@ struct matcher {};
|
|||||||
template<typename...>
|
template<typename...>
|
||||||
struct basic_collector;
|
struct basic_collector;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Collector.
|
* @brief Collector.
|
||||||
*
|
*
|
||||||
@@ -114,11 +109,9 @@ struct basic_collector<matcher<type_list<Reject...>, type_list<Require...>, Rule
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Variable template used to ease the definition of collectors. */
|
/*! @brief Variable template used to ease the definition of collectors. */
|
||||||
inline constexpr basic_collector<> collector{};
|
inline constexpr basic_collector<> collector{};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Observer.
|
* @brief Observer.
|
||||||
*
|
*
|
||||||
@@ -215,14 +208,15 @@ class basic_observer {
|
|||||||
struct matcher_handler<matcher<type_list<Reject...>, type_list<Require...>, type_list<NoneOf...>, AllOf...>> {
|
struct matcher_handler<matcher<type_list<Reject...>, type_list<Require...>, type_list<NoneOf...>, AllOf...>> {
|
||||||
template<std::size_t Index, typename... Ignore>
|
template<std::size_t Index, typename... Ignore>
|
||||||
static void maybe_valid_if(basic_observer &obs, basic_registry<Entity> ®, const Entity entt) {
|
static void maybe_valid_if(basic_observer &obs, basic_registry<Entity> ®, const Entity entt) {
|
||||||
if([®, entt]() {
|
auto condition = [®, entt]() {
|
||||||
if constexpr(sizeof...(Ignore) == 0) {
|
if constexpr(sizeof...(Ignore) == 0) {
|
||||||
return reg.template all_of<AllOf..., Require...>(entt) && !reg.template any_of<NoneOf..., Reject...>(entt);
|
return reg.template all_of<AllOf..., Require...>(entt) && !reg.template any_of<NoneOf..., Reject...>(entt);
|
||||||
} else {
|
} else {
|
||||||
return reg.template all_of<AllOf..., Require...>(entt) && ((std::is_same_v<Ignore..., NoneOf> || !reg.template any_of<NoneOf>(entt)) && ...) && !reg.template any_of<Reject...>(entt);
|
return reg.template all_of<AllOf..., Require...>(entt) && ((std::is_same_v<Ignore..., NoneOf> || !reg.template any_of<NoneOf>(entt)) && ...) && !reg.template any_of<Reject...>(entt);
|
||||||
}
|
}
|
||||||
}())
|
};
|
||||||
{
|
|
||||||
|
if(condition()) {
|
||||||
if(!obs.storage.contains(entt)) {
|
if(!obs.storage.contains(entt)) {
|
||||||
obs.storage.emplace(entt);
|
obs.storage.emplace(entt);
|
||||||
}
|
}
|
||||||
@@ -281,8 +275,7 @@ public:
|
|||||||
/*! @brief Default constructor. */
|
/*! @brief Default constructor. */
|
||||||
basic_observer()
|
basic_observer()
|
||||||
: release{},
|
: release{},
|
||||||
storage{}
|
storage{} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/*! @brief Default copy constructor, deleted on purpose. */
|
/*! @brief Default copy constructor, deleted on purpose. */
|
||||||
basic_observer(const basic_observer &) = delete;
|
basic_observer(const basic_observer &) = delete;
|
||||||
@@ -296,8 +289,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename... Matcher>
|
template<typename... Matcher>
|
||||||
basic_observer(basic_registry<entity_type> ®, basic_collector<Matcher...>)
|
basic_observer(basic_registry<entity_type> ®, basic_collector<Matcher...>)
|
||||||
: basic_observer{}
|
: basic_observer{} {
|
||||||
{
|
|
||||||
connect<Matcher...>(reg, std::index_sequence_for<Matcher...>{});
|
connect<Matcher...>(reg, std::index_sequence_for<Matcher...>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,13 +300,13 @@ public:
|
|||||||
* @brief Default copy assignment operator, deleted on purpose.
|
* @brief Default copy assignment operator, deleted on purpose.
|
||||||
* @return This observer.
|
* @return This observer.
|
||||||
*/
|
*/
|
||||||
basic_observer & operator=(const basic_observer &) = delete;
|
basic_observer &operator=(const basic_observer &) = delete;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default move assignment operator, deleted on purpose.
|
* @brief Default move assignment operator, deleted on purpose.
|
||||||
* @return This observer.
|
* @return This observer.
|
||||||
*/
|
*/
|
||||||
basic_observer & operator=(basic_observer &&) = delete;
|
basic_observer &operator=(basic_observer &&) = delete;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Connects an observer to a given registry.
|
* @brief Connects an observer to a given registry.
|
||||||
@@ -364,7 +356,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A pointer to the array of entities.
|
* @return A pointer to the array of entities.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
|
[[nodiscard]] const entity_type *data() const ENTT_NOEXCEPT {
|
||||||
return storage.data();
|
return storage.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,8 +431,6 @@ private:
|
|||||||
basic_storage<entity_type, payload_type> storage;
|
basic_storage<entity_type, payload_type> storage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,54 +1,47 @@
|
|||||||
#ifndef ENTT_ENTITY_ORGANIZER_HPP
|
#ifndef ENTT_ENTITY_ORGANIZER_HPP
|
||||||
#define ENTT_ENTITY_ORGANIZER_HPP
|
#define ENTT_ENTITY_ORGANIZER_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "../container/dense_map.hpp"
|
||||||
#include "../core/type_info.hpp"
|
#include "../core/type_info.hpp"
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
|
#include "../core/utility.hpp"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
#include "helper.hpp"
|
#include "helper.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @cond TURN_OFF_DOXYGEN
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
struct is_view: std::false_type {};
|
struct is_view: std::false_type {};
|
||||||
|
|
||||||
template<typename Entity, typename... Exclude, typename... Component>
|
template<typename Entity, typename... Component, typename... Exclude>
|
||||||
struct is_view<basic_view<Entity, exclude_t<Exclude...>, Component...>>: std::true_type {};
|
struct is_view<basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>>: std::true_type {};
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline constexpr bool is_view_v = is_view<Type>::value;
|
inline constexpr bool is_view_v = is_view<Type>::value;
|
||||||
|
|
||||||
|
|
||||||
template<typename Type, typename Override>
|
template<typename Type, typename Override>
|
||||||
struct unpack_type {
|
struct unpack_type {
|
||||||
using ro = std::conditional_t<
|
using ro = std::conditional_t<
|
||||||
type_list_contains_v<Override, std::add_const_t<Type>> || (std::is_const_v<Type> && !type_list_contains_v<Override, std::remove_const_t<Type>>),
|
type_list_contains_v<Override, std::add_const_t<Type>> || (std::is_const_v<Type> && !type_list_contains_v<Override, std::remove_const_t<Type>>),
|
||||||
type_list<std::remove_const_t<Type>>,
|
type_list<std::remove_const_t<Type>>,
|
||||||
type_list<>
|
type_list<>>;
|
||||||
>;
|
|
||||||
|
|
||||||
using rw = std::conditional_t<
|
using rw = std::conditional_t<
|
||||||
type_list_contains_v<Override, std::remove_const_t<Type>> || (!std::is_const_v<Type> && !type_list_contains_v<Override, std::add_const_t<Type>>),
|
type_list_contains_v<Override, std::remove_const_t<Type>> || (!std::is_const_v<Type> && !type_list_contains_v<Override, std::add_const_t<Type>>),
|
||||||
type_list<Type>,
|
type_list<Type>,
|
||||||
type_list<>
|
type_list<>>;
|
||||||
>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Entity, typename... Override>
|
template<typename Entity, typename... Override>
|
||||||
@@ -59,57 +52,47 @@ struct unpack_type<basic_registry<Entity>, type_list<Override...>> {
|
|||||||
|
|
||||||
template<typename Entity, typename... Override>
|
template<typename Entity, typename... Override>
|
||||||
struct unpack_type<const basic_registry<Entity>, type_list<Override...>>
|
struct unpack_type<const basic_registry<Entity>, type_list<Override...>>
|
||||||
: unpack_type<basic_registry<Entity>, type_list<Override...>>
|
: unpack_type<basic_registry<Entity>, type_list<Override...>> {};
|
||||||
{};
|
|
||||||
|
|
||||||
template<typename Entity, typename... Exclude, typename... Component, typename... Override>
|
template<typename Entity, typename... Component, typename... Exclude, typename... Override>
|
||||||
struct unpack_type<basic_view<Entity, exclude_t<Exclude...>, Component...>, type_list<Override...>> {
|
struct unpack_type<basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>, type_list<Override...>> {
|
||||||
using ro = type_list_cat_t<type_list<Exclude...>, typename unpack_type<Component, type_list<Override...>>::ro...>;
|
using ro = type_list_cat_t<type_list<Exclude...>, typename unpack_type<Component, type_list<Override...>>::ro...>;
|
||||||
using rw = type_list_cat_t<typename unpack_type<Component, type_list<Override...>>::rw...>;
|
using rw = type_list_cat_t<typename unpack_type<Component, type_list<Override...>>::rw...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Entity, typename... Exclude, typename... Component, typename... Override>
|
template<typename Entity, typename... Component, typename... Exclude, typename... Override>
|
||||||
struct unpack_type<const basic_view<Entity, exclude_t<Exclude...>, Component...>, type_list<Override...>>
|
struct unpack_type<const basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>, type_list<Override...>>
|
||||||
: unpack_type<basic_view<Entity, exclude_t<Exclude...>, Component...>, type_list<Override...>>
|
: unpack_type<basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>>, type_list<Override...>> {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename, typename>
|
template<typename, typename>
|
||||||
struct resource;
|
struct resource_traits;
|
||||||
|
|
||||||
template<typename... Args, typename... Req>
|
template<typename... Args, typename... Req>
|
||||||
struct resource<type_list<Args...>, type_list<Req...>> {
|
struct resource_traits<type_list<Args...>, type_list<Req...>> {
|
||||||
using args = type_list<std::remove_const_t<Args>...>;
|
using args = type_list<std::remove_const_t<Args>...>;
|
||||||
using ro = type_list_cat_t<typename unpack_type<Args, type_list<Req...>>::ro..., typename unpack_type<Req, type_list<>>::ro...>;
|
using ro = type_list_cat_t<typename unpack_type<Args, type_list<Req...>>::ro..., typename unpack_type<Req, type_list<>>::ro...>;
|
||||||
using rw = type_list_cat_t<typename unpack_type<Args, type_list<Req...>>::rw..., typename unpack_type<Req, type_list<>>::rw...>;
|
using rw = type_list_cat_t<typename unpack_type<Args, type_list<Req...>>::rw..., typename unpack_type<Req, type_list<>>::rw...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename... Req, typename Ret, typename... Args>
|
template<typename... Req, typename Ret, typename... Args>
|
||||||
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> free_function_to_resource(Ret(*)(Args...));
|
resource_traits<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> free_function_to_resource_traits(Ret (*)(Args...));
|
||||||
|
|
||||||
template<typename... Req, typename Ret, typename Type, typename... Args>
|
template<typename... Req, typename Ret, typename Type, typename... Args>
|
||||||
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource(Ret(*)(Type &, Args...));
|
resource_traits<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (*)(Type &, Args...));
|
||||||
|
|
||||||
template<typename... Req, typename Ret, typename Class, typename... Args>
|
template<typename... Req, typename Ret, typename Class, typename... Args>
|
||||||
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource(Ret(Class:: *)(Args...));
|
resource_traits<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (Class::*)(Args...));
|
||||||
|
|
||||||
template<typename... Req, typename Ret, typename Class, typename... Args>
|
template<typename... Req, typename Ret, typename Class, typename... Args>
|
||||||
resource<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource(Ret(Class:: *)(Args...) const);
|
resource_traits<type_list<std::remove_reference_t<Args>...>, type_list<Req...>> constrained_function_to_resource_traits(Ret (Class::*)(Args...) const);
|
||||||
|
|
||||||
template<typename... Req>
|
|
||||||
resource<type_list<>, type_list<Req...>> to_resource();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Utility class for creating a static task graph.
|
* @brief Utility class for creating a static task graph.
|
||||||
*
|
*
|
||||||
@@ -123,9 +106,9 @@ resource<type_list<>, type_list<Req...>> to_resource();
|
|||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
class basic_organizer final {
|
class basic_organizer final {
|
||||||
using callback_type = void(const void *, entt::basic_registry<Entity> &);
|
using callback_type = void(const void *, basic_registry<Entity> &);
|
||||||
using prepare_type = void(entt::basic_registry<Entity> &);
|
using prepare_type = void(basic_registry<Entity> &);
|
||||||
using dependency_type = std::size_t(const bool, type_info *, const std::size_t);
|
using dependency_type = std::size_t(const bool, const type_info **, const std::size_t);
|
||||||
|
|
||||||
struct vertex_data final {
|
struct vertex_data final {
|
||||||
std::size_t ro_count{};
|
std::size_t ro_count{};
|
||||||
@@ -135,7 +118,7 @@ class basic_organizer final {
|
|||||||
callback_type *callback{};
|
callback_type *callback{};
|
||||||
dependency_type *dependency;
|
dependency_type *dependency;
|
||||||
prepare_type *prepare{};
|
prepare_type *prepare{};
|
||||||
type_info info{};
|
const type_info *info{};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
@@ -145,7 +128,7 @@ class basic_organizer final {
|
|||||||
} else if constexpr(internal::is_view_v<Type>) {
|
} else if constexpr(internal::is_view_v<Type>) {
|
||||||
return as_view{reg};
|
return as_view{reg};
|
||||||
} else {
|
} else {
|
||||||
return reg.template ctx_or_set<std::remove_reference_t<Type>>();
|
return reg.ctx().template emplace<std::remove_reference_t<Type>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,11 +138,11 @@ class basic_organizer final {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Type>
|
template<typename... Type>
|
||||||
static std::size_t fill_dependencies(type_list<Type...>, [[maybe_unused]] type_info *buffer, [[maybe_unused]] const std::size_t count) {
|
static std::size_t fill_dependencies(type_list<Type...>, [[maybe_unused]] const type_info **buffer, [[maybe_unused]] const std::size_t count) {
|
||||||
if constexpr(sizeof...(Type) == 0u) {
|
if constexpr(sizeof...(Type) == 0u) {
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
type_info info[sizeof...(Type)]{type_id<Type>()...};
|
const type_info *info[sizeof...(Type)]{&type_id<Type>()...};
|
||||||
const auto length = (std::min)(count, sizeof...(Type));
|
const auto length = (std::min)(count, sizeof...(Type));
|
||||||
std::copy_n(info, length, buffer);
|
std::copy_n(info, length, buffer);
|
||||||
return length;
|
return length;
|
||||||
@@ -177,7 +160,7 @@ class basic_organizer final {
|
|||||||
const auto length = vertices.size();
|
const auto length = vertices.size();
|
||||||
std::vector<bool> edges(length * length, false);
|
std::vector<bool> edges(length * length, false);
|
||||||
|
|
||||||
// creates the ajacency matrix
|
// creates the adjacency matrix
|
||||||
for(const auto &deps: dependencies) {
|
for(const auto &deps: dependencies) {
|
||||||
const auto last = deps.second.cend();
|
const auto last = deps.second.cend();
|
||||||
auto it = deps.second.cbegin();
|
auto it = deps.second.cbegin();
|
||||||
@@ -262,8 +245,7 @@ public:
|
|||||||
vertex(const bool vtype, vertex_data data, std::vector<std::size_t> edges)
|
vertex(const bool vtype, vertex_data data, std::vector<std::size_t> edges)
|
||||||
: is_top_level{vtype},
|
: is_top_level{vtype},
|
||||||
node{std::move(data)},
|
node{std::move(data)},
|
||||||
reachable{std::move(edges)}
|
reachable{std::move(edges)} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fills a buffer with the type info objects for the writable
|
* @brief Fills a buffer with the type info objects for the writable
|
||||||
@@ -272,7 +254,7 @@ public:
|
|||||||
* @param length The length of the user-supplied buffer.
|
* @param length The length of the user-supplied buffer.
|
||||||
* @return The number of type info objects written to the buffer.
|
* @return The number of type info objects written to the buffer.
|
||||||
*/
|
*/
|
||||||
size_type ro_dependency(type_info *buffer, const std::size_t length) const ENTT_NOEXCEPT {
|
size_type ro_dependency(const type_info **buffer, const std::size_t length) const ENTT_NOEXCEPT {
|
||||||
return node.dependency(false, buffer, length);
|
return node.dependency(false, buffer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +265,7 @@ public:
|
|||||||
* @param length The length of the user-supplied buffer.
|
* @param length The length of the user-supplied buffer.
|
||||||
* @return The number of type info objects written to the buffer.
|
* @return The number of type info objects written to the buffer.
|
||||||
*/
|
*/
|
||||||
size_type rw_dependency(type_info *buffer, const std::size_t length) const ENTT_NOEXCEPT {
|
size_type rw_dependency(const type_info **buffer, const std::size_t length) const ENTT_NOEXCEPT {
|
||||||
return node.dependency(true, buffer, length);
|
return node.dependency(true, buffer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,15 +297,15 @@ public:
|
|||||||
* @brief Returns a type info object associated with a vertex.
|
* @brief Returns a type info object associated with a vertex.
|
||||||
* @return A properly initialized type info object.
|
* @return A properly initialized type info object.
|
||||||
*/
|
*/
|
||||||
type_info info() const ENTT_NOEXCEPT {
|
const type_info &info() const ENTT_NOEXCEPT {
|
||||||
return node.info;
|
return *node.info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a user defined name associated with a vertex, if any.
|
* @brief Returns a user defined name associated with a vertex, if any.
|
||||||
* @return The user defined name associated with the vertex, if any.
|
* @return The user defined name associated with the vertex, if any.
|
||||||
*/
|
*/
|
||||||
const char * name() const ENTT_NOEXCEPT {
|
const char *name() const ENTT_NOEXCEPT {
|
||||||
return node.name;
|
return node.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +313,7 @@ public:
|
|||||||
* @brief Returns the function associated with a vertex.
|
* @brief Returns the function associated with a vertex.
|
||||||
* @return The function associated with the vertex.
|
* @return The function associated with the vertex.
|
||||||
*/
|
*/
|
||||||
function_type * callback() const ENTT_NOEXCEPT {
|
function_type *callback() const ENTT_NOEXCEPT {
|
||||||
return node.callback;
|
return node.callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +321,7 @@ public:
|
|||||||
* @brief Returns the payload associated with a vertex, if any.
|
* @brief Returns the payload associated with a vertex, if any.
|
||||||
* @return The payload associated with the vertex, if any.
|
* @return The payload associated with the vertex, if any.
|
||||||
*/
|
*/
|
||||||
const void * data() const ENTT_NOEXCEPT {
|
const void *data() const ENTT_NOEXCEPT {
|
||||||
return node.payload;
|
return node.payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +329,7 @@ public:
|
|||||||
* @brief Returns the list of nodes reachable from a given vertex.
|
* @brief Returns the list of nodes reachable from a given vertex.
|
||||||
* @return The list of nodes reachable from the vertex.
|
* @return The list of nodes reachable from the vertex.
|
||||||
*/
|
*/
|
||||||
const std::vector<std::size_t> & children() const ENTT_NOEXCEPT {
|
const std::vector<std::size_t> &children() const ENTT_NOEXCEPT {
|
||||||
return reachable;
|
return reachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,25 +356,25 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<auto Candidate, typename... Req>
|
template<auto Candidate, typename... Req>
|
||||||
void emplace(const char *name = nullptr) {
|
void emplace(const char *name = nullptr) {
|
||||||
using resource_type = decltype(internal::free_function_to_resource<Req...>(Candidate));
|
using resource_type = decltype(internal::free_function_to_resource_traits<Req...>(Candidate));
|
||||||
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, basic_registry<entity_type>>;
|
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, basic_registry<entity_type>>;
|
||||||
|
|
||||||
callback_type *callback = +[](const void *, basic_registry<entity_type> ®) {
|
callback_type *callback = +[](const void *, basic_registry<entity_type> ®) {
|
||||||
std::apply(Candidate, to_args(reg, typename resource_type::args{}));
|
std::apply(Candidate, to_args(reg, typename resource_type::args{}));
|
||||||
};
|
};
|
||||||
|
|
||||||
track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
|
vertex_data vdata{
|
||||||
|
|
||||||
vertices.push_back({
|
|
||||||
resource_type::ro::size,
|
resource_type::ro::size,
|
||||||
resource_type::rw::size,
|
resource_type::rw::size,
|
||||||
name,
|
name,
|
||||||
nullptr,
|
nullptr,
|
||||||
callback,
|
callback,
|
||||||
+[](const bool rw, type_info *buffer, const std::size_t length) { return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length); },
|
+[](const bool rw, const type_info **buffer, const std::size_t length) { return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length); },
|
||||||
+[](basic_registry<entity_type> ®) { void(to_args(reg, typename resource_type::args{})); },
|
+[](basic_registry<entity_type> ®) { void(to_args(reg, typename resource_type::args{})); },
|
||||||
type_id<std::integral_constant<decltype(Candidate), Candidate>>()
|
&type_id<std::integral_constant<decltype(Candidate), Candidate>>()};
|
||||||
});
|
|
||||||
|
track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
|
||||||
|
vertices.push_back(std::move(vdata));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -406,7 +388,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<auto Candidate, typename... Req, typename Type>
|
template<auto Candidate, typename... Req, typename Type>
|
||||||
void emplace(Type &value_or_instance, const char *name = nullptr) {
|
void emplace(Type &value_or_instance, const char *name = nullptr) {
|
||||||
using resource_type = decltype(internal::constrained_function_to_resource<Req...>(Candidate));
|
using resource_type = decltype(internal::constrained_function_to_resource_traits<Req...>(Candidate));
|
||||||
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, basic_registry<entity_type>>;
|
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, basic_registry<entity_type>>;
|
||||||
|
|
||||||
callback_type *callback = +[](const void *payload, basic_registry<entity_type> ®) {
|
callback_type *callback = +[](const void *payload, basic_registry<entity_type> ®) {
|
||||||
@@ -414,22 +396,18 @@ public:
|
|||||||
std::apply(Candidate, std::tuple_cat(std::forward_as_tuple(*curr), to_args(reg, typename resource_type::args{})));
|
std::apply(Candidate, std::tuple_cat(std::forward_as_tuple(*curr), to_args(reg, typename resource_type::args{})));
|
||||||
};
|
};
|
||||||
|
|
||||||
track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
|
vertex_data vdata{
|
||||||
|
|
||||||
vertices.push_back({
|
|
||||||
resource_type::ro::size,
|
resource_type::ro::size,
|
||||||
resource_type::rw::size,
|
resource_type::rw::size,
|
||||||
name,
|
name,
|
||||||
&value_or_instance,
|
&value_or_instance,
|
||||||
callback,
|
callback,
|
||||||
+[](const bool rw, type_info *buffer, const std::size_t length) {
|
+[](const bool rw, const type_info **buffer, const std::size_t length) { return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length); },
|
||||||
return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length);
|
+[](basic_registry<entity_type> ®) { void(to_args(reg, typename resource_type::args{})); },
|
||||||
},
|
&type_id<std::integral_constant<decltype(Candidate), Candidate>>()};
|
||||||
+[](basic_registry<entity_type> ®) {
|
|
||||||
void(to_args(reg, typename resource_type::args{}));
|
track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
|
||||||
},
|
vertices.push_back(std::move(vdata));
|
||||||
type_id<std::integral_constant<decltype(Candidate), Candidate>>()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -442,21 +420,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename... Req>
|
template<typename... Req>
|
||||||
void emplace(function_type *func, const void *payload = nullptr, const char *name = nullptr) {
|
void emplace(function_type *func, const void *payload = nullptr, const char *name = nullptr) {
|
||||||
using resource_type = internal::resource<type_list<>, type_list<Req...>>;
|
using resource_type = internal::resource_traits<type_list<>, type_list<Req...>>;
|
||||||
track_dependencies(vertices.size(), true, typename resource_type::ro{}, typename resource_type::rw{});
|
track_dependencies(vertices.size(), true, typename resource_type::ro{}, typename resource_type::rw{});
|
||||||
|
|
||||||
vertices.push_back({
|
vertex_data vdata{
|
||||||
resource_type::ro::size,
|
resource_type::ro::size,
|
||||||
resource_type::rw::size,
|
resource_type::rw::size,
|
||||||
name,
|
name,
|
||||||
payload,
|
payload,
|
||||||
func,
|
func,
|
||||||
+[](const bool rw, type_info *buffer, const std::size_t length) {
|
+[](const bool rw, const type_info **buffer, const std::size_t length) { return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length); },
|
||||||
return rw ? fill_dependencies(typename resource_type::rw{}, buffer, length) : fill_dependencies(typename resource_type::ro{}, buffer, length);
|
|
||||||
},
|
|
||||||
nullptr,
|
nullptr,
|
||||||
type_info{}
|
&type_id<void>()};
|
||||||
});
|
|
||||||
|
vertices.push_back(std::move(vdata));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -498,12 +475,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<entt::id_type, std::vector<std::pair<std::size_t, bool>>> dependencies;
|
dense_map<id_type, std::vector<std::pair<std::size_t, bool>>, identity> dependencies;
|
||||||
std::vector<vertex_data> vertices;
|
std::vector<vertex_data> vertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
#ifndef ENTT_ENTITY_POLY_STORAGE_HPP
|
|
||||||
#define ENTT_ENTITY_POLY_STORAGE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <tuple>
|
|
||||||
#include "../core/type_info.hpp"
|
|
||||||
#include "../core/type_traits.hpp"
|
|
||||||
#include "../poly/poly.hpp"
|
|
||||||
#include "fwd.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Basic poly storage implementation.
|
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
|
||||||
*/
|
|
||||||
template<typename Entity>
|
|
||||||
struct Storage: type_list<type_info() const ENTT_NOEXCEPT> {
|
|
||||||
/**
|
|
||||||
* @brief Concept definition.
|
|
||||||
* @tparam Base Opaque base class from which to inherit.
|
|
||||||
*/
|
|
||||||
template<typename Base>
|
|
||||||
struct type: Base {
|
|
||||||
/**
|
|
||||||
* @brief Returns a type info for the contained objects.
|
|
||||||
* @return The type info for the contained objects.
|
|
||||||
*/
|
|
||||||
type_info value_type() const ENTT_NOEXCEPT {
|
|
||||||
return poly_call<0>(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Concept implementation.
|
|
||||||
* @tparam Type Type for which to generate an implementation.
|
|
||||||
*/
|
|
||||||
template<typename Type>
|
|
||||||
using impl = value_list<&type_id<typename Type::value_type>>;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Defines the poly storage type associate with a given entity type.
|
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
|
||||||
*/
|
|
||||||
template<typename Entity, typename = void>
|
|
||||||
struct poly_storage_traits {
|
|
||||||
/*! @brief Poly storage type for the given entity type. */
|
|
||||||
using storage_type = poly<Storage<Entity>>;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,23 +1,119 @@
|
|||||||
#ifndef ENTT_ENTITY_RUNTIME_VIEW_HPP
|
#ifndef ENTT_ENTITY_RUNTIME_VIEW_HPP
|
||||||
#define ENTT_ENTITY_RUNTIME_VIEW_HPP
|
#define ENTT_ENTITY_RUNTIME_VIEW_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <iterator>
|
|
||||||
#include <vector>
|
|
||||||
#include <utility>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
#include "sparse_set.hpp"
|
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
#include "sparse_set.hpp"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename Set>
|
||||||
|
class runtime_view_iterator final {
|
||||||
|
using iterator_type = typename Set::iterator;
|
||||||
|
|
||||||
|
[[nodiscard]] bool valid() const {
|
||||||
|
return (!tombstone_check || *it != tombstone)
|
||||||
|
&& std::all_of(++pools->begin(), pools->end(), [entt = *it](const auto *curr) { return curr->contains(entt); })
|
||||||
|
&& std::none_of(filter->cbegin(), filter->cend(), [entt = *it](const auto *curr) { return curr && curr->contains(entt); });
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
using difference_type = typename iterator_type::difference_type;
|
||||||
|
using value_type = typename iterator_type::value_type;
|
||||||
|
using pointer = typename iterator_type::pointer;
|
||||||
|
using reference = typename iterator_type::reference;
|
||||||
|
using iterator_category = std::bidirectional_iterator_tag;
|
||||||
|
|
||||||
|
runtime_view_iterator() ENTT_NOEXCEPT
|
||||||
|
: pools{},
|
||||||
|
filter{},
|
||||||
|
it{},
|
||||||
|
tombstone_check{} {}
|
||||||
|
|
||||||
|
runtime_view_iterator(const std::vector<const Set *> &cpools, const std::vector<const Set *> &ignore, iterator_type curr) ENTT_NOEXCEPT
|
||||||
|
: pools{&cpools},
|
||||||
|
filter{&ignore},
|
||||||
|
it{curr},
|
||||||
|
tombstone_check{pools->size() == 1u && (*pools)[0u]->policy() == deletion_policy::in_place} {
|
||||||
|
if(it != (*pools)[0]->end() && !valid()) {
|
||||||
|
++(*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime_view_iterator &operator++() {
|
||||||
|
while(++it != (*pools)[0]->end() && !valid()) {}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime_view_iterator operator++(int) {
|
||||||
|
runtime_view_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime_view_iterator &operator--() {
|
||||||
|
while(--it != (*pools)[0]->begin() && !valid()) {}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime_view_iterator operator--(int) {
|
||||||
|
runtime_view_iterator orig = *this;
|
||||||
|
return operator--(), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
|
return it.operator->();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
|
return *operator->();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator==(const runtime_view_iterator &other) const ENTT_NOEXCEPT {
|
||||||
|
return it == other.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator!=(const runtime_view_iterator &other) const ENTT_NOEXCEPT {
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::vector<const Set *> *pools;
|
||||||
|
const std::vector<const Set *> *filter;
|
||||||
|
iterator_type it;
|
||||||
|
bool tombstone_check;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Runtime view.
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Runtime view implementation.
|
||||||
|
*
|
||||||
|
* Primary template isn't defined on purpose. All the specializations give a
|
||||||
|
* compile-time error, but for a few reasonable cases.
|
||||||
|
*/
|
||||||
|
template<typename>
|
||||||
|
struct basic_runtime_view;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generic runtime view.
|
||||||
*
|
*
|
||||||
* Runtime views iterate over those entities that have at least all the given
|
* Runtime views iterate over those entities that have at least all the given
|
||||||
* components in their bags. During initialization, a runtime view looks at the
|
* components in their bags. During initialization, a runtime view looks at the
|
||||||
@@ -53,115 +149,47 @@ namespace entt {
|
|||||||
* In any other case, attempting to use a view results in undefined behavior.
|
* In any other case, attempting to use a view results in undefined behavior.
|
||||||
*
|
*
|
||||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity, typename Allocator>
|
||||||
class basic_runtime_view final {
|
struct basic_runtime_view<basic_sparse_set<Entity, Allocator>> {
|
||||||
using basic_common_type = basic_sparse_set<Entity>;
|
|
||||||
using underlying_iterator = typename basic_common_type::iterator;
|
|
||||||
|
|
||||||
class view_iterator final {
|
|
||||||
[[nodiscard]] bool valid() const {
|
|
||||||
const auto entt = *it;
|
|
||||||
|
|
||||||
return (!stable_storage || (entt != tombstone))
|
|
||||||
&& std::all_of(pools->begin()++, pools->end(), [entt](const auto *curr) { return curr->contains(entt); })
|
|
||||||
&& std::none_of(filter->cbegin(), filter->cend(), [entt](const auto *curr) { return curr && curr->contains(entt); });
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
using difference_type = typename underlying_iterator::difference_type;
|
|
||||||
using value_type = typename underlying_iterator::value_type;
|
|
||||||
using pointer = typename underlying_iterator::pointer;
|
|
||||||
using reference = typename underlying_iterator::reference;
|
|
||||||
using iterator_category = std::bidirectional_iterator_tag;
|
|
||||||
|
|
||||||
view_iterator() ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
view_iterator(const std::vector<const basic_common_type *> &cpools, const std::vector<const basic_common_type *> &ignore, underlying_iterator curr) ENTT_NOEXCEPT
|
|
||||||
: pools{&cpools},
|
|
||||||
filter{&ignore},
|
|
||||||
it{curr},
|
|
||||||
stable_storage{std::any_of(pools->cbegin(), pools->cend(), [](const basic_common_type *cpool) { return (cpool->policy() == deletion_policy::in_place); })}
|
|
||||||
{
|
|
||||||
if(it != (*pools)[0]->end() && !valid()) {
|
|
||||||
++(*this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
view_iterator & operator++() {
|
|
||||||
while(++it != (*pools)[0]->end() && !valid());
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
view_iterator operator++(int) {
|
|
||||||
view_iterator orig = *this;
|
|
||||||
return ++(*this), orig;
|
|
||||||
}
|
|
||||||
|
|
||||||
view_iterator & operator--() ENTT_NOEXCEPT {
|
|
||||||
while(--it != (*pools)[0]->begin() && !valid());
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
view_iterator operator--(int) ENTT_NOEXCEPT {
|
|
||||||
view_iterator orig = *this;
|
|
||||||
return operator--(), orig;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator==(const view_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return other.it == it;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const view_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] pointer operator->() const {
|
|
||||||
return it.operator->();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] reference operator*() const {
|
|
||||||
return *operator->();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::vector<const basic_common_type *> *pools;
|
|
||||||
const std::vector<const basic_common_type *> *filter;
|
|
||||||
underlying_iterator it;
|
|
||||||
bool stable_storage;
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]] bool valid() const {
|
|
||||||
return !pools.empty() && pools.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
/*! @brief Underlying entity identifier. */
|
/*! @brief Underlying entity identifier. */
|
||||||
using entity_type = Entity;
|
using entity_type = Entity;
|
||||||
/*! @brief Unsigned integer type. */
|
/*! @brief Unsigned integer type. */
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
|
/*! @brief Common type among all storage types. */
|
||||||
|
using base_type = basic_sparse_set<Entity, Allocator>;
|
||||||
/*! @brief Bidirectional iterator type. */
|
/*! @brief Bidirectional iterator type. */
|
||||||
using iterator = view_iterator;
|
using iterator = internal::runtime_view_iterator<base_type>;
|
||||||
|
|
||||||
/*! @brief Default constructor to use to create empty, invalid views. */
|
/*! @brief Default constructor to use to create empty, invalid views. */
|
||||||
basic_runtime_view() ENTT_NOEXCEPT
|
basic_runtime_view() ENTT_NOEXCEPT
|
||||||
: pools{},
|
: pools{},
|
||||||
filter{}
|
filter{} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a runtime view from a set of storage classes.
|
* @brief Appends an opaque storage object to a runtime view.
|
||||||
* @param cpools The storage for the types to iterate.
|
* @param base An opaque reference to a storage object.
|
||||||
* @param epools The storage for the types used to filter the view.
|
* @return This runtime view.
|
||||||
*/
|
*/
|
||||||
basic_runtime_view(std::vector<const basic_common_type *> cpools, std::vector<const basic_common_type *> epools) ENTT_NOEXCEPT
|
basic_runtime_view &iterate(const base_type &base) {
|
||||||
: pools{std::move(cpools)},
|
if(pools.empty() || !(base.size() < pools[0u]->size())) {
|
||||||
filter{std::move(epools)}
|
pools.push_back(&base);
|
||||||
{
|
} else {
|
||||||
// brings the best candidate (if any) on front of the vector
|
pools.push_back(std::exchange(pools[0u], &base));
|
||||||
std::rotate(pools.begin(), std::min_element(pools.begin(), pools.end(), [](const auto *lhs, const auto *rhs) {
|
}
|
||||||
return (!lhs && rhs) || (lhs && rhs && lhs->size() < rhs->size());
|
|
||||||
}), pools.end());
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds an opaque storage object as a filter of a runtime view.
|
||||||
|
* @param base An opaque reference to a storage object.
|
||||||
|
* @return This runtime view.
|
||||||
|
*/
|
||||||
|
basic_runtime_view &exclude(const base_type &base) {
|
||||||
|
filter.push_back(&base);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,7 +197,7 @@ public:
|
|||||||
* @return Estimated number of entities iterated by the view.
|
* @return Estimated number of entities iterated by the view.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] size_type size_hint() const {
|
[[nodiscard]] size_type size_hint() const {
|
||||||
return valid() ? pools.front()->size() : size_type{};
|
return pools.empty() ? size_type{} : pools.front()->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,7 +211,7 @@ public:
|
|||||||
* @return An iterator to the first entity that has the given components.
|
* @return An iterator to the first entity that has the given components.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator begin() const {
|
[[nodiscard]] iterator begin() const {
|
||||||
return valid() ? iterator{pools, filter, pools[0]->begin()} : iterator{};
|
return pools.empty() ? iterator{} : iterator{pools, filter, pools[0]->begin()};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,17 +226,18 @@ public:
|
|||||||
* given components.
|
* given components.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator end() const {
|
[[nodiscard]] iterator end() const {
|
||||||
return valid() ? iterator{pools, filter, pools[0]->end()} : iterator{};
|
return pools.empty() ? iterator{} : iterator{pools, filter, pools[0]->end()};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if a view contains an entity.
|
* @brief Checks if a view contains an entity.
|
||||||
* @param entt A valid entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return True if the view contains the given entity, false otherwise.
|
* @return True if the view contains the given entity, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool contains(const entity_type entt) const {
|
[[nodiscard]] bool contains(const entity_type entt) const {
|
||||||
return valid() && std::all_of(pools.cbegin(), pools.cend(), [entt](const auto *curr) { return curr->contains(entt); })
|
return !pools.empty()
|
||||||
&& std::none_of(filter.cbegin(), filter.cend(), [entt](const auto *curr) { return curr && curr->contains(entt); });
|
&& std::all_of(pools.cbegin(), pools.cend(), [entt](const auto *curr) { return curr->contains(entt); })
|
||||||
|
&& std::none_of(filter.cbegin(), filter.cend(), [entt](const auto *curr) { return curr && curr->contains(entt); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,12 +263,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<const basic_common_type *> pools;
|
std::vector<const base_type *> pools;
|
||||||
std::vector<const basic_common_type *> filter;
|
std::vector<const base_type *> filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
177
src/entt/entity/sigh_storage_mixin.hpp
Normal file
177
src/entt/entity/sigh_storage_mixin.hpp
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
#ifndef ENTT_ENTITY_SIGH_STORAGE_MIXIN_HPP
|
||||||
|
#define ENTT_ENTITY_SIGH_STORAGE_MIXIN_HPP
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include "../config/config.h"
|
||||||
|
#include "../core/any.hpp"
|
||||||
|
#include "../signal/sigh.hpp"
|
||||||
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mixin type used to add signal support to storage types.
|
||||||
|
*
|
||||||
|
* The function type of a listener is equivalent to:
|
||||||
|
*
|
||||||
|
* @code{.cpp}
|
||||||
|
* void(basic_registry<entity_type> &, entity_type);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* This applies to all signals made available.
|
||||||
|
*
|
||||||
|
* @tparam Type The type of the underlying storage.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
class sigh_storage_mixin final: public Type {
|
||||||
|
using basic_iterator = typename Type::basic_iterator;
|
||||||
|
|
||||||
|
template<typename Func>
|
||||||
|
void notify_destruction(basic_iterator first, basic_iterator last, Func func) {
|
||||||
|
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||||
|
|
||||||
|
for(; first != last; ++first) {
|
||||||
|
const auto entt = *first;
|
||||||
|
destruction.publish(*owner, entt);
|
||||||
|
const auto it = Type::find(entt);
|
||||||
|
func(it, it + 1u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap_and_pop(basic_iterator first, basic_iterator last) final {
|
||||||
|
notify_destruction(std::move(first), std::move(last), [this](auto... args) { Type::swap_and_pop(args...); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void in_place_pop(basic_iterator first, basic_iterator last) final {
|
||||||
|
notify_destruction(std::move(first), std::move(last), [this](auto... args) { Type::in_place_pop(args...); });
|
||||||
|
}
|
||||||
|
|
||||||
|
basic_iterator try_emplace(const typename Type::entity_type entt, const bool force_back, const void *value) final {
|
||||||
|
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||||
|
Type::try_emplace(entt, force_back, value);
|
||||||
|
construction.publish(*owner, entt);
|
||||||
|
return Type::find(entt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*! @brief Underlying entity identifier. */
|
||||||
|
using entity_type = typename Type::entity_type;
|
||||||
|
|
||||||
|
/*! @brief Inherited constructors. */
|
||||||
|
using Type::Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a sink object.
|
||||||
|
*
|
||||||
|
* The sink returned by this function can be used to receive notifications
|
||||||
|
* whenever a new instance is created and assigned to an entity.<br/>
|
||||||
|
* Listeners are invoked after the object has been assigned to the entity.
|
||||||
|
*
|
||||||
|
* @sa sink
|
||||||
|
*
|
||||||
|
* @return A temporary sink object.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] auto on_construct() ENTT_NOEXCEPT {
|
||||||
|
return sink{construction};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a sink object.
|
||||||
|
*
|
||||||
|
* The sink returned by this function can be used to receive notifications
|
||||||
|
* whenever an instance is explicitly updated.<br/>
|
||||||
|
* Listeners are invoked after the object has been updated.
|
||||||
|
*
|
||||||
|
* @sa sink
|
||||||
|
*
|
||||||
|
* @return A temporary sink object.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] auto on_update() ENTT_NOEXCEPT {
|
||||||
|
return sink{update};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a sink object.
|
||||||
|
*
|
||||||
|
* The sink returned by this function can be used to receive notifications
|
||||||
|
* whenever an instance is removed from an entity and thus destroyed.<br/>
|
||||||
|
* Listeners are invoked before the object has been removed from the entity.
|
||||||
|
*
|
||||||
|
* @sa sink
|
||||||
|
*
|
||||||
|
* @return A temporary sink object.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] auto on_destroy() ENTT_NOEXCEPT {
|
||||||
|
return sink{destruction};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assigns entities to a storage.
|
||||||
|
* @tparam Args Types of arguments to use to construct the object.
|
||||||
|
* @param entt A valid identifier.
|
||||||
|
* @param args Parameters to use to initialize the object.
|
||||||
|
* @return A reference to the newly created object.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
decltype(auto) emplace(const entity_type entt, Args &&...args) {
|
||||||
|
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||||
|
Type::emplace(entt, std::forward<Args>(args)...);
|
||||||
|
construction.publish(*owner, entt);
|
||||||
|
return this->get(entt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Patches the given instance for an entity.
|
||||||
|
* @tparam Func Types of the function objects to invoke.
|
||||||
|
* @param entt A valid identifier.
|
||||||
|
* @param func Valid function objects.
|
||||||
|
* @return A reference to the patched instance.
|
||||||
|
*/
|
||||||
|
template<typename... Func>
|
||||||
|
decltype(auto) patch(const entity_type entt, Func &&...func) {
|
||||||
|
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||||
|
Type::patch(entt, std::forward<Func>(func)...);
|
||||||
|
update.publish(*owner, entt);
|
||||||
|
return this->get(entt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assigns entities to a storage.
|
||||||
|
* @tparam It Type of input iterator.
|
||||||
|
* @tparam Args Types of arguments to use to construct the objects assigned
|
||||||
|
* to the entities.
|
||||||
|
* @param first An iterator to the first element of the range of entities.
|
||||||
|
* @param last An iterator past the last element of the range of entities.
|
||||||
|
* @param args Parameters to use to initialize the objects assigned to the
|
||||||
|
* entities.
|
||||||
|
*/
|
||||||
|
template<typename It, typename... Args>
|
||||||
|
void insert(It first, It last, Args &&...args) {
|
||||||
|
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||||
|
Type::insert(first, last, std::forward<Args>(args)...);
|
||||||
|
|
||||||
|
for(auto it = construction.empty() ? last : first; it != last; ++it) {
|
||||||
|
construction.publish(*owner, *it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Forwards variables to mixins, if any.
|
||||||
|
* @param value A variable wrapped in an opaque container.
|
||||||
|
*/
|
||||||
|
void bind(any value) ENTT_NOEXCEPT final {
|
||||||
|
auto *reg = any_cast<basic_registry<entity_type>>(&value);
|
||||||
|
owner = reg ? reg : owner;
|
||||||
|
Type::bind(std::move(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
sigh<void(basic_registry<entity_type> &, const entity_type)> construction{};
|
||||||
|
sigh<void(basic_registry<entity_type> &, const entity_type)> destruction{};
|
||||||
|
sigh<void(basic_registry<entity_type> &, const entity_type)> update{};
|
||||||
|
basic_registry<entity_type> *owner{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,25 +1,23 @@
|
|||||||
#ifndef ENTT_ENTITY_SNAPSHOT_HPP
|
#ifndef ENTT_ENTITY_SNAPSHOT_HPP
|
||||||
#define ENTT_ENTITY_SNAPSHOT_HPP
|
#define ENTT_ENTITY_SNAPSHOT_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
#include "../container/dense_map.hpp"
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
|
#include "component.hpp"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
#include "registry.hpp"
|
#include "registry.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Utility class to create snapshots from a registry.
|
* @brief Utility class to create snapshots from a registry.
|
||||||
*
|
*
|
||||||
@@ -32,12 +30,12 @@ namespace entt {
|
|||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
class basic_snapshot {
|
class basic_snapshot {
|
||||||
using traits_type = entt_traits<Entity>;
|
using entity_traits = entt_traits<Entity>;
|
||||||
|
|
||||||
template<typename Component, typename Archive, typename It>
|
template<typename Component, typename Archive, typename It>
|
||||||
void get(Archive &archive, std::size_t sz, It first, It last) const {
|
void get(Archive &archive, std::size_t sz, It first, It last) const {
|
||||||
const auto view = reg->template view<std::add_const_t<Component>>();
|
const auto view = reg->template view<std::add_const_t<Component>>();
|
||||||
archive(typename traits_type::entity_type(sz));
|
archive(typename entity_traits::entity_type(sz));
|
||||||
|
|
||||||
while(first != last) {
|
while(first != last) {
|
||||||
const auto entt = *(first++);
|
const auto entt = *(first++);
|
||||||
@@ -55,7 +53,7 @@ class basic_snapshot {
|
|||||||
|
|
||||||
while(begin != last) {
|
while(begin != last) {
|
||||||
const auto entt = *(begin++);
|
const auto entt = *(begin++);
|
||||||
((reg->template all_of<Component>(entt) ? ++size[Index] : size[Index]), ...);
|
((reg->template all_of<Component>(entt) ? ++size[Index] : 0u), ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
(get<Component>(archive, size[Index], first, last), ...);
|
(get<Component>(archive, size[Index], first, last), ...);
|
||||||
@@ -70,14 +68,13 @@ public:
|
|||||||
* @param source A valid reference to a registry.
|
* @param source A valid reference to a registry.
|
||||||
*/
|
*/
|
||||||
basic_snapshot(const basic_registry<entity_type> &source) ENTT_NOEXCEPT
|
basic_snapshot(const basic_registry<entity_type> &source) ENTT_NOEXCEPT
|
||||||
: reg{&source}
|
: reg{&source} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/*! @brief Default move constructor. */
|
/*! @brief Default move constructor. */
|
||||||
basic_snapshot(basic_snapshot &&) = default;
|
basic_snapshot(basic_snapshot &&) ENTT_NOEXCEPT = default;
|
||||||
|
|
||||||
/*! @brief Default move assignment operator. @return This snapshot. */
|
/*! @brief Default move assignment operator. @return This snapshot. */
|
||||||
basic_snapshot & operator=(basic_snapshot &&) = default;
|
basic_snapshot &operator=(basic_snapshot &&) ENTT_NOEXCEPT = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Puts aside all the entities from the underlying registry.
|
* @brief Puts aside all the entities from the underlying registry.
|
||||||
@@ -90,17 +87,16 @@ public:
|
|||||||
* @return An object of this type to continue creating the snapshot.
|
* @return An object of this type to continue creating the snapshot.
|
||||||
*/
|
*/
|
||||||
template<typename Archive>
|
template<typename Archive>
|
||||||
const basic_snapshot & entities(Archive &archive) const {
|
const basic_snapshot &entities(Archive &archive) const {
|
||||||
const auto sz = reg->size();
|
const auto sz = reg->size();
|
||||||
|
|
||||||
archive(typename traits_type::entity_type(sz));
|
archive(typename entity_traits::entity_type(sz + 1u));
|
||||||
|
archive(reg->released());
|
||||||
|
|
||||||
for(auto first = reg->data(), last = first + sz; first != last; ++first) {
|
for(auto first = reg->data(), last = first + sz; first != last; ++first) {
|
||||||
archive(*first);
|
archive(*first);
|
||||||
}
|
}
|
||||||
|
|
||||||
archive(reg->released());
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,10 +112,10 @@ public:
|
|||||||
* @return An object of this type to continue creating the snapshot.
|
* @return An object of this type to continue creating the snapshot.
|
||||||
*/
|
*/
|
||||||
template<typename... Component, typename Archive>
|
template<typename... Component, typename Archive>
|
||||||
const basic_snapshot & component(Archive &archive) const {
|
const basic_snapshot &component(Archive &archive) const {
|
||||||
if constexpr(sizeof...(Component) == 1u) {
|
if constexpr(sizeof...(Component) == 1u) {
|
||||||
const auto view = reg->template view<const Component...>();
|
const auto view = reg->template view<const Component...>();
|
||||||
(component<Component>(archive, view.data(), view.data() + view.size()), ...);
|
(component<Component>(archive, view.rbegin(), view.rend()), ...);
|
||||||
return *this;
|
return *this;
|
||||||
} else {
|
} else {
|
||||||
(component<Component>(archive), ...);
|
(component<Component>(archive), ...);
|
||||||
@@ -142,7 +138,7 @@ public:
|
|||||||
* @return An object of this type to continue creating the snapshot.
|
* @return An object of this type to continue creating the snapshot.
|
||||||
*/
|
*/
|
||||||
template<typename... Component, typename Archive, typename It>
|
template<typename... Component, typename Archive, typename It>
|
||||||
const basic_snapshot & component(Archive &archive, It first, It last) const {
|
const basic_snapshot &component(Archive &archive, It first, It last) const {
|
||||||
component<Component...>(archive, first, last, std::index_sequence_for<Component...>{});
|
component<Component...>(archive, first, last, std::index_sequence_for<Component...>{});
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -151,7 +147,6 @@ private:
|
|||||||
const basic_registry<entity_type> *reg;
|
const basic_registry<entity_type> *reg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Utility class to restore a snapshot as a whole.
|
* @brief Utility class to restore a snapshot as a whole.
|
||||||
*
|
*
|
||||||
@@ -164,30 +159,30 @@ private:
|
|||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
class basic_snapshot_loader {
|
class basic_snapshot_loader {
|
||||||
using traits_type = entt_traits<Entity>;
|
using entity_traits = entt_traits<Entity>;
|
||||||
|
|
||||||
template<typename Type, typename Archive>
|
template<typename Type, typename Archive>
|
||||||
void assign(Archive &archive) const {
|
void assign(Archive &archive) const {
|
||||||
typename traits_type::entity_type length{};
|
typename entity_traits::entity_type length{};
|
||||||
|
entity_type entt;
|
||||||
|
|
||||||
archive(length);
|
archive(length);
|
||||||
|
|
||||||
entity_type entt{};
|
if constexpr(ignore_as_empty_v<Type>) {
|
||||||
|
|
||||||
if constexpr(std::tuple_size_v<decltype(reg->template view<Type>().get({}))> == 0) {
|
|
||||||
while(length--) {
|
while(length--) {
|
||||||
archive(entt);
|
archive(entt);
|
||||||
const auto entity = reg->valid(entt) ? entt : reg->create(entt);
|
const auto entity = reg->valid(entt) ? entt : reg->create(entt);
|
||||||
ENTT_ASSERT(entity == entt, "Entity not available for use");
|
ENTT_ASSERT(entity == entt, "Entity not available for use");
|
||||||
reg->template emplace<Type>(entity);
|
reg->template emplace<Type>(entt);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Type instance{};
|
Type instance;
|
||||||
|
|
||||||
while(length--) {
|
while(length--) {
|
||||||
archive(entt, instance);
|
archive(entt, instance);
|
||||||
const auto entity = reg->valid(entt) ? entt : reg->create(entt);
|
const auto entity = reg->valid(entt) ? entt : reg->create(entt);
|
||||||
ENTT_ASSERT(entity == entt, "Entity not available for use");
|
ENTT_ASSERT(entity == entt, "Entity not available for use");
|
||||||
reg->template emplace<Type>(entity, std::move(instance));
|
reg->template emplace<Type>(entt, std::move(instance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,17 +196,16 @@ public:
|
|||||||
* @param source A valid reference to a registry.
|
* @param source A valid reference to a registry.
|
||||||
*/
|
*/
|
||||||
basic_snapshot_loader(basic_registry<entity_type> &source) ENTT_NOEXCEPT
|
basic_snapshot_loader(basic_registry<entity_type> &source) ENTT_NOEXCEPT
|
||||||
: reg{&source}
|
: reg{&source} {
|
||||||
{
|
|
||||||
// restoring a snapshot as a whole requires a clean registry
|
// restoring a snapshot as a whole requires a clean registry
|
||||||
ENTT_ASSERT(reg->empty(), "Registry must be empty");
|
ENTT_ASSERT(reg->empty(), "Registry must be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @brief Default move constructor. */
|
/*! @brief Default move constructor. */
|
||||||
basic_snapshot_loader(basic_snapshot_loader &&) = default;
|
basic_snapshot_loader(basic_snapshot_loader &&) ENTT_NOEXCEPT = default;
|
||||||
|
|
||||||
/*! @brief Default move assignment operator. @return This loader. */
|
/*! @brief Default move assignment operator. @return This loader. */
|
||||||
basic_snapshot_loader & operator=(basic_snapshot_loader &&) = default;
|
basic_snapshot_loader &operator=(basic_snapshot_loader &&) ENTT_NOEXCEPT = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Restores entities that were in use during serialization.
|
* @brief Restores entities that were in use during serialization.
|
||||||
@@ -224,20 +218,17 @@ public:
|
|||||||
* @return A valid loader to continue restoring data.
|
* @return A valid loader to continue restoring data.
|
||||||
*/
|
*/
|
||||||
template<typename Archive>
|
template<typename Archive>
|
||||||
const basic_snapshot_loader & entities(Archive &archive) const {
|
const basic_snapshot_loader &entities(Archive &archive) const {
|
||||||
typename traits_type::entity_type length{};
|
typename entity_traits::entity_type length{};
|
||||||
|
|
||||||
archive(length);
|
archive(length);
|
||||||
std::vector<entity_type> all(length);
|
std::vector<entity_type> all(length);
|
||||||
|
|
||||||
for(decltype(length) pos{}; pos < length; ++pos) {
|
for(std::size_t pos{}; pos < length; ++pos) {
|
||||||
archive(all[pos]);
|
archive(all[pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_type destroyed;
|
reg->assign(++all.cbegin(), all.cend(), all[0u]);
|
||||||
archive(destroyed);
|
|
||||||
|
|
||||||
reg->assign(all.cbegin(), all.cend(), destroyed);
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -256,7 +247,7 @@ public:
|
|||||||
* @return A valid loader to continue restoring data.
|
* @return A valid loader to continue restoring data.
|
||||||
*/
|
*/
|
||||||
template<typename... Component, typename Archive>
|
template<typename... Component, typename Archive>
|
||||||
const basic_snapshot_loader & component(Archive &archive) const {
|
const basic_snapshot_loader &component(Archive &archive) const {
|
||||||
(assign<Component>(archive), ...);
|
(assign<Component>(archive), ...);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -271,9 +262,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A valid loader to continue restoring data.
|
* @return A valid loader to continue restoring data.
|
||||||
*/
|
*/
|
||||||
const basic_snapshot_loader & orphans() const {
|
const basic_snapshot_loader &orphans() const {
|
||||||
reg->orphans([this](const auto entt) {
|
reg->each([this](const auto entt) {
|
||||||
reg->release(entt);
|
if(reg->orphan(entt)) {
|
||||||
|
reg->release(entt);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@@ -283,7 +276,6 @@ private:
|
|||||||
basic_registry<entity_type> *reg;
|
basic_registry<entity_type> *reg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Utility class for _continuous loading_.
|
* @brief Utility class for _continuous loading_.
|
||||||
*
|
*
|
||||||
@@ -302,7 +294,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
template<typename Entity>
|
template<typename Entity>
|
||||||
class basic_continuous_loader {
|
class basic_continuous_loader {
|
||||||
using traits_type = entt_traits<Entity>;
|
using entity_traits = entt_traits<Entity>;
|
||||||
|
|
||||||
void destroy(Entity entt) {
|
void destroy(Entity entt) {
|
||||||
if(const auto it = remloc.find(entt); it == remloc.cend()) {
|
if(const auto it = remloc.find(entt); it == remloc.cend()) {
|
||||||
@@ -329,8 +321,7 @@ class basic_continuous_loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
auto update(int, Container &container)
|
auto update(int, Container &container) -> decltype(typename Container::mapped_type{}, void()) {
|
||||||
-> decltype(typename Container::mapped_type{}, void()) {
|
|
||||||
// map like container
|
// map like container
|
||||||
Container other;
|
Container other;
|
||||||
|
|
||||||
@@ -348,12 +339,12 @@ class basic_continuous_loader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::swap(container, other);
|
using std::swap;
|
||||||
|
swap(container, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
auto update(char, Container &container)
|
auto update(char, Container &container) -> decltype(typename Container::value_type{}, void()) {
|
||||||
-> decltype(typename Container::value_type{}, void()) {
|
|
||||||
// vector like container
|
// vector like container
|
||||||
static_assert(std::is_same_v<typename Container::value_type, entity_type>, "Invalid value type");
|
static_assert(std::is_same_v<typename Container::value_type, entity_type>, "Invalid value type");
|
||||||
|
|
||||||
@@ -363,7 +354,7 @@ class basic_continuous_loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Other, typename Type, typename Member>
|
template<typename Other, typename Type, typename Member>
|
||||||
void update([[maybe_unused]] Other &instance, [[maybe_unused]] Member Type:: *member) {
|
void update([[maybe_unused]] Other &instance, [[maybe_unused]] Member Type::*member) {
|
||||||
if constexpr(!std::is_same_v<Other, Type>) {
|
if constexpr(!std::is_same_v<Other, Type>) {
|
||||||
return;
|
return;
|
||||||
} else if constexpr(std::is_same_v<Member, entity_type>) {
|
} else if constexpr(std::is_same_v<Member, entity_type>) {
|
||||||
@@ -386,20 +377,20 @@ class basic_continuous_loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Other, typename Archive, typename... Type, typename... Member>
|
template<typename Other, typename Archive, typename... Type, typename... Member>
|
||||||
void assign(Archive &archive, [[maybe_unused]] Member Type:: *... member) {
|
void assign(Archive &archive, [[maybe_unused]] Member Type::*...member) {
|
||||||
typename traits_type::entity_type length{};
|
typename entity_traits::entity_type length{};
|
||||||
|
entity_type entt;
|
||||||
|
|
||||||
archive(length);
|
archive(length);
|
||||||
|
|
||||||
entity_type entt{};
|
if constexpr(ignore_as_empty_v<Other>) {
|
||||||
|
|
||||||
if constexpr(std::tuple_size_v<decltype(reg->template view<Other>().get({}))> == 0) {
|
|
||||||
while(length--) {
|
while(length--) {
|
||||||
archive(entt);
|
archive(entt);
|
||||||
restore(entt);
|
restore(entt);
|
||||||
reg->template emplace_or_replace<Other>(map(entt));
|
reg->template emplace_or_replace<Other>(map(entt));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Other instance{};
|
Other instance;
|
||||||
|
|
||||||
while(length--) {
|
while(length--) {
|
||||||
archive(entt, instance);
|
archive(entt, instance);
|
||||||
@@ -419,14 +410,13 @@ public:
|
|||||||
* @param source A valid reference to a registry.
|
* @param source A valid reference to a registry.
|
||||||
*/
|
*/
|
||||||
basic_continuous_loader(basic_registry<entity_type> &source) ENTT_NOEXCEPT
|
basic_continuous_loader(basic_registry<entity_type> &source) ENTT_NOEXCEPT
|
||||||
: reg{&source}
|
: reg{&source} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/*! @brief Default move constructor. */
|
/*! @brief Default move constructor. */
|
||||||
basic_continuous_loader(basic_continuous_loader &&) = default;
|
basic_continuous_loader(basic_continuous_loader &&) = default;
|
||||||
|
|
||||||
/*! @brief Default move assignment operator. @return This loader. */
|
/*! @brief Default move assignment operator. @return This loader. */
|
||||||
basic_continuous_loader & operator=(basic_continuous_loader &&) = default;
|
basic_continuous_loader &operator=(basic_continuous_loader &&) = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Restores entities that were in use during serialization.
|
* @brief Restores entities that were in use during serialization.
|
||||||
@@ -439,25 +429,24 @@ public:
|
|||||||
* @return A non-const reference to this loader.
|
* @return A non-const reference to this loader.
|
||||||
*/
|
*/
|
||||||
template<typename Archive>
|
template<typename Archive>
|
||||||
basic_continuous_loader & entities(Archive &archive) {
|
basic_continuous_loader &entities(Archive &archive) {
|
||||||
typename traits_type::entity_type length{};
|
typename entity_traits::entity_type length{};
|
||||||
entity_type entt{};
|
entity_type entt{};
|
||||||
|
|
||||||
archive(length);
|
archive(length);
|
||||||
|
// discards the head of the list of destroyed entities
|
||||||
|
archive(entt);
|
||||||
|
|
||||||
for(decltype(length) pos{}; pos < length; ++pos) {
|
for(std::size_t pos{}, last = length - 1u; pos < last; ++pos) {
|
||||||
archive(entt);
|
archive(entt);
|
||||||
|
|
||||||
if(const auto entity = traits_type::to_entity(entt); entity == pos) {
|
if(const auto entity = entity_traits::to_entity(entt); entity == pos) {
|
||||||
restore(entt);
|
restore(entt);
|
||||||
} else {
|
} else {
|
||||||
destroy(entt);
|
destroy(entt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// discards the head of the list of destroyed entities
|
|
||||||
archive(entt);
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +470,7 @@ public:
|
|||||||
* @return A non-const reference to this loader.
|
* @return A non-const reference to this loader.
|
||||||
*/
|
*/
|
||||||
template<typename... Component, typename Archive, typename... Type, typename... Member>
|
template<typename... Component, typename Archive, typename... Type, typename... Member>
|
||||||
basic_continuous_loader & component(Archive &archive, Member Type:: *... member) {
|
basic_continuous_loader &component(Archive &archive, Member Type::*...member) {
|
||||||
(remove_if_exists<Component>(), ...);
|
(remove_if_exists<Component>(), ...);
|
||||||
(assign<Component>(archive, member...), ...);
|
(assign<Component>(archive, member...), ...);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -495,7 +484,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A non-const reference to this loader.
|
* @return A non-const reference to this loader.
|
||||||
*/
|
*/
|
||||||
basic_continuous_loader & shrink() {
|
basic_continuous_loader &shrink() {
|
||||||
auto it = remloc.begin();
|
auto it = remloc.begin();
|
||||||
|
|
||||||
while(it != remloc.cend()) {
|
while(it != remloc.cend()) {
|
||||||
@@ -527,9 +516,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @return A non-const reference to this loader.
|
* @return A non-const reference to this loader.
|
||||||
*/
|
*/
|
||||||
basic_continuous_loader & orphans() {
|
basic_continuous_loader &orphans() {
|
||||||
reg->orphans([this](const auto entt) {
|
reg->each([this](const auto entt) {
|
||||||
reg->release(entt);
|
if(reg->orphan(entt)) {
|
||||||
|
reg->release(entt);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@@ -537,7 +528,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Tests if a loader knows about a given entity.
|
* @brief Tests if a loader knows about a given entity.
|
||||||
* @param entt An entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return True if `entity` is managed by the loader, false otherwise.
|
* @return True if `entity` is managed by the loader, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool contains(entity_type entt) const ENTT_NOEXCEPT {
|
[[nodiscard]] bool contains(entity_type entt) const ENTT_NOEXCEPT {
|
||||||
@@ -546,7 +537,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the identifier to which an entity refers.
|
* @brief Returns the identifier to which an entity refers.
|
||||||
* @param entt An entity identifier.
|
* @param entt A valid identifier.
|
||||||
* @return The local identifier if any, the null entity otherwise.
|
* @return The local identifier if any, the null entity otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] entity_type map(entity_type entt) const ENTT_NOEXCEPT {
|
[[nodiscard]] entity_type map(entity_type entt) const ENTT_NOEXCEPT {
|
||||||
@@ -561,12 +552,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<entity_type, std::pair<entity_type, bool>> remloc;
|
dense_map<entity_type, std::pair<entity_type, bool>> remloc;
|
||||||
basic_registry<entity_type> *reg;
|
basic_registry<entity_type> *reg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,10 @@
|
|||||||
#ifndef ENTT_ENTITY_UTILITY_HPP
|
#ifndef ENTT_ENTITY_UTILITY_HPP
|
||||||
#define ENTT_ENTITY_UTILITY_HPP
|
#define ENTT_ENTITY_UTILITY_HPP
|
||||||
|
|
||||||
|
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias for exclusion lists.
|
* @brief Alias for exclusion lists.
|
||||||
* @tparam Type List of types.
|
* @tparam Type List of types.
|
||||||
@@ -15,7 +12,6 @@ namespace entt {
|
|||||||
template<typename... Type>
|
template<typename... Type>
|
||||||
struct exclude_t: type_list<Type...> {};
|
struct exclude_t: type_list<Type...> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variable template for exclusion lists.
|
* @brief Variable template for exclusion lists.
|
||||||
* @tparam Type List of types.
|
* @tparam Type List of types.
|
||||||
@@ -23,14 +19,12 @@ struct exclude_t: type_list<Type...> {};
|
|||||||
template<typename... Type>
|
template<typename... Type>
|
||||||
inline constexpr exclude_t<Type...> exclude{};
|
inline constexpr exclude_t<Type...> exclude{};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias for lists of observed components.
|
* @brief Alias for lists of observed components.
|
||||||
* @tparam Type List of types.
|
* @tparam Type List of types.
|
||||||
*/
|
*/
|
||||||
template<typename... Type>
|
template<typename... Type>
|
||||||
struct get_t: type_list<Type...>{};
|
struct get_t: type_list<Type...> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variable template for lists of observed components.
|
* @brief Variable template for lists of observed components.
|
||||||
@@ -39,8 +33,20 @@ struct get_t: type_list<Type...>{};
|
|||||||
template<typename... Type>
|
template<typename... Type>
|
||||||
inline constexpr get_t<Type...> get{};
|
inline constexpr get_t<Type...> get{};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Alias for lists of owned components.
|
||||||
|
* @tparam Type List of types.
|
||||||
|
*/
|
||||||
|
template<typename... Type>
|
||||||
|
struct owned_t: type_list<Type...> {};
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @brief Variable template for lists of owned components.
|
||||||
|
* @tparam Type List of types.
|
||||||
|
*/
|
||||||
|
template<typename... Type>
|
||||||
|
inline constexpr owned_t<Type...> owned{};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,20 @@
|
|||||||
|
#include "config/config.h"
|
||||||
|
#include "config/macro.h"
|
||||||
#include "config/version.h"
|
#include "config/version.h"
|
||||||
|
#include "container/dense_map.hpp"
|
||||||
|
#include "container/dense_set.hpp"
|
||||||
#include "core/algorithm.hpp"
|
#include "core/algorithm.hpp"
|
||||||
#include "core/any.hpp"
|
#include "core/any.hpp"
|
||||||
#include "core/attribute.h"
|
#include "core/attribute.h"
|
||||||
|
#include "core/compressed_pair.hpp"
|
||||||
|
#include "core/enum.hpp"
|
||||||
#include "core/family.hpp"
|
#include "core/family.hpp"
|
||||||
#include "core/hashed_string.hpp"
|
#include "core/hashed_string.hpp"
|
||||||
#include "core/ident.hpp"
|
#include "core/ident.hpp"
|
||||||
|
#include "core/iterator.hpp"
|
||||||
|
#include "core/memory.hpp"
|
||||||
#include "core/monostate.hpp"
|
#include "core/monostate.hpp"
|
||||||
|
#include "core/tuple.hpp"
|
||||||
#include "core/type_info.hpp"
|
#include "core/type_info.hpp"
|
||||||
#include "core/type_traits.hpp"
|
#include "core/type_traits.hpp"
|
||||||
#include "core/utility.hpp"
|
#include "core/utility.hpp"
|
||||||
@@ -16,9 +25,9 @@
|
|||||||
#include "entity/helper.hpp"
|
#include "entity/helper.hpp"
|
||||||
#include "entity/observer.hpp"
|
#include "entity/observer.hpp"
|
||||||
#include "entity/organizer.hpp"
|
#include "entity/organizer.hpp"
|
||||||
#include "entity/poly_storage.hpp"
|
|
||||||
#include "entity/registry.hpp"
|
#include "entity/registry.hpp"
|
||||||
#include "entity/runtime_view.hpp"
|
#include "entity/runtime_view.hpp"
|
||||||
|
#include "entity/sigh_storage_mixin.hpp"
|
||||||
#include "entity/snapshot.hpp"
|
#include "entity/snapshot.hpp"
|
||||||
#include "entity/sparse_set.hpp"
|
#include "entity/sparse_set.hpp"
|
||||||
#include "entity/storage.hpp"
|
#include "entity/storage.hpp"
|
||||||
@@ -43,8 +52,8 @@
|
|||||||
#include "process/process.hpp"
|
#include "process/process.hpp"
|
||||||
#include "process/scheduler.hpp"
|
#include "process/scheduler.hpp"
|
||||||
#include "resource/cache.hpp"
|
#include "resource/cache.hpp"
|
||||||
#include "resource/handle.hpp"
|
|
||||||
#include "resource/loader.hpp"
|
#include "resource/loader.hpp"
|
||||||
|
#include "resource/resource.hpp"
|
||||||
#include "signal/delegate.hpp"
|
#include "signal/delegate.hpp"
|
||||||
#include "signal/dispatcher.hpp"
|
#include "signal/dispatcher.hpp"
|
||||||
#include "signal/emitter.hpp"
|
#include "signal/emitter.hpp"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
#include "container/fwd.hpp"
|
||||||
#include "core/fwd.hpp"
|
#include "core/fwd.hpp"
|
||||||
#include "entity/fwd.hpp"
|
#include "entity/fwd.hpp"
|
||||||
|
#include "meta/fwd.hpp"
|
||||||
#include "poly/fwd.hpp"
|
#include "poly/fwd.hpp"
|
||||||
#include "resource/fwd.hpp"
|
#include "resource/fwd.hpp"
|
||||||
#include "signal/fwd.hpp"
|
#include "signal/fwd.hpp"
|
||||||
|
|||||||
@@ -1,111 +1,114 @@
|
|||||||
#ifndef ENTT_LOCATOR_LOCATOR_HPP
|
#ifndef ENTT_LOCATOR_LOCATOR_HPP
|
||||||
#define ENTT_LOCATOR_LOCATOR_HPP
|
#define ENTT_LOCATOR_LOCATOR_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Service locator, nothing more.
|
* @brief Service locator, nothing more.
|
||||||
*
|
*
|
||||||
* A service locator can be used to do what it promises: locate services.<br/>
|
* A service locator is used to do what it promises: locate services.<br/>
|
||||||
* Usually service locators are tightly bound to the services they expose and
|
* Usually service locators are tightly bound to the services they expose and
|
||||||
* thus it's hard to define a general purpose class to do that. This template
|
* thus it's hard to define a general purpose class to do that. This tiny class
|
||||||
* based implementation tries to fill the gap and to get rid of the burden of
|
* tries to fill the gap and to get rid of the burden of defining a different
|
||||||
* defining a different specific locator for each application.
|
* specific locator for each application.
|
||||||
*
|
*
|
||||||
* @tparam Service Type of service managed by the locator.
|
* @note
|
||||||
|
* Users shouldn't retain references to a service. The recommended way is to
|
||||||
|
* retrieve the service implementation currently set each and every time the
|
||||||
|
* need for it arises. The risk is to incur in unexpected behaviors otherwise.
|
||||||
|
*
|
||||||
|
* @tparam Service Service type.
|
||||||
*/
|
*/
|
||||||
template<typename Service>
|
template<typename Service>
|
||||||
struct service_locator {
|
struct locator final {
|
||||||
/*! @brief Type of service offered. */
|
/*! @brief Service type. */
|
||||||
using service_type = Service;
|
using type = Service;
|
||||||
|
|
||||||
/*! @brief Default constructor, deleted on purpose. */
|
/*! @brief Default constructor, deleted on purpose. */
|
||||||
service_locator() = delete;
|
locator() = delete;
|
||||||
/*! @brief Default destructor, deleted on purpose. */
|
/*! @brief Default destructor, deleted on purpose. */
|
||||||
~service_locator() = delete;
|
~locator() = delete;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Tests if a valid service implementation is set.
|
* @brief Checks whether a service locator contains a value.
|
||||||
* @return True if the service is set, false otherwise.
|
* @return True if the service locator contains a value, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static bool empty() ENTT_NOEXCEPT {
|
[[nodiscard]] static bool has_value() ENTT_NOEXCEPT {
|
||||||
return !static_cast<bool>(service);
|
return (service != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a weak pointer to a service implementation, if any.
|
* @brief Returns a reference to a valid service, if any.
|
||||||
*
|
|
||||||
* Clients of a service shouldn't retain references to it. The recommended
|
|
||||||
* way is to retrieve the service implementation currently set each and
|
|
||||||
* every time the need of using it arises. Otherwise users can incur in
|
|
||||||
* unexpected behaviors.
|
|
||||||
*
|
|
||||||
* @return A reference to the service implementation currently set, if any.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static std::weak_ptr<Service> get() ENTT_NOEXCEPT {
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns a weak reference to a service implementation, if any.
|
|
||||||
*
|
|
||||||
* Clients of a service shouldn't retain references to it. The recommended
|
|
||||||
* way is to retrieve the service implementation currently set each and
|
|
||||||
* every time the need of using it arises. Otherwise users can incur in
|
|
||||||
* unexpected behaviors.
|
|
||||||
*
|
*
|
||||||
* @warning
|
* @warning
|
||||||
* In case no service implementation has been set, a call to this function
|
* Invoking this function can result in undefined behavior if the service
|
||||||
* results in undefined behavior.
|
* hasn't been set yet.
|
||||||
*
|
*
|
||||||
* @return A reference to the service implementation currently set, if any.
|
* @return A reference to the service currently set, if any.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] static Service & ref() ENTT_NOEXCEPT {
|
[[nodiscard]] static Service &value() ENTT_NOEXCEPT {
|
||||||
|
ENTT_ASSERT(has_value(), "Service not available");
|
||||||
return *service;
|
return *service;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets or replaces a service.
|
* @brief Returns a service if available or sets it from a fallback type.
|
||||||
* @tparam Impl Type of the new service to use.
|
*
|
||||||
* @tparam Args Types of arguments to use to construct the service.
|
* Arguments are used only if a service doesn't already exist. In all other
|
||||||
* @param args Parameters to use to construct the service.
|
* cases, they are discarded.
|
||||||
|
*
|
||||||
|
* @tparam Args Types of arguments to use to construct the fallback service.
|
||||||
|
* @tparam Impl Fallback service type.
|
||||||
|
* @param args Parameters to use to construct the fallback service.
|
||||||
|
* @return A reference to a valid service.
|
||||||
*/
|
*/
|
||||||
template<typename Impl = Service, typename... Args>
|
template<typename Impl = Service, typename... Args>
|
||||||
static void set(Args &&... args) {
|
[[nodiscard]] static Service &value_or(Args &&...args) {
|
||||||
service = std::make_shared<Impl>(std::forward<Args>(args)...);
|
return service ? *service : emplace<Impl>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets or replaces a service.
|
* @brief Sets or replaces a service.
|
||||||
* @param ptr Service to use to replace the current one.
|
* @tparam Impl Service type.
|
||||||
|
* @tparam Args Types of arguments to use to construct the service.
|
||||||
|
* @param args Parameters to use to construct the service.
|
||||||
|
* @return A reference to a valid service.
|
||||||
*/
|
*/
|
||||||
static void set(std::shared_ptr<Service> ptr) {
|
template<typename Impl = Service, typename... Args>
|
||||||
ENTT_ASSERT(static_cast<bool>(ptr), "Null service not allowed");
|
static Service &emplace(Args &&...args) {
|
||||||
service = std::move(ptr);
|
service = std::make_shared<Impl>(std::forward<Args>(args)...);
|
||||||
|
return *service;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resets a service.
|
* @brief Sets or replaces a service using a given allocator.
|
||||||
*
|
* @tparam Impl Service type.
|
||||||
* The service is no longer valid after a reset.
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
* @tparam Args Types of arguments to use to construct the service.
|
||||||
|
* @param alloc The allocator to use.
|
||||||
|
* @param args Parameters to use to construct the service.
|
||||||
|
* @return A reference to a valid service.
|
||||||
*/
|
*/
|
||||||
static void reset() {
|
template<typename Impl = Service, typename Allocator, typename... Args>
|
||||||
|
static Service &allocate_emplace(Allocator alloc, Args &&...args) {
|
||||||
|
service = std::allocate_shared<Impl>(alloc, std::forward<Args>(args)...);
|
||||||
|
return *service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @brief Resets a service. */
|
||||||
|
static void reset() ENTT_NOEXCEPT {
|
||||||
service.reset();
|
service.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// std::shared_ptr because of its type erased allocator which is pretty useful here
|
||||||
inline static std::shared_ptr<Service> service = nullptr;
|
inline static std::shared_ptr<Service> service = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
#ifndef ENTT_META_ADL_POINTER_HPP
|
#ifndef ENTT_META_ADL_POINTER_HPP
|
||||||
#define ENTT_META_ADL_POINTER_HPP
|
#define ENTT_META_ADL_POINTER_HPP
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ADL based lookup function for dereferencing meta pointer-like types.
|
* @brief ADL based lookup function for dereferencing meta pointer-like types.
|
||||||
* @tparam Type Element type.
|
* @tparam Type Element type.
|
||||||
@@ -16,7 +14,6 @@ decltype(auto) dereference_meta_pointer_like(const Type &value) {
|
|||||||
return *value;
|
return *value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fake ADL based lookup function for meta pointer-like types.
|
* @brief Fake ADL based lookup function for meta pointer-like types.
|
||||||
* @tparam Type Element type.
|
* @tparam Type Element type.
|
||||||
@@ -33,8 +30,6 @@ struct adl_meta_pointer_like {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,295 +1,161 @@
|
|||||||
#ifndef ENTT_META_CONTAINER_HPP
|
#ifndef ENTT_META_CONTAINER_HPP
|
||||||
#define ENTT_META_CONTAINER_HPP
|
#define ENTT_META_CONTAINER_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../config/config.h"
|
#include "../container/dense_map.hpp"
|
||||||
#include "../core/type_traits.hpp"
|
#include "../container/dense_set.hpp"
|
||||||
|
#include "meta.hpp"
|
||||||
#include "type_traits.hpp"
|
#include "type_traits.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Container traits.
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* @tparam Container Type of the underlying container.
|
* Internal details not to be documented.
|
||||||
* @tparam Trait Traits associated with the underlying container.
|
|
||||||
*/
|
*/
|
||||||
template<typename Container, template<typename> class... Trait>
|
|
||||||
struct meta_container_traits: public Trait<Container>... {
|
|
||||||
/*! @brief Type of container. */
|
|
||||||
using type = Container;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
/**
|
template<typename, typename = void>
|
||||||
* @brief Basic STL-compatible container traits
|
struct is_dynamic_sequence_container: std::false_type {};
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
template<typename Type>
|
||||||
template<typename Container>
|
struct is_dynamic_sequence_container<Type, std::void_t<decltype(&Type::reserve)>>: std::true_type {};
|
||||||
struct basic_container {
|
|
||||||
/**
|
template<typename, typename = void>
|
||||||
* @brief Returns the size of the given container.
|
struct is_key_only_meta_associative_container: std::true_type {};
|
||||||
* @param cont The container for which to return the size.
|
|
||||||
* @return The size of the given container.
|
template<typename Type>
|
||||||
*/
|
struct is_key_only_meta_associative_container<Type, std::void_t<typename Type::mapped_type>>: std::false_type {};
|
||||||
[[nodiscard]] static typename Container::size_type size(const Container &cont) ENTT_NOEXCEPT {
|
|
||||||
return cont.size();
|
template<typename Type>
|
||||||
|
struct basic_meta_sequence_container_traits {
|
||||||
|
using iterator = meta_sequence_container::iterator;
|
||||||
|
using size_type = std::size_t;
|
||||||
|
|
||||||
|
[[nodiscard]] static size_type size(const any &container) ENTT_NOEXCEPT {
|
||||||
|
return any_cast<const Type &>(container).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
[[nodiscard]] static bool resize([[maybe_unused]] any &container, [[maybe_unused]] size_type sz) {
|
||||||
* @brief Returns an iterator to the first element of the given container.
|
if constexpr(is_dynamic_sequence_container<Type>::value) {
|
||||||
* @param cont The container for which to return the iterator.
|
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||||
* @return An iterator to the first element of the given container.
|
cont->resize(sz);
|
||||||
*/
|
return true;
|
||||||
[[nodiscard]] static typename Container::iterator begin(Container &cont) {
|
}
|
||||||
return cont.begin();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns an iterator to the first element of the given container.
|
|
||||||
* @param cont The container for which to return the iterator.
|
|
||||||
* @return An iterator to the first element of the given container.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static typename Container::const_iterator cbegin(const Container &cont) {
|
|
||||||
return cont.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns an iterator past the last element of the given container.
|
|
||||||
* @param cont The container for which to return the iterator.
|
|
||||||
* @return An iterator past the last element of the given container.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static typename Container::iterator end(Container &cont) {
|
|
||||||
return cont.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns an iterator past the last element of the given container.
|
|
||||||
* @param cont The container for which to return the iterator.
|
|
||||||
* @return An iterator past the last element of the given container.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static typename Container::const_iterator cend(const Container &cont) {
|
|
||||||
return cont.end();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Basic STL-compatible associative container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct basic_associative_container {
|
|
||||||
/**
|
|
||||||
* @brief Returns an iterator to the element with key equivalent to the
|
|
||||||
* given one, if any.
|
|
||||||
* @param cont The container in which to search for the element.
|
|
||||||
* @param key The key of the element to search.
|
|
||||||
* @return An iterator to the element with the given key, if any.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static typename Container::iterator find(Container &cont, const typename Container::key_type &key) {
|
|
||||||
return cont.find(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc find */
|
|
||||||
[[nodiscard]] static typename Container::const_iterator cfind(const Container &cont, const typename Container::key_type &key) {
|
|
||||||
return cont.find(key);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Basic STL-compatible dynamic container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct basic_dynamic_container {
|
|
||||||
/**
|
|
||||||
* @brief Clears the content of the given container.
|
|
||||||
* @param cont The container for which to clear the content.
|
|
||||||
* @return True in case of success, false otherwise.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static bool clear([[maybe_unused]] Container &cont) {
|
|
||||||
return cont.clear(), true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Basic STL-compatible dynamic associative container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct basic_dynamic_associative_container {
|
|
||||||
/**
|
|
||||||
* @brief Removes the specified element from the given container.
|
|
||||||
* @param cont The container from which to remove the element.
|
|
||||||
* @param key The element to remove.
|
|
||||||
* @return A bool denoting whether the removal took place.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static bool erase([[maybe_unused]] Container &cont, [[maybe_unused]] const typename Container::key_type &key) {
|
|
||||||
const auto sz = cont.size();
|
|
||||||
return cont.erase(key) != sz;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Basic STL-compatible sequence container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct basic_sequence_container {
|
|
||||||
/**
|
|
||||||
* @brief Returns a reference to the element at the specified location of
|
|
||||||
* the given container (no bounds checking is performed).
|
|
||||||
* @param cont The container from which to get the element.
|
|
||||||
* @param pos The position of the element to return.
|
|
||||||
* @return A reference to the requested element.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static typename Container::reference get(Container &cont, typename Container::size_type pos) {
|
|
||||||
return cont[pos];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc get */
|
|
||||||
[[nodiscard]] static typename Container::const_reference cget(const Container &cont, typename Container::size_type pos) {
|
|
||||||
return cont[pos];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief STL-compatible dynamic associative key-only container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct dynamic_associative_key_only_container {
|
|
||||||
/**
|
|
||||||
* @brief Inserts an element into the given container.
|
|
||||||
* @param cont The container in which to insert the element.
|
|
||||||
* @param key The element to insert.
|
|
||||||
* @return A bool denoting whether the insertion took place.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static bool insert([[maybe_unused]] Container &cont, [[maybe_unused]] const typename Container::key_type &key) {
|
|
||||||
return cont.insert(key).second;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief STL-compatible dynamic key-value associative container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct dynamic_associative_key_value_container {
|
|
||||||
/**
|
|
||||||
* @brief Inserts an element (a key/value pair) into the given container.
|
|
||||||
* @param cont The container in which to insert the element.
|
|
||||||
* @param key The key of the element to insert.
|
|
||||||
* @param value The value of the element to insert.
|
|
||||||
* @return A bool denoting whether the insertion took place.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static bool insert([[maybe_unused]] Container &cont, [[maybe_unused]] const typename Container::key_type &key, [[maybe_unused]] const typename Container::mapped_type &value) {
|
|
||||||
return cont.insert(std::make_pair(key, value)).second;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief STL-compatible dynamic sequence container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct dynamic_sequence_container {
|
|
||||||
/**
|
|
||||||
* @brief Resizes the given container to contain the given number of
|
|
||||||
* elements.
|
|
||||||
* @param cont The container to resize.
|
|
||||||
* @param sz The new size of the container.
|
|
||||||
* @return True in case of success, false otherwise.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static bool resize([[maybe_unused]] Container &cont, [[maybe_unused]] typename Container::size_type sz) {
|
|
||||||
return cont.resize(sz), true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Inserts an element at the specified location of the given
|
|
||||||
* container.
|
|
||||||
* @param cont The container into which to insert the element.
|
|
||||||
* @param it Iterator before which the element will be inserted.
|
|
||||||
* @param value Element value to insert.
|
|
||||||
* @return A pair consisting of an iterator to the inserted element (in case
|
|
||||||
* of success) and a bool denoting whether the insertion took place.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static std::pair<typename Container::iterator, bool> insert([[maybe_unused]] Container &cont, [[maybe_unused]] typename Container::const_iterator it, [[maybe_unused]] const typename Container::value_type &value) {
|
|
||||||
return { cont.insert(it, value), true };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Removes the element at the specified location from the given
|
|
||||||
* container.
|
|
||||||
* @param cont The container from which to remove the element.
|
|
||||||
* @param it Iterator to the element to remove.
|
|
||||||
* @return A pair consisting of an iterator following the last removed
|
|
||||||
* element (in case of success) and a bool denoting whether the insertion
|
|
||||||
* took place.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static std::pair<typename Container::iterator, bool> erase([[maybe_unused]] Container &cont, [[maybe_unused]] typename Container::const_iterator it) {
|
|
||||||
return { cont.erase(it), true };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief STL-compatible fixed sequence container traits
|
|
||||||
* @tparam Container The type of the container.
|
|
||||||
*/
|
|
||||||
template<typename Container>
|
|
||||||
struct fixed_sequence_container {
|
|
||||||
/**
|
|
||||||
* @brief Does nothing.
|
|
||||||
* @return False to indicate failure in all cases.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] static bool resize(const Container &, typename Container::size_type) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
[[nodiscard]] static iterator iter(any &container, const bool as_end) {
|
||||||
* @brief Does nothing.
|
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||||
* @return False to indicate failure in all cases.
|
return iterator{*cont, static_cast<typename iterator::difference_type>(as_end * cont->size())};
|
||||||
*/
|
}
|
||||||
[[nodiscard]] static bool clear(const Container &) {
|
|
||||||
return false;
|
const Type &as_const = any_cast<const Type &>(container);
|
||||||
|
return iterator{as_const, static_cast<typename iterator::difference_type>(as_end * as_const.size())};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
[[nodiscard]] static iterator insert([[maybe_unused]] any &container, [[maybe_unused]] const std::ptrdiff_t offset, [[maybe_unused]] meta_any &value) {
|
||||||
* @brief Does nothing.
|
if constexpr(is_dynamic_sequence_container<Type>::value) {
|
||||||
* @return A pair consisting of an invalid iterator and a false value to
|
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||||
* indicate failure in all cases.
|
// this abomination is necessary because only on macos value_type and const_reference are different types for std::vector<bool>
|
||||||
*/
|
if(value.allow_cast<typename Type::const_reference>() || value.allow_cast<typename Type::value_type>()) {
|
||||||
[[nodiscard]] static std::pair<typename Container::iterator, bool> insert(const Container &, typename Container::const_iterator, const typename Container::value_type &) {
|
const auto *element = value.try_cast<std::remove_reference_t<typename Type::const_reference>>();
|
||||||
return { {}, false };
|
const auto curr = cont->insert(cont->begin() + offset, element ? *element : value.cast<typename Type::value_type>());
|
||||||
|
return iterator{*cont, curr - cont->begin()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
[[nodiscard]] static iterator erase([[maybe_unused]] any &container, [[maybe_unused]] const std::ptrdiff_t offset) {
|
||||||
* @brief Does nothing.
|
if constexpr(is_dynamic_sequence_container<Type>::value) {
|
||||||
* @return A pair consisting of an invalid iterator and a false value to
|
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||||
* indicate failure in all cases.
|
const auto curr = cont->erase(cont->begin() + offset);
|
||||||
*/
|
return iterator{*cont, curr - cont->begin()};
|
||||||
[[nodiscard]] static std::pair<typename Container::iterator, bool> erase(const Container &, typename Container::const_iterator) {
|
}
|
||||||
return { {}, false };
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
struct basic_meta_associative_container_traits {
|
||||||
|
using iterator = meta_associative_container::iterator;
|
||||||
|
using size_type = std::size_t;
|
||||||
|
|
||||||
|
static constexpr auto key_only = is_key_only_meta_associative_container<Type>::value;
|
||||||
|
|
||||||
|
[[nodiscard]] static size_type size(const any &container) ENTT_NOEXCEPT {
|
||||||
|
return any_cast<const Type &>(container).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static bool clear(any &container) {
|
||||||
|
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||||
|
cont->clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static iterator iter(any &container, const bool as_end) {
|
||||||
|
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||||
|
return iterator{std::integral_constant<bool, key_only>{}, as_end ? cont->end() : cont->begin()};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &as_const = any_cast<const Type &>(container);
|
||||||
|
return iterator{std::integral_constant<bool, key_only>{}, as_end ? as_const.end() : as_const.begin()};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static bool insert(any &container, meta_any &key, [[maybe_unused]] meta_any &value) {
|
||||||
|
auto *const cont = any_cast<Type>(&container);
|
||||||
|
|
||||||
|
if constexpr(is_key_only_meta_associative_container<Type>::value) {
|
||||||
|
return cont && key.allow_cast<const typename Type::key_type &>()
|
||||||
|
&& cont->insert(key.cast<const typename Type::key_type &>()).second;
|
||||||
|
} else {
|
||||||
|
return cont && key.allow_cast<const typename Type::key_type &>() && value.allow_cast<const typename Type::mapped_type &>()
|
||||||
|
&& cont->emplace(key.cast<const typename Type::key_type &>(), value.cast<const typename Type::mapped_type &>()).second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static bool erase(any &container, meta_any &key) {
|
||||||
|
auto *const cont = any_cast<Type>(&container);
|
||||||
|
return cont && key.allow_cast<const typename Type::key_type &>()
|
||||||
|
&& (cont->erase(key.cast<const typename Type::key_type &>()) != cont->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static iterator find(any &container, meta_any &key) {
|
||||||
|
if(key.allow_cast<const typename Type::key_type &>()) {
|
||||||
|
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||||
|
return iterator{std::integral_constant<bool, key_only>{}, cont->find(key.cast<const typename Type::key_type &>())};
|
||||||
|
}
|
||||||
|
|
||||||
|
return iterator{std::integral_constant<bool, key_only>{}, any_cast<const Type &>(container).find(key.cast<const typename Type::key_type &>())};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta sequence container traits for `std::vector`s of any type.
|
* @brief Meta sequence container traits for `std::vector`s of any type.
|
||||||
@@ -298,15 +164,7 @@ struct fixed_sequence_container {
|
|||||||
*/
|
*/
|
||||||
template<typename Type, typename... Args>
|
template<typename Type, typename... Args>
|
||||||
struct meta_sequence_container_traits<std::vector<Type, Args...>>
|
struct meta_sequence_container_traits<std::vector<Type, Args...>>
|
||||||
: meta_container_traits<
|
: internal::basic_meta_sequence_container_traits<std::vector<Type, Args...>> {};
|
||||||
std::vector<Type, Args...>,
|
|
||||||
basic_container,
|
|
||||||
basic_dynamic_container,
|
|
||||||
basic_sequence_container,
|
|
||||||
dynamic_sequence_container
|
|
||||||
>
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta sequence container traits for `std::array`s of any type.
|
* @brief Meta sequence container traits for `std::array`s of any type.
|
||||||
@@ -315,14 +173,7 @@ struct meta_sequence_container_traits<std::vector<Type, Args...>>
|
|||||||
*/
|
*/
|
||||||
template<typename Type, auto N>
|
template<typename Type, auto N>
|
||||||
struct meta_sequence_container_traits<std::array<Type, N>>
|
struct meta_sequence_container_traits<std::array<Type, N>>
|
||||||
: meta_container_traits<
|
: internal::basic_meta_sequence_container_traits<std::array<Type, N>> {};
|
||||||
std::array<Type, N>,
|
|
||||||
basic_container,
|
|
||||||
basic_sequence_container,
|
|
||||||
fixed_sequence_container
|
|
||||||
>
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta associative container traits for `std::map`s of any type.
|
* @brief Meta associative container traits for `std::map`s of any type.
|
||||||
@@ -332,16 +183,7 @@ struct meta_sequence_container_traits<std::array<Type, N>>
|
|||||||
*/
|
*/
|
||||||
template<typename Key, typename Value, typename... Args>
|
template<typename Key, typename Value, typename... Args>
|
||||||
struct meta_associative_container_traits<std::map<Key, Value, Args...>>
|
struct meta_associative_container_traits<std::map<Key, Value, Args...>>
|
||||||
: meta_container_traits<
|
: internal::basic_meta_associative_container_traits<std::map<Key, Value, Args...>> {};
|
||||||
std::map<Key, Value, Args...>,
|
|
||||||
basic_container,
|
|
||||||
basic_associative_container,
|
|
||||||
basic_dynamic_container,
|
|
||||||
basic_dynamic_associative_container,
|
|
||||||
dynamic_associative_key_value_container
|
|
||||||
>
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta associative container traits for `std::unordered_map`s of any
|
* @brief Meta associative container traits for `std::unordered_map`s of any
|
||||||
@@ -352,16 +194,7 @@ struct meta_associative_container_traits<std::map<Key, Value, Args...>>
|
|||||||
*/
|
*/
|
||||||
template<typename Key, typename Value, typename... Args>
|
template<typename Key, typename Value, typename... Args>
|
||||||
struct meta_associative_container_traits<std::unordered_map<Key, Value, Args...>>
|
struct meta_associative_container_traits<std::unordered_map<Key, Value, Args...>>
|
||||||
: meta_container_traits<
|
: internal::basic_meta_associative_container_traits<std::unordered_map<Key, Value, Args...>> {};
|
||||||
std::unordered_map<Key, Value, Args...>,
|
|
||||||
basic_container,
|
|
||||||
basic_associative_container,
|
|
||||||
basic_dynamic_container,
|
|
||||||
basic_dynamic_associative_container,
|
|
||||||
dynamic_associative_key_value_container
|
|
||||||
>
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta associative container traits for `std::set`s of any type.
|
* @brief Meta associative container traits for `std::set`s of any type.
|
||||||
@@ -370,16 +203,7 @@ struct meta_associative_container_traits<std::unordered_map<Key, Value, Args...>
|
|||||||
*/
|
*/
|
||||||
template<typename Key, typename... Args>
|
template<typename Key, typename... Args>
|
||||||
struct meta_associative_container_traits<std::set<Key, Args...>>
|
struct meta_associative_container_traits<std::set<Key, Args...>>
|
||||||
: meta_container_traits<
|
: internal::basic_meta_associative_container_traits<std::set<Key, Args...>> {};
|
||||||
std::set<Key, Args...>,
|
|
||||||
basic_container,
|
|
||||||
basic_associative_container,
|
|
||||||
basic_dynamic_container,
|
|
||||||
basic_dynamic_associative_container,
|
|
||||||
dynamic_associative_key_only_container
|
|
||||||
>
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta associative container traits for `std::unordered_set`s of any
|
* @brief Meta associative container traits for `std::unordered_set`s of any
|
||||||
@@ -389,18 +213,27 @@ struct meta_associative_container_traits<std::set<Key, Args...>>
|
|||||||
*/
|
*/
|
||||||
template<typename Key, typename... Args>
|
template<typename Key, typename... Args>
|
||||||
struct meta_associative_container_traits<std::unordered_set<Key, Args...>>
|
struct meta_associative_container_traits<std::unordered_set<Key, Args...>>
|
||||||
: meta_container_traits<
|
: internal::basic_meta_associative_container_traits<std::unordered_set<Key, Args...>> {};
|
||||||
std::unordered_set<Key, Args...>,
|
|
||||||
basic_container,
|
|
||||||
basic_associative_container,
|
|
||||||
basic_dynamic_container,
|
|
||||||
basic_dynamic_associative_container,
|
|
||||||
dynamic_associative_key_only_container
|
|
||||||
>
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Meta associative container traits for `dense_map`s of any type.
|
||||||
|
* @tparam Key The key type of the elements.
|
||||||
|
* @tparam Type The value type of the elements.
|
||||||
|
* @tparam Args Other arguments.
|
||||||
|
*/
|
||||||
|
template<typename Key, typename Type, typename... Args>
|
||||||
|
struct meta_associative_container_traits<dense_map<Key, Type, Args...>>
|
||||||
|
: internal::basic_meta_associative_container_traits<dense_map<Key, Type, Args...>> {};
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @brief Meta associative container traits for `dense_set`s of any type.
|
||||||
|
* @tparam Type The value type of the elements.
|
||||||
|
* @tparam Args Other arguments.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename... Args>
|
||||||
|
struct meta_associative_container_traits<dense_set<Type, Args...>>
|
||||||
|
: internal::basic_meta_associative_container_traits<dense_set<Type, Args...>> {};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,52 +1,43 @@
|
|||||||
#ifndef ENTT_META_CTX_HPP
|
#ifndef ENTT_META_CTX_HPP
|
||||||
#define ENTT_META_CTX_HPP
|
#define ENTT_META_CTX_HPP
|
||||||
|
|
||||||
|
|
||||||
#include "../core/attribute.h"
|
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
#include "../core/attribute.h"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @cond TURN_OFF_DOXYGEN
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
||||||
struct meta_type_node;
|
struct meta_type_node;
|
||||||
|
|
||||||
|
|
||||||
struct ENTT_API meta_context {
|
struct ENTT_API meta_context {
|
||||||
// we could use the lines below but VS2017 returns with an ICE if combined with ENTT_API despite the code being valid C++
|
// we could use the lines below but VS2017 returns with an ICE if combined with ENTT_API despite the code being valid C++
|
||||||
// inline static meta_type_node *local = nullptr;
|
// inline static meta_type_node *local = nullptr;
|
||||||
// inline static meta_type_node **global = &local;
|
// inline static meta_type_node **global = &local;
|
||||||
|
|
||||||
[[nodiscard]] static meta_type_node * & local() ENTT_NOEXCEPT {
|
[[nodiscard]] static meta_type_node *&local() ENTT_NOEXCEPT {
|
||||||
static meta_type_node *chain = nullptr;
|
static meta_type_node *chain = nullptr;
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static meta_type_node ** & global() ENTT_NOEXCEPT {
|
[[nodiscard]] static meta_type_node **&global() ENTT_NOEXCEPT {
|
||||||
static meta_type_node **chain = &local();
|
static meta_type_node **chain = &local();
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Opaque container for a meta context. */
|
/*! @brief Opaque container for a meta context. */
|
||||||
struct meta_ctx {
|
struct meta_ctx {
|
||||||
/**
|
/**
|
||||||
@@ -61,8 +52,6 @@ private:
|
|||||||
internal::meta_type_node **ctx{&internal::meta_context::local()};
|
internal::meta_type_node **ctx{&internal::meta_context::local()};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#ifndef ENTT_META_FACTORY_HPP
|
#ifndef ENTT_META_FACTORY_HPP
|
||||||
#define ENTT_META_FACTORY_HPP
|
#define ENTT_META_FACTORY_HPP
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <functional>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -13,46 +14,11 @@
|
|||||||
#include "meta.hpp"
|
#include "meta.hpp"
|
||||||
#include "node.hpp"
|
#include "node.hpp"
|
||||||
#include "policy.hpp"
|
#include "policy.hpp"
|
||||||
|
#include "range.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @cond TURN_OFF_DOXYGEN
|
|
||||||
* Internal details not to be documented.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Node>
|
|
||||||
[[nodiscard]] bool find_if(const Node *candidate, const Node *node) ENTT_NOEXCEPT {
|
|
||||||
return node && (node == candidate || find_if(candidate, node->next));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Id, typename Node>
|
|
||||||
[[nodiscard]] bool find_if_not(const Id id, Node *node, const Node *owner) ENTT_NOEXCEPT {
|
|
||||||
if constexpr(std::is_pointer_v<Id>) {
|
|
||||||
return node && ((*node->id == *id && node != owner) || find_if_not(id, node->next, owner));
|
|
||||||
} else {
|
|
||||||
return node && ((node->id == id && node != owner) || find_if_not(id, node->next, owner));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal details not to be documented.
|
|
||||||
* @endcond
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta factory to be used for reflection purposes.
|
* @brief Meta factory to be used for reflection purposes.
|
||||||
*
|
*
|
||||||
@@ -62,8 +28,7 @@ template<typename Id, typename Node>
|
|||||||
* there are no subtle errors at runtime.
|
* there are no subtle errors at runtime.
|
||||||
*/
|
*/
|
||||||
template<typename...>
|
template<typename...>
|
||||||
struct meta_factory;
|
class meta_factory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Extended meta factory to be used for reflection purposes.
|
* @brief Extended meta factory to be used for reflection purposes.
|
||||||
@@ -71,58 +36,51 @@ struct meta_factory;
|
|||||||
* @tparam Spec Property specialization pack used to disambiguate overloads.
|
* @tparam Spec Property specialization pack used to disambiguate overloads.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename... Spec>
|
template<typename Type, typename... Spec>
|
||||||
struct meta_factory<Type, Spec...>: public meta_factory<Type> {
|
class meta_factory<Type, Spec...>: public meta_factory<Type> {
|
||||||
private:
|
void link_prop_if_required(internal::meta_prop_node &node) ENTT_NOEXCEPT {
|
||||||
template<std::size_t Step = 0, std::size_t... Index, typename... Property, typename... Other>
|
if(meta_range<internal::meta_prop_node *, internal::meta_prop_node> range{*ref}; std::find(range.cbegin(), range.cend(), &node) == range.cend()) {
|
||||||
void unpack(std::index_sequence<Index...>, std::tuple<Property...> property, Other &&... other) {
|
ENTT_ASSERT(std::find_if(range.cbegin(), range.cend(), [&node](const auto *curr) { return curr->id == node.id; }) == range.cend(), "Duplicate identifier");
|
||||||
unroll<Step>(choice<3>, std::move(std::get<Index>(property))..., std::forward<Other>(other)...);
|
node.next = *ref;
|
||||||
|
*ref = &node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t Step = 0, typename... Property, typename... Other>
|
template<std::size_t Step = 0, typename... Property, typename... Other>
|
||||||
void unroll(choice_t<3>, std::tuple<Property...> property, Other &&... other) {
|
void unroll(choice_t<2>, std::tuple<Property...> property, Other &&...other) ENTT_NOEXCEPT {
|
||||||
unpack<Step>(std::index_sequence_for<Property...>{}, std::move(property), std::forward<Other>(other)...);
|
std::apply([this](auto &&...curr) { (this->unroll<Step>(choice<2>, std::forward<Property>(curr)...)); }, property);
|
||||||
|
unroll<Step + sizeof...(Property)>(choice<2>, std::forward<Other>(other)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t Step = 0, typename... Property, typename... Other>
|
template<std::size_t Step = 0, typename... Property, typename... Other>
|
||||||
void unroll(choice_t<2>, std::pair<Property...> property, Other &&... other) {
|
void unroll(choice_t<1>, std::pair<Property...> property, Other &&...other) ENTT_NOEXCEPT {
|
||||||
assign<Step>(std::move(property.first), std::move(property.second));
|
assign<Step>(std::move(property.first), std::move(property.second));
|
||||||
unroll<Step+1>(choice<3>, std::forward<Other>(other)...);
|
unroll<Step + 1>(choice<2>, std::forward<Other>(other)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t Step = 0, typename Property, typename... Other>
|
template<std::size_t Step = 0, typename Property, typename... Other>
|
||||||
std::enable_if_t<!std::is_invocable_v<Property>>
|
void unroll(choice_t<0>, Property &&property, Other &&...other) ENTT_NOEXCEPT {
|
||||||
unroll(choice_t<1>, Property &&property, Other &&... other) {
|
|
||||||
assign<Step>(std::forward<Property>(property));
|
assign<Step>(std::forward<Property>(property));
|
||||||
unroll<Step+1>(choice<3>, std::forward<Other>(other)...);
|
unroll<Step + 1>(choice<2>, std::forward<Other>(other)...);
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t Step = 0, typename Func, typename... Other>
|
|
||||||
void unroll(choice_t<0>, Func &&invocable, Other &&... other) {
|
|
||||||
unroll<Step>(choice<3>, std::forward<Func>(invocable)(), std::forward<Other>(other)...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t>
|
template<std::size_t>
|
||||||
void unroll(choice_t<0>) {}
|
void unroll(choice_t<0>) ENTT_NOEXCEPT {}
|
||||||
|
|
||||||
template<std::size_t = 0, typename Key>
|
template<std::size_t = 0>
|
||||||
void assign(Key &&key, meta_any value = {}) {
|
void assign(meta_any key, meta_any value = {}) {
|
||||||
static meta_any property[2u]{};
|
static meta_any property[2u]{};
|
||||||
|
|
||||||
static internal::meta_prop_node node{
|
static internal::meta_prop_node node{
|
||||||
nullptr,
|
nullptr,
|
||||||
property[0u],
|
property[0u],
|
||||||
property[1u]
|
property[1u]
|
||||||
|
// tricks clang-format
|
||||||
};
|
};
|
||||||
|
|
||||||
entt::meta_any instance{std::forward<Key>(key)};
|
property[0u] = std::move(key);
|
||||||
ENTT_ASSERT(!internal::find_if_not(&instance, *curr, &node), "Duplicate key");
|
|
||||||
property[0u] = std::move(instance);
|
|
||||||
property[1u] = std::move(value);
|
property[1u] = std::move(value);
|
||||||
|
|
||||||
if(!internal::find_if(&node, *curr)) {
|
link_prop_if_required(node);
|
||||||
node.next = *curr;
|
|
||||||
*curr = &node;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -131,8 +89,7 @@ public:
|
|||||||
* @param target The underlying node to which to assign the properties.
|
* @param target The underlying node to which to assign the properties.
|
||||||
*/
|
*/
|
||||||
meta_factory(internal::meta_prop_node **target) ENTT_NOEXCEPT
|
meta_factory(internal::meta_prop_node **target) ENTT_NOEXCEPT
|
||||||
: curr{target}
|
: ref{target} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Assigns a property to the last meta object created.
|
* @brief Assigns a property to the last meta object created.
|
||||||
@@ -146,60 +103,127 @@ public:
|
|||||||
* @return A meta factory for the parent type.
|
* @return A meta factory for the parent type.
|
||||||
*/
|
*/
|
||||||
template<typename PropertyOrKey, typename... Value>
|
template<typename PropertyOrKey, typename... Value>
|
||||||
auto prop(PropertyOrKey &&property_or_key, Value &&... value) && {
|
meta_factory<Type> prop(PropertyOrKey &&property_or_key, Value &&...value) {
|
||||||
if constexpr(sizeof...(Value) == 0) {
|
if constexpr(sizeof...(Value) == 0) {
|
||||||
unroll(choice<3>, std::forward<PropertyOrKey>(property_or_key));
|
unroll(choice<2>, std::forward<PropertyOrKey>(property_or_key));
|
||||||
} else {
|
} else {
|
||||||
assign(std::forward<PropertyOrKey>(property_or_key), std::forward<Value>(value)...);
|
assign(std::forward<PropertyOrKey>(property_or_key), std::forward<Value>(value)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta_factory<Type, Spec..., PropertyOrKey, Value...>{curr};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Assigns properties to the last meta object created.
|
* @brief Assigns properties to the last meta object created.
|
||||||
*
|
*
|
||||||
* Both the keys and the values (if any) must be at least copy
|
* Both key and value (if any) must be at least copy constructible.
|
||||||
* constructible.
|
|
||||||
*
|
*
|
||||||
* @tparam Property Types of the properties.
|
* @tparam Property Types of the properties.
|
||||||
* @param property Properties to assign to the last meta object created.
|
* @param property Properties to assign to the last meta object created.
|
||||||
* @return A meta factory for the parent type.
|
* @return A meta factory for the parent type.
|
||||||
*/
|
*/
|
||||||
template <typename... Property>
|
template<typename... Property>
|
||||||
auto props(Property... property) && {
|
meta_factory<Type> props(Property... property) {
|
||||||
unroll(choice<3>, std::forward<Property>(property)...);
|
unroll(choice<2>, std::forward<Property>(property)...);
|
||||||
return meta_factory<Type, Spec..., Property...>{curr};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
internal::meta_prop_node **curr;
|
internal::meta_prop_node **ref;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Basic meta factory to be used for reflection purposes.
|
* @brief Basic meta factory to be used for reflection purposes.
|
||||||
* @tparam Type Reflected type for which the factory was created.
|
* @tparam Type Reflected type for which the factory was created.
|
||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct meta_factory<Type> {
|
class meta_factory<Type> {
|
||||||
|
void link_base_if_required(internal::meta_base_node &node) ENTT_NOEXCEPT {
|
||||||
|
if(meta_range<internal::meta_base_node *, internal::meta_base_node> range{owner->base}; std::find(range.cbegin(), range.cend(), &node) == range.cend()) {
|
||||||
|
node.next = owner->base;
|
||||||
|
owner->base = &node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void link_conv_if_required(internal::meta_conv_node &node) ENTT_NOEXCEPT {
|
||||||
|
if(meta_range<internal::meta_conv_node *, internal::meta_conv_node> range{owner->conv}; std::find(range.cbegin(), range.cend(), &node) == range.cend()) {
|
||||||
|
node.next = owner->conv;
|
||||||
|
owner->conv = &node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void link_ctor_if_required(internal::meta_ctor_node &node) ENTT_NOEXCEPT {
|
||||||
|
if(meta_range<internal::meta_ctor_node *, internal::meta_ctor_node> range{owner->ctor}; std::find(range.cbegin(), range.cend(), &node) == range.cend()) {
|
||||||
|
node.next = owner->ctor;
|
||||||
|
owner->ctor = &node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void link_data_if_required(const id_type id, internal::meta_data_node &node) ENTT_NOEXCEPT {
|
||||||
|
meta_range<internal::meta_data_node *, internal::meta_data_node> range{owner->data};
|
||||||
|
ENTT_ASSERT(std::find_if(range.cbegin(), range.cend(), [id, &node](const auto *curr) { return curr != &node && curr->id == id; }) == range.cend(), "Duplicate identifier");
|
||||||
|
node.id = id;
|
||||||
|
|
||||||
|
if(std::find(range.cbegin(), range.cend(), &node) == range.cend()) {
|
||||||
|
node.next = owner->data;
|
||||||
|
owner->data = &node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void link_func_if_required(const id_type id, internal::meta_func_node &node) ENTT_NOEXCEPT {
|
||||||
|
node.id = id;
|
||||||
|
|
||||||
|
if(meta_range<internal::meta_func_node *, internal::meta_func_node> range{owner->func}; std::find(range.cbegin(), range.cend(), &node) == range.cend()) {
|
||||||
|
node.next = owner->func;
|
||||||
|
owner->func = &node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Setter, auto Getter, typename Policy, std::size_t... Index>
|
||||||
|
auto data(const id_type id, std::index_sequence<Index...>) ENTT_NOEXCEPT {
|
||||||
|
using data_type = std::invoke_result_t<decltype(Getter), Type &>;
|
||||||
|
using args_type = type_list<typename meta_function_helper_t<Type, decltype(value_list_element_v<Index, Setter>)>::args_type...>;
|
||||||
|
static_assert(Policy::template value<data_type>, "Invalid return type for the given policy");
|
||||||
|
|
||||||
|
static internal::meta_data_node node{
|
||||||
|
{},
|
||||||
|
/* this is never static */
|
||||||
|
(std::is_member_object_pointer_v<decltype(value_list_element_v<Index, Setter>)> && ... && std::is_const_v<std::remove_reference_t<data_type>>) ? internal::meta_traits::is_const : internal::meta_traits::is_none,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
Setter::size,
|
||||||
|
internal::meta_node<std::remove_cv_t<std::remove_reference_t<data_type>>>::resolve(),
|
||||||
|
&meta_arg<type_list<type_list_element_t<type_list_element_t<Index, args_type>::size != 1u, type_list_element_t<Index, args_type>>...>>,
|
||||||
|
[](meta_handle instance, meta_any value) -> bool { return (meta_setter<Type, value_list_element_v<Index, Setter>>(*instance.operator->(), value.as_ref()) || ...); },
|
||||||
|
&meta_getter<Type, Getter, Policy>
|
||||||
|
// tricks clang-format
|
||||||
|
};
|
||||||
|
|
||||||
|
link_data_if_required(id, node);
|
||||||
|
return meta_factory<Type, Setter, std::integral_constant<decltype(Getter), Getter>>{&node.prop};
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*! @brief Default constructor. */
|
||||||
|
meta_factory() ENTT_NOEXCEPT
|
||||||
|
: owner{internal::meta_node<Type>::resolve()} {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Makes a meta type _searchable_.
|
* @brief Makes a meta type _searchable_.
|
||||||
* @param id Optional unique identifier.
|
* @param id Optional unique identifier.
|
||||||
* @return An extended meta factory for the given type.
|
* @return An extended meta factory for the given type.
|
||||||
*/
|
*/
|
||||||
auto type(const id_type id = type_hash<Type>::value()) {
|
auto type(const id_type id = type_hash<Type>::value()) ENTT_NOEXCEPT {
|
||||||
auto * const node = internal::meta_info<Type>::resolve();
|
meta_range<internal::meta_type_node *, internal::meta_type_node> range{*internal::meta_context::global()};
|
||||||
|
ENTT_ASSERT(std::find_if(range.cbegin(), range.cend(), [id, this](const auto *curr) { return curr != owner && curr->id == id; }) == range.cend(), "Duplicate identifier");
|
||||||
|
owner->id = id;
|
||||||
|
|
||||||
ENTT_ASSERT(!internal::find_if_not(id, *internal::meta_context::global(), node), "Duplicate identifier");
|
if(std::find(range.cbegin(), range.cend(), owner) == range.cend()) {
|
||||||
node->id = id;
|
owner->next = *internal::meta_context::global();
|
||||||
|
*internal::meta_context::global() = owner;
|
||||||
if(!internal::find_if(node, *internal::meta_context::global())) {
|
|
||||||
node->next = *internal::meta_context::global();
|
|
||||||
*internal::meta_context::global() = node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta_factory<Type, Type>{&node->prop};
|
return meta_factory<Type, Type>{&owner->prop};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,23 +236,22 @@ struct meta_factory<Type> {
|
|||||||
*/
|
*/
|
||||||
template<typename Base>
|
template<typename Base>
|
||||||
auto base() ENTT_NOEXCEPT {
|
auto base() ENTT_NOEXCEPT {
|
||||||
static_assert(std::is_base_of_v<Base, Type>, "Invalid base type");
|
static_assert(!std::is_same_v<Type, Base> && std::is_base_of_v<Base, Type>, "Invalid base type");
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
|
||||||
|
|
||||||
static internal::meta_base_node node{
|
static internal::meta_base_node node{
|
||||||
type,
|
|
||||||
nullptr,
|
nullptr,
|
||||||
&internal::meta_info<Base>::resolve,
|
internal::meta_node<Base>::resolve(),
|
||||||
[](const void *instance) ENTT_NOEXCEPT -> const void * {
|
[](meta_any other) ENTT_NOEXCEPT -> meta_any {
|
||||||
return static_cast<const Base *>(static_cast<const Type *>(instance));
|
if(auto *ptr = other.data(); ptr) {
|
||||||
|
return forward_as_meta(*static_cast<Base *>(static_cast<Type *>(ptr)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return forward_as_meta(*static_cast<const Base *>(static_cast<const Type *>(std::as_const(other).data())));
|
||||||
}
|
}
|
||||||
|
// tricks clang-format
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->base)) {
|
link_base_if_required(node);
|
||||||
node.next = type->base;
|
|
||||||
type->base = &node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return meta_factory<Type>{};
|
return meta_factory<Type>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,47 +268,17 @@ struct meta_factory<Type> {
|
|||||||
* @return A meta factory for the parent type.
|
* @return A meta factory for the parent type.
|
||||||
*/
|
*/
|
||||||
template<auto Candidate>
|
template<auto Candidate>
|
||||||
std::enable_if_t<std::is_member_function_pointer_v<decltype(Candidate)>, meta_factory<Type>> conv() ENTT_NOEXCEPT {
|
auto conv() ENTT_NOEXCEPT {
|
||||||
using conv_type = std::invoke_result_t<decltype(Candidate), Type &>;
|
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
|
||||||
|
|
||||||
static internal::meta_conv_node node{
|
static internal::meta_conv_node node{
|
||||||
type,
|
|
||||||
nullptr,
|
nullptr,
|
||||||
&internal::meta_info<conv_type>::resolve,
|
internal::meta_node<std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<decltype(Candidate), Type &>>>>::resolve(),
|
||||||
[](const void *instance) -> meta_any {
|
[](const meta_any &instance) -> meta_any {
|
||||||
return (static_cast<const Type *>(instance)->*Candidate)();
|
return forward_as_meta(std::invoke(Candidate, *static_cast<const Type *>(instance.data())));
|
||||||
}
|
}
|
||||||
|
// tricks clang-format
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->conv)) {
|
link_conv_if_required(node);
|
||||||
node.next = type->conv;
|
|
||||||
type->conv = &node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return meta_factory<Type>{};
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc conv */
|
|
||||||
template<auto Candidate>
|
|
||||||
std::enable_if_t<!std::is_member_function_pointer_v<decltype(Candidate)>, meta_factory<Type>> conv() ENTT_NOEXCEPT {
|
|
||||||
using conv_type = std::invoke_result_t<decltype(Candidate), Type &>;
|
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
|
||||||
|
|
||||||
static internal::meta_conv_node node{
|
|
||||||
type,
|
|
||||||
nullptr,
|
|
||||||
&internal::meta_info<conv_type>::resolve,
|
|
||||||
[](const void *instance) -> meta_any {
|
|
||||||
return Candidate(*static_cast<const Type *>(instance));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->conv)) {
|
|
||||||
node.next = type->conv;
|
|
||||||
type->conv = &node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return meta_factory<Type>{};
|
return meta_factory<Type>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,23 +293,14 @@ struct meta_factory<Type> {
|
|||||||
*/
|
*/
|
||||||
template<typename To>
|
template<typename To>
|
||||||
auto conv() ENTT_NOEXCEPT {
|
auto conv() ENTT_NOEXCEPT {
|
||||||
static_assert(std::is_convertible_v<Type, To>, "Could not convert to the required type");
|
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
|
||||||
|
|
||||||
static internal::meta_conv_node node{
|
static internal::meta_conv_node node{
|
||||||
type,
|
|
||||||
nullptr,
|
nullptr,
|
||||||
&internal::meta_info<To>::resolve,
|
internal::meta_node<std::remove_cv_t<std::remove_reference_t<To>>>::resolve(),
|
||||||
[](const void *instance) -> meta_any {
|
[](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast<To>(*static_cast<const Type *>(instance.data()))); }
|
||||||
return static_cast<To>(*static_cast<const Type *>(instance));
|
// tricks clang-format
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->conv)) {
|
link_conv_if_required(node);
|
||||||
node.next = type->conv;
|
|
||||||
type->conv = &node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return meta_factory<Type>{};
|
return meta_factory<Type>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,28 +320,19 @@ struct meta_factory<Type> {
|
|||||||
template<auto Candidate, typename Policy = as_is_t>
|
template<auto Candidate, typename Policy = as_is_t>
|
||||||
auto ctor() ENTT_NOEXCEPT {
|
auto ctor() ENTT_NOEXCEPT {
|
||||||
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
|
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
|
||||||
static_assert(std::is_same_v<std::decay_t<typename descriptor::return_type>, Type>, "The function doesn't return an object of the required type");
|
static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
static_assert(std::is_same_v<std::remove_cv_t<std::remove_reference_t<typename descriptor::return_type>>, Type>, "The function doesn't return an object of the required type");
|
||||||
|
|
||||||
static internal::meta_ctor_node node{
|
static internal::meta_ctor_node node{
|
||||||
type,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
nullptr,
|
||||||
descriptor::args_type::size,
|
descriptor::args_type::size,
|
||||||
[](const typename internal::meta_ctor_node::size_type index) ENTT_NOEXCEPT {
|
&meta_arg<typename descriptor::args_type>,
|
||||||
return meta_arg(typename descriptor::args_type{}, index);
|
&meta_construct<Type, Candidate, Policy>
|
||||||
},
|
// tricks clang-format
|
||||||
[](meta_any * const args) {
|
|
||||||
return meta_invoke<Type, Candidate, Policy>({}, args, std::make_index_sequence<descriptor::args_type::size>{});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->ctor)) {
|
link_ctor_if_required(node);
|
||||||
node.next = type->ctor;
|
return meta_factory<Type>{};
|
||||||
type->ctor = &node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return meta_factory<Type, std::integral_constant<decltype(Candidate), Candidate>>{&node.prop};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -372,40 +347,32 @@ struct meta_factory<Type> {
|
|||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
auto ctor() ENTT_NOEXCEPT {
|
auto ctor() ENTT_NOEXCEPT {
|
||||||
using descriptor = meta_function_helper_t<Type, Type(*)(Args...)>;
|
using descriptor = meta_function_helper_t<Type, Type (*)(Args...)>;
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
|
||||||
|
|
||||||
static internal::meta_ctor_node node{
|
static internal::meta_ctor_node node{
|
||||||
type,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
nullptr,
|
||||||
descriptor::args_type::size,
|
descriptor::args_type::size,
|
||||||
[](const typename internal::meta_ctor_node::size_type index) ENTT_NOEXCEPT {
|
&meta_arg<typename descriptor::args_type>,
|
||||||
return meta_arg(typename descriptor::args_type{}, index);
|
&meta_construct<Type, Args...>
|
||||||
},
|
// tricks clang-format
|
||||||
[](meta_any * const args) {
|
|
||||||
return meta_construct<Type, Args...>(args, std::make_index_sequence<descriptor::args_type::size>{});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->ctor)) {
|
link_ctor_if_required(node);
|
||||||
node.next = type->ctor;
|
return meta_factory<Type>{};
|
||||||
type->ctor = &node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return meta_factory<Type, Type(Args...)>{&node.prop};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Assigns a meta destructor to a meta type.
|
* @brief Assigns a meta destructor to a meta type.
|
||||||
*
|
*
|
||||||
* Free functions can be assigned to meta types in the role of destructors.
|
* Both free functions and member functions can be assigned to meta types in
|
||||||
* The signature of the function should identical to the following:
|
* the role of destructors.<br/>
|
||||||
|
* The signature of a free function should be identical to the following:
|
||||||
*
|
*
|
||||||
* @code{.cpp}
|
* @code{.cpp}
|
||||||
* void(Type &);
|
* void(Type &);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
|
* Member functions should not take arguments instead.<br/>
|
||||||
* The purpose is to give users the ability to free up resources that
|
* The purpose is to give users the ability to free up resources that
|
||||||
* require special treatment before an object is actually destroyed.
|
* require special treatment before an object is actually destroyed.
|
||||||
*
|
*
|
||||||
@@ -415,12 +382,7 @@ struct meta_factory<Type> {
|
|||||||
template<auto Func>
|
template<auto Func>
|
||||||
auto dtor() ENTT_NOEXCEPT {
|
auto dtor() ENTT_NOEXCEPT {
|
||||||
static_assert(std::is_invocable_v<decltype(Func), Type &>, "The function doesn't accept an object of the type provided");
|
static_assert(std::is_invocable_v<decltype(Func), Type &>, "The function doesn't accept an object of the type provided");
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
owner->dtor = [](void *instance) { std::invoke(Func, *static_cast<Type *>(instance)); };
|
||||||
|
|
||||||
type->dtor = [](void *instance) {
|
|
||||||
Func(*static_cast<Type *>(instance));
|
|
||||||
};
|
|
||||||
|
|
||||||
return meta_factory<Type>{};
|
return meta_factory<Type>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,31 +402,41 @@ struct meta_factory<Type> {
|
|||||||
template<auto Data, typename Policy = as_is_t>
|
template<auto Data, typename Policy = as_is_t>
|
||||||
auto data(const id_type id) ENTT_NOEXCEPT {
|
auto data(const id_type id) ENTT_NOEXCEPT {
|
||||||
if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
|
if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
|
||||||
return data<Data, Data, Policy>(id);
|
using data_type = std::remove_reference_t<std::invoke_result_t<decltype(Data), Type &>>;
|
||||||
} else {
|
|
||||||
using data_type = std::remove_pointer_t<decltype(Data)>;
|
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
|
||||||
|
|
||||||
static internal::meta_data_node node{
|
static internal::meta_data_node node{
|
||||||
{},
|
{},
|
||||||
type,
|
/* this is never static */
|
||||||
|
std::is_const_v<data_type> ? internal::meta_traits::is_const : internal::meta_traits::is_none,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
std::is_same_v<Type, data_type> || std::is_const_v<data_type>,
|
1u,
|
||||||
true,
|
internal::meta_node<std::remove_const_t<data_type>>::resolve(),
|
||||||
&internal::meta_info<data_type>::resolve,
|
&meta_arg<type_list<std::remove_const_t<data_type>>>,
|
||||||
&meta_setter<Type, Data>,
|
&meta_setter<Type, Data>,
|
||||||
&meta_getter<Type, Data, Policy>
|
&meta_getter<Type, Data, Policy>
|
||||||
|
// tricks clang-format
|
||||||
};
|
};
|
||||||
|
|
||||||
ENTT_ASSERT(!internal::find_if_not(id, type->data, &node), "Duplicate identifier");
|
link_data_if_required(id, node);
|
||||||
node.id = id;
|
return meta_factory<Type, std::integral_constant<decltype(Data), Data>, std::integral_constant<decltype(Data), Data>>{&node.prop};
|
||||||
|
} else {
|
||||||
|
using data_type = std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>;
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->data)) {
|
static internal::meta_data_node node{
|
||||||
node.next = type->data;
|
{},
|
||||||
type->data = &node;
|
((std::is_same_v<Type, std::remove_const_t<data_type>> || std::is_const_v<data_type>) ? internal::meta_traits::is_const : internal::meta_traits::is_none) | internal::meta_traits::is_static,
|
||||||
}
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
1u,
|
||||||
|
internal::meta_node<std::remove_const_t<data_type>>::resolve(),
|
||||||
|
&meta_arg<type_list<std::remove_const_t<data_type>>>,
|
||||||
|
&meta_setter<Type, Data>,
|
||||||
|
&meta_getter<Type, Data, Policy>
|
||||||
|
// tricks clang-format
|
||||||
|
};
|
||||||
|
|
||||||
|
link_data_if_required(id, node);
|
||||||
return meta_factory<Type, std::integral_constant<decltype(Data), Data>>{&node.prop};
|
return meta_factory<Type, std::integral_constant<decltype(Data), Data>>{&node.prop};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -491,34 +463,72 @@ struct meta_factory<Type> {
|
|||||||
*/
|
*/
|
||||||
template<auto Setter, auto Getter, typename Policy = as_is_t>
|
template<auto Setter, auto Getter, typename Policy = as_is_t>
|
||||||
auto data(const id_type id) ENTT_NOEXCEPT {
|
auto data(const id_type id) ENTT_NOEXCEPT {
|
||||||
using underlying_type = std::remove_reference_t<std::invoke_result_t<decltype(Getter), Type &>>;
|
using data_type = std::invoke_result_t<decltype(Getter), Type &>;
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
static_assert(Policy::template value<data_type>, "Invalid return type for the given policy");
|
||||||
|
|
||||||
static internal::meta_data_node node{
|
if constexpr(std::is_same_v<decltype(Setter), std::nullptr_t>) {
|
||||||
{},
|
static internal::meta_data_node node{
|
||||||
type,
|
{},
|
||||||
nullptr,
|
/* this is never static */
|
||||||
nullptr,
|
internal::meta_traits::is_const,
|
||||||
std::is_same_v<decltype(Setter), std::nullptr_t> || (std::is_member_object_pointer_v<decltype(Setter)> && std::is_const_v<underlying_type>),
|
nullptr,
|
||||||
false,
|
nullptr,
|
||||||
&internal::meta_info<underlying_type>::resolve,
|
0u,
|
||||||
&meta_setter<Type, Setter>,
|
internal::meta_node<std::remove_cv_t<std::remove_reference_t<data_type>>>::resolve(),
|
||||||
&meta_getter<Type, Getter, Policy>
|
&meta_arg<type_list<>>,
|
||||||
};
|
&meta_setter<Type, Setter>,
|
||||||
|
&meta_getter<Type, Getter, Policy>
|
||||||
|
// tricks clang-format
|
||||||
|
};
|
||||||
|
|
||||||
ENTT_ASSERT(!internal::find_if_not(id, type->data, &node), "Duplicate identifier");
|
link_data_if_required(id, node);
|
||||||
node.id = id;
|
return meta_factory<Type, std::integral_constant<decltype(Setter), Setter>, std::integral_constant<decltype(Getter), Getter>>{&node.prop};
|
||||||
|
} else {
|
||||||
|
using args_type = typename meta_function_helper_t<Type, decltype(Setter)>::args_type;
|
||||||
|
|
||||||
if(!internal::find_if(&node, type->data)) {
|
static internal::meta_data_node node{
|
||||||
node.next = type->data;
|
{},
|
||||||
type->data = &node;
|
/* this is never static nor const */
|
||||||
|
internal::meta_traits::is_none,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
1u,
|
||||||
|
internal::meta_node<std::remove_cv_t<std::remove_reference_t<data_type>>>::resolve(),
|
||||||
|
&meta_arg<type_list<type_list_element_t<args_type::size != 1u, args_type>>>,
|
||||||
|
&meta_setter<Type, Setter>,
|
||||||
|
&meta_getter<Type, Getter, Policy>
|
||||||
|
// tricks clang-format
|
||||||
|
};
|
||||||
|
|
||||||
|
link_data_if_required(id, node);
|
||||||
|
return meta_factory<Type, std::integral_constant<decltype(Setter), Setter>, std::integral_constant<decltype(Getter), Getter>>{&node.prop};
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta_factory<Type, std::integral_constant<decltype(Setter), Setter>, std::integral_constant<decltype(Getter), Getter>>{&node.prop};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Assigns a meta funcion to a meta type.
|
* @brief Assigns a meta data to a meta type by means of its setters and
|
||||||
|
* getter.
|
||||||
|
*
|
||||||
|
* Multi-setter support for meta data members. All setters are tried in the
|
||||||
|
* order of definition before returning to the caller.<br/>
|
||||||
|
* Setters can be either free functions, member functions or a mix of them
|
||||||
|
* and are provided via a `value_list` type.
|
||||||
|
*
|
||||||
|
* @sa data
|
||||||
|
*
|
||||||
|
* @tparam Setter The actual functions to use as setters.
|
||||||
|
* @tparam Getter The actual getter function.
|
||||||
|
* @tparam Policy Optional policy (no policy set by default).
|
||||||
|
* @param id Unique identifier.
|
||||||
|
* @return An extended meta factory for the parent type.
|
||||||
|
*/
|
||||||
|
template<typename Setter, auto Getter, typename Policy = as_is_t>
|
||||||
|
auto data(const id_type id) ENTT_NOEXCEPT {
|
||||||
|
return data<Setter, Getter, Policy>(id, std::make_index_sequence<Setter::size>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assigns a meta function to a meta type.
|
||||||
*
|
*
|
||||||
* Both member functions and free functions can be assigned to a meta
|
* Both member functions and free functions can be assigned to a meta
|
||||||
* type.<br/>
|
* type.<br/>
|
||||||
@@ -533,44 +543,27 @@ struct meta_factory<Type> {
|
|||||||
template<auto Candidate, typename Policy = as_is_t>
|
template<auto Candidate, typename Policy = as_is_t>
|
||||||
auto func(const id_type id) ENTT_NOEXCEPT {
|
auto func(const id_type id) ENTT_NOEXCEPT {
|
||||||
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
|
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
|
||||||
auto * const type = internal::meta_info<Type>::resolve();
|
static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");
|
||||||
|
|
||||||
static internal::meta_func_node node{
|
static internal::meta_func_node node{
|
||||||
{},
|
{},
|
||||||
type,
|
(descriptor::is_const ? internal::meta_traits::is_const : internal::meta_traits::is_none) | (descriptor::is_static ? internal::meta_traits::is_static : internal::meta_traits::is_none),
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
descriptor::args_type::size,
|
descriptor::args_type::size,
|
||||||
descriptor::is_const,
|
internal::meta_node<std::conditional_t<std::is_same_v<Policy, as_void_t>, void, std::remove_cv_t<std::remove_reference_t<typename descriptor::return_type>>>>::resolve(),
|
||||||
descriptor::is_static,
|
&meta_arg<typename descriptor::args_type>,
|
||||||
&internal::meta_info<std::conditional_t<std::is_same_v<Policy, as_void_t>, void, typename descriptor::return_type>>::resolve,
|
&meta_invoke<Type, Candidate, Policy>
|
||||||
[](const typename internal::meta_func_node::size_type index) ENTT_NOEXCEPT {
|
// tricks clang-format
|
||||||
return meta_arg(typename descriptor::args_type{}, index);
|
|
||||||
},
|
|
||||||
[](meta_handle instance, meta_any *args) {
|
|
||||||
return meta_invoke<Type, Candidate, Policy>(std::move(instance), args, std::make_index_sequence<descriptor::args_type::size>{});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for(auto *it = &type->func; *it; it = &(*it)->next) {
|
link_func_if_required(id, node);
|
||||||
if(*it == &node) {
|
|
||||||
*it = node.next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal::meta_func_node **it = &type->func;
|
|
||||||
for(; *it && (*it)->id != id; it = &(*it)->next);
|
|
||||||
for(; *it && (*it)->id == id && (*it)->arity < node.arity; it = &(*it)->next);
|
|
||||||
|
|
||||||
node.id = id;
|
|
||||||
node.next = *it;
|
|
||||||
*it = &node;
|
|
||||||
|
|
||||||
return meta_factory<Type, std::integral_constant<decltype(Candidate), Candidate>>{&node.prop};
|
return meta_factory<Type, std::integral_constant<decltype(Candidate), Candidate>>{&node.prop};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
internal::meta_type_node *owner;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Utility function to use for reflection.
|
* @brief Utility function to use for reflection.
|
||||||
@@ -585,13 +578,73 @@ struct meta_factory<Type> {
|
|||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] auto meta() ENTT_NOEXCEPT {
|
[[nodiscard]] auto meta() ENTT_NOEXCEPT {
|
||||||
auto * const node = internal::meta_info<Type>::resolve();
|
auto *const node = internal::meta_node<Type>::resolve();
|
||||||
// extended meta factory to allow assigning properties to opaque meta types
|
// extended meta factory to allow assigning properties to opaque meta types
|
||||||
return meta_factory<Type, Type>{&node->prop};
|
return meta_factory<Type, Type>{&node->prop};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets a type and all its parts.
|
||||||
|
*
|
||||||
|
* Resets a type and all its data members, member functions and properties, as
|
||||||
|
* well as its constructors, destructors and conversion functions if any.<br/>
|
||||||
|
* Base classes aren't reset but the link between the two types is removed.
|
||||||
|
*
|
||||||
|
* The type is also removed from the list of searchable types.
|
||||||
|
*
|
||||||
|
* @param id Unique identifier.
|
||||||
|
*/
|
||||||
|
inline void meta_reset(const id_type id) ENTT_NOEXCEPT {
|
||||||
|
auto clear_chain = [](auto **curr, auto... member) {
|
||||||
|
for(; *curr; *curr = std::exchange((*curr)->next, nullptr)) {
|
||||||
|
if constexpr(sizeof...(member) != 0u) {
|
||||||
|
static_assert(sizeof...(member) == 1u, "Assert in defense of the future me");
|
||||||
|
for(auto **sub = (&((*curr)->*member), ...); *sub; *sub = std::exchange((*sub)->next, nullptr)) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for(auto **it = internal::meta_context::global(); *it; it = &(*it)->next) {
|
||||||
|
if(auto *node = *it; node->id == id) {
|
||||||
|
clear_chain(&node->prop);
|
||||||
|
clear_chain(&node->base);
|
||||||
|
clear_chain(&node->conv);
|
||||||
|
clear_chain(&node->ctor);
|
||||||
|
clear_chain(&node->data, &internal::meta_data_node::prop);
|
||||||
|
clear_chain(&node->func, &internal::meta_func_node::prop);
|
||||||
|
|
||||||
|
node->id = {};
|
||||||
|
node->dtor = nullptr;
|
||||||
|
*it = std::exchange(node->next, nullptr);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets a type and all its parts.
|
||||||
|
*
|
||||||
|
* @sa meta_reset
|
||||||
|
*
|
||||||
|
* @tparam Type Type to reset.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
void meta_reset() ENTT_NOEXCEPT {
|
||||||
|
meta_reset(internal::meta_node<Type>::resolve()->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets all searchable types.
|
||||||
|
*
|
||||||
|
* @sa meta_reset
|
||||||
|
*/
|
||||||
|
inline void meta_reset() ENTT_NOEXCEPT {
|
||||||
|
while(*internal::meta_context::global()) {
|
||||||
|
meta_reset((*internal::meta_context::global())->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
24
src/entt/meta/fwd.hpp
Normal file
24
src/entt/meta/fwd.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef ENTT_META_FWD_HPP
|
||||||
|
#define ENTT_META_FWD_HPP
|
||||||
|
|
||||||
|
namespace entt {
|
||||||
|
|
||||||
|
class meta_sequence_container;
|
||||||
|
|
||||||
|
class meta_associative_container;
|
||||||
|
|
||||||
|
class meta_any;
|
||||||
|
|
||||||
|
struct meta_handle;
|
||||||
|
|
||||||
|
struct meta_prop;
|
||||||
|
|
||||||
|
struct meta_data;
|
||||||
|
|
||||||
|
struct meta_func;
|
||||||
|
|
||||||
|
class meta_type;
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,190 +1,161 @@
|
|||||||
#ifndef ENTT_META_NODE_HPP
|
#ifndef ENTT_META_NODE_HPP
|
||||||
#define ENTT_META_NODE_HPP
|
#define ENTT_META_NODE_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "../core/attribute.h"
|
#include "../core/attribute.h"
|
||||||
|
#include "../core/enum.hpp"
|
||||||
#include "../core/fwd.hpp"
|
#include "../core/fwd.hpp"
|
||||||
#include "../core/type_info.hpp"
|
#include "../core/type_info.hpp"
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
#include "type_traits.hpp"
|
#include "type_traits.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
class meta_any;
|
class meta_any;
|
||||||
class meta_type;
|
class meta_type;
|
||||||
struct meta_handle;
|
struct meta_handle;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @cond TURN_OFF_DOXYGEN
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
enum class meta_traits : std::uint32_t {
|
||||||
|
is_none = 0x0000,
|
||||||
|
is_const = 0x0001,
|
||||||
|
is_static = 0x0002,
|
||||||
|
is_arithmetic = 0x0004,
|
||||||
|
is_array = 0x0008,
|
||||||
|
is_enum = 0x0010,
|
||||||
|
is_class = 0x0020,
|
||||||
|
is_pointer = 0x0040,
|
||||||
|
is_meta_pointer_like = 0x0080,
|
||||||
|
is_meta_sequence_container = 0x0100,
|
||||||
|
is_meta_associative_container = 0x0200,
|
||||||
|
_entt_enum_as_bitmask
|
||||||
|
};
|
||||||
|
|
||||||
struct meta_type_node;
|
struct meta_type_node;
|
||||||
|
|
||||||
|
|
||||||
struct meta_prop_node {
|
struct meta_prop_node {
|
||||||
meta_prop_node * next;
|
meta_prop_node *next;
|
||||||
const meta_any &id;
|
const meta_any &id;
|
||||||
meta_any &value;
|
meta_any &value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct meta_base_node {
|
struct meta_base_node {
|
||||||
meta_type_node * const parent;
|
meta_base_node *next;
|
||||||
meta_base_node * next;
|
meta_type_node *const type;
|
||||||
meta_type_node *(* const type)() ENTT_NOEXCEPT;
|
meta_any (*const cast)(meta_any) ENTT_NOEXCEPT;
|
||||||
const void *(* const cast)(const void *) ENTT_NOEXCEPT;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct meta_conv_node {
|
struct meta_conv_node {
|
||||||
meta_type_node * const parent;
|
meta_conv_node *next;
|
||||||
meta_conv_node * next;
|
meta_type_node *const type;
|
||||||
meta_type_node *(* const type)() ENTT_NOEXCEPT;
|
meta_any (*const conv)(const meta_any &);
|
||||||
meta_any(* const conv)(const void *);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct meta_ctor_node {
|
struct meta_ctor_node {
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
meta_type_node * const parent;
|
meta_ctor_node *next;
|
||||||
meta_ctor_node * next;
|
|
||||||
meta_prop_node * prop;
|
|
||||||
const size_type arity;
|
const size_type arity;
|
||||||
meta_type(* const arg)(const size_type) ENTT_NOEXCEPT;
|
meta_type (*const arg)(const size_type) ENTT_NOEXCEPT;
|
||||||
meta_any(* const invoke)(meta_any * const);
|
meta_any (*const invoke)(meta_any *const);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct meta_data_node {
|
struct meta_data_node {
|
||||||
|
using size_type = std::size_t;
|
||||||
id_type id;
|
id_type id;
|
||||||
meta_type_node * const parent;
|
const meta_traits traits;
|
||||||
meta_data_node * next;
|
meta_data_node *next;
|
||||||
meta_prop_node * prop;
|
meta_prop_node *prop;
|
||||||
const bool is_const;
|
const size_type arity;
|
||||||
const bool is_static;
|
meta_type_node *const type;
|
||||||
meta_type_node *(* const type)() ENTT_NOEXCEPT;
|
meta_type (*const arg)(const size_type) ENTT_NOEXCEPT;
|
||||||
bool(* const set)(meta_handle, meta_any);
|
bool (*const set)(meta_handle, meta_any);
|
||||||
meta_any(* const get)(meta_handle);
|
meta_any (*const get)(meta_handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct meta_func_node {
|
struct meta_func_node {
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
id_type id;
|
id_type id;
|
||||||
meta_type_node * const parent;
|
const meta_traits traits;
|
||||||
meta_func_node * next;
|
meta_func_node *next;
|
||||||
meta_prop_node * prop;
|
meta_prop_node *prop;
|
||||||
const size_type arity;
|
const size_type arity;
|
||||||
const bool is_const;
|
meta_type_node *const ret;
|
||||||
const bool is_static;
|
meta_type (*const arg)(const size_type) ENTT_NOEXCEPT;
|
||||||
meta_type_node *(* const ret)() ENTT_NOEXCEPT;
|
meta_any (*const invoke)(meta_handle, meta_any *const);
|
||||||
meta_type(* const arg)(const size_type) ENTT_NOEXCEPT;
|
|
||||||
meta_any(* const invoke)(meta_handle, meta_any *);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct meta_template_node {
|
||||||
struct meta_template_info {
|
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
const bool is_template_specialization;
|
|
||||||
const size_type arity;
|
const size_type arity;
|
||||||
meta_type_node *(* const type)() ENTT_NOEXCEPT;
|
meta_type_node *const type;
|
||||||
meta_type_node *(* const arg)(const size_type) ENTT_NOEXCEPT;
|
meta_type_node *(*const arg)(const size_type)ENTT_NOEXCEPT;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct meta_type_node {
|
struct meta_type_node {
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
const type_info info;
|
const type_info *info;
|
||||||
id_type id;
|
id_type id;
|
||||||
meta_type_node * next;
|
const meta_traits traits;
|
||||||
meta_prop_node * prop;
|
meta_type_node *next;
|
||||||
|
meta_prop_node *prop;
|
||||||
const size_type size_of;
|
const size_type size_of;
|
||||||
const bool is_void;
|
meta_type_node *(*const remove_pointer)() ENTT_NOEXCEPT;
|
||||||
const bool is_integral;
|
meta_any (*const default_constructor)();
|
||||||
const bool is_floating_point;
|
double (*const conversion_helper)(void *, const void *);
|
||||||
const bool is_array;
|
const meta_template_node *const templ;
|
||||||
const bool is_enum;
|
|
||||||
const bool is_union;
|
|
||||||
const bool is_class;
|
|
||||||
const bool is_pointer;
|
|
||||||
const bool is_function_pointer;
|
|
||||||
const bool is_member_object_pointer;
|
|
||||||
const bool is_member_function_pointer;
|
|
||||||
const bool is_pointer_like;
|
|
||||||
const bool is_sequence_container;
|
|
||||||
const bool is_associative_container;
|
|
||||||
const meta_template_info template_info;
|
|
||||||
const size_type rank;
|
|
||||||
size_type(* const extent)(const size_type) ENTT_NOEXCEPT ;
|
|
||||||
meta_type_node *(* const remove_pointer)() ENTT_NOEXCEPT;
|
|
||||||
meta_type_node *(* const remove_extent)() ENTT_NOEXCEPT;
|
|
||||||
meta_ctor_node * const def_ctor;
|
|
||||||
meta_ctor_node *ctor{nullptr};
|
meta_ctor_node *ctor{nullptr};
|
||||||
meta_base_node *base{nullptr};
|
meta_base_node *base{nullptr};
|
||||||
meta_conv_node *conv{nullptr};
|
meta_conv_node *conv{nullptr};
|
||||||
meta_data_node *data{nullptr};
|
meta_data_node *data{nullptr};
|
||||||
meta_func_node *func{nullptr};
|
meta_func_node *func{nullptr};
|
||||||
void(* dtor)(void *){nullptr};
|
void (*dtor)(void *){nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<auto Member, typename Op, typename Node>
|
|
||||||
auto meta_visit(const Op &op, const Node *node)
|
|
||||||
-> std::decay_t<decltype(node->*Member)> {
|
|
||||||
for(auto *curr = node->*Member; curr; curr = curr->next) {
|
|
||||||
if(op(curr)) {
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if constexpr(std::is_same_v<Node, meta_type_node>) {
|
|
||||||
for(auto *curr = node->base; curr; curr = curr->next) {
|
|
||||||
if(auto *ret = meta_visit<Member>(op, curr->type()); ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
meta_type_node * meta_arg_node(type_list<Args...>, const std::size_t index) ENTT_NOEXCEPT;
|
meta_type_node *meta_arg_node(type_list<Args...>, const std::size_t index) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class ENTT_API meta_node {
|
class ENTT_API meta_node {
|
||||||
static_assert(std::is_same_v<Type, std::remove_cv_t<std::remove_reference_t<Type>>>, "Invalid type");
|
static_assert(std::is_same_v<Type, std::remove_cv_t<std::remove_reference_t<Type>>>, "Invalid type");
|
||||||
|
|
||||||
template<std::size_t... Index>
|
[[nodiscard]] static auto *meta_default_constructor() ENTT_NOEXCEPT {
|
||||||
[[nodiscard]] static auto extent(const meta_type_node::size_type dim, std::index_sequence<Index...>) ENTT_NOEXCEPT {
|
if constexpr(std::is_default_constructible_v<Type>) {
|
||||||
meta_type_node::size_type ext{};
|
return +[]() { return meta_any{std::in_place_type<Type>}; };
|
||||||
((ext = (dim == Index ? std::extent_v<Type, Index> : ext)), ...);
|
} else {
|
||||||
return ext;
|
return static_cast<std::decay_t<decltype(meta_type_node::default_constructor)>>(nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static meta_ctor_node * meta_default_constructor([[maybe_unused]] meta_type_node *type) ENTT_NOEXCEPT {
|
[[nodiscard]] static auto *meta_conversion_helper() ENTT_NOEXCEPT {
|
||||||
if constexpr(std::is_default_constructible_v<Type>) {
|
if constexpr(std::is_arithmetic_v<Type>) {
|
||||||
static meta_ctor_node node{
|
return +[](void *bin, const void *value) {
|
||||||
type,
|
return bin ? static_cast<double>(*static_cast<Type *>(bin) = static_cast<Type>(*static_cast<const double *>(value))) : static_cast<double>(*static_cast<const Type *>(value));
|
||||||
nullptr,
|
};
|
||||||
nullptr,
|
} else if constexpr(std::is_enum_v<Type>) {
|
||||||
0u,
|
return +[](void *bin, const void *value) {
|
||||||
nullptr,
|
return bin ? static_cast<double>(*static_cast<Type *>(bin) = static_cast<Type>(static_cast<std::underlying_type_t<Type>>(*static_cast<const double *>(value)))) : static_cast<double>(*static_cast<const Type *>(value));
|
||||||
[](meta_any * const) { return meta_any{std::in_place_type<Type>}; }
|
};
|
||||||
|
} else {
|
||||||
|
return static_cast<std::decay_t<decltype(meta_type_node::conversion_helper)>>(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static meta_template_node *meta_template_info() ENTT_NOEXCEPT {
|
||||||
|
if constexpr(is_complete_v<meta_template_traits<Type>>) {
|
||||||
|
static meta_template_node node{
|
||||||
|
meta_template_traits<Type>::args_type::size,
|
||||||
|
meta_node<typename meta_template_traits<Type>::class_type>::resolve(),
|
||||||
|
[](const std::size_t index) ENTT_NOEXCEPT { return meta_arg_node(typename meta_template_traits<Type>::args_type{}, index); }
|
||||||
|
// tricks clang-format
|
||||||
};
|
};
|
||||||
|
|
||||||
return &node;
|
return &node;
|
||||||
@@ -193,78 +164,74 @@ class ENTT_API meta_node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static meta_template_info meta_template_descriptor() ENTT_NOEXCEPT {
|
|
||||||
if constexpr(is_complete_v<meta_template_traits<Type>>) {
|
|
||||||
return {
|
|
||||||
true,
|
|
||||||
meta_template_traits<Type>::args_type::size,
|
|
||||||
&meta_node<typename meta_template_traits<Type>::class_type>::resolve,
|
|
||||||
[](const std::size_t index) ENTT_NOEXCEPT {
|
|
||||||
return meta_arg_node(typename meta_template_traits<Type>::args_type{}, index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return { false, 0u, nullptr, nullptr };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] static meta_type_node * resolve() ENTT_NOEXCEPT {
|
[[nodiscard]] static meta_type_node *resolve() ENTT_NOEXCEPT {
|
||||||
static meta_type_node node{
|
static meta_type_node node{
|
||||||
type_id<Type>(),
|
&type_id<Type>(),
|
||||||
{},
|
{},
|
||||||
|
internal::meta_traits::is_none
|
||||||
|
| (std::is_arithmetic_v<Type> ? internal::meta_traits::is_arithmetic : internal::meta_traits::is_none)
|
||||||
|
| (std::is_array_v<Type> ? internal::meta_traits::is_array : internal::meta_traits::is_none)
|
||||||
|
| (std::is_enum_v<Type> ? internal::meta_traits::is_enum : internal::meta_traits::is_none)
|
||||||
|
| (std::is_class_v<Type> ? internal::meta_traits::is_class : internal::meta_traits::is_none)
|
||||||
|
| (std::is_pointer_v<Type> ? internal::meta_traits::is_pointer : internal::meta_traits::is_none)
|
||||||
|
| (is_meta_pointer_like_v<Type> ? internal::meta_traits::is_meta_pointer_like : internal::meta_traits::is_none)
|
||||||
|
| (is_complete_v<meta_sequence_container_traits<Type>> ? internal::meta_traits::is_meta_sequence_container : internal::meta_traits::is_none)
|
||||||
|
| (is_complete_v<meta_associative_container_traits<Type>> ? internal::meta_traits::is_meta_associative_container : internal::meta_traits::is_none),
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
size_of_v<Type>,
|
size_of_v<Type>,
|
||||||
std::is_void_v<Type>,
|
|
||||||
std::is_integral_v<Type>,
|
|
||||||
std::is_floating_point_v<Type>,
|
|
||||||
std::is_array_v<Type>,
|
|
||||||
std::is_enum_v<Type>,
|
|
||||||
std::is_union_v<Type>,
|
|
||||||
std::is_class_v<Type>,
|
|
||||||
std::is_pointer_v<Type>,
|
|
||||||
std::is_pointer_v<Type> && std::is_function_v<std::remove_pointer_t<Type>>,
|
|
||||||
std::is_member_object_pointer_v<Type>,
|
|
||||||
std::is_member_function_pointer_v<Type>,
|
|
||||||
is_meta_pointer_like_v<Type>,
|
|
||||||
is_complete_v<meta_sequence_container_traits<Type>>,
|
|
||||||
is_complete_v<meta_associative_container_traits<Type>>,
|
|
||||||
meta_template_descriptor(),
|
|
||||||
std::rank_v<Type>,
|
|
||||||
[](meta_type_node::size_type dim) ENTT_NOEXCEPT { return extent(dim, std::make_index_sequence<std::rank_v<Type>>{}); },
|
|
||||||
&meta_node<std::remove_cv_t<std::remove_reference_t<std::remove_pointer_t<Type>>>>::resolve,
|
&meta_node<std::remove_cv_t<std::remove_reference_t<std::remove_pointer_t<Type>>>>::resolve,
|
||||||
&meta_node<std::remove_cv_t<std::remove_reference_t<std::remove_extent_t<Type>>>>::resolve,
|
meta_default_constructor(),
|
||||||
meta_default_constructor(&node),
|
meta_conversion_helper(),
|
||||||
meta_default_constructor(&node)
|
meta_template_info()
|
||||||
|
// tricks clang-format
|
||||||
};
|
};
|
||||||
|
|
||||||
return &node;
|
return &node;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
struct meta_info: meta_node<std::remove_cv_t<std::remove_reference_t<Type>>> {};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
meta_type_node * meta_arg_node(type_list<Args...>, const std::size_t index) ENTT_NOEXCEPT {
|
[[nodiscard]] meta_type_node *meta_arg_node(type_list<Args...>, const std::size_t index) ENTT_NOEXCEPT {
|
||||||
meta_type_node *args[sizeof...(Args) + 1u]{nullptr, internal::meta_info<Args>::resolve()...};
|
meta_type_node *args[sizeof...(Args) + 1u]{nullptr, internal::meta_node<std::remove_cv_t<std::remove_reference_t<Args>>>::resolve()...};
|
||||||
return args[index + 1u];
|
return args[index + 1u];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<auto Member, typename Type>
|
||||||
|
[[nodiscard]] static std::decay_t<decltype(std::declval<internal::meta_type_node>().*Member)> find_by(const Type &info_or_id, const internal::meta_type_node *node) ENTT_NOEXCEPT {
|
||||||
|
for(auto *curr = node->*Member; curr; curr = curr->next) {
|
||||||
|
if constexpr(std::is_same_v<Type, type_info>) {
|
||||||
|
if(*curr->type->info == info_or_id) {
|
||||||
|
return curr;
|
||||||
|
}
|
||||||
|
} else if constexpr(std::is_same_v<decltype(curr), meta_base_node *>) {
|
||||||
|
if(curr->type->id == info_or_id) {
|
||||||
|
return curr;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(curr->id == info_or_id) {
|
||||||
|
return curr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto *curr = node->base; curr; curr = curr->next) {
|
||||||
|
if(auto *ret = find_by<Member>(info_or_id, curr->type); ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,24 +1,19 @@
|
|||||||
#ifndef ENTT_META_POINTER_HPP
|
#ifndef ENTT_META_POINTER_HPP
|
||||||
#define ENTT_META_POINTER_HPP
|
#define ENTT_META_POINTER_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "type_traits.hpp"
|
#include "type_traits.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Makes plain pointers pointer-like types for the meta system.
|
* @brief Makes plain pointers pointer-like types for the meta system.
|
||||||
* @tparam Type Element type.
|
* @tparam Type Element type.
|
||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct is_meta_pointer_like<Type *>
|
struct is_meta_pointer_like<Type *>
|
||||||
: std::true_type
|
: std::true_type {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Partial specialization used to reject pointers to arrays.
|
* @brief Partial specialization used to reject pointers to arrays.
|
||||||
@@ -26,10 +21,8 @@ struct is_meta_pointer_like<Type *>
|
|||||||
* @tparam N Number of elements of the array.
|
* @tparam N Number of elements of the array.
|
||||||
*/
|
*/
|
||||||
template<typename Type, std::size_t N>
|
template<typename Type, std::size_t N>
|
||||||
struct is_meta_pointer_like<Type(*)[N]>
|
struct is_meta_pointer_like<Type (*)[N]>
|
||||||
: std::false_type
|
: std::false_type {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Makes `std::shared_ptr`s of any type pointer-like types for the meta
|
* @brief Makes `std::shared_ptr`s of any type pointer-like types for the meta
|
||||||
@@ -38,9 +31,7 @@ struct is_meta_pointer_like<Type(*)[N]>
|
|||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct is_meta_pointer_like<std::shared_ptr<Type>>
|
struct is_meta_pointer_like<std::shared_ptr<Type>>
|
||||||
: std::true_type
|
: std::true_type {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Makes `std::unique_ptr`s of any type pointer-like types for the meta
|
* @brief Makes `std::unique_ptr`s of any type pointer-like types for the meta
|
||||||
@@ -50,11 +41,8 @@ struct is_meta_pointer_like<std::shared_ptr<Type>>
|
|||||||
*/
|
*/
|
||||||
template<typename Type, typename... Args>
|
template<typename Type, typename... Args>
|
||||||
struct is_meta_pointer_like<std::unique_ptr<Type, Args...>>
|
struct is_meta_pointer_like<std::unique_ptr<Type, Args...>>
|
||||||
: std::true_type
|
: std::true_type {};
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,27 +1,66 @@
|
|||||||
#ifndef ENTT_META_POLICY_HPP
|
#ifndef ENTT_META_POLICY_HPP
|
||||||
#define ENTT_META_POLICY_HPP
|
#define ENTT_META_POLICY_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Empty class type used to request the _as ref_ policy. */
|
/*! @brief Empty class type used to request the _as ref_ policy. */
|
||||||
struct as_ref_t {};
|
struct as_ref_t {
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
static constexpr bool value = std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>;
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
/*! @brief Empty class type used to request the _as cref_ policy. */
|
/*! @brief Empty class type used to request the _as cref_ policy. */
|
||||||
struct as_cref_t {};
|
struct as_cref_t {
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
template<typename Type>
|
||||||
|
static constexpr bool value = std::is_reference_v<Type>;
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
/*! @brief Empty class type used to request the _as-is_ policy. */
|
/*! @brief Empty class type used to request the _as-is_ policy. */
|
||||||
struct as_is_t {};
|
struct as_is_t {
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
template<typename>
|
||||||
|
static constexpr bool value = true;
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
/*! @brief Empty class type used to request the _as void_ policy. */
|
/*! @brief Empty class type used to request the _as void_ policy. */
|
||||||
struct as_void_t {};
|
struct as_void_t {
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
}
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
template<typename>
|
||||||
|
static constexpr bool value = true;
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,13 +1,69 @@
|
|||||||
#ifndef ENTT_META_RANGE_HPP
|
#ifndef ENTT_META_RANGE_HPP
|
||||||
#define ENTT_META_RANGE_HPP
|
#define ENTT_META_RANGE_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include "../core/iterator.hpp"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename Type, typename Node>
|
||||||
|
struct meta_range_iterator final {
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using value_type = Type;
|
||||||
|
using pointer = input_iterator_pointer<value_type>;
|
||||||
|
using reference = value_type;
|
||||||
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
using node_type = Node;
|
||||||
|
|
||||||
|
meta_range_iterator() ENTT_NOEXCEPT
|
||||||
|
: it{} {}
|
||||||
|
|
||||||
|
meta_range_iterator(node_type *head) ENTT_NOEXCEPT
|
||||||
|
: it{head} {}
|
||||||
|
|
||||||
|
meta_range_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
|
return (it = it->next), *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
meta_range_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
|
meta_range_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
|
return operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator==(const meta_range_iterator &other) const ENTT_NOEXCEPT {
|
||||||
|
return it == other.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator!=(const meta_range_iterator &other) const ENTT_NOEXCEPT {
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
node_type *it;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Iterable range to use to iterate all types of meta objects.
|
* @brief Iterable range to use to iterate all types of meta objects.
|
||||||
@@ -15,51 +71,13 @@ namespace entt {
|
|||||||
* @tparam Node Type of meta nodes iterated.
|
* @tparam Node Type of meta nodes iterated.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename Node = typename Type::node_type>
|
template<typename Type, typename Node = typename Type::node_type>
|
||||||
class meta_range {
|
struct meta_range final {
|
||||||
struct range_iterator {
|
|
||||||
using difference_type = std::ptrdiff_t;
|
|
||||||
using value_type = Type;
|
|
||||||
using pointer = void;
|
|
||||||
using reference = value_type;
|
|
||||||
using iterator_category = std::input_iterator_tag;
|
|
||||||
using node_type = Node;
|
|
||||||
|
|
||||||
range_iterator() ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
range_iterator(node_type *head) ENTT_NOEXCEPT
|
|
||||||
: it{head}
|
|
||||||
{}
|
|
||||||
|
|
||||||
range_iterator & operator++() ENTT_NOEXCEPT {
|
|
||||||
return (it = it->next), *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
range_iterator operator++(int) ENTT_NOEXCEPT {
|
|
||||||
range_iterator orig = *this;
|
|
||||||
return ++(*this), orig;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
|
||||||
return it;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return other.it == it;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
node_type *it{};
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
/*! @brief Node type. */
|
/*! @brief Node type. */
|
||||||
using node_type = Node;
|
using node_type = Node;
|
||||||
/*! @brief Input iterator type. */
|
/*! @brief Input iterator type. */
|
||||||
using iterator = range_iterator;
|
using iterator = internal::meta_range_iterator<Type, Node>;
|
||||||
|
/*! @brief Constant input iterator type. */
|
||||||
|
using const_iterator = iterator;
|
||||||
|
|
||||||
/*! @brief Default constructor. */
|
/*! @brief Default constructor. */
|
||||||
meta_range() ENTT_NOEXCEPT = default;
|
meta_range() ENTT_NOEXCEPT = default;
|
||||||
@@ -68,33 +86,40 @@ public:
|
|||||||
* @brief Constructs a meta range from a given node.
|
* @brief Constructs a meta range from a given node.
|
||||||
* @param head The underlying node with which to construct the range.
|
* @param head The underlying node with which to construct the range.
|
||||||
*/
|
*/
|
||||||
meta_range(node_type *head)
|
meta_range(node_type *head) ENTT_NOEXCEPT
|
||||||
: node{head}
|
: node{head} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an iterator to the beginning.
|
* @brief Returns an iterator to the beginning.
|
||||||
* @return An iterator to the first meta object of the range.
|
* @return An iterator to the first meta object of the range.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||||
return iterator{node};
|
return iterator{node};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cbegin */
|
||||||
|
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||||
|
return cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an iterator to the end.
|
* @brief Returns an iterator to the end.
|
||||||
* @return An iterator to the element following the last meta object of the
|
* @return An iterator to the element following the last meta object of the
|
||||||
* range.
|
* range.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
|
||||||
return iterator{};
|
return iterator{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cend */
|
||||||
|
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
|
||||||
|
return cend();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
node_type *node{nullptr};
|
node_type *node{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef ENTT_META_RESOLVE_HPP
|
#ifndef ENTT_META_RESOLVE_HPP
|
||||||
#define ENTT_META_RESOLVE_HPP
|
#define ENTT_META_RESOLVE_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "../core/type_info.hpp"
|
#include "../core/type_info.hpp"
|
||||||
#include "ctx.hpp"
|
#include "ctx.hpp"
|
||||||
@@ -9,10 +8,8 @@
|
|||||||
#include "node.hpp"
|
#include "node.hpp"
|
||||||
#include "range.hpp"
|
#include "range.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the meta type associated with a given type.
|
* @brief Returns the meta type associated with a given type.
|
||||||
* @tparam Type Type to use to search for a meta type.
|
* @tparam Type Type to use to search for a meta type.
|
||||||
@@ -20,27 +17,25 @@ namespace entt {
|
|||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] meta_type resolve() ENTT_NOEXCEPT {
|
[[nodiscard]] meta_type resolve() ENTT_NOEXCEPT {
|
||||||
return internal::meta_info<Type>::resolve();
|
return internal::meta_node<std::remove_cv_t<std::remove_reference_t<Type>>>::resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a range to use to visit all meta types.
|
* @brief Returns a range to use to visit all meta types.
|
||||||
* @return An iterable range to use to visit all meta types.
|
* @return An iterable range to use to visit all meta types.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] inline meta_range<meta_type> resolve() {
|
[[nodiscard]] inline meta_range<meta_type> resolve() ENTT_NOEXCEPT {
|
||||||
return *internal::meta_context::global();
|
return *internal::meta_context::global();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the meta type associated with a given identifier, if any.
|
* @brief Returns the meta type associated with a given identifier, if any.
|
||||||
* @param id Unique identifier.
|
* @param id Unique identifier.
|
||||||
* @return The meta type associated with the given identifier, if any.
|
* @return The meta type associated with the given identifier, if any.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] inline meta_type resolve(const id_type id) ENTT_NOEXCEPT {
|
[[nodiscard]] inline meta_type resolve(const id_type id) ENTT_NOEXCEPT {
|
||||||
for(auto *curr = *internal::meta_context::global(); curr; curr = curr->next) {
|
for(auto &&curr: resolve()) {
|
||||||
if(curr->id == id) {
|
if(curr.id() == id) {
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,16 +43,14 @@ template<typename Type>
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the meta type associated with a given type info object, if
|
* @brief Returns the meta type associated with a given type info object.
|
||||||
* any.
|
|
||||||
* @param info The type info object of the requested type.
|
* @param info The type info object of the requested type.
|
||||||
* @return The meta type associated with the given type info object, if any.
|
* @return The meta type associated with the given type info object, if any.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] inline meta_type resolve(const type_info info) ENTT_NOEXCEPT {
|
[[nodiscard]] inline meta_type resolve(const type_info &info) ENTT_NOEXCEPT {
|
||||||
for(auto *curr = *internal::meta_context::global(); curr; curr = curr->next) {
|
for(auto &&curr: resolve()) {
|
||||||
if(curr->info == info) {
|
if(curr.info() == info) {
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,8 +58,6 @@ template<typename Type>
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,24 +1,20 @@
|
|||||||
#ifndef ENTT_META_TEMPLATE_HPP
|
#ifndef ENTT_META_TEMPLATE_HPP
|
||||||
#define ENTT_META_TEMPLATE_HPP
|
#define ENTT_META_TEMPLATE_HPP
|
||||||
|
|
||||||
|
|
||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Utility class to disambiguate class templates. */
|
/*! @brief Utility class to disambiguate class templates. */
|
||||||
template<template<typename...> typename>
|
template<template<typename...> class>
|
||||||
struct meta_class_template_tag {};
|
struct meta_class_template_tag {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief General purpose traits class for generating meta template information.
|
* @brief General purpose traits class for generating meta template information.
|
||||||
* @tparam Clazz Type of class template.
|
* @tparam Clazz Type of class template.
|
||||||
* @tparam Args Types of template arguments.
|
* @tparam Args Types of template arguments.
|
||||||
*/
|
*/
|
||||||
template<template<typename...> typename Clazz, typename... Args>
|
template<template<typename...> class Clazz, typename... Args>
|
||||||
struct meta_template_traits<Clazz<Args...>> {
|
struct meta_template_traits<Clazz<Args...>> {
|
||||||
/*! @brief Wrapped class template. */
|
/*! @brief Wrapped class template. */
|
||||||
using class_type = meta_class_template_tag<Clazz>;
|
using class_type = meta_class_template_tag<Clazz>;
|
||||||
@@ -26,8 +22,6 @@ struct meta_template_traits<Clazz<Args...>> {
|
|||||||
using args_type = type_list<Args...>;
|
using args_type = type_list<Args...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
#ifndef ENTT_META_TYPE_TRAITS_HPP
|
#ifndef ENTT_META_TYPE_TRAITS_HPP
|
||||||
#define ENTT_META_TYPE_TRAITS_HPP
|
#define ENTT_META_TYPE_TRAITS_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Traits class template to be specialized to enable support for meta
|
* @brief Traits class template to be specialized to enable support for meta
|
||||||
* template information.
|
* template information.
|
||||||
@@ -15,7 +13,6 @@ namespace entt {
|
|||||||
template<typename>
|
template<typename>
|
||||||
struct meta_template_traits;
|
struct meta_template_traits;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Traits class template to be specialized to enable support for meta
|
* @brief Traits class template to be specialized to enable support for meta
|
||||||
* sequence containers.
|
* sequence containers.
|
||||||
@@ -23,7 +20,6 @@ struct meta_template_traits;
|
|||||||
template<typename>
|
template<typename>
|
||||||
struct meta_sequence_container_traits;
|
struct meta_sequence_container_traits;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Traits class template to be specialized to enable support for meta
|
* @brief Traits class template to be specialized to enable support for meta
|
||||||
* associative containers.
|
* associative containers.
|
||||||
@@ -31,31 +27,6 @@ struct meta_sequence_container_traits;
|
|||||||
template<typename>
|
template<typename>
|
||||||
struct meta_associative_container_traits;
|
struct meta_associative_container_traits;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Provides the member constant `value` to true if a meta associative
|
|
||||||
* container claims to wrap a key-only type, false otherwise.
|
|
||||||
* @tparam Type Potentially key-only meta associative container type.
|
|
||||||
*/
|
|
||||||
template<typename, typename = void>
|
|
||||||
struct is_key_only_meta_associative_container: std::true_type {};
|
|
||||||
|
|
||||||
|
|
||||||
/*! @copydoc is_key_only_meta_associative_container */
|
|
||||||
template<typename Type>
|
|
||||||
struct is_key_only_meta_associative_container<Type, std::void_t<typename meta_associative_container_traits<Type>::type::mapped_type>>
|
|
||||||
: std::false_type
|
|
||||||
{};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Helper variable template.
|
|
||||||
* @tparam Type Potentially key-only meta associative container type.
|
|
||||||
*/
|
|
||||||
template<typename Type>
|
|
||||||
inline constexpr auto is_key_only_meta_associative_container_v = is_key_only_meta_associative_container<Type>::value;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provides the member constant `value` to true if a given type is a
|
* @brief Provides the member constant `value` to true if a given type is a
|
||||||
* pointer-like type from the point of view of the meta system, false otherwise.
|
* pointer-like type from the point of view of the meta system, false otherwise.
|
||||||
@@ -64,7 +35,6 @@ inline constexpr auto is_key_only_meta_associative_container_v = is_key_only_met
|
|||||||
template<typename>
|
template<typename>
|
||||||
struct is_meta_pointer_like: std::false_type {};
|
struct is_meta_pointer_like: std::false_type {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Partial specialization to ensure that const pointer-like types are
|
* @brief Partial specialization to ensure that const pointer-like types are
|
||||||
* also accepted.
|
* also accepted.
|
||||||
@@ -73,7 +43,6 @@ struct is_meta_pointer_like: std::false_type {};
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct is_meta_pointer_like<const Type>: is_meta_pointer_like<Type> {};
|
struct is_meta_pointer_like<const Type>: is_meta_pointer_like<Type> {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper variable template.
|
* @brief Helper variable template.
|
||||||
* @tparam Type Potentially pointer-like type.
|
* @tparam Type Potentially pointer-like type.
|
||||||
@@ -81,8 +50,6 @@ struct is_meta_pointer_like<const Type>: is_meta_pointer_like<Type> {};
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline constexpr auto is_meta_pointer_like_v = is_meta_pointer_like<Type>::value;
|
inline constexpr auto is_meta_pointer_like_v = is_meta_pointer_like<Type>::value;
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef ENTT_META_UTILITY_HPP
|
#ifndef ENTT_META_UTILITY_HPP
|
||||||
#define ENTT_META_UTILITY_HPP
|
#define ENTT_META_UTILITY_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -12,15 +11,12 @@
|
|||||||
#include "node.hpp"
|
#include "node.hpp"
|
||||||
#include "policy.hpp"
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Primary template isn't defined on purpose. */
|
/*! @brief Primary template isn't defined on purpose. */
|
||||||
template<typename, typename>
|
template<typename, typename>
|
||||||
struct meta_function_descriptor;
|
struct meta_function_descriptor;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta function descriptor.
|
* @brief Meta function descriptor.
|
||||||
* @tparam Type Reflected type to which the meta function is associated.
|
* @tparam Type Reflected type to which the meta function is associated.
|
||||||
@@ -29,19 +25,18 @@ struct meta_function_descriptor;
|
|||||||
* @tparam Args Function arguments.
|
* @tparam Args Function arguments.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename Ret, typename Class, typename... Args>
|
template<typename Type, typename Ret, typename Class, typename... Args>
|
||||||
struct meta_function_descriptor<Type, Ret(Class:: *)(Args...) const> {
|
struct meta_function_descriptor<Type, Ret (Class::*)(Args...) const> {
|
||||||
/*! @brief Meta function return type. */
|
/*! @brief Meta function return type. */
|
||||||
using return_type = Ret;
|
using return_type = Ret;
|
||||||
/*! @brief Meta function arguments. */
|
/*! @brief Meta function arguments. */
|
||||||
using args_type = std::conditional_t<std::is_same_v<Type, Class>, type_list<Args...>, type_list<const Class &, Args...>>;
|
using args_type = std::conditional_t<std::is_base_of_v<Class, Type>, type_list<Args...>, type_list<const Class &, Args...>>;
|
||||||
|
|
||||||
/*! @brief True if the meta function is const, false otherwise. */
|
/*! @brief True if the meta function is const, false otherwise. */
|
||||||
static constexpr auto is_const = true;
|
static constexpr auto is_const = true;
|
||||||
/*! @brief True if the meta function is static, false otherwise. */
|
/*! @brief True if the meta function is static, false otherwise. */
|
||||||
static constexpr auto is_static = !std::is_same_v<Type, Class>;
|
static constexpr auto is_static = !std::is_base_of_v<Class, Type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta function descriptor.
|
* @brief Meta function descriptor.
|
||||||
* @tparam Type Reflected type to which the meta function is associated.
|
* @tparam Type Reflected type to which the meta function is associated.
|
||||||
@@ -50,31 +45,68 @@ struct meta_function_descriptor<Type, Ret(Class:: *)(Args...) const> {
|
|||||||
* @tparam Args Function arguments.
|
* @tparam Args Function arguments.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename Ret, typename Class, typename... Args>
|
template<typename Type, typename Ret, typename Class, typename... Args>
|
||||||
struct meta_function_descriptor<Type, Ret(Class:: *)(Args...)> {
|
struct meta_function_descriptor<Type, Ret (Class::*)(Args...)> {
|
||||||
/*! @brief Meta function return type. */
|
/*! @brief Meta function return type. */
|
||||||
using return_type = Ret;
|
using return_type = Ret;
|
||||||
/*! @brief Meta function arguments. */
|
/*! @brief Meta function arguments. */
|
||||||
using args_type = std::conditional_t<std::is_same_v<Type, Class>, type_list<Args...>, type_list<Class &, Args...>>;
|
using args_type = std::conditional_t<std::is_base_of_v<Class, Type>, type_list<Args...>, type_list<Class &, Args...>>;
|
||||||
|
|
||||||
/*! @brief True if the meta function is const, false otherwise. */
|
/*! @brief True if the meta function is const, false otherwise. */
|
||||||
static constexpr auto is_const = false;
|
static constexpr auto is_const = false;
|
||||||
/*! @brief True if the meta function is static, false otherwise. */
|
/*! @brief True if the meta function is static, false otherwise. */
|
||||||
static constexpr auto is_static = !std::is_same_v<Type, Class>;
|
static constexpr auto is_static = !std::is_base_of_v<Class, Type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Meta function descriptor.
|
||||||
|
* @tparam Type Reflected type to which the meta data is associated.
|
||||||
|
* @tparam Class Actual owner of the data member.
|
||||||
|
* @tparam Ret Data member type.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Ret, typename Class>
|
||||||
|
struct meta_function_descriptor<Type, Ret Class::*> {
|
||||||
|
/*! @brief Meta data return type. */
|
||||||
|
using return_type = Ret &;
|
||||||
|
/*! @brief Meta data arguments. */
|
||||||
|
using args_type = std::conditional_t<std::is_base_of_v<Class, Type>, type_list<>, type_list<Class &>>;
|
||||||
|
|
||||||
|
/*! @brief True if the meta data is const, false otherwise. */
|
||||||
|
static constexpr auto is_const = false;
|
||||||
|
/*! @brief True if the meta data is static, false otherwise. */
|
||||||
|
static constexpr auto is_static = !std::is_base_of_v<Class, Type>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta function descriptor.
|
* @brief Meta function descriptor.
|
||||||
* @tparam Type Reflected type to which the meta function is associated.
|
* @tparam Type Reflected type to which the meta function is associated.
|
||||||
* @tparam Ret Function return type.
|
* @tparam Ret Function return type.
|
||||||
* @tparam Args Function arguments.
|
* @tparam MaybeType First function argument.
|
||||||
|
* @tparam Args Other function arguments.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename Ret, typename... Args>
|
template<typename Type, typename Ret, typename MaybeType, typename... Args>
|
||||||
struct meta_function_descriptor<Type, Ret(*)(Args...)> {
|
struct meta_function_descriptor<Type, Ret (*)(MaybeType, Args...)> {
|
||||||
/*! @brief Meta function return type. */
|
/*! @brief Meta function return type. */
|
||||||
using return_type = Ret;
|
using return_type = Ret;
|
||||||
/*! @brief Meta function arguments. */
|
/*! @brief Meta function arguments. */
|
||||||
using args_type = type_list<Args...>;
|
using args_type = std::conditional_t<std::is_base_of_v<std::remove_cv_t<std::remove_reference_t<MaybeType>>, Type>, type_list<Args...>, type_list<MaybeType, Args...>>;
|
||||||
|
|
||||||
|
/*! @brief True if the meta function is const, false otherwise. */
|
||||||
|
static constexpr auto is_const = std::is_base_of_v<std::remove_cv_t<std::remove_reference_t<MaybeType>>, Type> && std::is_const_v<std::remove_reference_t<MaybeType>>;
|
||||||
|
/*! @brief True if the meta function is static, false otherwise. */
|
||||||
|
static constexpr auto is_static = !std::is_base_of_v<std::remove_cv_t<std::remove_reference_t<MaybeType>>, Type>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Meta function descriptor.
|
||||||
|
* @tparam Type Reflected type to which the meta function is associated.
|
||||||
|
* @tparam Ret Function return type.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Ret>
|
||||||
|
struct meta_function_descriptor<Type, Ret (*)()> {
|
||||||
|
/*! @brief Meta function return type. */
|
||||||
|
using return_type = Ret;
|
||||||
|
/*! @brief Meta function arguments. */
|
||||||
|
using args_type = type_list<>;
|
||||||
|
|
||||||
/*! @brief True if the meta function is const, false otherwise. */
|
/*! @brief True if the meta function is const, false otherwise. */
|
||||||
static constexpr auto is_const = false;
|
static constexpr auto is_const = false;
|
||||||
@@ -82,7 +114,6 @@ struct meta_function_descriptor<Type, Ret(*)(Args...)> {
|
|||||||
static constexpr auto is_static = true;
|
static constexpr auto is_static = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Meta function helper.
|
* @brief Meta function helper.
|
||||||
*
|
*
|
||||||
@@ -95,20 +126,25 @@ struct meta_function_descriptor<Type, Ret(*)(Args...)> {
|
|||||||
template<typename Type, typename Candidate>
|
template<typename Type, typename Candidate>
|
||||||
class meta_function_helper {
|
class meta_function_helper {
|
||||||
template<typename Ret, typename... Args, typename Class>
|
template<typename Ret, typename... Args, typename Class>
|
||||||
static constexpr meta_function_descriptor<Type, Ret(Class:: *)(Args...) const> get_rid_of_noexcept(Ret(Class:: *)(Args...) const);
|
static constexpr meta_function_descriptor<Type, Ret (Class::*)(Args...) const> get_rid_of_noexcept(Ret (Class::*)(Args...) const);
|
||||||
|
|
||||||
template<typename Ret, typename... Args, typename Class>
|
template<typename Ret, typename... Args, typename Class>
|
||||||
static constexpr meta_function_descriptor<Type, Ret(Class:: *)(Args...)> get_rid_of_noexcept(Ret(Class:: *)(Args...));
|
static constexpr meta_function_descriptor<Type, Ret (Class::*)(Args...)> get_rid_of_noexcept(Ret (Class::*)(Args...));
|
||||||
|
|
||||||
|
template<typename Ret, typename Class>
|
||||||
|
static constexpr meta_function_descriptor<Type, Ret Class::*> get_rid_of_noexcept(Ret Class::*);
|
||||||
|
|
||||||
template<typename Ret, typename... Args>
|
template<typename Ret, typename... Args>
|
||||||
static constexpr meta_function_descriptor<Type, Ret(*)(Args...)> get_rid_of_noexcept(Ret(*)(Args...));
|
static constexpr meta_function_descriptor<Type, Ret (*)(Args...)> get_rid_of_noexcept(Ret (*)(Args...));
|
||||||
|
|
||||||
|
template<typename Class>
|
||||||
|
static constexpr meta_function_descriptor<Class, decltype(&Class::operator())> get_rid_of_noexcept(Class);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief The meta function descriptor of the given function. */
|
/*! @brief The meta function descriptor of the given function. */
|
||||||
using type = decltype(get_rid_of_noexcept(std::declval<Candidate>()));
|
using type = decltype(get_rid_of_noexcept(std::declval<Candidate>()));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper type.
|
* @brief Helper type.
|
||||||
* @tparam Type Reflected type to which the meta function is associated.
|
* @tparam Type Reflected type to which the meta function is associated.
|
||||||
@@ -117,36 +153,38 @@ public:
|
|||||||
template<typename Type, typename Candidate>
|
template<typename Type, typename Candidate>
|
||||||
using meta_function_helper_t = typename meta_function_helper<Type, Candidate>::type;
|
using meta_function_helper_t = typename meta_function_helper<Type, Candidate>::type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wraps a value depending on the given policy.
|
||||||
|
* @tparam Policy Optional policy (no policy set by default).
|
||||||
|
* @tparam Type Type of value to wrap.
|
||||||
|
* @param value Value to wrap.
|
||||||
|
* @return A meta any containing the returned value, if any.
|
||||||
|
*/
|
||||||
|
template<typename Policy = as_is_t, typename Type>
|
||||||
|
meta_any meta_dispatch([[maybe_unused]] Type &&value) {
|
||||||
|
if constexpr(std::is_same_v<Policy, as_void_t>) {
|
||||||
|
return meta_any{std::in_place_type<void>};
|
||||||
|
} else if constexpr(std::is_same_v<Policy, as_ref_t>) {
|
||||||
|
return meta_any{std::in_place_type<Type>, std::forward<Type>(value)};
|
||||||
|
} else if constexpr(std::is_same_v<Policy, as_cref_t>) {
|
||||||
|
static_assert(std::is_lvalue_reference_v<Type>, "Invalid type");
|
||||||
|
return meta_any{std::in_place_type<const std::remove_reference_t<Type> &>, std::as_const(value)};
|
||||||
|
} else {
|
||||||
|
static_assert(std::is_same_v<Policy, as_is_t>, "Policy not supported");
|
||||||
|
return meta_any{std::forward<Type>(value)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the meta type of the i-th element of a list of arguments.
|
* @brief Returns the meta type of the i-th element of a list of arguments.
|
||||||
* @tparam Args Actual types of arguments.
|
* @tparam Type Type list of the actual types of arguments.
|
||||||
* @return The meta type of the i-th element of the list of arguments.
|
* @return The meta type of the i-th element of the list of arguments.
|
||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename Type>
|
||||||
[[nodiscard]] static meta_type meta_arg(type_list<Args...>, const std::size_t index) ENTT_NOEXCEPT {
|
[[nodiscard]] static meta_type meta_arg(const std::size_t index) ENTT_NOEXCEPT {
|
||||||
return internal::meta_arg_node(type_list<Args...>{}, index);
|
return internal::meta_arg_node(Type{}, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructs an instance given a list of erased parameters, if possible.
|
|
||||||
* @tparam Type Actual type of the instance to construct.
|
|
||||||
* @tparam Args Types of arguments expected.
|
|
||||||
* @tparam Index Indexes to use to extract erased arguments from their list.
|
|
||||||
* @param args Parameters to use to construct the instance.
|
|
||||||
* @return A meta any containing the new instance, if any.
|
|
||||||
*/
|
|
||||||
template<typename Type, typename... Args, std::size_t... Index>
|
|
||||||
[[nodiscard]] meta_any meta_construct(meta_any * const args, std::index_sequence<Index...>) {
|
|
||||||
if(((args+Index)->allow_cast<Args>() && ...)) {
|
|
||||||
return Type{(args+Index)->cast<Args>()...};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the value of a given variable.
|
* @brief Sets the value of a given variable.
|
||||||
* @tparam Type Reflected type to which the variable is associated.
|
* @tparam Type Reflected type to which the variable is associated.
|
||||||
@@ -158,26 +196,20 @@ template<typename Type, typename... Args, std::size_t... Index>
|
|||||||
template<typename Type, auto Data>
|
template<typename Type, auto Data>
|
||||||
[[nodiscard]] bool meta_setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) {
|
[[nodiscard]] bool meta_setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) {
|
||||||
if constexpr(!std::is_same_v<decltype(Data), Type> && !std::is_same_v<decltype(Data), std::nullptr_t>) {
|
if constexpr(!std::is_same_v<decltype(Data), Type> && !std::is_same_v<decltype(Data), std::nullptr_t>) {
|
||||||
if constexpr(std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
|
if constexpr(std::is_member_function_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
|
||||||
using data_type = type_list_element_t<1u, typename meta_function_helper_t<Type, decltype(Data)>::args_type>;
|
using descriptor = meta_function_helper_t<Type, decltype(Data)>;
|
||||||
|
using data_type = type_list_element_t<descriptor::is_static, typename descriptor::args_type>;
|
||||||
|
|
||||||
if(auto * const clazz = instance->try_cast<Type>(); clazz && value.allow_cast<data_type>()) {
|
if(auto *const clazz = instance->try_cast<Type>(); clazz && value.allow_cast<data_type>()) {
|
||||||
Data(*clazz, value.cast<data_type>());
|
std::invoke(Data, *clazz, value.cast<data_type>());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if constexpr(std::is_member_function_pointer_v<decltype(Data)>) {
|
|
||||||
using data_type = type_list_element_t<0u, typename meta_function_helper_t<Type, decltype(Data)>::args_type>;
|
|
||||||
|
|
||||||
if(auto * const clazz = instance->try_cast<Type>(); clazz && value.allow_cast<data_type>()) {
|
|
||||||
(clazz->*Data)(value.cast<data_type>());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
|
} else if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
|
||||||
using data_type = std::remove_reference_t<decltype(std::declval<Type>().*Data)>;
|
using data_type = std::remove_reference_t<typename meta_function_helper_t<Type, decltype(Data)>::return_type>;
|
||||||
|
|
||||||
if constexpr(!std::is_array_v<data_type> && !std::is_const_v<data_type>) {
|
if constexpr(!std::is_array_v<data_type> && !std::is_const_v<data_type>) {
|
||||||
if(auto * const clazz = instance->try_cast<Type>(); clazz && value.allow_cast<data_type>()) {
|
if(auto *const clazz = instance->try_cast<Type>(); clazz && value.allow_cast<data_type>()) {
|
||||||
clazz->*Data = value.cast<data_type>();
|
std::invoke(Data, *clazz) = value.cast<data_type>();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,30 +228,6 @@ template<typename Type, auto Data>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Wraps a value depending on the given policy.
|
|
||||||
* @tparam Policy Optional policy (no policy set by default).
|
|
||||||
* @tparam Type Type of value to wrap.
|
|
||||||
* @param value Value to wrap.
|
|
||||||
* @return A meta any containing the returned value.
|
|
||||||
*/
|
|
||||||
template<typename Policy = as_is_t, typename Type>
|
|
||||||
meta_any meta_dispatch(Type &&value) {
|
|
||||||
if constexpr(std::is_same_v<Policy, as_void_t>) {
|
|
||||||
return meta_any{std::in_place_type<void>, std::forward<Type>(value)};
|
|
||||||
} else if constexpr(std::is_same_v<Policy, as_ref_t>) {
|
|
||||||
return meta_any{std::in_place_type<Type>, std::forward<Type>(value)};
|
|
||||||
} else if constexpr(std::is_same_v<Policy, as_cref_t>) {
|
|
||||||
static_assert(std::is_lvalue_reference_v<Type>, "Invalid type");
|
|
||||||
return meta_any{std::in_place_type<const std::remove_reference_t<Type> &>, std::as_const(value)};
|
|
||||||
} else {
|
|
||||||
static_assert(std::is_same_v<Policy, as_is_t>, "Policy not supported");
|
|
||||||
return meta_any{std::forward<Type>(value)};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the value of a given variable.
|
* @brief Gets the value of a given variable.
|
||||||
* @tparam Type Reflected type to which the variable is associated.
|
* @tparam Type Reflected type to which the variable is associated.
|
||||||
@@ -230,18 +238,18 @@ meta_any meta_dispatch(Type &&value) {
|
|||||||
*/
|
*/
|
||||||
template<typename Type, auto Data, typename Policy = as_is_t>
|
template<typename Type, auto Data, typename Policy = as_is_t>
|
||||||
[[nodiscard]] meta_any meta_getter([[maybe_unused]] meta_handle instance) {
|
[[nodiscard]] meta_any meta_getter([[maybe_unused]] meta_handle instance) {
|
||||||
if constexpr(std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
|
if constexpr(std::is_member_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
|
||||||
auto * const clazz = instance->try_cast<std::conditional_t<std::is_invocable_v<decltype(Data), const Type &>, const Type, Type>>();
|
if constexpr(!std::is_array_v<std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<decltype(Data), Type &>>>>) {
|
||||||
return clazz ? meta_dispatch<Policy>(Data(*clazz)) : meta_any{};
|
if constexpr(std::is_invocable_v<decltype(Data), Type &>) {
|
||||||
} else if constexpr(std::is_member_function_pointer_v<decltype(Data)>) {
|
if(auto *clazz = instance->try_cast<Type>(); clazz) {
|
||||||
auto * const clazz = instance->try_cast<std::conditional_t<std::is_invocable_v<decltype(Data), const Type &>, const Type, Type>>();
|
return meta_dispatch<Policy>(std::invoke(Data, *clazz));
|
||||||
return clazz ? meta_dispatch<Policy>((clazz->*Data)()) : meta_any{};
|
}
|
||||||
} else if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
|
}
|
||||||
if constexpr(!std::is_array_v<std::remove_cv_t<std::remove_reference_t<decltype(std::declval<Type>().*Data)>>>) {
|
|
||||||
if(auto * clazz = instance->try_cast<Type>(); clazz) {
|
if constexpr(std::is_invocable_v<decltype(Data), const Type &>) {
|
||||||
return meta_dispatch<Policy>(clazz->*Data);
|
if(auto *fallback = instance->try_cast<const Type>(); fallback) {
|
||||||
} else if(auto * fallback = instance->try_cast<const Type>(); fallback) {
|
return meta_dispatch<Policy>(std::invoke(Data, *fallback));
|
||||||
return meta_dispatch<Policy>(fallback->*Data);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,77 +265,132 @@ template<typename Type, auto Data, typename Policy = as_is_t>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Invokes a function given a list of erased parameters, if possible.
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* @tparam Type Reflected type to which the function is associated.
|
* Internal details not to be documented.
|
||||||
* @tparam Candidate The actual function to invoke.
|
|
||||||
* @tparam Policy Optional policy (no policy set by default).
|
|
||||||
* @tparam Index Indexes to use to extract erased arguments from their list.
|
|
||||||
* @param instance An opaque instance of the underlying type, if required.
|
|
||||||
* @param args Parameters to use to invoke the function.
|
|
||||||
* @return A meta any containing the returned value, if any.
|
|
||||||
*/
|
*/
|
||||||
template<typename Type, auto Candidate, typename Policy = as_is_t, std::size_t... Index>
|
|
||||||
[[nodiscard]] std::enable_if_t<!std::is_invocable_v<decltype(Candidate)>, meta_any> meta_invoke([[maybe_unused]] meta_handle instance, meta_any *args, std::index_sequence<Index...>) {
|
|
||||||
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
|
|
||||||
|
|
||||||
const auto invoke = [](auto &&maybe_clazz, auto &&... other) {
|
namespace internal {
|
||||||
if constexpr(std::is_member_function_pointer_v<decltype(Candidate)>) {
|
|
||||||
if constexpr(std::is_void_v<typename descriptor::return_type>) {
|
|
||||||
(std::forward<decltype(maybe_clazz)>(maybe_clazz).*Candidate)(std::forward<decltype(other)>(other)...);
|
|
||||||
return meta_any{std::in_place_type<void>};
|
|
||||||
} else {
|
|
||||||
return meta_dispatch<Policy>((std::forward<decltype(maybe_clazz)>(maybe_clazz).*Candidate)(std::forward<decltype(other)>(other)...));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if constexpr(std::is_void_v<typename descriptor::return_type>) {
|
|
||||||
Candidate(std::forward<decltype(maybe_clazz)>(maybe_clazz), std::forward<decltype(other)>(other)...);
|
|
||||||
return meta_any{std::in_place_type<void>};
|
|
||||||
} else {
|
|
||||||
return meta_dispatch<Policy>(Candidate(std::forward<decltype(maybe_clazz)>(maybe_clazz), std::forward<decltype(other)>(other)...));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if constexpr(std::is_invocable_v<decltype(Candidate), const Type &, type_list_element_t<Index, typename descriptor::args_type>...>) {
|
template<typename Type, typename Policy, typename Candidate, typename... Args>
|
||||||
if(const auto * const clazz = instance->try_cast<const Type>(); clazz && ((args+Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
[[nodiscard]] meta_any meta_invoke_with_args(Candidate &&candidate, Args &&...args) {
|
||||||
return invoke(*clazz, (args+Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
if constexpr(std::is_same_v<std::invoke_result_t<decltype(candidate), Args...>, void>) {
|
||||||
|
std::invoke(candidate, args...);
|
||||||
|
return meta_any{std::in_place_type<void>};
|
||||||
|
} else {
|
||||||
|
return meta_dispatch<Policy>(std::invoke(candidate, args...));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Type, typename Policy, typename Candidate, std::size_t... Index>
|
||||||
|
[[nodiscard]] meta_any meta_invoke([[maybe_unused]] meta_handle instance, Candidate &&candidate, [[maybe_unused]] meta_any *args, std::index_sequence<Index...>) {
|
||||||
|
using descriptor = meta_function_helper_t<Type, std::remove_reference_t<Candidate>>;
|
||||||
|
|
||||||
|
if constexpr(std::is_invocable_v<std::remove_reference_t<Candidate>, const Type &, type_list_element_t<Index, typename descriptor::args_type>...>) {
|
||||||
|
if(const auto *const clazz = instance->try_cast<const Type>(); clazz && ((args + Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
||||||
|
return meta_invoke_with_args<Type, Policy>(std::forward<Candidate>(candidate), *clazz, (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
||||||
}
|
}
|
||||||
} else if constexpr(std::is_invocable_v<decltype(Candidate), Type &, type_list_element_t<Index, typename descriptor::args_type>...>) {
|
} else if constexpr(std::is_invocable_v<std::remove_reference_t<Candidate>, Type &, type_list_element_t<Index, typename descriptor::args_type>...>) {
|
||||||
if(auto * const clazz = instance->try_cast<Type>(); clazz && ((args+Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
if(auto *const clazz = instance->try_cast<Type>(); clazz && ((args + Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
||||||
return invoke(*clazz, (args+Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
return meta_invoke_with_args<Type, Policy>(std::forward<Candidate>(candidate), *clazz, (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(((args+Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
if(((args + Index)->allow_cast<type_list_element_t<Index, typename descriptor::args_type>>() && ...)) {
|
||||||
return invoke((args+Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
return meta_invoke_with_args<Type, Policy>(std::forward<Candidate>(candidate), (args + Index)->cast<type_list_element_t<Index, typename descriptor::args_type>>()...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta_any{};
|
return meta_any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Type, typename... Args, std::size_t... Index>
|
||||||
|
[[nodiscard]] meta_any meta_construct(meta_any *const args, std::index_sequence<Index...>) {
|
||||||
|
if(((args + Index)->allow_cast<Args>() && ...)) {
|
||||||
|
return meta_any{std::in_place_type<Type>, (args + Index)->cast<Args>()...};
|
||||||
|
}
|
||||||
|
|
||||||
|
return meta_any{};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Invokes a function given a list of erased parameters, if possible.
|
* Internal details not to be documented.
|
||||||
|
* @endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to _invoke_ an object given a list of erased parameters.
|
||||||
|
* @tparam Type Reflected type to which the object to _invoke_ is associated.
|
||||||
|
* @tparam Policy Optional policy (no policy set by default).
|
||||||
|
* @tparam Candidate The type of the actual object to _invoke_.
|
||||||
|
* @param instance An opaque instance of the underlying type, if required.
|
||||||
|
* @param candidate The actual object to _invoke_.
|
||||||
|
* @param args Parameters to use to _invoke_ the object.
|
||||||
|
* @return A meta any containing the returned value, if any.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Policy = as_is_t, typename Candidate>
|
||||||
|
[[nodiscard]] meta_any meta_invoke([[maybe_unused]] meta_handle instance, Candidate &&candidate, [[maybe_unused]] meta_any *const args) {
|
||||||
|
return internal::meta_invoke<Type, Policy>(std::move(instance), std::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to invoke a function given a list of erased parameters.
|
||||||
* @tparam Type Reflected type to which the function is associated.
|
* @tparam Type Reflected type to which the function is associated.
|
||||||
* @tparam Candidate The actual function to invoke.
|
* @tparam Candidate The actual function to invoke.
|
||||||
* @tparam Policy Optional policy (no policy set by default).
|
* @tparam Policy Optional policy (no policy set by default).
|
||||||
* @tparam Index Indexes to use to extract erased arguments from their list.
|
* @param instance An opaque instance of the underlying type, if required.
|
||||||
|
* @param args Parameters to use to invoke the function.
|
||||||
* @return A meta any containing the returned value, if any.
|
* @return A meta any containing the returned value, if any.
|
||||||
*/
|
*/
|
||||||
template<typename Type, auto Candidate, typename Policy = as_is_t, std::size_t... Index>
|
template<typename Type, auto Candidate, typename Policy = as_is_t>
|
||||||
[[nodiscard]] std::enable_if_t<std::is_invocable_v<decltype(Candidate)>, meta_any> meta_invoke(meta_handle, meta_any *, std::index_sequence<Index...>) {
|
[[nodiscard]] meta_any meta_invoke(meta_handle instance, meta_any *const args) {
|
||||||
if constexpr(std::is_void_v<decltype(Candidate())>) {
|
return internal::meta_invoke<Type, Policy>(std::move(instance), Candidate, args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<decltype(Candidate)>>::args_type::size>{});
|
||||||
Candidate();
|
}
|
||||||
return meta_any{std::in_place_type<void>};
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to construct an instance given a list of erased parameters.
|
||||||
|
* @tparam Type Actual type of the instance to construct.
|
||||||
|
* @tparam Args Types of arguments expected.
|
||||||
|
* @param args Parameters to use to construct the instance.
|
||||||
|
* @return A meta any containing the new instance, if any.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename... Args>
|
||||||
|
[[nodiscard]] meta_any meta_construct(meta_any *const args) {
|
||||||
|
return internal::meta_construct<Type, Args...>(args, std::index_sequence_for<Args...>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to construct an instance given a list of erased parameters.
|
||||||
|
* @tparam Type Reflected type to which the object to _invoke_ is associated.
|
||||||
|
* @tparam Policy Optional policy (no policy set by default).
|
||||||
|
* @tparam Candidate The type of the actual object to _invoke_.
|
||||||
|
* @param args Parameters to use to _invoke_ the object.
|
||||||
|
* @param candidate The actual object to _invoke_.
|
||||||
|
* @return A meta any containing the returned value, if any.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Policy = as_is_t, typename Candidate>
|
||||||
|
[[nodiscard]] meta_any meta_construct(Candidate &&candidate, meta_any *const args) {
|
||||||
|
if constexpr(meta_function_helper_t<Type, Candidate>::is_static) {
|
||||||
|
return internal::meta_invoke<Type, Policy>({}, std::forward<Candidate>(candidate), args, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
||||||
} else {
|
} else {
|
||||||
return meta_dispatch<Policy>(Candidate());
|
return internal::meta_invoke<Type, Policy>(*args, std::forward<Candidate>(candidate), args + 1u, std::make_index_sequence<meta_function_helper_t<Type, std::remove_reference_t<Candidate>>::args_type::size>{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to construct an instance given a list of erased parameters.
|
||||||
|
* @tparam Type Reflected type to which the function is associated.
|
||||||
|
* @tparam Candidate The actual function to invoke.
|
||||||
|
* @tparam Policy Optional policy (no policy set by default).
|
||||||
|
* @param args Parameters to use to invoke the function.
|
||||||
|
* @return A meta any containing the returned value, if any.
|
||||||
|
*/
|
||||||
|
template<typename Type, auto Candidate, typename Policy = as_is_t>
|
||||||
|
[[nodiscard]] meta_any meta_construct(meta_any *const args) {
|
||||||
|
return meta_construct<Type, Policy>(Candidate, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,37 +1,29 @@
|
|||||||
#ifndef ENTT_PLATFORM_ANDROID_NDK_R17_HPP
|
#ifndef ENTT_PLATFORM_ANDROID_NDK_R17_HPP
|
||||||
#define ENTT_PLATFORM_ANDROID_NDK_R17_HPP
|
#define ENTT_PLATFORM_ANDROID_NDK_R17_HPP
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @cond TURN_OFF_DOXYGEN
|
* @cond TURN_OFF_DOXYGEN
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#include <android/ndk-version.h>
|
# include <android/ndk-version.h>
|
||||||
#if __NDK_MAJOR__ == 17
|
# if __NDK_MAJOR__ == 17
|
||||||
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
|
# include <functional>
|
||||||
|
# include <type_traits>
|
||||||
|
# include <utility>
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
||||||
template<typename Func, typename... Args>
|
template<typename Func, typename... Args>
|
||||||
constexpr auto is_invocable(int) -> decltype(std::invoke(std::declval<Func>(), std::declval<Args>()...), std::true_type{});
|
constexpr auto is_invocable(int) -> decltype(std::invoke(std::declval<Func>(), std::declval<Args>()...), std::true_type{});
|
||||||
|
|
||||||
|
|
||||||
template<typename, typename...>
|
template<typename, typename...>
|
||||||
constexpr std::false_type is_invocable(...);
|
constexpr std::false_type is_invocable(...);
|
||||||
|
|
||||||
|
|
||||||
template<typename Ret, typename Func, typename... Args>
|
template<typename Ret, typename Func, typename... Args>
|
||||||
constexpr auto is_invocable_r(int)
|
constexpr auto is_invocable_r(int)
|
||||||
-> std::enable_if_t<decltype(std::is_convertible_v<decltype(std::invoke(std::declval<Func>(), std::declval<Args>()...)), Ret>, std::true_type>;
|
-> std::enable_if_t<decltype(std::is_convertible_v<decltype(std::invoke(std::declval<Func>(), std::declval<Args>()...)), Ret>, std::true_type>;
|
||||||
@@ -40,47 +32,36 @@ constexpr auto is_invocable_r(int)
|
|||||||
template<typename, typename, typename...>
|
template<typename, typename, typename...>
|
||||||
constexpr std::false_type is_invocable_r(...);
|
constexpr std::false_type is_invocable_r(...);
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Func, typename... Args>
|
template<typename Func, typename... Args>
|
||||||
struct is_invocable: decltype(internal::is_invocable<Func, Args...>(0)) {};
|
struct is_invocable: decltype(internal::is_invocable<Func, Args...>(0)) {};
|
||||||
|
|
||||||
|
|
||||||
template<typename Func, typename... Argsv>
|
template<typename Func, typename... Argsv>
|
||||||
inline constexpr bool is_invocable_v = std::is_invocable<Func, Args...>::value;
|
inline constexpr bool is_invocable_v = std::is_invocable<Func, Args...>::value;
|
||||||
|
|
||||||
|
|
||||||
template<typename Ret, typename Func, typename... Args>
|
template<typename Ret, typename Func, typename... Args>
|
||||||
struct is_invocable_r: decltype(internal::is_invocable_r<Ret, Func, Args...>(0)) {};
|
struct is_invocable_r: decltype(internal::is_invocable_r<Ret, Func, Args...>(0)) {};
|
||||||
|
|
||||||
|
|
||||||
template<typename Ret, typename Func, typename... Args>
|
template<typename Ret, typename Func, typename... Args>
|
||||||
inline constexpr bool is_invocable_r_v = std::is_invocable_r<Ret, Func, Args...>::value;
|
inline constexpr bool is_invocable_r_v = std::is_invocable_r<Ret, Func, Args...>::value;
|
||||||
|
|
||||||
|
template<typename Func, typename... Args>
|
||||||
template<typename Func, typename...Args>
|
|
||||||
struct invoke_result {
|
struct invoke_result {
|
||||||
using type = decltype(std::invoke(std::declval<Func>(), std::declval<Args>()...));
|
using type = decltype(std::invoke(std::declval<Func>(), std::declval<Args>()...));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename Func, typename... Args>
|
template<typename Func, typename... Args>
|
||||||
using invoke_result_t = typename std::invoke_result<Func, Args...>::type;
|
using invoke_result_t = typename std::invoke_result<Func, Args...>::type;
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
}
|
# endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal details not to be documented.
|
* Internal details not to be documented.
|
||||||
* @endcond
|
* @endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,26 +1,21 @@
|
|||||||
#ifndef ENTT_POLY_FWD_HPP
|
#ifndef ENTT_POLY_FWD_HPP
|
||||||
#define ENTT_POLY_FWD_HPP
|
#define ENTT_POLY_FWD_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
template<typename, std::size_t Len = sizeof(double[2]), std::size_t = alignof(typename std::aligned_storage_t<Len + !Len>)>
|
||||||
template<typename, std::size_t Len, std::size_t = alignof(typename std::aligned_storage_t<Len + !Len>)>
|
|
||||||
class basic_poly;
|
class basic_poly;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Alias declaration for the most common use case.
|
* @brief Alias declaration for the most common use case.
|
||||||
* @tparam Concept Concept descriptor.
|
* @tparam Concept Concept descriptor.
|
||||||
*/
|
*/
|
||||||
template<typename Concept>
|
template<typename Concept>
|
||||||
using poly = basic_poly<Concept, sizeof(double[2])>;
|
using poly = basic_poly<Concept>;
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef ENTT_POLY_POLY_HPP
|
#ifndef ENTT_POLY_POLY_HPP
|
||||||
#define ENTT_POLY_POLY_HPP
|
#define ENTT_POLY_POLY_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@@ -13,17 +12,15 @@
|
|||||||
#include "../core/type_traits.hpp"
|
#include "../core/type_traits.hpp"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Inspector class used to infer the type of the virtual table. */
|
/*! @brief Inspector class used to infer the type of the virtual table. */
|
||||||
struct poly_inspector {
|
struct poly_inspector {
|
||||||
/**
|
/**
|
||||||
* @brief Generic conversion operator (definition only).
|
* @brief Generic conversion operator (definition only).
|
||||||
* @tparam Type Type to which conversion is requested.
|
* @tparam Type Type to which conversion is requested.
|
||||||
*/
|
*/
|
||||||
template <class Type>
|
template<class Type>
|
||||||
operator Type &&() const;
|
operator Type &&() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,15 +30,14 @@ struct poly_inspector {
|
|||||||
* @param args The arguments to pass to the function.
|
* @param args The arguments to pass to the function.
|
||||||
* @return A poly inspector convertible to any type.
|
* @return A poly inspector convertible to any type.
|
||||||
*/
|
*/
|
||||||
template<auto Member, typename... Args>
|
template<std::size_t Member, typename... Args>
|
||||||
poly_inspector invoke(Args &&... args) const;
|
poly_inspector invoke(Args &&...args) const;
|
||||||
|
|
||||||
/*! @copydoc invoke */
|
/*! @copydoc invoke */
|
||||||
template<auto Member, typename... Args>
|
template<std::size_t Member, typename... Args>
|
||||||
poly_inspector invoke(Args &&... args);
|
poly_inspector invoke(Args &&...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static virtual table factory.
|
* @brief Static virtual table factory.
|
||||||
* @tparam Concept Concept descriptor.
|
* @tparam Concept Concept descriptor.
|
||||||
@@ -53,35 +49,35 @@ class poly_vtable {
|
|||||||
using inspector = typename Concept::template type<poly_inspector>;
|
using inspector = typename Concept::template type<poly_inspector>;
|
||||||
|
|
||||||
template<typename Ret, typename... Args>
|
template<typename Ret, typename... Args>
|
||||||
static auto vtable_entry(Ret(*)(inspector &, Args...)) -> Ret(*)(basic_any<Len, Align> &, Args...);
|
static auto vtable_entry(Ret (*)(inspector &, Args...)) -> Ret (*)(basic_any<Len, Align> &, Args...);
|
||||||
|
|
||||||
template<typename Ret, typename... Args>
|
template<typename Ret, typename... Args>
|
||||||
static auto vtable_entry(Ret(*)(const inspector &, Args...)) -> Ret(*)(const basic_any<Len, Align> &, Args...);
|
static auto vtable_entry(Ret (*)(const inspector &, Args...)) -> Ret (*)(const basic_any<Len, Align> &, Args...);
|
||||||
|
|
||||||
template<typename Ret, typename... Args>
|
template<typename Ret, typename... Args>
|
||||||
static auto vtable_entry(Ret(*)(Args...)) -> Ret(*)(const basic_any<Len, Align> &, Args...);
|
static auto vtable_entry(Ret (*)(Args...)) -> Ret (*)(const basic_any<Len, Align> &, Args...);
|
||||||
|
|
||||||
template<typename Ret, typename... Args>
|
template<typename Ret, typename... Args>
|
||||||
static auto vtable_entry(Ret(inspector:: *)(Args...)) -> Ret(*)(basic_any<Len, Align> &, Args...);
|
static auto vtable_entry(Ret (inspector::*)(Args...)) -> Ret (*)(basic_any<Len, Align> &, Args...);
|
||||||
|
|
||||||
template<typename Ret, typename... Args>
|
template<typename Ret, typename... Args>
|
||||||
static auto vtable_entry(Ret(inspector:: *)(Args...) const) -> Ret(*)(const basic_any<Len, Align> &, Args...);
|
static auto vtable_entry(Ret (inspector::*)(Args...) const) -> Ret (*)(const basic_any<Len, Align> &, Args...);
|
||||||
|
|
||||||
template<auto... Candidate>
|
template<auto... Candidate>
|
||||||
static auto make_vtable(value_list<Candidate...>)
|
static auto make_vtable(value_list<Candidate...>) ENTT_NOEXCEPT
|
||||||
-> decltype(std::make_tuple(vtable_entry(Candidate)...));
|
-> decltype(std::make_tuple(vtable_entry(Candidate)...));
|
||||||
|
|
||||||
template<typename... Func>
|
template<typename... Func>
|
||||||
[[nodiscard]] static constexpr auto make_vtable(type_list<Func...>) {
|
[[nodiscard]] static constexpr auto make_vtable(type_list<Func...>) ENTT_NOEXCEPT {
|
||||||
if constexpr(sizeof...(Func) == 0) {
|
if constexpr(sizeof...(Func) == 0u) {
|
||||||
return decltype(make_vtable(typename Concept::template impl<inspector>{})){};
|
return decltype(make_vtable(typename Concept::template impl<inspector>{})){};
|
||||||
} else if constexpr((std::is_function_v<Func> && ...)) {
|
} else if constexpr((std::is_function_v<Func> && ...)) {
|
||||||
return decltype(std::make_tuple(vtable_entry(std::declval<Func inspector:: *>())...)){};
|
return decltype(std::make_tuple(vtable_entry(std::declval<Func inspector::*>())...)){};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type, auto Candidate, typename Ret, typename Any, typename... Args>
|
template<typename Type, auto Candidate, typename Ret, typename Any, typename... Args>
|
||||||
static void fill_vtable_entry(Ret(* &entry)(Any &, Args...)) {
|
static void fill_vtable_entry(Ret (*&entry)(Any &, Args...)) ENTT_NOEXCEPT {
|
||||||
if constexpr(std::is_invocable_r_v<Ret, decltype(Candidate), Args...>) {
|
if constexpr(std::is_invocable_r_v<Ret, decltype(Candidate), Args...>) {
|
||||||
entry = +[](Any &, Args... args) -> Ret {
|
entry = +[](Any &, Args... args) -> Ret {
|
||||||
return std::invoke(Candidate, std::forward<Args>(args)...);
|
return std::invoke(Candidate, std::forward<Args>(args)...);
|
||||||
@@ -94,15 +90,18 @@ class poly_vtable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type, auto... Index>
|
template<typename Type, auto... Index>
|
||||||
[[nodiscard]] static auto fill_vtable(std::index_sequence<Index...>) {
|
[[nodiscard]] static auto fill_vtable(std::index_sequence<Index...>) ENTT_NOEXCEPT {
|
||||||
type impl{};
|
vtable_type impl{};
|
||||||
(fill_vtable_entry<Type, value_list_element_v<Index, typename Concept::template impl<Type>>>(std::get<Index>(impl)), ...);
|
(fill_vtable_entry<Type, value_list_element_v<Index, typename Concept::template impl<Type>>>(std::get<Index>(impl)), ...);
|
||||||
return impl;
|
return impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using vtable_type = decltype(make_vtable(Concept{}));
|
||||||
|
static constexpr bool is_mono_v = std::tuple_size_v<vtable_type> == 1u;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief Virtual table type. */
|
/*! @brief Virtual table type. */
|
||||||
using type = decltype(make_vtable(Concept{}));
|
using type = std::conditional_t<is_mono_v, std::tuple_element_t<0u, vtable_type>, const vtable_type *>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a static virtual table for a specific concept and type.
|
* @brief Returns a static virtual table for a specific concept and type.
|
||||||
@@ -110,14 +109,18 @@ public:
|
|||||||
* @return A static virtual table for the given concept and type.
|
* @return A static virtual table for the given concept and type.
|
||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
[[nodiscard]] static const auto * instance() {
|
[[nodiscard]] static type instance() ENTT_NOEXCEPT {
|
||||||
static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Type differs from its decayed form");
|
static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Type differs from its decayed form");
|
||||||
static const auto vtable = fill_vtable<Type>(std::make_index_sequence<Concept::template impl<Type>::size>{});
|
static const vtable_type vtable = fill_vtable<Type>(std::make_index_sequence<Concept::template impl<Type>::size>{});
|
||||||
return &vtable;
|
|
||||||
|
if constexpr(is_mono_v) {
|
||||||
|
return std::get<0>(vtable);
|
||||||
|
} else {
|
||||||
|
return &vtable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Poly base class used to inject functionalities into concepts.
|
* @brief Poly base class used to inject functionalities into concepts.
|
||||||
* @tparam Poly The outermost poly class.
|
* @tparam Poly The outermost poly class.
|
||||||
@@ -132,21 +135,31 @@ struct poly_base {
|
|||||||
* @param args The arguments to pass to the function.
|
* @param args The arguments to pass to the function.
|
||||||
* @return The return value of the invoked function, if any.
|
* @return The return value of the invoked function, if any.
|
||||||
*/
|
*/
|
||||||
template<auto Member, typename... Args>
|
template<std::size_t Member, typename... Args>
|
||||||
[[nodiscard]] decltype(auto) invoke(const poly_base &self, Args &&... args) const {
|
[[nodiscard]] decltype(auto) invoke(const poly_base &self, Args &&...args) const {
|
||||||
const auto &poly = static_cast<const Poly &>(self);
|
const auto &poly = static_cast<const Poly &>(self);
|
||||||
return std::get<Member>(*poly.vtable)(poly.storage, std::forward<Args>(args)...);
|
|
||||||
|
if constexpr(std::is_function_v<std::remove_pointer_t<decltype(poly.vtable)>>) {
|
||||||
|
return poly.vtable(poly.storage, std::forward<Args>(args)...);
|
||||||
|
} else {
|
||||||
|
return std::get<Member>(*poly.vtable)(poly.storage, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc invoke */
|
/*! @copydoc invoke */
|
||||||
template<auto Member, typename... Args>
|
template<std::size_t Member, typename... Args>
|
||||||
[[nodiscard]] decltype(auto) invoke(poly_base &self, Args &&... args) {
|
[[nodiscard]] decltype(auto) invoke(poly_base &self, Args &&...args) {
|
||||||
auto &poly = static_cast<Poly &>(self);
|
auto &poly = static_cast<Poly &>(self);
|
||||||
return std::get<Member>(*poly.vtable)(poly.storage, std::forward<Args>(args)...);
|
|
||||||
|
if constexpr(std::is_function_v<std::remove_pointer_t<decltype(poly.vtable)>>) {
|
||||||
|
static_assert(Member == 0u, "Unknown member");
|
||||||
|
return poly.vtable(poly.storage, std::forward<Args>(args)...);
|
||||||
|
} else {
|
||||||
|
return std::get<Member>(*poly.vtable)(poly.storage, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Shortcut for calling `poly_base<Type>::invoke`.
|
* @brief Shortcut for calling `poly_base<Type>::invoke`.
|
||||||
* @tparam Member Index of the function to invoke.
|
* @tparam Member Index of the function to invoke.
|
||||||
@@ -156,12 +169,11 @@ struct poly_base {
|
|||||||
* @param args The arguments to pass to the function.
|
* @param args The arguments to pass to the function.
|
||||||
* @return The return value of the invoked function, if any.
|
* @return The return value of the invoked function, if any.
|
||||||
*/
|
*/
|
||||||
template<auto Member, typename Poly, typename... Args>
|
template<std::size_t Member, typename Poly, typename... Args>
|
||||||
decltype(auto) poly_call(Poly &&self, Args &&... args) {
|
decltype(auto) poly_call(Poly &&self, Args &&...args) {
|
||||||
return std::forward<Poly>(self).template invoke<Member>(self, std::forward<Args>(args)...);
|
return std::forward<Poly>(self).template invoke<Member>(self, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static polymorphism made simple and within everyone's reach.
|
* @brief Static polymorphism made simple and within everyone's reach.
|
||||||
*
|
*
|
||||||
@@ -182,17 +194,16 @@ class basic_poly: private Concept::template type<poly_base<basic_poly<Concept, L
|
|||||||
/*! @brief A poly base is allowed to snoop into a poly object. */
|
/*! @brief A poly base is allowed to snoop into a poly object. */
|
||||||
friend struct poly_base<basic_poly>;
|
friend struct poly_base<basic_poly>;
|
||||||
|
|
||||||
using vtable_type = typename poly_vtable<Concept, Len, Align>::type;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*! @brief Concept type. */
|
/*! @brief Concept type. */
|
||||||
using concept_type = typename Concept::template type<poly_base<basic_poly>>;
|
using concept_type = typename Concept::template type<poly_base<basic_poly>>;
|
||||||
|
/*! @brief Virtual table type. */
|
||||||
|
using vtable_type = typename poly_vtable<Concept, Len, Align>::type;
|
||||||
|
|
||||||
/*! @brief Default constructor. */
|
/*! @brief Default constructor. */
|
||||||
basic_poly() ENTT_NOEXCEPT
|
basic_poly() ENTT_NOEXCEPT
|
||||||
: storage{},
|
: storage{},
|
||||||
vtable{}
|
vtable{} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a poly by directly initializing the new object.
|
* @brief Constructs a poly by directly initializing the new object.
|
||||||
@@ -201,10 +212,9 @@ public:
|
|||||||
* @param args Parameters to use to construct the instance.
|
* @param args Parameters to use to construct the instance.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename... Args>
|
template<typename Type, typename... Args>
|
||||||
explicit basic_poly(std::in_place_type_t<Type>, Args &&... args)
|
explicit basic_poly(std::in_place_type_t<Type>, Args &&...args)
|
||||||
: storage{std::in_place_type<Type>, std::forward<Args>(args)...},
|
: storage{std::in_place_type<Type>, std::forward<Args>(args)...},
|
||||||
vtable{poly_vtable<Concept, Len, Align>::template instance<std::remove_const_t<std::remove_reference_t<Type>>>()}
|
vtable{poly_vtable<Concept, Len, Align>::template instance<std::remove_cv_t<std::remove_reference_t<Type>>>()} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a poly from a given value.
|
* @brief Constructs a poly from a given value.
|
||||||
@@ -213,40 +223,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, basic_poly>>>
|
template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, basic_poly>>>
|
||||||
basic_poly(Type &&value) ENTT_NOEXCEPT
|
basic_poly(Type &&value) ENTT_NOEXCEPT
|
||||||
: basic_poly{std::in_place_type<std::remove_cv_t<std::remove_reference_t<Type>>>, std::forward<Type>(value)}
|
: basic_poly{std::in_place_type<std::remove_cv_t<std::remove_reference_t<Type>>>, std::forward<Type>(value)} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copy constructor.
|
* @brief Returns the object type if any, `type_id<void>()` otherwise.
|
||||||
* @param other The instance to copy from.
|
* @return The object type if any, `type_id<void>()` otherwise.
|
||||||
*/
|
*/
|
||||||
basic_poly(const basic_poly &other) = default;
|
[[nodiscard]] const type_info &type() const ENTT_NOEXCEPT {
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Move constructor.
|
|
||||||
* @param other The instance to move from.
|
|
||||||
*/
|
|
||||||
basic_poly(basic_poly &&other) ENTT_NOEXCEPT
|
|
||||||
: basic_poly{}
|
|
||||||
{
|
|
||||||
swap(*this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Assignment operator.
|
|
||||||
* @param other The instance to assign from.
|
|
||||||
* @return This poly object.
|
|
||||||
*/
|
|
||||||
basic_poly & operator=(basic_poly other) {
|
|
||||||
swap(other, *this);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the type of the contained object.
|
|
||||||
* @return The type of the contained object, if any.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] type_info type() const ENTT_NOEXCEPT {
|
|
||||||
return storage.type();
|
return storage.type();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,12 +237,12 @@ public:
|
|||||||
* @brief Returns an opaque pointer to the contained instance.
|
* @brief Returns an opaque pointer to the contained instance.
|
||||||
* @return An opaque pointer the contained instance, if any.
|
* @return An opaque pointer the contained instance, if any.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const void * data() const ENTT_NOEXCEPT {
|
[[nodiscard]] const void *data() const ENTT_NOEXCEPT {
|
||||||
return storage.data();
|
return storage.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc data */
|
/*! @copydoc data */
|
||||||
[[nodiscard]] void * data() ENTT_NOEXCEPT {
|
[[nodiscard]] void *data() ENTT_NOEXCEPT {
|
||||||
return storage.data();
|
return storage.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,13 +253,15 @@ public:
|
|||||||
* @param args Parameters to use to construct the instance.
|
* @param args Parameters to use to construct the instance.
|
||||||
*/
|
*/
|
||||||
template<typename Type, typename... Args>
|
template<typename Type, typename... Args>
|
||||||
void emplace(Args &&... args) {
|
void emplace(Args &&...args) {
|
||||||
*this = basic_poly{std::in_place_type<Type>, std::forward<Args>(args)...};
|
storage.template emplace<Type>(std::forward<Args>(args)...);
|
||||||
|
vtable = poly_vtable<Concept, Len, Align>::template instance<std::remove_cv_t<std::remove_reference_t<Type>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @brief Destroys contained object */
|
/*! @brief Destroys contained object */
|
||||||
void reset() {
|
void reset() {
|
||||||
*this = basic_poly{};
|
storage.reset();
|
||||||
|
vtable = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -284,40 +269,30 @@ public:
|
|||||||
* @return False if the poly is empty, true otherwise.
|
* @return False if the poly is empty, true otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
|
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
|
||||||
return !(vtable == nullptr);
|
return static_cast<bool>(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a pointer to the underlying concept.
|
* @brief Returns a pointer to the underlying concept.
|
||||||
* @return A pointer to the underlying concept.
|
* @return A pointer to the underlying concept.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] concept_type * operator->() ENTT_NOEXCEPT {
|
[[nodiscard]] concept_type *operator->() ENTT_NOEXCEPT {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @copydoc operator-> */
|
/*! @copydoc operator-> */
|
||||||
[[nodiscard]] const concept_type * operator->() const ENTT_NOEXCEPT {
|
[[nodiscard]] const concept_type *operator->() const ENTT_NOEXCEPT {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Swaps two poly objects.
|
|
||||||
* @param lhs A valid poly object.
|
|
||||||
* @param rhs A valid poly object.
|
|
||||||
*/
|
|
||||||
friend void swap(basic_poly &lhs, basic_poly &rhs) {
|
|
||||||
using std::swap;
|
|
||||||
swap(lhs.storage, rhs.storage);
|
|
||||||
swap(lhs.vtable, rhs.vtable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Aliasing constructor.
|
* @brief Aliasing constructor.
|
||||||
* @return A poly that shares a reference to an unmanaged object.
|
* @return A poly that shares a reference to an unmanaged object.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] basic_poly as_ref() ENTT_NOEXCEPT {
|
[[nodiscard]] basic_poly as_ref() ENTT_NOEXCEPT {
|
||||||
basic_poly ref = std::as_const(*this).as_ref();
|
basic_poly ref{};
|
||||||
ref.storage = storage.as_ref();
|
ref.storage = storage.as_ref();
|
||||||
|
ref.vtable = vtable;
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,11 +306,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
basic_any<Len, Align> storage;
|
basic_any<Len, Align> storage;
|
||||||
const vtable_type *vtable;
|
vtable_type vtable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#ifndef ENTT_PROCESS_PROCESS_HPP
|
#ifndef ENTT_PROCESS_PROCESS_HPP
|
||||||
#define ENTT_PROCESS_PROCESS_HPP
|
#define ENTT_PROCESS_PROCESS_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <utility>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Base class for processes.
|
* @brief Base class for processes.
|
||||||
*
|
*
|
||||||
@@ -71,44 +69,44 @@ namespace entt {
|
|||||||
*/
|
*/
|
||||||
template<typename Derived, typename Delta>
|
template<typename Derived, typename Delta>
|
||||||
class process {
|
class process {
|
||||||
enum class state: unsigned int {
|
enum class state : std::uint8_t {
|
||||||
UNINITIALIZED = 0,
|
uninitialized = 0,
|
||||||
RUNNING,
|
running,
|
||||||
PAUSED,
|
paused,
|
||||||
SUCCEEDED,
|
succeeded,
|
||||||
FAILED,
|
failed,
|
||||||
ABORTED,
|
aborted,
|
||||||
FINISHED,
|
finished,
|
||||||
REJECTED
|
rejected
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Target = Derived>
|
template<typename Target = Derived>
|
||||||
auto next(std::integral_constant<state, state::UNINITIALIZED>)
|
auto next(std::integral_constant<state, state::uninitialized>)
|
||||||
-> decltype(std::declval<Target>().init(), void()) {
|
-> decltype(std::declval<Target>().init(), void()) {
|
||||||
static_cast<Target *>(this)->init();
|
static_cast<Target *>(this)->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Target = Derived>
|
template<typename Target = Derived>
|
||||||
auto next(std::integral_constant<state, state::RUNNING>, Delta delta, void *data)
|
auto next(std::integral_constant<state, state::running>, Delta delta, void *data)
|
||||||
-> decltype(std::declval<Target>().update(delta, data), void()) {
|
-> decltype(std::declval<Target>().update(delta, data), void()) {
|
||||||
static_cast<Target *>(this)->update(delta, data);
|
static_cast<Target *>(this)->update(delta, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Target = Derived>
|
template<typename Target = Derived>
|
||||||
auto next(std::integral_constant<state, state::SUCCEEDED>)
|
auto next(std::integral_constant<state, state::succeeded>)
|
||||||
-> decltype(std::declval<Target>().succeeded(), void()) {
|
-> decltype(std::declval<Target>().succeeded(), void()) {
|
||||||
static_cast<Target *>(this)->succeeded();
|
static_cast<Target *>(this)->succeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Target = Derived>
|
template<typename Target = Derived>
|
||||||
auto next(std::integral_constant<state, state::FAILED>)
|
auto next(std::integral_constant<state, state::failed>)
|
||||||
-> decltype(std::declval<Target>().failed(), void()) {
|
-> decltype(std::declval<Target>().failed(), void()) {
|
||||||
static_cast<Target *>(this)->failed();
|
static_cast<Target *>(this)->failed();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Target = Derived>
|
template<typename Target = Derived>
|
||||||
auto next(std::integral_constant<state, state::ABORTED>)
|
auto next(std::integral_constant<state, state::aborted>)
|
||||||
-> decltype(std::declval<Target>().aborted(), void()) {
|
-> decltype(std::declval<Target>().aborted(), void()) {
|
||||||
static_cast<Target *>(this)->aborted();
|
static_cast<Target *>(this)->aborted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +121,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
void succeed() ENTT_NOEXCEPT {
|
void succeed() ENTT_NOEXCEPT {
|
||||||
if(alive()) {
|
if(alive()) {
|
||||||
current = state::SUCCEEDED;
|
current = state::succeeded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +133,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
void fail() ENTT_NOEXCEPT {
|
void fail() ENTT_NOEXCEPT {
|
||||||
if(alive()) {
|
if(alive()) {
|
||||||
current = state::FAILED;
|
current = state::failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,8 +144,8 @@ protected:
|
|||||||
* running.
|
* running.
|
||||||
*/
|
*/
|
||||||
void pause() ENTT_NOEXCEPT {
|
void pause() ENTT_NOEXCEPT {
|
||||||
if(current == state::RUNNING) {
|
if(current == state::running) {
|
||||||
current = state::PAUSED;
|
current = state::paused;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,8 +156,8 @@ protected:
|
|||||||
* paused.
|
* paused.
|
||||||
*/
|
*/
|
||||||
void unpause() ENTT_NOEXCEPT {
|
void unpause() ENTT_NOEXCEPT {
|
||||||
if(current == state::PAUSED) {
|
if(current == state::paused) {
|
||||||
current = state::RUNNING;
|
current = state::running;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +166,7 @@ public:
|
|||||||
using delta_type = Delta;
|
using delta_type = Delta;
|
||||||
|
|
||||||
/*! @brief Default destructor. */
|
/*! @brief Default destructor. */
|
||||||
virtual ~process() {
|
virtual ~process() ENTT_NOEXCEPT {
|
||||||
static_assert(std::is_base_of_v<process, Derived>, "Incorrect use of the class template");
|
static_assert(std::is_base_of_v<process, Derived>, "Incorrect use of the class template");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +180,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void abort(const bool immediately = false) {
|
void abort(const bool immediately = false) {
|
||||||
if(alive()) {
|
if(alive()) {
|
||||||
current = state::ABORTED;
|
current = state::aborted;
|
||||||
|
|
||||||
if(immediately) {
|
if(immediately) {
|
||||||
tick({});
|
tick({});
|
||||||
@@ -195,7 +193,7 @@ public:
|
|||||||
* @return True if the process is still alive, false otherwise.
|
* @return True if the process is still alive, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool alive() const ENTT_NOEXCEPT {
|
[[nodiscard]] bool alive() const ENTT_NOEXCEPT {
|
||||||
return current == state::RUNNING || current == state::PAUSED;
|
return current == state::running || current == state::paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,7 +201,7 @@ public:
|
|||||||
* @return True if the process is terminated, false otherwise.
|
* @return True if the process is terminated, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool finished() const ENTT_NOEXCEPT {
|
[[nodiscard]] bool finished() const ENTT_NOEXCEPT {
|
||||||
return current == state::FINISHED;
|
return current == state::finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,7 +209,7 @@ public:
|
|||||||
* @return True if the process is paused, false otherwise.
|
* @return True if the process is paused, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool paused() const ENTT_NOEXCEPT {
|
[[nodiscard]] bool paused() const ENTT_NOEXCEPT {
|
||||||
return current == state::PAUSED;
|
return current == state::paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,7 +217,7 @@ public:
|
|||||||
* @return True if the process terminated with errors, false otherwise.
|
* @return True if the process terminated with errors, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool rejected() const ENTT_NOEXCEPT {
|
[[nodiscard]] bool rejected() const ENTT_NOEXCEPT {
|
||||||
return current == state::REJECTED;
|
return current == state::rejected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,13 +226,13 @@ public:
|
|||||||
* @param data Optional data.
|
* @param data Optional data.
|
||||||
*/
|
*/
|
||||||
void tick(const Delta delta, void *data = nullptr) {
|
void tick(const Delta delta, void *data = nullptr) {
|
||||||
switch (current) {
|
switch(current) {
|
||||||
case state::UNINITIALIZED:
|
case state::uninitialized:
|
||||||
next(std::integral_constant<state, state::UNINITIALIZED>{});
|
next(std::integral_constant<state, state::uninitialized>{});
|
||||||
current = state::RUNNING;
|
current = state::running;
|
||||||
break;
|
break;
|
||||||
case state::RUNNING:
|
case state::running:
|
||||||
next(std::integral_constant<state, state::RUNNING>{}, delta, data);
|
next(std::integral_constant<state, state::running>{}, delta, data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// suppress warnings
|
// suppress warnings
|
||||||
@@ -243,17 +241,17 @@ public:
|
|||||||
|
|
||||||
// if it's dead, it must be notified and removed immediately
|
// if it's dead, it must be notified and removed immediately
|
||||||
switch(current) {
|
switch(current) {
|
||||||
case state::SUCCEEDED:
|
case state::succeeded:
|
||||||
next(std::integral_constant<state, state::SUCCEEDED>{});
|
next(std::integral_constant<state, state::succeeded>{});
|
||||||
current = state::FINISHED;
|
current = state::finished;
|
||||||
break;
|
break;
|
||||||
case state::FAILED:
|
case state::failed:
|
||||||
next(std::integral_constant<state, state::FAILED>{});
|
next(std::integral_constant<state, state::failed>{});
|
||||||
current = state::REJECTED;
|
current = state::rejected;
|
||||||
break;
|
break;
|
||||||
case state::ABORTED:
|
case state::aborted:
|
||||||
next(std::integral_constant<state, state::ABORTED>{});
|
next(std::integral_constant<state, state::aborted>{});
|
||||||
current = state::REJECTED;
|
current = state::rejected;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// suppress warnings
|
// suppress warnings
|
||||||
@@ -262,10 +260,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
state current{state::UNINITIALIZED};
|
state current{state::uninitialized};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adaptor for lambdas and functors to turn them into processes.
|
* @brief Adaptor for lambdas and functors to turn them into processes.
|
||||||
*
|
*
|
||||||
@@ -313,9 +310,8 @@ struct process_adaptor: process<process_adaptor<Func, Delta>, Delta>, private Fu
|
|||||||
* @param args Parameters to use to initialize the actual process.
|
* @param args Parameters to use to initialize the actual process.
|
||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
process_adaptor(Args &&... args)
|
process_adaptor(Args &&...args)
|
||||||
: Func{std::forward<Args>(args)...}
|
: Func{std::forward<Args>(args)...} {}
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Updates a process and its internal state if required.
|
* @brief Updates a process and its internal state if required.
|
||||||
@@ -323,12 +319,14 @@ struct process_adaptor: process<process_adaptor<Func, Delta>, Delta>, private Fu
|
|||||||
* @param data Optional data.
|
* @param data Optional data.
|
||||||
*/
|
*/
|
||||||
void update(const Delta delta, void *data) {
|
void update(const Delta delta, void *data) {
|
||||||
Func::operator()(delta, data, [this]() { this->succeed(); }, [this]() { this->fail(); });
|
Func::operator()(
|
||||||
|
delta,
|
||||||
|
data,
|
||||||
|
[this]() { this->succeed(); },
|
||||||
|
[this]() { this->fail(); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
#ifndef ENTT_PROCESS_SCHEDULER_HPP
|
#ifndef ENTT_PROCESS_SCHEDULER_HPP
|
||||||
#define ENTT_PROCESS_SCHEDULER_HPP
|
#define ENTT_PROCESS_SCHEDULER_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
#include "process.hpp"
|
#include "process.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Cooperative scheduler for processes.
|
* @brief Cooperative scheduler for processes.
|
||||||
*
|
*
|
||||||
@@ -43,9 +41,9 @@ namespace entt {
|
|||||||
template<typename Delta>
|
template<typename Delta>
|
||||||
class scheduler {
|
class scheduler {
|
||||||
struct process_handler {
|
struct process_handler {
|
||||||
using instance_type = std::unique_ptr<void, void(*)(void *)>;
|
using instance_type = std::unique_ptr<void, void (*)(void *)>;
|
||||||
using update_fn_type = bool(process_handler &, Delta, void *);
|
using update_fn_type = bool(scheduler &, std::size_t, Delta, void *);
|
||||||
using abort_fn_type = void(process_handler &, bool);
|
using abort_fn_type = void(scheduler &, std::size_t, bool);
|
||||||
using next_type = std::unique_ptr<process_handler>;
|
using next_type = std::unique_ptr<process_handler>;
|
||||||
|
|
||||||
instance_type instance;
|
instance_type instance;
|
||||||
@@ -55,12 +53,11 @@ class scheduler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct continuation {
|
struct continuation {
|
||||||
continuation(process_handler *ref)
|
continuation(process_handler *ref) ENTT_NOEXCEPT
|
||||||
: handler{ref}
|
: handler{ref} {}
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename Proc, typename... Args>
|
template<typename Proc, typename... Args>
|
||||||
continuation then(Args &&... args) {
|
continuation then(Args &&...args) {
|
||||||
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>, "Invalid process type");
|
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>, "Invalid process type");
|
||||||
auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
||||||
handler->next.reset(new process_handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr});
|
handler->next.reset(new process_handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr});
|
||||||
@@ -78,17 +75,17 @@ class scheduler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Proc>
|
template<typename Proc>
|
||||||
[[nodiscard]] static bool update(process_handler &handler, const Delta delta, void *data) {
|
[[nodiscard]] static bool update(scheduler &owner, std::size_t pos, const Delta delta, void *data) {
|
||||||
auto *process = static_cast<Proc *>(handler.instance.get());
|
auto *process = static_cast<Proc *>(owner.handlers[pos].instance.get());
|
||||||
process->tick(delta, data);
|
process->tick(delta, data);
|
||||||
|
|
||||||
if(process->rejected()) {
|
if(process->rejected()) {
|
||||||
return true;
|
return true;
|
||||||
} else if(process->finished()) {
|
} else if(process->finished()) {
|
||||||
if(handler.next) {
|
if(auto &&handler = owner.handlers[pos]; handler.next) {
|
||||||
handler = std::move(*handler.next);
|
handler = std::move(*handler.next);
|
||||||
// forces the process to exit the uninitialized state
|
// forces the process to exit the uninitialized state
|
||||||
return handler.update(handler, {}, nullptr);
|
return handler.update(owner, pos, {}, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -98,8 +95,8 @@ class scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Proc>
|
template<typename Proc>
|
||||||
static void abort(process_handler &handler, const bool immediately) {
|
static void abort(scheduler &owner, std::size_t pos, const bool immediately) {
|
||||||
static_cast<Proc *>(handler.instance.get())->abort(immediately);
|
static_cast<Proc *>(owner.handlers[pos].instance.get())->abort(immediately);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Proc>
|
template<typename Proc>
|
||||||
@@ -118,7 +115,7 @@ public:
|
|||||||
scheduler(scheduler &&) = default;
|
scheduler(scheduler &&) = default;
|
||||||
|
|
||||||
/*! @brief Default move assignment operator. @return This scheduler. */
|
/*! @brief Default move assignment operator. @return This scheduler. */
|
||||||
scheduler & operator=(scheduler &&) = default;
|
scheduler &operator=(scheduler &&) = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Number of processes currently scheduled.
|
* @brief Number of processes currently scheduled.
|
||||||
@@ -172,13 +169,13 @@ public:
|
|||||||
* @return An opaque object to use to concatenate processes.
|
* @return An opaque object to use to concatenate processes.
|
||||||
*/
|
*/
|
||||||
template<typename Proc, typename... Args>
|
template<typename Proc, typename... Args>
|
||||||
auto attach(Args &&... args) {
|
auto attach(Args &&...args) {
|
||||||
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>, "Invalid process type");
|
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>, "Invalid process type");
|
||||||
auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
||||||
process_handler handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr};
|
auto &&ref = handlers.emplace_back(process_handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr});
|
||||||
// forces the process to exit the uninitialized state
|
// forces the process to exit the uninitialized state
|
||||||
handler.update(handler, {}, nullptr);
|
ref.update(*this, handlers.size() - 1u, {}, nullptr);
|
||||||
return continuation{&handlers.emplace_back(std::move(handler))};
|
return continuation{&handlers.back()};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,17 +247,14 @@ public:
|
|||||||
* @param data Optional data.
|
* @param data Optional data.
|
||||||
*/
|
*/
|
||||||
void update(const Delta delta, void *data = nullptr) {
|
void update(const Delta delta, void *data = nullptr) {
|
||||||
auto sz = handlers.size();
|
|
||||||
|
|
||||||
for(auto pos = handlers.size(); pos; --pos) {
|
for(auto pos = handlers.size(); pos; --pos) {
|
||||||
auto &handler = handlers[pos-1];
|
const auto curr = pos - 1u;
|
||||||
|
|
||||||
if(const auto dead = handler.update(handler, delta, data); dead) {
|
if(const auto dead = handlers[curr].update(*this, curr, delta, data); dead) {
|
||||||
std::swap(handler, handlers[--sz]);
|
std::swap(handlers[curr], handlers.back());
|
||||||
|
handlers.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handlers.erase(handlers.begin() + sz, handlers.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,23 +268,16 @@ public:
|
|||||||
* @param immediately Requests an immediate operation.
|
* @param immediately Requests an immediate operation.
|
||||||
*/
|
*/
|
||||||
void abort(const bool immediately = false) {
|
void abort(const bool immediately = false) {
|
||||||
decltype(handlers) exec;
|
for(auto pos = handlers.size(); pos; --pos) {
|
||||||
exec.swap(handlers);
|
const auto curr = pos - 1u;
|
||||||
|
handlers[curr].abort(*this, curr, immediately);
|
||||||
for(auto &&handler: exec) {
|
|
||||||
handler.abort(handler, immediately);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::move(handlers.begin(), handlers.end(), std::back_inserter(exec));
|
|
||||||
handlers.swap(exec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<process_handler> handlers{};
|
std::vector<process_handler> handlers{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,52 +1,288 @@
|
|||||||
#ifndef ENTT_RESOURCE_CACHE_HPP
|
#ifndef ENTT_RESOURCE_RESOURCE_CACHE_HPP
|
||||||
#define ENTT_RESOURCE_CACHE_HPP
|
#define ENTT_RESOURCE_RESOURCE_CACHE_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <functional>
|
||||||
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
|
#include "../container/dense_map.hpp"
|
||||||
|
#include "../core/compressed_pair.hpp"
|
||||||
#include "../core/fwd.hpp"
|
#include "../core/fwd.hpp"
|
||||||
#include "handle.hpp"
|
#include "../core/iterator.hpp"
|
||||||
#include "loader.hpp"
|
#include "../core/utility.hpp"
|
||||||
#include "fwd.hpp"
|
#include "fwd.hpp"
|
||||||
|
#include "loader.hpp"
|
||||||
|
#include "resource.hpp"
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @cond TURN_OFF_DOXYGEN
|
||||||
|
* Internal details not to be documented.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename Type, typename It>
|
||||||
|
class resource_cache_iterator final {
|
||||||
|
template<typename, typename>
|
||||||
|
friend class resource_cache_iterator;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using value_type = std::pair<id_type, resource<Type>>;
|
||||||
|
using pointer = input_iterator_pointer<value_type>;
|
||||||
|
using reference = value_type;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
|
||||||
|
resource_cache_iterator() ENTT_NOEXCEPT = default;
|
||||||
|
|
||||||
|
resource_cache_iterator(const It iter) ENTT_NOEXCEPT
|
||||||
|
: it{iter} {}
|
||||||
|
|
||||||
|
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
|
||||||
|
resource_cache_iterator(const resource_cache_iterator<std::remove_const_t<Type>, Other> &other) ENTT_NOEXCEPT
|
||||||
|
: it{other.it} {}
|
||||||
|
|
||||||
|
resource_cache_iterator &operator++() ENTT_NOEXCEPT {
|
||||||
|
return ++it, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
resource_cache_iterator operator++(int) ENTT_NOEXCEPT {
|
||||||
|
resource_cache_iterator orig = *this;
|
||||||
|
return ++(*this), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
resource_cache_iterator &operator--() ENTT_NOEXCEPT {
|
||||||
|
return --it, *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
resource_cache_iterator operator--(int) ENTT_NOEXCEPT {
|
||||||
|
resource_cache_iterator orig = *this;
|
||||||
|
return operator--(), orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
resource_cache_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
|
||||||
|
it += value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
resource_cache_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
resource_cache_iterator copy = *this;
|
||||||
|
return (copy += value);
|
||||||
|
}
|
||||||
|
|
||||||
|
resource_cache_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
|
||||||
|
return (*this += -value);
|
||||||
|
}
|
||||||
|
|
||||||
|
resource_cache_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
return (*this + -value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator[](const difference_type value) const ENTT_NOEXCEPT {
|
||||||
|
return {it[value].first, resource<Type>{it[value].second}};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||||
|
return (*this)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||||
|
return operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
friend std::ptrdiff_t operator-(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
friend bool operator==(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
friend bool operator<(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) ENTT_NOEXCEPT;
|
||||||
|
|
||||||
|
private:
|
||||||
|
It it;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
[[nodiscard]] std::ptrdiff_t operator-(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it - rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator==(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it == rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator!=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator<(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return lhs.it < rhs.it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator>(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return rhs < lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator<=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs > rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||||
|
[[nodiscard]] bool operator>=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
|
||||||
|
return !(lhs < rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Simple cache for resources of a given type.
|
* Internal details not to be documented.
|
||||||
*
|
* @endcond
|
||||||
* Minimal implementation of a cache for resources of a given type. It doesn't
|
|
||||||
* offer much functionalities but it's suitable for small or medium sized
|
|
||||||
* applications and can be freely inherited to add targeted functionalities for
|
|
||||||
* large sized applications.
|
|
||||||
*
|
|
||||||
* @tparam Resource Type of resources managed by a cache.
|
|
||||||
*/
|
*/
|
||||||
template<typename Resource>
|
|
||||||
struct resource_cache {
|
/**
|
||||||
|
* @brief Basic cache for resources of any type.
|
||||||
|
* @tparam Type Type of resources managed by a cache.
|
||||||
|
* @tparam Loader Type of loader used to create the resources.
|
||||||
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
||||||
|
*/
|
||||||
|
template<typename Type, typename Loader, typename Allocator>
|
||||||
|
class resource_cache {
|
||||||
|
using alloc_traits = typename std::allocator_traits<Allocator>;
|
||||||
|
static_assert(std::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
|
||||||
|
using container_allocator = typename alloc_traits::template rebind_alloc<std::pair<const id_type, typename Loader::result_type>>;
|
||||||
|
using container_type = dense_map<id_type, typename Loader::result_type, identity, std::equal_to<id_type>, container_allocator>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*! @brief Resource type. */
|
||||||
|
using value_type = Type;
|
||||||
/*! @brief Unsigned integer type. */
|
/*! @brief Unsigned integer type. */
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
/*! @brief Type of resources managed by a cache. */
|
/*! @brief Loader type. */
|
||||||
using resource_type = Resource;
|
using loader_type = Loader;
|
||||||
|
/*! @brief Allocator type. */
|
||||||
|
using allocator_type = Allocator;
|
||||||
|
/*! @brief Input iterator type. */
|
||||||
|
using iterator = internal::resource_cache_iterator<Type, typename container_type::iterator>;
|
||||||
|
/*! @brief Constant input iterator type. */
|
||||||
|
using const_iterator = internal::resource_cache_iterator<const Type, typename container_type::const_iterator>;
|
||||||
|
|
||||||
/*! @brief Default constructor. */
|
/*! @brief Default constructor. */
|
||||||
resource_cache() = default;
|
resource_cache()
|
||||||
|
: resource_cache{loader_type{}} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty cache with a given allocator.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
explicit resource_cache(const allocator_type &allocator)
|
||||||
|
: resource_cache{loader_type{}, allocator} {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs an empty cache with a given allocator and loader.
|
||||||
|
* @param callable The loader to use.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
explicit resource_cache(const loader_type &callable, const allocator_type &allocator = allocator_type{})
|
||||||
|
: pool{container_type{allocator}, callable} {}
|
||||||
|
|
||||||
|
/*! @brief Default copy constructor. */
|
||||||
|
resource_cache(const resource_cache &) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocator-extended copy constructor.
|
||||||
|
* @param other The instance to copy from.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
resource_cache(const resource_cache &other, const allocator_type &allocator)
|
||||||
|
: pool{std::piecewise_construct, std::forward_as_tuple(other.pool.first(), allocator), std::forward_as_tuple(other.pool.second())} {}
|
||||||
|
|
||||||
/*! @brief Default move constructor. */
|
/*! @brief Default move constructor. */
|
||||||
resource_cache(resource_cache &&) = default;
|
resource_cache(resource_cache &&) = default;
|
||||||
|
|
||||||
/*! @brief Default move assignment operator. @return This cache. */
|
/**
|
||||||
resource_cache & operator=(resource_cache &&) = default;
|
* @brief Allocator-extended move constructor.
|
||||||
|
* @param other The instance to move from.
|
||||||
|
* @param allocator The allocator to use.
|
||||||
|
*/
|
||||||
|
resource_cache(resource_cache &&other, const allocator_type &allocator)
|
||||||
|
: pool{std::piecewise_construct, std::forward_as_tuple(std::move(other.pool.first()), allocator), std::forward_as_tuple(std::move(other.pool.second()))} {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Number of resources managed by a cache.
|
* @brief Default copy assignment operator.
|
||||||
* @return Number of resources currently stored.
|
* @return This cache.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
resource_cache &operator=(const resource_cache &) = default;
|
||||||
return resources.size();
|
|
||||||
|
/**
|
||||||
|
* @brief Default move assignment operator.
|
||||||
|
* @return This cache.
|
||||||
|
*/
|
||||||
|
resource_cache &operator=(resource_cache &&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the associated allocator.
|
||||||
|
* @return The associated allocator.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
|
||||||
|
return pool.first().get_allocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the beginning.
|
||||||
|
*
|
||||||
|
* The returned iterator points to the first instance of the cache. If the
|
||||||
|
* cache is empty, the returned iterator will be equal to `end()`.
|
||||||
|
*
|
||||||
|
* @return An iterator to the first instance of the internal cache.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||||
|
return pool.first().begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cbegin */
|
||||||
|
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
|
||||||
|
return cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc begin */
|
||||||
|
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
|
||||||
|
return pool.first().begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to the end.
|
||||||
|
*
|
||||||
|
* The returned iterator points to the element following the last instance
|
||||||
|
* of the cache. Attempting to dereference the returned iterator results in
|
||||||
|
* undefined behavior.
|
||||||
|
*
|
||||||
|
* @return An iterator to the element following the last instance of the
|
||||||
|
* internal cache.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
|
||||||
|
return pool.first().end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc cend */
|
||||||
|
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
|
||||||
|
return cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @copydoc end */
|
||||||
|
[[nodiscard]] iterator end() ENTT_NOEXCEPT {
|
||||||
|
return pool.first().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,115 +290,79 @@ struct resource_cache {
|
|||||||
* @return True if the cache contains no resources, false otherwise.
|
* @return True if the cache contains no resources, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
|
||||||
return resources.empty();
|
return pool.first().empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clears a cache and discards all its resources.
|
* @brief Number of resources managed by a cache.
|
||||||
*
|
* @return Number of resources currently stored.
|
||||||
* Handles are not invalidated and the memory used by a resource isn't
|
|
||||||
* freed as long as at least a handle keeps the resource itself alive.
|
|
||||||
*/
|
*/
|
||||||
|
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
|
||||||
|
return pool.first().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @brief Clears a cache. */
|
||||||
void clear() ENTT_NOEXCEPT {
|
void clear() ENTT_NOEXCEPT {
|
||||||
resources.clear();
|
pool.first().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads the resource that corresponds to a given identifier.
|
* @brief Loads a resource, if its identifier does not exist.
|
||||||
*
|
*
|
||||||
* In case an identifier isn't already present in the cache, it loads its
|
* Arguments are forwarded directly to the loader and _consumed_ only if the
|
||||||
* resource and stores it aside for future uses. Arguments are forwarded
|
* resource doesn't already exist.
|
||||||
* directly to the loader in order to construct properly the requested
|
|
||||||
* resource.
|
|
||||||
*
|
|
||||||
* @note
|
|
||||||
* If the identifier is already present in the cache, this function does
|
|
||||||
* nothing and the arguments are simply discarded.
|
|
||||||
*
|
*
|
||||||
* @warning
|
* @warning
|
||||||
* If the resource cannot be loaded correctly, the returned handle will be
|
* If the resource isn't loaded correctly, the returned handle could be
|
||||||
* invalid and any use of it will result in undefined behavior.
|
* invalid and any use of it will result in undefined behavior.
|
||||||
*
|
*
|
||||||
* @tparam Loader Type of loader to use to load the resource if required.
|
|
||||||
* @tparam Args Types of arguments to use to load the resource if required.
|
* @tparam Args Types of arguments to use to load the resource if required.
|
||||||
* @param id Unique resource identifier.
|
* @param id Unique resource identifier.
|
||||||
* @param args Arguments to use to load the resource if required.
|
* @param args Arguments to use to load the resource if required.
|
||||||
|
* @return A pair consisting of an iterator to the inserted element (or to
|
||||||
|
* the element that prevented the insertion) and a bool denoting whether the
|
||||||
|
* insertion took place.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
std::pair<iterator, bool> load(const id_type id, Args &&...args) {
|
||||||
|
if(auto it = pool.first().find(id); it != pool.first().end()) {
|
||||||
|
return {it, false};
|
||||||
|
}
|
||||||
|
|
||||||
|
return pool.first().emplace(id, pool.second()(std::forward<Args>(args)...));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force loads a resource, if its identifier does not exist.
|
||||||
|
* @copydetails load
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
std::pair<iterator, bool> force_load(const id_type id, Args &&...args) {
|
||||||
|
return {pool.first().insert_or_assign(id, pool.second()(std::forward<Args>(args)...)).first, true};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a handle for a given resource identifier.
|
||||||
|
*
|
||||||
|
* @warning
|
||||||
|
* There is no guarantee that the returned handle is valid.<br/>
|
||||||
|
* If it is not, any use will result in indefinite behavior.
|
||||||
|
*
|
||||||
|
* @param id Unique resource identifier.
|
||||||
* @return A handle for the given resource.
|
* @return A handle for the given resource.
|
||||||
*/
|
*/
|
||||||
template<typename Loader, typename... Args>
|
[[nodiscard]] resource<const value_type> operator[](const id_type id) const {
|
||||||
resource_handle<Resource> load(const id_type id, Args &&... args) {
|
if(auto it = pool.first().find(id); it != pool.first().cend()) {
|
||||||
if(auto it = resources.find(id); it == resources.cend()) {
|
return resource<const value_type>{it->second};
|
||||||
if(auto handle = temp<Loader>(std::forward<Args>(args)...); handle) {
|
|
||||||
return (resources[id] = std::move(handle));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*! @copydoc operator[] */
|
||||||
* @brief Reloads a resource or loads it for the first time if not present.
|
[[nodiscard]] resource<value_type> operator[](const id_type id) {
|
||||||
*
|
if(auto it = pool.first().find(id); it != pool.first().end()) {
|
||||||
* Equivalent to the following snippet (pseudocode):
|
return resource<value_type>{it->second};
|
||||||
*
|
|
||||||
* @code{.cpp}
|
|
||||||
* cache.discard(id);
|
|
||||||
* cache.load(id, args...);
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* Arguments are forwarded directly to the loader in order to construct
|
|
||||||
* properly the requested resource.
|
|
||||||
*
|
|
||||||
* @warning
|
|
||||||
* If the resource cannot be loaded correctly, the returned handle will be
|
|
||||||
* invalid and any use of it will result in undefined behavior.
|
|
||||||
*
|
|
||||||
* @tparam Loader Type of loader to use to load the resource.
|
|
||||||
* @tparam Args Types of arguments to use to load the resource.
|
|
||||||
* @param id Unique resource identifier.
|
|
||||||
* @param args Arguments to use to load the resource.
|
|
||||||
* @return A handle for the given resource.
|
|
||||||
*/
|
|
||||||
template<typename Loader, typename... Args>
|
|
||||||
resource_handle<Resource> reload(const id_type id, Args &&... args) {
|
|
||||||
return (discard(id), load<Loader>(id, std::forward<Args>(args)...));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a temporary handle for a resource.
|
|
||||||
*
|
|
||||||
* Arguments are forwarded directly to the loader in order to construct
|
|
||||||
* properly the requested resource. The handle isn't stored aside and the
|
|
||||||
* cache isn't in charge of the lifetime of the resource itself.
|
|
||||||
*
|
|
||||||
* @tparam Loader Type of loader to use to load the resource.
|
|
||||||
* @tparam Args Types of arguments to use to load the resource.
|
|
||||||
* @param args Arguments to use to load the resource.
|
|
||||||
* @return A handle for the given resource.
|
|
||||||
*/
|
|
||||||
template<typename Loader, typename... Args>
|
|
||||||
[[nodiscard]] resource_handle<Resource> temp(Args &&... args) const {
|
|
||||||
return Loader{}.get(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a handle for a given resource identifier.
|
|
||||||
*
|
|
||||||
* A resource handle can be in a either valid or invalid state. In other
|
|
||||||
* terms, a resource handle is properly initialized with a resource if the
|
|
||||||
* cache contains the resource itself. Otherwise the returned handle is
|
|
||||||
* uninitialized and accessing it results in undefined behavior.
|
|
||||||
*
|
|
||||||
* @sa resource_handle
|
|
||||||
*
|
|
||||||
* @param id Unique resource identifier.
|
|
||||||
* @return A handle for the given resource.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] resource_handle<Resource> handle(const id_type id) const {
|
|
||||||
if(auto it = resources.find(id); it != resources.cend()) {
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@@ -174,64 +374,51 @@ struct resource_cache {
|
|||||||
* @return True if the cache contains the resource, false otherwise.
|
* @return True if the cache contains the resource, false otherwise.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool contains(const id_type id) const {
|
[[nodiscard]] bool contains(const id_type id) const {
|
||||||
return (resources.find(id) != resources.cend());
|
return pool.first().contains(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Discards the resource that corresponds to a given identifier.
|
* @brief Removes an element from a given position.
|
||||||
*
|
* @param pos An iterator to the element to remove.
|
||||||
* Handles are not invalidated and the memory used by the resource isn't
|
* @return An iterator following the removed element.
|
||||||
* freed as long as at least a handle keeps the resource itself alive.
|
*/
|
||||||
*
|
iterator erase(const_iterator pos) {
|
||||||
|
const auto it = pool.first().begin();
|
||||||
|
return pool.first().erase(it + (pos - const_iterator{it}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes the given elements from a cache.
|
||||||
|
* @param first An iterator to the first element of the range of elements.
|
||||||
|
* @param last An iterator past the last element of the range of elements.
|
||||||
|
* @return An iterator following the last removed element.
|
||||||
|
*/
|
||||||
|
iterator erase(const_iterator first, const_iterator last) {
|
||||||
|
const auto it = pool.first().begin();
|
||||||
|
return pool.first().erase(it + (first - const_iterator{it}), it + (last - const_iterator{it}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes the given elements from a cache.
|
||||||
* @param id Unique resource identifier.
|
* @param id Unique resource identifier.
|
||||||
|
* @return Number of resources erased (either 0 or 1).
|
||||||
*/
|
*/
|
||||||
void discard(const id_type id) {
|
size_type erase(const id_type id) {
|
||||||
if(auto it = resources.find(id); it != resources.end()) {
|
return pool.first().erase(id);
|
||||||
resources.erase(it);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Iterates all resources.
|
* @brief Returns the loader used to create resources.
|
||||||
*
|
* @return The loader used to create resources.
|
||||||
* The function object is invoked for each element. It is provided with
|
|
||||||
* either the resource identifier, the resource handle or both of them.<br/>
|
|
||||||
* The signature of the function must be equivalent to one of the following
|
|
||||||
* forms:
|
|
||||||
*
|
|
||||||
* @code{.cpp}
|
|
||||||
* void(const entt::id_type);
|
|
||||||
* void(entt::resource_handle<Resource>);
|
|
||||||
* void(const entt::id_type, entt::resource_handle<Resource>);
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* @tparam Func Type of the function object to invoke.
|
|
||||||
* @param func A valid function object.
|
|
||||||
*/
|
*/
|
||||||
template <typename Func>
|
[[nodiscard]] loader_type loader() const {
|
||||||
void each(Func func) const {
|
return pool.second();
|
||||||
auto begin = resources.begin();
|
|
||||||
auto end = resources.end();
|
|
||||||
|
|
||||||
while(begin != end) {
|
|
||||||
auto curr = begin++;
|
|
||||||
|
|
||||||
if constexpr(std::is_invocable_v<Func, id_type>) {
|
|
||||||
func(curr->first);
|
|
||||||
} else if constexpr(std::is_invocable_v<Func, resource_handle<Resource>>) {
|
|
||||||
func(curr->second);
|
|
||||||
} else {
|
|
||||||
func(curr->first, curr->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<id_type, resource_handle<Resource>> resources;
|
compressed_pair<container_type, loader_type> pool;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
#ifndef ENTT_RESOURCE_FWD_HPP
|
#ifndef ENTT_RESOURCE_FWD_HPP
|
||||||
#define ENTT_RESOURCE_FWD_HPP
|
#define ENTT_RESOURCE_FWD_HPP
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace entt {
|
namespace entt {
|
||||||
|
|
||||||
|
template<typename>
|
||||||
|
struct resource_loader;
|
||||||
|
|
||||||
|
template<typename Type, typename = resource_loader<Type>, typename = std::allocator<Type>>
|
||||||
|
class resource_cache;
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
struct resource_cache;
|
class resource;
|
||||||
|
|
||||||
|
|
||||||
template<typename>
|
|
||||||
class resource_handle;
|
|
||||||
|
|
||||||
|
|
||||||
template<typename, typename>
|
|
||||||
class resource_loader;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace entt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,189 +0,0 @@
|
|||||||
#ifndef ENTT_RESOURCE_HANDLE_HPP
|
|
||||||
#define ENTT_RESOURCE_HANDLE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <utility>
|
|
||||||
#include "../config/config.h"
|
|
||||||
#include "fwd.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace entt {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Shared resource handle.
|
|
||||||
*
|
|
||||||
* A shared resource handle is a small class that wraps a resource and keeps it
|
|
||||||
* alive even if it's deleted from the cache. It can be either copied or
|
|
||||||
* moved. A handle shares a reference to the same resource with all the other
|
|
||||||
* handles constructed for the same identifier.<br/>
|
|
||||||
* As a rule of thumb, resources should never be copied nor moved. Handles are
|
|
||||||
* the way to go to keep references to them.
|
|
||||||
*
|
|
||||||
* @tparam Resource Type of resource managed by a handle.
|
|
||||||
*/
|
|
||||||
template<typename Resource>
|
|
||||||
class resource_handle {
|
|
||||||
/*! @brief Resource handles are friends with each other. */
|
|
||||||
template<typename>
|
|
||||||
friend class resource_handle;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/*! @brief Default constructor. */
|
|
||||||
resource_handle() ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates a handle from a shared pointer, namely a resource.
|
|
||||||
* @param res A pointer to a properly initialized resource.
|
|
||||||
*/
|
|
||||||
resource_handle(std::shared_ptr<Resource> res) ENTT_NOEXCEPT
|
|
||||||
: resource{std::move(res)}
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Copy constructor.
|
|
||||||
* @param other The instance to copy from.
|
|
||||||
*/
|
|
||||||
resource_handle(const resource_handle<Resource> &other) ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Move constructor.
|
|
||||||
* @param other The instance to move from.
|
|
||||||
*/
|
|
||||||
resource_handle(resource_handle<Resource> &&other) ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Copy constructs a handle which shares ownership of the resource.
|
|
||||||
* @tparam Other Type of resource managed by the received handle.
|
|
||||||
* @param other The handle to copy from.
|
|
||||||
*/
|
|
||||||
template<typename Other, typename = std::enable_if_t<!std::is_same_v<Other, Resource> && std::is_base_of_v<Resource, Other>>>
|
|
||||||
resource_handle(const resource_handle<Other> &other) ENTT_NOEXCEPT
|
|
||||||
: resource{other.resource}
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Move constructs a handle which takes ownership of the resource.
|
|
||||||
* @tparam Other Type of resource managed by the received handle.
|
|
||||||
* @param other The handle to move from.
|
|
||||||
*/
|
|
||||||
template<typename Other, typename = std::enable_if_t<!std::is_same_v<Other, Resource> && std::is_base_of_v<Resource, Other>>>
|
|
||||||
resource_handle(resource_handle<Other> &&other) ENTT_NOEXCEPT
|
|
||||||
: resource{std::move(other.resource)}
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Copy assignment operator.
|
|
||||||
* @param other The instance to copy from.
|
|
||||||
* @return This resource handle.
|
|
||||||
*/
|
|
||||||
resource_handle & operator=(const resource_handle<Resource> &other) ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Move assignment operator.
|
|
||||||
* @param other The instance to move from.
|
|
||||||
* @return This resource handle.
|
|
||||||
*/
|
|
||||||
resource_handle & operator=(resource_handle<Resource> &&other) ENTT_NOEXCEPT = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Copy assignment operator from foreign handle.
|
|
||||||
* @tparam Other Type of resource managed by the received handle.
|
|
||||||
* @param other The handle to copy from.
|
|
||||||
* @return This resource handle.
|
|
||||||
*/
|
|
||||||
template<typename Other>
|
|
||||||
std::enable_if_t<!std::is_same_v<Other, Resource> && std::is_base_of_v<Resource, Other>, resource_handle &>
|
|
||||||
operator=(const resource_handle<Other> &other) ENTT_NOEXCEPT {
|
|
||||||
resource = other.resource;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Move assignment operator from foreign handle.
|
|
||||||
* @tparam Other Type of resource managed by the received handle.
|
|
||||||
* @param other The handle to move from.
|
|
||||||
* @return This resource handle.
|
|
||||||
*/
|
|
||||||
template<typename Other>
|
|
||||||
std::enable_if_t<!std::is_same_v<Other, Resource> && std::is_base_of_v<Resource, Other>, resource_handle &>
|
|
||||||
operator=(resource_handle<Other> &&other) ENTT_NOEXCEPT {
|
|
||||||
resource = std::move(other.resource);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Gets a reference to the managed resource.
|
|
||||||
*
|
|
||||||
* @warning
|
|
||||||
* The behavior is undefined if the handle doesn't contain a resource.
|
|
||||||
*
|
|
||||||
* @return A reference to the managed resource.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const Resource & get() const ENTT_NOEXCEPT {
|
|
||||||
ENTT_ASSERT(static_cast<bool>(resource), "Invalid resource");
|
|
||||||
return *resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc get */
|
|
||||||
[[nodiscard]] Resource & get() ENTT_NOEXCEPT {
|
|
||||||
return const_cast<Resource &>(std::as_const(*this).get());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc get */
|
|
||||||
[[nodiscard]] operator const Resource & () const ENTT_NOEXCEPT {
|
|
||||||
return get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc get */
|
|
||||||
[[nodiscard]] operator Resource & () ENTT_NOEXCEPT {
|
|
||||||
return get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc get */
|
|
||||||
[[nodiscard]] const Resource & operator *() const ENTT_NOEXCEPT {
|
|
||||||
return get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc get */
|
|
||||||
[[nodiscard]] Resource & operator *() ENTT_NOEXCEPT {
|
|
||||||
return get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Gets a pointer to the managed resource.
|
|
||||||
*
|
|
||||||
* @warning
|
|
||||||
* The behavior is undefined if the handle doesn't contain a resource.
|
|
||||||
*
|
|
||||||
* @return A pointer to the managed resource or `nullptr` if the handle
|
|
||||||
* contains no resource at all.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const Resource * operator->() const ENTT_NOEXCEPT {
|
|
||||||
return resource.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! @copydoc operator-> */
|
|
||||||
[[nodiscard]] Resource * operator->() ENTT_NOEXCEPT {
|
|
||||||
return const_cast<Resource *>(std::as_const(*this).operator->());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns true if a handle contains a resource, false otherwise.
|
|
||||||
* @return True if the handle contains a resource, false otherwise.
|
|
||||||
*/
|
|
||||||
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
|
|
||||||
return static_cast<bool>(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::shared_ptr<Resource> resource;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user