Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- #include <map>
- #include <vector>
- using Entity = int;
- namespace Tool
- {
- bool debug = false;
- void setDebug(bool state)
- {
- debug = state;
- }
- template <typename M>
- void log (M msg)
- {
- if (debug)
- std::cout << msg ;
- }
- void ln ()
- {
- if (debug)
- std::cout << std::endl;
- }
- }
- class ContentImage
- {
- public:
- ContentImage(std::string name)
- {
- _name = name;
- _w = 0;
- _h = 0;
- _filename = "noname";
- Tool::log("+++ Image : ");
- Tool::log(_name);
- Tool::ln();
- }
- virtual ~ContentImage()
- {
- Tool::log ("--- Image : ");
- Tool::log(_name);
- Tool::ln();
- }
- void showMe()
- {
- using namespace Tool;
- log("=== ShowMe ===");ln();
- log(" name = ");log(_name);ln();
- log(" filename = ");log(_filename);ln();
- log(" w = ");log(_w);ln();
- log(" h = ");log(_h);ln();
- log("=== ====== ===");
- }
- private:
- std::string _name;
- int _w;
- int _h;
- std::string _filename;
- };
- using PImage = std::shared_ptr<ContentImage>;
- using MapImage = std::map<std::string, std::shared_ptr<ContentImage>>;
- namespace Content
- {
- namespace Image
- {
- MapImage mapAsset;
- void add (std::string name)
- {
- //auto p = std::make_shared<ContentImage>(name);
- std::shared_ptr<ContentImage> p(new ContentImage(name));
- mapAsset.insert(std::make_pair(name, p) );
- }
- void del (std::string name)
- {
- mapAsset.erase(name);
- }
- const std::shared_ptr<ContentImage>& getData(std::string name)
- {
- MapImage::const_iterator it = mapAsset.find(name);
- if (it == mapAsset.end())
- return NULL;
- else
- return it->second;
- }
- void debuglog()
- {
- Tool::log("---- Debug ContentImage ----");
- Tool::ln();
- for (auto & it : mapAsset)
- {
- std::cout << "name = " << it.first << std::endl;
- }
- }
- }
- }
- int main()
- {
- Tool::setDebug(true);
- Content::Image::add("test");
- Content::Image::add("mugen");
- Content::Image::add("silver");
- Content::Image::debuglog();
- Tool::ln();
- Content::Image::del("test");
- Content::Image::debuglog();
- Tool::ln();
- //PImage myImage = Content::Image::getData("test");
- //myImage->showMe();
- Tool::log("Bye !");
- Tool::ln();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement