21 #ifndef __KGAMEPROPERTYARRAY_H_ 22 #define __KGAMEPROPERTYARRAY_H_ 24 #include <tqdatastream.h> 27 #include "kgamemessage.h" 28 #include "kgameproperty.h" 29 #include "kgamepropertyhandler.h" 41 KGamePropertyArray(
int size )
46 KGamePropertyArray(
const KGamePropertyArray<type> &a ) : TQMemArray<type>(a)
50 bool resize( uint size )
52 if (size!=TQMemArray<type>::size())
56 TQDataStream s(b, IO_WriteOnly);
57 KGameMessage::createPropertyCommand(s,KGamePropertyBase::IdCommand,
id(),CmdResize);
76 void setAt(uint i,type data)
79 TQDataStream s(b, IO_WriteOnly);
80 KGameMessage::createPropertyCommand(s,KGamePropertyBase::IdCommand,
id(),CmdAt);
97 type at( uint i )
const 99 return TQMemArray<type>::at(i);
102 type operator[](
int i )
const 104 return TQMemArray<type>::at(i);
107 KGamePropertyArray<type> &operator=(
const KGamePropertyArray<type> &a)
112 bool truncate( uint pos )
117 bool fill(
const type &data,
int size = -1 )
121 TQDataStream s(b, IO_WriteOnly);
122 KGameMessage::createPropertyCommand(s,KGamePropertyBase::IdCommand,
id(),CmdFill);
140 KGamePropertyArray<type>& assign(
const KGamePropertyArray<type>& a )
149 TQMemArray<type>::assign(a);
153 KGamePropertyArray<type>& assign(
const type *a, uint n )
161 TQMemArray<type>::assign(a,n);
165 KGamePropertyArray<type>& duplicate(
const KGamePropertyArray<type>& a )
173 TQMemArray<type>::duplicate(a);
177 KGamePropertyArray<type>& duplicate(
const type *a, uint n )
185 TQMemArray<type>::duplicate(a,n);
189 KGamePropertyArray<type>& setRawData(
const type *a, uint n )
197 TQMemArray<type>::setRawData(a,n);
204 TQDataStream s(b, IO_WriteOnly);
205 KGameMessage::createPropertyCommand(s,KGamePropertyBase::IdCommand,
id(),CmdSort);
219 void load(TQDataStream& s)
223 for (
unsigned int i=0; i<TQMemArray<type>::size(); i++)
226 TQMemArray<type>::at(i)=data;
233 void save(TQDataStream &s)
236 for (
unsigned int i=0; i<TQMemArray<type>::size(); i++)
242 void command(TQDataStream &s,
int cmd,
bool)
253 TQMemArray<type>::at(i)=data;
266 if (TQMemArray<type>::size() != size)
268 TQMemArray<type>::resize(size);
278 TQMemArray<type>::fill(data,size);
288 TQMemArray<type>::sort();
292 kdError(11001) <<
"Error in KPropertyArray::command: Unknown command " << cmd << endl;
297 void extractProperty(
const TQByteArray& b)
299 TQDataStream s(b, IO_ReadOnly);
302 KGameMessage::extractPropertyHeader(s, propId);
303 KGameMessage::extractPropertyCommand(s, propId, cmd);
bool sendProperty(TQDataStream &s)
called by a property to send itself into the datastream.
virtual void save(TQDataStream &s)=0
Write the value into a stream.
bool sendProperty()
Forward the data to the owner of this property which then sends it over network.
void emitSignal()
Causes the parent object to emit a signal on value change.
virtual void command(TQDataStream &stream, int msgid, bool isSender=false)
send a command to advanced properties like arrays
Base class of KGameProperty.
bool isEmittingSignal() const
See also setEmittingSignal.
PropertyPolicy policy() const
virtual void load(TQDataStream &s)=0
This will read the value of this property from the stream.