1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035
|
// Copyright Toru Niina 2017.
// Distributed under the MIT License.
#ifndef TOML11_VALUE_HPP
#define TOML11_VALUE_HPP
#include <cassert>
#include "comments.hpp"
#include "exception.hpp"
#include "into.hpp"
#include "region.hpp"
#include "source_location.hpp"
#include "storage.hpp"
#include "traits.hpp"
#include "types.hpp"
#include "utility.hpp"
namespace toml
{
namespace detail
{
// to show error messages. not recommended for users.
template<typename Value>
inline region_base const* get_region(const Value& v)
{
return v.region_info_.get();
}
template<typename Value>
void change_region(Value& v, region reg)
{
v.region_info_ = std::make_shared<region>(std::move(reg));
return;
}
template<value_t Expected, typename Value>
[[noreturn]] inline void
throw_bad_cast(const std::string& funcname, value_t actual, const Value& v)
{
throw type_error(detail::format_underline(
concat_to_string(funcname, "bad_cast to ", Expected), {
{v.location(), concat_to_string("the actual type is ", actual)}
}), v.location());
}
// Throw `out_of_range` from `toml::value::at()` and `toml::find()`
// after generating an error message.
//
// The implementation is a bit complicated and there are many edge-cases.
// If you are not interested in the error message generation, just skip this.
template<typename Value>
[[noreturn]] void
throw_key_not_found_error(const Value& v, const key& ky)
{
// The top-level table has its region at the first character of the file.
// That means that, in the case when a key is not found in the top-level
// table, the error message points to the first character. If the file has
// its first table at the first line, the error message would be like this.
// ```console
// [error] key "a" not found
// --> example.toml
// |
// 1 | [table]
// | ^------ in this table
// ```
// It actually points to the top-level table at the first character,
// not `[table]`. But it is too confusing. To avoid the confusion, the error
// message should explicitly say "key not found in the top-level table",
// or "the parsed file is empty" if there is no content at all (0 bytes in file).
const auto loc = v.location();
if(loc.line() == 1 && loc.region() == 0)
{
// First line with a zero-length region means "empty file".
// The region will be generated at `parse_toml_file` function
// if the file contains no bytes.
throw std::out_of_range(format_underline(concat_to_string(
"key \"", ky, "\" not found in the top-level table"), {
{loc, "the parsed file is empty"}
}));
}
else if(loc.line() == 1 && loc.region() == 1)
{
// Here it assumes that top-level table starts at the first character.
// The region corresponds to the top-level table will be generated at
// `parse_toml_file` function.
// It also assumes that the top-level table size is just one and
// the line number is `1`. It is always satisfied. And those conditions
// are satisfied only if the table is the top-level table.
//
// 1. one-character dot-key at the first line
// ```toml
// a.b = "c"
// ```
// toml11 counts whole key as the table key. Here, `a.b` is the region
// of the table "a". It could be counter intuitive, but it works.
// The size of the region is 3, not 1. The above example is the shortest
// dot-key example. The size cannot be 1.
//
// 2. one-character inline-table at the first line
// ```toml
// a = {b = "c"}
// ```
// toml11 considers the inline table body as the table region. Here,
// `{b = "c"}` is the region of the table "a". The size of the region
// is 9, not 1. The shotest inline table still has two characters, `{`
// and `}`. The size cannot be 1.
//
// 3. one-character table declaration at the first line
// ```toml
// [a]
// ```
// toml11 considers the whole table key as the table region. Here,
// `[a]` is the table region. The size is 3, not 1.
//
throw std::out_of_range(format_underline(concat_to_string(
"key \"", ky, "\" not found in the top-level table"), {
{loc, "the top-level table starts here"}
}));
}
else
{
// normal table.
throw std::out_of_range(format_underline(concat_to_string(
"key \"", ky, "\" not found"), { {loc, "in this table"} }));
}
}
// switch by `value_t` at the compile time.
template<value_t T>
struct switch_cast {};
#define TOML11_GENERATE_SWITCH_CASTER(TYPE) \
template<> \
struct switch_cast<value_t::TYPE> \
{ \
template<typename Value> \
static typename Value::TYPE##_type& invoke(Value& v) \
{ \
return v.as_##TYPE(); \
} \
template<typename Value> \
static typename Value::TYPE##_type const& invoke(const Value& v) \
{ \
return v.as_##TYPE(); \
} \
template<typename Value> \
static typename Value::TYPE##_type&& invoke(Value&& v) \
{ \
return std::move(v).as_##TYPE(); \
} \
}; \
/**/
TOML11_GENERATE_SWITCH_CASTER(boolean)
TOML11_GENERATE_SWITCH_CASTER(integer)
TOML11_GENERATE_SWITCH_CASTER(floating)
TOML11_GENERATE_SWITCH_CASTER(string)
TOML11_GENERATE_SWITCH_CASTER(offset_datetime)
TOML11_GENERATE_SWITCH_CASTER(local_datetime)
TOML11_GENERATE_SWITCH_CASTER(local_date)
TOML11_GENERATE_SWITCH_CASTER(local_time)
TOML11_GENERATE_SWITCH_CASTER(array)
TOML11_GENERATE_SWITCH_CASTER(table)
#undef TOML11_GENERATE_SWITCH_CASTER
}// detail
template<typename Comment, // discard/preserve_comment
template<typename ...> class Table = std::unordered_map,
template<typename ...> class Array = std::vector>
class basic_value
{
template<typename T, typename U>
static void assigner(T& dst, U&& v)
{
const auto tmp = ::new(std::addressof(dst)) T(std::forward<U>(v));
assert(tmp == std::addressof(dst));
(void)tmp;
}
using region_base = detail::region_base;
template<typename C, template<typename ...> class T,
template<typename ...> class A>
friend class basic_value;
public:
using comment_type = Comment;
using key_type = ::toml::key;
using value_type = basic_value<comment_type, Table, Array>;
using boolean_type = ::toml::boolean;
using integer_type = ::toml::integer;
using floating_type = ::toml::floating;
using string_type = ::toml::string;
using local_time_type = ::toml::local_time;
using local_date_type = ::toml::local_date;
using local_datetime_type = ::toml::local_datetime;
using offset_datetime_type = ::toml::offset_datetime;
using array_type = Array<value_type>;
using table_type = Table<key_type, value_type>;
public:
basic_value() noexcept
: type_(value_t::empty),
region_info_(std::make_shared<region_base>(region_base{}))
{}
~basic_value() noexcept {this->cleanup();}
basic_value(const basic_value& v)
: type_(v.type()), region_info_(v.region_info_), comments_(v.comments_)
{
switch(v.type())
{
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
case value_t::integer : assigner(integer_ , v.integer_ ); break;
case value_t::floating : assigner(floating_ , v.floating_ ); break;
case value_t::string : assigner(string_ , v.string_ ); break;
case value_t::offset_datetime: assigner(offset_datetime_, v.offset_datetime_); break;
case value_t::local_datetime : assigner(local_datetime_ , v.local_datetime_ ); break;
case value_t::local_date : assigner(local_date_ , v.local_date_ ); break;
case value_t::local_time : assigner(local_time_ , v.local_time_ ); break;
case value_t::array : assigner(array_ , v.array_ ); break;
case value_t::table : assigner(table_ , v.table_ ); break;
default: break;
}
}
basic_value(basic_value&& v)
: type_(v.type()), region_info_(std::move(v.region_info_)),
comments_(std::move(v.comments_))
{
switch(this->type_) // here this->type_ is already initialized
{
case value_t::boolean : assigner(boolean_ , std::move(v.boolean_ )); break;
case value_t::integer : assigner(integer_ , std::move(v.integer_ )); break;
case value_t::floating : assigner(floating_ , std::move(v.floating_ )); break;
case value_t::string : assigner(string_ , std::move(v.string_ )); break;
case value_t::offset_datetime: assigner(offset_datetime_, std::move(v.offset_datetime_)); break;
case value_t::local_datetime : assigner(local_datetime_ , std::move(v.local_datetime_ )); break;
case value_t::local_date : assigner(local_date_ , std::move(v.local_date_ )); break;
case value_t::local_time : assigner(local_time_ , std::move(v.local_time_ )); break;
case value_t::array : assigner(array_ , std::move(v.array_ )); break;
case value_t::table : assigner(table_ , std::move(v.table_ )); break;
default: break;
}
}
basic_value& operator=(const basic_value& v)
{
this->cleanup();
this->region_info_ = v.region_info_;
this->comments_ = v.comments_;
this->type_ = v.type();
switch(this->type_)
{
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
case value_t::integer : assigner(integer_ , v.integer_ ); break;
case value_t::floating : assigner(floating_ , v.floating_ ); break;
case value_t::string : assigner(string_ , v.string_ ); break;
case value_t::offset_datetime: assigner(offset_datetime_, v.offset_datetime_); break;
case value_t::local_datetime : assigner(local_datetime_ , v.local_datetime_ ); break;
case value_t::local_date : assigner(local_date_ , v.local_date_ ); break;
case value_t::local_time : assigner(local_time_ , v.local_time_ ); break;
case value_t::array : assigner(array_ , v.array_ ); break;
case value_t::table : assigner(table_ , v.table_ ); break;
default: break;
}
return *this;
}
basic_value& operator=(basic_value&& v)
{
this->cleanup();
this->region_info_ = std::move(v.region_info_);
this->comments_ = std::move(v.comments_);
this->type_ = v.type();
switch(this->type_)
{
case value_t::boolean : assigner(boolean_ , std::move(v.boolean_ )); break;
case value_t::integer : assigner(integer_ , std::move(v.integer_ )); break;
case value_t::floating : assigner(floating_ , std::move(v.floating_ )); break;
case value_t::string : assigner(string_ , std::move(v.string_ )); break;
case value_t::offset_datetime: assigner(offset_datetime_, std::move(v.offset_datetime_)); break;
case value_t::local_datetime : assigner(local_datetime_ , std::move(v.local_datetime_ )); break;
case value_t::local_date : assigner(local_date_ , std::move(v.local_date_ )); break;
case value_t::local_time : assigner(local_time_ , std::move(v.local_time_ )); break;
case value_t::array : assigner(array_ , std::move(v.array_ )); break;
case value_t::table : assigner(table_ , std::move(v.table_ )); break;
default: break;
}
return *this;
}
// overwrite comments ----------------------------------------------------
basic_value(const basic_value& v, std::vector<std::string> com)
: type_(v.type()), region_info_(v.region_info_),
comments_(std::move(com))
{
switch(v.type())
{
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
case value_t::integer : assigner(integer_ , v.integer_ ); break;
case value_t::floating : assigner(floating_ , v.floating_ ); break;
case value_t::string : assigner(string_ , v.string_ ); break;
case value_t::offset_datetime: assigner(offset_datetime_, v.offset_datetime_); break;
case value_t::local_datetime : assigner(local_datetime_ , v.local_datetime_ ); break;
case value_t::local_date : assigner(local_date_ , v.local_date_ ); break;
case value_t::local_time : assigner(local_time_ , v.local_time_ ); break;
case value_t::array : assigner(array_ , v.array_ ); break;
case value_t::table : assigner(table_ , v.table_ ); break;
default: break;
}
}
basic_value(basic_value&& v, std::vector<std::string> com)
: type_(v.type()), region_info_(std::move(v.region_info_)),
comments_(std::move(com))
{
switch(this->type_) // here this->type_ is already initialized
{
case value_t::boolean : assigner(boolean_ , std::move(v.boolean_ )); break;
case value_t::integer : assigner(integer_ , std::move(v.integer_ )); break;
case value_t::floating : assigner(floating_ , std::move(v.floating_ )); break;
case value_t::string : assigner(string_ , std::move(v.string_ )); break;
case value_t::offset_datetime: assigner(offset_datetime_, std::move(v.offset_datetime_)); break;
case value_t::local_datetime : assigner(local_datetime_ , std::move(v.local_datetime_ )); break;
case value_t::local_date : assigner(local_date_ , std::move(v.local_date_ )); break;
case value_t::local_time : assigner(local_time_ , std::move(v.local_time_ )); break;
case value_t::array : assigner(array_ , std::move(v.array_ )); break;
case value_t::table : assigner(table_ , std::move(v.table_ )); break;
default: break;
}
}
// -----------------------------------------------------------------------
// conversion between different basic_values.
template<typename C,
template<typename ...> class T,
template<typename ...> class A>
basic_value(const basic_value<C, T, A>& v)
: type_(v.type()), region_info_(v.region_info_), comments_(v.comments())
{
switch(v.type())
{
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
case value_t::integer : assigner(integer_ , v.integer_ ); break;
case value_t::floating : assigner(floating_ , v.floating_ ); break;
case value_t::string : assigner(string_ , v.string_ ); break;
case value_t::offset_datetime: assigner(offset_datetime_, v.offset_datetime_); break;
case value_t::local_datetime : assigner(local_datetime_ , v.local_datetime_ ); break;
case value_t::local_date : assigner(local_date_ , v.local_date_ ); break;
case value_t::local_time : assigner(local_time_ , v.local_time_ ); break;
case value_t::array :
{
array_type tmp(v.as_array(std::nothrow).begin(),
v.as_array(std::nothrow).end());
assigner(array_, std::move(tmp));
break;
}
case value_t::table :
{
table_type tmp(v.as_table(std::nothrow).begin(),
v.as_table(std::nothrow).end());
assigner(table_, std::move(tmp));
break;
}
default: break;
}
}
template<typename C,
template<typename ...> class T,
template<typename ...> class A>
basic_value(const basic_value<C, T, A>& v, std::vector<std::string> com)
: type_(v.type()), region_info_(v.region_info_),
comments_(std::move(com))
{
switch(v.type())
{
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
case value_t::integer : assigner(integer_ , v.integer_ ); break;
case value_t::floating : assigner(floating_ , v.floating_ ); break;
case value_t::string : assigner(string_ , v.string_ ); break;
case value_t::offset_datetime: assigner(offset_datetime_, v.offset_datetime_); break;
case value_t::local_datetime : assigner(local_datetime_ , v.local_datetime_ ); break;
case value_t::local_date : assigner(local_date_ , v.local_date_ ); break;
case value_t::local_time : assigner(local_time_ , v.local_time_ ); break;
case value_t::array :
{
array_type tmp(v.as_array(std::nothrow).begin(),
v.as_array(std::nothrow).end());
assigner(array_, std::move(tmp));
break;
}
case value_t::table :
{
table_type tmp(v.as_table(std::nothrow).begin(),
v.as_table(std::nothrow).end());
assigner(table_, std::move(tmp));
break;
}
default: break;
}
}
template<typename C,
template<typename ...> class T,
template<typename ...> class A>
basic_value& operator=(const basic_value<C, T, A>& v)
{
this->region_info_ = v.region_info_;
this->comments_ = comment_type(v.comments());
this->type_ = v.type();
switch(v.type())
{
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
case value_t::integer : assigner(integer_ , v.integer_ ); break;
case value_t::floating : assigner(floating_ , v.floating_ ); break;
case value_t::string : assigner(string_ , v.string_ ); break;
case value_t::offset_datetime: assigner(offset_datetime_, v.offset_datetime_); break;
case value_t::local_datetime : assigner(local_datetime_ , v.local_datetime_ ); break;
case value_t::local_date : assigner(local_date_ , v.local_date_ ); break;
case value_t::local_time : assigner(local_time_ , v.local_time_ ); break;
case value_t::array :
{
array_type tmp(v.as_array(std::nothrow).begin(),
v.as_array(std::nothrow).end());
assigner(array_, std::move(tmp));
break;
}
case value_t::table :
{
table_type tmp(v.as_table(std::nothrow).begin(),
v.as_table(std::nothrow).end());
assigner(table_, std::move(tmp));
break;
}
default: break;
}
return *this;
}
// boolean ==============================================================
basic_value(boolean b)
: type_(value_t::boolean),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->boolean_, b);
}
basic_value& operator=(boolean b)
{
this->cleanup();
this->type_ = value_t::boolean;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->boolean_, b);
return *this;
}
basic_value(boolean b, std::vector<std::string> com)
: type_(value_t::boolean),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->boolean_, b);
}
// integer ==============================================================
template<typename T, typename std::enable_if<detail::conjunction<
std::is_integral<T>, detail::negation<std::is_same<T, boolean>>>::value,
std::nullptr_t>::type = nullptr>
basic_value(T i)
: type_(value_t::integer),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->integer_, static_cast<integer>(i));
}
template<typename T, typename std::enable_if<detail::conjunction<
std::is_integral<T>, detail::negation<std::is_same<T, boolean>>>::value,
std::nullptr_t>::type = nullptr>
basic_value& operator=(T i)
{
this->cleanup();
this->type_ = value_t::integer;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->integer_, static_cast<integer>(i));
return *this;
}
template<typename T, typename std::enable_if<detail::conjunction<
std::is_integral<T>, detail::negation<std::is_same<T, boolean>>>::value,
std::nullptr_t>::type = nullptr>
basic_value(T i, std::vector<std::string> com)
: type_(value_t::integer),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->integer_, static_cast<integer>(i));
}
// floating =============================================================
template<typename T, typename std::enable_if<
std::is_floating_point<T>::value, std::nullptr_t>::type = nullptr>
basic_value(T f)
: type_(value_t::floating),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->floating_, static_cast<floating>(f));
}
template<typename T, typename std::enable_if<
std::is_floating_point<T>::value, std::nullptr_t>::type = nullptr>
basic_value& operator=(T f)
{
this->cleanup();
this->type_ = value_t::floating;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->floating_, static_cast<floating>(f));
return *this;
}
template<typename T, typename std::enable_if<
std::is_floating_point<T>::value, std::nullptr_t>::type = nullptr>
basic_value(T f, std::vector<std::string> com)
: type_(value_t::floating),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->floating_, f);
}
// string ===============================================================
basic_value(toml::string s)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->string_, std::move(s));
}
basic_value& operator=(toml::string s)
{
this->cleanup();
this->type_ = value_t::string ;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->string_, s);
return *this;
}
basic_value(toml::string s, std::vector<std::string> com)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->string_, std::move(s));
}
basic_value(std::string s)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->string_, toml::string(std::move(s)));
}
basic_value& operator=(std::string s)
{
this->cleanup();
this->type_ = value_t::string ;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->string_, toml::string(std::move(s)));
return *this;
}
basic_value(std::string s, string_t kind)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->string_, toml::string(std::move(s), kind));
}
basic_value(std::string s, std::vector<std::string> com)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->string_, toml::string(std::move(s)));
}
basic_value(std::string s, string_t kind, std::vector<std::string> com)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->string_, toml::string(std::move(s), kind));
}
basic_value(const char* s)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->string_, toml::string(std::string(s)));
}
basic_value& operator=(const char* s)
{
this->cleanup();
this->type_ = value_t::string ;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->string_, toml::string(std::string(s)));
return *this;
}
basic_value(const char* s, string_t kind)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->string_, toml::string(std::string(s), kind));
}
basic_value(const char* s, std::vector<std::string> com)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->string_, toml::string(std::string(s)));
}
basic_value(const char* s, string_t kind, std::vector<std::string> com)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->string_, toml::string(std::string(s), kind));
}
#if defined(TOML11_USING_STRING_VIEW) && TOML11_USING_STRING_VIEW>0
basic_value(std::string_view s)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->string_, toml::string(s));
}
basic_value& operator=(std::string_view s)
{
this->cleanup();
this->type_ = value_t::string ;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->string_, toml::string(s));
return *this;
}
basic_value(std::string_view s, std::vector<std::string> com)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->string_, toml::string(s));
}
basic_value(std::string_view s, string_t kind)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->string_, toml::string(s, kind));
}
basic_value(std::string_view s, string_t kind, std::vector<std::string> com)
: type_(value_t::string),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->string_, toml::string(s, kind));
}
#endif
// local date ===========================================================
basic_value(const local_date& ld)
: type_(value_t::local_date),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->local_date_, ld);
}
basic_value& operator=(const local_date& ld)
{
this->cleanup();
this->type_ = value_t::local_date;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->local_date_, ld);
return *this;
}
basic_value(const local_date& ld, std::vector<std::string> com)
: type_(value_t::local_date),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->local_date_, ld);
}
// local time ===========================================================
basic_value(const local_time& lt)
: type_(value_t::local_time),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->local_time_, lt);
}
basic_value(const local_time& lt, std::vector<std::string> com)
: type_(value_t::local_time),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->local_time_, lt);
}
basic_value& operator=(const local_time& lt)
{
this->cleanup();
this->type_ = value_t::local_time;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->local_time_, lt);
return *this;
}
template<typename Rep, typename Period>
basic_value(const std::chrono::duration<Rep, Period>& dur)
: type_(value_t::local_time),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->local_time_, local_time(dur));
}
template<typename Rep, typename Period>
basic_value(const std::chrono::duration<Rep, Period>& dur,
std::vector<std::string> com)
: type_(value_t::local_time),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->local_time_, local_time(dur));
}
template<typename Rep, typename Period>
basic_value& operator=(const std::chrono::duration<Rep, Period>& dur)
{
this->cleanup();
this->type_ = value_t::local_time;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->local_time_, local_time(dur));
return *this;
}
// local datetime =======================================================
basic_value(const local_datetime& ldt)
: type_(value_t::local_datetime),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->local_datetime_, ldt);
}
basic_value(const local_datetime& ldt, std::vector<std::string> com)
: type_(value_t::local_datetime),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->local_datetime_, ldt);
}
basic_value& operator=(const local_datetime& ldt)
{
this->cleanup();
this->type_ = value_t::local_datetime;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->local_datetime_, ldt);
return *this;
}
// offset datetime ======================================================
basic_value(const offset_datetime& odt)
: type_(value_t::offset_datetime),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->offset_datetime_, odt);
}
basic_value(const offset_datetime& odt, std::vector<std::string> com)
: type_(value_t::offset_datetime),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->offset_datetime_, odt);
}
basic_value& operator=(const offset_datetime& odt)
{
this->cleanup();
this->type_ = value_t::offset_datetime;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->offset_datetime_, odt);
return *this;
}
basic_value(const std::chrono::system_clock::time_point& tp)
: type_(value_t::offset_datetime),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->offset_datetime_, offset_datetime(tp));
}
basic_value(const std::chrono::system_clock::time_point& tp,
std::vector<std::string> com)
: type_(value_t::offset_datetime),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->offset_datetime_, offset_datetime(tp));
}
basic_value& operator=(const std::chrono::system_clock::time_point& tp)
{
this->cleanup();
this->type_ = value_t::offset_datetime;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->offset_datetime_, offset_datetime(tp));
return *this;
}
// array ================================================================
basic_value(const array_type& ary)
: type_(value_t::array),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->array_, ary);
}
basic_value(const array_type& ary, std::vector<std::string> com)
: type_(value_t::array),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->array_, ary);
}
basic_value& operator=(const array_type& ary)
{
this->cleanup();
this->type_ = value_t::array ;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->array_, ary);
return *this;
}
// array (initializer_list) ----------------------------------------------
template<typename T, typename std::enable_if<
std::is_convertible<T, value_type>::value,
std::nullptr_t>::type = nullptr>
basic_value(std::initializer_list<T> list)
: type_(value_t::array),
region_info_(std::make_shared<region_base>(region_base{}))
{
array_type ary(list.begin(), list.end());
assigner(this->array_, std::move(ary));
}
template<typename T, typename std::enable_if<
std::is_convertible<T, value_type>::value,
std::nullptr_t>::type = nullptr>
basic_value(std::initializer_list<T> list, std::vector<std::string> com)
: type_(value_t::array),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
array_type ary(list.begin(), list.end());
assigner(this->array_, std::move(ary));
}
template<typename T, typename std::enable_if<
std::is_convertible<T, value_type>::value,
std::nullptr_t>::type = nullptr>
basic_value& operator=(std::initializer_list<T> list)
{
this->cleanup();
this->type_ = value_t::array;
this->region_info_ = std::make_shared<region_base>(region_base{});
array_type ary(list.begin(), list.end());
assigner(this->array_, std::move(ary));
return *this;
}
// array (STL Containers) ------------------------------------------------
template<typename T, typename std::enable_if<detail::conjunction<
detail::negation<std::is_same<T, array_type>>,
detail::is_container<T>
>::value, std::nullptr_t>::type = nullptr>
basic_value(const T& list)
: type_(value_t::array),
region_info_(std::make_shared<region_base>(region_base{}))
{
static_assert(std::is_convertible<typename T::value_type, value_type>::value,
"elements of a container should be convertible to toml::value");
array_type ary(list.size());
std::copy(list.begin(), list.end(), ary.begin());
assigner(this->array_, std::move(ary));
}
template<typename T, typename std::enable_if<detail::conjunction<
detail::negation<std::is_same<T, array_type>>,
detail::is_container<T>
>::value, std::nullptr_t>::type = nullptr>
basic_value(const T& list, std::vector<std::string> com)
: type_(value_t::array),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
static_assert(std::is_convertible<typename T::value_type, value_type>::value,
"elements of a container should be convertible to toml::value");
array_type ary(list.size());
std::copy(list.begin(), list.end(), ary.begin());
assigner(this->array_, std::move(ary));
}
template<typename T, typename std::enable_if<detail::conjunction<
detail::negation<std::is_same<T, array_type>>,
detail::is_container<T>
>::value, std::nullptr_t>::type = nullptr>
basic_value& operator=(const T& list)
{
static_assert(std::is_convertible<typename T::value_type, value_type>::value,
"elements of a container should be convertible to toml::value");
this->cleanup();
this->type_ = value_t::array;
this->region_info_ = std::make_shared<region_base>(region_base{});
array_type ary(list.size());
std::copy(list.begin(), list.end(), ary.begin());
assigner(this->array_, std::move(ary));
return *this;
}
// table ================================================================
basic_value(const table_type& tab)
: type_(value_t::table),
region_info_(std::make_shared<region_base>(region_base{}))
{
assigner(this->table_, tab);
}
basic_value(const table_type& tab, std::vector<std::string> com)
: type_(value_t::table),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
assigner(this->table_, tab);
}
basic_value& operator=(const table_type& tab)
{
this->cleanup();
this->type_ = value_t::table;
this->region_info_ = std::make_shared<region_base>(region_base{});
assigner(this->table_, tab);
return *this;
}
// initializer-list ------------------------------------------------------
basic_value(std::initializer_list<std::pair<key, basic_value>> list)
: type_(value_t::table),
region_info_(std::make_shared<region_base>(region_base{}))
{
table_type tab;
for(const auto& elem : list) {tab[elem.first] = elem.second;}
assigner(this->table_, std::move(tab));
}
basic_value(std::initializer_list<std::pair<key, basic_value>> list,
std::vector<std::string> com)
: type_(value_t::table),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
table_type tab;
for(const auto& elem : list) {tab[elem.first] = elem.second;}
assigner(this->table_, std::move(tab));
}
basic_value& operator=(std::initializer_list<std::pair<key, basic_value>> list)
{
this->cleanup();
this->type_ = value_t::table;
this->region_info_ = std::make_shared<region_base>(region_base{});
table_type tab;
for(const auto& elem : list) {tab[elem.first] = elem.second;}
assigner(this->table_, std::move(tab));
return *this;
}
// other table-like -----------------------------------------------------
template<typename Map, typename std::enable_if<detail::conjunction<
detail::negation<std::is_same<Map, table_type>>,
detail::is_map<Map>
>::value, std::nullptr_t>::type = nullptr>
basic_value(const Map& mp)
: type_(value_t::table),
region_info_(std::make_shared<region_base>(region_base{}))
{
table_type tab;
for(const auto& elem : mp) {tab[elem.first] = elem.second;}
assigner(this->table_, std::move(tab));
}
template<typename Map, typename std::enable_if<detail::conjunction<
detail::negation<std::is_same<Map, table_type>>,
detail::is_map<Map>
>::value, std::nullptr_t>::type = nullptr>
basic_value(const Map& mp, std::vector<std::string> com)
: type_(value_t::table),
region_info_(std::make_shared<region_base>(region_base{})),
comments_(std::move(com))
{
table_type tab;
for(const auto& elem : mp) {tab[elem.first] = elem.second;}
assigner(this->table_, std::move(tab));
}
template<typename Map, typename std::enable_if<detail::conjunction<
detail::negation<std::is_same<Map, table_type>>,
detail::is_map<Map>
>::value, std::nullptr_t>::type = nullptr>
basic_value& operator=(const Map& mp)
{
this->cleanup();
this->type_ = value_t::table;
this->region_info_ = std::make_shared<region_base>(region_base{});
table_type tab;
for(const auto& elem : mp) {tab[elem.first] = elem.second;}
assigner(this->table_, std::move(tab));
return *this;
}
// user-defined =========================================================
// convert using into_toml() method -------------------------------------
template<typename T, typename std::enable_if<
detail::has_into_toml_method<T>::value, std::nullptr_t>::type = nullptr>
basic_value(const T& ud): basic_value(ud.into_toml()) {}
template<typename T, typename std::enable_if<
detail::has_into_toml_method<T>::value, std::nullptr_t>::type = nullptr>
basic_value(const T& ud, std::vector<std::string> com)
: basic_value(ud.into_toml(), std::move(com))
{}
template<typename T, typename std::enable_if<
detail::has_into_toml_method<T>::value, std::nullptr_t>::type = nullptr>
basic_value& operator=(const T& ud)
{
*this = ud.into_toml();
return *this;
}
// convert using into<T> struct -----------------------------------------
template<typename T, std::size_t S = sizeof(::toml::into<T>)>
basic_value(const T& ud): basic_value(::toml::into<T>::into_toml(ud)) {}
template<typename T, std::size_t S = sizeof(::toml::into<T>)>
basic_value(const T& ud, std::vector<std::string> com)
: basic_value(::toml::into<T>::into_toml(ud), std::move(com))
{}
template<typename T, std::size_t S = sizeof(::toml::into<T>)>
basic_value& operator=(const T& ud)
{
*this = ::toml::into<T>::into_toml(ud);
return *this;
}
// for internal use ------------------------------------------------------
//
// Those constructors take detail::region that contains parse result.
basic_value(boolean b, detail::region reg, std::vector<std::string> cm)
: type_(value_t::boolean),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->boolean_, b);
}
template<typename T, typename std::enable_if<
detail::conjunction<
std::is_integral<T>, detail::negation<std::is_same<T, boolean>>
>::value, std::nullptr_t>::type = nullptr>
basic_value(T i, detail::region reg, std::vector<std::string> cm)
: type_(value_t::integer),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->integer_, static_cast<integer>(i));
}
template<typename T, typename std::enable_if<
std::is_floating_point<T>::value, std::nullptr_t>::type = nullptr>
basic_value(T f, detail::region reg, std::vector<std::string> cm)
: type_(value_t::floating),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->floating_, static_cast<floating>(f));
}
basic_value(toml::string s, detail::region reg,
std::vector<std::string> cm)
: type_(value_t::string),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->string_, std::move(s));
}
basic_value(const local_date& ld, detail::region reg,
std::vector<std::string> cm)
: type_(value_t::local_date),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->local_date_, ld);
}
basic_value(const local_time& lt, detail::region reg,
std::vector<std::string> cm)
: type_(value_t::local_time),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->local_time_, lt);
}
basic_value(const local_datetime& ldt, detail::region reg,
std::vector<std::string> cm)
: type_(value_t::local_datetime),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->local_datetime_, ldt);
}
basic_value(const offset_datetime& odt, detail::region reg,
std::vector<std::string> cm)
: type_(value_t::offset_datetime),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->offset_datetime_, odt);
}
basic_value(const array_type& ary, detail::region reg,
std::vector<std::string> cm)
: type_(value_t::array),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->array_, ary);
}
basic_value(const table_type& tab, detail::region reg,
std::vector<std::string> cm)
: type_(value_t::table),
region_info_(std::make_shared<detail::region>(std::move(reg))),
comments_(std::move(cm))
{
assigner(this->table_, tab);
}
template<typename T, typename std::enable_if<
detail::is_exact_toml_type<T, value_type>::value,
std::nullptr_t>::type = nullptr>
basic_value(std::pair<T, detail::region> parse_result, std::vector<std::string> com)
: basic_value(std::move(parse_result.first),
std::move(parse_result.second),
std::move(com))
{}
// type checking and casting ============================================
template<typename T, typename std::enable_if<
detail::is_exact_toml_type<T, value_type>::value,
std::nullptr_t>::type = nullptr>
bool is() const noexcept
{
return detail::type_to_enum<T, value_type>::value == this->type_;
}
bool is(value_t t) const noexcept {return t == this->type_;}
bool is_uninitialized() const noexcept {return this->is(value_t::empty );}
bool is_boolean() const noexcept {return this->is(value_t::boolean );}
bool is_integer() const noexcept {return this->is(value_t::integer );}
bool is_floating() const noexcept {return this->is(value_t::floating );}
bool is_string() const noexcept {return this->is(value_t::string );}
bool is_offset_datetime() const noexcept {return this->is(value_t::offset_datetime);}
bool is_local_datetime() const noexcept {return this->is(value_t::local_datetime );}
bool is_local_date() const noexcept {return this->is(value_t::local_date );}
bool is_local_time() const noexcept {return this->is(value_t::local_time );}
bool is_array() const noexcept {return this->is(value_t::array );}
bool is_table() const noexcept {return this->is(value_t::table );}
value_t type() const noexcept {return type_;}
template<value_t T>
typename detail::enum_to_type<T, value_type>::type& cast() &
{
if(this->type_ != T)
{
detail::throw_bad_cast<T>("toml::value::cast: ", this->type_, *this);
}
return detail::switch_cast<T>::invoke(*this);
}
template<value_t T>
typename detail::enum_to_type<T, value_type>::type const& cast() const&
{
if(this->type_ != T)
{
detail::throw_bad_cast<T>("toml::value::cast: ", this->type_, *this);
}
return detail::switch_cast<T>::invoke(*this);
}
template<value_t T>
typename detail::enum_to_type<T, value_type>::type&& cast() &&
{
if(this->type_ != T)
{
detail::throw_bad_cast<T>("toml::value::cast: ", this->type_, *this);
}
return detail::switch_cast<T>::invoke(std::move(*this));
}
// ------------------------------------------------------------------------
// nothrow version
boolean const& as_boolean (const std::nothrow_t&) const& noexcept {return this->boolean_;}
integer const& as_integer (const std::nothrow_t&) const& noexcept {return this->integer_;}
floating const& as_floating (const std::nothrow_t&) const& noexcept {return this->floating_;}
string const& as_string (const std::nothrow_t&) const& noexcept {return this->string_;}
offset_datetime const& as_offset_datetime(const std::nothrow_t&) const& noexcept {return this->offset_datetime_;}
local_datetime const& as_local_datetime (const std::nothrow_t&) const& noexcept {return this->local_datetime_;}
local_date const& as_local_date (const std::nothrow_t&) const& noexcept {return this->local_date_;}
local_time const& as_local_time (const std::nothrow_t&) const& noexcept {return this->local_time_;}
array_type const& as_array (const std::nothrow_t&) const& noexcept {return this->array_.value();}
table_type const& as_table (const std::nothrow_t&) const& noexcept {return this->table_.value();}
boolean & as_boolean (const std::nothrow_t&) & noexcept {return this->boolean_;}
integer & as_integer (const std::nothrow_t&) & noexcept {return this->integer_;}
floating & as_floating (const std::nothrow_t&) & noexcept {return this->floating_;}
string & as_string (const std::nothrow_t&) & noexcept {return this->string_;}
offset_datetime& as_offset_datetime(const std::nothrow_t&) & noexcept {return this->offset_datetime_;}
local_datetime & as_local_datetime (const std::nothrow_t&) & noexcept {return this->local_datetime_;}
local_date & as_local_date (const std::nothrow_t&) & noexcept {return this->local_date_;}
local_time & as_local_time (const std::nothrow_t&) & noexcept {return this->local_time_;}
array_type & as_array (const std::nothrow_t&) & noexcept {return this->array_.value();}
table_type & as_table (const std::nothrow_t&) & noexcept {return this->table_.value();}
boolean && as_boolean (const std::nothrow_t&) && noexcept {return std::move(this->boolean_);}
integer && as_integer (const std::nothrow_t&) && noexcept {return std::move(this->integer_);}
floating && as_floating (const std::nothrow_t&) && noexcept {return std::move(this->floating_);}
string && as_string (const std::nothrow_t&) && noexcept {return std::move(this->string_);}
offset_datetime&& as_offset_datetime(const std::nothrow_t&) && noexcept {return std::move(this->offset_datetime_);}
local_datetime && as_local_datetime (const std::nothrow_t&) && noexcept {return std::move(this->local_datetime_);}
local_date && as_local_date (const std::nothrow_t&) && noexcept {return std::move(this->local_date_);}
local_time && as_local_time (const std::nothrow_t&) && noexcept {return std::move(this->local_time_);}
array_type && as_array (const std::nothrow_t&) && noexcept {return std::move(this->array_.value());}
table_type && as_table (const std::nothrow_t&) && noexcept {return std::move(this->table_.value());}
// ========================================================================
// throw version
// ------------------------------------------------------------------------
// const reference {{{
boolean const& as_boolean() const&
{
if(this->type_ != value_t::boolean)
{
detail::throw_bad_cast<value_t::boolean>(
"toml::value::as_boolean(): ", this->type_, *this);
}
return this->boolean_;
}
integer const& as_integer() const&
{
if(this->type_ != value_t::integer)
{
detail::throw_bad_cast<value_t::integer>(
"toml::value::as_integer(): ", this->type_, *this);
}
return this->integer_;
}
floating const& as_floating() const&
{
if(this->type_ != value_t::floating)
{
detail::throw_bad_cast<value_t::floating>(
"toml::value::as_floating(): ", this->type_, *this);
}
return this->floating_;
}
string const& as_string() const&
{
if(this->type_ != value_t::string)
{
detail::throw_bad_cast<value_t::string>(
"toml::value::as_string(): ", this->type_, *this);
}
return this->string_;
}
offset_datetime const& as_offset_datetime() const&
{
if(this->type_ != value_t::offset_datetime)
{
detail::throw_bad_cast<value_t::offset_datetime>(
"toml::value::as_offset_datetime(): ", this->type_, *this);
}
return this->offset_datetime_;
}
local_datetime const& as_local_datetime() const&
{
if(this->type_ != value_t::local_datetime)
{
detail::throw_bad_cast<value_t::local_datetime>(
"toml::value::as_local_datetime(): ", this->type_, *this);
}
return this->local_datetime_;
}
local_date const& as_local_date() const&
{
if(this->type_ != value_t::local_date)
{
detail::throw_bad_cast<value_t::local_date>(
"toml::value::as_local_date(): ", this->type_, *this);
}
return this->local_date_;
}
local_time const& as_local_time() const&
{
if(this->type_ != value_t::local_time)
{
detail::throw_bad_cast<value_t::local_time>(
"toml::value::as_local_time(): ", this->type_, *this);
}
return this->local_time_;
}
array_type const& as_array() const&
{
if(this->type_ != value_t::array)
{
detail::throw_bad_cast<value_t::array>(
"toml::value::as_array(): ", this->type_, *this);
}
return this->array_.value();
}
table_type const& as_table() const&
{
if(this->type_ != value_t::table)
{
detail::throw_bad_cast<value_t::table>(
"toml::value::as_table(): ", this->type_, *this);
}
return this->table_.value();
}
// }}}
// ------------------------------------------------------------------------
// nonconst reference {{{
boolean & as_boolean() &
{
if(this->type_ != value_t::boolean)
{
detail::throw_bad_cast<value_t::boolean>(
"toml::value::as_boolean(): ", this->type_, *this);
}
return this->boolean_;
}
integer & as_integer() &
{
if(this->type_ != value_t::integer)
{
detail::throw_bad_cast<value_t::integer>(
"toml::value::as_integer(): ", this->type_, *this);
}
return this->integer_;
}
floating & as_floating() &
{
if(this->type_ != value_t::floating)
{
detail::throw_bad_cast<value_t::floating>(
"toml::value::as_floating(): ", this->type_, *this);
}
return this->floating_;
}
string & as_string() &
{
if(this->type_ != value_t::string)
{
detail::throw_bad_cast<value_t::string>(
"toml::value::as_string(): ", this->type_, *this);
}
return this->string_;
}
offset_datetime & as_offset_datetime() &
{
if(this->type_ != value_t::offset_datetime)
{
detail::throw_bad_cast<value_t::offset_datetime>(
"toml::value::as_offset_datetime(): ", this->type_, *this);
}
return this->offset_datetime_;
}
local_datetime & as_local_datetime() &
{
if(this->type_ != value_t::local_datetime)
{
detail::throw_bad_cast<value_t::local_datetime>(
"toml::value::as_local_datetime(): ", this->type_, *this);
}
return this->local_datetime_;
}
local_date & as_local_date() &
{
if(this->type_ != value_t::local_date)
{
detail::throw_bad_cast<value_t::local_date>(
"toml::value::as_local_date(): ", this->type_, *this);
}
return this->local_date_;
}
local_time & as_local_time() &
{
if(this->type_ != value_t::local_time)
{
detail::throw_bad_cast<value_t::local_time>(
"toml::value::as_local_time(): ", this->type_, *this);
}
return this->local_time_;
}
array_type & as_array() &
{
if(this->type_ != value_t::array)
{
detail::throw_bad_cast<value_t::array>(
"toml::value::as_array(): ", this->type_, *this);
}
return this->array_.value();
}
table_type & as_table() &
{
if(this->type_ != value_t::table)
{
detail::throw_bad_cast<value_t::table>(
"toml::value::as_table(): ", this->type_, *this);
}
return this->table_.value();
}
// }}}
// ------------------------------------------------------------------------
// rvalue reference {{{
boolean && as_boolean() &&
{
if(this->type_ != value_t::boolean)
{
detail::throw_bad_cast<value_t::boolean>(
"toml::value::as_boolean(): ", this->type_, *this);
}
return std::move(this->boolean_);
}
integer && as_integer() &&
{
if(this->type_ != value_t::integer)
{
detail::throw_bad_cast<value_t::integer>(
"toml::value::as_integer(): ", this->type_, *this);
}
return std::move(this->integer_);
}
floating && as_floating() &&
{
if(this->type_ != value_t::floating)
{
detail::throw_bad_cast<value_t::floating>(
"toml::value::as_floating(): ", this->type_, *this);
}
return std::move(this->floating_);
}
string && as_string() &&
{
if(this->type_ != value_t::string)
{
detail::throw_bad_cast<value_t::string>(
"toml::value::as_string(): ", this->type_, *this);
}
return std::move(this->string_);
}
offset_datetime && as_offset_datetime() &&
{
if(this->type_ != value_t::offset_datetime)
{
detail::throw_bad_cast<value_t::offset_datetime>(
"toml::value::as_offset_datetime(): ", this->type_, *this);
}
return std::move(this->offset_datetime_);
}
local_datetime && as_local_datetime() &&
{
if(this->type_ != value_t::local_datetime)
{
detail::throw_bad_cast<value_t::local_datetime>(
"toml::value::as_local_datetime(): ", this->type_, *this);
}
return std::move(this->local_datetime_);
}
local_date && as_local_date() &&
{
if(this->type_ != value_t::local_date)
{
detail::throw_bad_cast<value_t::local_date>(
"toml::value::as_local_date(): ", this->type_, *this);
}
return std::move(this->local_date_);
}
local_time && as_local_time() &&
{
if(this->type_ != value_t::local_time)
{
detail::throw_bad_cast<value_t::local_time>(
"toml::value::as_local_time(): ", this->type_, *this);
}
return std::move(this->local_time_);
}
array_type && as_array() &&
{
if(this->type_ != value_t::array)
{
detail::throw_bad_cast<value_t::array>(
"toml::value::as_array(): ", this->type_, *this);
}
return std::move(this->array_.value());
}
table_type && as_table() &&
{
if(this->type_ != value_t::table)
{
detail::throw_bad_cast<value_t::table>(
"toml::value::as_table(): ", this->type_, *this);
}
return std::move(this->table_.value());
}
// }}}
// accessors =============================================================
//
// may throw type_error or out_of_range
//
value_type& at(const key& k)
{
if(!this->is_table())
{
detail::throw_bad_cast<value_t::table>(
"toml::value::at(key): ", this->type_, *this);
}
if(this->as_table(std::nothrow).count(k) == 0)
{
detail::throw_key_not_found_error(*this, k);
}
return this->as_table(std::nothrow).at(k);
}
value_type const& at(const key& k) const
{
if(!this->is_table())
{
detail::throw_bad_cast<value_t::table>(
"toml::value::at(key): ", this->type_, *this);
}
if(this->as_table(std::nothrow).count(k) == 0)
{
detail::throw_key_not_found_error(*this, k);
}
return this->as_table(std::nothrow).at(k);
}
value_type& operator[](const key& k)
{
if(this->is_uninitialized())
{
*this = table_type{};
}
else if(!this->is_table()) // initialized, but not a table
{
detail::throw_bad_cast<value_t::table>(
"toml::value::operator[](key): ", this->type_, *this);
}
return this->as_table(std::nothrow)[k];
}
value_type& at(const std::size_t idx)
{
if(!this->is_array())
{
detail::throw_bad_cast<value_t::array>(
"toml::value::at(idx): ", this->type_, *this);
}
if(this->as_array(std::nothrow).size() <= idx)
{
throw std::out_of_range(detail::format_underline(
"toml::value::at(idx): no element corresponding to the index", {
{this->location(), concat_to_string("the length is ",
this->as_array(std::nothrow).size(),
", and the specified index is ", idx)}
}));
}
return this->as_array().at(idx);
}
value_type const& at(const std::size_t idx) const
{
if(!this->is_array())
{
detail::throw_bad_cast<value_t::array>(
"toml::value::at(idx): ", this->type_, *this);
}
if(this->as_array(std::nothrow).size() <= idx)
{
throw std::out_of_range(detail::format_underline(
"toml::value::at(idx): no element corresponding to the index", {
{this->location(), concat_to_string("the length is ",
this->as_array(std::nothrow).size(),
", and the specified index is ", idx)}
}));
}
return this->as_array(std::nothrow).at(idx);
}
value_type& operator[](const std::size_t idx) noexcept
{
// no check...
return this->as_array(std::nothrow)[idx];
}
value_type const& operator[](const std::size_t idx) const noexcept
{
// no check...
return this->as_array(std::nothrow)[idx];
}
void push_back(const value_type& x)
{
if(!this->is_array())
{
detail::throw_bad_cast<value_t::array>(
"toml::value::push_back(value): ", this->type_, *this);
}
this->as_array(std::nothrow).push_back(x);
return;
}
void push_back(value_type&& x)
{
if(!this->is_array())
{
detail::throw_bad_cast<value_t::array>(
"toml::value::push_back(value): ", this->type_, *this);
}
this->as_array(std::nothrow).push_back(std::move(x));
return;
}
template<typename ... Ts>
value_type& emplace_back(Ts&& ... args)
{
if(!this->is_array())
{
detail::throw_bad_cast<value_t::array>(
"toml::value::emplace_back(...): ", this->type_, *this);
}
this->as_array(std::nothrow).emplace_back(std::forward<Ts>(args) ...);
return this->as_array(std::nothrow).back();
}
std::size_t size() const
{
switch(this->type_)
{
case value_t::array:
{
return this->as_array(std::nothrow).size();
}
case value_t::table:
{
return this->as_table(std::nothrow).size();
}
case value_t::string:
{
return this->as_string(std::nothrow).str.size();
}
default:
{
throw type_error(detail::format_underline(
"toml::value::size(): bad_cast to container types", {
{this->location(),
concat_to_string("the actual type is ", this->type_)}
}), this->location());
}
}
}
std::size_t count(const key_type& k) const
{
if(!this->is_table())
{
detail::throw_bad_cast<value_t::table>(
"toml::value::count(key): ", this->type_, *this);
}
return this->as_table(std::nothrow).count(k);
}
bool contains(const key_type& k) const
{
if(!this->is_table())
{
detail::throw_bad_cast<value_t::table>(
"toml::value::contains(key): ", this->type_, *this);
}
return (this->as_table(std::nothrow).count(k) != 0);
}
source_location location() const
{
return source_location(this->region_info_.get());
}
comment_type const& comments() const noexcept {return this->comments_;}
comment_type& comments() noexcept {return this->comments_;}
private:
void cleanup() noexcept
{
switch(this->type_)
{
case value_t::string : {string_.~string(); return;}
case value_t::array : {array_.~array_storage(); return;}
case value_t::table : {table_.~table_storage(); return;}
default : return;
}
}
// for error messages
template<typename Value>
friend region_base const* detail::get_region(const Value& v);
template<typename Value>
friend void detail::change_region(Value& v, detail::region reg);
private:
using array_storage = detail::storage<array_type>;
using table_storage = detail::storage<table_type>;
value_t type_;
union
{
boolean boolean_;
integer integer_;
floating floating_;
string string_;
offset_datetime offset_datetime_;
local_datetime local_datetime_;
local_date local_date_;
local_time local_time_;
array_storage array_;
table_storage table_;
};
std::shared_ptr<region_base> region_info_;
comment_type comments_;
};
// default toml::value and default array/table.
// TOML11_DEFAULT_COMMENT_STRATEGY is defined in comments.hpp
using value = basic_value<TOML11_DEFAULT_COMMENT_STRATEGY, std::unordered_map, std::vector>;
using array = typename value::array_type;
using table = typename value::table_type;
template<typename C, template<typename ...> class T, template<typename ...> class A>
inline bool
operator==(const basic_value<C, T, A>& lhs, const basic_value<C, T, A>& rhs)
{
if(lhs.type() != rhs.type()) {return false;}
if(lhs.comments() != rhs.comments()) {return false;}
switch(lhs.type())
{
case value_t::boolean :
{
return lhs.as_boolean() == rhs.as_boolean();
}
case value_t::integer :
{
return lhs.as_integer() == rhs.as_integer();
}
case value_t::floating :
{
return lhs.as_floating() == rhs.as_floating();
}
case value_t::string :
{
return lhs.as_string() == rhs.as_string();
}
case value_t::offset_datetime:
{
return lhs.as_offset_datetime() == rhs.as_offset_datetime();
}
case value_t::local_datetime:
{
return lhs.as_local_datetime() == rhs.as_local_datetime();
}
case value_t::local_date:
{
return lhs.as_local_date() == rhs.as_local_date();
}
case value_t::local_time:
{
return lhs.as_local_time() == rhs.as_local_time();
}
case value_t::array :
{
return lhs.as_array() == rhs.as_array();
}
case value_t::table :
{
return lhs.as_table() == rhs.as_table();
}
case value_t::empty : {return true; }
default: {return false;}
}
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
inline bool operator!=(const basic_value<C, T, A>& lhs, const basic_value<C, T, A>& rhs)
{
return !(lhs == rhs);
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
typename std::enable_if<detail::conjunction<
detail::is_comparable<typename basic_value<C, T, A>::array_type>,
detail::is_comparable<typename basic_value<C, T, A>::table_type>
>::value, bool>::type
operator<(const basic_value<C, T, A>& lhs, const basic_value<C, T, A>& rhs)
{
if(lhs.type() != rhs.type()){return (lhs.type() < rhs.type());}
switch(lhs.type())
{
case value_t::boolean :
{
return lhs.as_boolean() < rhs.as_boolean() ||
(lhs.as_boolean() == rhs.as_boolean() &&
lhs.comments() < rhs.comments());
}
case value_t::integer :
{
return lhs.as_integer() < rhs.as_integer() ||
(lhs.as_integer() == rhs.as_integer() &&
lhs.comments() < rhs.comments());
}
case value_t::floating :
{
return lhs.as_floating() < rhs.as_floating() ||
(lhs.as_floating() == rhs.as_floating() &&
lhs.comments() < rhs.comments());
}
case value_t::string :
{
return lhs.as_string() < rhs.as_string() ||
(lhs.as_string() == rhs.as_string() &&
lhs.comments() < rhs.comments());
}
case value_t::offset_datetime:
{
return lhs.as_offset_datetime() < rhs.as_offset_datetime() ||
(lhs.as_offset_datetime() == rhs.as_offset_datetime() &&
lhs.comments() < rhs.comments());
}
case value_t::local_datetime:
{
return lhs.as_local_datetime() < rhs.as_local_datetime() ||
(lhs.as_local_datetime() == rhs.as_local_datetime() &&
lhs.comments() < rhs.comments());
}
case value_t::local_date:
{
return lhs.as_local_date() < rhs.as_local_date() ||
(lhs.as_local_date() == rhs.as_local_date() &&
lhs.comments() < rhs.comments());
}
case value_t::local_time:
{
return lhs.as_local_time() < rhs.as_local_time() ||
(lhs.as_local_time() == rhs.as_local_time() &&
lhs.comments() < rhs.comments());
}
case value_t::array :
{
return lhs.as_array() < rhs.as_array() ||
(lhs.as_array() == rhs.as_array() &&
lhs.comments() < rhs.comments());
}
case value_t::table :
{
return lhs.as_table() < rhs.as_table() ||
(lhs.as_table() == rhs.as_table() &&
lhs.comments() < rhs.comments());
}
case value_t::empty :
{
return lhs.comments() < rhs.comments();
}
default:
{
return lhs.comments() < rhs.comments();
}
}
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
typename std::enable_if<detail::conjunction<
detail::is_comparable<typename basic_value<C, T, A>::array_type>,
detail::is_comparable<typename basic_value<C, T, A>::table_type>
>::value, bool>::type
operator<=(const basic_value<C, T, A>& lhs, const basic_value<C, T, A>& rhs)
{
return (lhs < rhs) || (lhs == rhs);
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
typename std::enable_if<detail::conjunction<
detail::is_comparable<typename basic_value<C, T, A>::array_type>,
detail::is_comparable<typename basic_value<C, T, A>::table_type>
>::value, bool>::type
operator>(const basic_value<C, T, A>& lhs, const basic_value<C, T, A>& rhs)
{
return !(lhs <= rhs);
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
typename std::enable_if<detail::conjunction<
detail::is_comparable<typename basic_value<C, T, A>::array_type>,
detail::is_comparable<typename basic_value<C, T, A>::table_type>
>::value, bool>::type
operator>=(const basic_value<C, T, A>& lhs, const basic_value<C, T, A>& rhs)
{
return !(lhs < rhs);
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
inline std::string format_error(const std::string& err_msg,
const basic_value<C, T, A>& v, const std::string& comment,
std::vector<std::string> hints = {},
const bool colorize = TOML11_ERROR_MESSAGE_COLORIZED)
{
return detail::format_underline(err_msg, {{v.location(), comment}},
std::move(hints), colorize);
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
inline std::string format_error(const std::string& err_msg,
const toml::basic_value<C, T, A>& v1, const std::string& comment1,
const toml::basic_value<C, T, A>& v2, const std::string& comment2,
std::vector<std::string> hints = {},
const bool colorize = TOML11_ERROR_MESSAGE_COLORIZED)
{
return detail::format_underline(err_msg, {
{v1.location(), comment1}, {v2.location(), comment2}
}, std::move(hints), colorize);
}
template<typename C, template<typename ...> class T, template<typename ...> class A>
inline std::string format_error(const std::string& err_msg,
const toml::basic_value<C, T, A>& v1, const std::string& comment1,
const toml::basic_value<C, T, A>& v2, const std::string& comment2,
const toml::basic_value<C, T, A>& v3, const std::string& comment3,
std::vector<std::string> hints = {},
const bool colorize = TOML11_ERROR_MESSAGE_COLORIZED)
{
return detail::format_underline(err_msg, {{v1.location(), comment1},
{v2.location(), comment2}, {v3.location(), comment3}
}, std::move(hints), colorize);
}
template<typename Visitor, typename C,
template<typename ...> class T, template<typename ...> class A>
detail::return_type_of_t<Visitor, const toml::boolean&>
visit(Visitor&& visitor, const toml::basic_value<C, T, A>& v)
{
switch(v.type())
{
case value_t::boolean : {return visitor(v.as_boolean ());}
case value_t::integer : {return visitor(v.as_integer ());}
case value_t::floating : {return visitor(v.as_floating ());}
case value_t::string : {return visitor(v.as_string ());}
case value_t::offset_datetime: {return visitor(v.as_offset_datetime());}
case value_t::local_datetime : {return visitor(v.as_local_datetime ());}
case value_t::local_date : {return visitor(v.as_local_date ());}
case value_t::local_time : {return visitor(v.as_local_time ());}
case value_t::array : {return visitor(v.as_array ());}
case value_t::table : {return visitor(v.as_table ());}
case value_t::empty : break;
default: break;
}
throw std::runtime_error(format_error("[error] toml::visit: toml::basic_value "
"does not have any valid basic_value.", v, "here"));
}
template<typename Visitor, typename C,
template<typename ...> class T, template<typename ...> class A>
detail::return_type_of_t<Visitor, toml::boolean&>
visit(Visitor&& visitor, toml::basic_value<C, T, A>& v)
{
switch(v.type())
{
case value_t::boolean : {return visitor(v.as_boolean ());}
case value_t::integer : {return visitor(v.as_integer ());}
case value_t::floating : {return visitor(v.as_floating ());}
case value_t::string : {return visitor(v.as_string ());}
case value_t::offset_datetime: {return visitor(v.as_offset_datetime());}
case value_t::local_datetime : {return visitor(v.as_local_datetime ());}
case value_t::local_date : {return visitor(v.as_local_date ());}
case value_t::local_time : {return visitor(v.as_local_time ());}
case value_t::array : {return visitor(v.as_array ());}
case value_t::table : {return visitor(v.as_table ());}
case value_t::empty : break;
default: break;
}
throw std::runtime_error(format_error("[error] toml::visit: toml::basic_value "
"does not have any valid basic_value.", v, "here"));
}
template<typename Visitor, typename C,
template<typename ...> class T, template<typename ...> class A>
detail::return_type_of_t<Visitor, toml::boolean&&>
visit(Visitor&& visitor, toml::basic_value<C, T, A>&& v)
{
switch(v.type())
{
case value_t::boolean : {return visitor(std::move(v.as_boolean ()));}
case value_t::integer : {return visitor(std::move(v.as_integer ()));}
case value_t::floating : {return visitor(std::move(v.as_floating ()));}
case value_t::string : {return visitor(std::move(v.as_string ()));}
case value_t::offset_datetime: {return visitor(std::move(v.as_offset_datetime()));}
case value_t::local_datetime : {return visitor(std::move(v.as_local_datetime ()));}
case value_t::local_date : {return visitor(std::move(v.as_local_date ()));}
case value_t::local_time : {return visitor(std::move(v.as_local_time ()));}
case value_t::array : {return visitor(std::move(v.as_array ()));}
case value_t::table : {return visitor(std::move(v.as_table ()));}
case value_t::empty : break;
default: break;
}
throw std::runtime_error(format_error("[error] toml::visit: toml::basic_value "
"does not have any valid basic_value.", v, "here"));
}
}// toml
#endif// TOML11_VALUE
|