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; }
192 char delimiter=
' ');
200 enum MatchType :
uint8
213 template <
typename Value,
typename Step,
typename End>
214 static inline bool inclusiveComp(
bool i,
220 return i ? (v <=
end) : (v < end);
222 return i ? (v >=
end) : (v > end);
231 { array.
append(myString); }
233 {
if (myHasInteger) array.
append(myInteger); }
235 {
if (myHasFloat) array.
append(myFloat); }
244 if (!start.myHasInteger || !end.myHasInteger)
247 for (
exint i = start.myInteger;
249 inclusive, i, 1, end.myInteger);
253 buffer.
format(
"{}{}", start.myPrefix, i);
262 if (!start.myHasFloat || !end.myHasFloat)
264 for (
fpreal i = start.myFloat;
266 inclusive, i, 1.0, end.myFloat);
277 if (!start.myHasInteger || !end.myHasInteger)
279 for (
exint i = start.myInteger;
281 inclusive, i, 1, end.myInteger);
297 if (!start.myHasInteger ||
301 if (step.myInteger == 0)
304 for (
exint i = start.myInteger;
307 step.myInteger, end.myInteger);
311 buffer.
format(
"{}{}", start.myPrefix, i);
321 if (!start.myHasFloat ||
328 for (
fpreal i = start.myFloat;
331 step.myFloat, end.myFloat);
343 if (!start.myHasInteger ||
350 for (
fpreal i = start.myInteger;
353 step.myFloat, end.myInteger);
364 {
return myString ==
value; }
366 {
return myHasFloat && SYSalmostEqual(value, myFloat); }
368 {
return myHasInteger && (myInteger ==
value); }
377 if (!myHasInteger)
return true;
378 else if (inclusive)
return value < myInteger;
379 else return value <= myInteger;
383 if (!myHasFloat)
return true;
384 else if (inclusive)
return value < myFloat;
385 else return value <= myFloat;
392 bool greater(
exint value,
bool inclusive)
const
394 if (!myHasInteger)
return true;
395 else if (inclusive)
return value > myInteger;
396 else return value >= myInteger;
398 bool greater(
fpreal value,
bool inclusive)
const
400 if (!myHasFloat)
return true;
401 else if (inclusive)
return value > myFloat;
402 else return value >= myFloat;
410 bool step(
const Value& start,
exint value)
const
412 if (!start.myHasInteger || !myHasFloat)
415 fpreal delta = value - start.myInteger;
416 return SYSalmostEqual(SYSfmod(delta, myFloat), 0);
420 if (!start.myHasFloat || !myHasFloat)
423 fpreal delta = value - start.myFloat;
424 return SYSalmostEqual(SYSfmod(delta, myFloat), 0);
433 bool myHasInteger : 1;
434 bool myHasPrefix : 1;
444 if (match(value,
nullptr, inclusive))
451 if (!SYSisdigit(data[len]))
455 exint suffix = atoi(data+len+1);
463 return match(suffix, &prefix, inclusive);
469 return match(suffix,
nullptr, inclusive);
472 bool matchFull(
const exint& value,
bool inclusive)
const
473 {
return match(value,
nullptr, inclusive); }
474 bool matchFull(
const fpreal& value,
bool inclusive)
const
475 {
return match(value,
nullptr, inclusive); }
478 template <
typename T>
479 bool match(
const T& value,
481 bool inclusive)
const
485 if (!myMatchValues[0].myHasPrefix && prefix)
489 if (myMatchType == eMatchTypeConstant)
491 if (!myMatchValues[0].match(value))
497 if (myMatchValues[0].
less(value,
true))
500 if (myMatchValues[1].greater(value, inclusive))
506 if (myMatchValues[0].myHasPrefix)
510 else if (*prefix != myMatchValues[0].myPrefix.c_str())
515 if (myMatchType <= eMatchTypeRange)
517 return myMatchValues[2].step(myMatchValues[0], value);
521 template <
typename T>
522 void append(
T& array,
bool inclusive)
const
524 if (myMatchType == eMatchTypeConstant)
525 myMatchValues[0].append(array);
526 else if (myMatchType == eMatchTypeRange)
548 if (index > myMatchType)
549 return default_value;
552 if (value.myHasFloat)
553 return value.myFloat;
554 if (value.myHasInteger)
555 return (
fpreal)(value.myInteger);
564 fpreal start = floatValue(0, 0);
565 fpreal end = floatValue(1, start);
566 fpreal step = floatValue(2, 1);
569 last = last*step +
start;
570 if (!inclusive && SYSalmostEqual(end, last))
580 Value myMatchValues[3];
583 MatchType myMatchType;
608 myIsExclusion =
false;
610 for (
int i = 0; i < 3; i++)
615 exint myRangeValues[3];
626 template <
typename T>
627 bool match(
const T& value,
629 const ValueMatch** value_match)
const
635 for (
auto&& match : myMatches)
637 if (!match.match(value,
nullptr, inclusive))
643 *value_match = &match;
647 if (!match.myIsExclusion)
650 *value_match = &match;
660 bool match(
exint value,
663 const ValueMatch** value_match)
const
669 for (
auto&& match : myMatches)
671 if (!match.match(value, &prefix, inclusive))
677 *value_match = &match;
681 if (!match.myIsExclusion)
684 *value_match = &match;
694 template <
typename T>
697 bool inclusive)
const
699 const ValueMatch* value_match =
nullptr;
700 if (!match(value, inclusive, &value_match))
705 value_match->setRange(range, inclusive);
710 template <
typename T>
711 void append(
T& array,
713 bool inclusive)
const
719 for (
auto&& match : myMatches)
721 if (!match.myIsExclusion)
723 match.append(array, inclusive);
727 for (
auto&& entry : array)
729 if (match.matchFull(entry, inclusive))
731 swap_array.append(entry);
742 template <
typename T>
743 void appendMap(
T& map,
745 bool inclusive)
const
750 typename T::mapped_type swap_array;
752 for (
auto&& match : myMatches)
754 auto&& array = map[i++];
756 if (!match.myIsExclusion)
758 match.append(array, inclusive);
762 for (
auto&& array : map)
764 for (
auto&& entry : array.second)
766 if (match.matchFull(entry, inclusive))
768 swap_array.append(entry);
778 for (
auto&& array : map)
785 bool addPattern(ParseState& parse_state);
802 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
void reset(const UT_StringHolder &pattern)
Resets the pattern.
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
__hostdev__ uint64_t last(uint32_t i) 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.