This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
testspb.cc
77 lines (65 loc) · 2.53 KB
/
testspb.cc
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifdef HAVE_CONFIG_H
#include <gsm_config.h>
#endif
#include <gsmlib/gsm_sorted_phonebook.h>
#include <algorithm>
#include <iostream>
void printPb(gsmlib::PhonebookEntry &e)
{
std::cout << "number: " << e.telephone()
<< " text: " << e.text() << std::endl;
}
int main(int argc, char *argv[])
{
try
{
// open phonebook file
gsmlib::SortedPhonebook pb(std::string("spb-copy.pb"), false);
// print all entries
std::cout << "Entries in pbs-copy.pb:" << std::endl;
for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
std::cout << " Text: " << i->text()
<< " Telephone: " << i->telephone() << std::endl;
// remove all entries with telephone == "0815"
std::cout << "Removing entries with telephone == 0815" << std::endl;
pb.setSortOrder(gsmlib::ByTelephone);
std::string s = "0815";
pb.erase(s);
std::cout << "Entries in pbs-copy.pb<2>:" << std::endl;
for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
std::cout << " Text: " << i->text()
<< " Telephone: " << i->telephone() << std::endl;
// insert some entries
std::cout << "Inserting some entries" << std::endl;
pb.insert(gsmlib::PhonebookEntryBase("08152", "new line with \r continued"));
pb.insert(gsmlib::PhonebookEntryBase("41598254", "Hans-Dieter Schmidt"));
pb.insert(gsmlib::PhonebookEntryBase("34058", "Hans-Dieter|Hofmann"));
pb.setSortOrder(gsmlib::ByText);
std::cout << "Entries in pbs-copy.pb<3>:" << std::endl;
for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
std::cout << " Text: " << i->text()
<< " Telephone: " << i->telephone() << std::endl;
// test erasing all "Hans-Dieter Schmidt" entries
std::cout << "Erasing all Hans-Dieter Schmidt entries" << std::endl;
s = "Hans-Dieter Schmidt";
std::pair<gsmlib::SortedPhonebook::iterator, gsmlib::SortedPhonebook::iterator> range =
pb.equal_range(s);
std::cout << "About to erase:" << std::endl;
for (gsmlib::SortedPhonebook::iterator i = range.first; i != range.second; ++i)
std::cout << " Text: " << i->text()
<< " Telephone: " << i->telephone() << std::endl;
pb.erase(range.first, range.second);
// write back to file
std::cout << "Writing back to file" << std::endl;
pb.sync();
// tests the NoCopy class
//SortedPhonebook pb2("spb.pb");
//pb2 = pb;
}
catch (gsmlib::GsmException &ge)
{
std::cerr << "GsmException '" << ge.what() << "'" << std::endl;
return 1;
}
return 0;
}