/usr/include/seqan/sequence/string_base.h is in seqan-dev 1.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2010, 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_HEADER_SEQUENCE_ARRAY_BASE_H
#define SEQAN_HEADER_SEQUENCE_ARRAY_BASE_H
namespace SEQAN_NAMESPACE_MAIN
{
//////////////////////////////////////////////////////////////////////////////
// Tags
//////////////////////////////////////////////////////////////////////////////
template <typename TSpec = void>
struct Alloc {};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
.Class.String:
..cat:Sequences
..summary:General purpose container for sequences.
..signature:String<TValue, TSpec>
..param.TValue:The value type, that is the type of the items/characters stored in the string.
...metafunction:Metafunction.Value
..param.TSpec:The specializing type.
...metafunction:Metafunction.Spec
...default:$Alloc<>$, see @Spec.Alloc String@.
..implements:Concept.Container
..include:seqan/sequence.h
*/
template <typename TValue, typename TSpec = Alloc<> >
class String;
//////////////////////////////////////////////////////////////////////////////
// METAFUNCTIONS
//////////////////////////////////////////////////////////////////////////////
///.Metafunction.Iterator.param.T.type:Class.String
//////////////////////////////////////////////////////////////////////////////
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.param.T.type:Class.String
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.IsSequence.param.T.type:Class.String
template <typename TValue, typename TSpec>
struct IsSequence<String<TValue, TSpec> > {
typedef True Type;
enum { VALUE = true };
};
//////////////////////////////////////////////////////////////////////////////
// Returns a Class that can be used to store a temporary copy of a String
template <typename T>
struct TempCopy_
{
typedef typename Value<T>::Type TValue;
typedef typename RemoveConst_<TValue>::Type TValue_NotConst;
typedef String<TValue_NotConst, Alloc<> > Type;
};
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
///.Function.id.param.object.type:Class.String
///.Function.empty.param.object.type:Class.String
///.Function.capacity.param.object.type:Class.String
//////////////////////////////////////////////////////////////////////////////
// swap
//////////////////////////////////////////////////////////////////////////////
// forwards for swap
template<typename TAlphabet, typename TSpec> class String;
template<typename TString, typename TSpec> class StringSet;
/**
.Function.swap:
..summary:Swaps the contents of two values.
..cat:Content Manipulation
..signature:swap(left, right)
..param.left:The first value.
...type:Class.String
...type:Class.StringSet
..param.right:The second value.
...type:Class.String
...type:Class.StringSet
..remarks:The function swaps the values of variables left and right.
This is equivalent to using move three times with a temporary variable.
Note that this function has the same name as the STL function $std::swap$ but is in a different namespace.
Argument Dependent Lookup (ADL, aka Koenig lookup) will take care that the right $swap$ function is called from STL $sort$, for example.
We only specialize it for Class.String and Class.StringSet.
..see:Function.move
..include:seqan/sequence.h
*/
template <typename TAlphabet, typename TSpec>
inline void
swap(String<TAlphabet, TSpec> & left,
String<TAlphabet, TSpec> & right)
{
SEQAN_CHECKPOINT;
typedef String<TAlphabet, TSpec> TString;
TString tmp(left, Move());
move(left, right);
move(right, tmp);
}
// TODO(holtgrew): This actually belongs into sequence_multiple.h.
template <typename TString, typename TSpec>
inline void
swap(StringSet<TString, TSpec> & left,
StringSet<TString, TSpec> & right)
{
SEQAN_CHECKPOINT;
typedef StringSet<TString, TSpec> TStringSet;
TStringSet tmp(left, Move());
move(left, right);
move(right, tmp);
}
//////////////////////////////////////////////////////////////////////////////
//shareResources
///.Function.shareResources.param.sequence1, sequence2.type:Class.String
template <typename TValue, typename TSpec>
inline bool
shareResources(String<TValue, TSpec> const & obj1,
TValue const & obj2)
{
SEQAN_CHECKPOINT
return (begin(obj1) >= &obj2) && (end(obj1) <= &obj2);
}
template <typename TValue, typename TSpec>
inline bool
shareResources(TValue const & obj1,
String<TValue, TSpec> const & obj2)
{
SEQAN_CHECKPOINT
return (begin(obj2) >= &obj1) && (end(obj2) <= &obj1);
}
//////////////////////////////////////////////////////////////////////////////
///.Function.begin.param.object.type:Class.String
///.Function.end.param.object.type:Class.String
//////////////////////////////////////////////////////////////////////////////
///.Function.value.param.container.type:Class.String
template <typename TValue, typename TSpec, typename TPos>
inline typename Reference< String<TValue, TSpec> >::Type
value(String<TValue, TSpec> & me,
TPos pos)
{
typedef typename Position< String<TValue, TSpec> >::Type TStringPos;
SEQAN_CHECKPOINT;
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 pos)
{
typedef typename Position< String<TValue, TSpec> const >::Type TStringPos;
SEQAN_CHECKPOINT;
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.param.object.type:Class.String
template <typename TValue, typename TSpec>
inline typename Size< String<TValue, TSpec> const>::Type
length(String<TValue, TSpec> const & me)
{
SEQAN_CHECKPOINT
return end(me, Standard()) - begin(me, Standard());
}
//////////////////////////////////////////////////////////////////////////////
///.Function.length.param.object.type:Class.String
template <typename TValue, typename TSpec>
inline bool
empty(String<TValue, TSpec> const & me)
{
SEQAN_CHECKPOINT
return end(me, Standard()) == begin(me, Standard());
}
//////////////////////////////////////////////////////////////////////////////
/**
.Function.clear:
..cat:Containers
..summary:Resets an object.
..signature:clear(object)
..param.object:The object that will be resetted.
...type:Class.String
..remarks:$object$ is set to a state that is equivalent to a default constructed object of the same type.
..remarks:If $object$ is a container, then all elements are removed from this container.
The length is set to 0.
The capacity can be changed, depending on the implementation.
..see:Function.resize
..see:Function.length
..include:seqan/sequence.h
*/
template <typename TValue, typename TSpec>
inline void
clear(String<TValue, TSpec> & me)
{
SEQAN_CHECKPOINT
arrayDestruct(begin(me, Standard()), end(me, Standard()));
_setLength(me, 0);
}
//////////////////////////////////////////////////////////////////////////////
template <typename TExpand>
struct ClearSpaceStringBase_
{
};
//____________________________________________________________________________
template <>
struct ClearSpaceStringBase_<Insist>
{
template <typename T>
static inline typename Size<T>::Type
_clearSpace_(
T & seq,
typename Size<T>::Type size)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
typename Size<T>::Type removed_size = end - start;
typename Size<T>::Type new_length = seq_length - removed_size + size;
if (limit < new_length)
{
SEQAN_CHECKPOINT
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
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
_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)
{
SEQAN_CHECKPOINT
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;
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)
{
SEQAN_CHECKPOINT
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);
}
else
{
SEQAN_CHECKPOINT
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;
typename Size<T>::Type new_length = need_length;
typename Size<T>::Type length_to_copy = old_length;
if (limit < need_length)
{
SEQAN_CHECKPOINT
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>
{
};
//____________________________________________________________________________
/**
.Internal._clearSpace:
..cat:Functions
..summary:Makes space in container
..signature:_clearSpace(object, size [, pos_begin, pos_end] [, limit], resize_tag)
..param.object:The container.
..param.size:Length of the freed space.
..param.pos_begin:Position of the first item in $object$ that is to be destroyed. (optional)
..param.pos_end:Position behind the last item in $object$ that is to be destroyed. (optional)
...remarks:If $pos_end == pos_begin$, no item in $object$ will be destroyed.
..param.limit:Maximal length $object$ can get after this operation. (optional)
..param.resize_tag:Strategy that is applied if $object$ has not enough capacity to store the complete content.
..returns:The number of free characters.
...remarks:Depeding on the @Tag.Overflow Strategy.overflow strategy@ specified by $resize_tag$,
this could be $size$ or less than $size$ if $object$ has not enough @Function.capacity@.
..remarks:This function is similar to @Function.resizeSpace@ and @Function.fillSpace@.
The main difference is that $_clearSpace$ does not construct objects in the new created space.
*/
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> const)
{
SEQAN_CHECKPOINT
return ClearSpaceStringBase_<Tag<TExpand> const>::_clearSpace_(me, size);
}
template<typename TValue, typename TSpec, typename TSize, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
_clearSpace(String<TValue, TSpec> & me,
TSize size,
TSize limit,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT
return ClearSpaceStringBase_<Tag<TExpand> const>::_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> const)
{
SEQAN_CHECKPOINT
return ClearSpaceStringBase_<Tag<TExpand> const>::_clearSpace_(me, size, pos_begin, pos_end);
}
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,
TSize limit,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT
return ClearSpaceStringBase_<Tag<TExpand> const>::_clearSpace_(me, size, pos_begin, pos_end, limit);
}
//////////////////////////////////////////////////////////////////////////////
///.Function.resizeSpace.param.object.type:Class.String
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> const tag)
{
SEQAN_CHECKPOINT
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 TLimit, typename TExpand>
inline typename Size< String<TValue, TSpec> >::Type
resizeSpace(String<TValue, TSpec> & me,
TSize size,
TBeginPosition pos_begin,
TEndPosition pos_end,
TLimit limit,
Tag<TExpand> const tag)
{
SEQAN_CHECKPOINT
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_;
}
//////////////////////////////////////////////////////////////////////////////
// assignValue (2)
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec, typename TValue2>
inline void
assignValue(String<TValue, TSpec> & /*me*/,
TValue2 const & /*_value*/)
{
// assign(me, toString(_value)); ???TODO
}
//???TODO: moveValue (2)
//////////////////////////////////////////////////////////////////////////////
// assign
//////////////////////////////////////////////////////////////////////////////
///.Function.assign.param.target.type:Class.String
///.Function.assign.param.source.type:Class.String
//overload of binary version for strings:
template<typename TTargetValue, typename TTargetSpec, typename TSource>
inline void
assign(String<TTargetValue, TTargetSpec> & target,
TSource & source)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
assign(target, source, typename DefaultOverflowImplicit<TTarget>::Type());
}
//////////////////////////////////////////////////////////////////////////////
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 (!id(source) || !shareResources(target, source))
{
SEQAN_CHECKPOINT
typename Size<TTarget>::Type part_length = _clearSpace(target, length(source), TExpand());
arrayConstructCopy(begin(source, Standard()), begin(source, Standard()) + part_length, begin(target, Standard()));
}
else
{
SEQAN_CHECKPOINT
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 (!id(source) || !shareResources(target, source))
{
SEQAN_CHECKPOINT
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
{
SEQAN_CHECKPOINT
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());
}
}
};
//////////////////////////////////////////////////////////////////////////////
template<typename TTargetValue, typename TTargetSpec, typename TSource, typename TExpand>
inline void
assign(String<TTargetValue, TTargetSpec> & target,
TSource const & source,
Tag<TExpand> const)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
AssignString_<Tag<TExpand> const>::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> const)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
AssignString_<Tag<TExpand> const>::assign_(target, source, limit);
}
//____________________________________________________________________________
//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> const)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
AssignString_<Tag<TExpand> const>::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> const)
{
typedef String<TTargetValue, TTargetSpec> TTarget;
AssignString_<Tag<TExpand> const>::assign_(target, source, limit);
}
//////////////////////////////////////////////////////////////////////////////
// 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))
{
SEQAN_CHECKPOINT
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);
_setBegin(source, 0);
_setLength(source, 0);
_setCapacity(source, 0);
}
else
{
clear(source);
}
}
//____________________________________________________________________________
//overload of binary version for strings:
template<typename TTargetValue, typename TTargetSpec, typename TSource>
inline void
move(String<TTargetValue, TTargetSpec> & target,
TSource & source)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
assign(target, source, tag);
}
//////////////////////////////////////////////////////////////////////////////
// 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);
}
*/
//////////////////////////////////////////////////////////////////////////////
// append
//////////////////////////////////////////////////////////////////////////////
///.Function.append.param.target.type:Class.String
///.Function.append.param.source.type:Class.String
template <typename TExpand>
struct AppendString_
{
template <typename TTarget, typename TSource>
static inline void
append_(TTarget & target,
TSource & source)
{
if (!id(source) || !shareResources(target, source))
{
SEQAN_CHECKPOINT
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
{
SEQAN_CHECKPOINT
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 (!id(source) || !shareResources(target, source))
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
arrayDestruct(target_begin + limit, target_begin + target_length);
_setLength(target, limit);
}
else
{
SEQAN_CHECKPOINT
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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
AppendString_<Tag<TExpand> const>::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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
AppendString_<Tag<TExpand> const>::append_(target, source, limit);
}
//____________________________________________________________________________
//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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
AppendString_<Tag<TExpand> const>::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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
AppendString_<Tag<TExpand> const>::append_(target, source, limit);
}
//////////////////////////////////////////////////////////////////////////////
// appendValue
//////////////////////////////////////////////////////////////////////////////
template <typename TExpand>
struct AppendValueToString_
{
template <typename T, typename TValue>
static inline void
appendValue_(T & me,
TValue & _value)
{
SEQAN_CHECKPOINT
typename Position<T>::Type me_length = length(me);
if (capacity(me) <= me_length)
{
typename Value<T>::Type temp_copy(_value); //temp copy because resize could invalidate _value
typename Size<T>::Type new_length = resize(me, me_length + 1, TExpand());
if (me_length < new_length)
{
valueConstruct(begin(me) + me_length, temp_copy); //??? this should be valueMoveConstruct
}
}
else
{
valueConstruct(begin(me, Standard()) + me_length, _value);
_setLength(me, me_length + 1);
}
}
};
//____________________________________________________________________________
template <typename TTargetValue, typename TTargetSpec, typename TValue, typename TExpand>
inline void
appendValue(String<TTargetValue, TTargetSpec> & me,
TValue const & _value,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT
AppendValueToString_<Tag<TExpand> const>::appendValue_(me, _value);
}
//////////////////////////////////////////////////////////////////////////////
// insertValue
//////////////////////////////////////////////////////////////////////////////
/**
.Function.insertValue:
..include:seqan/sequence.h
*/
template <typename TExpand>
struct InsertValueToString_
{
template <typename T, typename TPosition, typename TValue>
static inline void
insertValue_(T & me,
TPosition pos,
TValue & _value)
{
SEQAN_CHECKPOINT
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> const)
{
SEQAN_CHECKPOINT
InsertValueToString_<Tag<TExpand> const>::insertValue_(me, pos, _value);
}
//////////////////////////////////////////////////////////////////////////////
// replace
//////////////////////////////////////////////////////////////////////////////
///.Function.replace.param.target.type:Class.String
///.Function.replace.param.source.type:Class.String
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 (!id(source) || !shareResources(target, source))
{
SEQAN_CHECKPOINT
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
{
SEQAN_CHECKPOINT
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 (!id(source) || !shareResources(target, source))
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
arrayDestruct(begin(target) + limit, end(target));
_setLength(target, limit);
}
else
{
SEQAN_CHECKPOINT
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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
ReplaceString_<Tag<TExpand> const>::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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
ReplaceString_<Tag<TExpand> const>::replace_(target, pos_begin, pos_end, source, limit);
}
//____________________________________________________________________________
//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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
ReplaceString_<Tag<TExpand> const>::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> const)
{
SEQAN_CHECKPOINT
typedef String<TTargetValue, TTargetSpec> TTarget;
ReplaceString_<Tag<TExpand> const>::replace_(target, pos_begin, pos_end, source, limit);
}
//////////////////////////////////////////////////////////////////////////////
/**
.Internal._reallocateStorage:
..cat:Functions
..summary:Allocates a new buffer if needed.
..signature:_reallocateStorage(object, new_capacity, resize_tag)
..param.object:A container for which the buffer is reallocated.
...type:Class.String
..param.new_capacity:The capacity $object$ will get after reallocating the buffer.
..param.resize_tag:Strategy that is used for changing the capacity.
..returns:Returns the old buffer, if a new buffer has been allocated, $0$ otherwise.
..remarks:This function only allocates a new buffer if the current capacity is less then $new_capacity$.
A new buffer is not filled with any content, all copy operations must be done by the caller.
..remarks:If $object$ never had a buffer, or the buffer is not changed by the function,
the returned pointer is 0.
*/
template <typename TValue, typename TSpec, typename TSize>
inline typename Value<String<TValue, TSpec> >::Type *
_reallocateStorage(
String<TValue, TSpec> & me,
TSize new_capacity)
{
SEQAN_CHECKPOINT
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;
else
{
SEQAN_CHECKPOINT
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;
else
{
SEQAN_CHECKPOINT
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;
}
else
{
SEQAN_CHECKPOINT
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;
else
{
SEQAN_CHECKPOINT
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.param.object.type:Class.String
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> const 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
// arrayConstruct(begin(seq, Standard()), begin(seq, Standard()) + seq_length);
// arrayMoveForward(old_array, old_array + seq_length, begin(seq, Standard()));
arrayConstructCopy(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);
}
else if (!old_capacity)
{//new buffer created and the string had no buffer yet
_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> const tag)
{
SEQAN_CHECKPOINT
_reserveStorage(seq, new_capacity, tag);
return _capacityReturned(seq, new_capacity, tag);
}
//////////////////////////////////////////////////////////////////////////////
///.Function.resize.param.object.type:Class.String
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)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
TSize new_capacity = reserve(me, new_length, TExpand());
if (new_capacity < new_length)
{
new_length = new_capacity;
}
}
if (new_length > me_length)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
arrayDestruct(begin(me, Standard()) + new_length, begin(me, Standard()) + me_length);
}
else
{
TSize me_capacity = capacity(me);
if (new_length > me_capacity)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
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> const)
{
SEQAN_CHECKPOINT
return _Resize_String<Tag<TExpand> const>::resize_(me, new_length);
}
template <typename TValue, typename TSpec, typename TSize, typename TValue2, typename TExpand>
inline TSize
resize(String<TValue, TSpec> & me,
TSize new_length,
TValue2 const & val,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT
return _Resize_String<Tag<TExpand> const>::resize_(me, new_length, val);
}
//////////////////////////////////////////////////////////////////////////////
/*
template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
String<TLeftValue, TLeftSpec> const &
operator += (String<TLeftValue, TLeftSpec> & left,
String<TRightValue, TRightSpec> const & right)
{
append(left, right);
return left;
}
template <typename TLeftValue, typename TLeftSpec, typename TRight>
String<TLeftValue, TLeftSpec> const &
operator += (String<TLeftValue, TLeftSpec> & left,
TRight const & right)
{
append(left, right);
return left;
}
template <typename TLeft, typename TRightValue, typename TRightSpec>
TLeft const &
operator += (TLeft & left,
String<TRightValue, TRightSpec> const & right)
{
append(left, right);
return left;
}
*/
template <typename TLeftValue, typename TLeftSpec, typename TRight >
String<TLeftValue, TLeftSpec> const &
operator += (String<TLeftValue, TLeftSpec> & left,
TRight const & right)
{
SEQAN_CHECKPOINT
append(left, right);
return left;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TLeftValue, typename TLeftSpec, typename TRight >
inline bool
operator == (String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
typename Comparator<String<TRightValue, TRightSpec> >::Type _lex(left, right);
return isEqual(_lex);
}
//////////////////////////////////////////////////////////////////////////////
template <typename TLeftValue, typename TLeftSpec, typename TRight >
inline bool
operator !=(String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
typename Comparator<String<TRightValue, TRightSpec> >::Type _lex(left, right);
return isNotEqual(_lex);
}
//////////////////////////////////////////////////////////////////////////////
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator < (String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
return isLess(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
//////////////////////////////////////////////////////////////////////////////
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator <= (String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
return isLessOrEqual(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
//////////////////////////////////////////////////////////////////////////////
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator > (String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
return isGreater(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
//////////////////////////////////////////////////////////////////////////////
template <typename TLeftValue, typename TLeftSpec, typename TRight>
inline bool
operator >= (String<TLeftValue, TLeftSpec> const & left,
TRight const & right)
{
SEQAN_CHECKPOINT
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)
{
SEQAN_CHECKPOINT
return isGreaterOrEqual(left, right, typename DefaultPrefixOrder<TLeftValue *>::Type());
}
//////////////////////////////////////////////////////////////////////////////
// stream operators
//////////////////////////////////////////////////////////////////////////////
template <typename TStream, typename TValue, typename TSpec>
inline TStream &
operator << (TStream & target,
String<TValue, TSpec> const & source)
{
SEQAN_CHECKPOINT
write(target, source);
return target;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TStream, typename TValue, typename TSpec>
inline TStream &
operator >> (TStream & source,
String<TValue, TSpec> & target)
{
SEQAN_CHECKPOINT
read(source, target);
return source;
}
//////////////////////////////////////////////////////////////////////////////
/*
//////////////////////////////////////////////////////////////////////////////
// Converter
//////////////////////////////////////////////////////////////////////////////
template <typename TTarget, typename TSource, typename TSpec>
struct Value<String<Convert<TTarget, TSource>, TSpec> >:
Value< String<TSource, TSpec> >
{
};
//////////////////////////////////////////////////////////////////////////////
template <typename T, typename TAccessor, typename TConverter>
struct AccessorConverter_
{
typedef T Type;
};
template <typename T, typename TAccessor, typename TConverter>
struct AccessorConverter_<T, TAccessor &, typename TConverter &>
{
typedef T & Type;
};
template <typename TTarget, typename TSource, typename TSpec>
struct GetValue<String<Converter<TTarget, TSource>, TSpec> >:
AccessorConverter_<
TTarget,
typename GetValue<String<TSource, TSpec> >::Type,
typename Converter<TTarget, TSource>::Type
>
{
};
*/
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
} //namespace SEQAN_NAMESPACE_MAIN
#endif //#ifndef SEQAN_HEADER_...
|