ModuleAccess.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program 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
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 
00019 #include "ModuleAccess.h"
00020 
00021 inline bool isNode(cModule *mod)
00022 {
00023     cProperties *props = mod->getProperties();
00024     return props && props->getAsBool("node");
00025 }
00026 
00027 static cModule *findSubmodRecursive(cModule *curmod, const char *name)
00028 {
00029     for (cModule::SubmoduleIterator i(curmod); !i.end(); i++)
00030     {
00031         cModule *submod = i();
00032         if (!strcmp(submod->getFullName(), name))
00033             return submod;
00034         cModule *foundmod = findSubmodRecursive(submod, name);
00035         if (foundmod)
00036             return foundmod;
00037     }
00038     return NULL;
00039 }
00040 
00041 cModule *findModuleWherever(const char *name, cModule *from)
00042 {
00043     cModule *mod = NULL;
00044     for (cModule *curmod=from; !mod && curmod; curmod=curmod->getParentModule())
00045         mod = findSubmodRecursive(curmod, name);
00046     return mod;
00047 }
00048 
00049 cModule *findModuleWhereverInNode(const char *name, cModule *from)
00050 {
00051     cModule *mod = NULL;
00052     for (cModule *curmod=from; curmod; curmod=curmod->getParentModule())
00053     {
00054         mod = findSubmodRecursive(curmod, name);
00055         if (mod || isNode(curmod))
00056             break;
00057     }
00058     return mod;
00059 }
00060 
00061 cModule *findModuleSomewhereUp(const char *name, cModule *from)
00062 {
00063     cModule *mod = NULL;
00064     for (cModule *curmod=from; !mod && curmod; curmod=curmod->getParentModule())
00065         mod = curmod->getSubmodule(name);
00066     return mod;
00067 }
00068