Node.h

Go to the documentation of this file.
00001 /* ========================================================================
00002  * Copyright (c) 2006,
00003  * Institute for Computer Graphics and Vision
00004  * Graz University of Technology
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  * Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the following disclaimer.
00013  *
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the distribution.
00017  *
00018  * Neither the name of the Graz University of Technology nor the names of
00019  * its contributors may be used to endorse or promote products derived from
00020  * this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00023  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00024  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00026  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  * ========================================================================
00034  * PROJECT: OpenTracker
00035  * ======================================================================== */
00043 /* ======================================================================= */
00044 
00045 #ifndef _NODE_H
00046 #define _NODE_H
00047 
00048 #include "../dllinclude.h"
00049 
00059 #include <string>
00060 #include <vector>
00061 
00062 namespace ot {
00063 
00064     class Context;
00065     class ConfigurationParser;
00066     class Node;
00067     class NodePort;
00068 
00069 #ifdef USE_LIVE
00070     class LiveContext;
00071 #endif
00072 
00073 } // namespace ot
00074 
00075 #include "StringTable.h"
00076 #include <OpenTracker/core/IRefCounted.h>
00077 #include <OpenTracker/misc/Cptr.h>
00078 
00079 #include "Event.h"
00080 #ifdef USE_LIVE
00081 #include <OpenTracker/skeletons/OTGraph.hh>
00082 #endif
00083 
00084 namespace ot {
00085 
00086 
00087 
00096 #ifdef USE_LIVE
00097     class OPENTRACKER_API Node : public POA_OTGraph::Node,
00098                                  public PortableServer::RefCountServantBase
00099 #else
00100     class OPENTRACKER_API Node
00101 #endif
00102     {
00103         
00104 
00105     public:
00106 #ifdef USE_LIVE
00107         typedef Node* Ptr;
00108 #else
00109         OT_DECLARE_IREFCOUNTED;
00110         typedef Cptr<Node> Ptr;
00111 #endif
00112 
00117     typedef std::vector<Ptr> NodeVector;
00118 
00119     protected:
00123         NodeVector parents;
00124         NodeVector children;
00125 
00126         StringTable attributes;
00127 
00131 
00132         std::string name;
00133         
00134 
00136         std::string type;
00137 
00138     public:
00140         enum error { OK=0,                              
00141                      GRAPH_CONSTRAINT,  
00142                      READONLY,                  
00143                      CONTEXT_ERROR,             
00144                      NOT_FOUND                  
00145         };
00146 
00147     protected:
00148 
00149 
00150     public:        
00151 
00160         Node();
00161 
00169 
00170 
00174         const std::string get( const std::string & key ) const;
00184         int get(const std::string & key, int * value, int len = 1 ) ;
00194         int get(const std::string & key, float * value, int len = 1 ) ;
00204         int get(const std::string & key, double * value, int len = 1 ) ;
00205 
00210         void put( const std::string &key, const std::string &value );
00214         void remove( const std::string &key );
00215 
00222         void put(const std::string & key, const int value);
00229         void put(const std::string & key, const float value);
00236         void put(const std::string & key, const double value);
00237 
00246         void put(const std::string & key, const int * value, int len);
00255         void put(const std::string & key, const float * value, int len);
00264         void put(const std::string & key, const double * value, int len);
00266 
00267     public:
00268 
00272         virtual ~Node();
00273 
00280         const std::string & getType() const
00281         {
00282             return type;
00283         }
00284 
00290         const std::string & getName() const
00291         {
00292             return name;
00293         }
00294 
00295         void setName(const std::string & name_){
00296             name = name_;
00297         }
00298 
00303         Context * getContext() const;
00304 
00309 
00310    
00319         Node * getParent();
00320 
00326         Node * getParent( unsigned int index);
00327 
00332         unsigned int countParents();
00337         unsigned int countChildren();
00338 
00339 
00340 
00347         Node * getChild( unsigned int index );
00348 
00355         error addChild(Node & child);
00356 
00364         error removeChild(Node & child);
00365 
00366 
00372         unsigned int countPorts();
00373 #ifdef USE_LIVE
00374         char* get_type();
00375         char* get_name();
00376         char* get_id();
00377         char* get_attribute(const char* _key);
00378         OTGraph::StringTable* get_attributes();
00379 #endif
00380         
00381 
00389         NodePort * getPort( const std::string & name, unsigned int index = 0 );
00390 
00397         NodePort * getPort( unsigned int index );
00398 
00405         error addPort( const std::string & name );
00406 
00414         error removePort( const std::string & name );
00415 
00416         error removePort( NodePort & port);
00417 
00418         error removePort( unsigned int index );
00419 
00421 
00429 
00437         virtual int isEventGenerator()
00438         {
00439             return 0;
00440         }
00441 
00450         virtual void onEventGenerated( Event& event, Node& generator)
00451         {
00452         }
00453 
00460         void updateObservers( Event &data );
00461 
00463 
00472 
00479         virtual int isEventQueue()
00480         {
00481             return 0;
00482         }
00489         virtual Event& getEvent(unsigned int index = 0)
00490         {
00491             return Event::null;
00492         }
00497         virtual Event& getEventNearTime(double time)
00498         {
00499             return Event::null;
00500         }
00504         virtual unsigned int getSize()
00505         {
00506             return 0;
00507         }
00508 
00510 
00517 
00524         virtual int isTimeDependend()
00525         {
00526             return 0;
00527         }
00528 
00534         virtual Event& getEventAtTime(double time)
00535         {
00536             return Event::null;
00537         }
00538 
00540 
00548         virtual int isNodePort()
00549         {
00550             return 0;
00551         }
00552 
00553         
00554 
00559         Node * findNode(const std::string & key, const std::string & val);
00560           
00561        // adds a parent to this node. Because the new implementation 
00562        // is a graph, any given child can have more than one parent.
00563         void addParent( Node * parent);
00564 
00569         unsigned int countAllChildren();
00570 
00575         Node * getAnyChild( unsigned int index);
00576 
00577         StringTable & getAttributes();
00578 
00579 
00580 
00581         friend class Context;
00582 
00583 #ifdef USE_LIVE
00584         friend class LiveContext;
00585 #endif
00586     };
00587 
00588 } // namespace ot
00589 
00590 #endif
00591 
00592 /* 
00593  * ------------------------------------------------------------
00594  *   End of Node.h
00595  * ------------------------------------------------------------
00596  *   Automatic Emacs configuration follows.
00597  *   Local Variables:
00598  *   mode:c++
00599  *   c-basic-offset: 4
00600  *   eval: (c-set-offset 'substatement-open 0)
00601  *   eval: (c-set-offset 'case-label '+)
00602  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00603  *   eval: (setq indent-tabs-mode nil)
00604  *   End:
00605  * ------------------------------------------------------------ 
00606  */

Generated on Wed Feb 28 15:18:48 2007 for NaviTrack by  doxygen 1.4.6