00001 #ifndef ITEM_CLASS_HH_ 00002 # define ITEM_CLASS_HH_ 00003 00004 # include <map> 00005 # include <iostream> 00006 00007 # include "objects_fwd.hh" 00008 00009 # define UNKNOWN_ITEM_CLASS (-1) 00010 00011 namespace objects 00012 { 00013 class ItemClassFactory 00014 { 00015 public: 00016 ItemClassFactory(); 00017 ~ItemClassFactory(); 00018 00019 static ItemClassFactory &get_instance(); 00020 const ItemClass &get(int id); 00021 00022 protected: 00023 std::map<int, ItemClass *> _item_class_map; 00024 00025 void register_item(ItemClass &i); 00026 }; 00027 00028 class ItemClass 00029 { 00030 public: 00031 ItemClass(); 00032 00033 static const ItemClass &get(int id); 00034 virtual void accept(ItemVisitor &iv) = 0; 00035 virtual void print(std::ostream &os) = 0; 00036 00037 virtual int get_id() const = 0; 00038 virtual const std::string &get_name() = 0; 00039 }; 00040 00041 template<int ITEM_CLASS_ID> 00042 class DefItemClass : public ItemClass 00043 { 00044 public: 00045 DefItemClass(); 00046 00047 static const int id = ITEM_CLASS_ID; 00048 00049 void accept(ItemVisitor &iv); 00050 int get_id() const; 00051 const std::string &get_name(); 00052 void print(std::ostream &os); 00053 }; 00054 00055 std::ostream &operator <<(std::ostream &os, const ItemClass &ic); 00056 } 00057 00058 # include "item_class.hxx" 00059 00060 #endif