Code Search for Developers
 
 
  

CValueTree.h from osgDesigner at Krugle


Show CValueTree.h syntax highlighted

#ifndef __CVALUETREE_H__
#define __CVALUETREE_H__ 1

#include <boost/signals/trackable.hpp>

#include <osgIntrospectionToolKit/Export.h>
#include <osgIntrospectionToolKit/signalslib.hpp>
#include <boost/bind.hpp>

#include <osgIntrospectionToolKit/IGraph.h>
#include <osgIntrospectionToolKit/STypeGraph.h>
#include <osgIntrospectionToolKit/ControlList.h>
#include <osgIntrospectionToolKit/IReflectedValue.h>
#include <osgIntrospectionToolKit/CReflectedRefPointer.h>
#include <osgIntrospectionToolKit/IReflectedValueLink.h>
#include <osgIntrospectionToolKit/CommonStdType.h>


 







namespace osgIntrospectionToolKit
{
    struct reflected_value_t 
    { typedef boost::vertex_property_tag kind; };
    struct reflected_value_link_t 
    { typedef boost::edge_property_tag kind; };
    
    
    
    typedef IGraph<boost::listS, boost::listS, boost::bidirectionalS,
                   boost::property<reflected_value_t, osg::ref_ptr< IReflectedValue > >,
                   boost::property<reflected_value_link_t, osg::ref_ptr< IReflectedValueLink > >,
                   boost::no_property, 
                   boost::listS>                                   CValueTreeBase;
    /**
     * CValueTree is a tree representation of a value. 
     * This value could be a int or a class with variables. 
     * Each node of the tree is a variable, a variable of a variable, etc
     * */
    class OSGINTROSPECTIONTOOLKIT_EXPORT CValueTree : public CValueTreeBase, public boost::signalslib::trackable
    {
            friend class CValueTreeModifier;
            
        public:
    
            typedef CValueTreeBase                                              Base;
//            typedef IReflectedValue                                             VertexProperty;
//            typedef IReflectedValueLink                                         EdgeProperty;
                    
            // ** boost::adjacency_list used typedef ** //
            typedef Base::graph_base                                            graph_base;
            typedef Base::adjacency_iterator                                    adjacency_iterator;
            typedef Base::inv_adjacency_iterator                                inv_adjacency_iterator;
            typedef Base::out_edge_iterator                                     out_edge_iterator;
            typedef Base::in_edge_iterator                                      in_edge_iterator;
            typedef Base::vertex_iterator                                       vertex_iterator;
            typedef Base::vertex_descriptor                                     vertex_descriptor;
            typedef Base::edge_iterator                                         edge_iterator;
            typedef Base::edge_descriptor                                       edge_descriptor;
            
            typedef Base::adjacency_range                                       adjacency_range;
            typedef Base::inv_adjacency_range                                   inv_adjacency_range;
            typedef Base::out_edge_range                                        out_edge_range;
            typedef Base::in_edge_range                                         in_edge_range;
            typedef Base::vertex_range                                          vertex_range;
            typedef Base::edge_range                                            edge_range;
            
            typedef std::list<vertex_descriptor>                                VertexList;
            typedef std::list<edge_descriptor>                                  EdgeList;
            typedef std::vector< const osgIntrospection::Type* >                TypeList;
            typedef std::list< osgIntrospection::Value >                        ValueList;
 

            typedef boost::signal<void (vertex_descriptor, size_t, size_t)>     ModificationSignal;
            typedef boost::signal<void (void)>                                  ResetSignal;
                    
        	CValueTree(std::string name);
            
        protected:
        	virtual ~CValueTree();
        
        public:
        
        
            //////////////////////////////////////
            // ** Vertex and Edges Interface ** //
            //////////////////////////////////////
            
            // ** accessor
            const IReflectedValue*                                  reflectedValue(const vertex_descriptor vd) const;
            const IReflectedValueLink*                              reflectedValueLink(const edge_descriptor ed) const;
            const osgIntrospection::PropertyInfo*                   propertyInfo(edge_descriptor ed) const;


            // ** manipulator
            IReflectedValue*                                        reflectedValue(const vertex_descriptor vd);
            IReflectedValueLink*                                    reflectedValueLink(const edge_descriptor ed);
            void                                                    reflectedValue(const vertex_descriptor vd, IReflectedValue* rv);
            void                                                    reflectedValueLink(const edge_descriptor ed, IReflectedValueLink* rvl);
            void                                                    disconnectClearAndRemoveVertex(vertex_descriptor vd);
            
            edge_descriptor                                         addChild(vertex_descriptor parent, IReflectedValue* rv, IReflectedValueLink* rvl);
            


            //////////////////////////
            // ** Tree Interface ** //
            //////////////////////////
            
            // ** accessor
            CReflectedRefPointer*                                   getRootReflectedRefPointer(size_t idx)
            {
                if (out_degree(root()) <= idx) return (NULL);
                return (dynamic_cast<CReflectedRefPointer*>(reflectedValue(child(root(), idx))));
            }
            const CReflectedRefPointer*                             getFirstReflectedRefPointerInParents(const vertex_descriptor vd) const;
            const std::string&                                      name();


            // ** manipulator
            void                                                    clearTree();
            void                                                    add(osg::Referenced* refPtr);
            void                                                    add(osgIntrospection::Value & val);
            void                                                    explore(const vertex_descriptor vd);
            void                                                    update(const vertex_descriptor vd);
            void                                                    remove(const vertex_descriptor vd);
            void                                                    reload();
            
            

            ///////////////////////////////
            // ** Tree stat Interface ** //
            ///////////////////////////////
            
            // ** accessor
            void                                                    listGraph();
            void                                                    statGraph();




            ///////////////////////////////////
            // ** Real Variable Interface ** //
            ///////////////////////////////////
            
            // ** accessor
            void                                                    getTypeStr(const vertex_descriptor vd, std::string& type) const;
            void                                                    getInstanceTypeStr(const vertex_descriptor vd, std::string& type) const;
            void                                                    getPointedTypeStr(const vertex_descriptor vd, std::string& typeName) const;
            void                                                    getName(const vertex_descriptor vd, std::string& name) const;
            void                                                    getValueStr(const vertex_descriptor vd, std::string& value) const;
       
            const osgIntrospection::Type*                           getType(const vertex_descriptor vd) const;
            const osgIntrospection::Type*                           getInstanceType(const vertex_descriptor vd) const;
            const osgIntrospection::Type*                           getPointedType(const vertex_descriptor vd) const;
       
            std::size_t                                             getSimplePropertyInfoList(const vertex_descriptor vd, osgIntrospection::PropertyInfoList& pil) const;
            std::size_t                                             getArrayPropertyInfoList(const vertex_descriptor vd, osgIntrospection::PropertyInfoList& pil) const;
            std::size_t                                             getIndexedPropertyInfoList(const vertex_descriptor vd, osgIntrospection::PropertyInfoList& pil) const;
            
            void                                                    getValue(const vertex_descriptor vd, osgIntrospection::Value& returnValue) const;
            
            bool                                                    canSet(vertex_descriptor vd) const;
            bool                                                    canAdd(vertex_descriptor vd) const;
            bool                                                    canRemove(vertex_descriptor vd) const;
            bool                                                    canInsert(vertex_descriptor vd) const;
            bool                                                    isPointer(vertex_descriptor vd) const;
            bool                                                    isRefPointer(vertex_descriptor vd) const;
            bool                                                    isSimple(vertex_descriptor vd) const;
            bool                                                    isArray(vertex_descriptor vd) const;
            bool                                                    isIndexed(vertex_descriptor vd) const;
            
            // ** manipulation
            vertex_descriptor                                       setValue(const vertex_descriptor vd, const std::string& valueStr);
            vertex_descriptor                                       setValue(const vertex_descriptor vd, const osgIntrospection::Value& value);
            vertex_descriptor                                       addArrayValue(const vertex_descriptor vd, const osgIntrospection::PropertyInfo& pi, osgIntrospection::Value& newValue);
            vertex_descriptor                                       removeValue(const vertex_descriptor vd);
            vertex_descriptor                                       insertValue(const vertex_descriptor vd);
            vertex_descriptor                                       addIndexedValue(const vertex_descriptor vd, const osgIntrospection::PropertyInfo& pi, osgIntrospection::ValueList& index, osgIntrospection::Value& newValue);


//            vertex_descriptor                                       setNewValue(const vertex_descriptor vd, const std::string& typeName);


            ///////////////////////////////////////
            // ** Propery and Value Interface ** //
            ///////////////////////////////////////

            size_t                                                  getAllowedPropertyInfoList(const osgIntrospection::Type& type, osgIntrospection::PropertyInfoList& pil) const;
                


            /////////////////////////////////
            // ** Type Filter Interface ** //
            /////////////////////////////////

            // ** accessor
            Policy                                                  isValidIn(const osgIntrospection::Type* type) const;
            Policy                                                  isValidThrow(const osgIntrospection::Type* type) const;
            Policy                                                  isValidThrow(const osgIntrospection::PropertyInfo* propertyInfo) const;
            size_t                                                  filterPropertyInfoList(const osgIntrospection::PropertyInfoList& allPil, osgIntrospection::PropertyInfoList& filteredPil) const;

            
            // ** manipulator            
            void                                                    addInTypePolicy(TypeControl* tc);
            void                                                    addInTypePolicy(const std::string type, Policy policy);

            void                                                    addThrowTypePolicy(TypeControl* tc);
            void                                                    addThrowTypePolicy(const std::string type, Policy policy);

            void                                                    addThrowPropertyInfoPolicy(PropertyInfoControl* pic);
            void                                                    addThrowPropertyInfoPolicy(const std::string type, const std::string property, Policy policy);

            void                                                    clearInTypePolicy();
            void                                                    removeThrowTypePolicy();
            void                                                    removeThrowPropertyInfoPolicy();



            ////////////////////////////
            // ** signal interface ** //
            ////////////////////////////
            
            // ** accessor
            ModificationSignal&                                     beginUpdateSignal();
            ModificationSignal&                                     endUpdateSignal();
            ModificationSignal&                                     beginRemoveSignal();
            ModificationSignal&                                     endRemoveSignal();
            ModificationSignal&                                     beginAddSignal();
            ModificationSignal&                                     endAddSignal();
            ResetSignal&                                            beginResetSignal();
            ResetSignal&                                            endResetSignal();


        protected:
            
            bool                                                    _getPathAndValueListToFirstReflectedRefPointer(const vertex_descriptor vd, EdgeList& path, ValueList& valueList);
            bool                                                    _setValueWithPathAndValueList(const vertex_descriptor parentVd, const EdgeList& path, ValueList& valueList);
            const CReflectedRefPointer*                             _findReflectedRefPointerInParents(vertex_descriptor vd, EdgeList& path) const;
            void                                                    _connect(const vertex_descriptor vd, IReflectedValue* rv);
            void                                                    _disconnect(const vertex_descriptor vd);
            



            // ** name of the graph
            std::string                 _name;
            
            // ** types ControlList for the root vertex  
            TypeControlList             _inTypeControlList;
            Policy                      _defaultInPolicy;
            
            // ** types and properties ControlList for node vertex and edges
            TypeControlList             _throwTypeControlList;
            PropertyInfoControlList     _throwPropertyInfoControlList;
            Policy                      _defaultThrowPolicy;
            
            // ** begin and end signal
            ModificationSignal          _beginAddSignal;
            ModificationSignal          _endAddSignal;            
            ModificationSignal          _beginRemoveSignal;
            ModificationSignal          _endRemoveSignal;     
            ModificationSignal          _beginUpdateSignal;
            ModificationSignal          _endUpdateSignal;     
            ResetSignal                 _beginResetSignal;
            ResetSignal                 _endResetSignal;
    };







    //
    // ** ACCESSOR ** //
    //
    inline const IReflectedValue*                       CValueTree::reflectedValue(const vertex_descriptor vd) const
    { return (boost::get(reflected_value_t(), tree(), vd).get()); }
    inline const IReflectedValueLink*                   CValueTree::reflectedValueLink(const edge_descriptor ed) const
    { return (boost::get(reflected_value_link_t(), tree(), ed).get()); }
    inline const osgIntrospection::PropertyInfo*        CValueTree::propertyInfo(edge_descriptor ed) const
    { 
        const IReflectedValueLink* rvl = reflectedValueLink(ed);
        return ((rvl) ? (&rvl->propertyInfo()) : (NULL));
    }

 
    
    //
    // ** MANIPULATOR ** //
    //
    inline IReflectedValue*                             CValueTree::reflectedValue(const vertex_descriptor vd)
    { return (boost::get(reflected_value_t(), tree(), vd).get()); }
    inline IReflectedValueLink*                         CValueTree::reflectedValueLink(const edge_descriptor ed)
    { return (boost::get(reflected_value_link_t(), tree(), ed).get()); }
    inline void                                         CValueTree::reflectedValue(const vertex_descriptor vd, IReflectedValue* rv)
    {
        _disconnect(vd);
        _connect(vd, rv);
        boost::put(reflected_value_t(), tree(), vd, osg::ref_ptr<IReflectedValue>(rv));
    }
    inline void                                         CValueTree::reflectedValueLink(const edge_descriptor ed, IReflectedValueLink* rvl)
    {
        boost::put(reflected_value_link_t(), tree(), ed, osg::ref_ptr<IReflectedValueLink>(rvl));
    }
    inline CValueTree::edge_descriptor                  CValueTree::addChild(vertex_descriptor parent, IReflectedValue* rv, IReflectedValueLink* rvl)
    {
        vertex_descriptor vd = add_vertex();
        reflectedValue(vd, rv);
        edge_descriptor ed = add_edge(parent, vd).first;
        reflectedValueLink(ed, rvl);
        return (ed); 
    }




    inline bool                                         CValueTree::isRefPointer(vertex_descriptor vd) const
    { 
        const IReflectedValue* rv = reflectedValue(vd);
        return (rv->valueScope() == IReflectedValue::RefPointer);
    }
    inline bool                                         CValueTree::isPointer(vertex_descriptor vd) const
    { 
        const IReflectedValue* rv = reflectedValue(vd);
        return (rv->valueScope() == IReflectedValue::Pointer);
    }
    inline bool                                         CValueTree::isSimple(vertex_descriptor vd) const
    {
        const osgIntrospection::PropertyInfo* pi = propertyInfo(*in_edges(vd).first);
        return ((pi) ? (pi->isSimple()) : (false));
    }
    inline bool                                         CValueTree::isArray(vertex_descriptor vd) const
    {
        const osgIntrospection::PropertyInfo* pi = propertyInfo(*in_edges(vd).first);
        return ((pi) ? (pi->isArray()) : (false));
    }
    inline bool                                         CValueTree::isIndexed(vertex_descriptor vd) const
    {
        const osgIntrospection::PropertyInfo* pi = propertyInfo(*in_edges(vd).first);
        return ((pi) ? (pi->isIndexed()) : (false));
    }        
    inline bool                                         CValueTree::canAdd(vertex_descriptor vd) const
    { 
        const osgIntrospection::PropertyInfo* pi = propertyInfo(*in_edges(vd).first);
        return ((pi) ? (pi->canAdd()) : (false));
    }
    inline bool                                         CValueTree::canRemove(vertex_descriptor vd) const
    { 
        const osgIntrospection::PropertyInfo* pi = propertyInfo(*in_edges(vd).first);
        return ((pi) ? (pi->canRemove()) : (false));
    }
    inline bool                                         CValueTree::canInsert(vertex_descriptor vd) const
    { 
        const osgIntrospection::PropertyInfo* pi = propertyInfo(*in_edges(vd).first);
        return ((pi) ? (pi->canInsert()) : (false));
    }
    inline Policy                                       CValueTree::isValidIn(const osgIntrospection::Type* type) const
    {
        if (type->isDefined() == false) return (Reject);
        
        Policy result = _inTypeControlList.check(type);
        if (result == Next)
            result = _defaultInPolicy;
        
        return (result);
    }

    inline Policy                                       CValueTree::isValidThrow(const osgIntrospection::Type* type) const
    {
        if (type->isDefined() == false) return (Reject);
        
        Policy result = _throwTypeControlList.check(type);
        if (result == Next)
            result = _defaultThrowPolicy;
        
        return (result);
    }
    inline Policy                                       CValueTree::isValidThrow(const osgIntrospection::PropertyInfo* propertyInfo) const
    {
        if (propertyInfo->getPropertyType().isDefined() == false) return (Reject);

        Policy result = _throwPropertyInfoControlList.check(propertyInfo);
        if (result == Next)
        {
            result = _throwTypeControlList.check(&propertyInfo->getPropertyType());
            if (result == Next)
                result = _defaultThrowPolicy;
        }
        
        return (result); 
    }
    
    inline void                                         CValueTree::addInTypePolicy(TypeControl* tc)
    { _inTypeControlList.push_back(tc); }
    inline void                                         CValueTree::addThrowTypePolicy(TypeControl* tc)
    { _throwTypeControlList.push_back(tc); }
    inline void                                         CValueTree::addThrowPropertyInfoPolicy(PropertyInfoControl* pic)
    { _throwPropertyInfoControlList.push_back(pic); }

    
    inline void                                         CValueTree::addInTypePolicy(const std::string type, Policy policy)
    {
        const osgIntrospection::Type*   t = STypeGraph::getType(type);
        if (t) addInTypePolicy(new TypeControl(t, policy));
    }
    inline void                                         CValueTree::addThrowTypePolicy(const std::string type, Policy policy)
    {
        const osgIntrospection::Type*   t = STypeGraph::getType(type);
        if (t) addThrowTypePolicy(new TypeControl(t, policy));
    }
    inline void                                         CValueTree::addThrowPropertyInfoPolicy(const std::string type, const std::string property, Policy policy)
    {
        const osgIntrospection::PropertyInfo*   pi = STypeGraph::getPropertyInType(type, property);
        if (pi) addThrowPropertyInfoPolicy(new PropertyInfoControl(pi, policy));
    }
    
    inline void                                         CValueTree::clearInTypePolicy()
    { _inTypeControlList.clear(); }
    inline void                                         CValueTree::removeThrowTypePolicy()
    { _throwTypeControlList.clear(); }
    inline void                                         CValueTree::removeThrowPropertyInfoPolicy()
    { _throwPropertyInfoControlList.clear(); }


    inline void                                         CValueTree::disconnectClearAndRemoveVertex(vertex_descriptor vd)
    {
        _disconnect(vd);
        clear_and_remove_vertex(vd);
    }

    inline const std::string&                           CValueTree::name()
    { return (_name); }

    // ** signal interface            
    inline CValueTree::ModificationSignal&              CValueTree::beginUpdateSignal()
    { return (_beginUpdateSignal); }
    inline CValueTree::ModificationSignal&              CValueTree::endUpdateSignal()
    { return (_endUpdateSignal); }
    inline CValueTree::ModificationSignal&              CValueTree::beginRemoveSignal()
    { return (_beginRemoveSignal); }
    inline CValueTree::ModificationSignal&              CValueTree::endRemoveSignal()
    { return (_endRemoveSignal); }
    inline CValueTree::ModificationSignal&              CValueTree::beginAddSignal()
    { return (_beginAddSignal); }
    inline CValueTree::ModificationSignal&              CValueTree::endAddSignal()
    { return (_endAddSignal); }
    inline CValueTree::ResetSignal&                     CValueTree::beginResetSignal()
    { return (_beginResetSignal); }
    inline CValueTree::ResetSignal&                     CValueTree::endResetSignal()
    { return (_endResetSignal); }
}

#endif /*CVALUETREE_H_*/




See more files for this project here

osgDesigner

osgDesigner is a graphical tool used to modify an OpenSceneGraph (OSG) scene using the osgIntrospection framework. OpenSceneGraph developpers will be able to extend osgDesigner at need using (editor | render | osgIntrospection wrapper) plugin system.

Project homepage: http://sourceforge.net/projects/osgdesigner
Programming language(s): C++,Shell Script
License: other

  CArrayItemLink.h
  CIndexedItemLink.h
  CPropertyExtractor.h
  CReflectedInstance.h
  CReflectedPointer.h
  CReflectedRefPointer.h
  CReflectedValueLinkExtractor.h
  CValueTree.h
  CValueTreeFunctor.h
  CValueTreeModifier.h
  CommonStdType.h
  ControlList.h
  ExceptionUtility.h
  Export.h
  IGraph.h
  IReflectedValue.h
  IReflectedValueLink.h
  SMemoryManager.h
  STypeGraph.h
  SWrapperManager.h
  signalslib.hpp