9
3

Variables.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef EQ2_VARIABLES_H
  17. #define EQ2_VARIABLES_H
  18. #include <vector>
  19. #include <string>
  20. class Variable{
  21. public:
  22. Variable (const char* name, const char* value, const char* comment){
  23. variableName = string(name);
  24. variableValue = string(value);
  25. if(comment)
  26. variableComment = string(comment);
  27. }
  28. const char* GetName() { return variableName.c_str(); }
  29. const char* GetValue() { return variableValue.c_str(); }
  30. const char* GetComment() { return variableComment.c_str(); }
  31. string GetNameValuePair(){ return string(variableName).append(" ").append(variableValue); }
  32. void SetValue(const char* value){
  33. if(value)
  34. variableValue = string(value);
  35. }
  36. private:
  37. string variableName;
  38. string variableValue;
  39. string variableComment;
  40. };
  41. class Variables
  42. {
  43. public:
  44. ~Variables(){
  45. ClearVariables();
  46. }
  47. void AddVariable ( Variable* var )
  48. {
  49. variables[string(var->GetName())] = var;
  50. }
  51. void ClearVariables()
  52. {
  53. if(variables.size() == 0)
  54. return;
  55. map<string,Variable*>::iterator map_list;
  56. for( map_list = variables.begin(); map_list != variables.end(); map_list++ ) {
  57. safe_delete(map_list->second);
  58. }
  59. variables.clear();
  60. }
  61. Variable* FindVariable ( string name )
  62. {
  63. if(variables.count(name) > 0)
  64. return variables[name];
  65. return 0;
  66. }
  67. vector<Variable*>* GetVariables(string partial_name){
  68. vector<Variable*>* ret = new vector<Variable*>();
  69. map<string,Variable*>::iterator itr;
  70. for(itr = variables.begin(); itr != variables.end(); itr++){
  71. if(itr->first.find(partial_name) < 0xFFFFFFFF)
  72. ret->push_back(itr->second);
  73. }
  74. return ret;
  75. }
  76. private:
  77. map<string,Variable*> variables;
  78. };
  79. #endif