Crossfire Server, Trunk
WrapperLoader.h
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020-2021 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #ifndef WRAPPERLOADER_H
14 #define WRAPPERLOADER_H
15 
16 #include "AssetLoader.h"
17 #include "Utils.h"
18 #include <functional>
19 #include <string>
20 #include "global.h"
21 
25 class WrapperLoader : public AssetLoader {
26 public:
28  typedef std::function<void(BufferReader *, const char *)> wrapped;
29 
35  WrapperLoader(const std::string& name, wrapped fct) : m_name(name), m_function(fct) {
36  };
37 
38  virtual bool willLoad(const std::string &filename) override {
39  return Utils::endsWith(filename.c_str(), m_name.c_str());
40  }
41 
42  virtual void load(BufferReader *reader, const std::string &filename) override {
43  m_function(reader, filename.c_str());
44  }
45 
46 private:
47  std::string m_name;
49 };
50 
51 #endif /* WRAPPERLOADER_H */
52 
global.h
AssetLoader
Definition: AssetLoader.h:24
npc_dialog.filename
filename
Definition: npc_dialog.py:99
WrapperLoader::m_function
wrapped m_function
Definition: WrapperLoader.h:48
Utils.h
WrapperLoader::wrapped
std::function< void(BufferReader *, const char *)> wrapped
Definition: WrapperLoader.h:28
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
WrapperLoader::WrapperLoader
WrapperLoader(const std::string &name, wrapped fct)
Definition: WrapperLoader.h:35
WrapperLoader::load
virtual void load(BufferReader *reader, const std::string &filename) override
Definition: WrapperLoader.h:42
WrapperLoader::m_name
std::string m_name
Definition: WrapperLoader.h:47
WrapperLoader::willLoad
virtual bool willLoad(const std::string &filename) override
Definition: WrapperLoader.h:38
WrapperLoader
Definition: WrapperLoader.h:25
BufferReader
Definition: bufferreader.cpp:21
Utils::endsWith
static bool endsWith(const char *const str, const char *const with)
Definition: Utils.cpp:16
AssetLoader.h
give.name
name
Definition: give.py:27