*Functions4U: Added details

git-svn-id: svn://ultimatepp.org/upp/trunk@13544 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2019-08-14 08:44:44 +00:00
parent aa437d819d
commit 7301f45080
4 changed files with 70 additions and 6 deletions

View file

@ -255,6 +255,11 @@ template<class T>
inline T pow3(T a) {return a*a*a;}
template<class T>
inline T pow4(T a) {return pow2(pow2(a));}
template<class T>
inline T fround(T x, int numdec) {
int64 mult = 10*numdec;
return T(int64(x*mult + .5))/mult;
}
template <class T>
inline bool Between(const T& val, const T& min, const T& max) {
return val >= min && val <= max;
@ -667,6 +672,17 @@ void Shuffle(C &data, int randomSeed = Null) {
ShuffleDescending(data, generator);
}
template <class T>
bool Equal(const T& a, const T& b, const T& ratio) {
if (a == 0)
return b <= ratio;
if (b == 0)
return a <= ratio;
if(abs((a - b)/b) <= ratio)
return true;
return false;
}
template <class Range, class V>
void FindAdd(Range& r, const V& value, int from = 0) {
for(int i = from; i < r.GetCount(); i++)
@ -675,6 +691,14 @@ void FindAdd(Range& r, const V& value, int from = 0) {
r.Add(value);
}
template <class Range, class V>
void FindAddRatio(Range& r, const V& value, const V& ratio, int from = 0) {
for(int i = from; i < r.GetCount(); i++)
if(Equal(r[i], value, ratio))
return;
r.Add(value);
}
template <class Range, class V>
int FindIndexDelta(const Range& r, const V& value, const V& delta, int from = 0)
{
@ -687,22 +711,36 @@ int FindIndexDelta(const Range& r, const V& value, const V& delta, int from = 0)
template <class Range, class V>
int FindIndexRatio(const Range& r, const V& value, const V& ratio, int from = 0)
{
for(int i = from; i < r.GetCount(); i++)
if(abs((r[i] - value)/value) <= ratio)
for(int i = from; i < r.GetCount(); i++) {
if (Equal(r[i], value, ratio))
return i;
}
return -1;
}
template <class Range>
bool Compare(Range& a, Range& b, int from = 0) {
template <class Range, class V>
bool Compare(const Range& a, const Range& b, const V& ratio = 0) {
if (a.GetCount() != b.GetCount())
return false;
for(int i = from; i < a.GetCount(); i++)
if(a[i] != b[i])
for(int i = 0; i < a.GetCount(); i++) {
V div = (b[i] != 0) ? b[i] : (a[i] != 0 ? a[i] : 1);
if(abs(a[i] - b[i])/div > ratio)
return false;
}
return true;
}
template <class Range>
String ToString(const Range& a) {
String ret;
for(int i = 0; i < a.GetCount(); i++) {
if (i > 0)
ret << ";";
ret << a[i];
}
return ret;
}
class RealTimeStop {
typedef RealTimeStop CLASSNAME;
public:

View file

@ -46,3 +46,4 @@ file
Html/htmld.h,
Copying;
spellcheck_comments "EN-GB"

View file

@ -193,5 +193,26 @@ ConsoleOutput::~ConsoleOutput() {
#endif
}
void ArrayCtrlWhenBar(Bar &menu, ArrayCtrl &array) {
menu.Add(t_("Select all"), Null, [&] {ArrayCtrlRowSelect(array);})
.Key(K_CTRL_A).Help(t_("Select all rows"));
int count = array.GetSelectCount();
if (count == 0)
menu.Add(t_("No row selected"), Null, Null).Enable(false).Bold(true);
else {
menu.Add(Format(t_("Selected %d rows"), count), Null, Null).Enable(false).Bold(true);
menu.Add(t_("Copy"), Null, [&] {ArrayCtrlRowCopy(array, false);})
.Key(K_CTRL_C).Help(t_("Copy selected rows to clipboard"));
}
}
void ArrayCtrlRowCopy(ArrayCtrl &array, bool header) {
array.SetClipboard(true, header);
}
void ArrayCtrlRowSelect(ArrayCtrl &array) {
array.Select(0, array.GetCount(), true);
}
#endif

View file

@ -106,4 +106,8 @@ private:
#endif
};
void ArrayCtrlWhenBar(Bar &menu, ArrayCtrl &array);
void ArrayCtrlRowCopy(ArrayCtrl &array, bool header);
void ArrayCtrlRowSelect(ArrayCtrl &array);
#endif