~ubuntu-branches/ubuntu/gutsy/c++-annotations/gutsy

« back to all changes in this revision

Viewing changes to yo/templateapp/examples/storage.cc

  • Committer: Bazaar Package Importer
  • Author(s): Frank B. Brokken
  • Date: 2007-06-15 19:31:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070615193112-i48grmnykrf1ipqf
Tags: 7.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <iostream>
 
2
#include <string>
 
3
#include <vector>
 
4
#include <list>
 
5
#include <queue>
 
6
#include <algorithm>
 
7
#include <iterator>
 
8
 
 
9
#include "placementalloc.h"
 
10
#include "plainalloc.h"
 
11
#include "newalloc.h"
 
12
 
 
13
#include "storage.h"
 
14
 
 
15
using namespace std;
 
16
 
 
17
int main(int argc, char **argv)
 
18
{
 
19
    switch (argv[1][0])
 
20
    {
 
21
        default:
 
22
            cout << "Provide argument to read from stdin:\n"
 
23
                "n: read strings, using NewAlloc with a vector\n"
 
24
                "p: read strings, using PlacementAlloc with a deque\n"
 
25
                "s: read ints, using a simple PlainAlloc with a list\n";
 
26
        break;
 
27
 
 
28
        case 'n':
 
29
        {
 
30
            Storage<string, NewAlloc> storage;
 
31
 
 
32
            copy(istream_iterator<string>(cin), istream_iterator<string>(),
 
33
                    back_inserter(storage));
 
34
 
 
35
            cout << "Element index 1 is " << storage[1] << endl;
 
36
            storage[1] = "hello";
 
37
 
 
38
            copy(storage.begin(), storage.end(),
 
39
                 ostream_iterator<NewAlloc<string> >(cout, "\n"));
 
40
        }
 
41
        break;
 
42
 
 
43
         case 'p':
 
44
         {
 
45
            Storage<string, PlacementAlloc, deque> storage;
 
46
 
 
47
            copy(istream_iterator<string>(cin), istream_iterator<string>(),
 
48
                    back_inserter(storage));
 
49
 
 
50
            copy(storage.begin(), storage.end(),
 
51
                 ostream_iterator<PlacementAlloc<string> >(cout, "\n"));
 
52
        }
 
53
        break;
 
54
 
 
55
        case 's':
 
56
        {
 
57
             Storage<int, PlainAlloc, list> storage;
 
58
 
 
59
             copy(istream_iterator<int>(cin), istream_iterator<int>(),
 
60
                     back_inserter(storage));
 
61
 
 
62
             copy(storage.begin(), storage.end(),
 
63
                  ostream_iterator<PlainAlloc<int> >(cout, "\n"));
 
64
        }
 
65
        break;
 
66
    }
 
67
    return 0;
 
68
}