KGamePropertyBase Class Reference

#include <kgameproperty.h>

Inheritance diagram for KGamePropertyBase:

KGameProperty< type > List of all members.

Detailed Description

Base class of KGameProperty.

The KGamePropertyBase class is the base class of KGameProperty. See KGameProperty for further information.

Author:
Andreas Beckermann <b_mann@gmx.de>

Definition at line 42 of file kgameproperty.h.


Public Types

enum  PropertyDataIds {
  IdGroup = 1, IdUserId = 2, IdAsyncInput = 3, IdTurn = 4,
  IdName = 5, IdGameStatus = 6, IdMaxPlayer = 7, IdMinPlayer = 8,
  IdGrabInput = 16, IdReleaseInput = 17, IdCommand, IdUser = 256,
  IdAutomatic = 0x7000
}
enum  PropertyCommandIds {
  CmdLock = 1, CmdAt = 51, CmdResize = 52, CmdFill = 53,
  CmdSort = 54, CmdInsert = 61, CmdAppend = 62, CmdRemove = 63,
  CmdClear = 64
}
enum  PropertyPolicy { PolicyUndefined = 0, PolicyClean = 1, PolicyDirty = 2, PolicyLocal = 3 }

Public Member Functions

 KGamePropertyBase (int id, KGamePropertyHandler *owner)
 KGamePropertyBase (int id, KGame *parent)
 KGamePropertyBase (int id, KPlayer *parent)
 KGamePropertyBase ()
void setPolicy (PropertyPolicy p)
PropertyPolicy policy () const
void setEmittingSignal (bool p)
bool isEmittingSignal () const
void setOptimized (bool p)
bool isOptimized () const
bool isDirty () const
bool isLocked () const
bool lock ()
bool unlock (bool force=false)
virtual void load (QDataStream &s)=0
virtual void save (QDataStream &s)=0
virtual void command (QDataStream &stream, int msgid, bool isSender=false)
int id () const
virtual const type_info * typeinfo ()
int registerData (int id, KGamePropertyHandler *owner, PropertyPolicy p, QString name=0)
int registerData (int id, KGamePropertyHandler *owner, QString name=0)
int registerData (int id, KGame *owner, QString name=0)
int registerData (int id, KPlayer *owner, QString name=0)
int registerData (KGamePropertyHandler *owner, PropertyPolicy p=PolicyUndefined, QString name=0)
void unregisterData ()

Protected Member Functions

void setLock (bool l)
void setDirty (bool d)
bool sendProperty ()
bool sendProperty (const QByteArray &b)
void emitSignal ()

Protected Attributes

KGamePropertyHandlermOwner
KGamePropertyBase::Flags mFlags

Friends

class KGamePropertyHandler

Member Enumeration Documentation

enum KGamePropertyBase::PropertyCommandIds
 

Commands for advanced properties (Q_INT8).

Definition at line 71 of file kgameproperty.h.

enum KGamePropertyBase::PropertyPolicy
 

The policy of the property.

This can be PolicyClean (setValue uses send), PolicyDirty (setValue uses changeValue) or PolicyLocal (setValue uses setLocal).

A "clean" policy means that the property is always the same on every client. This is achieved by calling send which actually changes the value only when the message from the MessageServer is received.

A "dirty" policy means that as soon as setValue is called the property is changed immediately. And additionally sent over network. This can sometimes lead to bugs as the other clients do not immediately have the same value. For more information see changeValue.

PolicyLocal means that a KGameProperty behaves like ever "normal" variable. Whenever setValue is called (e.g. using "=") the value of the property is changes immediately without sending it over network. You might want to use this if you are sure that all clients set the property at the same time.

Definition at line 109 of file kgameproperty.h.


Constructor & Destructor Documentation

KGamePropertyBase::KGamePropertyBase int  id,
KGamePropertyHandler owner
 

Constructs a KGamePropertyBase object and calls registerData.

Parameters:
id The id of this property. MUST be UNIQUE! Used to send and receive changes in the property of the playere automatically via network.
owner The owner of the object. Must be a KGamePropertyHandler which manages the changes made to this object, i.e. which will send the new data

Definition at line 44 of file kgameproperty.cpp.

KGamePropertyBase::KGamePropertyBase  ) 
 

Creates a KGamePropertyBase object without an owner.

Remember to call registerData!

Definition at line 50 of file kgameproperty.cpp.


Member Function Documentation

void KGamePropertyBase::command QDataStream &  stream,
int  msgid,
bool  isSender = false
[virtual]
 

send a command to advanced properties like arrays

Parameters:
stream The stream containing the data of the comand
msgid The ID of the command - see PropertyCommandIds
isSender whether this client is also the sender of the command

Definition at line 195 of file kgameproperty.cpp.

void KGamePropertyBase::emitSignal  )  [protected]
 

Causes the parent object to emit a signal on value change.

Definition at line 185 of file kgameproperty.cpp.

int KGamePropertyBase::id  )  const [inline]
 

Returns:
The id of this property

Definition at line 238 of file kgameproperty.h.

bool KGamePropertyBase::isDirty  )  const [inline]
 

Returns:
Whether this property is "dirty". See also setDirty

Definition at line 180 of file kgameproperty.h.

bool KGamePropertyBase::isEmittingSignal  )  const [inline]
 

See also setEmittingSignal.

Returns:
Whether this property emits a signal on value change

Definition at line 163 of file kgameproperty.h.

bool KGamePropertyBase::isLocked  )  const [inline]
 

A locked property can only be changed by the player who has set the lock.

See also setLocked

Returns:
Whether this property is currently locked.

Definition at line 187 of file kgameproperty.h.

bool KGamePropertyBase::isOptimized  )  const [inline]
 

See also setOptimize.

Returns:
Whether the property optimizes access (signals,network traffic)

Definition at line 175 of file kgameproperty.h.

virtual void KGamePropertyBase::load QDataStream &  s  )  [pure virtual]
 

This will read the value of this property from the stream.

You MUST overwrite this method in order to use this class

Parameters:
s The stream to read from

Implemented in KGameProperty< type >, KGameProperty< QString >, KGameProperty< int >, KGameProperty< Q_INT8 >, and KGameProperty< unsigned int >.

bool KGamePropertyBase::lock  ) 
 

A locked property can only be changed by the player who has set the lock.

You can only call this if isLocked is false. A message is sent over network so that the property is locked for all players except you.

Returns:
returns false if the property can not be locked, i.e. it is already locked

Definition at line 152 of file kgameproperty.cpp.

PropertyPolicy KGamePropertyBase::policy  )  const [inline]
 

Returns:
The default policy of the property

Definition at line 150 of file kgameproperty.h.

int KGamePropertyBase::registerData KGamePropertyHandler owner,
PropertyPolicy  p = PolicyUndefined,
QString  name = 0
 

This is an overloaded member function, provided for convenience.

It differs from the above function only in what argument(s) it accepts. In particular you can use this function to create properties which will have an automatic id assigned. Thtr>

KGamePropertyHandler owner
 

Constructs a KGamePropertyBase object and calls registerData.

Parameters:
id The id of this property. MUST be UNIQUE! Used to send and receive changes in the property of the playere automatically via network.
owner The owner of the object. Must be a KGamePropertyHandler which manages the changes made to this object, i.e. which will send the new data

Definition at line 44 of file kgameproperty.cpp.

KGamePropertyBase::KGamePropertyBase  ) 
 

Creates a KGamePropertyBase object without an owner.

Remember to call registerData!

Definition at line 50 of file kgameproperty.cpp.


Member Function Documentation

void KGamePropertyBase::command QDataStream &  stream,
int  msgid,
bool  isSender = false
[virtual]
 

send a command to advanced properties like arrays

Parameters:
stream The stream containing the data of the comand
msgid The ID of the command - see PropertyCommandIds
isSender whether this client is also the sender of the command

Definition at line 195 of file kgameproperty.cpp.

void KGamePropertyBase::emitSignal  )  [protected]
 

Causes the parent object to emit a signal on value change.

Definition at line 185 of file kgameproperty.cpp.

int KGamePropertyBase::id  )  const [inline]
 

Returns:
The id of this property

Definition at line 238 of file kgameproperty.h.

bool KGamePropertyBase::isDirty  )  const [inline]
 

Returns:
Whether this property is "dirty". See also setDirty

Definition at line 180 of file kgameproperty.h.

bool KGamePropertyBase::isEmittingSignal  )  const [inline]
 

See also setEmittingSignal.

Returns:
Whether this property emits a signal on value change

Definition at line 163 of file kgameproperty.h.

bool KGamePropertyBase::isLocked  )  const [inline]
 

A locked property can only be changed by the player who has set the lock.

See also setLocked

Returns:
Whether this property is currently locked.

Definition at line 187 of file kgameproperty.h.

bool KGamePropertyBase::isOptimized  )  const [inline]
 

See also setOptimize.

Returns:
Whether the property optimizes access (signals,network traffic)

Definition at line 175 of file kgameproperty.h.

virtual void KGamePropertyBase::load QDataStream &  s  )  [pure virtual]
 

This will read the value of this property from the stream.

You MUST overwrite this method in order to use this class

Parameters:
s The stream to read from

Implemented in KGameProperty< type >, KGameProperty< QString >, KGameProperty< int >, KGameProperty< Q_INT8 >, and KGameProperty< unsigned int >.

bool KGamePropertyBase::lock  ) 
 

A locked property can only be changed by the player who has set the lock.

You can only call this if isLocked is false. A message is sent over network so that the property is locked for all players except you.

Returns:
returns false if the property can not be locked, i.e. it is already locked

Definition at line 152 of file kgameproperty.cpp.

PropertyPolicy KGamePropertyBase::policy  )  const [inline]
 

Returns:
The default policy of the property

Definition at line 150 of file kgameproperty.h.

int KGamePropertyBase::registerData KGamePropertyHandler owner,
PropertyPolicy  p = PolicyUndefined,
QString  name = 0
 

This is an overloaded member function, provided for convenience.

It differs from the above function only in what argument(s) it accepts. In particular you can use this function to create properties which will have an automatic id assigned. Thtr>

KGamePropertyHandler owner
 

Constructs a KGamePropertyBase object and calls registerData.

Parameters:
id The id of this property. MUST be UNIQUE! Used to send and receive changes in the property of the playere automatically via network.
owner The owner of the object. Must be a KGamePropertyHandler which manages the changes made to this object, i.e. which will send the new data

Definition at line 44 of file kgameproperty.cpp.

KGamePropertyBase::KGamePropertyBase  ) 
 

Creates a KGamePropertyBase object without an owner.

Remember to call registerData!

Definition at line 50 of file kgameproperty.cpp.


Member Function Documentation

void KGamePropertyBase::command QDataStream &  stream,
int  msgid,
bool  isSender = false
[virtual]
 

send a command to advanced properties like arrays

Parameters:
stream The stream containing the data of the comand
msgid The ID of the command - see PropertyCommandIds
isSender whether this client is also the sender of the command

Definition at line 195 of file kgameproperty.cpp.

void KGamePropertyBase::emitSignal  )  [protected]
 

Causes the parent object to emit a signal on value change.

Definition at line 185 of file kgameproperty.cpp.

int KGamePropertyBase::id  )  const [inline]
 

Returns:
The id of this property

Definition at line 238 of file kgameproperty.h.

bool KGamePropertyBase::isDirty  )  const [inline]
 

Returns:
Whether this property is "dirty". See also setDirty

Definition at line 180 of file kgameproperty.h.

bool KGamePropertyBase::isEmittingSignal  )  const [inline]
 

See also setEmittingSignal.

Returns:
Whether this property emits a signal on value change

Definition at line 163 of file kgameproperty.h.

bool KGamePropertyBase::isLocked  )  const [inline]
 

A locked property can only be changed by the player who has set the lock.

See also setLocked

Returns:
Whether this property is currently locked.

Definition at line 187 of file kgameproperty.h.

bool KGamePropertyBase::isOptimized  )  const [inline]
 

See also setOptimize.

Returns:
Whether the property optimizes access (signals,network traffic)

Definition at line 175 of file kgameproperty.h.