RZ

01: // ExtractRemoteCon.cc # rz offsets table for analysis and synthesis
02:
03: #include <vector>
04: #include <algorithm>
05:
06: #include "RZError.hh"
07: #include "RZMagic.hh"
08: #include "RZIO.hh"
09: #include "RZNetOrder.hh"
10: #include "ExtractRemoteCon.hh"
11:
12: /****** simple header extracted from wrapper ******/
13:         
14: RZ::RemoteWrapper::RemoteWrapper(RZStreamStructure const & ss)
15: :
16:     n_blks(ss.n_blks),
17:     rz_end(ss.rz_end),
18:     rz_off(ss.rz_off),
19:
20:     wrapper_size(64 + 16 * n_blks),
21:     file_size(wrapper_size + rz_end)
22: {}
23:
24: void RZ::RemoteWrapper::extract_header(RZStreamStructure const & ss)
25: {
26:     n_blks = ss.n_blks;
27:     rz_end = ss.rz_end;
28:     rz_off = ss.rz_off;
29:
30:     wrapper_size = 64 + 16 * n_blks;
31:     file_size = wrapper_size + rz_end;
32: }
33:
34: /****** rz offsets extracted from wrapper ******/
35:         
36: void RZ::ConTable::extract_rz_tab(
37:     RZSignatureTable::Signature const & sigtab)
38: {
39:     rz_tab.push_back(0);
40:     rz_at_begin = 0;
41:     if (rz_off) { rz_tab.push_back(rz_off); --rz_at_begin; }
42:
43:     if (sigtab.size() != n_blks) throw AssertionError("Wrong size");
44:     std::transform(sigtab.begin(), sigtab.end(),
45:         std::back_inserter(rz_tab), RZSignatureTable::EntryTo());
46:     rz_at_end = n_blks;
47:     if (rz_end - rz_tab.back()) { rz_tab.push_back(rz_end); ++rz_at_end; }
48:
49:     rz_to = rz_tab.begin();
50:     if (rz_off) ++rz_to;
51:     rz_at = rz_to++;
52: }
53:
54: /****** rz offsets extracted from file ******/
55:         
56: void RZ::ConTable::extract_rz_tab(std::FILE * const RZWRAPPER)
57: {
58:     rz_tab.push_back(0);
59:     rz_at_begin = 0;
60:     if (rz_off) { rz_tab.push_back(rz_off); --rz_at_begin; }
61:     for (unsigned int i = 0; i < n_blks; ++i) {
62:         char buffer[ 16 ];
63:         {
64:             int n = std::fread(buffer, 1, 16, RZWRAPPER);
65:             ScanError::what_if("Can't read rz signature table!", n != 16);
66:         }
67:         rz_tab.push_back(net_in(buffer + 12));
68:     }
69:     rz_at_end = n_blks;
70:     if (rz_end - rz_tab.back()) { rz_tab.push_back(rz_end); ++rz_at_end; }
71:
72:     rz_to = rz_tab.begin();
73:     if (rz_off) ++rz_to;
74:     rz_at = rz_to++;
75: }
76:
77: // ExtractRemoteCon.cc # rz offsets table for analysis and synthesis