Example #1
0
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;
}
Example #2
0
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;
}
//-----------------------------------------------------------------------------
// 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;
}
Example #4
0
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);
}
Example #5
0
Node ReadStateClass::readSyscall() {
	ItemFactory ifact = this->item_factory;	
	Item it = ifact->read();
	if ( it->tok_type == tokty_id ) {
		return makeConstant( GNX_SYSFN, it->nameString() );
	} else {
		throw CompileTimeError( "Invalid token after >-> (syscall) arrow" ).culprit( it->nameString() );
	}
}
Example #6
0
bool ReadStateClass::tryToken( TokType fnc ) {
	ItemFactory ifact = this->item_factory;
	if ( ifact->peek()->tok_type == fnc ) {
		ifact->drop();
		return true;
	} else {
		return false;
	}
}
Example #7
0
bool ReadStateClass::tryName( const char * name ) {
	ItemFactory ifact = this->item_factory;
	Item it = ifact->peek();
	if ( it->nameString() == name ) {
		ifact->drop();
		return true;
	} else {
		return false;
	}
}
Example #8
0
 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);
 }
Example #9
0
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;
}
Example #10
0
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));
		}
	}
}
Example #11
0
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 );
}
Example #12
0
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);
}
Example #13
0
Node ReadStateClass::prefixProcessing() {
	ItemFactory ifact = this->item_factory;
	const int start = ifact->lineNumber();
	Node node = this->prefixProcessingCore();
	if ( node && this->span_mode ) {
		const int end = ifact->lineNumber();
		stringstream span;
		span << start;
		if ( start != end ) {
			span << ";" << end;
		}
		string spanstr( span.str() );
		string spanspan( SPAN );
		node->putAttribute( spanspan, spanstr );
	}
	return node;
}
Example #14
0
// 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();
}
Example #15
0
///	@param only1 True if one and only one result permitted.
Node ReadStateClass::readAtomicExpr( const bool only1 ) {
	ItemFactory ifact = this->item_factory;
	Item item = ifact->read();
	TokType fnc = item->tok_type;
	Role role = item->role;
	if ( role.IsLiteral() ) {
	 	return makeConstant( tok_type_as_type( fnc ), item->nameString() ); 
	} else if ( item->item_is_name() ) {
		return makeSymbol( item->nameString() );
	} else if ( fnc == tokty_charseq ) {
		//	TODO: Could give a better error message here.
		return maybeMakeAssert1( only1, makeCharSequence( item ) );
	} else if ( fnc == tokty_oparen ) {
		return maybeMakeAssert1( only1, this->readExprCheck( tokty_cparen ) );
	} else {
		throw CompileTimeError( "Unexpected token while reading attribute in element" ).culprit( "Token", item->nameString() );
	}
}
Example #16
0
/**
 * 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;
}
Example #17
0
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;
}
/*
-----------------------------------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;
        }
Example #19
0
  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;
  }
Example #20
0
static void readTags( ReadStateClass & r, NodeFactory & imp, const char * prefix, const bool add_default ) {
	if ( r.tryToken( tokty_oparen ) ) {
		ItemFactory ifact = r.item_factory;
		if ( ifact->peek()->tok_type != tokty_cparen ) {
			for ( int i = 0; true; i++ ) {
				Item item = ifact->read();
				ostringstream s;
				s << prefix << i;
				imp.put( s.str(), item->nameString() );
				
				item = ifact->read();
				if ( item->tok_type != tokty_comma ) {
					if ( item->tok_type != tokty_cparen ) throw CompileTimeError( "Expecting close parenthesis" );
					break;
				}
			}	
		}
	} else if ( add_default ) {
		imp.put( prefix, "public" );
	}
}
Example #21
0
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;
}
Example #22
0
  zorba::Item HttpResponseParser::createTextItem(std::istream* aStream)
  {
    ItemFactory* lFactory = Zorba::getInstance(0)->getItemFactory();

    // When we create a StreamableString, memory ownership gets very convoluted
    // because the StreamableString object has a longer lifecycle than the
    // iterator which creates it. The StreamableString object depends on its
    // istream, which in turn depends on its read buffer. For us, the read
    // buffer in turn depends on the HttpResponseParser (this object) because
    // it is registered as the "informer" (callback object) for
    // theStreamBuffer. Therefore, this HttpResponseParser object is no longer
    // "self-contained". We delegate ownership of ourself to theStreamBuffer
    // and mark ourselves as no longer being self-contained.
    theStreamBuffer->set_listener(this, true);
    theSelfContained = false;

    // The ownership of theStreamBuffer, in turn, is delegated to the
    // StreamableString object (via streamReleaser, which will free the
    // istream's rdbuf).
    theStreamBuffer = NULL;
    return lFactory->createStreamableString(*aStream, &streamReleaser, false);
  }
Example #23
0
void
testMultipleFactoryInitilizations()
{
  Zorba* zorba = NULL;
  void* store = NULL;

  store = zorba::StoreManager::getStore();
  zorba = Zorba::getInstance(store);

  ItemFactory* factory = zorba->getItemFactory();
  factory->createString( "" );

  zorba->shutdown();
  zorba::StoreManager::shutdownStore(store);

  store = zorba::StoreManager::getStore();
  zorba = Zorba::getInstance(store);

  factory = zorba->getItemFactory();
  factory->createString( "" ); // <-- zorba crashes here

  zorba->shutdown();
  zorba::StoreManager::shutdownStore(store);
}
Example #24
0
Node ReadStateClass::readOptExprPrec( int prec ) {
	ItemFactory ifact = this->item_factory;
	Node e = this->prefixProcessing();
	if ( not e ) return Node();
	//cerr << "starting postfix checking ... " << this->isPostfixAllowed() << endl;
	while ( this->isPostfixAllowed() ) {
	    int q;
	    //cerr << "peeking" << endl;
		Item it = ifact->peek();
		if ( it->item_is_signed_num() ) {
			NodeFactory t;
			t.start( SYSAPP );
			t.put( "name", "+" );
			t.add( e );			
			if ( it->tok_type == tokty_int ) {
				t.start( "constant" );
				t.put( "type", "int" );
				t.put( "value", it->nameString() );
				t.end();
			} else {
				throw CompileTimeError( "Only integers supported so far" ).culprit( "Item", it->nameString() );
			}
			t.end();
			e = t.build();
			ifact->drop();
		} else if ( it->item_is_postfix() ) {
	        q = it->precedence;
            if ( q >= prec ) break;
	        ifact->drop();
	        e = this->postfixProcessing( e, it, q );
		} else {
			break;
		}
    }
    return e;
}
Example #25
0
uint32 Ship::_Spawn(ItemFactory &factory, ItemData &data) {
    // make sure it's a ship
    const ShipType *st = factory.GetShipType(data.typeID);
    if(st == NULL)
        return 0;

    // store item data
    uint32 shipID = InventoryItem::_Spawn(factory, data);
    if(shipID == 0)
        return 0;

    // nothing additional

    return shipID;
}
Example #26
0
uint32 Skill::_Spawn(ItemFactory &factory, ItemData &data)
{
    // check it's a skill
    const ItemType *type = factory.GetType( data.typeID );
    if( type == NULL )
        return 0;

    if( type->categoryID() != EVEDB::invCategories::Skill )
    {
        _log( ITEM__ERROR, "Trying to spawn %s as Skill.", type->category().name().c_str() );
        return 0;
    }

    // spawn item, nothing else
    return InventoryItem::_Spawn( factory, data );
}
Example #27
0
uint32 CargoContainer::_Spawn(ItemFactory &factory,
    // InventoryItem stuff:
    ItemData &data
) {
    // make sure it's a cargo container
    const ItemType *st = factory.GetType(data.typeID);
    if(st == NULL)
        return 0;

    // store item data
    uint32 containerID = InventoryItem::_Spawn(factory, data);
    if(containerID == 0)
        return 0;

    // nothing additional

    return containerID;
}
Example #28
0
uint32 Station::_Spawn(ItemFactory &factory,
    // InventoryItem stuff:
    ItemData &data
) {
    // make sure it's a Station
    const ItemType *item = factory.GetType(data.typeID);
    if( !(item->categoryID() == EVEDB::invCategories::Station) )
        return 0;

    // store item data
    uint32 stationID = InventoryItem::_Spawn(factory, data);
    if( stationID == 0 )
        return 0;

    // nothing additional

    return stationID;
}
Example #29
0
uint32 CelestialObject::_Spawn(ItemFactory &factory,
    // InventoryItem stuff:
    ItemData &data
) {
    // make sure it's a ship
    const ItemType *item = factory.GetType(data.typeID);
    if( !(item->categoryID() == EVEDB::invCategories::Celestial) )
        return 0;

    // store item data
    uint32 celestialID = InventoryItem::_Spawn(factory, data);
    if( celestialID == 0 )
        return 0;

    // nothing additional

    return celestialID;
}
Example #30
0
uint32 Structure::_Spawn(ItemFactory &factory,
    // InventoryItem stuff:
    ItemData &data
) {
    // make sure it's a Structure
    const ItemType *st = factory.GetType(data.typeID);
    if(st == NULL)
        return 0;

    // store item data
    uint32 structureID = InventoryItem::_Spawn(factory, data);
    if(structureID == 0)
        return 0;

    // nothing additional

    return structureID;
}