Logo
~Apps~
~Projects~
~Contact~


BTDictionary.h

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2005  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4