153 lines
No EOL
15 KiB
MQL5
153 lines
No EOL
15 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ConfigFiles.mqh |
|
|
//| Copyright 2013, MetaQuotes Software Corp. |
|
|
//| http://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2013, MetaQuotes Software Corp."
|
|
#property link "http://www.mql5.com"
|
|
#property strict
|
|
|
|
/********************************************************************************/
|
|
/*The function sets the file pointer to the beginning of the section containing */
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/********************************************************************************/
|
|
bool GotoSection(string strSec, int handle) {
|
|
if (!FileSeek(handle,0,SEEK_SET) ) return (false);
|
|
while(!FileIsEnding(handle)) {
|
|
if (StringCompare(FileReadString(handle), strSec) == 0) return (true);
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
|
|
/********************************************************************************/
|
|
/*The function reads one iRes value of long type in the section containing */
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/********************************************************************************/
|
|
bool _ReadIntInConfigSection(string strSec, int handle, long& iRes) {
|
|
if (!FileSeek(handle,0,SEEK_SET) ) return (false);
|
|
string s;
|
|
while(!FileIsEnding(handle)) {
|
|
if (StringCompare(FileReadString(handle), strSec) == 0) {
|
|
iRes = StringToInteger(FileReadString(handle));
|
|
return (true);
|
|
}
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
/********************************************************************************/
|
|
/*The function reads one bRes value of bool type in the section containing */
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/********************************************************************************/
|
|
bool _ReadBoolInConfigSection(string strSec, int handle, bool& bRes) {
|
|
if (!FileSeek(handle,0,SEEK_SET) ) return (false);
|
|
while(!FileIsEnding(handle)) {
|
|
if (StringCompare(FileReadString(handle), strSec) == 0) {
|
|
bRes = (bool)StringToInteger(FileReadString(handle));
|
|
return (true);
|
|
}
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
/********************************************************************************/
|
|
/*The function reads one dRes value of double type in the section containing */
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/********************************************************************************/
|
|
bool _ReadDoubleInConfigSection(string strSec, int handle, double& dRes) {
|
|
if (!FileSeek(handle,0,SEEK_SET) ) return (false);
|
|
while(!FileIsEnding(handle)) {
|
|
if (StringCompare(FileReadString(handle), strSec) == 0) {
|
|
dRes = StringToDouble(FileReadString(handle));
|
|
return (true);
|
|
}
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
/*********************************************************************************/
|
|
/*The function reads one dtRes value of datetime type in the section containing */
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/*********************************************************************************/
|
|
bool _ReadDatetimeInConfigSection(string strSec, int handle, datetime& dtRes) {
|
|
if (!FileSeek(handle,0,SEEK_SET) ) return (false);
|
|
while(!FileIsEnding(handle)) {
|
|
if (StringCompare(FileReadString(handle), strSec) == 0) {
|
|
dtRes = StringToTime(FileReadString(handle));
|
|
return (true);
|
|
}
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
|
|
/**********************************************************************************/
|
|
/*The function reads sArray having count size in the section containing */
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/**********************************************************************************/
|
|
bool _ReadStringArrayInConfigSection(string strSec, int handle, string& sArray[], int count) {
|
|
if (!FileSeek(handle,0,SEEK_SET) ) return (false);
|
|
while(!FileIsEnding(handle)) {
|
|
if (StringCompare(FileReadString(handle), strSec) == 0) {
|
|
ArrayResize(sArray, count);
|
|
for (int i = 0; i < count; i++) sArray[i] = FileReadString(handle);
|
|
return (true);
|
|
}
|
|
}
|
|
return (false);
|
|
}
|
|
|
|
|
|
/************************************************************************************/
|
|
/*The function reads bArray of bool type having count size in the section containing*/
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/************************************************************************************/
|
|
bool _ReadBoolArrayInConfigSection(string strSec, int handle, bool& bArray[], int count) {
|
|
string sArray[];
|
|
if (!_ReadStringArrayInConfigSection(strSec, handle, sArray, count) ) return (false);
|
|
ArrayResize(bArray, count);
|
|
for (int i = 0; i < count; i++) {
|
|
bArray[i] = (bool)StringToInteger(sArray[i]);
|
|
}
|
|
return (true);
|
|
}
|
|
|
|
|
|
/************************************************************************************/
|
|
/*The function reads iArray of long type having count size in the section containing*/
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/************************************************************************************/
|
|
bool _ReadIntArrayInConfigSection(string strSec, int handle, long& iArray[], int count) {
|
|
string sArray[];
|
|
if (!_ReadStringArrayInConfigSection(strSec, handle, sArray, count) ) return (false);
|
|
ArrayResize(iArray, count);
|
|
for (int i = 0; i < count; i++) {
|
|
iArray[i] = StringToInteger(sArray[i]);
|
|
}
|
|
return (true);
|
|
}
|
|
|
|
|
|
/**************************************************************************************/
|
|
/*The function reads dArray of double type having count size in the section containing*/
|
|
/*strSec "anchor" name in the handle file. If successful, true is returned, */
|
|
/*otherwise – false. */
|
|
/**************************************************************************************/
|
|
bool _ReadDoubleArrayInConfigSection(string strSec, int handle, double& dArray[], int count) {
|
|
string sArray[];
|
|
if (!_ReadStringArrayInConfigSection(strSec, handle, sArray, count) ) return (false);
|
|
ArrayResize(dArray, count);
|
|
for (int i = 0; i < count; i++) {
|
|
dArray[i] = StringToDouble(sArray[i]);
|
|
}
|
|
return (true);
|
|
} |