Main Page   Class Hierarchy   Compound List   File List   Compound Members  

mclass.cc

00001 /***************************************************************************
00002  *   This file is part of the MagiC++ library.                             *
00003  *                                                                         *
00004  *   Copyright (C) 1998-2001 Marko Grönroos <magi@iki.fi>                  *
00005  *                                                                         *
00006  ***************************************************************************
00007  *                                                                         *
00008  *  This library is free software; you can redistribute it and/or          *
00009  *  modify it under the terms of the GNU Library General Public            *
00010  *  License as published by the Free Software Foundation; either           *
00011  *  version 2 of the License, or (at your option) any later version.       *
00012  *                                                                         *
00013  *  This library is distributed in the hope that it will be useful,        *
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
00016  *  Library General Public License for more details.                       *
00017  *                                                                         *
00018  *  You should have received a copy of the GNU Library General Public      *
00019  *  License along with this library; see the file COPYING.LIB.  If         *
00020  *  not, write to the Free Software Foundation, Inc., 59 Temple Place      *
00021  *  - Suite 330, Boston, MA 02111-1307, USA.                               *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 #include "magic/mclass.h"
00026 #include "magic/mmap.h"
00027 
00029 
00030 //decl_dynamic (Class)
00031 
00032 Class*  appclass = NULL;
00033 Class*  taskclass = NULL;
00034 
00035 //Class::Class (const char* nam, const char* bases, Object& (Object::*getinst)()){
00036 Class::Class (const char* nam, const char* bases, GetClassInstance* getInstPtr){
00037     #ifdef MODULEDEBUG
00038     TRACE2 ("Class (%s, %s)", nam, bases);
00039     #endif
00040     name = nam;
00041     name.checksum ();
00042     // parents_unfound = new Array<String>;
00043     // parents = new CRefArray<Class>;
00044     //  getinstance = (Object&(Object::*getinst)()) ();
00045     //getinstance = (Object&(Object::*)()) getinst;
00046     mGetInstance = getInstPtr;
00047 
00048     if (bases) {
00049 
00050         // Remove extra characters {""} from ends of the parent class list
00051         String bases_str = bases;
00052         while (bases_str.length()>0 && (bases_str[0]=='{' || bases_str[0]=='"'))
00053             bases_str = bases_str.mid (1);
00054         while (bases_str.length()>0 && (bases_str[bases_str.length()-1]=='}' || bases_str[bases_str.length()-1]=='"'))
00055             bases_str.dellast (1);
00056 
00057         // Go through the list of parent classes
00058         bases_str.split (parents_unfound, ',');
00059         for (int i=0; i<parents_unfound.size; i++) {
00060             if ((parents_unfound[i] == "Application" ||
00061                  parents_unfound[i] == "HTMLQuery") &&
00062                 name != "HTMLQuery") {
00063                 appclass = this;
00064                 // TRACE2 ("Class (%s, %s)", nam, bases);
00065             }
00066             if (parents_unfound[i] == "Task")
00067                 taskclass = this;
00068         }
00069     }
00070 
00071     // printclassinfo ();
00072     
00073     ClassLib::insert (*this);
00074 }
00075 
00076 Class::~Class () {
00077     // delete parents_unfound;
00078     // delete parents;
00079 }
00080 
00081 void Class::printclassinfo (FILE* out) const {
00082     fprintf (out, "class %s",
00083             (CONSTR) name);
00084 
00085     // Tulostetaan vanhemmat
00086     if (parents_unfound.size>0) {
00087         fprintf (out, ": ");
00088         for (int i=0; i<parents_unfound.size; i++) {
00089             fprintf (out, "%s", (CONSTR) parents_unfound[i]);
00090             if (i<parents_unfound.size-1)
00091                 fprintf (out, ",");
00092         }
00093     }
00094     fprintf (out, " {\n");
00095 
00096     // Tulostetaan attribuutit
00097 
00098     // NOT WORKING TEMPORARILY!
00099     //Object* inst = (const_cast<Class*>(this)->getinstance ());
00100     Object* inst=NULL;
00101 
00102     DumpContext ar (out);
00103     ar << *inst;
00104     for (int i=0; i<ar.getattribs().size; i++)
00105         fprintf (out, "\t%s;\n", (CONSTR) ar.getattribs()[i]);
00106     delete inst;
00107     fprintf (out, "};\n");
00108 }
00109 
00111 
00112 // Class* ClassLib::firstclass = NULL;
00113 CMap<String,Class>* ClassLib::classes = NULL;
00114 
00115 void ClassLib::printclassinfo (const String& classname, FILE* out) {
00116     const Class* cls = classes->getp (classname);
00117     if (cls)
00118         cls->printclassinfo (out);
00119 }
00120 
00121 Class* ClassLib::getclass (const String& classname) {
00122     return classes->getvp (classname);
00123 }
00124 
00125 Object& ClassLib::getinstance (const String& classname) {
00126     //TRACE1("%s", (CONSTR) classname);
00127     Class* cls = classes->getvp (classname);
00128     if (cls)
00129         return *cls->getInstance();
00130     TRACE1("%%ERROR: No instance for '%s' found", (CONSTR) classname);
00131     return *(Object*)NULL;
00132 }
00133 
00134 void ClassLib::insert (Class& cls) {
00135     if (!classes)
00136         classes = new CMap<String,Class> (256, MAP_REF);
00137     
00138     classes->set (cls.name, cls);
00139 
00140     // Haetaan luokan vanhemmat
00141     for (int i=0; i<cls.parents_unfound.size; i++)
00142         ;
00143 }

Generated at Tue Dec 4 19:53:24 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001