string_setting.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "string_setting.h"
  6. #include "string_utils.h"
  7. namespace crown
  8. {
  9. static StringSetting* g_string_settings_head = NULL;
  10. StringSetting::StringSetting(const char* name, const char* synopsis, const char* value)
  11. : _name(name)
  12. , _synopsis(synopsis)
  13. , _value(value)
  14. , _next(NULL)
  15. {
  16. *this = value;
  17. if (g_string_settings_head != NULL)
  18. {
  19. _next = g_string_settings_head;
  20. }
  21. g_string_settings_head = this;
  22. }
  23. const char* StringSetting::name() const
  24. {
  25. return _name;
  26. }
  27. const char* StringSetting::synopsis() const
  28. {
  29. return _synopsis;
  30. }
  31. const char* StringSetting::value() const
  32. {
  33. return _value;
  34. }
  35. StringSetting& StringSetting::operator=(const char* value)
  36. {
  37. _value = value;
  38. return *this;
  39. }
  40. StringSetting* StringSetting::find_setting(const char* name)
  41. {
  42. StringSetting* head = g_string_settings_head;
  43. while (head != NULL)
  44. {
  45. if (strcmp(name, head->name()) == 0)
  46. {
  47. return head;
  48. }
  49. head = head->_next;
  50. }
  51. return NULL;
  52. }
  53. } // namespace crown