102 lines
No EOL
2.4 KiB
MQL5
102 lines
No EOL
2.4 KiB
MQL5
#ifndef FRAMEWORK_TOOL_CACHE_MQH
|
|
#define FRAMEWORK_TOOL_CACHE_MQH
|
|
|
|
#define TOOL_CACHED( type, name, action ) \
|
|
static type name; \
|
|
static int name##_instance_saved; \
|
|
if( name##_instance_saved != _tool_instance_state ){ \
|
|
name##_instance_saved = _tool_instance_state; \
|
|
action; \
|
|
} \
|
|
return name;
|
|
|
|
#define TOOL_CACHED_TICK( type, name, action ) \
|
|
static type name; \
|
|
static int name##_tick_saved; \
|
|
if( name##_tick_saved != _tool_tick_state ){ \
|
|
name##_tick_saved= _tool_tick_state; \
|
|
action; \
|
|
} \
|
|
return name;
|
|
|
|
#define TOOL_CACHED_HOUR( type, name, action ) \
|
|
static type name; \
|
|
static int name##_hour_saved; \
|
|
if( name##_hour_saved != _tool_hour_state ){ \
|
|
name##_hour_saved= _tool_hour_state; \
|
|
action; \
|
|
} \
|
|
return name;
|
|
|
|
#define TOOL_CACHED_TICK_TESTING( type, name, action ) \
|
|
static type name; \
|
|
static int name##_tick_saved; \
|
|
static bool name##_testing_saved; \
|
|
if(layer_account::is_testing() \
|
|
|| layer_account::is_optimization()) { \
|
|
if(!name##_testing_saved) { \
|
|
name##_testing_saved = true; \
|
|
action; \
|
|
} \
|
|
} \
|
|
else if( name##_tick_saved != _tool_tick_state ){ \
|
|
name##_tick_saved = _tool_tick_state; \
|
|
action; \
|
|
} \
|
|
return name;
|
|
|
|
#define TOOL_CACHED_INSTANCE( type, name, action ) \
|
|
private: \
|
|
type _##name; \
|
|
int _##name##_instance_saved; \
|
|
public: \
|
|
type name() { \
|
|
if( _##name##_instance_saved != _tool_instance_state ){ \
|
|
_##name##_instance_saved = _tool_instance_state; \
|
|
action; \
|
|
} \
|
|
return _##name; \
|
|
}
|
|
|
|
#define TOOL_CACHED_INSTANCE_TICK( type, name, action ) \
|
|
private: \
|
|
type _##name; \
|
|
int _##name##_tick_saved; \
|
|
public: \
|
|
type name() { \
|
|
if( _##name##_tick_saved != _tool_tick_state ){ \
|
|
_##name##_tick_saved = _tool_tick_state; \
|
|
action; \
|
|
} \
|
|
return _##name; \
|
|
}
|
|
|
|
int _tool_instance_state = -512;
|
|
int _tool_tick_state = -256;
|
|
int _tool_hour_state = -128;
|
|
|
|
timer_t* _cache_hour_update_timer=NULL;
|
|
|
|
class tool_cache {
|
|
public:
|
|
static void update_instance_state() {
|
|
_tool_instance_state += 1;
|
|
|
|
_cache_hour_update_timer=timer_t::create ( 3600 );
|
|
gc::push ( gc_dispose_type_on_end_deinit, _cache_hour_update_timer );
|
|
}
|
|
|
|
static void update_tick_state() {
|
|
_tool_tick_state += 1;
|
|
|
|
if (_cache_hour_update_timer!=NULL && _cache_hour_update_timer.is_elapsed())
|
|
{
|
|
_cache_hour_update_timer.reset();
|
|
_tool_hour_state++;
|
|
}
|
|
|
|
|
|
}
|
|
};
|
|
|
|
#endif |