Guest User

cstl.cpp

a guest
May 10th, 2013
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 35.55 KB | None | 0 0
  1. /*
  2.  * @author Teprey
  3.  * @version 0.2
  4.  *
  5.  * CSTL plugin for SA:MP by Teprey (C) 2011
  6.  * Edited Some bugs by Cyber_Punk (C) 2012
  7.  * Provides some STL functions/data containers for SA:MP PAWN language
  8.  * Do not remove this author credit
  9.  */
  10.  
  11. /* Entry types */
  12. #define CSTL_TYPE_CELL 1
  13. #define CSTL_TYPE_PTR 2
  14. #define CSTL_TYPE_FLOAT 3
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <cstdlib>
  19. #include <stdexcept>
  20. #include <iostream>
  21. #include <string>
  22. #include <cstring>
  23. #include <vector>
  24. #include <map>
  25. #include <deque>
  26. #include <algorithm>
  27.  
  28. #include "AMX_SDK/amx/amx.h"
  29. #include "AMX_SDK/plugincommon.h"
  30.  
  31. extern void * pAMXFunctions;
  32. using namespace std;  
  33.  
  34. typedef struct {
  35.     cell entry;
  36.     string strentry;
  37.     int type;
  38.    
  39. } entry;
  40.  
  41. bool operator ==(const entry& lhs, const entry& rhs)
  42. {
  43.     if (lhs.entry == NULL || rhs.entry == NULL)
  44.     {
  45.         return (lhs.strentry == rhs.strentry);
  46.     }
  47.     return (lhs.entry == rhs.entry);
  48. }
  49.  
  50. static int cstl_index = 0;
  51. static map<AMX*, map<cell, vector<entry> > > vectors;
  52. static map<cell, AMX*> isVectorGlobalized;
  53.  
  54. static map<AMX*, map<cell, map<string, entry> > > maps;
  55. static map<cell, AMX*> isMapGlobalized;
  56.  
  57. static map<AMX*, map<cell, deque<entry> > > deques;
  58. static map<cell, AMX*> isDequeGlobalized;
  59.  
  60. PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
  61. {
  62.     return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
  63. }
  64.  
  65. PLUGIN_EXPORT bool PLUGIN_CALL Load( void **ppData )
  66. {
  67.     pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
  68.     cout << "cstl by Teprey edited by Cyber_Punk(C) 2011 - 2012";
  69.     return true;
  70. }
  71.  
  72. PLUGIN_EXPORT void PLUGIN_CALL Unload( )
  73. {
  74.  
  75. }
  76.  
  77. // DEQUE
  78.  
  79. /* native deque_push_back(deqid, element); */
  80. static cell AMX_NATIVE_CALL n_deque_push_back( AMX* amx, cell* params )
  81. {
  82.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  83.     cell deqid = params[1];
  84.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  85.     cell element = params[2];
  86.     entry n;
  87.     n.entry = element;
  88.     n.type = CSTL_TYPE_CELL;
  89.     deques[amx][deqid].push_back(n);
  90.  
  91.     return 1;
  92. }
  93.  
  94. /* native deque_push_back_float(deqid, Float:element); */
  95. static cell AMX_NATIVE_CALL n_deque_push_back_float( AMX* amx, cell* params )
  96. {
  97.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  98.     cell deqid = params[1];
  99.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  100.     cell element = params[2];
  101.     entry n;
  102.     n.entry = element;
  103.     n.type = CSTL_TYPE_FLOAT;
  104.     deques[amx][deqid].push_back(n);
  105.  
  106.     return 1;
  107. }
  108.  
  109. /* native deque_push_back_arr(deqid, arr[]); */
  110. static cell AMX_NATIVE_CALL n_deque_push_back_arr( AMX* amx, cell* params )
  111. {
  112.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  113.     cell deqid = params[1];
  114.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  115.     char * element;
  116.     amx_StrParam(amx,params[2],element);
  117.     entry n;
  118.     n.strentry = element;
  119.     n.type = CSTL_TYPE_PTR;
  120.     deques[amx][deqid].push_back(n);
  121.  
  122.     return 1;
  123. }
  124.  
  125. /* native deque_push_front(deqid, element); */
  126. static cell AMX_NATIVE_CALL n_deque_push_front( AMX* amx, cell* params )
  127. {
  128.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  129.     cell deqid = params[1];
  130.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  131.     cell element = params[2];
  132.     entry n;
  133.     n.entry = element;
  134.     n.type = CSTL_TYPE_CELL;
  135.     deques[amx][deqid].push_front(n);
  136.  
  137.     return 1;
  138. }
  139.  
  140. /* native deque_push_front_float(deqid, Float:element); */
  141. static cell AMX_NATIVE_CALL n_deque_push_front_float( AMX* amx, cell* params )
  142. {
  143.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  144.     cell deqid = params[1];
  145.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  146.     cell element = params[2];
  147.     entry n;
  148.     n.entry = element;
  149.     n.type = CSTL_TYPE_FLOAT;
  150.     deques[amx][deqid].push_front(n);
  151.  
  152.     return 1;
  153. }
  154.  
  155. /* native deque_push_front_arr(deqid, arr[]); */
  156. static cell AMX_NATIVE_CALL n_deque_push_front_arr( AMX* amx, cell* params )
  157. {
  158.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  159.     cell deqid = params[1];
  160.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  161.     char * element;
  162.     amx_StrParam(amx,params[2],element);
  163.     entry n;
  164.     n.strentry = element;
  165.     n.type = CSTL_TYPE_PTR;
  166.     deques[amx][deqid].push_front(n);
  167.  
  168.     return 1;
  169. }
  170.  
  171. /* native deque_swap(deqid1, id1, dequeid2, id2); */
  172. static cell AMX_NATIVE_CALL n_deque_swap( AMX* amx, cell* params )
  173. {
  174.     if (params[0] != 16) { return -1; /* insufficient parameters */ }
  175.     cell deqid1 = params[1];
  176.     cell deqid2 = params[3];
  177.     if (isDequeGlobalized[deqid1] != NULL) { amx = isDequeGlobalized[deqid1]; } /* get AMX address if global */
  178.     if (isDequeGlobalized[deqid2] != NULL) { amx = isDequeGlobalized[deqid2]; }
  179.     cell element1 = params[2];
  180.     cell element2 = params[4];
  181.     entry tmp = deques[amx][deqid1][element1];
  182.     deques[amx][deqid1][element1] = deques[amx][deqid2][element2];
  183.     deques[amx][deqid2][element2] = tmp;
  184.  
  185.     return 1;
  186. }
  187.  
  188. /* native deque_size(deqid); */
  189. static cell AMX_NATIVE_CALL n_deque_size( AMX* amx, cell* params )
  190. {
  191.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  192.     cell deqid = params[1];
  193.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  194.     return deques[amx][deqid].size();
  195. }
  196.  
  197. /* native deque_get(deqid, id); */
  198. static cell AMX_NATIVE_CALL n_deque_get( AMX* amx, cell* params )
  199. {
  200.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  201.     cell deqid = params[1];
  202.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  203.     cell id = params[2];
  204.     cell result = -1;
  205.     if (deques[amx][deqid][id].type != CSTL_TYPE_CELL)
  206.     {
  207.         return -1;
  208.     }
  209.     try{
  210.         result = deques[amx][deqid].at(id).entry;
  211.     }
  212.     catch(out_of_range& oor){
  213.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  214.     }
  215.  
  216.     return result;
  217. }
  218.  
  219. /* native deque_get_float(deqid, id); */
  220. static cell AMX_NATIVE_CALL n_deque_get_float( AMX* amx, cell* params )
  221. {
  222.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  223.     cell deqid = params[1];
  224.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  225.     cell id = params[2];
  226.     cell result = -1;
  227.     if (deques[amx][deqid][id].type != CSTL_TYPE_FLOAT)
  228.     {
  229.         return -1;
  230.     }
  231.     try{
  232.         result = deques[amx][deqid].at(id).entry;
  233.     }
  234.     catch(out_of_range& oor){
  235.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  236.     }
  237.  
  238.     return result;
  239. }
  240.  
  241. /* native deque_get_arr(deqid, id, buffer[], buflen); */
  242. static cell AMX_NATIVE_CALL n_deque_get_arr( AMX* amx, cell* params )
  243. {
  244.     if (params[0] != 16) { return -1; /* insufficient parameters */ }
  245.     cell deqid = params[1];
  246.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  247.     cell id = params[2];
  248.     if (deques[amx][deqid][id].type != CSTL_TYPE_PTR)
  249.     {
  250.         return -1;
  251.     }
  252.  
  253.     char* result = NULL;
  254.     try{
  255.         result = (char*)deques[amx][deqid].at(id).strentry.c_str();
  256.     }
  257.     catch(out_of_range& oor){
  258.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  259.     }
  260.  
  261.     cell *dest;
  262.     amx_GetAddr(amx,params[3],&dest);
  263.     amx_SetString(dest,(const char*)(result),0,0,params[4] + 1);
  264.     return strlen((const char*)result) + 1;
  265. }
  266.  
  267. /* native deque_set(deqid, id, element); */
  268. static cell AMX_NATIVE_CALL n_deque_set( AMX* amx, cell* params )
  269. {
  270.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  271.     cell deqid = params[1];
  272.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  273.     cell id = params[2];
  274.     cell element = params[3];
  275.  
  276.     try{
  277.         entry n;
  278.         n.entry = element;
  279.         n.type = CSTL_TYPE_CELL;
  280.         deques[amx][deqid].at(id) = n;
  281.     }
  282.     catch(out_of_range& oor){
  283.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  284.     }
  285.     return 1;
  286. }
  287. /* native deque_set_float(deqid, id, element); */
  288. static cell AMX_NATIVE_CALL n_deque_set_float( AMX* amx, cell* params )
  289. {
  290.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  291.     cell deqid = params[1];
  292.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  293.     cell id = params[2];
  294.     cell element = params[3];
  295.  
  296.     try{
  297.         entry n;
  298.         n.entry = element;
  299.         n.type = CSTL_TYPE_FLOAT;
  300.         deques[amx][deqid].at(id) = n;
  301.     }
  302.     catch(out_of_range& oor){
  303.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  304.     }
  305.     return 1;
  306. }
  307.  
  308.  
  309. /* native deque_set_arr(deqid, id, element[]); */
  310. static cell AMX_NATIVE_CALL n_deque_set_arr( AMX* amx, cell* params )
  311. {
  312.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  313.  
  314.     cell deqid = params[1];
  315.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  316.     cell id = params[2];
  317.     char * element;
  318.     amx_StrParam(amx,params[3],element);
  319.  
  320.    
  321.     entry n;
  322.     n.strentry = element;
  323.     n.type = CSTL_TYPE_PTR;
  324.     try {
  325.         deques[amx][deqid].at(id) = n;
  326.     }
  327.     catch(out_of_range& oor){
  328.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  329.     }
  330.     return 1;
  331. }
  332.  
  333. /* native deque_clear(deqid); */
  334. static cell AMX_NATIVE_CALL n_deque_clear( AMX* amx, cell* params )
  335. {
  336.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  337.     cell deqid = params[1];
  338.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  339.     deques[amx][deqid].clear();
  340.     return 1;
  341. }
  342.  
  343.  
  344. /* native deque_resize(deqid, newsize); */
  345. static cell AMX_NATIVE_CALL n_deque_resize( AMX* amx, cell* params )
  346. {
  347.     /*+ attention: realloc with reducing size may cause memory leak ! */
  348.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  349.     cell deqid = params[1];
  350.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  351.     cell newsize = params[2];
  352.     deques[amx][deqid].resize(newsize);
  353.     return 1;
  354. }
  355.  
  356. /* native deque_find(deqid, element); */
  357. static cell AMX_NATIVE_CALL n_deque_find( AMX* amx, cell* params )
  358. {
  359.     /*+ attention: realloc with reducing size may cause memory leak ! */
  360.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  361.     cell deqid = params[1];
  362.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  363.     cell element = params[2];
  364.     entry n;
  365.     n.type = CSTL_TYPE_CELL;
  366.     n.entry = element;
  367.     deque<entry>::iterator it =  find(deques[amx][deqid].begin(), deques[amx][deqid].end(), n);
  368.     if (it == deques[amx][deqid].end())
  369.     {
  370.         return -1;
  371.     } else {
  372.         return distance(deques[amx][deqid].begin(),it);
  373.     }
  374. }
  375. /* native deque_find_float(deqid, Float:element); */
  376. static cell AMX_NATIVE_CALL n_deque_find_float( AMX* amx, cell* params )
  377. {
  378.     /*+ attention: realloc with reducing size may cause memory leak ! */
  379.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  380.     cell deqid = params[1];
  381.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  382.     cell element = params[2];
  383.     entry n;
  384.     n.type = CSTL_TYPE_FLOAT;
  385.     n.entry = element;
  386.     deque<entry>::iterator it =  find(deques[amx][deqid].begin(), deques[amx][deqid].end(), n);
  387.     if (it == deques[amx][deqid].end())
  388.     {
  389.         return -1;
  390.     } else {
  391.         return distance(deques[amx][deqid].begin(),it);
  392.     }
  393. }
  394. /* native deque_find_arr(deqid, element[]); */
  395. static cell AMX_NATIVE_CALL n_deque_find_arr( AMX* amx, cell* params )
  396. {
  397.     /*+ attention: realloc with reducing size may cause memory leak ! */
  398.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  399.     cell deqid = params[1];
  400.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  401.     char * element;
  402.     amx_StrParam(amx,params[2],element);
  403.     entry n;
  404.     n.type = CSTL_TYPE_CELL;
  405.     n.strentry = element;
  406.     n.entry = NULL;
  407.     deque<entry>::iterator it =  find(deques[amx][deqid].begin(), deques[amx][deqid].end(), n);
  408.     if (it == deques[amx][deqid].end())
  409.     {
  410.         return -1;
  411.     } else {
  412.         return distance(deques[amx][deqid].begin(),it);
  413.     }
  414. }
  415. /* native deque_remove(deqid, id); */
  416. static cell AMX_NATIVE_CALL n_deque_remove( AMX* amx, cell* params )
  417. {
  418.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  419.     cell deqid = params[1];
  420.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  421.     cell element = params[2];
  422.     try {
  423.     deques[amx][deqid].erase(deques[amx][deqid].begin() + element);
  424.     } catch(exception) {}
  425.     return 1;
  426. }
  427. /* native deque_entry_type(deqid, id); */
  428. static cell AMX_NATIVE_CALL n_deque_entry_type( AMX* amx, cell* params )
  429. {
  430.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  431.     cell deqid = params[1];
  432.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  433.     cell id = params[2];
  434.     if (deques[amx][deqid][id].type == 0 || deques[amx][deqid][id].type == NULL)
  435.     {
  436.         return -1;
  437.     }
  438.     return deques[amx][deqid][id].type;
  439. }
  440. /* native deque_globalize(deqid); */
  441. static cell AMX_NATIVE_CALL n_deque_globalize( AMX* amx, cell* params )
  442. {
  443.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  444.     cell deqid = params[1];
  445.     if (isDequeGlobalized[deqid] != NULL) {
  446.         /* already global, return FALSE*/
  447.         return -1;
  448.     }
  449.  
  450.     isDequeGlobalized[deqid] = amx;
  451.     return 1;
  452. }
  453. /* native deque_deglobalize(deqid); */
  454. static cell AMX_NATIVE_CALL n_deque_deglobalize( AMX* amx, cell* params )
  455. {
  456.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  457.     cell deqid = params[1];
  458.     if (isDequeGlobalized[deqid] == NULL) {
  459.         /* already local, return FALSE*/
  460.         return -1;
  461.     }
  462.     /* copy vector into local and remove original */
  463.     deque<entry> _new(deques[isDequeGlobalized[deqid]][deqid]);
  464.     deques[amx][deqid] = _new;
  465.     isDequeGlobalized[deqid] = NULL;
  466.     return 1;
  467. }
  468. /* native deque_is_globalized(deqid); */
  469. static cell AMX_NATIVE_CALL n_deque_is_globalized( AMX* amx, cell* params )
  470. {
  471.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  472.     cell deqid = params[1];
  473.     if (isDequeGlobalized[deqid] == NULL) {
  474.    
  475.         return -1;
  476.     }
  477.     return 1;
  478. }
  479. /* native deque_index_exists(deqid, index); */
  480. static cell AMX_NATIVE_CALL n_deque_index_exists( AMX* amx, cell* params )
  481. {
  482.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  483.     cell deqid = params[1];
  484.     if (isDequeGlobalized[deqid] != NULL) { amx = isDequeGlobalized[deqid]; } /* get AMX address if global */
  485.     cell element = params[2];
  486.     try {
  487.     deques[amx][deqid].at(element).entry;
  488.     } catch(out_of_range& oor) { cerr << "Out of Range error: " << oor.what() << endl; return -1; }
  489.     return 1;
  490. }
  491.  
  492. // VECTOR
  493.  
  494. /* native vector_push_back(vecid, element); */
  495. static cell AMX_NATIVE_CALL n_vector_push_back( AMX* amx, cell* params )
  496. {
  497.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  498.     cell vecid = params[1];
  499.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  500.     cell element = params[2];
  501.     entry n;
  502.     n.entry = element;
  503.     n.type = CSTL_TYPE_CELL;
  504.     vectors[amx][vecid].push_back(n);
  505.  
  506.     return 1;
  507. }
  508.  
  509. /* native vector_push_back_float(vecid, Float:element); */
  510. static cell AMX_NATIVE_CALL n_vector_push_back_float( AMX* amx, cell* params )
  511. {
  512.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  513.     cell vecid = params[1];
  514.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  515.     cell element = params[2];
  516.     entry n;
  517.     n.entry = element;
  518.     n.type = CSTL_TYPE_FLOAT;
  519.     vectors[amx][vecid].push_back(n);
  520.  
  521.     return 1;
  522. }
  523.  
  524.  
  525. /* native vector_push_back_arr(vecid, arr[]); */
  526. static cell AMX_NATIVE_CALL n_vector_push_back_arr( AMX* amx, cell* params )
  527. {
  528.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  529.     cell vecid = params[1];
  530.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  531.     char * element;
  532.     amx_StrParam(amx,params[2],element);
  533.     entry n;
  534.     n.strentry = element;
  535.     n.type = CSTL_TYPE_PTR;
  536.     vectors[amx][vecid].push_back(n);
  537.  
  538.     return 1;
  539. }
  540.  
  541.  
  542. /* native vector_size(vecid); */
  543. static cell AMX_NATIVE_CALL n_vector_size( AMX* amx, cell* params )
  544. {
  545.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  546.     cell vecid = params[1];
  547.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  548.     return vectors[amx][vecid].size();
  549. }
  550.  
  551.  
  552. /* native vector_get(vecid, id); */
  553. static cell AMX_NATIVE_CALL n_vector_get( AMX* amx, cell* params )
  554. {
  555.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  556.     cell vecid = params[1];
  557.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  558.     cell id = params[2];
  559.     cell result = -1;
  560.     if (vectors[amx][vecid][id].type != CSTL_TYPE_CELL)
  561.     {
  562.         return -1;
  563.     }
  564.     try{
  565.         result = vectors[amx][vecid].at(id).entry;
  566.     }
  567.     catch(out_of_range& oor){
  568.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  569.     }
  570.  
  571.     return result;
  572. }
  573. /* native Float:vector_get_float(vecid, id); */
  574. static cell AMX_NATIVE_CALL n_vector_get_float( AMX* amx, cell* params )
  575. {
  576.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  577.     cell vecid = params[1];
  578.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  579.     cell id = params[2];
  580.     cell result = -1;
  581.     if (vectors[amx][vecid][id].type != CSTL_TYPE_FLOAT)
  582.     {
  583.         return -1;
  584.     }
  585.     try{
  586.         result = vectors[amx][vecid].at(id).entry;
  587.     }
  588.     catch(out_of_range& oor){
  589.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  590.     }
  591.  
  592.     return result;
  593. }
  594.  
  595. /* native vector_get_arr(vecid, id, buffer[], buflen); */
  596. static cell AMX_NATIVE_CALL n_vector_get_arr( AMX* amx, cell* params )
  597. {
  598.     if (params[0] != 16) { return -1; /* insufficient parameters */ }
  599.     cell vecid = params[1];
  600.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  601.     cell id = params[2];
  602.     if (vectors[amx][vecid][id].type != CSTL_TYPE_PTR)
  603.     {
  604.         return -1;
  605.     }
  606.  
  607.     char* result = NULL;
  608.     try{
  609.         result = (char*)vectors[amx][vecid].at(id).strentry.c_str();
  610.     }
  611.     catch(out_of_range& oor){
  612.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  613.     }
  614.  
  615.     cell *dest;
  616.     amx_GetAddr(amx,params[3],&dest);
  617.     amx_SetString(dest,(const char*)(result),0,0,params[4] + 1);
  618.     return strlen((const char*)result) + 1;
  619. }
  620.  
  621.  
  622. /* native vector_set(vecid, id, element); */
  623. static cell AMX_NATIVE_CALL n_vector_set( AMX* amx, cell* params )
  624. {
  625.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  626.     cell vecid = params[1];
  627.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  628.     cell id = params[2];
  629.     cell element = params[3];
  630.  
  631.     try{
  632.         entry n;
  633.         n.entry = element;
  634.         n.type = CSTL_TYPE_CELL;
  635.         vectors[amx][vecid].at(id) = n;
  636.     }
  637.     catch(out_of_range& oor){
  638.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  639.     }
  640.     return 1;
  641. }
  642. /* native vector_set_float(vecid, id, element); */
  643. static cell AMX_NATIVE_CALL n_vector_set_float( AMX* amx, cell* params )
  644. {
  645.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  646.     cell vecid = params[1];
  647.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  648.     cell id = params[2];
  649.     cell element = params[3];
  650.  
  651.     try{
  652.         entry n;
  653.         n.entry = element;
  654.         n.type = CSTL_TYPE_FLOAT;
  655.         vectors[amx][vecid].at(id) = n;
  656.     }
  657.     catch(out_of_range& oor){
  658.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  659.     }
  660.     return 1;
  661. }
  662.  
  663.  
  664. /* native vector_set_arr(vecid, id, element[]); */
  665. static cell AMX_NATIVE_CALL n_vector_set_arr( AMX* amx, cell* params )
  666. {
  667.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  668.  
  669.     cell vecid = params[1];
  670.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  671.     cell id = params[2];
  672.     char * element;
  673.     amx_StrParam(amx,params[3],element);
  674.  
  675.    
  676.     entry n;
  677.     n.strentry = element;
  678.     n.type = CSTL_TYPE_PTR;
  679.     try {
  680.         vectors[amx][vecid].at(id) = n;
  681.     }
  682.     catch(out_of_range& oor){
  683.         cerr << "Out of Range error: " << oor.what() << endl; return -1;
  684.     }
  685.     return 1;
  686. }
  687.  
  688. /* native vector_clear(vecid); */
  689. static cell AMX_NATIVE_CALL n_vector_clear( AMX* amx, cell* params )
  690. {
  691.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  692.     cell vecid = params[1];
  693.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  694.     vectors[amx][vecid].clear();
  695.     return 1;
  696. }
  697.  
  698.  
  699. /* native vector_resize(vecid, newsize); */
  700. static cell AMX_NATIVE_CALL n_vector_resize( AMX* amx, cell* params )
  701. {
  702.     /*+ attention: realloc with reducing size may cause memory leak ! */
  703.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  704.     cell vecid = params[1];
  705.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  706.     cell newsize = params[2];
  707.     vectors[amx][vecid].resize(newsize);
  708.     return 1;
  709. }
  710.  
  711. /* native vector_find(vecid, element); */
  712. static cell AMX_NATIVE_CALL n_vector_find( AMX* amx, cell* params )
  713. {
  714.     /*+ attention: realloc with reducing size may cause memory leak ! */
  715.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  716.     cell vecid = params[1];
  717.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  718.     cell element = params[2];
  719.     entry n;
  720.     n.type = CSTL_TYPE_CELL;
  721.     n.entry = element;
  722.     vector<entry>::iterator it =  find(vectors[amx][vecid].begin(), vectors[amx][vecid].end(), n);
  723.     if (it == vectors[amx][vecid].end())
  724.     {
  725.         return -1;
  726.     } else {
  727.         return distance(vectors[amx][vecid].begin(),it);
  728.     }
  729. }
  730. /* native vector_find_float(vecid, Float:element); */
  731. static cell AMX_NATIVE_CALL n_vector_find_float( AMX* amx, cell* params )
  732. {
  733.     /*+ attention: realloc with reducing size may cause memory leak ! */
  734.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  735.     cell vecid = params[1];
  736.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  737.     cell element = params[2];
  738.     entry n;
  739.     n.type = CSTL_TYPE_FLOAT;
  740.     n.entry = element;
  741.     vector<entry>::iterator it =  find(vectors[amx][vecid].begin(), vectors[amx][vecid].end(), n);
  742.     if (it == vectors[amx][vecid].end())
  743.     {
  744.         return -1;
  745.     } else {
  746.         return distance(vectors[amx][vecid].begin(),it);
  747.     }
  748. }
  749. /* native vector_find_arr(vecid, element[]); */
  750. static cell AMX_NATIVE_CALL n_vector_find_arr( AMX* amx, cell* params )
  751. {
  752.     /*+ attention: realloc with reducing size may cause memory leak ! */
  753.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  754.     cell vecid = params[1];
  755.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  756.     char * element;
  757.     amx_StrParam(amx,params[2],element);
  758.     entry n;
  759.     n.type = CSTL_TYPE_CELL;
  760.     n.strentry = element;
  761.     n.entry = NULL;
  762.     vector<entry>::iterator it =  find(vectors[amx][vecid].begin(), vectors[amx][vecid].end(), n);
  763.     if (it == vectors[amx][vecid].end())
  764.     {
  765.         return -1;
  766.     } else {
  767.         return distance(vectors[amx][vecid].begin(),it);
  768.     }
  769. }
  770. /* native vector_remove(vecid, id); */
  771. static cell AMX_NATIVE_CALL n_vector_remove( AMX* amx, cell* params )
  772. {
  773.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  774.     cell vecid = params[1];
  775.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  776.     cell element = params[2];
  777.     try {
  778.     vectors[amx][vecid].erase(vectors[amx][vecid].begin() + element);
  779.     } catch(exception) {}
  780.     return 1;
  781. }
  782. /* native vector_entry_type(vecid, id); */
  783. static cell AMX_NATIVE_CALL n_vector_entry_type( AMX* amx, cell* params )
  784. {
  785.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  786.     cell vecid = params[1];
  787.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  788.     cell id = params[2];
  789.     if (vectors[amx][vecid][id].type == 0 || vectors[amx][vecid][id].type == NULL)
  790.     {
  791.         return -1;
  792.     }
  793.     return vectors[amx][vecid][id].type;
  794. }
  795. /* native vector_globalize(vecid); */
  796. static cell AMX_NATIVE_CALL n_vector_globalize( AMX* amx, cell* params )
  797. {
  798.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  799.     cell vecid = params[1];
  800.     if (isVectorGlobalized[vecid] != NULL) {
  801.         /* already global, return FALSE*/
  802.         return -1;
  803.     }
  804.  
  805.     isVectorGlobalized[vecid] = amx;
  806.     return 1;
  807. }
  808. /* native vector_deglobalize(vecid); */
  809. static cell AMX_NATIVE_CALL n_vector_deglobalize( AMX* amx, cell* params )
  810. {
  811.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  812.     cell vecid = params[1];
  813.     if (isVectorGlobalized[vecid] == NULL) {
  814.         /* already local, return FALSE*/
  815.         return -1;
  816.     }
  817.     /* copy vector into local and remove original */
  818.     vector<entry> _new(vectors[isVectorGlobalized[vecid]][vecid]);
  819.     vectors[amx][vecid] = _new;
  820.     isVectorGlobalized[vecid] = NULL;
  821.     return 1;
  822. }
  823. /* native vector_is_globalized(vecid); */
  824. static cell AMX_NATIVE_CALL n_vector_is_globalized( AMX* amx, cell* params )
  825. {
  826.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  827.     cell vecid = params[1];
  828.     if (isVectorGlobalized[vecid] == NULL) {
  829.    
  830.         return -1;
  831.     }
  832.     return 1;
  833. }
  834. /* native vector_index_exists(vecid, index); */
  835. static cell AMX_NATIVE_CALL n_vector_index_exists( AMX* amx, cell* params )
  836. {
  837.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  838.     cell vecid = params[1];
  839.     if (isVectorGlobalized[vecid] != NULL) { amx = isVectorGlobalized[vecid]; } /* get AMX address if global */
  840.     cell element = params[2];
  841.     try {
  842.     vectors[amx][vecid].at(element).entry;
  843.     } catch(out_of_range& oor) { cerr << "Out of Range error: " << oor.what() << endl; return -1; }
  844.     return 1;
  845. }
  846. // MAP
  847. /* native map_insert(mapid, key[], value); */
  848. static cell AMX_NATIVE_CALL n_map_insert( AMX* amx, cell* params )
  849. {
  850.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  851.     cell mapid = params[1];
  852.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  853.     char * key = NULL;
  854.     amx_StrParam(amx,params[2],key);
  855.     cell element = params[3];
  856.     entry n;
  857.     n.entry = element;
  858.     n.type = CSTL_TYPE_CELL;
  859.  
  860.     if(key == NULL) return -1;
  861.     maps[amx][mapid][key] = n;
  862.     return 1;
  863. }
  864.  
  865. /* native map_insert_float(mapid, key[], Float:value); */
  866. static cell AMX_NATIVE_CALL n_map_insert_float( AMX* amx, cell* params )
  867. {
  868.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  869.     cell mapid = params[1];
  870.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  871.     char * key = NULL;
  872.     amx_StrParam(amx,params[2],key);
  873.     cell element = params[3];
  874.     entry n;
  875.     n.entry = element;
  876.     n.type = CSTL_TYPE_FLOAT;
  877.  
  878.     if(key == NULL) return -1;
  879.     maps[amx][mapid][key] = n;
  880.     return 1;
  881. }
  882. /* native map_insert_arr(mapid, key[], value[]); */
  883. static cell AMX_NATIVE_CALL n_map_insert_arr( AMX* amx, cell* params )
  884. {
  885.     if (params[0] != 12) { return -1; /* insufficient parameters */ }
  886.     cell mapid = params[1];
  887.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  888.     char * key = NULL;
  889.     amx_StrParam(amx,params[2],key);
  890.     char * element;
  891.     amx_StrParam(amx,params[3],element);
  892.     entry n;
  893.     n.strentry = element;
  894.     n.type = CSTL_TYPE_PTR;
  895.  
  896.     if(key == NULL) return -1;
  897.     maps[amx][mapid][key] = n;
  898.     return 1;
  899. }
  900. /* native map_get(mapid, key[]); */
  901. static cell AMX_NATIVE_CALL n_map_get( AMX* amx, cell* params )
  902. {
  903.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  904.     cell mapid = params[1];
  905.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  906.     char * key = NULL;
  907.     amx_StrParam(amx,params[2],key);
  908.     if(key == NULL) return -1;
  909.     if (maps[amx][mapid].find(key) == maps[amx][mapid].end() || maps[amx][mapid][key].type != CSTL_TYPE_CELL) { return -1; }
  910.     return maps[amx][mapid][key].entry;
  911. }
  912. /* native Float:map_get_float(mapid, key[]); */
  913. static cell AMX_NATIVE_CALL n_map_get_float( AMX* amx, cell* params )
  914. {
  915.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  916.     cell mapid = params[1];
  917.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  918.     char * key = NULL;
  919.     amx_StrParam(amx,params[2],key);
  920.     if(key == NULL) return -1;
  921.     if (maps[amx][mapid].find(key) == maps[amx][mapid].end() || maps[amx][mapid][key].type != CSTL_TYPE_FLOAT) { return -1; }
  922.     return maps[amx][mapid][key].entry;
  923. }
  924. /* native map_get_arr(mapid, key[], buffer[], buflen); */
  925. static cell AMX_NATIVE_CALL n_map_get_arr( AMX* amx, cell* params )
  926. {
  927.     if (params[0] != 16) { return -1; /* insufficient parameters */ }
  928.     cell mapid = params[1];
  929.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  930.     char * key = NULL;
  931.     amx_StrParam(amx,params[2],key);
  932.     if(key == NULL) return -1;
  933.     if (maps[amx][mapid].find(key) == maps[amx][mapid].end() || maps[amx][mapid][key].type != CSTL_TYPE_PTR) { return -1; }
  934.     const char* result = maps[amx][mapid][key].strentry.c_str();
  935.  
  936.     cell *dest;
  937.     amx_GetAddr(amx,params[3],&dest);
  938.     amx_SetString(dest,(const char*)(result),0,0,params[4] + 1);
  939.     return strlen((const char*)result) + 1;
  940. }
  941. /* native map_size(mapid); */
  942. static cell AMX_NATIVE_CALL n_map_size( AMX* amx, cell* params )
  943. {
  944.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  945.     cell mapid = params[1];
  946.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  947.     return maps[amx][mapid].size();
  948. }
  949. /* native map_remove(mapid, key[]); */
  950. static cell AMX_NATIVE_CALL n_map_remove( AMX* amx, cell* params )
  951. {
  952.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  953.     cell mapid = params[1];
  954.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  955.     char * key = NULL;
  956.     amx_StrParam(amx,params[2],key);
  957.     if(key == NULL) return -1;
  958.     if(maps[amx][mapid].find(key) == maps[amx][mapid].end()) return -1;
  959.     maps[amx][mapid].erase(key);
  960.     return 1;
  961. }
  962. /* native map_contains(mapid, key[]); */
  963. static cell AMX_NATIVE_CALL n_map_contains( AMX* amx, cell* params )
  964. {
  965.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  966.     cell mapid = params[1];
  967.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  968.     char * key = NULL;
  969.     amx_StrParam(amx,params[2],key);
  970.     if(key == NULL) return -1;
  971.     if (maps[amx][mapid].find(key) == maps[amx][mapid].end()) { return 0; }
  972.     return 1;
  973. }
  974. /* native map_entry_type(mapid, key[]); */
  975. static cell AMX_NATIVE_CALL n_map_entry_type( AMX* amx, cell* params )
  976. {
  977.     if (params[0] != 8) { return -1; /* insufficient parameters */ }
  978.     cell mapid = params[1];
  979.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  980.     char * key = NULL;
  981.     amx_StrParam(amx,params[2],key);
  982.     if(key == NULL) return -1;
  983.     if (maps[amx][mapid][key].type == 0 || maps[amx][mapid][key].type == NULL)
  984.     {
  985.         return -1;
  986.     }
  987.     return maps[amx][mapid][key].type;
  988. }
  989. /* native map_clear(mapid); */
  990. static cell AMX_NATIVE_CALL n_map_clear( AMX* amx, cell* params )
  991. {
  992.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  993.     cell mapid = params[1];
  994.     if (isMapGlobalized[mapid] != NULL) { amx = isMapGlobalized[mapid]; } /* get AMX address if global */
  995.     maps[amx][mapid].clear();
  996.     return 1;
  997. }
  998. /* native map_globalize(vecid); */
  999. static cell AMX_NATIVE_CALL n_map_globalize( AMX* amx, cell* params )
  1000. {
  1001.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  1002.     cell mapid = params[1];
  1003.     if (isMapGlobalized[mapid] != NULL) {
  1004.         /* already global, return FALSE*/
  1005.         return -1;
  1006.     }
  1007.  
  1008.     isMapGlobalized[mapid] = amx;
  1009.     return 1;
  1010. }
  1011. /* native map_deglobalize(vecid); */
  1012. static cell AMX_NATIVE_CALL n_map_deglobalize( AMX* amx, cell* params )
  1013. {
  1014.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  1015.     cell mapid = params[1];
  1016.     if (isMapGlobalized[mapid] == NULL) {
  1017.         /* already local, return FALSE*/
  1018.         return -1;
  1019.     }
  1020.     /* copy vector into local and remove original */
  1021.     map<string, entry> _new(maps[isMapGlobalized[mapid]][mapid]);
  1022.     maps[amx][mapid] = _new;
  1023.     isMapGlobalized[mapid] = NULL;
  1024.     return 1;
  1025. }
  1026. /* native map_is_globalized(vecid); */
  1027. static cell AMX_NATIVE_CALL n_map_is_globalized( AMX* amx, cell* params )
  1028. {
  1029.     if (params[0] != 4) { return -1; /* insufficient parameters */ }
  1030.     cell mapid = params[1];
  1031.     if (isMapGlobalized[mapid] == NULL) {
  1032.    
  1033.         return -1;
  1034.     }
  1035.     return 1;
  1036. }
  1037.  
  1038. AMX_NATIVE_INFO hashAMXNatives[ ] =
  1039. {
  1040.     /* deque */
  1041.     {"deque_push_back", n_deque_push_back},
  1042.     {"deque_push_back_float", n_deque_push_back_float},
  1043.     {"deque_push_back_arr", n_deque_push_back_arr},
  1044.     {"deque_push_front", n_deque_push_front},
  1045.     {"deque_push_front_float", n_deque_push_front_float},
  1046.     {"deque_push_front_arr", n_deque_push_front_arr},
  1047.     {"deque_swap", n_deque_swap},
  1048.     {"deque_size", n_deque_size},
  1049.     {"deque_get", n_deque_get},
  1050.     {"deque_get_float", n_deque_get_float},
  1051.     {"deque_get_arr", n_deque_get_arr},
  1052.     {"deque_set", n_deque_set},
  1053.     {"deque_set_float", n_deque_set_float},
  1054.     {"deque_set_arr", n_deque_set_arr},
  1055.     {"deque_clear", n_deque_clear},
  1056.     {"deque_resize", n_deque_resize},
  1057.     {"deque_entry_type", n_deque_entry_type},
  1058.     {"deque_find",n_deque_find},
  1059.     {"deque_find_float",n_deque_find_float},
  1060.     {"deque_find_arr",n_deque_find_arr},
  1061.     {"deque_remove",n_deque_remove},
  1062.     {"deque_globalize", n_deque_globalize},
  1063.     {"deque_deglobalize", n_deque_deglobalize},
  1064.     {"deque_is_globalized", n_deque_is_globalized},
  1065.     {"deque_index_exists", n_deque_index_exists},
  1066.     /* vector */
  1067.     {"vector_push_back", n_vector_push_back},
  1068.     {"vector_push_back_float", n_vector_push_back_float},
  1069.     {"vector_push_back_arr", n_vector_push_back_arr},
  1070.     {"vector_size", n_vector_size},
  1071.     {"vector_get", n_vector_get},
  1072.     {"vector_get_float", n_vector_get_float},
  1073.     {"vector_get_arr", n_vector_get_arr},
  1074.     {"vector_set", n_vector_set},
  1075.     {"vector_set_float", n_vector_set_float},
  1076.     {"vector_set_arr", n_vector_set_arr},
  1077.     {"vector_clear", n_vector_clear},
  1078.     {"vector_resize", n_vector_resize},
  1079.     {"vector_entry_type", n_vector_entry_type},
  1080.     {"vector_find",n_vector_find},
  1081.     {"vector_find_float",n_vector_find_float},
  1082.     {"vector_find_arr",n_vector_find_arr},
  1083.     {"vector_remove",n_vector_remove},
  1084.     {"vector_globalize", n_vector_globalize},
  1085.     {"vector_deglobalize", n_vector_deglobalize},
  1086.     {"vector_is_globalized", n_vector_is_globalized},
  1087.     {"vector_index_exists", n_vector_index_exists},
  1088.     /* map */
  1089.     {"map_insert", n_map_insert},
  1090.     {"map_insert_float", n_map_insert_float},
  1091.     {"map_insert_arr", n_map_insert_arr},
  1092.     {"map_get", n_map_get},
  1093.     {"map_get_float", n_map_get_float},
  1094.     {"map_get_arr", n_map_get_arr},
  1095.     {"map_size", n_map_size},
  1096.     {"map_remove",n_map_remove},
  1097.     {"map_contains",n_map_contains},
  1098.     {"map_entry_type",n_map_entry_type},
  1099.     {"map_clear",n_map_clear},
  1100.     {"map_globalize", n_map_globalize},
  1101.     {"map_deglobalize", n_map_deglobalize},
  1102.     {"map_is_globalized", n_map_is_globalized},
  1103.     {0,                0}
  1104. };
  1105.  
  1106. PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx )
  1107. {
  1108.     return amx_Register( amx, hashAMXNatives, -1 );
  1109. }
  1110.  
  1111. PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
  1112. {
  1113.     for (map<cell, vector<entry> >::iterator it = vectors[amx].begin() ; it != vectors[amx].end() ; it++)
  1114.     {
  1115.         (*it).second.clear();
  1116.     }
  1117.     vectors[amx].clear();
  1118.     for (map<cell, map<string, entry> >::iterator it = maps[amx].begin() ; it != maps[amx].end() ; it++)
  1119.     {
  1120.         (*it).second.clear();
  1121.     }
  1122.     maps[amx].clear();
  1123.  
  1124.     return AMX_ERR_NONE;
  1125. }
Advertisement
Add Comment
Please, Sign In to add comment