Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List

Message.h

Go to the documentation of this file.
00001 /*
00002 Copyright 2003 - 2005 Elliott Kleinrock, Dan Neely, Kurt W. Over, Damon Domjan
00003 
00004 This file is part of FreeStars, a free clone of the Stars! game.
00005 
00006 FreeStars is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 FreeStars is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with FreeStars; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 The full GPL Copyright notice should be in the file COPYING.txt
00021 
00022 Contact:
00023 Email Elliott at 9jm0tjj02@sneakemail.com
00024 */
00025 
00030 #if !defined(Message_h)
00031 #define Message_h
00032 
00033 #include <string>
00034 using namespace std;
00035 
00036 class Location;
00037 class Player;
00038 
00039 class MessItem {
00040 public:
00041         virtual ~MessItem();
00042         virtual void WriteNode(TiXmlNode * node) const = 0;
00043         virtual string ToString() const = 0;
00044         void AddDesc(TiXmlElement * node) const;
00045         static MessItem * ParseNode(const TiXmlNode * node);
00046 
00047 protected:
00048         string mDesc;
00049         MessItem(const char * d) : mDesc(d) {}
00050 };
00051 
00052 class MessLoc : public MessItem {
00053 public:
00054         MessLoc(const char * d, const Location * loc, bool dwd = false) : MessItem(d), mLoc(loc), mDWD(dwd) {}
00055         virtual ~MessLoc();
00056         virtual void WriteNode(TiXmlNode * node) const;
00057         virtual string ToString() const;
00058         static MessLoc * ParseNode(const TiXmlNode * node);
00059         bool StoreMessageLocation(const Location * loc);
00060 
00061 private:
00062         const Location * mLoc;
00063         bool mDWD;      // Delete When Done
00064 };
00065 
00066 
00067 class MessPlayer : public MessItem {
00068 public:
00069         MessPlayer(const char * d, const Player * player) : MessItem(d) { mPlayer = player; }
00070         virtual ~MessPlayer();
00071         virtual void WriteNode(TiXmlNode * node) const;
00072         virtual string ToString() const;
00073         static MessPlayer * ParseNode(const TiXmlNode * node);
00074 
00075 private:
00076         const Player * mPlayer;
00077 };
00078 
00079 
00080 class MessNumber : public MessItem {
00081 public:
00082         MessNumber(const char * d, long number) : MessItem(d)                   { mNumber = number; }
00083         virtual ~MessNumber();
00084         virtual void WriteNode(TiXmlNode * node) const;
00085         virtual string ToString() const;
00086         static MessNumber * ParseNode(const TiXmlNode * node);
00087 
00088 private:
00089         long mNumber;
00090 };
00091 
00092 
00093 class MessFloat : public MessItem {
00094 public:
00095         MessFloat(const char * d, double number) : MessItem(d)                  { mNumber = number; }
00096         virtual ~MessFloat();
00097         virtual void WriteNode(TiXmlNode * node) const;
00098         virtual string ToString() const;
00099         static MessFloat * ParseNode(const TiXmlNode * node);
00100 
00101 private:
00102         double mNumber;
00103 };
00104 
00105 
00106 class MessString : public MessItem {
00107 public:
00108         MessString(const char * d, string str) : MessItem(d)                    { mStr = str; }
00109         virtual ~MessString();
00110         virtual void WriteNode(TiXmlNode * node) const;
00111         virtual string ToString() const;
00112         static MessString * ParseNode(const TiXmlNode * node);
00113 
00114 private:
00115         string mStr;
00116 };
00117 
00118 
00119 class Message {
00120 public:
00121         Message(string type, const Location * loc) : mType(type) { AddItem("", loc); }
00122         Message(string type) : mType(type) {}
00123         Message() {}
00124         ~Message();
00125         void AddItem(const char * d, const Location * loc, bool dwd = false)    { AddItem(new MessLoc(d, loc, dwd)); }
00126         void AddItem(const char * d, const Player * player)     { AddItem(new MessPlayer(d, player)); }
00127         void AddItem(const char * d, string str)                        { AddItem(new MessString(d, str)); }
00128         void AddLong(const char * d, long number)                       { AddItem(new MessNumber(d, number)); }
00129         void AddFloat(const char * d, double number)            { AddItem(new MessFloat(d, number)); }
00130         void StoreMessageLocation(const Location * loc, const Player * player);
00131 
00132         bool IsType(const char * t)                     { return mType.find(t) >= 0; }
00133         void WriteNode(TiXmlNode * node) const;
00134         bool ParseNode(const TiXmlNode * node);
00135         string ToString() const;
00136 
00137 private:
00138         string mType;
00139         void AddItem(MessItem * mi);
00140         deque<MessItem *> mItems;
00141 };
00142 
00143 #endif // !defined(Message_h)

Generated on Mon Aug 8 21:33:43 2005 for Freestars by  doxygen 1.4.2-20050421