| 1 |
#ifndef _DataStore_h_ |
| 2 |
#define _DataStore_h_ |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "Data.h" |
| 22 |
#include "Collection.h" |
| 23 |
#include "Simple.h" |
| 24 |
|
| 25 |
Thing_define (StoredData, Daata) { |
| 26 |
autoDaata data; |
| 27 |
autoSimpleString description; |
| 28 |
}; |
| 29 |
|
| 30 |
|
| 31 |
autoStoredData StoredData_create (Daata data, conststring32 description); |
| 32 |
|
| 33 |
Collection_define (StoredDataList, OrderedOf, StoredData) { |
| 34 |
}; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
class autoDataStore { |
| 45 |
|
| 46 |
autoStoredDataList storedData; |
| 47 |
integer current; |
| 48 |
|
| 49 |
public: |
| 50 |
|
| 51 |
autoDataStore () { |
| 52 |
storedData = StoredDataList_create (); |
| 53 |
current = 0; |
| 54 |
} |
| 55 |
|
| 56 |
void forth () { |
| 57 |
if (current <= storedData -> size) |
| 58 |
current ++; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
void back () { |
| 66 |
if (current > 0) |
| 67 |
current --; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
StoredData getData () { |
| 75 |
Melder_assert (current > 0 && current <= storedData -> size); |
| 76 |
return storedData -> at [current]; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
void insertData_move (Daata data, conststring32 description) { |
| 83 |
for (integer i = storedData -> size; i >= current + 1; i --) |
| 84 |
storedData -> removeItem (i); |
| 85 |
autoStoredData thee = StoredData_create (data, description); |
| 86 |
storedData -> addItem_move (thee.move()); |
| 87 |
current = storedData -> size; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
bool isEmpty () { |
| 96 |
return storedData -> size == 0; |
| 97 |
} |
| 98 |
|
| 99 |
bool isOffleft () { |
| 100 |
return current == 0; |
| 101 |
} |
| 102 |
|
| 103 |
bool isOffright (){ |
| 104 |
return storedData -> size == 0 || current == storedData -> size + 1; |
| 105 |
} |
| 106 |
|
| 107 |
autostring32 getDataDescription (integer offsetFromCurrent) { |
| 108 |
const integer pos = current + offsetFromCurrent; |
| 109 |
autostring32 result; |
| 110 |
if (pos >= 1 && pos <= storedData -> size) { |
| 111 |
StoredData data = storedData -> at [pos]; |
| 112 |
SimpleString ss = data -> description.get(); |
| 113 |
result = Melder_dup (ss ->string.get()); |
| 114 |
} |
| 115 |
return result; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
}; |
| 122 |
|
| 123 |
#endif |