9 #ifndef __PDG_VALUE_PATTERN_H__
10 #define __PDG_VALUE_PATTERN_H__
55 if (match(value, inclusive,
nullptr))
60 bool has_digit =
false;
63 if (!SYSisdigit(data[len]))
72 int suffix = atoi(data+len+1);
75 suffix, prefix, inclusive,
nullptr);
80 {
return match(value, inclusive,
nullptr); }
84 {
return match(value, inclusive,
nullptr); }
95 range, value, inclusive);
103 bool inclusive)
const
106 range, value, inclusive);
114 bool inclusive)
const
117 values, sorted, inclusive);
124 bool inclusive)
const
127 values, sorted, inclusive);
134 bool inclusive)
const
137 values, sorted, inclusive);
146 bool inclusive)
const
149 values, sorted, inclusive);
157 bool inclusive)
const
160 values, sorted, inclusive);
168 bool inclusive)
const
171 values, sorted, inclusive);
179 bool inclusive)
const
182 index >= myMatches.size())
187 if (myMatches[index].myIsExclusion)
190 myMatches[
index].setRange(
200 index >= myMatches.size())
205 return myMatches[
index].floatValue(
212 {
return myIsNumeric; }
216 {
return myHasVariableStep; }
220 {
return myMinimumStep; }
231 char delimiter=
' ');
239 enum MatchType :
uint8
252 template <
typename Value,
typename Step,
typename End>
253 static inline bool inclusiveComp(
260 return i ? (v <=
end) : (v < end);
262 return i ? (v >=
end) : (v > end);
271 { array.
append(myString); }
273 {
if (myHasInteger) array.
append(myInteger); }
275 {
if (myHasFloat) array.
append(myFloat); }
285 if (!start.myHasInteger || !end.myHasInteger)
288 for (
exint i = start.myInteger;
290 inclusive, i, 1, end.myInteger);
294 buffer.
format(
"{}{}", start.myPrefix, i);
305 if (!start.myHasFloat || !end.myHasFloat)
307 for (
fpreal i = start.myFloat;
309 inclusive, i, 1.0, end.myFloat);
322 if (!start.myHasInteger || !end.myHasInteger)
324 for (
exint i = start.myInteger;
326 inclusive, i, 1, end.myInteger);
343 if (!start.myHasInteger ||
347 if (step.myInteger == 0)
350 for (
exint i = start.myInteger;
353 step.myInteger, end.myInteger);
357 buffer.
format(
"{}{}", start.myPrefix, i);
369 if (!start.myHasFloat ||
376 for (
fpreal i = start.myFloat;
379 step.myFloat, end.myFloat);
393 if (!start.myHasInteger ||
400 for (
fpreal i = start.myInteger;
403 step.myFloat, end.myInteger);
414 {
return myString ==
value; }
417 return myHasFloat && SYSalmostEqual(
421 {
return myHasInteger && (myInteger ==
value); }
430 if (!myHasInteger)
return true;
431 else if (inclusive)
return value < myInteger;
432 else return value <= myInteger;
436 if (!myHasFloat)
return true;
437 else if (inclusive)
return value < myFloat;
438 else return value <= myFloat;
445 bool inclusive)
const
447 bool greater(
exint value,
bool inclusive)
const
449 if (!myHasInteger)
return true;
450 else if (inclusive)
return value > myInteger;
451 else return value >= myInteger;
453 bool greater(
fpreal value,
bool inclusive)
const
455 if (!myHasFloat)
return true;
456 else if (inclusive)
return value > myFloat;
457 else return value >= myFloat;
467 bool step(
const Value& start,
exint value)
const
469 if (!start.myHasInteger || !myHasFloat)
472 fpreal delta = value - start.myInteger;
473 return SYSalmostEqual(
474 SYSfmod(delta, myFloat), 0);
478 if (!start.myHasFloat || !myHasFloat)
481 fpreal delta = value - start.myFloat;
482 return SYSalmostEqual(
483 SYSfmod(delta, myFloat), 0);
493 bool myHasInteger : 1;
494 bool myHasPrefix : 1;
504 bool inclusive)
const
506 if (match(value,
nullptr, inclusive))
511 bool has_digits =
false;
514 if (!SYSisdigit(data[len]))
523 exint suffix = atoi(data+len+1);
530 return match(suffix, &prefix, inclusive);
536 return match(suffix,
nullptr, inclusive);
539 bool matchFull(
const exint& value,
bool inclusive)
const
540 {
return match(value,
nullptr, inclusive); }
541 bool matchFull(
const fpreal& value,
bool inclusive)
const
542 {
return match(value,
nullptr, inclusive); }
545 template <
typename T>
549 bool inclusive)
const
553 if (!myMatchValues[0].myHasPrefix && prefix)
557 if (myMatchType == eMatchTypeConstant)
559 if (!myMatchValues[0].match(value))
565 if (myMatchValues[0].
less(value,
true))
568 if (myMatchValues[1].greater(value, inclusive))
574 if (myMatchValues[0].myHasPrefix)
579 myMatchValues[0].myPrefix.c_str())
586 if (myMatchType <= eMatchTypeRange)
588 return myMatchValues[2].step(
589 myMatchValues[0], value);
593 template <
typename T>
594 void append(
T& array,
bool inclusive)
const
596 if (myMatchType == eMatchTypeConstant)
597 myMatchValues[0].append(array);
598 else if (myMatchType == eMatchTypeRange)
620 if (index > myMatchType)
621 return default_value;
624 if (value.myHasFloat)
625 return value.myFloat;
626 if (value.myHasInteger)
627 return (
fpreal)(value.myInteger);
636 fpreal start = floatValue(0, 0);
637 fpreal end = floatValue(1, start);
638 fpreal step = floatValue(2, 1);
641 last = last*step +
start;
642 if (!inclusive && SYSalmostEqual(end, last))
652 Value myMatchValues[3];
655 MatchType myMatchType;
683 myIsExclusion =
false;
685 for (
int i = 0; i < 3; i++)
690 exint myRangeValues[3];
701 template <
typename T>
705 const ValueMatch** value_match)
const
711 for (
auto&& match : myMatches)
713 if (!match.match(value,
nullptr, inclusive))
719 *value_match = &match;
723 if (!match.myIsExclusion)
726 *value_match = &match;
740 const ValueMatch** value_match)
const
746 for (
auto&& match : myMatches)
748 if (!match.match(value, &prefix, inclusive))
754 *value_match = &match;
758 if (!match.myIsExclusion)
761 *value_match = &match;
771 template <
typename T>
775 bool inclusive)
const
777 const ValueMatch* value_match =
nullptr;
778 if (!match(value, inclusive, &value_match))
783 value_match->setRange(range, inclusive);
787 template <
typename T>
791 bool inclusive)
const
797 for (
auto&& match : myMatches)
799 if (!match.myIsExclusion)
801 match.append(array, inclusive);
805 for (
auto&& entry : array)
807 if (match.matchFull(entry, inclusive))
809 swap_array.append(entry);
820 template <
typename T>
824 bool inclusive)
const
829 typename T::mapped_type swap_array;
831 for (
auto&& match : myMatches)
833 auto&& array = map[i++];
835 if (!match.myIsExclusion)
837 match.append(array, inclusive);
841 for (
auto&& array : map)
843 for (
auto&& entry : array.second)
851 swap_array.append(entry);
861 for (
auto&& array : map)
868 bool addPattern(ParseState& parse_state);
872 ValueMatchArray myMatches;
885 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_API fpreal32 SYSfloor(const fpreal32 val)
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.
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.