File: uservars.h

package info (click to toggle)
nsis 2.37-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,860 kB
  • ctags: 8,113
  • sloc: cpp: 32,080; ansic: 29,202; python: 1,118; xml: 451; pascal: 113; makefile: 80
file content (103 lines) | stat: -rwxr-xr-x 2,288 bytes parent folder | download
1
2
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
/*
 * uservars.h
 * 
 * This file is a part of NSIS.
 * 
 * Copyright (C) 2003 Ramon
 * 
 * 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.
 */

#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:
    UserVarsStringList()
    {
      index = 0;
    }
    ~UserVarsStringList() { }

    int add(const char *name, int ref_count = 0 )
    {
      int pos=SortedStringListND<struct uservarstring>::add(name);
      if (pos == -1) return -1;

      ((struct uservarstring*)gr.get())[pos].index = index;
      ((struct uservarstring*)gr.get())[pos].pos = pos;
      ((struct uservarstring*)gr.get())[pos].reference = ref_count;

      int temp = index;
      index++;

      return temp;
    }

    int get(char *name, int n_chars = -1)
    {
      int v=SortedStringListND<struct uservarstring>::find(name, n_chars);
      if (v==-1) return -1;
      return (((struct uservarstring*)gr.get())[v].index);
    }

    int getnum()
    {
      return index;
    }

    int get_reference(int idx)
    {
      int pos=get_internal_idx(idx);
      if (pos==-1) return -1;
      return (((struct uservarstring*)gr.get())[pos].reference);
    }

    int inc_reference(int idx)
    {
      int pos=get_internal_idx(idx);
      ((struct uservarstring*)gr.get())[pos].reference++;
      return (((struct uservarstring*)gr.get())[pos].reference)-1;
    }

    char *idx2name(int idx)
    {
      int pos=get_internal_idx(idx);
      if (pos==-1) return NULL;
      struct uservarstring *data=(struct uservarstring *)gr.get();      
      return ((char*)strings.get() + data[pos].name);
    }

  private:
    int index;
    int get_internal_idx(int idx)
    {
      struct uservarstring *data=(struct uservarstring *)gr.get();      
      for (int i = 0; i < index; i++)
      {
        if (data[i].index == idx)
        {
          return i;
        }
      }
      return -1;
    }
};

#endif