# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlCore/VLXVisitorCountIDs.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 VLXVisitorCountIDs_INCLUDE_ONCE
    00033 #define VLXVisitorCountIDs_INCLUDE_ONCE
    00034
    00035 #include <vlCore/VLXVisitor.hpp>
    00036 #include <vlCore/VLXValue.hpp>
    00037 #include <vlCore/Log.hpp>
    00038 #include <vlCore/Say.hpp>
    00039
    00040 namespace vl
    00041 {
    00043   class VLXVisitorCountIDs: public VLXVisitor
    00044   {
    00045     VL_INSTRUMENT_CLASS(vl::VLXVisitorCountIDs, VLXVisitor)
    00046
    00047   public:
    00048     VLXVisitorCountIDs(): mIDSet(NULL) {}
    00049
    00050     virtual void visitStructure(VLXStructure* obj)
    00051     {
    00052       if(!obj->uid().empty() && obj->uid() != "#NULL")
    00053         (*mIDSet)[obj->uid()]++;
    00054
    00055       if (isVisited(obj))
    00056         return;
    00057
    00058       for(size_t i=0; i<obj->value().size(); ++i)
    00059       {
    00060         VLXStructure::Value& keyval = obj->value()[i];
    00061         if (keyval.value().type() == VLXValue::Structure)
    00062           keyval.value().getStructure()->acceptVisitor(this);
    00063         else
    00064         if (keyval.value().type() == VLXValue::List)
    00065           keyval.value().getList()->acceptVisitor(this);
    00066         else
    00067         /*
    00068         if (keyval.value().type() == VLXValue::ArrayID)
    00069           keyval.value().getArrayID()->acceptVisitor(this);
    00070         else
    00071         */
    00072         if (keyval.value().type() == VLXValue::ID)
    00073           (*mIDSet)[keyval.value().getID()]++;
    00074       }
    00075     }
    00076
    00077     virtual void visitList(VLXList* list)
    00078     {
    00079       // this should happen only if the user manually creates loops
    00080       if (isVisited(list))
    00081       {
    00082         Log::warning("VLXVisitorCountIDs: cycle detected on VLXList.\n");
    00083         return;
    00084       }
    00085
    00086       for(size_t i=0; i<list->value().size(); ++i)
    00087       {
    00088         if (list->value()[i].type() == VLXValue::Structure)
    00089           list->value()[i].getStructure()->acceptVisitor(this);
    00090         if (list->value()[i].type() == VLXValue::List)
    00091           list->value()[i].getList()->acceptVisitor(this);
    00092         else
    00093         /*
    00094         if (list->value()[i].type() == VLXValue::ArrayID)
    00095           list->value()[i].getArrayID()->acceptVisitor(this);
    00096         else
    00097         */
    00098         if (list->value()[i].type() == VLXValue::ID)
    00099           (*mIDSet)[list->value()[i].getID()]++;
    00100       }
    00101     }
    00102
    00103     /*
    00104     virtual void visitArray(VLXArrayString*)  {}
    00105
    00106     virtual void visitArray(VLXArrayID* arr)
    00107     {
    00108       // retrieves the assigned Structure
    00109       for(size_t i=0 ;i<arr->value().size(); ++i)
    00110         (*mIDSet)[arr->value()[i].uid()]++;
    00111     }
    00112
    00113     virtual void visitArray(VLXArrayIdentifier*) {}
    00114     */
    00115
    00116     virtual void visitArray(VLXArrayInteger*)  {}
    00117
    00118     virtual void visitArray(VLXArrayReal*)  {}
    00119
    00120     void setIDSet(std::map< std::string, int >* uids) { mIDSet = uids; }
    00121
    00122     std::map< std::string, int >* uidSet() { return mIDSet; }
    00123
    00124     const std::map< std::string, int >* uidSet() const { return mIDSet; }
    00125
    00126   private:
    00127     std::map< std::string, int >* mIDSet;
    00128   };
    00129 }
    00130
    00131 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:33.
Permission is granted to use this page to write and publish articles regarding Visualization Library.