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

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