Compiles under gcc 4.3.2
[ustl.git] / memlink.cc
blob79e9b5856aba9b9fec2d1184c3ef41c1da49d20f
1 // This file is part of the ustl library, an STL implementation.
2 //
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 // memlink.cc
7 //
8 // A pointer to a sized block of memory.
9 //
11 #include "mistream.h"
12 #include "ustdxept.h"
14 namespace ustl {
16 /// Reads the object from stream \p s
17 void memlink::read (istream& is)
19 written_size_type n;
20 is >> n;
21 is.verify_remaining ("read", "ustl::memlink", n);
22 if (n > size())
23 throw length_error ("memlink can not increase the size of the linked storage for reading");
24 resize (n);
25 is.read (data(), n);
26 is.align (alignof (n));
29 /// Copies data from \p p, \p n to the linked block starting at \p start.
30 void memlink::copy (iterator start, const void* p, size_type n)
32 assert (data() || !n);
33 assert (p || !n);
34 assert (start >= begin() && start + n <= end());
35 if (p)
36 copy_n (const_iterator(p), n, start);
39 /// Fills the linked block with the given pattern.
40 /// \arg start Offset at which to start filling the linked block
41 /// \arg p Pointer to the pattern.
42 /// \arg elSize Size of the pattern.
43 /// \arg elCount Number of times to write the pattern.
44 /// Total number of bytes written is \p elSize * \p elCount.
45 ///
46 void memlink::fill (iterator start, const void* p, size_type elSize, size_type elCount)
48 assert (data() || !elCount || !elSize);
49 assert (start >= begin() && start + elSize * elCount <= end());
50 if (elSize == 1)
51 fill_n (start, elCount, *reinterpret_cast<const uint8_t*>(p));
52 else while (elCount--)
53 start = copy_n (const_iterator(p), elSize, start);
56 } // namespace ustl