rc_common_header.cpp

Go to the documentation of this file.
00001 // vim:set et sts=4 ts=4 tw=75 sw=4 ai ci cin cino=g0,t0:
00002 /*
00003  * Copyright (C) 2007, Technical Computer Science Group,
00004  *                     University of Bonn
00005  *
00006  * This file is part of the ReChannel library.
00007  *
00008  * The ReChannel library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be
00014  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this library; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  *
00023  * Authors: Andreas Raabe and Armin Felke. Implementation by Armin Felke.
00024  *          {raabe, felke}@cs.uni-bonn.de
00025  */
00037 #include "rc_common_header.h"
00038 
00039 namespace ReChannel {
00040 
00041 sc_object* rc_find_object(
00042     const char* obj_name, const sc_object* rel_obj)
00043 {
00044     if (obj_name == NULL) {
00045         return NULL;
00046     }
00047     if (obj_name[0] == '.' || obj_name[0] == '#') {
00048         if (rel_obj == NULL) {
00049             return NULL;
00050         }
00051         std::string buf;
00052         if (obj_name[0] == '.') {
00053             buf.append(rel_obj->name());
00054             buf.append(obj_name);
00055         } else { // '#'
00056             // resolve the relative name
00057             const char* pos_rel_name = obj_name + 1;
00058             const sc_object* base_obj = rel_obj;
00059             while(*pos_rel_name == '.') {
00060                 if (base_obj == NULL) {
00061                     break;
00062                 }
00063                 base_obj = base_obj->get_parent_object();
00064                 pos_rel_name++;
00065             }
00066             if (pos_rel_name == obj_name + 1 || *pos_rel_name == '\0') {
00067                 RC_REPORT_ERROR(RC_ID_RELNAME_SYNTAX_ERROR_,
00068                     "Relative name '" << obj_name << "'"
00069                     " could not be resolved due to"
00070                     " syntax error");
00071             }
00072             if (*pos_rel_name == '.') {
00073                 return NULL;
00074             } else if (base_obj == NULL) {
00075                 buf.append(pos_rel_name);
00076             } else {
00077                 buf.append(rel_obj->name());
00078                 buf.append(pos_rel_name - 1);
00079             }
00080         }
00081         return sc_find_object(buf.c_str());
00082     } else {
00083         return sc_find_object(obj_name);
00084     }
00085 }
00086 
00087 sc_module* rc_find_parent_module(sc_object* obj)
00088 {
00089     sc_module* parent = NULL;
00090     while(obj != NULL
00091         && (parent = dynamic_cast<sc_module*>(
00092                 obj = obj->get_parent_object())) == NULL);
00093     return parent;
00094 }
00095 
00096 } // namespace ReChannel
00097 
00098 //
00099 // $Id: rc_common_header.cpp,v 1.3 2007/10/09 00:22:26 felke Exp $
00100 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/core/rc_common_header.cpp,v $
00101 //

Generated on Tue Jan 1 23:13:31 2008 for ReChannel by  doxygen 1.5.3