EnumToString and turning values to string in a template class - page 3

 

Thanks!

But, I prefer that format:

template<typename T>
void PrintEnum(T dummy = -1)
  {
   Print(typename(T));
   Print("  {");
   for(int i = -2; i < USHORT_MAX + 1000; i++)
      if(StringFind(EnumToString((T)i),"::")<0)
         printf("   %s = %d,",EnumToString((T)i),i);
   Print("  };");
  }

void OnStart()
  {
   PrintEnum<ENUM_DATATYPE>();
   PrintEnum<ENUM_TERMINAL_INFO_STRING>();
  }

/*
enum ENUM_DATATYPE
  {
   TYPE_BOOL = 1,
   TYPE_CHAR = 2,
   TYPE_UCHAR = 3,
   TYPE_SHORT = 4,
   TYPE_USHORT = 5,
   TYPE_COLOR = 6,
   TYPE_INT = 7,
   TYPE_UINT = 8,
   TYPE_DATETIME = 9,
   TYPE_LONG = 10,
   TYPE_ULONG = 11,
   TYPE_FLOAT = 12,
   TYPE_DOUBLE = 13,
   TYPE_STRING = 14,
   TYPE_VECTOR = 96,
   TYPE_MATRIX = 97,
   TYPE_VECTORF = 98,
   TYPE_MATRIXF = 99,
   TYPE_VECTORC = 100,
   TYPE_MATRIXC = 101,
  };
enum ENUM_TERMINAL_INFO_STRING
  {
   TERMINAL_COMPANY = 0,
   TERMINAL_NAME = 1,
   TERMINAL_PATH = 2,
   TERMINAL_DATA_PATH = 3,
   TERMINAL_COMMONDATA_PATH = 4,
   TERMINAL_LANGUAGE = 13,
   TERMINAL_CPU_NAME = 39,
   TERMINAL_OS_VERSION = 40,
  };
*/
 
amrali #:

Thanks!

But, I prefer that format:

Nice , why USHORT_MAX+1000 though ?

The max value i caught was 

2097152

edit i turned the enum grabber to this ,it is useless but it goes through the possible values so the loop is smaller : 

template <typename X>
bool is_enumeration(X &object){
/*
default and custom enum typenames have enum and then the name of the enum 
*/
if(StringFind(typename(object),"enum",0)!=-1){return(true);}
return(false);
}

template <typename X>
int full_enumeration_grab(X enumeration,
                          long &result_codes[],
                          string &results[]){
int enum_values=0;
ArrayResize(result_codes,1000,0);
if(is_enumeration(enumeration)){
//set the first value
  X en=(X)allPossibleEnumItemValues[0]; 
  string name="";
  for(int i=0;i<ArraySize(allPossibleEnumItemValues);i++)
  {
  en=(X)(allPossibleEnumItemValues[i]);
  name=EnumToString(en);
  //if valid
  if(StringFind(name,"::",0)==-1){
    enum_values++;
    result_codes[enum_values-1]=allPossibleEnumItemValues[i];
    }
  }
//grab the values 
  if(enum_values>0){
  ArrayResize(result_codes,enum_values,0);
  ArrayResize(results,enum_values,0);
  for(int i=0;i<enum_values;i++){
  results[i]=EnumToString((X)(result_codes[i]));
  }  
  }else{
  ArrayFree(result_codes);
  }
}
return(enum_values);
}
template <typename X>
int full_enumeration_grab(X enumeration,
                          string &results[]){
long enum_codes[];
return(full_enumeration_grab(enumeration,enum_codes,results));
}
//this does not include all ENUM_DX_FORMAT values and ENUM_GEMM
long allPossibleEnumItemValues[]={37,38,39,40,41,42,43,45,46,48,49,50,51,52,0,32,33,34,35,44,47,53,54,55,56,1,2,3,36,4,5,6,7,8,9,10,11,12,13,14,15,16,1000,66534,108,109,17,18,19,21,22,23,24,25,26,27,28,29,30,31,100,101,102,103,104,105,106,107,110,111,112,115,116,118,20,113,114,64,128,65536,131072,262144,524288,1048576,2097152,4096,96,97,98,99,255,-1,57,58,59,60,61,62,63,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,130,131,132,-2,32767,65535,204,1006,1007,1010,200,201,202,203,207,208,1002,1003,1004,1005,1008,1011,1012,1013,1014,1015,1016,1018,1019,1020,1022,1023,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,205,206,1001,1017,1021,4094,4095,4097,4098,4099,4100,4101,4108,4127,4131,4146,4354,4528,4530,4532,2304,2305,2306,2307,2308,4093,4139,4140,4141,4142,4143,4144,4157,4159,117,119,120,121,122,123,151,152,153,154,155,156,157,158,159,160,161,162,251,252,253,254,256,257,258,259,260,261,262,263,264,265,266,267,268,269,301,302,303,304,305,306,307,308,309,310,311,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,401,402,403,404,405,406,407,408,409,410,411,412,451,452,453,454,455,456,457,458,459,460,461,462,501,502,503,504,505,506,551,552,553,554,1009,1037,1038,1039,1040,1045,1046,1144,1145,16385,16386,16387,16388,16390,16392,16396,16408,32769,49153};
 

Also , if you came to this thread for the solution and you are wondering what on earth are these codes , they are not relevant to the solution 

The solutions are these :

https://www.mql5.com/en/forum/439668/page2#comment_44348770

https://www.mql5.com/en/forum/439668/page2#comment_44349656

 
Lorentzos Roussos #:

Nice , why USHORT_MAX+1000 though ?

The max value i caught was 

    2097152

For me, I found that ENUM_CHART_EVENT contains the highest enum value (USHORT_MAX+1000).

So, which enumeration you find that contains this 2097152?!
 
amrali #:
For me, I found that ENUM_CHART_EVENT contains the highest enum value (USHORT_MAX+1000).

So, which enumeration you find that contains this 2097152?!

These , and excluding ENUM_GEMM and some ENUM_DX_FORMAT which are probably above it

 
Lorentzos Roussos #:

These , and excluding ENUM_GEMM and some ENUM_DX_FORMAT which are probably above it

Hello Lorentzos,

I just tested your scriipt/expert to gather all defined ENUMS instead of scraping them from the docs....

And instantly I found the enum ENUM_APPLIED_PRICE was not in the list.

Does the script want to produce a full list of all defined enumerations? Or did I misunderstand the intent? 

Reason: