-
Notifications
You must be signed in to change notification settings - Fork 3
/
stltest2.cxx
56 lines (50 loc) · 1.69 KB
/
stltest2.cxx
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
//-< STLTEST.CXX >---------------------------------------------------*--------*
// POST++ Version 1.0 (c) 1998 GARRET * ? *
// (Persistent Object Storage) * /\| *
// * / \ *
// Created: 31-May-99 K.A. Knizhnik * / [] \ *
// Last update: 30-Jan-2004 K.A. Knizhnik * GARRET *
//-------------------------------------------------------------------*--------*
// Example of using STL classes with POST++
// This example explicitly specify allocator for STL types
//-------------------------------------------------------------------*--------*
#include "post_stl.h"
#include "iostream"
#include "vector"
#include "string"
using namespace std;
USE_POST_NAMESPACE
typedef basic_string<char, char_traits<char>, post_alloc<char> > post_string;
typedef vector<post_string, post_alloc<post_string> > text;
int main()
{
storage sto("teststl.odb");
if (sto.open(storage::fixed)) {
text* root = (text*)sto.get_root_object();
if (root != NULL) {
for (text::iterator i = root->begin();
i != root->end(); i++)
{
cout << *i << '\n';
}
} else {
root = new (sto) text;
sto.set_root_object((object*)root);
}
cout << "\nAdd some lines. Terminate input with empty line.\n";
while (true) {
char buf[256];
cin.getline(buf, sizeof buf);
if (*buf == '\0') {
cout << "End of session\n";
sto.flush();
sto.close();
return EXIT_SUCCESS;
}
root->push_back(*new (sto) post_string(buf));
}
} else {
cerr << "Failed to open storage\n";
return EXIT_FAILURE;
}
}