From 804cdc5e317d913541fda130c0483ad108310577 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 4 May 2021 19:55:58 +0100 Subject: [PATCH] Minor code improvements --- Bar.struct.h | 3 +++ Chart.enum.h | 1 + Chart.struct.tf.h | 2 +- Convert.mqh | 3 +++ DateTime.enum.h | 2 +- DateTime.struct.h | 7 +++++++ Math.h | 9 --------- String.mqh | 20 -------------------- 8 files changed, 16 insertions(+), 31 deletions(-) diff --git a/Bar.struct.h b/Bar.struct.h index 5f2c2f0ff..6edb35f79 100644 --- a/Bar.struct.h +++ b/Bar.struct.h @@ -32,6 +32,7 @@ // Includes. #include "Bar.enum.h" +#include "Chart.enum.h" #include "Serializer.mqh" #include "SerializerNode.enum.h" @@ -130,6 +131,8 @@ struct BarOHLC { _s3 = _s1 - _range; _s4 = _s2 - _range; // ? break; + default: + break; } return _r4 > _r3 && _r3 > _r2 && _r2 > _r1 && _r1 > _pp && _pp > _s1 && _s1 > _s2 && _s2 > _s3 && _s3 > _s4; } diff --git a/Chart.enum.h b/Chart.enum.h index 322b0034d..98585383f 100644 --- a/Chart.enum.h +++ b/Chart.enum.h @@ -32,6 +32,7 @@ #ifndef __MQL__ // Defines enumeration for price price base calculations. +// https://docs.mql4.com/constants/indicatorconstants/prices enum ENUM_APPLIED_PRICE { PRICE_CLOSE = 0, // Close price. PRICE_OPEN = 1, // Open price. diff --git a/Chart.struct.tf.h b/Chart.struct.tf.h index a22015f13..d2225093b 100644 --- a/Chart.struct.tf.h +++ b/Chart.struct.tf.h @@ -183,7 +183,7 @@ struct ChartTf { return (ENUM_TIMEFRAMES_INDEX)i; } } - return NULL; + return FINAL_ENUM_TIMEFRAMES_INDEX; } /** diff --git a/Convert.mqh b/Convert.mqh index 1e821dcbe..8676112cd 100644 --- a/Convert.mqh +++ b/Convert.mqh @@ -366,15 +366,18 @@ public: switch (param.type) { case TYPE_BOOL: return param.integer_value ? 1 : 0; + case TYPE_DATETIME: case TYPE_INT: case TYPE_LONG: case TYPE_UINT: case TYPE_ULONG: + case TYPE_SHORT: return param.integer_value; case TYPE_DOUBLE: case TYPE_FLOAT: return (int) param.double_value; case TYPE_CHAR: + case TYPE_COLOR: case TYPE_STRING: case TYPE_UCHAR: return StringToInteger(param.string_value); diff --git a/DateTime.enum.h b/DateTime.enum.h index 7077dc413..73e7facbe 100644 --- a/DateTime.enum.h +++ b/DateTime.enum.h @@ -63,4 +63,4 @@ enum ENUM_TIME { TIME_MINUTES = 1 << 1, // Formats date as hh:mi. TIME_SECONDS = 1 << 2, // Formats date as hh:mi:ss. }; -#endif \ No newline at end of file +#endif diff --git a/DateTime.struct.h b/DateTime.struct.h index bfd96ba2b..bd1d057a1 100644 --- a/DateTime.struct.h +++ b/DateTime.struct.h @@ -30,6 +30,9 @@ #pragma once #endif +// Forward declarations. +struct DateTimeStatic; + // Includes. #include "DateTime.enum.h" #include "DateTime.struct.h" @@ -89,6 +92,8 @@ struct DateTimeEntry : MqlDateTime { return GetMonth(); case DATETIME_YEAR: return GetYear(); + default: + break; } return _result; } @@ -150,6 +155,8 @@ struct DateTimeEntry : MqlDateTime { case DATETIME_YEAR: SetYear(_value); break; + default: + break; } } void SetValue(unsigned short _unit, int _value) { diff --git a/Math.h b/Math.h index b3ed41383..f87c6a3ae 100644 --- a/Math.h +++ b/Math.h @@ -30,15 +30,6 @@ #include "Math.enum.h" #include "Math.struct.h" -// Includes standard C++ library for non-MQL code. -#ifndef __MQLBUILD__ -#include // GNU GCC extension. - -#include -#include -using namespace std; -#endif - // Defines macros. #define fmax2(_v1, _v2) fmax(_v1, _v2) #define fmax3(_v1, _v2, _v3) fmax(fmax(_v1, _v2), _v3) diff --git a/String.mqh b/String.mqh index 6b7352907..724959d05 100644 --- a/String.mqh +++ b/String.mqh @@ -28,26 +28,6 @@ #define NL "\n" // New line: 0x0A (MQL file functions auto-convert 0x0A to 0x0D0A). #define TAB "\t" // Tab: 0x09. -// Includes standard C++ library for non-MQL code. -#ifndef __MQLBUILD__ -#include // For std::unique_ptr -#include // For va_start, etc. -#include - -template -std::string StringFormat(const std::string& format, Args ... args) -{ - size_t size = snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0' - if (size <= 0) { throw std::runtime_error("Error during formatting."); } - std::unique_ptr buf(new char[size]); - snprintf(buf.get(), size, format.c_str(), args ...); - return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside -} - -#define PrintFormat printf - -#endif - /** * Class to provide methods to deal with strings. */