1 | #ifndef FILE_H |
---|
2 | #define FILE_H |
---|
3 | |
---|
4 | #include <stdint.h> |
---|
5 | #include <iostream> |
---|
6 | #include "slot.h" |
---|
7 | |
---|
8 | using namespace std; |
---|
9 | |
---|
10 | namespace hierarchy_memory |
---|
11 | { |
---|
12 | namespace sort_file |
---|
13 | { |
---|
14 | template <class T> |
---|
15 | class File |
---|
16 | { |
---|
17 | protected : char * name; |
---|
18 | protected : uint32_t nb_slot; // number of slot |
---|
19 | protected : uint32_t size; // size of file |
---|
20 | protected : slot_t<T> * slot; |
---|
21 | |
---|
22 | public : File (char * name, |
---|
23 | uint32_t size) |
---|
24 | { |
---|
25 | uint32_t size_name = strlen(name)+1; |
---|
26 | this->name = new char [size_name]; |
---|
27 | strncpy(this->name,name,size_name); |
---|
28 | |
---|
29 | nb_slot = 0; |
---|
30 | this->size = size; |
---|
31 | slot = new slot_t<T> [size]; |
---|
32 | }; |
---|
33 | |
---|
34 | public : virtual ~File () |
---|
35 | { |
---|
36 | }; |
---|
37 | |
---|
38 | // *****[ empty ]***** |
---|
39 | // Test if the file is empty |
---|
40 | public : bool empty () |
---|
41 | { |
---|
42 | return (nb_slot == 0); |
---|
43 | } |
---|
44 | |
---|
45 | // *****[ full ]***** |
---|
46 | // Test if the file is full |
---|
47 | public : bool full () |
---|
48 | { |
---|
49 | return (nb_slot == size); |
---|
50 | } |
---|
51 | |
---|
52 | // *****[ nb_slot_free ]***** |
---|
53 | // return the number of free slot |
---|
54 | public : uint32_t nb_slot_free () |
---|
55 | { |
---|
56 | return (size-nb_slot); |
---|
57 | } |
---|
58 | |
---|
59 | // *****[ nb_slot_use ]***** |
---|
60 | // return the number of use slot |
---|
61 | public : uint32_t nb_slot_use () |
---|
62 | { |
---|
63 | return (nb_slot); |
---|
64 | } |
---|
65 | |
---|
66 | // *****[ pop ]***** |
---|
67 | // read the file, and update the pointer |
---|
68 | public : virtual T pop () {return T();}; |
---|
69 | |
---|
70 | // *****[ pop ]***** |
---|
71 | // read the file, and update the pointer |
---|
72 | public : virtual T pop (uint32_t num) {return T();}; |
---|
73 | |
---|
74 | // *****[ push ]***** |
---|
75 | // Push a new value (they must have a slot free) |
---|
76 | public : virtual bool push (T val) {return false;}; |
---|
77 | |
---|
78 | }; // File |
---|
79 | |
---|
80 | }; //sort_file |
---|
81 | }; //hierarchy_memory |
---|
82 | #endif //!FILE_H |
---|
83 | |
---|