• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kget

bnode.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Joris Guisson                                   *
00003  *   joris.guisson@gmail.com                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
00019  ***************************************************************************/
00020 #include "bnode.h"
00021 #include <util/log.h>
00022 
00023 namespace bt
00024 {
00025 
00026     BNode::BNode(Type type,Uint32 off) : type(type),off(off),len(0)
00027     {
00028     }
00029 
00030 
00031     BNode::~BNode()
00032     {}
00033 
00035 
00036     BValueNode::BValueNode(const Value & v,Uint32 off) : BNode(VALUE,off),v(v)
00037     {}
00038     
00039     BValueNode::~BValueNode()
00040     {}
00041     
00042     void BValueNode::printDebugInfo()
00043     {
00044         if (v.getType() == Value::INT)
00045             Out(SYS_GEN|LOG_DEBUG) << "Value = " << v.toInt() << endl;
00046         else
00047             Out(SYS_GEN|LOG_DEBUG) << "Value = " << v.toString() << endl;
00048     }
00049     
00051 
00052     BDictNode::BDictNode(Uint32 off) : BNode(DICT,off)
00053     {
00054     }
00055     
00056     BDictNode::~BDictNode()
00057     {
00058         QList<DictEntry>::iterator i = children.begin();
00059         while (i != children.end())
00060         {
00061             DictEntry & e = *i;
00062             delete e.node;
00063             i++;
00064         }
00065     }
00066     
00067     void BDictNode::insert(const QByteArray & key,BNode* node)
00068     {
00069         DictEntry entry;
00070         entry.key = key;
00071         entry.node = node;
00072         children.append(entry);
00073     }
00074     
00075     BNode* BDictNode::getData(const QString & key)
00076     {
00077         QList<DictEntry>::iterator i = children.begin();
00078         while (i != children.end())
00079         {
00080             DictEntry & e = *i;
00081             if (QString(e.key) == key)
00082                 return e.node;
00083             i++;
00084         }
00085         return 0;
00086     }
00087     
00088     BDictNode* BDictNode::getDict(const QByteArray & key)
00089     {
00090         QList<DictEntry>::iterator i = children.begin();
00091         while (i != children.end())
00092         {
00093             DictEntry & e = *i;
00094             if (e.key == key)
00095                 return dynamic_cast<BDictNode*>(e.node);
00096             i++;
00097         }
00098         return 0;
00099     }
00100 
00101     BListNode* BDictNode::getList(const QString & key)
00102     {
00103         BNode* n = getData(key);
00104         return dynamic_cast<BListNode*>(n);
00105     }
00106     
00107     BDictNode* BDictNode::getDict(const QString & key)
00108     {
00109         BNode* n = getData(key);
00110         return dynamic_cast<BDictNode*>(n);
00111     }
00112     
00113     BValueNode* BDictNode::getValue(const QString & key)
00114     {
00115         BNode* n = getData(key);
00116         return dynamic_cast<BValueNode*>(n);
00117     }
00118     
00119     void BDictNode::printDebugInfo()
00120     {
00121         Out(SYS_GEN|LOG_DEBUG) << "DICT" << endl;
00122         QList<DictEntry>::iterator i = children.begin();
00123         while (i != children.end())
00124         {
00125             DictEntry & e = *i;
00126             Out(SYS_GEN|LOG_DEBUG) << QString(e.key) << ": " << endl;
00127             e.node->printDebugInfo();
00128             i++;
00129         }
00130         Out(SYS_GEN|LOG_DEBUG) << "END" << endl;
00131     }
00132     
00134 
00135     BListNode::BListNode(Uint32 off) : BNode(LIST,off)
00136     {
00137     }
00138     
00139     
00140     BListNode::~BListNode()
00141     {
00142         for (int i = 0;i < children.count();i++)
00143         {
00144             BNode* n = children.at(i);
00145             delete n;
00146         }
00147     }
00148     
00149     
00150     void BListNode::append(BNode* node)
00151     {
00152         children.append(node);
00153     }
00154 
00155     BListNode* BListNode::getList(Uint32 idx)
00156     {
00157         return dynamic_cast<BListNode*>(getChild(idx));
00158     }
00159 
00160     BDictNode* BListNode::getDict(Uint32 idx)
00161     {
00162         return dynamic_cast<BDictNode*>(getChild(idx));
00163     }
00164 
00165     BValueNode* BListNode::getValue(Uint32 idx)
00166     {
00167         return dynamic_cast<BValueNode*>(getChild(idx));
00168     }
00169     
00170     void BListNode::printDebugInfo()
00171     {
00172         Out(SYS_GEN|LOG_DEBUG) << "LIST " <<  children.count() << endl;
00173         for (int i = 0;i < children.count();i++)
00174         {
00175             BNode* n = children.at(i);
00176             n->printDebugInfo();
00177         }
00178         Out(SYS_GEN|LOG_DEBUG) << "END" << endl;
00179     }
00180 }
00181 

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal