1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/CMsgIdPool.h Fri Feb 16 18:47:16 2007 +0000
1.3 @@ -0,0 +1,63 @@
1.4 +/**
1.5 +* vim: set ts=4 :
1.6 +* ===============================================================
1.7 +* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.8 +* ===============================================================
1.9 +*
1.10 +* This file is not open source and may not be copied without explicit
1.11 +* written permission of AlliedModders LLC. This file may not be redistributed
1.12 +* in whole or significant part.
1.13 +* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
1.14 +*
1.15 +* Version: $Id$
1.16 +*/
1.17 +
1.18 +#ifndef _INCLUDE_SOURCEMOD_CMSGIDPOOL_H_
1.19 +#define _INCLUDE_SOURCEMOD_CMSGIDPOOL_H_
1.20 +
1.21 +#include "sm_trie.h"
1.22 +#include "sourcemm_api.h"
1.23 +
1.24 +#define INVALID_MESSAGE_ID -1
1.25 +
1.26 +class CMessageIdPool
1.27 +{
1.28 +public:
1.29 + CMessageIdPool()
1.30 + {
1.31 + m_Names = sm_trie_create();
1.32 + }
1.33 + ~CMessageIdPool()
1.34 + {
1.35 + sm_trie_destroy(m_Names);
1.36 + }
1.37 +public:
1.38 + int GetMessageId(const char *name)
1.39 + {
1.40 + int msgid;
1.41 + if (!sm_trie_retrieve(m_Names, name, reinterpret_cast<void **>(&msgid)))
1.42 + {
1.43 + char buf[255];
1.44 + int dummy;
1.45 + msgid = 0;
1.46 +
1.47 + while (gamedll->GetUserMessageInfo(msgid, buf, sizeof(buf), dummy))
1.48 + {
1.49 + if (strcmp(name, buf) == 0)
1.50 + {
1.51 + sm_trie_insert(m_Names, name, reinterpret_cast<void *>(msgid));
1.52 + return msgid;
1.53 + }
1.54 + msgid++;
1.55 + }
1.56 +
1.57 + return INVALID_MESSAGE_ID;
1.58 + }
1.59 +
1.60 + return msgid;
1.61 + }
1.62 +private:
1.63 + Trie *m_Names;
1.64 +};
1.65 +
1.66 +#endif //_INCLUDE_SOURCEMOD_CMSGIDPOOL_H_