/usr/include/crystalspace-2.0/csutil/csevent.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | /*
Crystal Space 3D engine: Event class interface
Written by Andrew Zabolotny <bit@eltech.ru>, Jonathan Tarbox,
Frank Richter, Adam D. Bradley <artdodge@cs.bu.edu>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_CSEVENT_H__
#define __CS_CSEVENT_H__
#include "csextern.h"
#include "csutil/hash.h"
#include "csutil/strset.h"
#include "csutil/scf_implementation.h"
#include "csutil/weakref.h"
#include "iutil/event.h"
#include "hashr.h"
#include "csendian.h"
#include "weakref.h"
#include "cseventq.h"
#include "strset.h"
#include "eventnames.h"
class csEventQueue;
/**\file
* Implementation for iEvent
*/
class csEventAttributeIterator;
class csEvent;
/**
* This class represents a system event.<p>
* Events can be generated by hardware (keyboard, mouse)
* as well as by software. There are so much constructors of
* this class as much different types of events exists.
*/
class CS_CRYSTALSPACE_EXPORT csEvent : public scfImplementation1<csEvent, iEvent>
{
private:
struct attribute
{
union
{
int64 intVal;
double doubleVal;
char* bufferVal;
iBase* ibaseVal;
void* rawPtr;
};
csEventAttributeType type;
size_t dataSize;
attribute (csEventAttributeType t) { type = t; }
attribute (const attribute &o)
{
type = o.type;
intVal = o.intVal;
dataSize = o.dataSize;
if ((o.type == csEventAttrEvent) || (o.type == csEventAttriBase))
ibaseVal->IncRef();
if (type == csEventAttrDatabuffer)
{
bufferVal = new char[dataSize];
memcpy(bufferVal, o.bufferVal,dataSize);
}
}
~attribute ()
{
if (type == csEventAttrDatabuffer)
delete[] bufferVal;
else if ((type == csEventAttrEvent) || (type == csEventAttriBase))
ibaseVal->DecRef();
}
};
csHash<attribute*, csStringID> attributes;
friend class csEventAttributeIterator;
size_t count;
bool CheckForLoops(iEvent *current, iEvent *e);
template <class T>
bool InternalAddInt (const char* name, T value)
{
if (attributes.In (GetKeyID (name))) return false;
attribute* object = new attribute (csEventAttrInt);
object->intVal = (int64)value;
attributes.Put (GetKeyID (name), object);
count++;
return true;
}
template <class T>
bool InternalAddUInt (const char* name, T value)
{
if (attributes.In (GetKeyID (name))) return false;
attribute* object = new attribute (csEventAttrUInt);
object->intVal = (int64)value;
attributes.Put (GetKeyID (name), object);
count++;
return true;
}
csEventError InternalReportMismatch (attribute* attr) const
{
switch (attr->type)
{
case csEventAttrInt:
return csEventErrMismatchInt;
case csEventAttrUInt:
return csEventErrMismatchUInt;
case csEventAttrFloat:
return csEventErrMismatchFloat;
case csEventAttrDatabuffer:
return csEventErrMismatchBuffer;
case csEventAttrEvent:
return csEventErrMismatchEvent;
case csEventAttriBase:
return csEventErrMismatchIBase;
default:
break;
}
return csEventErrUhOhUnknown;
}
template <class T>
csEventError InternalRetrieveInt (const char* name, T& value) const
{
attribute* object = attributes.Get (GetKeyID (name), 0);
if (!object) return csEventErrNotFound;
if ((object->type == csEventAttrInt) || (object->type == csEventAttrUInt))
{
value = (T)object->intVal;
const T rangeMin = (T)(1 << (sizeof(T) * 8 - 1));
const T rangeMax = ~rangeMin;
if ((object->intVal < rangeMin) || (object->intVal > rangeMax))
return csEventErrLossy;
else
return csEventErrNone;
}
else
{
return InternalReportMismatch (object);
}
}
template <class T>
csEventError InternalRetrieveUint (const char* name, T& value) const
{
attribute* object = attributes.Get (GetKeyID (name), 0);
if (!object) return csEventErrNotFound;
if ((object->type == csEventAttrInt) || (object->type == csEventAttrUInt))
{
value = (T)object->intVal;
const T rangeMax = (T)~0;
if ((uint64)object->intVal > rangeMax)
return csEventErrLossy;
else
return csEventErrNone;
}
else
{
return InternalReportMismatch (object);
}
}
static char const* GetTypeName (csEventAttributeType t);
static csStringID GetKeyID (const char* key);
static const char* GetKeyName (csStringID id);
protected:
virtual csRef<iEvent> CreateEvent();
public:
/// Empty initializer
csEvent ();
/**
* Cloning constructor. Note that for command style events, this performs
* only a shallow copy of the `Info' attribute.
*/
csEvent (csEvent const&);
/**
* Basic constructor.
*/
csEvent (csTicks iTime, csEventID iName, bool iBroadcast);
/// Destructor
virtual ~csEvent ();
/// Return the event's name
const csEventID GetName();
/// Add a named parameter and typed value
#define CS_CSEVENT_ADDINT(type) \
virtual bool Add (const char* name, type value) \
{ return InternalAddInt (name, value); }
CS_CSEVENT_ADDINT(int8)
CS_CSEVENT_ADDINT(int16)
CS_CSEVENT_ADDINT(int32)
CS_CSEVENT_ADDINT(int64)
#undef CS_CSEVENT_ADDINT
#define CS_CSEVENT_ADDUINT(type) \
virtual bool Add (const char* name, type value) \
{ return InternalAddUInt (name, value); }
CS_CSEVENT_ADDUINT(uint8)
CS_CSEVENT_ADDUINT(uint16)
CS_CSEVENT_ADDUINT(uint32)
CS_CSEVENT_ADDUINT(uint64)
#undef CS_CSEVENT_ADDUINT
virtual bool Add (const char *name, float v);
virtual bool Add (const char *name, double v);
virtual bool Add (const char *name, const char *v);
virtual bool Add (const char *name, const void *v, size_t size);
virtual bool Add (const char *name, bool v);
virtual bool Add (const char *name, iEvent* v);
virtual bool Add (const char *name, iBase* v);
virtual bool Add (const char *name, void *v);
/// Find a named event for a given type.
#define CS_CSEVENT_FINDINT(T) \
virtual csEventError Retrieve (const char* name, T& value) const \
{ return InternalRetrieveInt (name, value); }
CS_CSEVENT_FINDINT(int8)
CS_CSEVENT_FINDINT(int16)
CS_CSEVENT_FINDINT(int32)
#undef CS_CSEVENT_FINDINT
virtual csEventError Retrieve (const char* name, int64& value) const
{
attribute* object = attributes.Get (GetKeyID (name), 0);
if (!object) return csEventErrNotFound;
if ((object->type == csEventAttrInt) || (object->type == csEventAttrUInt))
{
value = object->intVal;
return csEventErrNone;
}
else
{
return InternalReportMismatch (object);
}
}
#define CS_CSEVENT_FINDUINT(T) \
virtual csEventError Retrieve (const char* name, T& value) const \
{ return InternalRetrieveUint (name, value); }
CS_CSEVENT_FINDUINT(uint8)
CS_CSEVENT_FINDUINT(uint16)
CS_CSEVENT_FINDUINT(uint32)
#undef CS_CSEVENT_FINDUINT
virtual csEventError Retrieve (const char* name, uint64& value) const
{
attribute* object = attributes.Get (GetKeyID (name), 0);
if (!object) return csEventErrNotFound;
if ((object->type == csEventAttrInt) || (object->type == csEventAttrUInt))
{
value = (uint64)object->intVal;
return csEventErrNone;
}
else
{
return InternalReportMismatch (object);
}
}
virtual csEventError Retrieve (const char *name, float &v) const;
virtual csEventError Retrieve (const char *name, double &v) const;
virtual csEventError Retrieve (const char *name, const char *&v) const;
virtual csEventError Retrieve (const char *name, const void *&v,
size_t &size) const;
virtual csEventError Retrieve (const char *name, bool &v) const;
virtual csEventError Retrieve (const char *name, csRef<iEvent> &v) const;
virtual csEventError Retrieve (const char *name, csRef<iBase> &v) const;
virtual csEventError Retrieve (const char *name, void* &v) const;
virtual bool AttributeExists (const char* name);
virtual csEventAttributeType GetAttributeType (const char* name);
virtual bool Remove (const char *name);
virtual bool RemoveAll ();
virtual csRef<iEventAttributeIterator> GetAttributeIterator();
virtual bool Print (int level = 0);
};
/**
* This class is a system event designed for the pool system<p>
* Due to the possibilities of networking traffic and other assorted
* events traversing the event system, a more efficient method of
* event creation was needed. Thus, the event pool was born, and
* there are the events that reside within it.
*/
class CS_CRYSTALSPACE_EXPORT csPoolEvent : public csEvent
{
typedef csEvent superclass;
friend class csEventQueue;
friend class csEvent;
private:
// As per the XML pool, keep a reference to the pool container obejct
// and this also allows our overridden DecRef() to place the event back
// into the pool when users are done with it.
csWeakRef<csEventQueue> pool;
// The next event in the pool, or null if the event is in use.
csPoolEvent *next;
// The 'real' DecRef() call that deletes the event, should in theory only be
// called from csEventQueue.
void Free () { csEvent::DecRef(); }
protected:
virtual csRef<iEvent> CreateEvent();
public:
/// The constructor; should only be called from within csEventQueue.
csPoolEvent (csEventQueue *q);
/// Places the event back into the pool if this is the last reference.
virtual void DecRef ();
};
/**
* \internal csEvent attribute iterator
*/
class csEventAttributeIterator :
public scfImplementation1<csEventAttributeIterator, iEventAttributeIterator>
{
csHash<csEvent::attribute*, csStringID>::GlobalIterator iterator;
public:
csEventAttributeIterator (
csHash<csEvent::attribute*, csStringID>::GlobalIterator& iter)
: scfImplementationType (this), iterator(iter)
{
}
virtual ~csEventAttributeIterator()
{
}
virtual bool HasNext()
{
return iterator.HasNext();
}
virtual const char* Next();
virtual void Reset()
{
iterator.Reset();
}
};
#endif // __CS_CSEVENT_H__
|