annotate packages/language/cxx/ustl/current/src/memlink.cpp @ 2904:88af52c64ce4

* ecos.db: Add uSTL library package record. * language/cxx/ustl/*: Initial check-in of the port of uSTL 1.3 to eCos contributed by Uwe Kindler.
author jld
date Thu, 20 Aug 2009 17:00:30 +0000
parents
children 4885e0722884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
1 // This file is part of the uSTL library, an STL implementation.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
2 //
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
3 // Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
4 // This file is free software, distributed under the MIT License.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
5
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
6 #include "mistream.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
7 #include "ustdxept.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
8
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
9 namespace ustl {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
10
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
11 /// Reads the object from stream \p s
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
12 void memlink::read (istream& is)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
13 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
14 written_size_type n = 0;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
15 is >> n;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
16 if (!is.verify_remaining ("read", "ustl::memlink", n))
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
17 return;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
18 if (n > size())
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
19 USTL_THROW(length_error ("memlink can not increase the size of the linked storage for reading"));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
20 resize (n);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
21 is.read (data(), n);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
22 is.align (alignof (n));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
23 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
24
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
25 /// Copies data from \p p, \p n to the linked block starting at \p start.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
26 void memlink::copy (iterator start, const void* p, size_type n)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
27 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
28 assert (data() || !n);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
29 assert (p || !n);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
30 assert (start >= begin() && start + n <= end());
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
31 if (p)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
32 copy_n (const_iterator(p), n, start);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
33 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
34
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
35 /// Fills the linked block with the given pattern.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
36 /// \arg start Offset at which to start filling the linked block
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
37 /// \arg p Pointer to the pattern.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
38 /// \arg elSize Size of the pattern.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
39 /// \arg elCount Number of times to write the pattern.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
40 /// Total number of bytes written is \p elSize * \p elCount.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
41 ///
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
42 void memlink::fill (iterator start, const void* p, size_type elSize, size_type elCount)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
43 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
44 assert (data() || !elCount || !elSize);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
45 assert (start >= begin() && start + elSize * elCount <= end());
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
46 if (elSize == 1)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
47 fill_n (start, elCount, *reinterpret_cast<const uint8_t*>(p));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
48 else while (elCount--)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
49 start = copy_n (const_iterator(p), elSize, start);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
50 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
51
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
52 } // namespace ustl