/usr/include/seqan/sequence/string_cstyle.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 | // ==========================================================================
// 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>
// ==========================================================================
// Implementation of the CStyle String specialization,
// ==========================================================================
#ifndef SEQAN_HEADER_SEQUENCE_CSTYLE_H
#define SEQAN_HEADER_SEQUENCE_CSTYLE_H
namespace seqan {
// ============================================================================
// Forwards
// ============================================================================
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
//////////////////////////////////////////////////////////////////////////////
//string that exports an interface to cstyle strings.
/**
.Spec.CStyle String:
..cat:Strings
..general:Class.String
..summary:Allows adaption of strings to C-style strings.
..signature:String<TValue, CStyle>
..param.TValue:The value type, that is the type of the items/characters stored in the string.
...remarks:Use @Metafunction.Value@ to get the value type for a given class.
...note:$TValue$ must be a @Concept.Simple Type@.
..remarks:
..text:Assigning a string $TValue *$ to a CStyle String will not create a copy of the string but just copy pointers.
..remarks:
...text:The purpose of this class is to access to the content of a sequence
in a "zero terminated string" style.
This can be useful if SeqAn classes has to be integrated in programs that use $char$ arrays
to store strings.
Instances of $String<TValue, CStyle>$ can implicitely converted to a $TValue *$ that
points to a zero terminated CStyle of $TValue$.
...text:The stored c-style string object can be set by constructors or assignment.
The content of a c-style string can eighter be stored in a separate buffer, that is the source string
is copied. Or the buffer of the source string itself is used instead, in this case the c-style string
depends on the source string and gets invalid as soon as the buffer of the source string is destroyed.
...text:Hence, this class is a kind of adaptor from an arbitrary SeqAn string to char arrays.
Of course, the opposite way is possible too:
Read @Adaption.char array.here@ about adapting char arrays to SeqAn strings.
..example:
...code:// Create a string str:
String<char> str = "this is a test string";
// Create a c-style string object for str:
String<char, CStyle> cStyle = str;
// Now use cStyle as char array:
strcmp(cStyle, "compare it to this string");
...text:If the c-style string is needed only temporarily, the function $toCString$ can be used:
...code:String<char> str = "this is a test string";
strcmp(toCString(str), "compare it to this string");
..include:seqan/sequence.h
*/
struct CStyle;
#ifdef PLATFORM_WINDOWS_VS
#pragma warning( push )
// Disable warning C4521 locally (multiple copy constructors).
#pragma warning( disable: 4521 )
// Disable warning C4522 locally (multiple assignment operators).
#pragma warning( disable: 4522 )
#endif // PLATFORM_WINDOWS_VS
template <typename TValue>
class String <TValue, CStyle >
{
public:
TValue * data_begin;
TValue * data_end;
// If data_size > 0, then the buffer is owned by me and must be deallocated.
size_t data_size;
public:
// TODO(holtgrew): Maybe better point to 0?
static TValue EMPTY_STRING;
//____________________________________________________________________________
public:
String():
data_begin(&EMPTY_STRING),
data_end(&EMPTY_STRING),
data_size(0)
{
SEQAN_CHECKPOINT;
}
//____________________________________________________________________________
template <typename TString>
String(TString & str):
data_size(0)
{
SEQAN_CHECKPOINT;
assign(*this, str);
}
template <typename TString>
String(TString const & str):
data_size(0)
{
SEQAN_CHECKPOINT;
assign(*this, str);
}
String(String & str):
data_size(0)
{
SEQAN_CHECKPOINT;
assign(*this, str);
}
String(String const & str):
data_size(0)
{
SEQAN_CHECKPOINT;
assign(*this, str);
}
String(TValue * str):
data_begin(str),
data_end(end(str)),
data_size(0)
{
SEQAN_CHECKPOINT;
}
//____________________________________________________________________________
template <typename TString>
String & operator = (TString & str)
{
SEQAN_CHECKPOINT;
assign(*this, str);
return *this;
}
template <typename TString>
String & operator = (TString const & str)
{
SEQAN_CHECKPOINT;
assign(*this, str);
return *this;
}
String & operator = (String & str)
{
SEQAN_CHECKPOINT;
assign(*this, str);
return *this;
}
String & operator = (String const & str)
{
SEQAN_CHECKPOINT;
assign(*this, str);
return *this;
}
~String()
{
SEQAN_CHECKPOINT;
clear(*this);
}
//____________________________________________________________________________
operator TValue * ()
{
SEQAN_CHECKPOINT;
return data_begin;
}
operator TValue const * () const
{
SEQAN_CHECKPOINT;
return data_begin;
}
};
// Define the static member
template <typename TValue>
TValue String<TValue, CStyle >::EMPTY_STRING = TValue();
#ifdef PLATFORM_WINDOWS_VS
// Reset warning state to previous one for C4521, C4522.
#pragma warning( pop )
#endif // PLATFORM_WINDOWS_VS
// ============================================================================
// Metafunctions
// ============================================================================
// --------------------------------------------------------------------------
// Metafunction DefaultOverflowImplicit
// --------------------------------------------------------------------------
template <typename TValue>
struct DefaultOverflowImplicit<String<TValue, CStyle> >
{
typedef Exact Type;
};
// --------------------------------------------------------------------------
// Metafunction IsContiguous
// --------------------------------------------------------------------------
template <typename TValue>
struct IsContiguous< String<TValue, CStyle > >
{
typedef True Type;
enum { VALUE = true };
};
// ============================================================================
// Functions
// ============================================================================
// --------------------------------------------------------------------------
// Function move()
// --------------------------------------------------------------------------
template <typename TValue>
inline void
move(
String <TValue, CStyle > & target,
String <TValue, CStyle > & source)
{
SEQAN_CHECKPOINT;
clear(target);
target.data_begin = source.data_begin;
target.data_end = source.data_end;
target.data_size = source.data_size;
source.data_begin = 0;
source.data_end = 0;
source.data_size = 0;
}
template <typename TValue>
inline void
move(
String <TValue, CStyle > & target,
String <TValue, CStyle > const & source)
{
SEQAN_CHECKPOINT;
move(target, const_cast<String<TValue, CStyle> &>(source));
}
// --------------------------------------------------------------------------
// Function begin()
// --------------------------------------------------------------------------
template <typename TValue>
inline typename Iterator<String<TValue, CStyle >, Standard>::Type
begin(String <TValue, CStyle > & me,
Standard)
{
SEQAN_CHECKPOINT;
return me.data_begin;
}
template <typename TValue>
inline typename Iterator<String<TValue, CStyle > const, Standard>::Type
begin(String <TValue, CStyle > const & me,
Standard)
{
SEQAN_CHECKPOINT;
return me.data_begin;
}
// --------------------------------------------------------------------------
// Function _setBegin()
// --------------------------------------------------------------------------
template <typename TValue, typename TValue2>
inline void
_setBegin(String <TValue, CStyle > & me, TValue2 new_begin)
{
SEQAN_CHECKPOINT;
me.data_begin = new_begin;
}
// --------------------------------------------------------------------------
// Function end()
// --------------------------------------------------------------------------
template <typename TValue>
inline typename Iterator<String <TValue, CStyle >, Standard>::Type
end(String <TValue, CStyle > & me,
Standard)
{
SEQAN_CHECKPOINT;
return me.data_end;
}
template <typename TValue>
inline typename Iterator<String <TValue, CStyle > const, Standard>::Type
end(String <TValue, CStyle > const & me,
Standard)
{
SEQAN_CHECKPOINT;
return me.data_end;
}
// --------------------------------------------------------------------------
// Function _setEnd()
// --------------------------------------------------------------------------
template <typename TValue, typename TValue2>
inline void
_setEnd(String <TValue, CStyle > & me, TValue2 new_end)
{
SEQAN_CHECKPOINT;
me.data_end = new_end;
if (new_end != NULL)
*new_end = TValue(); //??? ist das wirklich sinnvoll fuer typen, die weder char noch wchar_t sind?
}
// --------------------------------------------------------------------------
// Function capacity()
// --------------------------------------------------------------------------
template <typename TValue>
inline size_t
capacity(String <TValue, CStyle > const & me)
{
SEQAN_CHECKPOINT;
if (me.data_size) return me.data_size -1;
else return me.data_end - me.data_begin;
}
// --------------------------------------------------------------------------
// Function _reallocateStorage()
// --------------------------------------------------------------------------
///.Internal._reallocateStorage.param.object.type:Spec.CStyle String
///.Internal._reallocateStorage.param.resize_tag.remarks:@Spec.CStyle String@ only supports @Tag.Overflow Strategy.exact@.
//this function works also for dependent buffers
template <typename TValue>
inline TValue *
_reallocateStorage(
String <TValue, CStyle > & me,
size_t new_capacity,
Exact)
{
SEQAN_CHECKPOINT;
TValue * _returnValue;
if (me.data_size)
{//dependent
_returnValue = me.data_begin;
}
else
{//not dependent
_returnValue = 0;
}
me.data_size = new_capacity + 1; //+1 for zero termination
allocate(me, me.data_begin, me.data_size, TagAllocateStorage());
return _returnValue;
}
// --------------------------------------------------------------------------
// Function _deallocateStorage()
// --------------------------------------------------------------------------
///.Internal._deallocateStorage.param.object.type:Spec.CStyle String
template <typename TValue>
inline void
_deallocateStorage(
String <TValue, CStyle > & me,
TValue * ptr,
size_t capacity)
{
SEQAN_CHECKPOINT;
size_t size = capacity + 1;
deallocate(me, ptr, size, TagAllocateStorage());
}
// --------------------------------------------------------------------------
// Function dependent()
// --------------------------------------------------------------------------
/**
.Function.dependent:
..summary:Test whether object depends on other objects.
..cat:Dependent Objects
..signature:bool dependent(object)
..param.object:An object.
...type:Spec.CStyle String
..returns:$true$ if $object$ depends one some other object, $false$ otherwise.
..remarks:An object "$a$" depends on another object "$b$", if changing "$b$" can invalidate "$a$";
especially the destruction of "$b$" invalidates "$a$".
..include:seqan/sequence.h
*/
template <typename TValue>
inline bool
dependent(String <TValue, CStyle > & me)
{
SEQAN_CHECKPOINT;
return (me.data_size == 0);
}
// --------------------------------------------------------------------------
// Function assign()
// --------------------------------------------------------------------------
//special implementation for char array sources
template <typename TValue>
inline void
assign(String <TValue, CStyle > & target,
TValue * source)
{
SEQAN_CHECKPOINT;
clear(target);
target.data_begin = source;
target.data_end = end(source);
}
// --------------------------------------------------------------------------
// Function assign()
// --------------------------------------------------------------------------
template <typename TTargetValue, typename TSource, typename TExpand>
inline void
assign(String<TTargetValue, CStyle> & target,
TSource & source,
Tag<TExpand> const tag)
{
SEQAN_CHECKPOINT;
create(target, source, tag);
}
template <typename TTargetValue, typename TSource, typename TExpand>
inline void
assign(String<TTargetValue, CStyle> & target,
TSource const & source,
Tag<TExpand> const tag)
{
SEQAN_CHECKPOINT;
create(target, source, tag);
}
template <typename TTargetValue, typename TSource, typename TSize, typename TExpand>
inline void
assign(String<TTargetValue, CStyle> & target,
TSource & source,
TSize /*limit*/,
Tag<TExpand> const tag)
{
SEQAN_CHECKPOINT;
create(target, source, tag);
}
template <typename TTargetValue, typename TSource, typename TSize, typename TExpand>
inline void
assign(String<TTargetValue, CStyle> & target,
TSource const & source,
TSize limit,
Tag<TExpand> const tag)
{
SEQAN_CHECKPOINT;
create(target, source, limit, tag);
}
//this variant is a workaround for the "const array"-bug of VC++
template <typename TTargetValue, typename TSourceValue, typename TExpand>
inline void
assign(String<TTargetValue, CStyle> & target,
TSourceValue const * source,
Tag<TExpand> const tag)
{
SEQAN_CHECKPOINT;
create(target, source, tag);
}
template <typename TTargetValue, typename TSourceValue, typename TSize, typename TExpand>
inline void
assign(String<TTargetValue, CStyle> & target,
TSourceValue const * source,
TSize limit,
Tag<TExpand> const tag)
{
SEQAN_CHECKPOINT;
create(target, source, limit, tag);
}
//If source is non-const String, then there could be the possibility
//to use the source buffer
template <typename TExpand, bool IS_CONTIGUOUS>
struct AssignStringToStringArray_;
template <typename TExpand>
struct AssignStringToStringArray_<TExpand, true>
{
template <typename TValue, typename TSourceSpec>
static inline void
assign_(String<TValue, CStyle> & target,
String<TValue, TSourceSpec> & source)
{
if (capacity(source) > length(source))
{//use source's buffer
SEQAN_CHECKPOINT;
clear(target);
_setBegin(target, begin(source));
_setEnd(target, end(source));
}
else
{
create(target, source, TExpand());
}
}
//special treatment of char:
//_computeSizeForCapacity is specialized for char such that there
//is enough place for the zero termination
template <typename TSourceSpec>
static inline void
assign_(String<char, CStyle> & target,
String<char, TSourceSpec> & source)
{
SEQAN_CHECKPOINT;
clear(target);
typedef String<char, CStyle> TTarget;
typedef typename Iterator<TTarget>::Type TIterator;
_setBegin(target, TIterator(begin(source)));
_setEnd(target, TIterator(end(source)));
}
};
template <typename TExpand>
struct AssignStringToStringArray_<TExpand, false>
{
template <typename TValue, typename TSourceSpec>
static inline void
assign_(String<TValue, CStyle> & target,
String<TValue, TSourceSpec> & source)
{
SEQAN_CHECKPOINT;
create(target, source, TExpand());
}
};
template <typename TValue, typename TSourceSpec, typename TExpand>
inline void
assign(String<TValue, CStyle> & target,
String<TValue, TSourceSpec> & source,
Tag<TExpand> const)
{
typedef String<TValue, TSourceSpec> TSource;
AssignStringToStringArray_<Tag<TExpand> const, IsContiguous<TSource>::VALUE>::assign_(target, source);
}
// --------------------------------------------------------------------------
// Function clear()
// --------------------------------------------------------------------------
template <typename TValue>
inline void
clear(String<TValue, CStyle> & me)
{
if (me.data_size)
{
SEQAN_CHECKPOINT
// arrayDestruct(me, length(me));
deallocate(me, me.data_begin, me.data_size);
me.data_size = 0;
}
me.data_begin = me.data_end = &me.EMPTY_STRING;
}
// --------------------------------------------------------------------------
// Function create()
// --------------------------------------------------------------------------
//see basic_holder
/**
.Function.create:
..signature:create(target, source [, limit] [,resize_tag])
..param.target: Gets a copy of the content of $source$.
...type:Spec.CStyle String
..param.source: Is copied to $target$.
..param.limit: The maximal length of $target$ after the operation. (optional)
..param.resize_tag: Specifies the strategy that is applied if $target$ has not enough capacity to store the complete content. (optional)
...type:Tag.Overflow Strategy
...default:Specified by @Metafunction.DefaultOverflowImplicit@ of the $target$ type.
..remarks.text:It is guaranteed, that after calling this function $source$ and $target$ can be used independently.
..see:Spec.CStyle String
..include:seqan/sequence.h
*/
template <typename TExpand>
struct CreateArrayStringExpand_
{
template <typename TTarget, typename TSource>
static inline void
create_(TTarget & target,
TSource & source)
{
typename Size<TTarget>::Type source_length = length(source);
if (dependent(target) || (capacity(target) < source_length))
{
SEQAN_CHECKPOINT;
typename Size<TTarget>::Type old_target_capacity = capacity(target);
typename Value<TTarget>::Type * buf = _reallocateStorage(target, source_length, TExpand());
if (buf)
{
_deallocateStorage(target, buf, old_target_capacity);
}
}
if (length(source) > 0)
{
assignValue(begin(target, Standard()), 0); //set target length to 0
assign(begin(target, Standard()), source, Insist());
typedef typename Iterator<TTarget>::Type TTargetIterator;
_setEnd(target, TTargetIterator( begin(target) + source_length));
}
}
template <typename TTarget, typename TSource, typename TLimit>
static inline void
create_(TTarget & target,
TSource & source,
TLimit limit)
{
typename Size<TTarget>::Type copy_length = length(source);
if (limit < copy_length)
{
copy_length = limit;
}
if (dependent(target) || (capacity(target) < copy_length))
{
SEQAN_CHECKPOINT;
typename Size<TTarget>::Type old_target_capacity = capacity(target);
TTarget * buf = _reallocateStorage(target, copy_length, TExpand());
if (buf)
{
_deallocateStorage(target, buf, old_target_capacity);
}
}
assign(begin(target, Standard()), source, copy_length, Insist());
_setEnd(target, begin(target, Standard()) + copy_length);
}
};
template <typename TExpand>
struct CreateArrayString_;
template <>
struct CreateArrayString_<Insist>
{
template <typename TTarget, typename TSource>
static inline void
create_(TTarget & target,
TSource & source)
{
SEQAN_CHECKPOINT;
typename Size<TTarget>::Type source_length = length(source);
if (dependent(target))
{
TTarget * buf = _reallocateStorage(target, source_length, Exact());
}
assign(begin(target, Standard()), source, source_length, Insist());
_setEnd(target, begin(target, Standard()) + source_length);
}
template <typename TTarget, typename TSource, typename TSize>
static inline void
create_(TTarget & target,
TSource & source,
TSize limit)
{
SEQAN_CHECKPOINT;
typename Size<TTarget>::Type copy_size = length(source);
if (limit < copy_size)
{
copy_size = limit;
}
if (dependent(target))
{
TTarget * buf = _reallocateStorage(target, copy_size, Exact());
}
assign(begin(target, Standard()), source, copy_size, Insist());
_setEnd(target, begin(target, Standard()) + copy_size);
}
};
template <>
struct CreateArrayString_<Limit>
{
template <typename TTarget, typename TSource>
static inline void
create_(TTarget & target,
TSource & source)
{
SEQAN_CHECKPOINT;
CreateArrayString_<Insist>::create_(target, source, capacity(target));
}
template <typename TTarget, typename TSource, typename TSize>
static inline void
create_(TTarget & target,
TSource & source,
TSize & limit)
{
SEQAN_CHECKPOINT;
typename Size<TTarget>::Type copy_size = capacity(target);
if (copy_size > limit)
{
copy_size = limit;
}
CreateArrayString_<Insist>::create_(target, source, copy_size);
}
};
template <>
struct CreateArrayString_<Exact>:
CreateArrayStringExpand_<Exact>
{
};
template <>
struct CreateArrayString_<Generous>:
CreateArrayStringExpand_<Generous>
{
};
template <typename TTargetValue, typename TSource>
inline void
create(String<TTargetValue, CStyle> & target,
TSource & source)
{
SEQAN_CHECKPOINT;
typedef String<TTargetValue, CStyle> TTarget;
create(target, source, typename DefaultOverflowImplicit<TTarget>::Type());
}
template <typename TTargetValue, typename TSource, typename TSize>
inline void
create(String<TTargetValue, CStyle> & target,
TSource & source,
TSize limit)
{
SEQAN_CHECKPOINT;
typedef String<TTargetValue, CStyle> TTarget;
create(target, source, limit, typename DefaultOverflowImplicit<TTarget>::Type());
}
template <typename TTargetValue, typename TSource, typename TExpand>
inline void
create(String<TTargetValue, CStyle> & target,
TSource & source,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT;
CreateArrayString_<Tag<TExpand> const>::create_(target, source);
}
template <typename TTargetValue, typename TSource, typename TSize, typename TExpand>
inline void
create(String<TTargetValue, CStyle> & target,
TSource & source,
TSize limit,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT;
CreateArrayString_<Tag<TExpand> const>::create_(target, source, limit);
}
template <typename TTargetValue, typename TSource, typename TExpand>
inline void
create(String<TTargetValue, CStyle> & target,
TSource const & source,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT;
CreateArrayString_<Tag<TExpand> const>::create_(target, source);
}
template <typename TTargetValue, typename TSource, typename TSize, typename TExpand>
inline void
create(String<TTargetValue, CStyle> & target,
TSource const & source,
TSize limit,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT;
CreateArrayString_<Tag<TExpand> const>::create_(target, source, limit);
}
//this variant is a workaround for the "const array"-bug of VC++
template <typename TTargetValue, typename TSourceValue, typename TExpand>
inline void
create(String<TTargetValue, CStyle> & target,
TSourceValue const * source,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT;
CreateArrayString_<Tag<TExpand> const>::create_(target, source);
}
template <typename TTargetValue, typename TSourceValue, typename TSize, typename TExpand>
inline void
create(String<TTargetValue, CStyle> & target,
TSourceValue const * source,
TSize limit,
Tag<TExpand> const)
{
SEQAN_CHECKPOINT;
CreateArrayString_<Tag<TExpand> const>::create_(target, source, limit);
}
// --------------------------------------------------------------------------
// Function toCString()
// --------------------------------------------------------------------------
/**
.Function.toCString:
..cat:Containers
..summary:Access sequence as c-style string.
..signature:toCString(object)
..param.object:A string.
...type:Class.String
...type:Adaption.char array
..returns:For strings that store their elements in a contiguous block (see @Metafunction.IsContiguous@)
a pointer to first element of $object$ is returned.
The last element is followed by a default constructed element.
..remarks:If the alphabet of $object$ is $char$ or $wchar_t$ the return value is a c-style string representing the contents of $object$.
Calling this function for non-contiguous containers will raise a compilation error.
To create c-style strings for non-contiguous strings or strings with different alphabets, use a @Spec.CStyle String@ as an intermediate.
..include:seqan/sequence.h
*/
template <typename TValue>
inline TValue *
toCString(TValue * me)
{
SEQAN_CHECKPOINT;
return me;
}
template <typename TValue>
inline TValue const *
toCString(TValue const * me)
{
SEQAN_CHECKPOINT;
return me;
}
template <typename TValue>
inline TValue *
toCString(String<TValue, CStyle> & me)
{
SEQAN_CHECKPOINT;
return me;
}
template <typename TValue>
inline TValue const *
toCString(String<TValue, CStyle> const & me)
{
SEQAN_CHECKPOINT;
return me;
}
template <typename TValue, typename TSpec>
inline TValue *
_toCStringImpl(String<TValue, TSpec> & me, True)
{
SEQAN_CHECKPOINT;
typename Size< String<TValue, TSpec> >::Type len = length(me);
if (len >= capacity(me))
reserve(me, len + 1);
if (end(me) != NULL)
*end(me) = TValue();
return begin(me);
}
// You called toCString with non-contiguous strings.
// Convert to String<..., CStyle> and try again!
template <typename TValue, typename TSpec>
inline TValue *
_toCStringImpl(String<TValue, TSpec> & me, False);
template <typename TValue, typename TSpec>
inline TValue *
toCString(String<TValue, TSpec> & me)
{
SEQAN_CHECKPOINT;
return _toCStringImpl(me, typename IsContiguous<String<TValue, TSpec> >::Type());
}
template <typename TValue, typename TSpec>
inline TValue *
toCString(String<TValue, TSpec> const & me)
{
SEQAN_CHECKPOINT;
return toCString(const_cast<String<TValue, TSpec> &>(me));
}
} // namespace seqan
#endif //#ifndef SEQAN_HEADER_...
|