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

OSGGraphOp.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 
00040 /***************************************************************************\
00041 *                             Includes                                    *
00042 \***************************************************************************/
00043 
00044 #include <string.h>
00045 #include <OSGGraphOp.h>
00046 #include <OSGSimpleAttachments.h>
00047 
00048 OSG_USING_NAMESPACE
00049 
00050 /***************************************************************************\
00051  *                            Description                                  *
00052 \***************************************************************************/
00053 
00074 /***************************************************************************\
00075  *                           Instance methods                              *
00076 \***************************************************************************/
00077 
00078 /*-------------------------------------------------------------------------*\
00079  -  public                                                                 -
00080 \*-------------------------------------------------------------------------*/
00081 
00082 
00083 /*------------- constructors & destructors --------------------------------*/
00084 
00085 GraphOp::GraphOp(const char* name): 
00086     _name(name), _excludeListNodes(), _excludeListNames()
00087 {
00088 }
00089 
00090 GraphOp::~GraphOp(void)
00091 {
00092 }
00093 
00094 bool GraphOp::traverse(NodePtr& node)
00095 {
00096     Action::ResultE res;
00097     res = ::traverse(node,
00098           osgTypedMethodFunctor1ObjPtrCPtrRef<Action::ResultE,
00099           GraphOp,
00100           NodePtr>(this,&GraphOp::traverseEnter),
00101           osgTypedMethodFunctor2ObjPtrCPtrRef<Action::ResultE,
00102           GraphOp,
00103           NodePtr,
00104           Action::ResultE>(this,&GraphOp::traverseLeave));
00105 
00106     if (res == Action::Continue) 
00107         return true;
00108     else 
00109         return false;
00110 }
00111 
00112 const std::string & GraphOp::getName(void)
00113 {
00114     return _name;
00115 };
00116 
00117 void GraphOp::setName(const char *name)
00118 {
00119     _name = name;
00120 };
00121 
00122 /*--------------------------- Exclude List --------------------------------*/
00123 
00124 void GraphOp::addToExcludeList(NodePtr& node)
00125 {
00126     if (!isInExcludeListNodes(node))
00127         _excludeListNodes.push_back(node);
00128 }
00129 
00130 void GraphOp::addToExcludeList(const std::string &name)
00131 {
00132     if (!isInExcludeListNames(name))
00133         _excludeListNames.push_back(name);
00134 }
00135 
00136 void GraphOp::removeFromExcludeList(NodePtr& node)
00137 {
00138     _excludeListNodes.remove(node);
00139 }
00140 
00141 void GraphOp::removeFromExcludeList(const std::string &name)
00142 {
00143     _excludeListNames.remove(name);
00144 }
00145 
00146 void GraphOp::clearExcludeList(void)
00147 {
00148     _excludeListNames.clear();
00149     _excludeListNodes.clear();
00150 }
00151 
00152 bool GraphOp::isInExcludeListNodes(NodePtr& node)
00153 {
00154     std::list<NodePtr>::iterator list_iter;
00155     list_iter = std::find(_excludeListNodes.begin(),_excludeListNodes.end(),node);
00156 
00157     if (list_iter==_excludeListNodes.end()) 
00158         return false;
00159     else 
00160         return true;
00161 }
00162 
00163 bool GraphOp::isInExcludeListNames(const std::string &name)
00164 {
00165     std::list<std::string>::iterator namelist_iter;
00166     namelist_iter = std::find(_excludeListNames.begin(),_excludeListNames.end(),name);
00167 
00168     if (namelist_iter==_excludeListNames.end()) 
00169         return false;
00170     else 
00171         return true;
00172 }
00173 
00174 bool GraphOp::isInExcludeList(NodePtr& node)
00175 {
00176     if (isInExcludeListNodes(node) || (OSG::getName(node)!=NULL && isInExcludeListNames(OSG::getName(node))))
00177         return true;
00178     else
00179         return false;
00180 }
00181 
00182 // Parameter Helpers
00183 
00184 GraphOp::ParamSet::ParamSet(const std::string &params) :
00185     _values(),
00186     _used()
00187 {
00188     std::string::const_iterator it = params.begin(), end = params.end();
00189     
00190     std::string key, value;
00191     
00192     while(it != end)
00193     {
00194         char c = 0;
00195         
00196         key = "";
00197         value = "";
00198         
00199         // Read key
00200         while(it != end)
00201         {
00202             c = *it++;
00203             
00204             if(c == ' ' || c == '=')
00205                 break;
00206             
00207             key += tolower(c);
00208         }
00209         
00210         // Do we have a value? Read it
00211         if (it != end && c == '=')
00212         {
00213             while(it != end)
00214             {
00215                 c = *it++;
00216 
00217                 if(c == ' ')
00218                     break;
00219 
00220                 value += c;
00221             }           
00222         }
00223 
00224         // Add key, value pair
00225         
00226         FDEBUG(("GraphOp::ParamSet: key='%s', value='%s'\n", key.c_str(),
00227                                                              value.c_str()));
00228 
00229         _values.insert(valuesT::value_type(key, value));
00230 
00231         // Skip to next param
00232 
00233         while(it != end && (*it == ' '));
00234    }
00235 }
00236 
00237 bool GraphOp::ParamSet::operator()(const char *name, std::string &val)
00238 {
00239     valuesT::iterator it = _values.find(name);
00240     
00241     if(it != _values.end())
00242     {
00243         val = (*it).second;
00244         
00245         _used[name] = true;
00246         
00247         return true;
00248     }
00249     return false;
00250 }
00251  
00252 bool GraphOp::ParamSet::operator()(const char *name, Real32 &val)
00253 {
00254     valuesT::iterator it = _values.find(name);
00255     
00256     if(it != _values.end())
00257     {
00258         const Char8* c = (*it).second.c_str();       
00259         FieldDataTraits<Real32>::getFromString(val, c);
00260         
00261         _used[name] = true;
00262         return true;
00263     }
00264     return false;
00265 }
00266 
00267 bool GraphOp::ParamSet::operator()(const char *name, UInt16 &val)
00268 {
00269     valuesT::iterator it = _values.find(name);
00270     
00271     if(it != _values.end())
00272     {
00273         const Char8* c = (*it).second.c_str();       
00274         FieldDataTraits<UInt16>::getFromString(val, c);
00275         
00276         _used[name] = true;
00277         return true;
00278     }
00279     return false;
00280 }
00281 
00282 bool GraphOp::ParamSet::operator()(const char *name, UInt32 &val)
00283 {
00284     valuesT::iterator it = _values.find(name);
00285     
00286     if(it != _values.end())
00287     {
00288         const Char8* c = (*it).second.c_str();       
00289         FieldDataTraits<UInt32>::getFromString(val, c);
00290         
00291         _used[name] = true;
00292         return true;
00293     }
00294     return false;
00295 }
00296 
00297 bool GraphOp::ParamSet::operator()(const char *name, bool &val)
00298 {
00299     valuesT::iterator it = _values.find(name);
00300     
00301     if(it != _values.end())
00302     {
00303         if((*it).second.length() == 0)
00304         {
00305             val = true;
00306         }
00307         else
00308         {
00309             const Char8* c = (*it).second.c_str();       
00310             FieldDataTraits2<bool>::getFromString(val, c);
00311         }
00312         
00313         _used[name] = true;
00314         return true;
00315     }
00316     return false;
00317 }
00318 
00319 void GraphOp::ParamSet::markUsed(const char *name)
00320 {
00321     _used[name] = true;
00322 }
00323 
00324 std::string GraphOp::ParamSet::getUnusedParams(void)
00325 {
00326     std::string out;
00327     
00328     for (valuesT::iterator it = _values.begin(); it != _values.end(); ++it)
00329     {
00330         usedT::iterator uit = _used.find((*it).first);
00331         
00332         if(uit == _used.end())
00333         {
00334             if(out.length())
00335                 out += " ";
00336                 
00337             out += (*it).first;
00338         }
00339     }
00340  
00341     return out;   
00342 }
00343 
00344 
00345 /*-------------------------------------------------------------------------*\
00346  -  protected                                                              -
00347 \*-------------------------------------------------------------------------*/

Generated on Thu Aug 25 04:05:52 2005 for OpenSG by  doxygen 1.4.3