mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Core: decode
git-svn-id: svn://ultimatepp.org/upp/trunk@5920 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
409dc657e3
commit
9466c21835
2 changed files with 67 additions and 2 deletions
|
|
@ -217,6 +217,9 @@ template <class T> inline const T& max(const T& a, const T& b) { return a > b ?
|
|||
template <class T>
|
||||
inline T minmax(T x, T _min, T _max) { return min(max(x, _min), _max); }
|
||||
|
||||
template <class T>
|
||||
inline T clamp(T x, T _min, T _max) { return minmax(x, _min, _max); }
|
||||
|
||||
//$-int findarg(const T& x, const T1& p0, ...);
|
||||
inline void findarg_NOP() {} // Only to make List work for findarg
|
||||
|
||||
|
|
@ -241,6 +244,48 @@ __Expand40(E__NFBody)
|
|||
|
||||
//$+
|
||||
|
||||
//$-D decode(const T& x, const T1& p0, const V1& v0, ...);
|
||||
#define E__TL(I) typename COMBINE(T, I), typename COMBINE(V, I)
|
||||
#define E__NFIf(I) findarg_NOP(); if(x == COMBINE(p, I)) return COMBINE(v, I); findarg_NOP()
|
||||
#define E__NFValue(I) const COMBINE(T, I)& COMBINE(p, I), const COMBINE(V, I)& COMBINE(v, I)
|
||||
|
||||
#define E__NFBody(I) \
|
||||
template <typename T, __List##I(E__TL), typename D> \
|
||||
D decode(const T& x, __List##I(E__NFValue), const D& def) \
|
||||
{ \
|
||||
__List##I(E__NFIf); \
|
||||
return def; \
|
||||
}
|
||||
|
||||
__Expand40(E__NFBody)
|
||||
|
||||
#undef E__TL
|
||||
#undef E__NFIf
|
||||
#undef E__NFValue
|
||||
#undef E__NFBody
|
||||
//$+
|
||||
|
||||
//$-const char *decode(const T& x, const T1& p0, const char *v0, ...);
|
||||
#define E__TL(I) typename COMBINE(T, I)
|
||||
#define E__NFIf(I) findarg_NOP(); if(x == COMBINE(p, I)) return COMBINE(v, I); findarg_NOP()
|
||||
#define E__NFValue(I) const COMBINE(T, I)& COMBINE(p, I), const char *COMBINE(v, I)
|
||||
|
||||
#define E__NFBody(I) \
|
||||
template <typename T, __List##I(E__TL)> \
|
||||
const char *decode(const T& x, __List##I(E__NFValue), const char *def) \
|
||||
{ \
|
||||
__List##I(E__NFIf); \
|
||||
return def; \
|
||||
}
|
||||
|
||||
__Expand40(E__NFBody)
|
||||
|
||||
#undef E__TL
|
||||
#undef E__NFIf
|
||||
#undef E__NFValue
|
||||
#undef E__NFBody
|
||||
//$+
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef signed char int8;
|
||||
typedef unsigned char uint8;
|
||||
|
|
|
|||
|
|
@ -144,19 +144,39 @@ URL that will be opened in the browser&]
|
|||
[s4; &]
|
||||
[s5;:minmax`(T`,T`,T`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T]>_[*@4 T]_[* minmax]([*@4 T
|
||||
]_[*@3 x], [*@4 T]_[*@3 `_min], [*@4 T]_[*@3 `_max])&]
|
||||
[s5;:clamp`(T`,T`,T`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T]>_[*@4 T]_[* clamp]([*@4 T
|
||||
]_[*@3 x], [*@4 T]_[*@3 `_min], [*@4 T]_[*@3 `_max])&]
|
||||
[s2;%% Returns [%-*@3 x] if it is between [%-*@3 `_min] and [%-*@3 `_max].&]
|
||||
[s2; [%% If ][*@3 x][%% is lower than ][*@3 `_min][%% it returns ][*@3 `_min.]&]
|
||||
[s0;l288; [%% If ][*@3 x][%% is higher than ][*@3 `_max][%% it returns ][*@3 `_max.]&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:findarg`(const T`&`,const T1`&`,`.`.`.`): [@(0.0.255) template]_<[@(0.0.255) class]_
|
||||
[*@4 T]>_[@(0.0.255) int]_[* findarg]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x],
|
||||
[@(0.0.255) const]_[*@4 T1][@(0.0.255) `&]_[*@3 p0], ...)&]
|
||||
[*@4 T], [@(0.0.255) class]_[*@4 T1], ...>_[@(0.0.255) int]_[* findarg]([@(0.0.255) const]_[*@4 T
|
||||
][@(0.0.255) `&]_[*@3 x], [@(0.0.255) const]_[*@4 T1][@(0.0.255) `&]_[*@3 p0],
|
||||
...)&]
|
||||
[s2;%% Searches the list of arguments for the value of [%-*@3 x]. If
|
||||
it is found, function returns the index of argument (starting
|
||||
with 0). If not found, `-1 is returned.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:decode`(const T`&`,const T1`&`,const V1`&`,`.`.`.`): [@(0.0.255) template]_<[@(0.0.255) c
|
||||
lass]_[*@4 T], [@(0.0.255) class]_[*@4 T1], [@(0.0.255) class]_[*@4 V1],
|
||||
..., [@(0.0.255) class]_[*@4 D]>&]
|
||||
[s5; [*@4 D]_[* decode]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) const]_[*@4 T1
|
||||
][@(0.0.255) `&]_[*@3 p0], [@(0.0.255) const]_[*@4 V1][@(0.0.255) `&]_[*@3 v0],
|
||||
..., [@(0.0.255) const]_[*@4 D][@(0.0.255) `&]_[*@3 def])&]
|
||||
[s5;:decode`(const T`&`,const T1`&`,const char`*`,`.`.`.`): [@(0.0.255) template]_<[@(0.0.255) c
|
||||
lass]_[*@4 T], [@(0.0.255) class]_[*@4 T1], ...>&]
|
||||
[s5; [@(0.0.255) const]_[@(0.0.255) char]_`*[* decode]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_
|
||||
[*@3 x], [@(0.0.255) const]_[*@4 T1][@(0.0.255) `&]_[*@3 p0], [@(0.0.255) const]_[@(0.0.255) ch
|
||||
ar]_`*[*@3 v0], ..., [@(0.0.255) const]_[*@4 D][@(0.0.255) `&]_[*@3 def])&]
|
||||
[s2;%% Searches the list of argument pairs for the value of [%-*@3 x]
|
||||
to be equal to the first argument in the pair. If found, returns
|
||||
the second argument of pair. If no match is found, returns the
|
||||
last argument [%-*@3 def].&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:CpuSSE`(`): [@(0.0.255) bool]_[* CpuSSE]()&]
|
||||
[s2;%% Returns true if CPU has SSE support.&]
|
||||
[s3; &]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue