forked from whoopdedo/publicscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMsgHandlerArray.h
More file actions
89 lines (76 loc) · 2.54 KB
/
MsgHandlerArray.h
File metadata and controls
89 lines (76 loc) · 2.54 KB
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
/******************************************************************************
* MsgHandlerArray.h
*
* This file is part of Public Scripts
* Copyright (C) 2005-2011 Tom N Harris <telliamed@whoopdedo.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*****************************************************************************/
#ifndef MSGHANDLERARRAY_H
#define MSGHANDLERARRAY_H
#if _MSC_VER > 1000
#pragma once
#endif
#include <lg/dynarray.h>
class cScript;
struct sScrMsg;
struct sMultiParm;
typedef long (*MessageHandlerProc)(cScript*,sScrMsg*,sMultiParm*);
struct sMessageHandler
{
const char* pszName;
MessageHandlerProc pfnHandler;
};
struct sMessageHandlerNode
{
ulong ulKey;
const sMessageHandler* pData;
sMessageHandlerNode(const sMessageHandler* _data);
bool operator==(const char* _s);
bool operator!=(const char* _s);
bool operator==(const sMessageHandlerNode& _r);
bool operator!=(const sMessageHandlerNode& _r);
bool operator<(const sMessageHandlerNode& _r);
};
/***
* Return a 32-bit quick'n'dirty hash of a string.
* Case-insensitive.
*/
ulong hash_name(const char* pszName);
/***
* Return the first index not less than the given name,
* with a pre-computed hash.
* Returns array.size() if no node is found.
*/
uint find_first(cDynArray<sMessageHandlerNode>& array, const char* name, ulong key);
/***
* Inline overload of find_first that dynamically computes the hash.
*/
inline uint find_first(cDynArray<sMessageHandlerNode>& array, const char* name)
{
return find_first(array, name, hash_name(name));
}
/***
* Inline overload of find_first using an existing reference node.
*/
inline uint find_first(cDynArray<sMessageHandlerNode>& array, const sMessageHandlerNode& node)
{
return find_first(array, node.pData->pszName, node.ulKey);
}
/***
* Inserts a node at the position returned from find_first.
*/
uint insert_sorted(cDynArray<sMessageHandlerNode>& array, const sMessageHandlerNode& node);
#endif // MSGHANDLERARRAY_H