Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Examples

ColCOWS_WorkspaceDesc.cc

00001 //===========================================================================//
00002 //    
00003 //    Description: interface for user defined event handling classes
00004 //    Filename: colcows/ColCOWS_WorkspaceDesc .cc
00005 //    Authors: Michael Dussere and Aurélien Esnard
00006 //    
00007 //===========================================================================//
00008 //    
00009 //    Copyright (C) 2003 INRIA and CNRS
00010 //    
00011 //    This library is free software; you can redistribute it and/or
00012 //    modify it under the terms of the GNU Lesser General Public
00013 //    License as published by the Free Software Foundation; either
00014 //    version 2.1 of the License, or (at your option) any later version.
00015 //    
00016 //    This library is distributed in the hope that it will be useful,
00017 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 //    Lesser General Public License for more details.
00020 //    
00021 //    You should have received a copy of the GNU Lesser General Public
00022 //    License along with this library; if not, write to the Free Software
00023 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //    
00025 //===========================================================================//
00026 
00027 #include "ColCOWS_WorkspaceDesc.hh" 
00028 #include "ColCOWS_Corba.hh" 
00029 
00030 using namespace std;
00031 
00032 __COLCOWS_BEGIN__
00033 
00034 //===========================================================================//
00035 
00036 void WorkspaceDesc::getObjectDescVec( ExtObjectDescVec & object_desc_vec, std::string node_kind, std::string obj_id, std::string obj_kind ) const 
00037 {
00038   COLCOWS_IN_DEBUG( );
00039 
00040   unsigned int init_size = object_desc_vec.size();
00041 
00042   for( const_iterator it = begin(); it != end(); ++it ) 
00043     {
00044       if ( node_kind.empty() || ( it->getKind() == node_kind )) 
00045         {
00046           it->getObjectDescVec(object_desc_vec, obj_id, obj_kind );
00047         }
00048     }
00049   
00050   for( unsigned int i = init_size; i < object_desc_vec.size(); ++i )
00051     object_desc_vec[i].num_connection = _num_connection;
00052 
00053   COLCOWS_OUT_DEBUG( );
00054   return;
00055 }
00056 
00057 //===========================================================================//
00058 
00059 void WorkspaceDesc::convertFromIdl( const IdlWorkspaceDesc & idl_ws_desc ) 
00060 { 
00061   COLCOWS_IN_DEBUG( );
00062 
00063   clear();
00064 
00065   _ws_id = idl_ws_desc.ws_id;
00066   _ws_kind = idl_ws_desc.ws_kind;
00067   _nb_nodes = idl_ws_desc.nb_nodes;
00068   _activated = idl_ws_desc.activated;
00069   _num_connection = idl_ws_desc.num_connection;
00070   //  _enter_node_ref = idl_ws_desc.enter_node_ref;
00071 
00072   //==== Walk through the node hierarchy ===//
00073 
00074   const IdlNodeDesc * node_desc = &(idl_ws_desc.enter_node);
00075     
00076   stack< const IdlNodeDesc * > node_desc_stack;
00077   stack< unsigned long > num_child_stack;
00078   
00079   unsigned long num_child = 0;
00080   unsigned long current_num_node = node_desc->num_node;
00081   unsigned long max_descendant = node_desc->max_descendant ;  
00082     
00083   while ( max_descendant >= current_num_node ) {
00084     COLCOWS_DEBUG( dblTest, "passing on node " << node_desc->num_node );
00085 
00086     if (node_desc->num_node == current_num_node) {
00087      
00088       // node is the one i was looking for
00089       push_back(*node_desc);
00090 
00091       // increment
00092       current_num_node ++;
00093     }
00094       
00095     if (num_child < node_desc->children_seq.length()){
00096       // node has another child, go down
00097         
00098       node_desc_stack.push(node_desc);
00099       num_child_stack.push(num_child + 1);
00100      
00101       node_desc = &(node_desc->children_seq[num_child]);
00102       num_child = 0;
00103      
00104     }
00105     else if ( node_desc_stack.empty() == false) {
00106       // no more child, go up
00107      
00108       node_desc = node_desc_stack.top();
00109       num_child = num_child_stack.top();
00110      
00111       node_desc_stack.pop();
00112       num_child_stack.pop();
00113      
00114     }
00115     else if ( node_desc_stack.empty() == true) {
00116       // stack empty
00117       COLCOWS_DEBUG( dblTest, "stack empty all the tree has been run through ..." );    
00118       break ;
00119     }
00120     else {
00121       COLCOWS_DEBUG( dblWarning, "Cannot find node in the Workspace." );    
00122       COLCOWS_OUT_DEBUG();  
00123       return ;
00124     }
00125   }
00126 
00127   COLCOWS_OUT_DEBUG( );
00128 }
00129 
00130 //===========================================================================//
00131 
00132 unsigned long WorkspaceDesc::getNbNodes( std::string node_kind ) const
00133 {
00134   COLCOWS_IN_DEBUG();
00135 
00136   unsigned long nb_nodes = 0;
00137 
00138   if ( node_kind.empty() ) {
00139     nb_nodes = size();
00140   }
00141   else {
00142     for ( const_iterator it = begin() ; it != end(); ++it )
00143       if ( it->getKind() == node_kind ) ++nb_nodes;
00144   }
00145 
00146   COLCOWS_OUT_DEBUG();  
00147   return nb_nodes;
00148 }
00149 
00150 //===========================================================================//
00151 
00152 void WorkspaceDesc::printself( std::ostream & stream , int indent ) const
00153 { 
00154   std::string space; 
00155   for(int i = 0; i < indent; i++, space += COLCOWS_TAB);
00156 
00157   stream << space << "workspace ID: " << _ws_id << std::endl;
00158   stream << space << "workspace kind: " << _ws_kind << std::endl;
00159   stream << space << "nb nodes: " << _nb_nodes << std::endl;
00160   stream << space << "activated: " << boolalpha << _activated << std::endl;
00161   stream << space << "nodes: " << std::endl;
00162   
00163   for( const_iterator it = begin(); it != end() ; ++it ){
00164     stream << "+" ;
00165     it->printself(stream, indent+1);
00166     stream << endl;
00167   }    
00168 }
00169 
00170 //===========================================================================//
00171 
00172 __COLCOWS_END__
00173 
00174 // EOF
00175 

Generated on Tue Jun 21 12:55:56 2005 for ColCOWS by  doxygen 1.4.1