home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / ShConstants.h < prev    next >
C/C++ Source or Header  |  2003-12-22  |  2KB  |  92 lines

  1. // constants.h by Ramon 18 Nov 2003
  2.  
  3. #ifndef ___CONSTANTS___H_____
  4. #define ___CONSTANTS___H_____
  5.  
  6. #include "Lang.h"
  7.  
  8. struct constantstring {
  9.   int name;
  10.   int index;
  11.   int pos;
  12.   int value1;
  13.   int value2;
  14. };
  15.  
  16. class ConstantsStringList : public SortedStringListND<struct constantstring>
  17. {
  18.   public:
  19.     ConstantsStringList()
  20.     {
  21.       index = 0;
  22.     }
  23.     ~ConstantsStringList() { }
  24.  
  25.     int add(const char *name, int value1, int value2)
  26.     {
  27.       int pos=SortedStringListND<struct constantstring>::add(name);
  28.       if (pos == -1) return -1;
  29.  
  30.       ((struct constantstring*)gr.get())[pos].index = index;
  31.       ((struct constantstring*)gr.get())[pos].pos = pos;
  32.       ((struct constantstring*)gr.get())[pos].value1 = value1;
  33.       ((struct constantstring*)gr.get())[pos].value2 = value2;
  34.  
  35.       int temp = index;
  36.       index++;
  37.  
  38.       return temp;
  39.     }
  40.  
  41.     int get(char *name, size_t n_chars = -1)
  42.     {
  43.       int v=SortedStringListND<struct constantstring>::find(name, n_chars);
  44.       if (v==-1) return -1;
  45.       return (((struct constantstring*)gr.get())[v].index);
  46.     }
  47.  
  48.     int getnum()
  49.     {
  50.       return index;
  51.     }
  52.  
  53.     int get_value1(int idx)
  54.     {
  55.       int pos=get_internal_idx(idx);
  56.       if (pos==-1) return -1;
  57.       return (((struct constantstring*)gr.get())[pos].value1);
  58.     }
  59.  
  60.     int get_value2(int idx)
  61.     {
  62.       int pos=get_internal_idx(idx);
  63.       if (pos==-1) return -1;
  64.       return (((struct constantstring*)gr.get())[pos].value2);
  65.     }
  66.  
  67.     char *idx2name(int idx)
  68.     {
  69.       int pos=get_internal_idx(idx);
  70.       if (pos==-1) return NULL;
  71.       struct constantstring *data=(struct constantstring *)gr.get();      
  72.       return ((char*)strings.get() + data[pos].name);
  73.     }
  74.  
  75.   private:
  76.     int index;
  77.     int get_internal_idx(int idx)
  78.     {
  79.       struct constantstring *data=(struct constantstring *)gr.get();      
  80.       for (int i = 0; i < index; i++)
  81.       {
  82.         if (data[i].index == idx)
  83.         {
  84.           return i;
  85.         }
  86.       }
  87.       return -1;
  88.     }
  89. };
  90.  
  91. #endif
  92.