OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [tests/] [bvt06.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#include "stdtest.h"
7
 
8
void PrintBlock (const cmemlink& l)
9
{
10
    const int* numbers = reinterpret_cast<const int*>(l.begin());
11
    const size_t nNumbers = l.size() / sizeof(int);
12
    for (size_t i = 0; i < nNumbers; ++ i)
13
        cout << numbers[i] << ' ';
14
    cout << endl;
15
}
16
 
17
void TestObjectVector (void)
18
{
19
    vector<memblock> v;
20
    const size_t nNumbers = 1000;
21
    int numbers [nNumbers];
22
    const size_t nLinks = 10;
23
    cmemlink links [nLinks];
24
    for (size_t i = 0; i < nNumbers; ++ i)
25
        numbers[i] = i;
26
    uoff_t offset = 0;
27
    for (size_t l = 0; l < nLinks; ++ l) {
28
        links[l].link (numbers + offset, l * sizeof(int));
29
        offset += l;
30
        v.push_back (memblock(links[l]));
31
    }
32
    cout.format ("---\nvector<memblock> of %zu elements:\n---\n", v.size());
33
    for_each (v.begin(), v.end(), &PrintBlock);
34
    cout.format ("---\nsize() = %zu, max_size() = ", v.size());
35
    if (v.max_size() == SIZE_MAX / sizeof(memblock))
36
        cout << "SIZE_MAX/elsize";
37
    else
38
        cout << v.max_size();
39
    static const char tf[2][6]={"false","true"};
40
    cout.format (", empty() = %s\n", tf[v.empty()]);
41
    v.push_back (memblock(5));
42
    cout.format ("back()->size() = %zu\n", v.back().size());
43
    v.back().resize (40);
44
    cout.format ("back()->size() = %zu\n", v.back().size());
45
    v.pop_back();
46
    PrintBlock (v.back());
47
    vector<memblock> cache;
48
    cache.assign (v.begin(), v.end());
49
    v.clear();
50
    v.assign (cache.begin(), cache.end());
51
    v.erase (v.begin() + 5, 2);
52
    v.erase (v.end() - 1, 1);
53
    v.erase (v.end(), streamsize(0));
54
    cout.format ("---\nvector of %zu elements backwards:\n---\n", v.size());
55
    for_each (v.rbegin(), v.rend(), &PrintBlock);
56
    cout << "---\n";
57
}
58
 
59
StdBvtMain (TestObjectVector)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.