Debian Codegraph @

tests/testspb.cc

raw symbols SCIP
1 #ifdef HAVE_CONFIG_H
2 #include <gsm_config.h>
3 #endif
4 #include <gsmlib/gsm_sorted_phonebook.h>
5 #include <algorithm>
6 #include <iostream>
7
8 void printPb(gsmlib::PhonebookEntry &e)
9 {
10 std::cout << "number: " << e.telephone()
11 << " text: " << e.text() << std::endl;
12 }
13
14 int main(int argc, char *argv[])
15 {
16 try
17 {
18 // open phonebook file
19 gsmlib::SortedPhonebook pb(std::string("spb-copy.pb"), false);
20
21 // print all entries
22 std::cout << "Entries in pbs-copy.pb:" << std::endl;
23 for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
24 std::cout << " Text: " << i->text()
25 << " Telephone: " << i->telephone() << std::endl;
26
27 // remove all entries with telephone == "0815"
28 std::cout << "Removing entries with telephone == 0815" << std::endl;
29 pb.setSortOrder(gsmlib::ByTelephone);
30
31 std::string s = "0815";
32 pb.erase(s);
33
34 std::cout << "Entries in pbs-copy.pb<2>:" << std::endl;
35 for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
36 std::cout << " Text: " << i->text()
37 << " Telephone: " << i->telephone() << std::endl;
38
39 // insert some entries
40 std::cout << "Inserting some entries" << std::endl;
41 pb.insert(gsmlib::PhonebookEntryBase("08152", "new line with \r continued"));
42 pb.insert(gsmlib::PhonebookEntryBase("41598254", "Hans-Dieter Schmidt"));
43 pb.insert(gsmlib::PhonebookEntryBase("34058", "Hans-Dieter|Hofmann"));
44
45 pb.setSortOrder(gsmlib::ByText);
46 std::cout << "Entries in pbs-copy.pb<3>:" << std::endl;
47 for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
48 std::cout << " Text: " << i->text()
49 << " Telephone: " << i->telephone() << std::endl;
50
51 // test erasing all "Hans-Dieter Schmidt" entries
52 std::cout << "Erasing all Hans-Dieter Schmidt entries" << std::endl;
53 s = "Hans-Dieter Schmidt";
54 std::pair<gsmlib::SortedPhonebook::iterator, gsmlib::SortedPhonebook::iterator> range =
55 pb.equal_range(s);
56 std::cout << "About to erase:" << std::endl;
57 for (gsmlib::SortedPhonebook::iterator i = range.first; i != range.second; ++i)
58 std::cout << " Text: " << i->text()
59 << " Telephone: " << i->telephone() << std::endl;
60
61 pb.erase(range.first, range.second);
62
63 // write back to file
64 std::cout << "Writing back to file" << std::endl;
65 pb.sync();
66
67 // tests the NoCopy class
68 //SortedPhonebook pb2("spb.pb");
69 //pb2 = pb;
70 }
71 catch (gsmlib::GsmException &ge)
72 {
73 std::cerr << "GsmException '" << ge.what() << "'" << std::endl;
74 return 1;
75 }
76 return 0;
77 }