1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Andreas Gogol-Doering <andreas.doering@mdc-berlin.de>
// ==========================================================================
// Tags, declarations and generic code for the String class and its
// specializations.
// ==========================================================================
#ifndef SEQAN_SEQUENCE_STRING_ARRAY_BASE_H_
#define SEQAN_SEQUENCE_STRING_ARRAY_BASE_H_
namespace seqan {
// ============================================================================
// Forwards
// ============================================================================
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
// NOTE(rrahn): Special alloc overload for over-aligned data, e.g., simd vector types.
// We need this, since the standard new/delete operator are not guarenteed
// to support alignment higher than sizeof(void *), which causes seg faults when holding
// simd vector types in a string.
struct OverAligned_;
using OverAligned = Tag<OverAligned_>;
template <typename TSpec = void>
struct Alloc {};
// TODO(holtgrew): This requires some work: explain it, maybe rather put this into a group since the text object appears in no function's signatures.
/*!
* @concept TextConcept
* @brief Concept for a type that can be as text of an index.
* @headerfile <seqan/sequence.h>
*
* @signature concept TextConcept;
*
* Certain algorithms and data structures can work for both strings and string sets but need to treat these two
* types slightly different. Examples are index data structures and algorithms that build the indices and use
* the indices for lookup.
*
* To facilitate writing of generic algorithms, the TextConcept concept gives a common interface to both for this
* kind of algorithms.
*
* @see String
* @see StringSet
*/
/*!
* @mfn TextConcept#StringSetLimits
* @brief Return type of string set limits for TextConcept types.
*
* @signature StringSetLimits<TText>::Type;
*
* @tparam TText The type of the text.
*
* @return Type The type of string set limits objects.
*/
/*!
* @mfn TextConcept#SAValue
* @brief The default alphabet type of a suffix array, i.e. the type to store a
* position of a string or string set.
*
* @signature SAValue<TText>::Type
*
* @tparam TText The text type to query.
*
* @return TReturn A type to store a position in a <tt>TText</tt>. This could be an integer for strings or a
* pair of integers for string sets.
*
* @section Usage
*
* This type should be removed for functions returning positions in texts such as online or index-based search.
* Thus, always use this metafunction for declaring position variables.
*
* Use the functions @link TextConcept#posLocalize @endlink, @link TextConcept#posGlobalize @endlink, @link
* TextConcept#getSeqNo @endlink, and @link TextConcept#getSeqOffset @endlink for conversion between local
* and global positions in texts.
*
* @section Examples
*
* The following shows the original definition of the SAValue metafunction in SeqAn.
*
* @code{.cpp}
* template <typename TString, typename TSpec>
* struct SAValue<StringSet<TString, TSpec> >
* {
* typedef Pair<
* typename Size<StringSet<TString, TSpec> >::Type,
* typename SAValue<TString>::Type,
* Pack
* > Type;
* };
* @endcode
*/
/*!
* @fn TextConcept#stringSetLimits
* @brief Return string delimiter positions for TextConcept types.
*
* @signature TStringSetLimits stringSetLimits(text);
*
* @param[in] text The text to query for its string set limits.
*
* @return TStringSetLimits The string set limits (of type @link TextConcept#StringSetLimits @endlink).
*/
/*!
* @fn TextConcept#posLocalToX
* @brief Converts a local to a local/global position.
*
* @signature void posLocalToX(dst, localPos, limits);
*
* @param[in] dst The local or global position (pair or integer value) is written here.
* @param[in] localPos The local position.
* @param[in] limits The string limits as returned by @link TextConcept#stringSetLimits @endlink.
*/
/*!
* @class String
* @implements StringConcept
* @implements TextConcept
* @implements SegmentableConcept
* @headerfile <seqan/sequence.h>
* @brief @link StringConcept Sequence @endlink container class.
*
* @signature template <typename TValue, typename TSpec>
* class String<TValue, TSpec>;
*
* @tparam TValue The element type of the string.
* @tparam TSpec The tag for selecting the string specialization.
*
* The String class is for storing sequences and thus at the core of the sequence analysis library SeqAn. They
* are models for the @link StringConcept sequence concept @endlink but extend the sequence concept by allowing
* implicit conversion of other sequence into strings as long as the element conversion works:
*
* @snippet demos/dox/sequence/string.cpp initializing strings
*
* Aside from that, the usual operations (appending, insertion, removing, element access) are available as well.
*
* @snippet demos/dox/sequence/string.cpp usual operations
*
* Strings have a size (the actual number of elements) and a capacity (the number of elements that memory has been
* allocated for). Note that clearing a string does not free the memory (as the STL, SeqAn assumes that strings will
* later require a similar amount of memory as before). Using @link ContainerConcept#shrinkToFit @endlink, the user can
* force a re-allocation of the memory such that the string afterward uses the minimal amount of memory to accomodate
* all of its objects.
*
* @snippet demos/dox/sequence/string.cpp clear and resize
*
* @section Examples
*
* This example shows a brute force pattern matching scheme for two character Strings. Creation of String "text" shows
* the usage of some available String operating functions. See class @link StringSet @endlink for an example of a
* String container with other than simple type values. See class @link Index @endlink example for efficiently finding
* the same pattern matches using an index.
*
* @include demos/dox/sequence/string2.cpp
*
* The output is as follows:
*
* @include demos/dox/sequence/string2.cpp.stdout
*
* @see StringSet
*/
/*!
* @fn String::String
* @brief Constructor.
*
* @signature String::String()
* @signature String::String(other)
*
* @param[in] other The source for the copy constructor. Can be of any @link StringConcept sequence @endlink type
* as long as <tt>other</tt>'s elements are convertible to the value type of this string.
*
* Default and copy constructor are implemented.
*/
/*!
* @fn String::operator=
* @brief The String assignment operator allows assignment of convertible sequences.
*
* @signature TString String::operator=(other)
*
* @param[in] other The other string. Must be a sequence whose elements are convertible into this String's type.
*
* @return TString Reference to the String objecta after assignment.
*/
// TODO(holtgrew): The conversion functions rather belong into their own group than to the concept. The original documentation was a bit misleading and needs to be updated.
/*!
* @fn TextConcept#posLocalize
* @brief Converts a local/global to a local position.
* @headerfile <seqan/sequence.h>
*
* @signature void posLocalize(result, pos, limits)
*
* @param[in] pos A local or global position (pair or integer value).
* @param[in] limits The limits string returned by @link TextConcept#stringSetLimits @endlink.
* @param[in] result Reference to the resulting corresponding local position of
* <tt>pos</tt>.
*/
/*!
* @fn TextConcept#posGlobalize
* @brief Converts a local/global to a global position.
* @headerfile <seqan/sequence.h>
*
* @signature TPos posGlobalize(pos, limits)
*
* @param[in] pos A local or global position (pair or integer value). Types: Pair
* @param[in] limits The limits string returned by @link TextConcept#stringSetLimits @endlink.
*
* @return TPos The corresponding global position of <tt>pos</tt>. If
* <tt>pos</tt> is an integral type <tt>pos</tt> is returned. If
* not, <tt>limits[getSeqNo(pos, limits)] + getSeqOffset(pos,
* limits)</tt> is returned.
*/
/*!
* @fn TextConcept#getSeqNo
* @brief Returns the sequence number of a position.
* @headerfile <seqan/sequence.h>
*
* @signature TSeqNo getSeqNo(pos[, limits]);
*
* @param[in] pos A position. Types: Pair
* @param[in] limits The limits string returned by @link TextConcept#stringSetLimits @endlink.
*
* @return TSeqNo A single integer value that identifies the string within the stringset <tt>pos</tt> points at. If
* <tt>limits</tt> is omitted or @link Nothing @endlink <tt>getSeqNo</tt> returns 0.If <tt>pos</tt> is a
* local position (of class @link Pair @endlink) then <tt>i1</tt> is returned.If <tt>pos</tt> is a global
* position (integer type and <tt>limits</tt> is a @link String @endlink) then <tt>pos</tt> is converted
* to a local position and <tt>i1</tt> is returned.
*/
/*!
* @fn TextConcept#getSeqOffset
* @brief Returns the local sequence offset of a position.
* @headerfile <seqan/sequence.h>
*
* @signature TOffset getSeqOffset(pos[, limits]);
*
* @param[in] pos A position. Types: Pair
* @param[in] limits The limits string returned by @link TextConcept#stringSetLimits @endlink.
*
* @return TOffset A single integer value that identifies the position within the string <tt>pos</tt> points at.If
* <tt>limits</tt> is omitted or @link Nothing @endlink <tt>getSeqNo</tt> returns <tt>pos</tt>. If
* <tt>pos</tt> is a local position (of class @link Pair @endlink) then <tt>i2</tt> is returned.If
* <tt>pos</tt> is a global position (integer type and <tt>limits</tt> is a @link String @endlink) then
* <tt>pos</tt> is converted to a local position and <tt>i2</tt> is returned.
*/
template <typename TValue, typename TSpec = Alloc<> >
class String;
// ============================================================================
// Metafunctions
// ============================================================================
// ----------------------------------------------------------------------------
// Metafunction Value
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
struct Value<String<TValue, TSpec> >
{
typedef TValue Type;
};
template <typename TValue, typename TSpec>
struct Value<String<TValue, TSpec> const >
: public Value<String<TValue, TSpec> >
{};
// ----------------------------------------------------------------------------
// Metafunction Spec
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
struct Spec<String<TValue, TSpec> >
{
typedef TSpec Type;
};
template <typename TValue, typename TSpec>
struct Spec<String<TValue, TSpec> const>:
public Spec<String<TValue, TSpec> >
{
};
// ----------------------------------------------------------------------------
// Metafunction StringSpec
// ----------------------------------------------------------------------------
template <typename T>
struct StringSpec
{
typedef Alloc<> Type;
};
template <typename T>
struct StringSpec<T const> : StringSpec<T> {};
template <typename TValue, typename TSpec>
struct StringSpec<String<TValue, TSpec> >
{
typedef TSpec Type;
};
// ----------------------------------------------------------------------------
// Metafunction StringSpecForValue_
// ----------------------------------------------------------------------------
template <typename TValue>
struct StringSpecForValue_
{
typedef typename If<Is<SimdVectorConcept<TValue> >, Alloc<OverAligned>, Alloc<> >::Type Type;
};
// ----------------------------------------------------------------------------
// Metafunction Chunk
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
struct Chunk<String<TValue, TSpec> >:
Chunk<typename Iterator<String<TValue, TSpec>, Rooted>::Type> {};
// ----------------------------------------------------------------------------
// Metafunction IsSequence
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
struct IsSequence<String<TValue, TSpec> > : True {};
// ----------------------------------------------------------------------------
// Concept StringConcept
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
SEQAN_CONCEPT_IMPL((String<TValue, TSpec>), (StringConcept)); // resizable container
template <typename TValue, typename TSpec>
SEQAN_CONCEPT_IMPL((String<TValue, TSpec> const), (ContainerConcept)); // read-only container
// ----------------------------------------------------------------------------
// Internal Metafunction TempCopy_
// ----------------------------------------------------------------------------
template <typename T>
struct TempCopy_
{
typedef typename Value<T>::Type TValue_;
typedef typename RemoveConst_<TValue_>::Type TValueNotConst_;
typedef String<TValueNotConst_, Alloc<> > Type;
};
// ============================================================================
// Functions
// ============================================================================
// TODO(holtgrew): Where to move this documentation/specification-only stuff?
// ----------------------------------------------------------------------------
// Function swap()
// ----------------------------------------------------------------------------
template <typename TAlphabet, typename TSpec>
inline void
swap(String<TAlphabet, TSpec> & left,
String<TAlphabet, TSpec> & right)
{
typedef String<TAlphabet, TSpec> TString;
TString tmp(left, Move());
move(left, right);
move(right, tmp);
}
// ----------------------------------------------------------------------------
// Function shareResources()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
inline bool
shareResources(String<TValue, TSpec> const & obj1,
TValue const & obj2)
{
return (begin(obj1) >= &obj2) && (end(obj1) <= &obj2);
}
template <typename TValue, typename TSpec>
inline bool
shareResources(TValue const & obj1,
String<TValue, TSpec> const & obj2)
{
return (begin(obj2) >= &obj1) && (end(obj2) <= &obj1);
}
// TODO(holtgrew): Where to move this documentation/specification-only stuff?
// ----------------------------------------------------------------------------
// Function value()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec, typename TPos>
inline typename Reference< String<TValue, TSpec> >::Type
value(String<TValue, TSpec> & me,
TPos const & pos)
{
#if SEQAN_ENABLE_DEBUG
typedef typename Position< String<TValue, TSpec> >::Type TStringPos SEQAN_TYPEDEF_FOR_DEBUG;
#endif
SEQAN_ASSERT_LT_MSG(static_cast<TStringPos>(pos), static_cast<TStringPos>(length(me)), "Trying to access an element behind the last one!");
return *(begin(me, Standard()) + pos);
}
template <typename TValue, typename TSpec, typename TPos>
inline typename Reference< String<TValue, TSpec> const >::Type
value(String<TValue, TSpec> const & me,
TPos const & pos)
{
#if SEQAN_ENABLE_DEBUG
typedef typename Position< String<TValue, TSpec> const >::Type TStringPos SEQAN_TYPEDEF_FOR_DEBUG;
#endif
SEQAN_ASSERT_LT_MSG(static_cast<TStringPos>(pos), static_cast<TStringPos>(length(me)), "Trying to access an element behind the last one!");
return *(begin(me, Standard()) + pos);
}
// ----------------------------------------------------------------------------
// Function length()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
inline typename Size< String<TValue, TSpec> const>::Type
length(String<TValue, TSpec> const & me)
{
return end(me, Standard()) - begin(me, Standard());
}
// ----------------------------------------------------------------------------
// Function empty()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
inline bool
empty(String<TValue, TSpec> const & me)
{
return end(me, Standard()) == begin(me, Standard());
}
// ----------------------------------------------------------------------------
// Function clear()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec>
inline void
clear(String<TValue, TSpec> & me)
{
arrayDestruct(begin(me, Standard()), end(me, Standard()));
_setLength(me, 0);
}
// ----------------------------------------------------------------------------
// Function length()
// ----------------------------------------------------------------------------
template <typename TExpand>
struct ClearSpaceStringBase_
{
};
// ----------------------------------------------------------------------------
// Internal Function _clearSpace()
// ----------------------------------------------------------------------------
template <>
struct ClearSpaceStringBase_<Insist>
{
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size)
{
arrayDestruct(begin(seq, Standard()), end(seq, Standard()));
_setLength(seq, size);
return size;
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type limit)
{
arrayDestruct(begin(seq, Standard()), end(seq, Standard()));
if (limit < size)
{
size = limit;
}
_setLength(seq, size);
return size;
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type start,
typename Size<T>::Type end)
{
typename Size<T>::Type new_length = length(seq) + size - (end - start);
arrayClearSpace(begin(seq, Standard()) + start, length(seq) - start, end - start, size);
_setLength(seq, new_length);
return size;
}
template <typename T>
static typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type start,
typename Size<T>::Type end,
typename Size<T>::Type limit)
{
typename Value<T>::Type * seq_buffer = begin(seq);
typename Size<T>::Type seq_length = length(seq);
if (limit > start + size)
{
typename Size<T>::Type removed_size = end - start;
typename Size<T>::Type new_length = seq_length - removed_size + size;
if (limit < new_length)
{
arrayDestruct(seq_buffer + limit, seq_buffer + new_length);
seq_length -= new_length - limit;
}
arrayClearSpace(seq_buffer + start, seq_length - start, end - start, size);
_setLength(seq, new_length);
return size;
}
else
{
arrayDestruct(seq_buffer + start, seq_buffer + seq_length);
_setLength(seq, limit);
if (limit > start) return limit - start;
else return 0;
}
}
/*
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Iterator<T>::Type start,
typename Iterator<T>::Type end)
{
typename Iterator<T>::Type seq_begin = begin(seq);
return _clearSpace(seq, size, start - seq_begin, end - seq_begin, Insist());
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Iterator<T>::Type start,
typename Iterator<T>::Type end,
typename Size<T>::Type limit)
{
typename Iterator<T>::Type seq_begin = begin(seq);
return _clearSpace(seq, size, start - seq_begin, end - seq_begin, limit, Insist());
}
*/
};
template <>
struct ClearSpaceStringBase_<Limit>
{
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size)
{
return _clearSpace(seq, size, capacity(seq), Insist());
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type limit)
{
typename Size<T>::Type seq_capacity = capacity(seq);
if (limit > seq_capacity)
{
limit = seq_capacity;
}
return _clearSpace(seq, size, limit, Insist());
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type start,
typename Size<T>::Type end)
{
return _clearSpace(seq, size, start, end, capacity(seq), Insist());
}
template <typename T>
static typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type start,
typename Size<T>::Type end,
typename Size<T>::Type limit)
{
typename Size<T>::Type seq_capacity = capacity(seq);
if (limit > seq_capacity)
{
limit = seq_capacity;
}
return _clearSpace(seq, size, start, end, limit, Insist());
}
/*
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Iterator<T>::Type start,
typename Iterator<T>::Type end)
{
typename Iterator<T>::Type seq_begin = begin(seq);
return _clearSpace(seq, size, start - seq_begin, end - seq_begin, Insist());
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Iterator<T>::Type start,
typename Iterator<T>::Type end,
typename Size<T>::Type limit)
{
typename Iterator<T>::Type seq_begin = begin(seq);
return _clearSpace(seq, size, start - seq_begin, end - seq_begin, limit, Insist());
}
*/
};
template <typename TExpand>
struct ClearSpaceExpandStringBase_
{
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size)
{
arrayDestruct(begin(seq, Standard()), end(seq, Standard()));
typename Size<T>::Type old_capacity = capacity(seq);
typename Value<T>::Type * old_array = _reallocateStorage(seq, size, TExpand());
if (old_array)
{
_deallocateStorage(seq, old_array, old_capacity);
}
_setLength(seq, size);
return size;
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type limit)
{
arrayDestruct(begin(seq, Standard()), end(seq, Standard()));
if (limit < size)
{
size = limit;
}
typename Size<T>::Type old_capacity = capacity(seq);
typename Value<T>::Type * old_array = _reallocateStorage(seq, size, limit, TExpand());
if (old_array)
{
_deallocateStorage(seq, old_array, old_capacity);
}
_setLength(seq, size);
return size;
}
template <typename T>
static typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type start,
typename Size<T>::Type end)
{
typename Size<T>::Type old_length = length(seq);
typename Size<T>::Type removed_size = end - start;
typename Size<T>::Type new_length = old_length - removed_size + size;
SEQAN_ASSERT_LEQ(start, end);
SEQAN_ASSERT_LEQ(start, old_length);
typename Size<T>::Type old_capacity = capacity(seq);
typename Value<T>::Type * old_array = _reallocateStorage(seq, new_length, TExpand());
typename Value<T>::Type * seq_array = begin(seq);
if (old_array)
{
arrayConstructMove(old_array, old_array + start, seq_array);
arrayConstructMove(old_array + end, old_array + old_length, seq_array + start + size);
_deallocateStorage(seq, old_array, old_capacity);
// TODO(weese:) Did we miss to destruct the old_array here, e.g. with arrayDestruct
}
else
{
arrayClearSpace(seq_array + start, old_length - start, removed_size, size);
}
_setLength(seq, new_length);
return size;
}
template <typename T>
static typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Size<T>::Type start,
typename Size<T>::Type end,
typename Size<T>::Type limit)
{
typename Size<T>::Type old_length = length(seq);
typename Size<T>::Type removed_size = end - start;
typename Size<T>::Type need_length = old_length - removed_size + size;
SEQAN_ASSERT_LEQ(start, end);
SEQAN_ASSERT_LEQ(start, old_length);
typename Size<T>::Type new_length = need_length;
typename Size<T>::Type length_to_copy = old_length;
if (limit < need_length)
{
new_length = limit;
length_to_copy = new_length - size + removed_size;
}
bool keep_second_part = (new_length > start + size);
typename Size<T>::Type old_capacity = capacity(seq);
typename Value<T>::Type * old_array = _reallocateStorage(seq, new_length, limit, TExpand());
typename Value<T>::Type * seq_array = begin(seq);
if (old_array)
{//new buffer allocated
typename Size<T>::Type keep_start_length = (start > new_length) ? new_length : start;
arrayConstructMove(old_array, old_array + keep_start_length, seq_array);
if (keep_second_part)
{
arrayConstructMove(old_array + end, old_array + length_to_copy, seq_array + start + size);
}
_deallocateStorage(seq, old_array, old_capacity);
}
else
{
if (keep_second_part)
{
arrayClearSpace(seq_array + start, length_to_copy - start, end - start, size);
if (length_to_copy < old_length)
{
arrayDestruct(seq_array + length_to_copy, seq_array + old_length);
}
}
else
{
arrayDestruct(seq_array + start, seq_array + old_length);
}
}
_setLength(seq, new_length);
if (keep_second_part) return size;
else if (new_length > start) return new_length - start;
else return 0;
}
/*
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Iterator<T>::Type start,
typename Iterator<T>::Type end)
{
typename Iterator<T>::Type seq_begin = begin(seq);
return _clearSpace(seq, size, start - seq_begin, end - seq_begin, TExpand());
}
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size,
typename Iterator<T>::Type start,
typename Iterator<T>::Type end,
typename Size<T>::Type limit)
{
typename Iterator<T>::Type seq_begin = begin(seq);
return _clearSpace(seq, size, start - seq_begin, end - seq_begin, limit, TExpand());
}
*/
};
template <>
struct ClearSpaceStringBase_<Exact>:
ClearSpaceExpandStringBase_<Exact>
{
};
template <>
struct ClearSpaceStringBase_<Generous>:
ClearSpaceExpandStringBase_<Generous>
{
};
template<typename TValue, typename TSpec, typename TSize, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
_clearSpace(String<TValue, TSpec> & me,
TSize size,
Tag<TExpand>)
{
return ClearSpaceStringBase_<Tag<TExpand> >::_clearSpace_(me, size);
}
template<typename TValue, typename TSpec, typename TSize, typename TCapacity, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
_clearSpace(String<TValue, TSpec> & me,
TSize size,
TCapacity limit,
Tag<TExpand>)
{
return ClearSpaceStringBase_<Tag<TExpand> >::_clearSpace_(me, size, limit);
}
template<typename TValue, typename TSpec, typename TSize, typename TPosition, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
_clearSpace(String<TValue, TSpec> & me,
TSize size,
TPosition pos_begin,
TPosition pos_end,
Tag<TExpand>)
{
return ClearSpaceStringBase_<Tag<TExpand> >::_clearSpace_(me, size, pos_begin, pos_end);
}
template<typename TValue, typename TSpec, typename TSize, typename TPosition, typename TCapacity, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
_clearSpace(String<TValue, TSpec> & me,
TSize size,
TPosition pos_begin,
TPosition pos_end,
TCapacity limit,
Tag<TExpand>)
{
return ClearSpaceStringBase_<Tag<TExpand> >::_clearSpace_(me, size, pos_begin, pos_end, limit);
}
// ----------------------------------------------------------------------------
// Function resizeSpace()
// ----------------------------------------------------------------------------
template<typename TValue, typename TSpec, typename TSize, typename TBeginPosition, typename TEndPosition, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
resizeSpace(String<TValue, TSpec> & me,
TSize size,
TBeginPosition pos_begin,
TEndPosition pos_end,
Tag<TExpand> tag)
{
typedef typename Size< String<TValue, TSpec> >::Type TSize_;
typedef typename Position<String<TValue, TSpec> >::Type TPos_;
TSize_ ret_ = _clearSpace(
me,
static_cast<TSize_>(size),
static_cast<TPos_>(pos_begin),
static_cast<TPos_>(pos_end),
tag);
arrayConstruct(iter(me, pos_begin), iter(me, pos_begin) + ret_);
return ret_;
}
template<typename TValue, typename TSpec, typename TSize, typename TBeginPosition, typename TEndPosition, typename TCapacity, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
resizeSpace(String<TValue, TSpec> & me,
TSize size,
TBeginPosition pos_begin,
TEndPosition pos_end,
TCapacity limit,
Tag<TExpand> tag)
{
typedef typename Size< String<TValue, TSpec> >::Type TSize_;
typedef typename Position<String<TValue, TSpec> >::Type TPos_;
TSize_ ret_ = _clearSpace(
me,
static_cast<TSize_>(size),
static_cast<TPos_>(pos_begin),
static_cast<TPos_>(pos_end),
static_cast<TSize_>(limit),
tag);
arrayConstruct(iter(me, pos_begin), iter(me, pos_begin) + ret_);
return ret_;
}
// ----------------------------------------------------------------------------
// Function assign()
// ----------------------------------------------------------------------------
// Facade version without overflow tag. Forwards to version with overflow
// tag, using Metafunction.DefaultOverflowImplicity.
template<typename TTargetValue, typename TTargetSpec, typename TSource>
inline void
assign(String<TTargetValue, TTargetSpec> & target,
TSource & source)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
assign(target, source, typename DefaultOverflowImplicit<TTarget>::Type());
}
template<typename TTargetValue, typename TTargetSpec, typename TSource>
inline void
assign(String<TTargetValue, TTargetSpec> & target,
TSource const & source)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
assign(target, source, typename DefaultOverflowImplicit<TTarget>::Type());
}
// Helper struct for assigning strings.
template <typename TExpand>
struct AssignString_
{
template <typename TTarget, typename TSource>
static inline void
assign_(
TTarget & target,
TSource & source)
{
if (empty(source) && empty(target))
return; // Do nothing if both source and target are empty.
if (!getObjectId(source) || !shareResources(target, source))
{
typename Size<TTarget>::Type part_length = _clearSpace(target, length(source), TExpand());
arrayConstructCopy(begin(source, Standard()), begin(source, Standard()) + part_length, begin(target, Standard()));
}
else
{
if ((void *) &target == (void *) &source) return;
typename TempCopy_<TSource>::Type temp(source, length(source));
assign(target, temp, TExpand());
}
}
template <typename TTarget, typename TSource>
static inline void
assign_(
TTarget & target,
TSource & source,
typename Size<TTarget>::Type limit)
{
if (!getObjectId(source) || !shareResources(target, source))
{
typename Size<TTarget>::Type part_length = _clearSpace(target, typename Size<TTarget>::Type(length(source)), limit, TExpand());
arrayConstructCopy(begin(source, Standard()), begin(source, Standard()) + part_length, begin(target, Standard()));
}
else
{
if ((void *) &target == (void *) &source) return;
typename Size<TTarget>::Type source_length = length(source);
if (source_length > limit) source_length = limit;
typename TempCopy_<TSource>::Type temp(source, source_length);
assign(target, temp, TExpand());
}
}
};
// Interface for assign with overflow strategy tag. Forwards to static
// functions of helper struct.
template<typename TTargetValue, typename TTargetSpec, typename TSource, typename TExpand>
inline void
assign(String<TTargetValue, TTargetSpec> & target,
TSource const & source,
Tag<TExpand>)
{
AssignString_<Tag<TExpand> >::assign_(target, source);
}
template<typename TTargetValue, typename TTargetSpec, typename TSource, typename TSize, typename TExpand>
inline void
assign(String<TTargetValue, TTargetSpec> & target,
TSource const & source,
TSize limit,
Tag<TExpand>)
{
AssignString_<Tag<TExpand> >::assign_(target, source, limit);
}
//// TODO(holtgrew): Still required with dropped VC++ 2003 support?
////this variant is a workaround for the "const array"-bug of VC++
//
//template<typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TExpand>
//inline void
//assign(String<TTargetValue, TTargetSpec> & target,
// TSourceValue const * source,
// Tag<TExpand>)
//{
// AssignString_<Tag<TExpand> >::assign_(target, source);
//}
//template<typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TSize, typename TExpand>
//inline void
//assign(String<TTargetValue, TTargetSpec> & target,
// TSourceValue const * source,
// TSize limit,
// Tag<TExpand>)
//{
// AssignString_<Tag<TExpand> >::assign_(target, source, limit);
//}
// ----------------------------------------------------------------------------
// Function move()
// ----------------------------------------------------------------------------
//implementation of move for contiguous sequences
//note: there is a problem, if sizeof(TSourceValue) and sizeof(TTargetValue) are not a multiple
// of each other, since in this case the correct size cannot be determined afterwards
// when calling the deallocate function.
// ???TODO
template <typename TTarget, typename TSource>
void
_moveContiguous(TTarget & target,
TSource & source)
{
typedef typename Value<TSource>::Type TSourceValue;
typedef typename Value<TTarget>::Type TTargetValue;
clear(target);
typename Iterator<TSource, Standard>::Type source_begin = begin(source, Standard());
typename Iterator<TTarget, Standard>::Type target_begin = (typename Iterator<TTarget, Standard>::Type) begin(source, Standard());
typename Size<TTarget>::Type size = sizeof(TSourceValue) * capacity(source);
if (size >= sizeof(TTargetValue))
{
if (sizeof(TSourceValue) <= 2) ++size; //regard the "end of string termination" case
typename Size<TTarget>::Type target_capacity = size / sizeof(TTargetValue);
if (sizeof(TTargetValue) <= 2) --target_capacity; //regard the "end of string termination" case
typename Size<TTarget>::Type target_length = length(source);
if (target_length > target_capacity)
{
target_length = target_capacity;
}
if (sizeof(TSourceValue) >= sizeof(TTargetValue))
{
arrayMoveForward(source_begin, source_begin + target_length, target_begin);
}
else
{
arrayMoveBackward(source_begin, source_begin + target_length, target_begin);
}
_setBegin(target, target_begin);
_setLength(target, target_length);
_setCapacity(target, target_capacity);
typedef typename Iterator<TSource, Standard>::Type TSourceIterator;
_setBegin(source, TSourceIterator(0));
_setLength(source, 0);
_setCapacity(source, 0);
}
else
{
clear(source);
}
}
template<typename TTargetValue, typename TTargetSpec, typename TSource>
inline void
move(String<TTargetValue, TTargetSpec> & target,
TSource & source)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
move(target, source, typename DefaultOverflowImplicit<TTarget>::Type());
}
template<typename TTargetValue, typename TTargetSpec, typename TSource>
inline void
move(String<TTargetValue, TTargetSpec> & target,
TSource const & source)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
move(target, source, typename DefaultOverflowImplicit<TTarget>::Type());
}
template<typename TTargetValue, typename TTargetSpec, typename TSource, typename TTag>
inline void
move(String<TTargetValue, TTargetSpec> & target,
TSource & source,
Tag<TTag> const & tag)
{
assign(target, source, tag);
}
template<typename TTargetValue, typename TTargetSpec, typename TSource, typename TTag>
inline void
move(String<TTargetValue, TTargetSpec> & target,
TSource const & source,
Tag<TTag> const & tag)
{
assign(target, source, tag);
}
// TODO(holtgrew): Garbage?
//////////////////////////////////////////////////////////////////////////////
// valueConstructMove:
// it is usually better for strings to default construct and move instead of
// copy construct strings
/*
template <typename TIterator, typename TValue, typename TSpec>
inline void
valueConstructMove(TIterator it,
String<TValue, TSpec> const & value)
{
valueConstruct(it);
move(*it, value);
}
*/
// ----------------------------------------------------------------------------
// Function _stringCheckForOverlap
// ----------------------------------------------------------------------------
template <typename TIter1, typename TIter2, typename TSize>
inline bool
_stringCheckForPossibleOverlap(TIter1 const &, TIter2 const &, TSize)
{
return true;
}
template <typename TIter, typename TSize>
inline bool
_stringCheckForPossibleOverlap(TIter const &it1, TIter const &it2, TSize length)
{
// return false if [it1,it1+length) and [it2,it2+length) are not overlapping
return !(it2 + length <= it1 || it1 + length <= it2);
}
// ----------------------------------------------------------------------------
// Function append()
// ----------------------------------------------------------------------------
template <typename TExpand>
struct AppendString_
{
template <typename TTarget, typename TSource>
static inline void
append_(TTarget & target,
TSource & source)
{
if (!getObjectId(source) || !shareResources(target, source) ||
!_stringCheckForPossibleOverlap(begin(source, Standard()), end(target, Standard()), length(source)))
{
typename Size<TTarget>::Type target_length = length(target);
typename Size<TTarget>::Type part_length = _clearSpace(target, length(source), target_length, target_length, TExpand());
arrayConstructCopy(begin(source, Standard()), begin(source, Standard()) + part_length, begin(target, Standard()) + target_length);
}
else
{
typename TempCopy_<TSource>::Type temp(source, length(source));
append(target, temp, TExpand());
}
}
template <typename TTarget, typename TSource>
static inline void
append_(TTarget & target,
TSource & source,
typename Size<TTarget>::Type limit)
{
typename Iterator<TTarget, Standard>::Type target_begin = begin(target, Standard());
if (!getObjectId(source) || !shareResources(target, source))
{
typename Size<TTarget>::Type target_length = length(target);
typename Size<TTarget>::Type part_length = _clearSpace(target, length(source), target_length, target_length, limit, TExpand());
arrayConstructCopy(begin(source, Standard()), begin(source, Standard()) + part_length, begin(target, Standard()) + target_length);
}
else
{
typename Size<TTarget>::Type target_length = length(target);
if (target_length >= limit)
{
arrayDestruct(target_begin + limit, target_begin + target_length);
_setLength(target, limit);
}
else
{
limit -= target_length;
typename Size<TTarget>::Type source_length = length(source) ;
if (source_length > limit) source_length = limit;
typename TempCopy_<TSource>::Type temp(source, source_length);
append(target, temp, TExpand());
}
}
}
};
template<typename TTargetValue, typename TTargetSpec, typename TSource, typename TExpand>
inline void
append(String<TTargetValue, TTargetSpec> & target,
TSource const & source,
Tag<TExpand>)
{
AppendString_<Tag<TExpand> >::append_(target, source);
}
template<typename TTargetValue, typename TTargetSpec, typename TSource, typename TExpand>
inline void
append(String<TTargetValue, TTargetSpec> & target,
TSource const & source,
typename Size< String<TTargetValue, TTargetSpec> >::Type limit,
Tag<TExpand>)
{
AppendString_<Tag<TExpand> >::append_(target, source, limit);
}
// TODO(holtgrew): Still required with dropped VC++ 2003 support?
//this variant is a workaround for the "const array"-bug of VC++
// template<typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TExpand>
// inline void
// append(String<TTargetValue, TTargetSpec> & target,
// TSourceValue * source,
// Tag<TExpand>)
// {
// AppendString_<Tag<TExpand> >::append_(target, source);
// }
//
// template<typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TExpand>
// inline void
// append(String<TTargetValue, TTargetSpec> & target,
// TSourceValue * source,
// typename Size< String<TTargetValue, TTargetSpec> >::Type limit,
// Tag<TExpand>)
// {
// AppendString_<Tag<TExpand> >::append_(target, source, limit);
// }
// ----------------------------------------------------------------------------
// Function appendValue()
// ----------------------------------------------------------------------------
//TODO(h4nn3): why do we have these weird extra class? the function inside
// is only ever used in the function below and could reside directly there
template <typename TExpand>
struct AppendValueToString_
{
template <typename T, typename TValue>
static inline void
appendValue_(T & me,
TValue && _value)
{
typedef typename Value<T>::Type TTargetValue;
typedef typename Size<T>::Type TSize;
TSize me_length = length(me);
if (capacity(me) <= me_length)
{
TTargetValue temp_copy(std::forward<TValue>(_value)); //temp copy because resize could invalidate _value
// TODO(holtgrew): The resize() function will default construct the last element. This is slow. Get rid of this.
TSize new_length = reserve(me, me_length + 1, TExpand());
if (me_length < new_length)
{
// *(begin(me) + me_length) = temp_copy;
valueConstruct(begin(me, Standard()) + me_length, std::forward<TTargetValue>(temp_copy)); //??? this should be valueMoveConstruct
_setLength(me, me_length + 1);
}
}
else
{
valueConstruct(begin(me, Standard()) + me_length, std::forward<TValue>(_value));
_setLength(me, me_length + 1);
}
}
};
template <typename TTargetValue, typename TTargetSpec, typename TValue, typename TExpand>
inline void
appendValue(String<TTargetValue, TTargetSpec> & me,
TValue && _value,
Tag<TExpand>)
{
AppendValueToString_<Tag<TExpand> >::appendValue_(me, std::forward<TValue>(_value));
}
// ----------------------------------------------------------------------------
// Function appendValue(Serial)
// ----------------------------------------------------------------------------
template <typename TTargetValue, typename TTargetSpec, typename TValue, typename TExpand>
inline void
appendValue(String<TTargetValue, TTargetSpec> & me,
TValue && _value,
Tag<TExpand> const & expandTag,
Serial)
{
appendValue(me, std::forward<TValue>(_value), expandTag);
}
//////////////////////////////////////////////////////////////////////////////
// insertValue
//////////////////////////////////////////////////////////////////////////////
template <typename TExpand>
struct InsertValueToString_
{
template <typename T, typename TPosition, typename TValue>
static inline void
insertValue_(T & me,
TPosition pos,
TValue & _value)
{
typename Value<T>::Type temp_copy = _value; //temp copy because resizeSpace could invalidate _value
resizeSpace(me, 1, pos, pos, TExpand());
if ((typename Size<T>::Type) pos < length(me))
moveValue(me, pos, temp_copy);
}
};
template <typename TTargetValue, typename TTargetSpec, typename TPosition, typename TValue, typename TExpand>
inline void
insertValue(String<TTargetValue, TTargetSpec> & me,
TPosition pos,
TValue const & _value,
Tag<TExpand>)
{
InsertValueToString_<Tag<TExpand> >::insertValue_(me, pos, _value);
}
// ----------------------------------------------------------------------------
// Function replace()
// ----------------------------------------------------------------------------
template <typename TExpand>
struct ReplaceString_
{
template <typename TTarget, typename TSource>
static inline void
replace_(TTarget & target,
typename Size<TTarget>::Type pos_begin,
typename Size<TTarget>::Type pos_end,
TSource & source)
{
if (!getObjectId(source) || !shareResources(target, source))
{
typename Size<TTarget>::Type part_length = _clearSpace(target, length(source), pos_begin, pos_end, TExpand());
arrayConstructCopy(begin(source, Standard()), begin(source, Standard()) + part_length, begin(target, Standard()) + pos_begin);
}
else
{
typename TempCopy_<TSource>::Type temp(source, length(source));
replace(target, pos_begin, pos_end, temp, TExpand());
}
}
template <typename TTarget, typename TSource>
static inline void
replace_(TTarget & target,
typename Size<TTarget>::Type pos_begin,
typename Size<TTarget>::Type pos_end,
TSource & source,
typename Size<TTarget>::Type limit)
{
if (!getObjectId(source) || !shareResources(target, source))
{
typename Size<TTarget>::Type part_length = _clearSpace(target, length(source), pos_begin, pos_end, limit, TExpand());
arrayConstructCopy(begin(source, Standard()), begin(source, Standard()) + part_length, begin(target, Standard()) + pos_begin);
}
else
{
if (pos_begin >= limit)
{
arrayDestruct(begin(target) + limit, end(target));
_setLength(target, limit);
}
else
{
limit -= pos_begin;
typename Size<TTarget>::Type source_length = length(source) ;
if (source_length > limit) source_length = limit;
typename TempCopy_<TSource>::Type temp(source, source_length);
replace(target, pos_begin, pos_end, temp, limit, TExpand());
}
}
}
};
template<typename TTargetValue, typename TTargetSpec, typename TPositionBegin, typename TPositionEnd, typename TSource, typename TExpand>
inline void
replace(String<TTargetValue, TTargetSpec> & target,
TPositionBegin pos_begin,
TPositionEnd pos_end,
TSource const & source,
Tag<TExpand>)
{
ReplaceString_<Tag<TExpand> >::replace_(target, pos_begin, pos_end, source);
}
template<typename TTargetValue, typename TTargetSpec, typename TPositionBegin, typename TPositionEnd, typename TSource, typename TExpand>
inline void
replace(String<TTargetValue, TTargetSpec> & target,
TPositionBegin pos_begin,
TPositionEnd pos_end,
TSource const & source,
typename Size< String<TTargetValue, TTargetSpec> >::Type limit,
Tag<TExpand>)
{
ReplaceString_<Tag<TExpand> >::replace_(target, pos_begin, pos_end, source, limit);
}
// TODO(holtgrew): Still required with dropped VC++ 2003 support?
//this variant is a workaround for the "const array"-bug of VC++
template<typename TTargetValue, typename TTargetSpec, typename TPositionBegin, typename TPositionEnd, typename TSourceValue, typename TExpand>
inline void
replace(String<TTargetValue, TTargetSpec> & target,
TPositionBegin pos_begin,
TPositionEnd pos_end,
TSourceValue const * source,
Tag<TExpand>)
{
ReplaceString_<Tag<TExpand> >::replace_(target, pos_begin, pos_end, source);
}
template<typename TTargetValue, typename TTargetSpec, typename TPositionBegin, typename TPositionEnd, typename TSourceValue, typename TExpand>
inline void
replace(String<TTargetValue, TTargetSpec> & target,
TPositionBegin pos_begin,
TPositionEnd pos_end,
TSourceValue const * source,
typename Size< String<TTargetValue, TTargetSpec> >::Type limit,
Tag<TExpand>)
{
ReplaceString_<Tag<TExpand> >::replace_(target, pos_begin, pos_end, source, limit);
}
// ----------------------------------------------------------------------------
// Internal Function _reallocateStorage()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec, typename TSize>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> & me,
TSize new_capacity)
{
return _allocateStorage(me, new_capacity);
}
template <typename TValue, typename TSpec, typename TSize>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> & me,
TSize new_capacity,
Exact)
{
typedef typename Size<String<TValue, TSpec> >::Type TStringSize;
if (static_cast<TStringSize>(new_capacity) <= capacity(me))
return 0;
return _reallocateStorage(me, new_capacity);
}
template <typename TValue, typename TSpec, typename TSize, typename TSize2>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> & me,
TSize new_capacity,
TSize2 limit,
Exact)
{
typedef typename Size<String<TValue, TSpec> >::Type TStringSize;
if (static_cast<TStringSize>(new_capacity) <= capacity(me))
return 0;
if (new_capacity > limit) new_capacity = limit;
return _reallocateStorage(me, new_capacity);
}
template <typename TValue, typename TSpec, typename TSize>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> & me,
TSize new_capacity,
Generous)
{
typedef typename Size<String<TValue, TSpec> >::Type TStringSize;
if (static_cast<TStringSize>(new_capacity) <= capacity(me))
return 0;
new_capacity = computeGenerousCapacity(me, new_capacity);
return _reallocateStorage(me, new_capacity);
}
template <typename TValue, typename TSpec, typename TSize, typename TSize2>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> & me,
TSize new_capacity,
TSize2 limit,
Generous)
{
typedef typename Size<String<TValue, TSpec> >::Type TStringSize;
if (static_cast<TStringSize>(new_capacity) <= capacity(me))
return 0;
new_capacity = computeGenerousCapacity(me, new_capacity);
if (new_capacity > limit) new_capacity = limit;
return _reallocateStorage(me, new_capacity);
}
template <typename TValue, typename TSpec, typename TSize>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> &,
TSize,
Insist)
{
return 0;
}
template <typename TValue, typename TSpec, typename TSize, typename TSize2>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> &,
TSize,
TSize2,
Insist)
{
return 0;
}
template <typename TValue, typename TSpec, typename TSize>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> &,
TSize,
Limit)
{
return 0;
}
template <typename TValue, typename TSpec, typename TSize, typename TSize2>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> &,
TSize,
TSize2,
Limit)
{
return 0;
}
// ----------------------------------------------------------------------------
// Function reserve()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec, typename TSize_>
inline void
_reserveStorage(
String<TValue, TSpec> & /*seq*/,
TSize_ /*new_capacity*/,
Insist)
{
// do nothing
}
template <typename TValue, typename TSpec, typename TSize_>
inline void
_reserveStorage(
String<TValue, TSpec> & /*seq*/,
TSize_ /*new_capacity*/,
Limit)
{
// do nothing
}
template <typename TValue, typename TSpec, typename TSize_, typename TExpand>
inline void
_reserveStorage(
String<TValue, TSpec> & seq,
TSize_ new_capacity,
Tag<TExpand> tag)
{
typedef typename Size< String<TValue, TSpec> >::Type TSize;
TSize old_capacity = capacity(seq);
// if (old_capacity == (TSize)new_capacity) return;
// if (!IsSameType<TExpand,TagExact_>::VALUE && old_capacity > (TSize)new_capacity) return;
if (old_capacity >= (TSize)new_capacity) return;
TSize seq_length = length(seq);
typename Value< String<TValue, TSpec> >::Type * old_array = _reallocateStorage(seq, new_capacity, tag);
if (old_array)
{//buffer was replaced, destruct old buffer
// arrayConstructCopy(old_array, old_array + seq_length, begin(seq, Standard()));
arrayConstructMove(old_array, old_array + seq_length, begin(seq, Standard()));
arrayDestruct(old_array, old_array + seq_length);
_deallocateStorage(seq, old_array, old_capacity);
}
_setLength(seq, seq_length);
}
template <typename TValue, typename TSpec, typename TSize_, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
reserve(
String<TValue, TSpec> & seq,
TSize_ new_capacity,
Tag<TExpand> tag)
{
_reserveStorage(seq, new_capacity, tag);
return _capacityReturned(seq, new_capacity, tag);
}
// ----------------------------------------------------------------------------
// Function resize()
// ----------------------------------------------------------------------------
template <typename TExpand>
struct _Resize_String
{
template <typename T>
static inline typename Size<T>::Type
resize_(
T & me,
typename Size<T>::Type new_length)
{
typedef typename Size<T>::Type TSize;
TSize me_length = length(me);
if (new_length < me_length)
{
arrayDestruct(begin(me, Standard()) + new_length, begin(me, Standard()) + me_length);
}
else
{
typename Size<T>::Type me_capacity = capacity(me);
if (new_length > me_capacity)
{
TSize new_capacity = reserve(me, new_length, TExpand());
if (new_capacity < new_length)
{
new_length = new_capacity;
}
}
if (new_length > me_length)
{
arrayConstruct(begin(me, Standard()) + me_length, begin(me, Standard()) + new_length);
}
}
_setLength(me, new_length);
return new_length;
}
template <typename T, typename TValue>
static inline typename Size<T>::Type
resize_(
T & me,
typename Size<T>::Type new_length,
TValue const & val)
{
typedef typename Size<T>::Type TSize;
TSize me_length = length(me);
if (new_length < me_length)
{
arrayDestruct(begin(me, Standard()) + new_length, begin(me, Standard()) + me_length);
}
else
{
TSize me_capacity = capacity(me);
if (new_length > me_capacity)
{
TValue tempCopy = val; // reserve could invalidate val
TSize new_capacity = reserve(me, new_length, TExpand());
if (new_capacity < new_length)
{
new_length = new_capacity;
}
arrayConstruct(begin(me, Standard()) + me_length, begin(me, Standard()) + new_length, tempCopy);
} else
if (new_length > me_length)
{
arrayConstruct(begin(me, Standard()) + me_length, begin(me, Standard()) + new_length, val);
}
}
_setLength(me, new_length);
return new_length;
}
};
template <typename TValue, typename TSpec, typename TSize, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
resize(
String<TValue, TSpec> & me,
TSize new_length,
Tag<TExpand>)
{
return _Resize_String<Tag<TExpand> >::resize_(me, new_length);
}
template <typename TValue, typename TSpec, typename TSize, typename TValue2, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
resize(
String<TValue, TSpec> & me,
TSize new_length,
TValue2 const & val,
Tag<TExpand>)
{
return _Resize_String<Tag<TExpand> >::resize_(me, new_length, val);
}
// ----------------------------------------------------------------------------
// Function operator+=(), shortcut to append()
// ----------------------------------------------------------------------------
// TODO(holtgrew): Maybe move to a string_shortcuts.h?
template <typename TLeftValue, typename TLeftSpec, typename TRight >
inline
String<TLeftValue, TLeftSpec> &
operator+=(String<TLeftValue, TLeftSpec> & left,
TRight const & right)
{
append(left, right);
return left;
}
// The comparator functions forward to the code in sequence_lexical.h.
// ----------------------------------------------------------------------------
// Function operator==()
// ----------------------------------------------------------------------------
template <typename TLeftValue, typename TLeftSpec, typename TRight >
inline bool
operator==(String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
typename Comparator<String<TLeftValue, TLeftSpec> >::Type _lex(left, right);
return isEqual(_lex);
}
template <typename TLeftValue, typename TRightValue, typename TRightSpec >
inline bool
operator==(TLeftValue * left,
String<TRightValue, TRightSpec> const & right)
{
typename Comparator<String<TRightValue, TRightSpec> >::Type _lex(left, right);
return isEqual(_lex);
}
// ----------------------------------------------------------------------------
// Function operator!=()
// ----------------------------------------------------------------------------
template <typename TLeftValue, typename TLeftSpec, typename TRight >
inline bool
operator!=(String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
typename Comparator<String<TLeftValue, TLeftSpec> >::Type _lex(left, right);
return isNotEqual(_lex);
}
template <typename TLeftValue, typename TRightValue, typename TRightSpec >
inline bool
operator!=(TLeftValue * left,
String<TRightValue, TRightSpec> const & right)
{
typename Comparator<String<TRightValue, TRightSpec> >::Type _lex(left, right);
return isNotEqual(_lex);
}
// ----------------------------------------------------------------------------
// Function operator<()
// ----------------------------------------------------------------------------
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator<(String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
return isLess(left, right, typename DefaultPrefixOrder<String<TLeftValue, TLeftSpec> >::Type());
}
template <typename TLeftValue, typename TRightValue, typename TRightSpec >
inline bool
operator<(TLeftValue * left,
String<TRightValue, TRightSpec> const & right)
{
return isLess(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
// ----------------------------------------------------------------------------
// Function operator<=()
// ----------------------------------------------------------------------------
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator<=(String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
return isLessOrEqual(left, right, typename DefaultPrefixOrder<String<TLeftValue, TLeftSpec> >::Type());
}
template <typename TLeftValue, typename TRightValue, typename TRightSpec >
inline bool
operator<=(TLeftValue * left,
String<TRightValue, TRightSpec> const & right)
{
return isLessOrEqual(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
// ----------------------------------------------------------------------------
// Function operator>()
// ----------------------------------------------------------------------------
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator>(String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
return isGreater(left, right, typename DefaultPrefixOrder<String<TLeftValue, TLeftSpec> >::Type());
}
template <typename TLeftValue, typename TRightValue, typename TRightSpec >
inline bool
operator>(TLeftValue * left,
String<TRightValue, TRightSpec> const & right)
{
return isGreater(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
// ----------------------------------------------------------------------------
// Function operator>=()
// ----------------------------------------------------------------------------
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator>=(String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
return isGreaterOrEqual(left, right, typename DefaultPrefixOrder<String<TLeftValue, TLeftSpec> >::Type());
}
template <typename TLeftValue, typename TRightValue, typename TRightSpec>
inline bool
operator>=(TLeftValue * left,
String<TRightValue, TRightSpec> const & right)
{
return isGreaterOrEqual(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
// ----------------------------------------------------------------------------
// Function beginPosition()
// ----------------------------------------------------------------------------
/*!
* @fn String#beginPosition
* @headerfile <seqan/sequence.h>
* @brief Return 0 for compatibility with @link Segment @endlink.
*
* @signature TPos beginPosition(str);
*
* @param[in] seg The String to use.
*
* @return TPos Always 0.
*/
// ----------------------------------------------------------------------------
// Function endPosition()
// ----------------------------------------------------------------------------
/*!
* @fn String#endPosition
* @headerfile <seqan/sequence.h>
* @brief Return length of string for compatibility with @link Segment @endlink.
*
* @signature TPos endPosition(str);
*
* @param[in] seg The string to use.
*
* @return TPos Length of the string.
*/
// ----------------------------------------------------------------------------
// Function reserveChunk()
// ----------------------------------------------------------------------------
template <typename TValue, typename TSpec, typename TSize>
inline void reserveChunk(String<TValue, TSpec> &str, TSize size, Output)
{
reserve(str, length(str) + size);
}
template <typename TValue, typename TSpec, typename TSize>
inline void reserveChunk(String<TValue, TSpec> const &, TSize, Input)
{}
// ----------------------------------------------------------------------------
// Function getChunk()
// ----------------------------------------------------------------------------
template <typename TChunk, typename TValue, typename TSpec>
inline void
getChunk(TChunk &result, String<TValue, TSpec> &cont, Output)
{
return assignRange(result, end(cont, Standard()), begin(cont, Standard()) + capacity(cont));
}
// ----------------------------------------------------------------------------
// Function advanceChunk()
// ----------------------------------------------------------------------------
// extend target string size
template <typename TValue, typename TSpec, typename TSize>
inline void advanceChunk(String<TValue, TSpec> &str, TSize size)
{
_setLength(str, length(str) + size);
}
template <typename TValue, typename TStringSpec, typename TSpec, typename TSize>
inline void advanceChunk(Iter<String<TValue, TStringSpec>, TSpec> &iter, TSize size)
{
typedef String<TValue, TStringSpec> TContainer;
typedef Iter<TContainer, TSpec> TIter;
iter += size;
TContainer &cont = container(iter);
typename Position<TIter>::Type pos = position(iter);
if (pos > length(cont))
_setLength(cont, pos);
}
// ----------------------------------------------------------------------------
// Function operator<<() for streams.
// ----------------------------------------------------------------------------
template <typename TStream, typename TValue, typename TSpec>
inline TStream &
operator<<(TStream & target,
String<TValue, TSpec> const & source)
{
typename DirectionIterator<TStream, Output>::Type it = directionIterator(target, Output());
write(it, source);
return target;
}
// A specialization needed to avoid an ambiguous call combined with googletest.
//
// We use `std::basic_ostream<char>` instead of `std::ostream`, because we would
// need to redefine a lot of CONCEPTS within seqan. Unfortunately,
// `std::basic_ostream<char>` does not work, because `directionIterator` might not
// be included yet (defined in <iter_stream.h>). Thus using `TChar` with the
// restriction that it can only be `char`.
//
// We do not use the more generic `std::basic_ostream<TChar, Traits>` type,
// because this would clash with other overloads of `<<` where `TSpec` within
// String<TValue, ...> is more specific. E.g. in the case of `TSpec =
// Journaled<...>`.
//
// https://github.com/seqan/seqan/issues/2182
template <typename TChar, typename TValue>
inline SEQAN_FUNC_ENABLE_IF(IsSameType<TChar, char>, std::basic_ostream<TChar> &)
operator<<(std::basic_ostream<TChar> & target,
String<TValue> const & source)
{
auto it = directionIterator(target, Output());
write(it, source);
return target;
}
// ----------------------------------------------------------------------------
// Function operator>>() for streams.
// ----------------------------------------------------------------------------
template <typename TStream, typename TValue, typename TSpec>
inline TStream &
operator>>(TStream & source,
String<TValue, TSpec> & target)
{
typename DirectionIterator<TStream, Input>::Type it = directionIterator(source, Input());;
read(it, target);
return source;
}
// ----------------------------------------------------------------------------
// Function assignValueById
// ----------------------------------------------------------------------------
template<typename TValue, typename TSpec, typename TId, typename TValue2>
inline SEQAN_FUNC_ENABLE_IF(Is<IntegerConcept<TId> >, void)
assignValueById(String<TValue, TSpec> & me,
TId id,
TValue2 const & obj)
{
if (length(me) <= id)
resize(me, id + 1, TValue());
assignValue(me, id, obj);
}
// ----------------------------------------------------------------------------
// Function getValueById
// ----------------------------------------------------------------------------
template<typename TValue, typename TSpec, typename TId>
inline SEQAN_FUNC_ENABLE_IF(Is<IntegerConcept<TId> >, TValue)
getValueById(String<TValue, TSpec> & me,
TId id)
{
if (id < length(me))
return getValue(me, id);
else
return TValue();
}
} // namespace seqan
#endif // #ifndef SEQAN_SEQUENCE_STRING_ARRAY_BASE_H_
|