//+------------------------------------------------------------------+ //| 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 /*****************************************************************************/ /*Функция устанавливает файловый указатель на начало секции с именем "якоря" */ /*strSec в файле с хендлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /******************************************************************************/ /*Функция читает одно значение iRes типа long в секции с именем "якоря" strSec*/ /*в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /******************************************************************************/ /*Функция читает одно значение bRes типа bool в секции с именем "якоря" strSec*/ /*в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /********************************************************************************/ /*Функция читает одно значение dRes типа double в секции с именем "якоря" strSec*/ /*в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /***********************************************************************************/ /*Функция читает одно значение dtRes типа datetime в секции с именем "якоря" strSec*/ /*в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /************************************************************************************/ /*Функция читает массив строк sArray размером count в секции с именем "якоря" */ /*strSec в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /************************************************************************************/ /*Функция читает массив bArray типа bool размером count в секции с именем "якоря" */ /*strSec в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /************************************************************************************/ /*Функция читает массив iArray типа long размером count в секции с именем "якоря" */ /*strSec в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); } /************************************************************************************/ /*Функция читает массив dArray типа double размером count в секции с именем "якоря" */ /*strSec в файле с хэндлом handle. В случае успеха возвращается true, */ /*в случае ошибки возвращается 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); }