filters

command.cc

00001 /* This file is part of the KDE project
00002  * Copyright (C) 2003 Robert JACOLIN <rjacolin@ifrance.com>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "command.h"
00021 #include <iostream.h>
00022 #include "kdebug.h"
00023 
00024 Command::Command()
00025 {
00026     setType(Element::LATEX_COMMAND);
00027     _options.setAutoDelete(true);
00028     _params.setAutoDelete(true);
00029 }
00030 
00031 Command::Command(const char* name)
00032 {
00033     setType(Element::LATEX_COMMAND);
00034     _options.setAutoDelete(true);
00035     _params.setAutoDelete(true);
00036     _name = name;
00037     _name = _name.stripWhiteSpace();
00038 }
00039 
00040 Command::Command(const char* name, QPtrList<QPtrList<Element> >* groups)
00041 {
00042     setType(Element::LATEX_COMMAND);
00043     _options.setAutoDelete(true);
00044     _params.setAutoDelete(true);
00045     _name = name;
00046     if(groups != NULL)
00047         _elements = *groups;
00048     _name = _name.stripWhiteSpace();
00049 }
00050 
00051 Command::Command(const char* name, QPtrList<QPtrList<Param> >* params,
00052         QPtrList<QPtrList<Element> >* groups)
00053 {
00054     setType(Element::LATEX_COMMAND);
00055     _options.setAutoDelete(true);
00056     _params.setAutoDelete(true);
00057     _name = name;
00058     if(groups != NULL)
00059         _elements = *groups;
00060     if(params != NULL)
00061         _params = *params;
00062     _name = _name.stripWhiteSpace();
00063 }
00064 
00065 Command::Command(const char* name, QPtrList<QPtrList<Param> >* params, QPtrList<Param>* options,
00066         QPtrList<QPtrList<Element> >* groups)
00067 {
00068     setType(Element::LATEX_COMMAND);
00069     _options.setAutoDelete(true);
00070     _params.setAutoDelete(true);
00071     _name = name;
00072     if(groups != NULL)
00073         _elements = *groups;
00074     if(params != NULL)
00075         _params = *params;
00076     if(options != NULL)
00077         _options = *options;
00078     _name = name;
00079     _name = _name.stripWhiteSpace();
00080 }
00081 
00082 Command::~Command()
00083 {
00084 }
00085 
00086 void Command::addParam(const char* )
00087 {
00088     /*QString test = QString(name);
00089     QString key = test.left(test.find("="));
00090     QString value = test.right(test.find("="));
00091     addParam(key, value);*/
00092 }
00093 
00094 void Command::addOption(const char* )
00095 {
00096     /*QString test = QString(name);
00097     QString key = test.left(test.find("="));
00098     QString value = test.right(test.find("="));
00099     addOption(key, value);*/
00100 }
00101 
00102 void Command::print(int tab)
00103 {
00104     cout << _name.latin1();
00105     QPtrList<Param>* params;
00106     for ( params = _params.first(); params; params = _params.next() )
00107     {
00108         cout << "[";
00109         Param* param;
00110         for ( param = params->first(); param; param = params->next() )
00111         {
00112             param->print(tab);
00113             if(param != params->getLast())
00114                 cout << ", ";
00115         }
00116         cout << "]";
00117     }
00118     if(_options.count() > 0)
00119     {
00120         cout << " - [";
00121         Param* param;
00122         for ( param = _options.first(); param; param = _options.next() )
00123         {
00124             param->print(tab);
00125             if(param != _options.getLast())
00126             cout << ", ";
00127         }
00128         cout << "]";
00129     }
00130     
00131     QPtrList<Element>* group;
00132     for(group = _elements.first(); group; group = _elements.next() )
00133     {
00134         cout << " {";
00135         Element* elt;
00136         for ( elt = group->first(); elt; elt = group->next() )
00137         {
00138             elt->print(tab);
00139         }
00140         cout << "}";
00141     }
00142     cout << endl;
00143 }
KDE Home | KDE Accessibility Home | Description of Access Keys