keyobservers.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright (C) 2001-2006, William Joseph.
  3. All Rights Reserved.
  4. This file is part of GtkRadiant.
  5. GtkRadiant 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 2 of the License, or
  8. (at your option) any later version.
  9. GtkRadiant 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 GtkRadiant; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #if !defined(INCLUDED_KEYOBSERVERS_H)
  18. #define INCLUDED_KEYOBSERVERS_H
  19. #include "entitylib.h"
  20. #include <map>
  21. class KeyObserverMap : public EntityKeyValues::Observer
  22. {
  23. typedef std::multimap<const char*, KeyObserver, RawStringLess> KeyObservers;
  24. KeyObservers m_keyObservers;
  25. public:
  26. void insert(const char* key, const KeyObserver& observer)
  27. {
  28. m_keyObservers.insert(KeyObservers::value_type(key, observer));
  29. }
  30. void insert(const char* key, EntityKeyValues::Value& value)
  31. {
  32. for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i)
  33. {
  34. value.attach((*i).second);
  35. }
  36. }
  37. void erase(const char* key, EntityKeyValues::Value& value)
  38. {
  39. for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i)
  40. {
  41. value.detach((*i).second);
  42. }
  43. }
  44. };
  45. #endif