umbrello API Documentation

classifierinfo.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright       : (C) 2003 Brian Thomas brian.thomas@gsfc.nasa.gov    *
00009  *   (C) 2004-2006  Umbrello UML Modeller Authors <uml-devel@uml.sf.net>   *
00010  ***************************************************************************/
00011 
00012 
00013 #include "classifierinfo.h"
00014 
00015 #include "../classifier.h"
00016 #include "../operation.h"
00017 
00018 ClassifierInfo::ClassifierInfo( UMLClassifier *classifier , UMLDoc */*doc*/)
00019 {
00020 
00021     init(classifier);
00022 }
00023 
00024 ClassifierInfo::~ClassifierInfo() { }
00025 
00026 void ClassifierInfo::init(UMLClassifier *c) {
00027 
00028     // make all QPtrLists autoDelete false
00029     atpub.setAutoDelete(false);
00030     atprot.setAutoDelete(false);
00031     atpriv.setAutoDelete(false);
00032 
00033     static_atpub.setAutoDelete(false);
00034     static_atprot.setAutoDelete(false);
00035     static_atpriv.setAutoDelete(false);
00036 
00037     // set default class, file names
00038     className = c->getName();
00039     fileName = c->getName().lower();
00040 
00041     // determine up-front what we are dealing with
00042     isInterface = c->isInterface();
00043 
00044     // set id
00045     m_nID = c->getID();
00046 
00047     // sort attributes by Scope
00048     if(!isInterface) {
00049         UMLAttributeList atl = c->getAttributeList();
00050         for(UMLAttribute *at=atl.first(); at ; at=atl.next()) {
00051             switch(at->getVisibility())
00052             {
00053               case Uml::Visibility::Public:
00054                 if(at->getStatic())
00055                     static_atpub.append(at);
00056                 else
00057                     atpub.append(at);
00058                 break;
00059               case Uml::Visibility::Protected:
00060                 if(at->getStatic())
00061                     static_atprot.append(at);
00062                 else
00063                     atprot.append(at);
00064                 break;
00065               case Uml::Visibility::Private:
00066               case Uml::Visibility::Implementation:
00067                     if(at->getStatic())
00068                     static_atpriv.append(at);
00069                 else
00070                     atpriv.append(at);
00071                 break;
00072             }
00073             m_AttsList.append(at);
00074         }
00075     }
00076 
00077     // inheritance issues
00078     superclasses = c->getSuperClasses(); // list of what we inherit from
00079     superclasses.setAutoDelete(false);
00080 
00081     subclasses = c->getSubClasses();     // list of what inherits from us
00082     subclasses.setAutoDelete(false);
00083 
00084     // another preparation, determine what we have
00085     plainAssociations = c->getSpecificAssocs(Uml::at_Association); // BAD! only way to get "general" associations.
00086     plainAssociations.setAutoDelete(false);
00087 
00088     uniAssociations = c->getUniAssociationToBeImplemented();
00089     uniAssociations.setAutoDelete(false);
00090 
00091     aggregations = c->getAggregations();
00092     aggregations.setAutoDelete(false);
00093 
00094     compositions = c->getCompositions();
00095     compositions.setAutoDelete(false);
00096 
00097     // set some summary information about the classifier now
00098     hasAssociations = plainAssociations.count() > 0 || aggregations.count() > 0 || compositions.count() > 0 || uniAssociations.count() > 0;
00099     hasAttributes = atpub.count() > 0 || atprot.count() > 0 || atpriv.count() > 0
00100                     || static_atpub.count() > 0
00101                     || static_atprot.count() > 0
00102                     || static_atpriv.count() > 0;
00103 
00104     hasStaticAttributes = static_atpub.count() > 0
00105                           || static_atprot.count() > 0
00106                           || static_atpriv.count() > 0;
00107 
00108     hasAccessorMethods = hasAttributes || hasAssociations;
00109 
00110     hasOperationMethods = c->getOpList().last() ? true : false;
00111 
00112     hasMethods = hasOperationMethods || hasAccessorMethods;
00113 
00114     // this is a bit too simplistic..some associations are for
00115     // SINGLE objects, and WONT be declared as Vectors, so this
00116     // is a bit overly inclusive (I guess that's better than the other way around)
00117     hasVectorFields = hasAssociations ? true : false;
00118 
00119 
00120 }
00121 
00122 UMLClassifierList ClassifierInfo::getPlainAssocChildClassifierList() {
00123     return findAssocClassifierObjsInRoles(&plainAssociations);
00124 }
00125 
00126 UMLClassifierList ClassifierInfo::getAggregateChildClassifierList() {
00127     return findAssocClassifierObjsInRoles(&aggregations);
00128 }
00129 
00130 UMLClassifierList ClassifierInfo::getCompositionChildClassifierList() {
00131     return findAssocClassifierObjsInRoles(&compositions);
00132 }
00133 
00134 UMLClassifierList ClassifierInfo::findAssocClassifierObjsInRoles (UMLAssociationList * list)
00135 {
00136 
00137 
00138     UMLClassifierList classifiers;
00139     classifiers.setAutoDelete(false);
00140 
00141     for (UMLAssociation *a = list->first(); a; a = list->next()) {
00142         // DONT accept a classifier IF the association role is empty, by
00143         // convention, that means to ignore the classifier on that end of
00144         // the association.
00145         // We also ignore classifiers which are the same as the current one
00146         // (e.g. id matches), we only want the "other" classifiers
00147         if (a->getObjectId(Uml::A) == m_nID && !a->getRoleName(Uml::B).isEmpty()) {
00148             UMLClassifier *c = dynamic_cast<UMLClassifier*>(a->getObject(Uml::B));
00149             if(c)
00150                 classifiers.append(c);
00151         } else if (a->getObjectId(Uml::B) == m_nID && !a->getRoleName(Uml::A).isEmpty()) {
00152             UMLClassifier *c = dynamic_cast<UMLClassifier*>(a->getObject(Uml::A));
00153             if(c)
00154                 classifiers.append(c);
00155         }
00156     }
00157 
00158     return classifiers;
00159 }
00160 
00161 UMLAttributeList* ClassifierInfo::getAttList() {
00162     return &m_AttsList;
00163 }
00164 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:54 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003