-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStorageEntry.hpp
136 lines (123 loc) · 4.96 KB
/
StorageEntry.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* =============================================================================
* Vader Modular Fuzzer (VMF)
* Copyright (c) 2021-2024 The Charles Stark Draper Laboratory, Inc.
* <vmf@draper.com>
*
* Effort sponsored by the U.S. Government under Other Transaction number
* W9124P-19-9-0001 between AMTC and the Government. The U.S. Government
* Is authorized to reproduce and distribute reprints for Governmental purposes
* notwithstanding any copyright notation thereon.
*
* The views and conclusions contained herein are those of the authors and
* should not be interpreted as necessarily representing the official policies
* or endorsements, either expressed or implied, of the U.S. Government.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 (only) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @license GPL-2.0-only <https://spdx.org/licenses/GPL-2.0-only.html>
* ===========================================================================*/
#pragma once
#include "StorageRegistry.hpp"
#include "StorageEntryListener.hpp"
#include "RuntimeException.hpp"
#include <vector>
namespace vmf
{
/**
* @brief The class that stores information about each test case
*
* The actual fields that are stored are configurable via the StorageRegistry object.
*
*/
class StorageEntry
{
public:
StorageEntry(bool isMetadata, bool isLocal, StorageEntryListener* listener);
/**
* @brief Not defined. StorageEntry should never be copied.
* All allocations/access for this object should be via the Storage Module.
*
* Be careful when accessing metadata to access it as a reference:
* StorageEntry& metadata = storage->getMetadata();
* Attempts to write the following code will result in a compiler
* error because the copy constructor would be used instead:
* StorageEntry metdata = storage->getMetadata();
*/
StorageEntry (const StorageEntry&) = delete;
~StorageEntry();
static void init(StorageRegistry& registry);
static void initMetadata(StorageRegistry& metadata);
unsigned long getID() const;
bool isLocalEntry() const;
bool operator == ( const StorageEntry& e );
bool sortByValueIsLessThan( const StorageEntry& e );
void setValue(int key, int value);
void setValue(int key, unsigned int value);
void setValue(int key, float value);
int incrementIntValue(int key);
unsigned int incrementUIntValue(int key);
int getIntValue(int key) const;
unsigned int getUIntValue(int key) const;
float getFloatValue(int key) const;
char* allocateBuffer(int key, int size);
char* allocateAndCopyBuffer(int key, int size, char* srcBuffer);
char* allocateAndCopyBuffer(int key, StorageEntry* srcEntry);
void clearBuffer(int key);
bool hasBuffer(int key) const;
int getBufferSize(int key) const;
char* getBufferPointer(int key) const;
void addTag(int tagId);
void removeTag(int tagId);
bool hasTag(int tagId);
std::vector<int> getTagList();
private:
static int getHandleIndex(int handle, int expectedType, bool isMetadata, int entryMax, int metaMax);
static int getBufferHandleIndex(int handle, int isMetadata, bool& isTmpBuffer);
//Note: This is not a multi-threaded implementation
static unsigned long uidCounter;
static int pKey;
static StorageRegistry::storageTypes pKeyType;
static int maxInts;
static int maxUInts;
static int maxFloats;
static int maxBuffers;
static int maxTempBuffers;
static int maxTags;
//default values
static std::vector<int> intDefaults;
static std::vector<unsigned int> uintDefaults;
static std::vector<float> floatDefaults;
static std::vector<int> intMetadataDefaults;
static std::vector<unsigned int> uintMetadataDefaults;
static std::vector<float> floatMetadataDefaults;
//metadata specific parameters
static int maxIntsMetadata;
static int maxUIntsMetadata;
static int maxFloatsMetadata;
static int maxBuffersMetadata;
static int maxTempBuffersMetadata;
unsigned long uid;
bool isMetadataEntry;
bool isLocal;
std::vector<int> intValues;
std::vector<unsigned int> uintValues;
std::vector<float> floatValues;
std::vector<char*> bufferValues;
std::vector<int> bufferSizes;///Size will equal UNALLOCATED_BUFFER if the buffer is not yet allocated
std::vector<char*> tmpBufferValues;
std::vector<int> tmpBufferSizes;
const int UNALLOCATED_BUFFER = -1;
std::vector<bool> tagValues;
StorageEntryListener* listener;
};
}