Advertisement
Guest User

Untitled

a guest
Aug 11th, 2015
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <unordered_map>
  5. #include <functional>
  6.  
  7. struct PrefixObject;
  8.  
  9. struct Asset {
  10.     enum Type : int {
  11.         TEXTURE, DERP, BURP, FURP, NONE
  12.     };
  13. };
  14.  
  15. std::unordered_map<Asset::Type, std::vector<std::string>, std::hash<int>> global_pref;
  16. std::unordered_map<Asset::Type, std::vector<std::string>, std::hash<int>> global_post;
  17.  
  18. struct PrefixObject {
  19.     std::vector<std::string> pref;
  20.    
  21.     PrefixObject operator | (const PrefixObject& other) {
  22.         PrefixObject o;
  23.         for (std::string& s : pref)
  24.             o.pref.push_back(s);
  25.         for (const std::string& s : other.pref)
  26.             o.pref.push_back(s);
  27.         return o;
  28.     }
  29.  
  30.     Asset::Type operator >> (const Asset::Type& other) {
  31.         for (std::string& s : pref)
  32.             global_pref[other].push_back(s);
  33.         return other;
  34.     }
  35. };
  36.  
  37. Asset::Type operator << (const Asset::Type& t, const PrefixObject& other) {
  38.     for (const std::string& s : other.pref)
  39.             global_post[t].push_back(s);
  40.     return t;
  41. }
  42.  
  43. PrefixObject operator "" _p(const char* s, unsigned int size) {
  44.     return {{std::string(s)}};
  45. }
  46.  
  47. int main() {
  48.     ("images/"_p | "textures/"_p) >> Asset::TEXTURE << (".png"_p | ".jpg"_p | ".dds"_p | ".bmp"_p);
  49.    
  50.     for (std::string& d : global_pref[Asset::TEXTURE])
  51.         std::cout << d << std::endl;
  52.     std::cout << "--------------------" << std::endl;
  53.     for (std::string& d : global_post[Asset::TEXTURE])
  54.         std::cout << d << std::endl;
  55.    
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement