-
Notifications
You must be signed in to change notification settings - Fork 6
/
ConfigBase.hpp
183 lines (161 loc) · 5.45 KB
/
ConfigBase.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* *********************************************************************
* This Original Work is copyright of 51 Degrees Mobile Experts Limited.
* Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
* Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
*
* This Original Work is licensed under the European Union Public Licence
* (EUPL) v.1.2 and is subject to its terms as set out below.
*
* If a copy of the EUPL was not distributed with this file, You can obtain
* one at https://opensource.org/licenses/EUPL-1.2.
*
* The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
* amended by the European Commission) shall be deemed incompatible for
* the purposes of the Work and the provisions of the compatibility
* clause in Article 5 of the EUPL shall not apply.
*
* If using the Work as, or as part of, a network application, by
* including the attribution notice(s) required under Article 5 of the EUPL
* in the end user terms of the application under an appropriate heading,
* such notice(s) shall fulfill the requirements of that article.
* ********************************************************************* */
#ifndef FIFTYONE_DEGREES_CONFIG_BASE_HPP
#define FIFTYONE_DEGREES_CONFIG_BASE_HPP
#include <vector>
#include <string>
#include "Exceptions.hpp"
#include "config.h"
using std::vector;
namespace FiftyoneDegrees {
namespace Common {
/**
* C++ class wrapper for the #fiftyoneDegreesConfigBase configuration
* structure. See config.h.
*
* Configuration options are set using setter methods and fetched using
* corresponding getter methods. The names are self explanatory.
*
* ## Usage Example
*
* ```
* using namespace FiftyoneDegrees::Common;
* RequiredPropertiesConfig *properties;
*
* // Construct a new configuration
* ConfigBase *config = new ConfigBase();
*
* // Configure the engine to create a temporary data file, or reuse
* // an existing temporary file if one exists
* config->setUseTempFile(true);
* config->setReuseTempFile(true);
*
* // Use the configuration when constructing an engine
* EngineBase *engine = new EngineBase(config, properties);
* ```
*/
class ConfigBase {
public:
/**
* @name Constructors and Destructors
* @{
*/
/**
* Constructs a new instance of the configuration with a reference
* to the C configuration provided.
* @param config pointer to the underlying configuration structure
*/
ConfigBase(fiftyoneDegreesConfigBase *config);
/**
* Free any memory associated with temporary directories.
*/
virtual ~ConfigBase();
/**
* @}
* @name Setters
* @{
*/
/**
* Set whether or not the HTTP header field might be prefixed with
* 'HTTP_'.
* @param use whether or not prefixed upper headers should be used
*/
void setUseUpperPrefixHeaders(bool use);
/**
* Set whether or not a temporary file should be created from the
* original data file and used to initialise the data set.
* @param use should create a temp file
*/
void setUseTempFile(bool use);
/**
* Set whether or not a temporary file that already exists for a
* master file should be reused by another process.
* @param reuse should create a temp files be reused
*/
void setReuseTempFile(bool reuse);
/**
* Sets a collection of temporary directories to use if temporary
* file operation is required in the order in which the directories
* should be used. If no temporary directories are provided and
* temporary files should be used the temporary files will be
* placed in the same directory as the master file.
* @param tempDirs collection of temporary directories.
*/
void setTempDirectories(vector<string> tempDirs);
/**
* @}
* @name Getters
* @{
*/
/**
* Get whether or not an HTTP_ upper case prefixes should be
* considered when evaluating HTTP headers.
* @return true if upper case HTTP_ prefixed header keys should be
* considered.
*/
bool getUseUpperPrefixHeaders() const;
/**
* Get whether or not a temporary file should be created from the
* original data file and used to initialise the data set.
* @return true if temporary files should be used, otherwise false.
*/
bool getUseTempFile() const;
/**
* Get whether temporary files can be reused across multiple
* processes.
* @return true if temporary files can be reused, otherwise false.
*/
bool getReuseTempFile() const;
/**
* Gets a vector of temporary directory strings which should be
* used to store temporary files.
* @return a vector of temporary directories, or NULL if no
* temporary directories are to be used.
*/
vector<string> getTempDirectories() const;
/**
* Get the expected number of concurrent accessors of the data set.
* @return concurrency
*/
virtual uint16_t getConcurrency() const;
/**
* @}
*/
private:
/** Pointer to the underlying C configuration structure. */
fiftyoneDegreesConfigBase *config;
/** Paths to directories which should be used when attempting to
create temp files. */
vector<string> tempDirs;
/**
* Frees any memory associated with temporary directories.
*/
void freeTempDirectories();
/**
* Maps the strings in the temporary directories vector to string
* pointers in the config data structure.
*/
void mapTempDirectories();
};
}
}
#endif