CrystalSpace

Public API Reference

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

csutil/csevent.h

00001 /*
00002     Crystal Space 3D engine: Event class interface
00003     Written by Andrew Zabolotny <bit@eltech.ru>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CSEVENT_H__
00021 #define __CS_CSEVENT_H__
00022 
00023 #include "iutil/event.h"
00024 #include "hashmapr.h"
00025 #include "csendian.h"
00026 #include "weakref.h"
00027 
00029 enum
00030 {
00031   CS_DATATYPE_INT8 = 0x00,
00032   CS_DATATYPE_UINT8,
00033   CS_DATATYPE_INT16,
00034   CS_DATATYPE_UINT16,
00035   CS_DATATYPE_INT32,
00036   CS_DATATYPE_UINT32,
00037   CS_DATATYPE_INT64,
00038   CS_DATATYPE_UINT64,
00039   CS_DATATYPE_FLOAT,
00040   CS_DATATYPE_DOUBLE,
00041   CS_DATATYPE_BOOL,
00042   CS_DATATYPE_STRING,
00043   CS_DATATYPE_DATABUFFER,
00044   CS_DATATYPE_EVENT
00045 };
00046 
00054 class csEvent : public iEvent
00055 {
00056 private:
00057   csHashMapReversible attributes;
00058 
00059   uint32 count;
00060 
00061   bool CheckForLoops(iEvent *current, iEvent *e);
00062 
00063   bool FlattenCrystal(char *buffer);
00064   bool FlattenMuscle(char *buffer);
00065   bool FlattenXML(char *buffer);
00066 
00067   uint32 FlattenSizeCrystal();
00068   uint32 FlattenSizeMuscle();
00069   uint32 FlattenSizeXML();
00070 
00071   bool UnflattenCrystal(const char *buffer, uint32 length);
00072   bool UnflattenMuscle(const char *buffer, uint32 length);
00073   bool UnflattenXML(const char *buffer, uint32 length);
00074 
00075 protected:
00076   virtual csRef<iEvent> CreateEvent();
00077 
00078 public:
00080   csEvent ();
00081 
00086   csEvent (csEvent const&);
00087 
00089   csEvent (csTicks, int type, int x, int y, int button, int modifiers);
00090 
00092   csEvent (csTicks, int type, int n, int x, int y, int button, int modifiers);
00093 
00095   csEvent (csTicks, int type, int code, void* info = 0);
00096 
00098   virtual ~csEvent ();
00099 
00101   virtual bool Add (const char *name, int8 v);
00102   virtual bool Add (const char *name, uint8 v);
00103   virtual bool Add (const char *name, int16 v);
00104   virtual bool Add (const char *name, uint16 v);
00105   virtual bool Add (const char *name, int32 v, bool force_boolean = false);
00106   virtual bool Add (const char *name, uint32 v);
00107   virtual bool Add (const char *name, int64 v);
00108   virtual bool Add (const char *name, uint64 v);
00109   virtual bool Add (const char *name, float v);
00110   virtual bool Add (const char *name, double v);
00111   virtual bool Add (const char *name, const char *v);
00112   virtual bool Add (const char *name, const void *v, uint32 size);
00113 #ifndef CS_USE_FAKE_BOOL_TYPE
00114   virtual bool Add (const char *name, bool v, bool force_boolean = true);
00115 #endif
00116   virtual bool Add (const char *name, iEvent *v);
00117 
00119   virtual bool Find (const char *name, int8 &v, int index = 0) const;
00120   virtual bool Find (const char *name, uint8 &v, int index = 0) const;
00121   virtual bool Find (const char *name, int16 &v, int index = 0) const;
00122   virtual bool Find (const char *name, uint16 &v, int index = 0) const;
00123   virtual bool Find (const char *name, int32 &v, int index = 0) const;
00124   virtual bool Find (const char *name, uint32 &v, int index = 0) const;
00125   virtual bool Find (const char *name, int64 &v, int index = 0) const;
00126   virtual bool Find (const char *name, uint64 &v, int index = 0) const;
00127   virtual bool Find (const char *name, float &v, int index = 0) const;
00128   virtual bool Find (const char *name, double &v, int index = 0) const;
00129   virtual bool Find (const char *name, const char *&v, int index = 0) const;
00130   virtual bool Find (const char *name, const void *&v, uint32 &size, 
00131     int index = 0) const;
00132 #ifndef CS_USE_FAKE_BOOL_TYPE
00133   virtual bool Find (const char *name, bool &v, int index = 0) const;
00134 #endif
00135   virtual bool Find (const char *name, csRef<iEvent> &v, int index = 0) const;
00136 
00137   virtual bool Remove (const char *name, int index = -1);
00138   virtual bool RemoveAll ();
00139 
00140   virtual uint32 FlattenSize (int format = CS_CRYSTAL_PROTOCOL);
00141   virtual bool Flatten (char *buffer, int format = CS_CRYSTAL_PROTOCOL);
00142   virtual bool Unflatten (const char *buffer, uint32 length);
00143 
00144   virtual bool Print (int level = 0);
00145 
00146   SCF_DECLARE_IBASE;
00147 };
00148 
00156 class csPoolEvent : public csEvent
00157 {
00158   typedef csEvent superclass;
00159   friend class csEventQueue;
00160   friend class csEvent;
00161 
00162 private:
00163   // As per the XML pool, keep a reference to the pool container obejct
00164   // and this also allows our overridden DecRef() to place the event back
00165   // into the pool when users are done with it.
00166   csWeakRef<csEventQueue> pool;
00167 
00168   // The next event in the pool, or null if the event is in use.
00169   csPoolEvent *next;
00170 
00171   // The 'real' DecRef() call that deletes the event, should in theory only be
00172   // called from csEventQueue.
00173   void Free () { csEvent::DecRef(); }
00174 
00175 protected:
00176   virtual csRef<iEvent> CreateEvent();
00177 
00178 public:
00180   csPoolEvent (csEventQueue *q);
00181 
00183   virtual void DecRef ();
00184 };
00185 
00186 #endif // __CS_CSEVENT_H__

Generated for Crystal Space by doxygen 1.2.18