forked from ngageoint/csm
-
Notifications
You must be signed in to change notification settings - Fork 13
/
ModelIdentifier.h
530 lines (471 loc) · 18.8 KB
/
ModelIdentifier.h
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
//#############################################################################
//
// FILENAME: ModelIdentifier.h
//
// CLASSIFICATION: Unclassified
//
// DESCRIPTION:
//
// This files defines various structs and classes to allow identification
// of a specific Model within a "bundle" of related Models.
//
// LIMITATIONS: None
//
//
// SOFTWARE HISTORY:
//>
// Date Author Comment
// ----------- ------ -------
// 20-Feb-2017 JPK Initial creation
// 01-Mar-2017 JPK Moved implementaitons to ModelIdentifier.cpp
// Fixed includes, namespace usage.
//<
//#############################################################################
#ifndef __CSM_MODEL_IDENTIFIER_H
#define __CSM_MODEL_IDENTIFIER_H
#include "csm.h"
#include <string>
#include <vector>
#include <map>
#include <ostream>
namespace csm
{
namespace MIC // Namespace for Model Identifier Components
{
//*****************************************************************************
// Data is a class for holding values of various types for a single
// component of a Model Identifier
//*****************************************************************************
class CSM_EXPORT_API Data
{
public:
enum Type
{
STRING_TYPE,
INT_TYPE,
DOUBLE_TYPE
};
//> This enumeration indicated the data type for
// the Model Identifier
//<
Data() : theType(INT_TYPE),theInt(0) {}
//> The default constructor is declared private so that it cannot be
// invoked.
//<
Data(int argValue) : theType(INT_TYPE), theInt(argValue) {}
//> This constructor creates an MIData object from an integer
//<
Data(double argValue) : theType(DOUBLE_TYPE),theDbl(argValue){}
//> This contructor creates an MIData object from a double
//<
Data(const std::string& argValue);
//> This constructor creates an MIData object from a string
//<
Data(const Data& argData);
//> This is the copy constructor
//<
~Data();
//> This is the destructor.
//<
std::string strValue() const;
//> This method returns the current Data's value as a string
//<
int intValue() const;
//> This method returns the current Data's value as an integer
//<
double dblValue() const;
//> This method returns the current Data's value as a double
//<
const Type& type() const {return theType;}
//> This method returns the enumerated Type for the current Data
//<
void setValue(const std::string& value,bool clearPrevious = true);
//> This method sets the value to the argument string.
// and sets the Type to STRING_TYPE. If clearPrevious is set to
// true, any previous value is removed.
//<
void setValue(int value,bool clearPrevious = true);
//> This method sets the value to the argument int.
// and sets the Type to INTEGER_TYPE If clearPrevious is set to
// true, any previous value is removed.
//<
void setValue(double value,bool clearPrevious = true);
//> This method sets the value to the argument double.
// and sets the Type to DOUBLE_TYPE If clearPrevious is set to
// true, any previous value is removed.
//<
bool operator<(const Data& argData) const;
//> This method returns "true" if the argument data is less than
// the current data, "false" otherwise. Note that a STRING_TYPE
// is always less than an INT_TYPE or a DOUBLE_TYPE. For any
// other comparisons, operator< on the actual types is returned.
//<
bool operator==(const Data& argData) const;
//> This method returns "true" if argData is equal to the
// current Data. Note that a STRING_TYPE is never
// equivalent to and INT_TYPE, but INT_TYPES and DOUBLE_TYPES
// can be equivalent if the values they hold are.
//<
Data& operator=(const Data&);
//> This is the assignment operator
//<
private:
void clear();
Type theType;
//> This data member is the enumerated Type
//<
union
{
struct{size_t theLen; char* theStr;};
int theInt;
double theDbl;
};
};
//*****************************************************************************
// RangeList
//> This class represents the set of possible ranges for the value
// associated with a single "component" of a Model Identifier.
//<
//*****************************************************************************
class CSM_EXPORT_API RangeList
{
public:
//************************************************************************
// Class Range
//> This class represents a single range of possible values for a Data
//<
//************************************************************************
class CSM_EXPORT_API Range
{
public:
Range();
//> This is the default constructor.
//<
Range(const std::string& single);
//> This constructor creates a range equal to a single "string"
// value.
//<
Range(int minValue,
int maxValue,
int stepValue = 1);
//> This constructor creates a range from specified minimum value
// to specified maximum value, given a specified step.
//<
Range(double minValue,
double maxValue,
double stepValue = 0.0,
bool includesMin = true,
bool includesMax = true);
//> This constructor creates a range from specified minimum value
// to specified maximum value, given a specified step.
//<
~Range() {};
//> This is the destructor
//<
const Data::Type& type() const {return theMinimum.type();}
//> This method returns the type associated with the data elements
// for this Range.
//<
const Data& minimum() const {return theMinimum;}
//> This method returns the minimum value for the current range.
//<
const Data& maximum() const {return theMaximum;}
//> This method returns the maximum value for the current range.
//<
const Data& step() const {return theStep;}
//> This method returns the step size for the current range.
// If the step is empty or 0 / 0.0, it is ignored.
//<
bool minInclusive() const {return theMinInclusive;}
//> This data member indicates if the minimum value is included
// in the range.
//<
bool maxInclusive() const {return theMaxInclusive;}
//> This data member indicates if the maximum value is included
// in the range.
//<
bool contains(const Data& argValue) const;
//> This method determines if the specified data is in the current
// range.
//<
bool contains(const std::string& argValue) const;
//> This method determines if the specified string is in the current
// range, which will only be true if the current data type is
// of type STRING_TYPE
//<
bool contains(int argValue) const;
//> This method determines if the specified integer is in the current
// range, which will only be true if the current data type is
// of type INT_TYPE
//<
bool contains(double argValue) const;
//> This method determines if the specified integer is in the current
// range, which will only be true if the current data type is
// of type DOUBLE_TYPE
//<
bool operator<(const Range& argRange) const;
//> This method returns "true" if the argument Range is less than
// the current Range, "false" otherwise. Note that a STRING_TYPE
// Range is always less than an INT_TYPE or a DOUBLE_TYPE. For any
// other comparisons, operator< on the actual types is returned.
//<
bool operator==(const Range& argRange) const;
//> This method returns "true" if argRange is equal to the
// current Range. Note that a STRING_TYPE is never
// equivalent to and INT_TYPE, but INT_TYPES and DOUBLE_TYPES
// can be equivalent if the values they hold are.
//<
private:
void adjustToStep();
//> This method adjusts the range to agree with the step size if a
// valid step size is specified.
//<
Data theMinimum;
//> This data member represents the minimum value assoicated with the
// current range.
//<
Data theMaximum;
//> This data member represents the maximum value assoicated with the
// current range.
//<
Data theStep;
//> This data member represents the step size assoicated with the
// current range.
//<
bool theMinInclusive;
//> This data member indicates of the current minimum value is
// included in the range.
//<
bool theMaxInclusive;
//> This data member indicates of the current maximum value is
// included in the range.
//<
};
RangeList() : theRanges() {}
//> This is the default constructor
//<
RangeList(const std::string& single);
//> This constructor creates a RangeList with a single "string"
// value.
//<
RangeList(int minValue,
int maxValue,
int stepValue = 1);
//> This constructor creates a RangeList with a single "integer"
// range from specified minimum value
// to specified maximum value, given a specified step.
//<
RangeList(double minValue,
double maxValue,
double stepValue = 0.0,
bool includesMin = true,
bool includesMax = true);
//> This constructor creates a RangeList from a single "double"
// range from specified minimum value
// to specified maximum value, given a specified step.
//<
RangeList(const Range& argRange);
//> This constructor creates an MICRangeList single range.
//<
RangeList(const std::vector<std::string>& argValues);
//> This constructor creates an MICRangeList from the given list
// of possible "string" values.
//<
RangeList(const std::vector<int>& argValues);
//> This constructor creates an MICRangeList from the given list
// of possible "integer" values. The values are sorted and then
// assigned to ranges based on the distance between the adjacent
// values.
//<
RangeList(const std::vector<double>& argValues);
//> This constructor creates an MICRangeList from the given list
// of possible "double" values. The values are sorted and then
// assigned to ranges based on the distance between the adjacent
// values.
//<
size_t size() const {return theRanges.size();}
//> This method returns the number of ranges.
//<
const Range& range(size_t index) const;
//> This method returns the specified range. If the passed in
// "index" is outside of the valid range, a csm::Error is thrown.
//<
const Data::Type& type(size_t index) const;
//> This method returns the Type of the specified Range.
// Note that it is possible for different types of
// Ranges to be present for the same Data object.
// For example, a "Band ID" could be expressed as an
// integer index, a wavelength (non-integer number), or
// a name (Red,Green,Blue, etc).
//<
~RangeList() {}
//> This is the destuctor
//<
void addRange(const Range& argRange) {theRanges.push_back(argRange);}
//> This method allows a range to be added to the current RangeList.
//<
bool contains(const Data& argValue) const;
//> This method determined if any of the ranges in the list contain the
// specified value.
//<
private:
std::vector<Range> theRanges;
//> this data member represents the set of Ranges own by the current
// MICRangeList.
//<
};
std::ostream& operator<<(std::ostream& os,const Data& argData);
std::ostream& operator<<(std::ostream& os,const RangeList::Range& range);
std::ostream& operator<<(std::ostream& os,const RangeList& rangeList);
} // namespace MIC
typedef std::map<std::string,MIC::Data> MIComponentMap;
typedef MIComponentMap::value_type MIComponent;
typedef std::map<std::string,MIC::RangeList> MIComponentDescMap;
typedef MIComponentDescMap::value_type MIComponentDesc;
//*****************************************************************************
// ModelIdentifier
//> This class holds a set of "Components" which are intented to uniquely
// identify a specific Model within a "bundle" of models.
//<
//*****************************************************************************
class CSM_EXPORT_API ModelIdentifier
{
public:
ModelIdentifier();
//> This is the default constructor
//<
ModelIdentifier(const std::string& argName,
const std::string& argValue);
//> This constructor creates a ModelIdentifier from the specified
// component name and string value.
//<
ModelIdentifier(const std::string& argName,
int argValue);
//> This constructor creates a ModelIdentifier from the specified
// component name and integer value.
//<
ModelIdentifier(const std::string& argName,
double argValue);
//> This constructor creates a ModelIdentifier from the specified
// component name and double value.
//<
ModelIdentifier(const std::string& argName,
const MIC::Data& argValue);
//> This constructor creates a ModelIdentifier from the specified
// component name and MIC::Data value.
//<
ModelIdentifier(const MIComponent& argComponent);
//> This constructor creates a ModelIdentifier given a single
// MIComponent.
//<
ModelIdentifier(const std::vector<MIComponent>& argComponents);
//> This constructor creates a ModelIdentifier from the supplied vector
// of MIComponents.
//<
~ModelIdentifier() {}
//> This is the destructor.
//<
bool addComponent(const std::string& argName,
const std::string& argValue);
//> This method adds a new string component with name argName
// and value argValue to the current ModelIdentifier.
//<
bool addComponent(const std::string& argName,
int argValue);
//> This method adds a new integer component with name argName
// and value argValue to the current ModelIdentifier.
//<
bool addComponent(const std::string& argName,
double argValue);
//> This method adds a new double component with name argName
// and value argValue to the current ModelIdentifier.
//<
bool addComponent(const MIComponent& argComponent);
//> This method allows a particular MIComponent to be added the this
// ModelIdentifier. If the argument Component's name is equivalent
// to the name of a Component already owned by this ModelIdentifier,
// "false" is returned. Otherwise, the argument Component is added
// to this ModelIdentifier, and "true" is returned.
//<
size_t size() const {return theComponents.size();}
//> This method returns the current number of components
//<
std::vector<std::string> componentNames() const;
//> This method returns the names for each Component.
//<
const MIC::Data& dataFor(const std::string& name) const;
//> This method returns the Data associated with a specific
// Component.
//<
const MIComponentMap& components() const {return theComponents;}
//> This method returns the current set of Components
//<
private:
MIComponentMap theComponents;
//> This data member stores the current set of Components.
//<
};
//*****************************************************************************
// MIDescription
//> This class holds a set of "Component Descriptions" which define the valid
// ranges for the "Components" of a ModelIdentifier.
//<
//*****************************************************************************
class CSM_EXPORT_API MIDescription
{
public:
MIDescription();
//> This is the default constructor
//<
MIDescription(const std::string& argName,
const MIC::RangeList& argDesc);
//> This constructor creates an MIDescription given a single Component
// wth name argName and MIC::RangeList argDesc.
//<
MIDescription(const MIComponentDesc& argDesc);
//> This constructor creates an MIDescription given a single Component
// description.
//<
MIDescription(const std::vector<MIComponentDesc>& argDescs);
//> This constructor creates an MIDescription from the supplied
// vector of component descriptions
//<
~MIDescription() {}
//> This is the destructor
//<
bool addDescription(const std::string& argName,
const MIC::RangeList& argDesc);
//> This method allows a RangeList for the value named by argName
// to be added to the current MIDescription.
//<
bool addDescription(const MIComponentDesc& argDesc);
//> This method allows a particular MIComponentDesc to be added the this
// MIDescription. If the argument ComponentDesc's name is equivalent
// to the name of a Component already owned by this ModelIdentifier,
// "false" is returned. Otherwise, the argument ComponentDesc is added
// to this MIDescription, and "true" is returned.
//<
size_t size() const {return theDescriptions.size();}
//> This method returns the number of descriptions
//<
std::vector<std::string> componentNames() const;
//> This method returns the names for each ComponentDesc.
//<
const MIC::RangeList& rangesFor(const std::string& name) const;
//> This method returns the RangeList for each Component name..
//<
const MIComponentDescMap& descriptions() const {return theDescriptions;}
//> This method returns the current set of ComponentDescs.
//<
bool inRange(const ModelIdentifier& id) const;
//> This method returns "true" if the specified ModelIdentifier's
// components are each found in the current set of descritions and
// each Components's value is contained in its associated range.
//<
private:
MIComponentDescMap theDescriptions;
//> This data member stores the current set of ComponentDescs.
//<
};
} // namespace csm
#endif