Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlCore/VLXVisitorLinkMapper.hpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.visualizationlibrary.org                                               */
00005 /*                                                                                    */
00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
00007 /*  All rights reserved.                                                              */
00008 /*                                                                                    */
00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
00010 /*  are permitted provided that the following conditions are met:                     */
00011 /*                                                                                    */
00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
00013 /*  list of conditions and the following disclaimer.                                  */
00014 /*                                                                                    */
00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
00017 /*  other materials provided with the distribution.                                   */
00018 /*                                                                                    */
00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
00029 /*                                                                                    */
00030 /**************************************************************************************/
00031 
00032 #ifndef VLXVisitorLinkMapper_INCLUDE_ONCE
00033 #define VLXVisitorLinkMapper_INCLUDE_ONCE
00034 
00035 #include <vlCore/VLXVisitor.hpp>
00036 
00037 namespace vl
00038 {
00040   class VLXVisitorLinkMapper: public VLXVisitor
00041   {
00042     VL_INSTRUMENT_CLASS(vl::VLXVisitorLinkMapper, VLXVisitor)
00043 
00044   public:
00045     typedef enum 
00046     {
00047       NoError,
00048       DuplicateID
00049     } EError;
00050 
00051   public:
00052     VLXVisitorLinkMapper(std::map< std::string, ref<VLXStructure> >* map=NULL)
00053     {
00054       mLinkMap = map;
00055       mError = NoError;
00056     }
00057 
00058     void setLinkMap(std::map< std::string, ref<VLXStructure> >* map)
00059     {
00060       mLinkMap = map;
00061     }
00062 
00063     void declareID(VLXStructure* obj)
00064     {
00065       if (obj->uid() != "#NULL")
00066       {
00067         const std::map< std::string, ref<VLXStructure> >::const_iterator it = mLinkMap->find(obj->uid());
00068         if (it == mLinkMap->end())
00069           (*mLinkMap)[obj->uid()] = obj;
00070         else
00071         {
00072           if ( it->second != obj )
00073           {
00074             mError = DuplicateID;
00075             Log::error( Say("ID '%s' used by '%s' is already assigned to another node '%s'!\n") << obj->uid() << obj->tag() << it->second->tag() );
00076           }
00077         }
00078       }
00079     }
00080 
00081     virtual void visitStructure(VLXStructure* obj)
00082     {
00083       if (isVisited(obj))
00084         return;
00085 
00086       declareID(obj);
00087 
00088       for(size_t i=0; i<obj->value().size(); ++i)
00089       {
00090         if (obj->value()[i].value().type() == VLXValue::Structure)
00091           obj->value()[i].value().getStructure()->acceptVisitor(this);
00092         else
00093         if (obj->value()[i].value().type() == VLXValue::List)
00094           obj->value()[i].value().getList()->acceptVisitor(this);
00095       }
00096     }
00097 
00098     virtual void visitList(VLXList* list)
00099     {
00100       // this should happen only if the user manually creates loops
00101       if (isVisited(list))
00102       {
00103         Log::warning("VLXVisitorLinkMapper: cycle detected on VLXList.\n");
00104         return;
00105       }
00106 
00107       for(size_t i=0; i<list->value().size(); ++i)
00108       {
00109         if (list->value()[i].type() == VLXValue::Structure)
00110           list->value()[i].getStructure()->acceptVisitor(this);
00111         else
00112         if (list->value()[i].type() == VLXValue::List)
00113           list->value()[i].getList()->acceptVisitor(this);
00114       }
00115     }
00116 
00117     /*
00118     virtual void visitArray(VLXArrayString*)  {}
00119 
00120     virtual void visitArray(VLXArrayIdentifier*) {}
00121 
00122     virtual void visitArray(VLXArrayID*) {}
00123     */
00124 
00125     virtual void visitArray(VLXArrayInteger*)  {}
00126 
00127     virtual void visitArray(VLXArrayReal*)  {}
00128 
00129     EError error() const { return mError; }
00130 
00131     void setError(EError err) { mError = err; }
00132 
00133   private:
00134     std::map< std::string, ref<VLXStructure> >* mLinkMap;
00135     EError mError;
00136   };
00137 }
00138 
00139 #endif

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:33.
Permission is granted to use this page to write and publish articles regarding Visualization Library.