Debian Codegraph @

data/0.12-dev/impl/FileArray.t.cpp

raw
1 #include "FileArray.h"
2 #include <string>
3 #include <iostream>
4 using namespace std;
5 using namespace AiksaurusImpl;
6
7 int main()
8 {
9 cout << "Enter file name: " << flush;
10 string fname; cin >> fname;
11
12 cout << "Enter struct size: " << flush;
13 long ssize; cin >> ssize;
14
15 bool success;
16 FileArray f(fname.c_str(), ssize, success);
17
18 if (!success)
19 {
20 cout << "Error opening file for reading." << endl;
21 return 0;
22 }
23
24 cout << "File is " << f.getBytes() << " bytes long." << endl;
25 cout << "So file contains " << f.getBytes() / f.getStructSize()
26 << " structures." << endl;
27
28 unsigned char *buf = new unsigned char[f.getStructSize()];
29
30 while(1)
31 {
32 cout << "Request structure: " << flush;
33 long i; cin >> i;
34
35 if (!f.at(i, buf))
36 {
37 cout << "Error reading element " << dec << i << endl;
38 }
39
40 else
41 {
42 cout << "Element read successfully. Contents: " << endl;
43
44 for(long i = 0;i < f.getStructSize();++i)
45 {
46 cout << hex << buf[i] << " ";
47 }
48
49 cout << endl;
50 }
51 }
52
53 delete buf;
54
55 return 0;
56 }