Virtual_by_fxsaber/Include/fxsaber/Virtual/String.mqh

90 lines
No EOL
3.6 KiB
MQL5

#ifdef VIRTUAL_COUNTER
struct COUNTER_UNIT
{
int Count;
string Name;
COUNTER_UNIT() : Count(0), Name(NULL)
{
}
bool Set( const string &Str )
{
bool Res = (this.Name == Str);
if (!Res && (Res = (this.Name == NULL)))
this.Name = Str;
return(Res && (bool)++this.Count);
}
};
class COUNTER
{
COUNTER_UNIT Units[];
int Amount;
public:
COUNTER( void ) : Amount(::ArrayResize(Units, 1000) * 0)
{
}
void Set( const string Str )
{
for (int i = 0; (i <= this.Amount); i++)
if (this.Units[i].Set(Str))
{
if (i == this.Amount)
this.Amount++;
break;
}
}
~COUNTER()
{
::ArrayResize(this.Units, this.Amount);
::ArrayPrint(this.Units);
}
};
COUNTER Counter; // Counter.Set(__FUNCTION__); прописать в функциях.
#define _VC Counter.Set(__FUNCTION__);
#else // #ifdef VIRTUAL_COUNTER
#define _VC
#endif // #ifdef VIRTUAL_COUNTER #else
#define STRING_LEN (sizeof(uint) * 16) // Выравнивание по uint
struct STRING
{
//private: // https://www.mql5.com/ru/forum/1111/page2274#comment_8563787
uchar Array[STRING_LEN];
public:
void operator =( const int ) const
{
_VC
return;
}
void operator =( const string &Str )
{
_VC
if (Str == NULL) // https://www.mql5.com/ru/forum/1111/page2323#comment_9414672
this.Array[0] = 0; // NULL-строка будет превращаться в ""-строку, т.е. NULL-строку не сохранить.
else
::StringToCharArray(Str, this.Array);
return;
}
string Get( void ) const
{
_VC
return(::CharArrayToString(this.Array)); // https://www.mql5.com/ru/forum/380278/page13#comment_25676915
}
};
#undef STRING_LEN