Crossfire Server, Trunk  1.75.0
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 "global.h"
19 
23 class WrapperLoader : public AssetLoader {
24 public:
26  typedef std::function<void(BufferReader *, const char *)> wrapped;
27 
33  WrapperLoader(const std::string& name, wrapped fct) : m_name(name), m_function(fct) {
34  };
35 
36  virtual bool willLoad(const std::string &filename) override {
37  return Utils::endsWith(filename.c_str(), m_name.c_str());
38  }
39 
40  virtual void load(BufferReader *reader, const std::string &filename) override {
41  m_function(reader, filename.c_str());
42  }
43 
44 private:
45  std::string m_name;
47 };
48 
49 #endif /* WRAPPERLOADER_H */
50 
global.h
AssetLoader
Abstract buffer handler, processing a BufferReader.
Definition: AssetLoader.h:24
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
WrapperLoader::m_function
wrapped m_function
Function to call.
Definition: WrapperLoader.h:46
Utils.h
WrapperLoader::wrapped
std::function< void(BufferReader *, const char *)> wrapped
Wrapper to the function to call for each file.
Definition: WrapperLoader.h:26
WrapperLoader::WrapperLoader
WrapperLoader(const std::string &name, wrapped fct)
Standard construction.
Definition: WrapperLoader.h:33
WrapperLoader::load
virtual void load(BufferReader *reader, const std::string &filename) override
Load assets from the specified reader.
Definition: WrapperLoader.h:40
WrapperLoader::m_name
std::string m_name
File name.
Definition: WrapperLoader.h:45
WrapperLoader::willLoad
virtual bool willLoad(const std::string &filename) override
Whether this instance will process or not the specified file.
Definition: WrapperLoader.h:36
WrapperLoader
Loader calling a function for files ending with a specific string.
Definition: WrapperLoader.h:23
BufferReader
Definition: bufferreader.cpp:21
Utils::endsWith
static bool endsWith(const char *const str, const char *const with)
Checks if a string ends with another one.
Definition: Utils.cpp:16
AssetLoader.h