
Compiler output is identical before & after this step git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6036 212acab6-be3b-0410-9dea-997c60f758d6
129 lines
3 KiB
C++
129 lines
3 KiB
C++
/*
|
|
* 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 TCHAR *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;
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
int v=SortedStringListND<struct uservarstring>::find(name, n_chars);
|
|
if (v==-1) return -1;
|
|
return (((struct uservarstring*)gr.get())[v].index);
|
|
}
|
|
|
|
/**
|
|
* Get count of strings.
|
|
*
|
|
* @return The count of strings.
|
|
*/
|
|
int getnum()
|
|
{
|
|
return 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)
|
|
{
|
|
int pos=get_internal_idx(idx);
|
|
if (pos==-1) return -1;
|
|
return (((struct uservarstring*)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);
|
|
((struct uservarstring*)gr.get())[pos].reference++;
|
|
return (((struct uservarstring*)gr.get())[pos].reference)-1;
|
|
}
|
|
|
|
TCHAR *idx2name(int idx)
|
|
{
|
|
int pos=get_internal_idx(idx);
|
|
if (pos==-1) return NULL;
|
|
struct uservarstring *data=(struct uservarstring *)gr.get();
|
|
return ((TCHAR*)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
|