9 #ifndef __PDG_VALUE_PATTERN_H__
10 #define __PDG_VALUE_PATTERN_H__
54 if (match(value, inclusive,
nullptr))
61 if (!SYSisdigit(data[len]))
65 int suffix = atoi(data+len+1);
68 suffix, prefix, inclusive,
nullptr);
73 {
return match(value, inclusive,
nullptr); }
77 {
return match(value, inclusive,
nullptr); }
85 {
return matchRange(range, value, inclusive); }
92 {
return matchRange(range, value, inclusive); }
99 {
return append(values, sorted, inclusive); }
104 bool inclusive)
const
105 {
return append(values, sorted, inclusive); }
110 bool inclusive)
const
111 {
return append(values, sorted, inclusive); }
118 bool inclusive)
const
121 values, sorted, inclusive);
128 bool inclusive)
const
131 values, sorted, inclusive);
138 bool inclusive)
const
141 values, sorted, inclusive);
148 bool inclusive)
const
152 if (myMatches[index].myIsExclusion)
155 myMatches[
index].setRange(
167 return myMatches[
index].floatValue(2, 1);
173 {
return myIsNumeric; }
177 {
return myHasVariableStep; }
181 {
return myMinimumStep; }
189 enum MatchType :
uint8
202 template <
typename Value,
typename Step,
typename End>
203 static inline bool inclusiveComp(
bool i,
209 return i ? (v <=
end) : (v < end);
211 return i ? (v >=
end) : (v > end);
220 { array.
append(myString); }
222 {
if (myHasInteger) array.
append(myInteger); }
224 {
if (myHasFloat) array.
append(myFloat); }
233 if (!start.myHasInteger || !end.myHasInteger)
236 for (
exint i = start.myInteger;
238 inclusive, i, 1, end.myInteger);
242 buffer.
format(
"{}{}", start.myPrefix, i);
251 if (!start.myHasFloat || !end.myHasFloat)
253 for (
fpreal i = start.myFloat;
255 inclusive, i, 1.0, end.myFloat);
266 if (!start.myHasInteger || !end.myHasInteger)
268 for (
exint i = start.myInteger;
270 inclusive, i, 1, end.myInteger);
286 if (!start.myHasInteger ||
290 if (step.myInteger == 0)
293 for (
exint i = start.myInteger;
296 step.myInteger, end.myInteger);
300 buffer.
format(
"{}{}", start.myPrefix, i);
310 if (!start.myHasFloat ||
317 for (
fpreal i = start.myFloat;
320 step.myFloat, end.myFloat);
332 if (!start.myHasInteger ||
339 for (
fpreal i = start.myInteger;
342 step.myFloat, end.myInteger);
353 {
return myString ==
value; }
355 {
return myHasFloat && SYSalmostEqual(value, myFloat); }
357 {
return myHasInteger && (myInteger ==
value); }
366 if (!myHasInteger)
return true;
367 else if (inclusive)
return value < myInteger;
368 else return value <= myInteger;
372 if (!myHasFloat)
return true;
373 else if (inclusive)
return value < myFloat;
374 else return value <= myFloat;
381 bool greater(
exint value,
bool inclusive)
const
383 if (!myHasInteger)
return true;
384 else if (inclusive)
return value > myInteger;
385 else return value >= myInteger;
387 bool greater(
fpreal value,
bool inclusive)
const
389 if (!myHasFloat)
return true;
390 else if (inclusive)
return value > myFloat;
391 else return value >= myFloat;
399 bool step(
const Value& start,
exint value)
const
401 if (!start.myHasInteger || !myHasFloat)
404 fpreal delta = value - start.myInteger;
405 return SYSalmostEqual(SYSfmod(delta, myFloat), 0);
409 if (!start.myHasFloat || !myHasFloat)
412 fpreal delta = value - start.myFloat;
413 return SYSalmostEqual(SYSfmod(delta, myFloat), 0);
422 bool myHasInteger : 1;
423 bool myHasPrefix : 1;
433 if (match(value,
nullptr, inclusive))
440 if (!SYSisdigit(data[len]))
444 exint suffix = atoi(data+len+1);
452 return match(suffix, &prefix, inclusive);
458 return match(suffix,
nullptr, inclusive);
461 bool matchFull(
const exint& value,
bool inclusive)
const
462 {
return match(value,
nullptr, inclusive); }
463 bool matchFull(
const fpreal& value,
bool inclusive)
const
464 {
return match(value,
nullptr, inclusive); }
467 template <
typename T>
468 bool match(
const T& value,
470 bool inclusive)
const
474 if (!myMatchValues[0].myHasPrefix && prefix)
478 if (myMatchType == eMatchTypeConstant)
480 if (!myMatchValues[0].match(value))
486 if (myMatchValues[0].
less(value,
true))
489 if (myMatchValues[1].greater(value, inclusive))
495 if (myMatchValues[0].myHasPrefix)
499 else if (*prefix != myMatchValues[0].myPrefix.c_str())
504 if (myMatchType <= eMatchTypeRange)
506 return myMatchValues[2].step(myMatchValues[0], value);
510 template <
typename T>
511 void append(
T& array,
bool inclusive)
const
513 if (myMatchType == eMatchTypeConstant)
514 myMatchValues[0].append(array);
515 else if (myMatchType == eMatchTypeRange)
537 if (index > myMatchType)
538 return default_value;
541 if (value.myHasFloat)
542 return value.myFloat;
543 if (value.myHasInteger)
544 return (
fpreal)(value.myInteger);
553 fpreal start = floatValue(0, 0);
554 fpreal end = floatValue(1, start);
555 fpreal step = floatValue(2, 1);
558 last = last*step +
start;
559 if (!inclusive && SYSalmostEqual(end, last))
569 Value myMatchValues[3];
572 MatchType myMatchType;
597 myIsExclusion =
false;
599 for (
int i = 0; i < 3; i++)
604 exint myRangeValues[3];
615 template <
typename T>
616 bool match(
const T& value,
618 const ValueMatch** value_match)
const
624 for (
auto&& match : myMatches)
626 if (!match.match(value,
nullptr, inclusive))
632 *value_match = &match;
636 if (!match.myIsExclusion)
639 *value_match = &match;
649 bool match(
exint value,
652 const ValueMatch** value_match)
const
658 for (
auto&& match : myMatches)
660 if (!match.match(value, &prefix, inclusive))
666 *value_match = &match;
670 if (!match.myIsExclusion)
673 *value_match = &match;
683 template <
typename T>
686 bool inclusive)
const
688 const ValueMatch* value_match =
nullptr;
689 if (!match(value, inclusive, &value_match))
694 value_match->setRange(range, inclusive);
699 template <
typename T>
700 void append(
T& array,
702 bool inclusive)
const
708 for (
auto&& match : myMatches)
710 if (!match.myIsExclusion)
712 match.append(array, inclusive);
716 for (
auto&& entry : array)
718 if (match.matchFull(entry, inclusive))
720 swap_array.append(entry);
731 template <
typename T>
732 void appendMap(
T& map,
734 bool inclusive)
const
739 typename T::mapped_type swap_array;
741 for (
auto&& match : myMatches)
743 auto&& array = map[i++];
745 if (!match.myIsExclusion)
747 match.append(array, inclusive);
751 for (
auto&& array : map)
753 for (
auto&& entry : array.second)
755 if (match.matchFull(entry, inclusive))
757 swap_array.append(entry);
767 for (
auto&& array : map)
774 bool addPattern(ParseState& parse_state);
791 bool myHasVariableStep;
void arrayMap(IntMap &values, bool sorted, bool inclusive) const
void array(UT_StringArray &values, bool sorted, bool inclusive) const
Returns the array of string values that match the pattern.
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
GLsizei const GLfloat * value
bool containsRange(UT_FprealArray &range, exint value, bool inclusive) const
SYS_FORCE_INLINE const char * buffer() const
bool contains(exint value, bool inclusive) const
Checks if the specified integer value is in the pattern.
A utility class to do read-only operations on a subset of an existing string.
A generic, discriminated value, whose type may be queried dynamically.
bool contains(fpreal value, bool inclusive) const
Checks if the specified float value is in the pattern.
SYS_FORCE_INLINE const char * c_str() const
void arrayMap(FloatMap &values, bool sorted, bool inclusive) const
void array(UT_FprealArray &values, bool sorted, bool inclusive) const
Returns the array of float values that match the pattern.
SYS_API fpreal32 SYSfloor(fpreal32 val)
bool componentRange(UT_FprealArray &range, exint index, bool inclusive) const
Returns the value range for the specified component number.
fpreal minimumStep() const
Returns the minimum step size from all components in the pattern.
void array(UT_ExintArray &values, bool sorted, bool inclusive) const
Returns the array of integer values that match the pattern.
bool SYSequalZero(const UT_Vector3T< T > &v)
bool containsRange(UT_FprealArray &range, fpreal value, bool inclusive) const
size_t format(const char *fmt, const Args &...args)
GLenum GLsizei GLsizei GLint * values
bool contains(const UT_StringHolder &value, bool inclusive) const
Checks if the specified string value is in the pattern.
fpreal componentStep(exint index) const
Returns the step value for the specified component number.
void arrayMap(StringMap &values, bool sorted, bool inclusive) const
void clear()
Resets list to an empty list.
bool hasVariableStep() const
Returns true if the pattern has segments with different step sizes.