CCA
|
Configuration.cpp
Go to the documentation of this file.
00001 /* ============================================================ 00002 * 00003 * This file is a part of CCA project 00004 * 00005 * Copyright (C) 2011 by Arne Nordmann <anordman at cor-lab dot uni-bielefeld dot de> 00006 * 00007 * This file may be licensed under the terms of the 00008 * GNU Lesser General Public License Version 3 (the ``LGPL''), 00009 * or (at your option) any later version. 00010 * 00011 * Software distributed under the License is distributed 00012 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either 00013 * express or implied. See the LGPL for the specific language 00014 * governing rights and limitations. 00015 * 00016 * You should have received a copy of the LGPL along with this 00017 * program. If not, go to http://www.gnu.org/licenses/lgpl.html 00018 * or write to the Free Software Foundation, Inc., 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 * 00021 * The development of this software was supported by: 00022 * CoR-Lab, Research Institute for Cognition and Robotics 00023 * Bielefeld University 00024 * 00025 * ============================================================ */ 00026 00031 #include "Configuration.h" 00032 00033 #include <sstream> 00034 00035 using namespace std; 00036 00037 namespace cca { 00038 00039 Configuration::Configuration(const std::string &n) : 00040 DataTransferObject(), name(n), strategyCache(), dataPortsCache(), 00041 statePortsCache(), beatPortsCache() { 00042 } 00043 00044 Configuration::~Configuration() { 00045 } 00046 00047 std::string Configuration::print() const { 00048 ostringstream outstream(ostringstream::out); 00049 00050 outstream << line(name, 0, true); 00051 00052 if (!strategyCache.empty()) { 00053 outstream << this->strategyCache; 00054 } 00055 if (!beatPortsCache.empty()) { 00056 outstream << this->beatPortsCache; 00057 } 00058 if (!statePortsCache.empty()) { 00059 outstream << this->statePortsCache; 00060 } 00061 if (!dataPortsCache.empty()) { 00062 outstream << this->dataPortsCache; 00063 } 00064 00065 outstream << line("", 0, true); 00066 00067 if (true) { 00068 outstream << line("...", 1); 00069 } 00070 00071 outstream << line("", 0, true); 00072 return outstream.str(); 00073 } 00074 00075 std::string Configuration::line(std::string str, unsigned int place, 00076 bool horizontal) const { 00077 unsigned int linelen = 80; 00078 unsigned int cursor = 0; 00079 00080 ostringstream outstream(ostringstream::out); 00081 00082 // Start the line 00083 outstream << " "; 00084 if (horizontal) { 00085 outstream << " +----"; 00086 cursor += 6; 00087 } else { 00088 outstream << " | "; 00089 cursor += 4; 00090 } 00091 00092 // Insert tabs 00093 for (unsigned int tabs = 0; tabs < place; ++tabs) { 00094 if (!horizontal) { 00095 outstream << " "; 00096 cursor += 4; 00097 } 00098 } 00099 00100 // Insert string 00101 if (!str.empty()) { 00102 outstream << " " << str << " "; 00103 cursor += str.length() + 2; 00104 } 00105 00106 // Fill up the line 00107 for (; cursor < linelen; ++cursor) { 00108 if (horizontal) { 00109 outstream << "-"; 00110 } else { 00111 outstream << " "; 00112 } 00113 } 00114 00115 // Finish the line 00116 if (horizontal) { 00117 outstream << "+"; 00118 } else { 00119 outstream << "|"; 00120 } 00121 00122 outstream << std::endl; 00123 return outstream.str(); 00124 } 00125 00126 void Configuration::displayDataPorts(std::vector<InputPortPtr> ip, 00127 std::vector<OutputPortPtr> op, std::vector<Buffer<rsb::VoidPtr>*> bf) { 00128 ostringstream outstream(ostringstream::out); 00129 00130 if (ip.empty()) { 00131 outstream << line("No data input ports."); 00132 } else { 00133 outstream << line("Data input ports:"); 00134 for (unsigned int port = 0; port < ip.size(); ++port) { 00135 outstream << line(ip[port]->print(), 1); 00136 if (ip[port]->getConfig()) { 00137 outstream 00138 << line( 00139 "Scope: " 00140 + ip[port]->getConfig()->getScopePtr()->toString(), 00141 2); 00142 outstream << line("Buffer: " + bf[port]->print(), 2); 00143 } 00144 } 00145 } 00146 if (op.empty()) { 00147 outstream << line("No data output ports."); 00148 } else { 00149 outstream << line("Data output ports:"); 00150 for (unsigned int port = 0; port < op.size(); ++port) { 00151 outstream << line(op[port]->print(), 1); 00152 if (op[port]->getConfig()) { 00153 outstream 00154 << line( 00155 "Scope: " 00156 + op[port]->getConfig()->getScopePtr()->toString(), 00157 2); 00158 } 00159 } 00160 } 00161 00162 this->dataPortsCache = outstream.str(); 00163 } 00164 00165 void Configuration::displayStatePorts(InputPortPtr ip, OutputPortPtr op) { 00166 ostringstream outstream(ostringstream::out); 00167 00168 outstream << line("Component State Ports:"); 00169 outstream << line(ip->print(), 1); 00170 outstream 00171 << line("Scope: " + ip->getConfig()->getScopePtr()->toString(), 2); 00172 outstream << line(op->print(), 1); 00173 outstream 00174 << line("Scope: " + op->getConfig()->getScopePtr()->toString(), 2); 00175 00176 this->statePortsCache = outstream.str(); 00177 } 00178 00179 void Configuration::displayBeatPort(InputPortPtr ip) { 00180 ostringstream outstream(ostringstream::out); 00181 00182 outstream << line("Beat Port:"); 00183 outstream << line(ip->print(), 1); 00184 outstream 00185 << line("Scope: " + ip->getConfig()->getScopePtr()->toString(), 2); 00186 00187 this->beatPortsCache = outstream.str(); 00188 } 00189 00190 void Configuration::displayStrategy(StrategyPtr strat) { 00191 ostringstream outstream(ostringstream::out); 00192 00193 if (strat) { 00194 outstream << line("Processing strategy:"); 00195 outstream << line(strat->print(), 1); 00196 } else { 00197 outstream << line("Processing strategy:"); 00198 outstream << line("<unconfigured>", 1); 00199 } 00200 00201 this->strategyCache = outstream.str(); 00202 } 00203 00204 }