00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _BTDICTIONARY_H
00024 #define _BTDICTIONARY_H
00025
00026 #include "BTObject.h"
00027 #include <map>
00028
00029 typedef std::map<std::string,BTObject *> btmap_t;
00030
00031
00033
00034 class BTDictionary : public BTObject
00035 {
00036 public:
00037 BTDictionary(size_t i) : BTObject(i) {}
00038 ~BTDictionary() {
00039 for (btmap_t::iterator it = m_map.begin(); it != m_map.end(); it++)
00040 {
00041 delete (*it).second;
00042 }
00043 }
00044 char Type() { return 'd'; }
00045 void Show() {
00046 bool first = true;
00047 BTObject *p = GetParent();
00048 printf("\n");
00049 printf("Show Dictionary, length %d\n",GetLength());
00050 while (p)
00051 {
00052 printf(" ");
00053 p = p -> GetParent();
00054 }
00055 printf("( ");
00056 for (btmap_t::iterator it = m_map.begin(); it != m_map.end(); it++)
00057 {
00058 if (!first)
00059 printf(", ");
00060 first = false;
00061 printf("%s: ",(*it).first.c_str());
00062 (*it).second -> Show();
00063 }
00064 printf(")");
00065 }
00066 BTObject *Find(const std::string &str) {
00067 for (btmap_t::iterator it = m_map.begin(); it != m_map.end(); it++)
00068 {
00069 if ((*it).first == str)
00070 return (*it).second;
00071 }
00072 return NULL;
00073 }
00074
00075 void AddObject(const std::string &str,BTObject *p) {
00076 m_map[str] = p;
00077 }
00078 btmap_t& GetMap() { return m_map; }
00079
00080 private:
00081 btmap_t m_map;
00082 };
00083
00084
00085 #endif // _BTDICTIONARY_H