1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /* -----------------------------------------
25 * Static Implementation of CGuildPD
26 * ----------------------------------------- */
27 TGuildId
CGuildPD::getId() const
31 uint64
CGuildPD::getMoney() const
35 void CGuildPD::setMoney(uint64 __v
, bool forceWrite
)
37 if ((_Money
!= __v
) || forceWrite
)
39 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(1), __v
);
43 uint32
CGuildPD::getCreationDate() const
47 void CGuildPD::setCreationDate(uint32 __v
, bool forceWrite
)
49 if ((_CreationDate
!= __v
) || forceWrite
)
51 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(2), __v
);
55 uint32
CGuildPD::getXP() const
59 void CGuildPD::setXP(uint32 __v
, bool forceWrite
)
61 if ((_XP
!= __v
) || forceWrite
)
63 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(3), __v
);
67 uint32
CGuildPD::getChargesPoints() const
69 return _ChargesPoints
;
71 void CGuildPD::setChargesPoints(uint32 __v
, bool forceWrite
)
73 if ((_ChargesPoints
!= __v
) || forceWrite
)
75 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(4), __v
);
79 CPeople::TPeople
CGuildPD::getRace() const
83 void CGuildPD::setRace(CPeople::TPeople __v
, bool forceWrite
)
85 nlassert(__v
<CPeople::___TPeople_useSize
);
86 if ((_Race
!= __v
) || forceWrite
)
88 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(5), (uint32
)__v
);
92 uint64
CGuildPD::getIcon() const
96 void CGuildPD::setIcon(uint64 __v
, bool forceWrite
)
98 if ((_Icon
!= __v
) || forceWrite
)
100 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(6), __v
);
104 uint32
CGuildPD::getBuilding() const
108 void CGuildPD::setBuilding(uint32 __v
, bool forceWrite
)
110 if ((_Building
!= __v
) || forceWrite
)
112 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(7), __v
);
116 uint32
CGuildPD::getVersion() const
120 void CGuildPD::setVersion(uint32 __v
, bool forceWrite
)
122 if ((_Version
!= __v
) || forceWrite
)
124 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(8), __v
);
128 CGuildMemberPD
* CGuildPD::getMembers(const TCharacterId
& __k
)
130 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator _it
= _Members
.find(__k
);
131 return (_it
==_Members
.end() ? NULL
: (*_it
).second
);
133 const CGuildMemberPD
* CGuildPD::getMembers(const TCharacterId
& __k
) const
135 std::map
<TCharacterId
, CGuildMemberPD
*>::const_iterator _it
= _Members
.find(__k
);
136 return (_it
==_Members
.end() ? NULL
: (*_it
).second
);
138 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator
CGuildPD::getMembersBegin()
140 return _Members
.begin();
142 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator
CGuildPD::getMembersEnd()
144 return _Members
.end();
146 std::map
<TCharacterId
, CGuildMemberPD
*>::const_iterator
CGuildPD::getMembersBegin() const
148 return _Members
.begin();
150 std::map
<TCharacterId
, CGuildMemberPD
*>::const_iterator
CGuildPD::getMembersEnd() const
152 return _Members
.end();
154 const std::map
<TCharacterId
, CGuildMemberPD
*> & CGuildPD::getMembers() const
158 void CGuildPD::setMembers(CGuildMemberPD
* __v
)
160 if (__v
== NULL
) return;
161 TCharacterId __k
= __v
->getId();
162 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator _it
= _Members
.find(__k
);
163 if (_it
!= _Members
.end())
165 CGuildMemberPD
* __prev
= (*_it
).second
;
166 if (__prev
== __v
) return;
167 __prev
->pds__setParent(NULL
);
168 __prev
->pds__unregister();
169 __prev
->pds__destroy();
172 __v
->pds__setParent(this);
175 // callback the manager
176 IGuildManager::getInstance().guildMemberListChanged(this);
179 void CGuildPD::deleteFromMembers(const TCharacterId
&__k
)
181 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __it
= _Members
.find(__k
);
182 if (__it
== _Members
.end()) return;
183 CGuildMemberPD
* __o
= (*__it
).second
;
184 __o
->pds__unregister();
188 // callback the manager
189 IGuildManager::getInstance().guildMemberListChanged(this);
192 CGuildFameContainerPD
* CGuildPD::getFameContainer()
194 return _FameContainer
;
196 const CGuildFameContainerPD
* CGuildPD::getFameContainer() const
198 return _FameContainer
;
200 void CGuildPD::setFameContainer(CGuildFameContainerPD
* __v
)
202 if (_FameContainer
!= NULL
)
204 _FameContainer
->pds__setParent(NULL
);
206 __v
->pds__setParent(this);
207 _FameContainer
= __v
;
209 CGuildContainerPD
* CGuildPD::getParent()
213 const CGuildContainerPD
* CGuildPD::getParent() const
217 void CGuildPD::clear()
220 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(1), (uint64
)0);
222 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(2), 0);
224 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(3), 0);
226 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(4), 0);
227 _Race
= (CPeople::TPeople
)0;
228 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(5), (uint32
)(CPeople::TPeople
)0);
230 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(6), (uint64
)0);
232 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(7), 0);
234 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(8), 0);
235 for (std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __it
=_Members
.begin(); __it
!=_Members
.end(); )
237 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __itr
=__it
++;
238 CGuildMemberPD
* __o
= (*__itr
).second
;
239 __o
->pds__unregister();
244 CGuildFameContainerPD
* __o
= _FameContainer
;
245 __o
->pds__unregister();
249 CGuildPD
* CGuildPD::cast(RY_PDS::IPDBaseData
* obj
)
251 return (obj
->getTable() == 4) ? static_cast<CGuildPD
*>(obj
) : NULL
;
253 const CGuildPD
* CGuildPD::cast(const RY_PDS::IPDBaseData
* obj
)
255 return (obj
->getTable() == 4) ? static_cast<const CGuildPD
*>(obj
) : NULL
;
257 void CGuildPD::setFactory(RY_PDS::TPDFactory userFactory
)
259 pds_static__setFactory(userFactory
);
261 CGuildPD
* CGuildPD::create(const TGuildId
&Id
)
263 CGuildPD
*__o
= static_cast<CGuildPD
*>(PDSLib
.create(4));
265 __o
->pds__register();
266 __o
->pds__notifyInit();
269 void CGuildPD::apply(CPersistentDataRecord
&__pdr
)
271 uint16 __Tok_MapKey
= __pdr
.addString("__Key__");
272 uint16 __Tok_MapVal
= __pdr
.addString("__Val__");
273 uint16 __Tok_ClassName
= __pdr
.addString("__Class__");
274 uint16 __TokId
= __pdr
.addString("Id");
275 uint16 __TokMoney
= __pdr
.addString("Money");
276 uint16 __TokCreationDate
= __pdr
.addString("CreationDate");
277 uint16 __TokXP
= __pdr
.addString("XP");
278 uint16 __TokChargesPoints
= __pdr
.addString("ChargesPoints");
279 uint16 __TokRace
= __pdr
.addString("Race");
280 uint16 __TokIcon
= __pdr
.addString("Icon");
281 uint16 __TokBuilding
= __pdr
.addString("Building");
282 uint16 __TokVersion
= __pdr
.addString("Version");
283 uint16 __TokMembers
= __pdr
.addString("Members");
284 uint16 __TokFameContainer
= __pdr
.addString("FameContainer");
286 while (!__pdr
.isEndOfStruct())
289 else if (__pdr
.peekNextToken() == __TokId
)
291 __pdr
.pop(__TokId
, _Id
);
293 else if (__pdr
.peekNextToken() == __TokMoney
)
295 __pdr
.pop(__TokMoney
, _Money
);
297 else if (__pdr
.peekNextToken() == __TokCreationDate
)
299 __pdr
.pop(__TokCreationDate
, _CreationDate
);
301 else if (__pdr
.peekNextToken() == __TokXP
)
303 __pdr
.pop(__TokXP
, _XP
);
305 else if (__pdr
.peekNextToken() == __TokChargesPoints
)
307 __pdr
.pop(__TokChargesPoints
, _ChargesPoints
);
309 else if (__pdr
.peekNextToken() == __TokRace
)
312 std::string valuename
;
313 __pdr
.pop(__TokRace
, valuename
);
314 _Race
= CPeople::fromString(valuename
);
317 else if (__pdr
.peekNextToken() == __TokIcon
)
319 __pdr
.pop(__TokIcon
, _Icon
);
321 else if (__pdr
.peekNextToken() == __TokBuilding
)
323 __pdr
.pop(__TokBuilding
, _Building
);
325 else if (__pdr
.peekNextToken() == __TokVersion
)
327 __pdr
.pop(__TokVersion
, _Version
);
330 else if (__pdr
.peekNextToken() == __TokMembers
)
332 __pdr
.popStructBegin(__TokMembers
);
333 while (!__pdr
.isEndOfStruct())
336 __pdr
.pop(__Tok_MapKey
, key
);
337 __pdr
.popStructBegin(__Tok_MapVal
);
340 if (__pdr
.peekNextToken() == __Tok_ClassName
)
342 std::string __className
;
343 __pdr
.pop(__Tok_ClassName
, __className
);
344 obj
= CGuildMemberPD::cast(PDSLib
.create(__className
));
347 __pdr
.popStructBegin(__TokMembers
);
349 obj
->pds__setParentUnnotified(this);
350 __pdr
.popStructEnd(__TokMembers
);
361 __pdr
.popStructEnd(__Tok_MapVal
);
363 __pdr
.popStructEnd(__TokMembers
);
365 // end of apply Members
366 // apply FameContainer
367 else if (__pdr
.peekNextToken() == __TokFameContainer
)
369 __pdr
.popStructBegin(__TokFameContainer
);
370 _FameContainer
= NULL
;
371 if (__pdr
.peekNextToken() == __Tok_ClassName
)
373 std::string __className
;
374 __pdr
.pop(__Tok_ClassName
, __className
);
375 _FameContainer
= CGuildFameContainerPD::cast(PDSLib
.create(__className
));
376 if (_FameContainer
!= NULL
)
378 __pdr
.popStructBegin(__TokFameContainer
);
379 _FameContainer
->apply(__pdr
);
380 _FameContainer
->pds__setParentUnnotified(this);
381 __pdr
.popStructEnd(__TokFameContainer
);
388 __pdr
.popStructEnd(__TokFameContainer
);
392 nlwarning("Skipping unrecognised token: %s", __pdr
.peekNextTokenName().c_str());
397 void CGuildPD::store(CPersistentDataRecord
&__pdr
) const
399 uint16 __Tok_MapKey
= __pdr
.addString("__Key__");
400 uint16 __Tok_MapVal
= __pdr
.addString("__Val__");
401 uint16 __Tok_ClassName
= __pdr
.addString("__Class__");
402 uint16 __TokId
= __pdr
.addString("Id");
403 uint16 __TokMoney
= __pdr
.addString("Money");
404 uint16 __TokCreationDate
= __pdr
.addString("CreationDate");
405 uint16 __TokXP
= __pdr
.addString("XP");
406 uint16 __TokChargesPoints
= __pdr
.addString("ChargesPoints");
407 uint16 __TokRace
= __pdr
.addString("Race");
408 uint16 __TokIcon
= __pdr
.addString("Icon");
409 uint16 __TokBuilding
= __pdr
.addString("Building");
410 uint16 __TokVersion
= __pdr
.addString("Version");
411 uint16 __TokMembers
= __pdr
.addString("Members");
412 uint16 __TokFameContainer
= __pdr
.addString("FameContainer");
413 __pdr
.push(__TokId
, _Id
);
414 __pdr
.push(__TokMoney
, _Money
);
415 __pdr
.push(__TokCreationDate
, _CreationDate
);
416 __pdr
.push(__TokXP
, _XP
);
417 __pdr
.push(__TokChargesPoints
, _ChargesPoints
);
419 std::string valuename
= CPeople::toString(_Race
);
420 __pdr
.push(__TokRace
, valuename
);
422 __pdr
.push(__TokIcon
, _Icon
);
423 __pdr
.push(__TokBuilding
, _Building
);
424 __pdr
.push(__TokVersion
, _Version
);
426 __pdr
.pushStructBegin(__TokMembers
);
427 for (std::map
<TCharacterId
, CGuildMemberPD
*>::const_iterator it
=_Members
.begin(); it
!=_Members
.end(); ++it
)
429 TCharacterId key
= (*it
).first
;
430 __pdr
.push(__Tok_MapKey
, key
);
431 __pdr
.pushStructBegin(__Tok_MapVal
);
432 if ((*it
).second
!= NULL
)
434 std::string __className
= PDSLib
.getClassName((*it
).second
);
435 __pdr
.push(__Tok_ClassName
, __className
);
436 __pdr
.pushStructBegin(__TokMembers
);
437 (*it
).second
->store(__pdr
);
438 __pdr
.pushStructEnd(__TokMembers
);
440 __pdr
.pushStructEnd(__Tok_MapVal
);
442 __pdr
.pushStructEnd(__TokMembers
);
443 // end of store Members
444 // store FameContainer
445 __pdr
.pushStructBegin(__TokFameContainer
);
446 if (_FameContainer
!= NULL
)
448 std::string __className
= PDSLib
.getClassName(_FameContainer
);
449 __pdr
.push(__Tok_ClassName
, __className
);
450 __pdr
.pushStructBegin(__TokFameContainer
);
451 _FameContainer
->store(__pdr
);
452 __pdr
.pushStructEnd(__TokFameContainer
);
454 __pdr
.pushStructEnd(__TokFameContainer
);
456 void CGuildPD::init()
459 void CGuildPD::release()
462 void CGuildPD::pds__init(const TGuildId
&Id
)
469 _Race
= (CPeople::TPeople
)0;
473 _FameContainer
= NULL
;
476 void CGuildPD::pds__destroy()
478 for (std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __it
=_Members
.begin(); __it
!=_Members
.end(); )
480 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __itr
=__it
++;
481 CGuildMemberPD
* __o
= ((*__itr
).second
);
489 if (_FameContainer
!= NULL
)
491 CGuildFameContainerPD
* __o
= _FameContainer
;
496 void CGuildPD::pds__fetch(RY_PDS::CPData
&data
)
500 data
.serial(_CreationDate
);
502 data
.serial(_ChargesPoints
);
503 data
.serialEnum(_Race
);
505 data
.serial(_Building
);
506 data
.serial(_Version
);
507 RY_PDS::TTableIndex tableIndex
;
508 RY_PDS::TRowIndex rowIndex
;
511 // read table and row, create an object, affect to the ref, and fetch it
512 data
.serial(tableIndex
, rowIndex
);
513 if (rowIndex
== RY_PDS::INVALID_ROW_INDEX
|| tableIndex
== RY_PDS::INVALID_TABLE_INDEX
) break;
516 CGuildMemberPD
* __o
= static_cast<CGuildMemberPD
*>(PDSLib
.create(tableIndex
));
517 _Members
.insert(std::make_pair(__k
, __o
));
518 PDSLib
.setRowIndex(rowIndex
, __o
);
519 __o
->pds__fetch(data
);
520 __o
->pds__setParentUnnotified(this);
523 // read table and row, create an object, affect to the ref, and fetch it
524 _FameContainer
= NULL
;
525 data
.serial(tableIndex
, rowIndex
);
526 if (rowIndex
!= RY_PDS::INVALID_ROW_INDEX
&& tableIndex
!= RY_PDS::INVALID_TABLE_INDEX
)
528 _FameContainer
= static_cast<CGuildFameContainerPD
*>(PDSLib
.create(tableIndex
));
529 PDSLib
.setRowIndex(rowIndex
, _FameContainer
);
530 _FameContainer
->pds__fetch(data
);
531 _FameContainer
->pds__setParentUnnotified(this);
535 void CGuildPD::pds__register()
537 __BaseRow
= _IndexAllocator
.allocate();
538 PDSLib
.allocateRow(4, __BaseRow
, 0);
539 pds__registerAttributes();
541 void CGuildPD::pds__registerAttributes()
543 if (RY_PDS::PDVerbose
) nldebug("CGuildPD: registerAttributes %u:%u", 4, __BaseRow
);
544 PDSLib
.set(4, __BaseRow
, (RY_PDS::TColumnIndex
)(0), _Id
);
546 void CGuildPD::pds__unregister()
548 pds__unregisterAttributes();
549 PDSLib
.deallocateRow(4, __BaseRow
);
550 _IndexAllocator
.deallocate(__BaseRow
);
552 void CGuildPD::pds__unregisterAttributes()
554 if (RY_PDS::PDVerbose
) nldebug("CGuildPD: unregisterAttributes %u:%u", 4, __BaseRow
);
555 pds__setParent(NULL
);
556 for (std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __it
=_Members
.begin(); __it
!=_Members
.end(); )
558 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __itr
=__it
++;
559 CGuildMemberPD
* __o
= (*__itr
).second
;
560 __o
->pds__unregister();
564 if (_FameContainer
!= NULL
)
566 CGuildFameContainerPD
* __o
= _FameContainer
;
567 __o
->pds__unregister();
572 void CGuildPD::pds__setParent(CGuildContainerPD
* __parent
)
576 _Parent
->pds__unlinkGuilds(_Id
);
579 PDSLib
.setParent(4, getRow(), (RY_PDS::TColumnIndex
)(11), (__parent
!= NULL
? RY_PDS::CObjectIndex(5, __parent
->getRow()) : RY_PDS::CObjectIndex::null()));
581 void CGuildPD::pds__setParentUnnotified(CGuildContainerPD
* __parent
)
585 void CGuildPD::pds__notifyInit()
588 for (std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __it
=_Members
.begin(); __it
!=_Members
.end(); )
590 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __itr
=__it
++;
591 (*__itr
).second
->pds__notifyInit();
593 if (_FameContainer
!= NULL
)
595 _FameContainer
->pds__notifyInit();
598 void CGuildPD::pds__notifyRelease()
601 PDSLib
.release(4, __BaseRow
);
602 for (std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __it
=_Members
.begin(); __it
!=_Members
.end(); )
604 std::map
<TCharacterId
, CGuildMemberPD
*>::iterator __itr
=__it
++;
605 (*__itr
).second
->pds__notifyRelease();
607 if (_FameContainer
!= NULL
)
609 _FameContainer
->pds__notifyRelease();
612 void CGuildPD::pds__unlinkMembers(TCharacterId __k
)
616 void CGuildPD::pds__unlinkFameContainer(NLMISC::CEntityId dummy
)
619 _FameContainer
= NULL
;
622 void CGuildPD::pds_static__init()
624 PDSLib
.setIndexAllocator(4, _IndexAllocator
);
625 nlassertex(_FactoryInitialised
, ("User Factory for class CGuildPD not set!"));
626 // factory must have been set by user before database init called!
627 // You must provide a factory for the class CGuildPD as it is marked as derived
628 // Call EGSPD::CGuildPD::setFactory() with a factory before any call to EGSPD::init()!
630 void CGuildPD::pds_static__setFactory(RY_PDS::TPDFactory userFactory
)
632 if (!_FactoryInitialised
)
634 PDSLib
.registerClass(4, userFactory
, pds_static__fetch
, NULL
);
635 _FactoryInitialised
= true;
638 bool CGuildPD::_FactoryInitialised
;
639 RY_PDS::CIndexAllocator
CGuildPD::_IndexAllocator
;
640 void CGuildPD::pds_static__fetch(RY_PDS::IPDBaseData
*object
, RY_PDS::CPData
&data
)
642 CGuildPD
*__o
= static_cast<CGuildPD
*>(object
);
643 __o
->pds__fetch(data
);
644 __o
->pds__notifyInit();
646 // End of static implementation of CGuildPD