Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/messagecontext.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001-2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 
00024 #ifndef _MESSAGECONTEXT_HH_
00025 #define _MESSAGECONTEXT_HH_
00026 
00027 #include <vos/corelibs/vos/vosdefs.hh>
00028 #include <vos/corelibs/vos/refcount.hh>
00029 
00030 #include <stdexcept>
00031 #include <map>
00032 
00033 namespace VOS
00034 {
00035     class Message;
00036 
00037 /** A message substitution context. */
00038 class VOS_API MessageContext : public virtual RefCounted
00039 {
00040 private:
00041     MessageContext* parentcontext;
00042     map<string, string> parameters;
00043     map<string, Message*> reply_record;
00044 public:
00045     class NoSuchParameterError : public runtime_error {
00046     public:
00047         NoSuchParameterError(const string& s) : runtime_error(s) { };
00048     };
00049 
00050     MessageContext();
00051     ~MessageContext();
00052 
00053     void setParentContext(MessageContext* mc);
00054 
00055 /** Get the parent (enclosing) context.
00056     @return the parent context, if any, or 0.  NOTE YOU MUST CALL release() WHEN DONE OR USE A pREF() BLOCK  */
00057     MessageContext* getParentContext();
00058 
00059     /** Do substitutions on a string based on this (and enclosing) contexts.
00060         @param s the string to substitute into (will be changed!)
00061         @param p offset to start processing (used internally)
00062     */
00063     void doSubstitution(string& s, unsigned int p=0);
00064 
00065     /** Set a substitution parameter.
00066         @param p the parameter name or key
00067         @param v the value to be substituted
00068      */
00069     void setParameter(const string& p, const string& v);
00070 
00071     /** Get a substitution parameter.
00072         @param p the parameter name or key
00073         @return the value to be substituted
00074         @throw NoSuchParameterError if there is no such parameter
00075      */
00076     string getParameter(const string& p) throw (NoSuchParameterError);
00077 
00078     /** The reply record is a record of our outgoing replies to method
00079         calls that we have received from others.  We collect these
00080         replies in the reply record for the purpose of doing
00081         substitutions using on the contents of these messages.
00082         @param m the message to add
00083      */
00084     void addToReplyRecord(Message* m);
00085 
00086     /** Tests to see if the reply record contains a message with a certain nonce.
00087         @param s the nonce
00088         @return whether a messages matches that nonce or not
00089     */
00090     bool replyRecordContains(const string& s);
00091 
00092     /** Retrieve a message from the reply record, given a nonce.
00093         @param s the nonce string
00094         @return the message nonce requested, or 0 if not found.
00095         NOTE YOU MUST CALL release() WHEN DONE OR USE A pREF() BLOCK
00096      */
00097     Message* getFromReplyRecord(const string& s);
00098 
00099     /** Remove a message from the reply record.
00100         @param m the message to be removed
00101      */
00102     void removeFromReplyRecord(Message* m);
00103 };
00104 }
00105 
00106 #endif

Generated on Tue Aug 12 03:55:40 2003 for Interreality Project - VOS by doxygen 1.3.2