Debian Codegraph @

tests/hugePackRead_row.cc

raw
1 #include <iostream>
2 #include <fstream>
3 #include <cstdlib>
4
5 #include "test_utils.hh"
6
7 #include "geners/MultiFileArchive.hh"
8 #include "geners/RowPacker.hh"
9
10 using namespace gs;
11 using namespace std;
12
13 #ifdef CPP11_STD_AVAILABLE
14
15 static const char* filename;
16 static const char* objname;
17
18 void usage_and_exit(const char* prog)
19 {
20 cerr << "\nUsage: " << parse_progname(prog)
21 << " filename\n" << endl;
22 exit(1);
23 }
24
25 void read_big_tuple()
26 {
27 MultiFileArchive ar(filename, "r", "Huge pack test");
28 if (!ar.isReadable())
29 {
30 std::cerr << "Failed to open archive \"" << ar.name()
31 << "\" for reading" << std::endl;
32 return;
33 }
34
35 double d;
36 long double ld;
37 long li;
38 unsigned long uli;
39 long long lli;
40 unsigned long long ulli;
41 auto t = std::tie(d, ld, li, uli, lli, ulli);
42
43 typedef RowPacker<decltype(t)> Packer;
44 RPReference<Packer> ref(ar, objname, "my category");
45 assert(ref.unique());
46
47 std::unique_ptr<Packer> nt = ref.get(0);
48
49 const unsigned long nrows = nt->nRows();
50 for (unsigned long i=0; i<nrows; ++i)
51 {
52 nt->rowContents(i, &t);
53 unsigned long j = std::tuple_size<decltype(t)>::value*nrows;
54
55 if (d != j++) cout << "Problem with d, row " << i << endl;
56 if (ld != j++) cout << "Problem with ld, row " << i << endl;
57 if ((unsigned long)li != j++) cout << "Problem with li, row " << i << endl;
58 if (uli != j++) cout << "Problem with uli, row " << i << endl;
59 if ((unsigned long long)lli != j++) cout << "Problem with lli, row " << i << endl;
60 if (ulli != j++) cout << "Problem with ulli, row " << i << endl;
61 }
62 cout << "Read " << nrows << " rows" << endl;
63 }
64
65 int main(int argc, char const* argv[])
66 {
67 if (argc != 3)
68 usage_and_exit(argv[0]);
69
70 filename = argv[1];
71 objname = argv[2];
72
73 const double t = time_of_run(read_big_tuple, 1);
74 std::cout << "Program took " << t/1000000 << " sec" << std::endl;
75
76 return 0;
77 }
78
79 #else // CPP11_STD_AVAILABLE
80
81 int main(int argc, char const* argv[])
82 {
83 cout << "Please recompile with C++11 features enabled" << endl;
84 return 0;
85 }
86
87 #endif // CPP11_STD_AVAILABLE