本文整理汇总了C++中ItemFactory类的典型用法代码示例。如果您正苦于以下问题:C++ ItemFactory类的具体用法?C++ ItemFactory怎么用?C++ ItemFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ItemFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _Spawn
uint32 Blueprint::_Spawn(ItemFactory &factory,
// InventoryItem stuff:
ItemData &data,
// Blueprint stuff:
BlueprintData &bpData
) {
// make sure it's a blueprint type
const BlueprintType *bt = factory.GetBlueprintType(data.typeID);
if(bt == NULL)
return 0;
// get the blueprintID
uint32 blueprintID = InventoryItem::_Spawn(factory, data);
if(blueprintID == 0)
return 0;
// insert blueprint entry into DB
if(!factory.db().NewBlueprint(blueprintID, bpData)) {
// delete item
factory.db().DeleteItem(blueprintID);
return 0;
}
return blueprintID;
}
示例2: _Spawn
uint32 Character::_Spawn(ItemFactory &factory,
// InventoryItem stuff:
ItemData &data,
// Character stuff:
CharacterData &charData, CharacterAppearance &appData, CorpMemberInfo &corpData
) {
// make sure it's a character
const CharacterType *ct = factory.GetCharacterType(data.typeID);
if(ct == NULL)
return 0;
// make sure it's a singleton with qty 1
if(!data.singleton || data.quantity != 1) {
_log(ITEM__ERROR, "Tried to create non-singleton character %s.", data.name.c_str());
return 0;
}
// first the item
uint32 characterID = Owner::_Spawn(factory, data);
if(characterID == 0)
return 0;
// then character
if(!factory.db().NewCharacter(characterID, charData, appData, corpData)) {
// delete the item
factory.db().DeleteItem(characterID);
return 0;
}
return characterID;
}
示例3: create
//-----------------------------------------------------------------------------
// create
// This method parses the data out of the string and then checks the data.
// If the data is correct, creates the ChechOutTransaction object and
// returns it, otherwise does not create the object and returns NULL
//parameters are userId, itemType, itemFormat, itemDescription
Transaction* CheckOutTransaction::create(ifstream& infile)
{
int tempid;
Transaction* fail = NULL;
//read in the user id first
infile >> tempid;
if (infile.eof())
{
return fail;
}
//read in the type
ItemFactory tempfact;
Item* itemp = tempfact.createtrans(infile);
cout << "........." << itemp->getTitle() << "........";
//use the type to create an item using item factory
//and extract the information from the book
if(itemp != NULL)
{
CheckOutTransaction* newcheck = new CheckOutTransaction
(tempid, itemp->getItemType(), 'H', itemp->getTitle());
return newcheck;
}
else
return fail;
}
示例4: getFactory
void TreasureArme::open(Personnage &p) {
Random *r = Random::getInstance();
ItemFactory *f = getFactory(r->getRand());
Arme *a;
switch (r->getRand()%3) {
case 1:
a = f->GetEpee();
break;
case 2:
a = f->GetDague();
break;
default:
a = f->GetHache();
}
for (int i = 0; i < m_lvl; ++i) {
switch (r->getRand()%6) {
case 0:
a = new DArmeD(a);
break;
case 1:
a = new DArmeC(a);
break;
case 2:
a = new DArmeF(a);
break;
case 3:
a = new DArmeV(a);
break;
}
}
delete f;
p.trouverArme(a);
}
示例5:
zorba::Item HttpResponseParser::createBase64Item( std::istream& aStream )
{
ItemFactory* lFactory = Zorba::getInstance(0)->getItemFactory();
// TODO: once a proper streaming implementation is in place this can be
// changed. This required a Base64 encoding stream since the item factory
// work only builds base64binary and assumes the data is already encoded.
String lEncoded;
zorba::base64::encode(aStream, &lEncoded);
return lFactory->createBase64Binary(lEncoded.data(), lEncoded.size(), true);
}
示例6: staticcollectionamanger3
bool
staticcollectionamanger3(zorba::Zorba* z)
{
try {
std::ifstream lIn("module1.xq");
zorba::XQuery_t lQuery = z->createQuery();
Zorba_CompilerHints lHints;
lQuery->compile(lIn, lHints);
const StaticContext* lSctx = lQuery->getStaticContext();
StaticCollectionManager* lColMgr = lSctx->getStaticCollectionManager();
ItemFactory* lFac = z->getItemFactory();
Item lCollName2 = lFac->createQName("http://www.mod2.com/", "coll");
lColMgr->createCollection(lCollName2);
{
Collection_t lColl = lColMgr->getCollection(lCollName2);
std::vector<Annotation_t> lAnnotations;
lColl->getAnnotations(lAnnotations);
size_t num_annotations = 0;
for (std::vector<Annotation_t>::const_iterator lIter = lAnnotations.begin();
lIter != lAnnotations.end(); ++lIter)
{
std::cout << "Annotation QName " << (*lIter)->getQName().getStringValue() << std::endl;
++num_annotations;
}
if (num_annotations != 3)
{
return false;
}
}
lColMgr->deleteCollection(lCollName2);
return true;
}
catch ( std::exception const &e ) {
std::cerr << e.what() << std::endl;
}
catch ( ... ) {
std::cerr << "caught unexpected exception" << std::endl;
}
return false;
}
示例7: ItemFactory
STATIC void ItemFactory::LoadAllItems() {
String relDir = "Data/Items/";
std::vector<String> filePaths = FileUtils::GetAllFilenamesInDirectory(relDir);
for (unsigned int i = 0; i < filePaths.size(); i++) {
XMLNode root = XMLNode::parseFile(filePaths[i].c_str());
root = root.getChildNode(0);
for (int j = 0; j < root.nChildNode(); j++) {
XMLNode itemBlueprint = root.getChildNode(j);
ItemFactory* currFactory = new ItemFactory(itemBlueprint);
s_itemFactories.insert(std::pair<String, ItemFactory*>(currFactory->GetName(), currFactory));
}
}
}
示例8: Spawn
OwnerRef Owner::Spawn(ItemFactory &factory, ItemData &data)
{
// obtain type of new item
const ItemType *t = factory.GetType( data.typeID );
if( t == NULL )
return OwnerRef();
switch( t->groupID() )
{
///////////////////////////////////////
// Character:
///////////////////////////////////////
case EVEDB::invGroups::Character: {
// we're not gonna create character from default attributes ...
_log( ITEM__ERROR, "Refusing to create character '%s' from default attributes.", data.name.c_str() );
return OwnerRef();
}
}
// fallback to default:
uint32 ownerID = Owner::_Spawn( factory, data );
if( ownerID == 0 )
return OwnerRef();
return Owner::Load( factory, ownerID );
}
示例9: _Spawn
uint32 InventoryItem::_Spawn(ItemFactory &factory,
// InventoryItem stuff:
ItemData &data
) {
// obtain type of new item
// this also checks that the type is valid
const ItemType *t = factory.GetType(data.typeID);
if(t == NULL)
return 0;
// fix the name (if empty)
if(data.name.empty())
data.name = t->name();
// insert new entry into DB
return factory.db().NewItem(data);
}
示例10: _SpawnEntity
// This Spawn function is meant for in-memory only items created from the
// EVEDB::invCategories::Entity category, items meant to never be saved to database
// and be thrown away on server shutdown.
uint32 InventoryItem::_SpawnEntity(ItemFactory &factory,
// InventoryItem stuff:
ItemData &data
) {
// obtain type of new item
// this also checks that the type is valid
const ItemType *t = factory.GetType(data.typeID);
if(t == NULL)
return 0;
// fix the name (if empty)
if(data.name.empty())
data.name = t->name();
// Get a new Entity ID from ItemFactory's ID Authority:
return factory.GetNextEntityID();
}
示例11: staticcollectionmanager6
/**
* test that declaredIndexes doesn't return temporary indexes and crashes
* if one tries to create one
*/
bool
staticcollectionmanager6(zorba::Zorba* z)
{
try {
std::ifstream lIn("module1.xq");
zorba::XQuery_t lQuery = z->createQuery();
Zorba_CompilerHints lHints;
lQuery->compile(lIn, lHints);
StaticCollectionManager* lColMgr = lQuery->getStaticCollectionManager();
ItemFactory* lFac = z->getItemFactory();
Item lCollName2 = lFac->createQName("http://www.mod2.com/", "coll");
Item lIdxName = lFac->createQName("http://www.mod2.com/", "index");
Item lCollName3 = lFac->createQName("http://www.mod3.com/", "coll");
ItemSequence_t lSeq = lColMgr->declaredCollections();
Iterator_t lIter = lSeq->getIterator();
lIter->open();
Item lTmp;
while (lIter->next(lTmp)) {
std::cout << "name " << lTmp.getStringValue() << std::endl;
lColMgr->createCollection(lTmp);
}
lSeq = lColMgr->declaredIndexes();
lIter = lSeq->getIterator();
lIter->open();
while (lIter->next(lTmp)) {
std::cout << "name " << lTmp.getStringValue() << std::endl;
lColMgr->createIndex(lTmp);
}
return true;
}
catch ( std::exception const &e ) {
std::cerr << e.what() << std::endl;
}
catch ( ... ) {
std::cerr << "caught unexpected exception" << std::endl;
}
return false;
}
示例12: LoadEntity
InventoryItemRef InventoryItem::LoadEntity(ItemFactory &factory, uint32 itemID, const ItemData &data)
{
const ItemType *type = factory.GetType( data.typeID );
InventoryItemRef itemRef = InventoryItemRef( new InventoryItem(factory, itemID, *type, data) );
itemRef->_Load();
return itemRef;
}
示例13: set
/*
-----------------------------------set-------------------------------------
set - Sets up and defines, and inserts the the transaction.
Preconditions: valid file stream containing properly formatted input
Postconditions: Execute action as specified by corresponding concrete action.
*/
bool Transaction::set(std::ifstream& infile) {
//Setting up local identifiers.
int ID = -1, hash = -1;
bool set = false, success = false;
char itemType = NULL_ITEM;
std::string junk;
Patron* patron = NULL;
Item* item = NULL;
ItemFactory factory;
//Verify that we're not at the end of the file stream - something invalid
//got us here?
if(!infile.eof()) {
infile.get();
infile >> ID;
//Does the patron exist? -> set
patron = MyLibrary.find(ID);
if(patron != NULL) {
MyPatron = patron;
PatronID = ID;
patron = NULL;
}
//If not, let's get out.
else {
return false;
}
//Get a temporary item from the factory
infile.get();
infile >> itemType;
//build item -> does it exist?
if(itemType == FICTION_ITEM ||
itemType == YOUTH_ITEM ||
itemType == PERIODICAL_ITEM) {
item = factory.create(itemType);
//Throwing out the 'H' for hardcopy.
infile >> junk;
}
示例14: parseBody
bool HttpResponseParser::parseBody(std::istream& aStream, const std::string& aBoundary)
{
std::string lLine;
std::stringstream lBody;
zorba::Item lItem;
bool bodyEnd = false;
bool responseEnd = false;
ItemFactory* lFactory = Zorba::getInstance(0)->getItemFactory();
theHandler.beginBody(theCurrentContentType, "", NULL);
while (aStream.good())
{
std::getline(aStream, lLine);
if (lLine.compare("--" + aBoundary + "\r") == 0 ||
lLine.compare("--" + aBoundary) == 0)
bodyEnd = true;
else if (lLine.compare("--" + aBoundary + "--\r") == 0 ||
lLine.compare("--" + aBoundary + "--") == 0)
{
bodyEnd = true;
responseEnd = true;
}
if (bodyEnd)
{
if (isTextualBody())
lItem = lFactory->createString(lBody.str());
else
lItem = createBase64Item(lBody);
theHandler.any(lItem, theCurrentCharset);
theHandler.endBody();
return responseEnd;
}
else
lBody << lLine << "\n";
}
if (!aStream.good())
theErrorThrower.raiseException("HTTP", "An HTTP error occurred reading the multipart response bodies.");
return false;
}
示例15: inventoryID
bool Inventory::LoadContents(ItemFactory &factory)
{
// check if the contents has already been loaded...
if( ContentsLoaded() )
{
return true;
}
sLog.Debug("Inventory", "Recursively loading contents of inventory %u", inventoryID() );
//load the list of items we need
std::vector<uint32> items;
if( !GetItems( factory, items ) )
{
sLog.Error("Inventory", "Failed to get items of %u", inventoryID() );
return false;
}
//Now get each one from the factory (possibly recursing)
ItemData into;
uint32 characterID;
uint32 corporationID;
uint32 locationID;
std::vector<uint32>::iterator cur, end;
cur = items.begin();
end = items.end();
for(; cur != end; cur++)
{
// Each "cur" item should be checked to see if they are "owned" by the character connected to this client,
// and if not, then do not "get" the entire contents of this for() loop for that item, except in the case that
// this item is located in space or belongs to this character's corporation:
factory.db().GetItem( *cur, into );
if( factory.GetUsingClient() != NULL )
{
characterID = factory.GetUsingClient()->GetCharacterID();
corporationID = factory.GetUsingClient()->GetCorporationID();
locationID = factory.GetUsingClient()->GetLocationID();
}
else
sLog.Error( "Inventory::LoadContents()", "Failed to resolve pointer to Client object currently using the ItemFactory." );
if( (into.ownerID == characterID) || (characterID == 0) || (into.ownerID == corporationID) || (into.locationID == locationID) )
{
// Continue to GetItem() if the client calling this is owned by the character that owns this item
// --OR--
// The characterID == 0, which means this is attempting to load the character of this client for the first time.
InventoryItemRef i = factory.GetItem( *cur );
if( !i )
{
sLog.Error("Inventory::LoadContents()", "Failed to load item %u contained in %u. Skipping.", *cur, inventoryID() );
continue;
}
AddItem( i );
}
}
mContentsLoaded = true;
return true;
}