common.h 696 B

1234567891011121314151617181920212223242526
  1. /*
  2. * common.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. class CBattleCallback;
  12. template<typename Key, typename Val, typename Val2>
  13. const Val getValOr(const std::map<Key, Val> &Map, const Key &key, const Val2 defaultValue)
  14. {
  15. //returning references here won't work: defaultValue must be converted into Val, creating temporary
  16. auto i = Map.find(key);
  17. if(i != Map.end())
  18. return i->second;
  19. else
  20. return defaultValue;
  21. }
  22. void setCbc(std::shared_ptr<CBattleCallback> cb);
  23. std::shared_ptr<CBattleCallback> getCbc();