LibCT 2.0

Include/Node.h

Go to the documentation of this file.
00001 // ------------------------------------------------------------------
00012 #ifndef _LIBCT_NODE_H
00013 #define _LIBCT_NODE_H
00014 
00015 #include "NodeTypes.h"
00016 
00017 #include <string>
00018 #include <vector>
00019 #include <fstream>
00020 
00021 namespace LibCT
00022 {
00024         class ConversationNode;
00025         class EventType;
00026         class InputStream;
00027         class OutputStream;
00028 
00030         class Node
00031         {
00032         public:
00033                 static const unsigned int MAX_CONNECTIONS = 2;  
00034                 static const unsigned int MAX_EVENTS = 4;               
00035 
00038                 static Node* Create(InputStream* pInput, Node* pParent);
00039 
00041                 Node(
00042                         Node* pParent,                  
00043                         NodeType type,                  
00044                         const std::string text  
00045                         );
00046 
00048                 virtual ~Node();
00049 
00052                 bool Serialise(InputStream* pInput);
00053 
00056                 bool Serialise(OutputStream* pOutput);
00057 
00060                 virtual bool SerialiseImpl(InputStream* pInput);
00061 
00064                 virtual bool SerialiseImpl(OutputStream* pOutput);
00065 
00068                 inline Node* GetParent() const { return m_pParent; }
00069 
00072                 inline NodeType GetType() const { return m_Type; }
00073 
00076                 inline std::string GetText() const { return m_Text; }
00077 
00079                 inline void SetText(const std::string& text) { m_Text = text; }
00080 
00082                 const std::string& GetParsedText();
00083 
00085                 void AddChild(
00086                         Node* pNode,            
00087                         int index = -1          
00088                         );
00089 
00091                 void RemoveChild(
00092                         Node* pNode                     
00093                         );
00094 
00097                 Node* GetChildByIndex(
00098                         unsigned int index      
00099                         ) const;
00100 
00103                 Node* GetChildById(
00104                         NodeId                          
00105                         ) const;
00106 
00109                 inline unsigned int GetNumChildren() const;
00110 
00113                 bool IsChildNode(
00114                         Node* pNode                     
00115                         ) const;
00116 
00119                 int GetChildIndex(
00120                         Node*                           
00121                         ) const;
00122 
00125                 inline NodeId GetId() const { return m_Id; }
00126 
00129                 inline ConversationNode* GetRoot() const { return m_pRoot; }
00130 
00133                 virtual Node* GetNext();
00134 
00136                 void ConnectTo(
00137                         Node* pNode,            
00138                         unsigned int index      
00139                         );
00140 
00143                 Node* GetConnection(
00144                         unsigned int index      
00145                         ) const;
00146 
00149                 EventType* GetEvent(
00150                         unsigned int index      
00151                         ) const;
00152 
00154                 void SetEvent(
00155                         unsigned int index,                             
00156                         const std::string& eventName    
00157                         );
00158 
00159         protected:
00160                 NodeId                          m_Id;                                                   
00161                 Node*                           m_pParent;                                              
00162                 ConversationNode*       m_pRoot;                                                
00163                 Node*                           m_pConnected[MAX_CONNECTIONS];  
00164                 EventType*                      m_pEvents[MAX_EVENTS];                  
00165                 NodeType                        m_Type;                                                 
00166                 std::string                     m_Text;                                                 
00167                 std::string                     m_ParsedText;                                   
00168                 NodeList                        m_Children;                                             
00169 
00171                 void SetParent(
00172                         Node* pNode                             
00173                         );
00174 
00177                 inline void SetId(NodeId id) { m_Id = id; }
00178 
00181                 bool SerialiseConnections(InputStream* pInput);
00182 
00185                 bool SerialiseConnections(OutputStream* pOutput);
00186 
00188                 void FireEvent(
00189                         unsigned int index              
00190                         ) const;
00191         };
00192 }
00193 
00194 #endif // _LIBCT_NODE_H