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 "csextern.h" 00024 #include "iutil/event.h" 00025 #include "hashmapr.h" 00026 #include "csendian.h" 00027 #include "weakref.h" 00028 #include "cseventq.h" 00029 00031 enum 00032 { 00033 CS_DATATYPE_INT8 = 0x00, 00034 CS_DATATYPE_UINT8, 00035 CS_DATATYPE_INT16, 00036 CS_DATATYPE_UINT16, 00037 CS_DATATYPE_INT32, 00038 CS_DATATYPE_UINT32, 00039 CS_DATATYPE_INT64, 00040 CS_DATATYPE_UINT64, 00041 CS_DATATYPE_FLOAT, 00042 CS_DATATYPE_DOUBLE, 00043 CS_DATATYPE_BOOL, 00044 CS_DATATYPE_STRING, 00045 CS_DATATYPE_DATABUFFER, 00046 CS_DATATYPE_EVENT 00047 }; 00048 00056 class CS_CSUTIL_EXPORT csEvent : public iEvent 00057 { 00058 private: 00059 csHashMapReversible attributes; 00060 00061 uint32 count; 00062 00063 bool CheckForLoops(iEvent *current, iEvent *e); 00064 00065 bool FlattenCrystal(char *buffer); 00066 bool FlattenMuscle(char *buffer); 00067 bool FlattenXML(char *buffer); 00068 00069 uint32 FlattenSizeCrystal(); 00070 uint32 FlattenSizeMuscle(); 00071 uint32 FlattenSizeXML(); 00072 00073 bool UnflattenCrystal(const char *buffer, uint32 length); 00074 bool UnflattenMuscle(const char *buffer, uint32 length); 00075 bool UnflattenXML(const char *buffer, uint32 length); 00076 00077 protected: 00078 virtual csRef<iEvent> CreateEvent(); 00079 00080 public: 00082 csEvent (); 00083 00088 csEvent (csEvent const&); 00089 00091 csEvent (csTicks, int type, int x, int y, int button, int modifiers); 00092 00094 csEvent (csTicks, int type, int n, int x, int y, int button, int modifiers); 00095 00097 csEvent (csTicks, int type, int code, void* info = 0); 00098 00100 virtual ~csEvent (); 00101 00103 virtual bool Add (const char *name, int8 v); 00104 virtual bool Add (const char *name, uint8 v); 00105 virtual bool Add (const char *name, int16 v); 00106 virtual bool Add (const char *name, uint16 v); 00107 virtual bool Add (const char *name, int32 v, bool force_boolean = false); 00108 virtual bool Add (const char *name, uint32 v); 00109 virtual bool Add (const char *name, int64 v); 00110 virtual bool Add (const char *name, uint64 v); 00111 virtual bool Add (const char *name, float v); 00112 virtual bool Add (const char *name, double v); 00113 virtual bool Add (const char *name, const char *v); 00114 virtual bool Add (const char *name, const void *v, uint32 size); 00115 #ifndef CS_USE_FAKE_BOOL_TYPE 00116 virtual bool Add (const char *name, bool v, bool force_boolean = true); 00117 #endif 00118 virtual bool Add (const char *name, iEvent *v); 00119 00121 virtual bool Find (const char *name, int8 &v, int index = 0) const; 00122 virtual bool Find (const char *name, uint8 &v, int index = 0) const; 00123 virtual bool Find (const char *name, int16 &v, int index = 0) const; 00124 virtual bool Find (const char *name, uint16 &v, int index = 0) const; 00125 virtual bool Find (const char *name, int32 &v, int index = 0) const; 00126 virtual bool Find (const char *name, uint32 &v, int index = 0) const; 00127 virtual bool Find (const char *name, int64 &v, int index = 0) const; 00128 virtual bool Find (const char *name, uint64 &v, int index = 0) const; 00129 virtual bool Find (const char *name, float &v, int index = 0) const; 00130 virtual bool Find (const char *name, double &v, int index = 0) const; 00131 virtual bool Find (const char *name, const char *&v, int index = 0) const; 00132 virtual bool Find (const char *name, const void *&v, uint32 &size, 00133 int index = 0) const; 00134 #ifndef CS_USE_FAKE_BOOL_TYPE 00135 virtual bool Find (const char *name, bool &v, int index = 0) const; 00136 #endif 00137 virtual bool Find (const char *name, csRef<iEvent> &v, int index = 0) const; 00138 00139 virtual bool Remove (const char *name, int index = -1); 00140 virtual bool RemoveAll (); 00141 00142 virtual uint32 FlattenSize (int format = CS_CRYSTAL_PROTOCOL); 00143 virtual bool Flatten (char *buffer, int format = CS_CRYSTAL_PROTOCOL); 00144 virtual bool Unflatten (const char *buffer, uint32 length); 00145 00146 virtual bool Print (int level = 0); 00147 00148 SCF_DECLARE_IBASE; 00149 }; 00150 00158 class CS_CSUTIL_EXPORT csPoolEvent : public csEvent 00159 { 00160 typedef csEvent superclass; 00161 friend class csEventQueue; 00162 friend class csEvent; 00163 00164 private: 00165 // As per the XML pool, keep a reference to the pool container obejct 00166 // and this also allows our overridden DecRef() to place the event back 00167 // into the pool when users are done with it. 00168 csWeakRef<csEventQueue> pool; 00169 00170 // The next event in the pool, or null if the event is in use. 00171 csPoolEvent *next; 00172 00173 // The 'real' DecRef() call that deletes the event, should in theory only be 00174 // called from csEventQueue. 00175 void Free () { csEvent::DecRef(); } 00176 00177 protected: 00178 virtual csRef<iEvent> CreateEvent(); 00179 00180 public: 00182 csPoolEvent (csEventQueue *q); 00183 00185 virtual void DecRef (); 00186 }; 00187 00188 #endif // __CS_CSEVENT_H__
Generated for Crystal Space by doxygen 1.2.18