Updated dependency mql4-lib; improved ZmqMsg setData method

This commit is contained in:
Ding Li
2017-12-26 16:08:23 +08:00
parent 5738f693d1
commit 66602232d6
5 changed files with 101 additions and 43 deletions
Binary file not shown.
+1 -1
View File
@@ -91,7 +91,7 @@ long AtomicVar::increment(long by)
value=(long)get();
success=setOn(value+by,value);
}
while(!success);
while(!success && !IsStopped());
return (value+by);
}
//+------------------------------------------------------------------+
+60 -17
View File
@@ -19,14 +19,7 @@
//| and limitations under the License. |
//+------------------------------------------------------------------+
#property strict
#import "stdlib.ex4"
string ErrorDescription(int error_code);
int RGB(int red_value,int green_value,int blue_value);
bool CompareDoubles(double number1,double number2);
string DoubleToStrMorePrecision(double number,int precision);
string IntegerToHexString(int integer_number);
#import
#include "Error.mqh"
//+------------------------------------------------------------------+
//| Mql language specific methods |
//+------------------------------------------------------------------+
@@ -34,13 +27,29 @@ class Mql
{
public:
static int getLastError() {return GetLastError();}
static string getErrorMessage(int errorCode) {return ErrorDescription(errorCode);}
static string getErrorMessage(int errorCode) {return GetErrorDescription(errorCode);}
static string doubleToString(double value,int precision) {return DoubleToStrMorePrecision(value,precision);}
static string integerToHexString(int value) {return IntegerToHexString(value);}
static int rgb(int red,int green,int blue) {return RGB(red,green,blue);}
//--- Prefer global DoubleToString function
static string doubleToString(double value,int precision) {return DoubleToString(value,precision);}
//--- Adapted from stdlib.mq4 by using `StringSetCharacter` instead of `StringSetChar`
static string integerToHexString(int value)
{
static const string digits="0123456789ABCDEF";
string hex="00000000";
int digit,shift=28;
for(int i=0; i<8; i++)
{
digit=(value>>shift)&0x0F;
StringSetCharacter(hex,i,digits[digit]);
shift-=4;
}
return(hex);
}
//--- Prefer Canvas/Canvas.mqh XRGB
static int rgb(int r,int g,int b) {return int(0xFF000000|(uchar(r)<<16)|(uchar(g)<<8)|uchar(b));}
static bool isEqual(double a,double b) {return CompareDoubles(a,b);}
//--- Prefer Lang/Number.mqh Double::IsEqual
static bool isEqual(double a,double b) {return NormalizeDouble(a-b,8)==0;}
static bool isStopped() {return IsStopped();}
@@ -67,7 +76,19 @@ public:
static string getProgramName() {return MQLInfoString(MQL_PROGRAM_NAME);}
static string getProgramPath() {return MQLInfoString(MQL_PROGRAM_PATH);}
};
//+------------------------------------------------------------------+
//| Object getter/setter generator |
//| ObjectAttr generates: |
//| 1. private member m_property |
//| 2. public method setProperty |
//| 3. public method getProperty |
//| ObjectAttrBool is specific to boolean type properties: |
//| 1. private member m_isProperty |
//| 2. public method setProperty |
//| 3. public method isProperty |
//| Use *Read or *Write versions for read only or write only |
//| properties |
//+------------------------------------------------------------------+
#define ObjectAttr(Type, Private, Public) \
public:\
Type get##Public() const {return m_##Private;}\
@@ -87,13 +108,35 @@ public:\
private:\
Type m_##Private\
#define ObjectAttrBool(Public) \
public:\
bool is##Public() const {return m_is##Public;}\
void set##Public(bool value) {m_is##Public=value;}\
private:\
bool m_is##Public\
#define ObjectAttrBoolRead(Public) \
public:\
bool is##Public() const {return m_is##Public;}\
private:\
bool m_is##Public\
#define ObjectAttrBoolWrite(Public) \
public:\
void set##Public(bool value) {m_is##Public=value;}\
private:\
bool m_##Private\
//+------------------------------------------------------------------+
//| Print debug messages: only generate code for debugging runs |
//+------------------------------------------------------------------+
#ifdef _DEBUG
#define Debug(msg) Print(">>> DEBUG: In ",__FUNCTION__,"(",__FILE__,":",__LINE__,") [", msg, "]")
#define Debug(msg) PrintFormat(">>> DEBUG[%s,%d,%s]: %s",__FILE__,__LINE__,__FUNCTION__,msg);
#else
#define Debug(msg)
#endif
//--- Execute some code in the global scope
//+------------------------------------------------------------------+
//| Execute some code in the global scope |
//+------------------------------------------------------------------+
#define BEGIN_EXECUTE(Name) class __Execute##Name\
{\
public:__Execute##Name()\
+30 -4
View File
@@ -48,6 +48,10 @@
#import "kernel32.dll"
void RtlMoveMemory(intptr_t dest,const uchar &array[],size_t length);
void RtlMoveMemory(uchar &array[],intptr_t src,size_t length);
void RtlMoveMemory(intptr_t dest,const MqlRates &array[],size_t length);
void RtlMoveMemory(MqlRates &array[],intptr_t src,size_t length);
void RtlMoveMemory(intptr_t dest,const MqlTick &value,size_t length);
void RtlMoveMemory(MqlTick &value,intptr_t src,size_t length);
void RtlMoveMemory(intptr_t &dest,intptr_t src,size_t length);
int lstrlen(intptr_t psz);
int lstrlenW(intptr_t psz);
@@ -65,19 +69,41 @@ int MultiByteToWideChar(uint codePage,
//+------------------------------------------------------------------+
//| Copy the memory contents pointed by src to array |
//| array parameter should be initialized to the desired size |
//| Need to import RtlMoveMemory with appropriate parameter type T |
//+------------------------------------------------------------------+
void ArrayFromPointer(uchar &array[],intptr_t src,int count=WHOLE_ARRAY)
template<typename T>
void ArrayFromPointer(T &array[],intptr_t src,int count=WHOLE_ARRAY)
{
int size=(count==WHOLE_ARRAY)?ArraySize(array):count;
RtlMoveMemory(array,src,(size_t)size);
RtlMoveMemory(array,src,(size_t)(size*sizeof(T)));
}
//+------------------------------------------------------------------+
//| Copy array to the memory pointed by dest |
//| Need to import RtlMoveMemory with appropriate parameter type T |
//+------------------------------------------------------------------+
void ArrayToPointer(const uchar &array[],intptr_t dest,int count=WHOLE_ARRAY)
template<typename T>
void ArrayToPointer(const T &array[],intptr_t dest,int count=WHOLE_ARRAY)
{
int size=(count==WHOLE_ARRAY)?ArraySize(array):count;
RtlMoveMemory(dest,array,(size_t)size);
RtlMoveMemory(dest,array,(size_t)(size*sizeof(T)));
}
//+------------------------------------------------------------------+
//| Copy the memory contents pointed by src to value type T |
//| Need to import RtlMoveMemory with appropriate parameter type T |
//+------------------------------------------------------------------+
template<typename T>
void ValueFromPointer(T &value,intptr_t src)
{
RtlMoveMemory(value,src,(size_t)sizeof(T));
}
//+------------------------------------------------------------------+
//| Copy value to the memory pointed by dest |
//| Need to import RtlMoveMemory with appropriate parameter type T |
//+------------------------------------------------------------------+
template<typename T>
void ValueToPointer(const T &value,intptr_t dest)
{
RtlMoveMemory(dest,value,(size_t)sizeof(T));
}
//+------------------------------------------------------------------+
//| For void** type, dereference a level to void* |
+10 -21
View File
@@ -88,9 +88,17 @@ public:
size_t size() {return zmq_msg_size(this);}
void getData(uchar &data[]);
string getData();
void setData(const uchar &data[]);
template<typename T>
void getData(T &array[]) const {ArrayFromPointer(array,data());}
template<typename T>
void setData(const T &array[]) {ArrayToPointer(array,data());}
template<typename T>
void getData(T &value) const {ValueFromPointer(value,data());}
template<typename T>
void setData(const T &value) {ValueToPointer(value,data());}
bool more() {return 1==zmq_msg_more(this);}
@@ -111,16 +119,6 @@ bool ZmqMsg::setStringData(string data,bool nullterminated)
return res;
}
//+------------------------------------------------------------------+
//| Get message data as bytes array |
//+------------------------------------------------------------------+
void ZmqMsg::getData(uchar &data[])
{
size_t size=size();
intptr_t src=data();
if(ArraySize(data)<size) ArrayResize(data,(int)size);
ArrayFromPointer(data,src);
}
//+------------------------------------------------------------------+
//| Get message data as utf-8 string |
//+------------------------------------------------------------------+
string ZmqMsg::getData()
@@ -130,15 +128,6 @@ string ZmqMsg::getData()
return StringFromUtf8Pointer(psz,(int)size);
}
//+------------------------------------------------------------------+
//| copy data to message internal storage |
//+------------------------------------------------------------------+
void ZmqMsg::setData(const uchar &data[])
{
intptr_t dest=data();
size_t size=size();
ArrayToPointer(data,dest,(int)size);
}
//+------------------------------------------------------------------+
//| Wraps zmq_msg_gets: get metadata associated with the msg |
//+------------------------------------------------------------------+
string ZmqMsg::meta(const string property)