| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 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
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 
 | /*
 * uservars.h
 * 
 * This file is a part of NSIS.
 * 
 * Copyright (C) 2003 Ramon
 * Copyright (C) 2003-2018 NSIS Contributors
 * 
 * Licensed under the zlib/libpng license (the "License");
 * you may not use this file except in compliance with the License.
 * 
 * Licence details can be found in the file COPYING.
 * 
 * This software is provided 'as-is', without any express or implied
 * warranty.
 * 
 * Doxygen comments by Jim Park -- 07/25/2007
 */
#ifndef ___USERVARS___H_____
#define ___USERVARS___H_____
#include "lang.h"
struct uservarstring {
  int name;
  int index;
  int pos;
  int reference;
};
class UserVarsStringList : public SortedStringListND<struct uservarstring>
{
  public:
    /* Default constructor */
    UserVarsStringList() : m_index(0) {}
    /* Destructor */
    virtual ~UserVarsStringList() {}
    /**
     * Adds a name to the UserVarsStringList.  Sets reference count to
     * ref_count.
     *
     * @param name The User variable string to store.
     * @param ref_count The reference count to store.  Default is 0.
     * @return The index of the added variable string.
     */
    int add(const TCHAR *name, int ref_count = 0 )
    {
      int pos=SortedStringListND<struct uservarstring>::add(name);
      if (pos == -1) return -1;
      uservarstring* ustr = ((uservarstring*) m_gr.get()) + pos;
      ustr->index     = m_index;
      ustr->pos       = pos;
      ustr->reference = ref_count;
      int temp = m_index;
      m_index++;
      return temp;
    }
    /**
     * Get the index of the string that matches 'name.'
     *
     * @param name The name of the string to search for.
     * @param n_chars If -1, match entire string, otherwise compare only
     * n_chars worth of characters.
     * @return The index position of the structure where structure.name ==
     * name.
     */
    int get(const TCHAR *name, int n_chars = -1) const
    {
      int v = SortedStringListND<struct uservarstring>::find(name, n_chars);
      if (v == -1) return -1;
      return (((struct uservarstring*) m_gr.get())[v].index);
    }
    /**
     * Get count of strings.
     *
     * @return The count of strings.
     */
    int getnum() const
    {
       return m_index;
    }
    /**
     * Given the index of the structure, return the reference count.
     *
     * @return The reference count of the nth uservarstring structure.
     * If not found, returns -1.
     */
    int get_reference(int idx) const
    {
      int pos=get_internal_idx(idx);
      if (pos==-1) return -1;
      return (((struct uservarstring*) m_gr.get())[pos].reference);
    }
    /**
     * Given the index of the structure, increment the reference count.
     *
     * @return The previous reference count (before the increment).
     * If not found, returns -1.
     */
    int inc_reference(int idx)
    {
      int pos=get_internal_idx(idx);
      if (pos==-1) return -1;
      return ((struct uservarstring*) m_gr.get())[pos].reference++;
    }
    /**
     * Given the index of the structure, return the string value
     * of the name.
     *
     * @return String value of the name as TCHAR*.
     * If not found, returns NULL.
     */
    TCHAR *idx2name(int idx)
    {
      int pos=get_internal_idx(idx);
      if (pos==-1) return NULL;
      struct uservarstring *data=(struct uservarstring *) m_gr.get();      
      return ((TCHAR*) m_strings.get() + data[pos].name);
    }
  private:
    int m_index;
    int get_internal_idx(int idx) const
    {
      struct uservarstring *data=(struct uservarstring *) m_gr.get();
      for (int i = 0; i < m_index; i++)
      {
        if (data[i].index == idx)
        {
          return i;
        }
      }
      return -1;
    }
};
#endif
 |